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

Source Code for Module timeside.analyzer.dc

 1  # -*- coding: utf-8 -*- 
 2  # 
 3  # Copyright (c) 2007-2009 Guillaume Pellerin <yomguy@parisson.com> 
 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: Guillaume Pellerin <yomguy@parisson.com> 
21   
22  from timeside.core import implements, interfacedoc 
23  from timeside.analyzer.core import Analyzer 
24  from timeside.api import IValueAnalyzer 
25  import numpy 
26 27 28 -class MeanDCShift(Analyzer):
29 implements(IValueAnalyzer) 30 31 @interfacedoc
32 - def setup(self, channels=None, 33 samplerate=None, 34 blocksize=None, 35 totalframes=None):
36 super(MeanDCShift, self).setup( 37 channels, samplerate, blocksize, totalframes) 38 self.values = numpy.array([0])
39 40 @staticmethod 41 @interfacedoc
42 - def id():
43 return "mean_dc_shift"
44 45 @staticmethod 46 @interfacedoc
47 - def name():
48 return "Mean DC shift"
49 50 @staticmethod 51 @interfacedoc
52 - def unit():
53 return "%"
54
55 - def process(self, frames, eod=False):
56 if frames.size: 57 self.values = numpy.append(self.values, numpy.mean(frames)) 58 return frames, eod
59
60 - def post_process(self):
61 dc_result = self.new_result(data_mode='value', time_mode='global') 62 dc_result.data_object.value = numpy.round( 63 numpy.mean(100 * self.values), 3) 64 self.process_pipe.results.add(dc_result)
65