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

Source Code for Module timeside.grapher.waveform_contour

 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 WaveformContourBlack(Waveform):
29 """ Builds a PIL image representing an amplitude coutour (envelop) of the audio stream. 30 """ 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(WaveformContourBlack, self).__init__(width, height, bg_color, color_scheme) 37 self.contour = numpy.zeros(self.image_width) 38 self.ndiv = 4 39 self.x = numpy.r_[0:self.image_width-1:1] 40 self.symetry = True 41 self.color_offset = 160
42 43 @staticmethod 44 @interfacedoc
45 - def id():
46 return "waveform_contour_black"
47 48 @staticmethod 49 @interfacedoc
50 - def name():
51 return "Contour black"
52 53 @interfacedoc
54 - def setup(self, channels=None, samplerate=None, blocksize=None, totalframes=None):
56 57 @interfacedoc
58 - def process(self, frames, eod=False):
59 if len(frames) != 1: 60 buffer = frames[:,0].copy() 61 buffer.shape = (len(buffer),1) 62 for samples, end in self.pixels_adapter.process(buffer, eod): 63 if self.pixel_cursor < self.image_width: 64 self.contour[self.pixel_cursor] = numpy.max(peaks(samples)) 65 self.pixel_cursor += 1 66 if eod: 67 self.draw_peaks_contour() 68 return frames, eod
69
70 71 72 -class WaveformContourWhite(WaveformContourBlack):
73 74 """ Builds a PIL image representing an amplitude coutour (envelop) of the audio stream. 75 """ 76 77 implements(IGrapher) 78 79 @interfacedoc
80 - def __init__(self, width=1024, height=256, bg_color=(255,255,255), color_scheme='default'):
81 super(WaveformContourWhite, self).__init__(width, height, bg_color, color_scheme) 82 self.color_offset = 60
83 84 @staticmethod 85 @interfacedoc
86 - def id():
87 return "waveform_contour_white"
88 89 @staticmethod 90 @interfacedoc
91 - def name():
92 return "Contour white"
93