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

Source Code for Module timeside.grapher.waveform_centroid

 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 Processor, implements, interfacedoc, FixedSizeInputAdapter 
23  from timeside.api import IGrapher 
24  from timeside.grapher.core import * 
25  from timeside.grapher.waveform_simple import Waveform 
26 27 28 -class WaveformCentroid(Waveform):
29 """ Builds a PIL image representing a waveform of the audio stream. 30 Peaks are colored relatively to the spectral centroids of each frame buffer. """ 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(WaveformCentroid, self).__init__(width, height, bg_color, color_scheme) 37 self.lower_freq = 200 38 colors = default_color_schemes[color_scheme]['waveform'] 39 self.color_lookup = interpolate_colors(colors)
40 41 @staticmethod 42 @interfacedoc
43 - def id():
44 return "waveform_centroid"
45 46 @staticmethod 47 @interfacedoc
48 - def name():
49 return "Waveform spectral"
50 51 @interfacedoc
52 - def setup(self, channels=None, samplerate=None, blocksize=None, totalframes=None):
54 55 @interfacedoc
56 - def process(self, frames, eod=False):
57 if len(frames) != 1: 58 buffer = frames[:,0].copy() 59 buffer.shape = (len(buffer),1) 60 for samples, end in self.pixels_adapter.process(buffer, eod): 61 if self.pixel_cursor < self.image_width: 62 (spectral_centroid, db_spectrum) = self.spectrum.process(samples, True) 63 line_color = self.color_lookup[int(spectral_centroid*255.0)] 64 self.draw_peaks(self.pixel_cursor, peaks(samples), line_color) 65 self.pixel_cursor += 1 66 return frames, eod
67