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

Source Code for Module timeside.grapher.waveform_simple

 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 26 27 -class Waveform(Grapher):
28 """ Builds a PIL image representing a simple waveform of the audio stream. 29 """ 30 31 implements(IGrapher) 32 33 @interfacedoc
34 - def __init__(self, width=1024, height=256, bg_color=(255,255,255), color_scheme='default'):
35 super(Waveform, self).__init__(width, height, bg_color, color_scheme) 36 self.line_color = (0,0,0)
37 38 @staticmethod 39 @interfacedoc
40 - def id():
41 return "waveform_simple"
42 43 @staticmethod 44 @interfacedoc
45 - def name():
46 return "Waveform simple"
47 48 @interfacedoc
49 - def setup(self, channels=None, samplerate=None, blocksize=None, totalframes=None):
51 52 @interfacedoc
53 - def process(self, frames, eod=False):
54 if len(frames) != 1: 55 buffer = frames[:,0] 56 buffer.shape = (len(buffer),1) 57 for samples, end in self.pixels_adapter.process(buffer, eod): 58 if self.pixel_cursor < self.image_width-1: 59 self.draw_peaks(self.pixel_cursor, peaks(samples), self.line_color) 60 self.pixel_cursor += 1 61 if self.pixel_cursor == self.image_width-1: 62 self.draw_peaks(self.pixel_cursor, peaks(samples), self.line_color) 63 self.pixel_cursor += 1 64 return frames, eod
65 66 @interfacedoc
67 - def post_process(self, output=None):
68 a = 1 69 for x in range(self.image_width): 70 self.pixel[x, self.image_height/2] = tuple(map(lambda p: p+a, self.pixel[x, self.image_height/2]))
71