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

Source Code for Module timeside.analyzer.aubio_mfcc

 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 mfcc, pvoc 
29 30 31 -class AubioMfcc(Analyzer):
32 implements(IAnalyzer) 33
34 - def __init__(self):
35 super(AubioMfcc, 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(AubioMfcc, 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.mfcc = mfcc(self.input_blocksize, 48 self.n_filters, 49 self.n_coeffs, 50 samplerate) 51 self.block_read = 0 52 self.mfcc_results = numpy.zeros([self.n_coeffs, ])
53 54 @staticmethod 55 @interfacedoc
56 - def id():
57 return "aubio_mfcc"
58 59 @staticmethod 60 @interfacedoc
61 - def name():
62 return "MFCC (aubio)"
63 64 @staticmethod 65 @interfacedoc
66 - def unit():
67 return ""
68 69 @downmix_to_mono 70 @frames_adapter
71 - def process(self, frames, eod=False):
72 fftgrain = self.pvoc(frames) 73 coeffs = self.mfcc(fftgrain) 74 self.mfcc_results = numpy.vstack((self.mfcc_results, coeffs)) 75 self.block_read += 1 76 return frames, eod
77
78 - def post_process(self):
79 mfcc = self.new_result(data_mode='value', time_mode='framewise') 80 mfcc.parameters = dict(n_filters=self.n_filters, 81 n_coeffs=self.n_coeffs) 82 mfcc.data_object.value = self.mfcc_results 83 self.process_pipe.results.add(mfcc)
84