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

Source Code for Module timeside.analyzer.aubio_melenergy

 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  from preprocessors import downmix_to_mono, frames_adapter 
26   
27  import numpy 
28  from aubio import filterbank, pvoc 
29 30 31 -class AubioMelEnergy(Analyzer):
32 implements(IAnalyzer) 33
34 - def __init__(self):
35 super(AubioMelEnergy, self).__init__() 36 self.input_blocksize = 1024 37 self.input_stepsize = self.input_blocksize / 4
38 39 @interfacedoc
40 - def setup(self, channels=None, samplerate=None, 41 blocksize=None, totalframes=None):
42 super(AubioMelEnergy, self).setup( 43 channels, samplerate, blocksize, totalframes) 44 self.n_filters = 40 45 self.n_coeffs = 13 46 self.pvoc = pvoc(self.input_blocksize, self.input_stepsize) 47 self.melenergy = filterbank(self.n_filters, self.input_blocksize) 48 self.melenergy.set_mel_coeffs_slaney(samplerate) 49 self.block_read = 0 50 self.melenergy_results = []
51 52 @staticmethod 53 @interfacedoc
54 - def id():
55 return "aubio_melenergy"
56 57 @staticmethod 58 @interfacedoc
59 - def name():
60 return "Mel Energy (aubio)"
61 62 @staticmethod 63 @interfacedoc
64 - def unit():
65 return ""
66 67 @downmix_to_mono 68 @frames_adapter
69 - def process(self, frames, eod=False):
70 71 fftgrain = self.pvoc(frames) 72 self.melenergy_results.append(self.melenergy(fftgrain)) 73 self.block_read += 1 74 return frames, eod
75
76 - def post_process(self):
77 melenergy = self.new_result(data_mode='value', time_mode='framewise') 78 melenergy.parameters = dict(n_filters=self.n_filters, 79 n_coeffs=self.n_coeffs) 80 melenergy.data_object.value = self.melenergy_results 81 self.process_pipe.results.add(melenergy)
82