Package timeside :: Package grapher :: Module spectrogram_lin
[hide private]
[frames] | no frames]

Source Code for Module timeside.grapher.spectrogram_lin

 1  # -*- coding: utf-8 -*- 
 2  # 
 3  # Copyright (c) 2007-2010 Guillaume Pellerin <yomguy@parisson.com> 
 4  # Copyright (c) 2010 Olivier Guilyardi <olivier@samalyse.com> 
 5   
 6  # This file is part of TimeSide. 
 7   
 8  # TimeSide is free software: you can redistribute it and/or modify 
 9  # it under the terms of the GNU General Public License as published by 
10  # the Free Software Foundation, either version 2 of the License, or 
11  # (at your option) any later version. 
12   
13  # TimeSide is distributed in the hope that it will be useful, 
14  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
16  # GNU General Public License for more details. 
17   
18  # You should have received a copy of the GNU General Public License 
19  # along with TimeSide.  If not, see <http://www.gnu.org/licenses/>. 
20   
21   
22  from timeside.core import implements, interfacedoc 
23  from timeside.api import IGrapher 
24  from timeside.grapher.core import * 
25  from timeside.grapher.spectrogram_log import SpectrogramLog 
26 27 28 -class SpectrogramLinear(SpectrogramLog):
29 """ Builds a PIL image representing a spectrogram of the audio stream (level vs. frequency vs. time). 30 Adds pixels iteratively thanks to the adapter providing fixed size frame buffers.""" 31 32 implements(IGrapher) 33 34 @interfacedoc
35 - def __init__(self, width=1024, height=256, bg_color=(0,0,0), color_scheme='default'):
36 super(SpectrogramLinear, self).__init__(width, height, bg_color, color_scheme)
37 38 @staticmethod 39 @interfacedoc
40 - def id():
41 return "spectrogram_lin"
42 43 @staticmethod 44 @interfacedoc
45 - def name():
46 return "Spectrogram linear"
47 48 @interfacedoc
49 - def setup(self, channels=None, samplerate=None, blocksize=None, totalframes=None):
51
52 - def set_scale(self):
53 """generate the lookup which translates y-coordinate to fft-bin""" 54 55 f_min = float(self.lower_freq) 56 f_max = float(self.higher_freq) 57 y_min = f_min 58 y_max = f_max 59 for y in range(self.image_height): 60 freq = y_min + y / (self.image_height - 1.0) *(y_max - y_min) 61 fft_bin = freq / f_max * (self.fft_size/2 + 1) 62 if fft_bin < self.fft_size/2: 63 alpha = fft_bin - int(fft_bin) 64 self.y_to_bin.append((int(fft_bin), alpha * 255))
65