Package timeside :: Package analyzer :: Module waveform
[hide private]
[frames] | no frames]

Source Code for Module timeside.analyzer.waveform

 1  # -*- coding: utf-8 -*- 
 2  # 
 3  # Copyright (c) 2013 Paul Brossier <piem@piem.org> 
 4   
 5  # This file is part of TimeSide. 
 6   
 7  # TimeSide is free software: you can redistribute it and/or modify 
 8  # it under the terms of the GNU General Public License as published by 
 9  # the Free Software Foundation, either version 2 of the License, or 
10  # (at your option) any later version. 
11   
12  # TimeSide is distributed in the hope that it will be useful, 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
15  # GNU General Public License for more details. 
16   
17  # You should have received a copy of the GNU General Public License 
18  # along with TimeSide.  If not, see <http://www.gnu.org/licenses/>. 
19   
20  # Author: Paul Brossier <piem@piem.org> 
21   
22  from timeside.core import implements, interfacedoc 
23  from timeside.analyzer.core import Analyzer 
24  from timeside.api import IAnalyzer 
25  import numpy as np 
26   
27  from preprocessors import downmix_to_mono, frames_adapter 
28 29 -class Waveform(Analyzer):
30 implements(IAnalyzer) # TODO check if needed with inheritance 31
32 - def __init__(self):
33 super(Waveform, self).__init__()
34 # self.input_blocksize = 2048 35 # self.input_stepsize = self.input_blocksize / 2 36 37 @interfacedoc
38 - def setup(self, channels=None, samplerate=None, 39 blocksize=None, totalframes=None):
40 super(Waveform, self).setup(channels, samplerate, 41 blocksize, totalframes) 42 self.values = [] 43 self.result_blocksize = 1 44 self.result_stepsize = 1
45 46 @staticmethod 47 @interfacedoc
48 - def id():
49 return "waveform_analyzer"
50 51 @staticmethod 52 @interfacedoc
53 - def name():
54 return "Waveform Analyzer"
55 56 @staticmethod 57 @interfacedoc
58 - def unit():
59 return ""
60 61 # @downmix_to_mono 62 # @frames_adapter
63 - def process(self, frames, eod=False):
64 self.values.append(frames) 65 return frames, eod
66
67 - def post_process(self):
68 waveform = self.new_result(data_mode='value', time_mode='framewise') 69 waveform.data_object.value = np.vstack(self.values) 70 self.process_pipe.results.add(waveform)
71