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

Source Code for Module timeside.analyzer.aubio_specdesc

 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 Processor, implements, interfacedoc, FixedSizeInputAdapter 
23  from timeside.analyzer.core import Analyzer 
24  from timeside.api import IAnalyzer 
25  from preprocessors import downmix_to_mono, frames_adapter 
26   
27  from aubio import specdesc, pvoc 
28 29 30 -class AubioSpecdesc(Analyzer):
31 implements(IAnalyzer) 32
33 - def __init__(self):
34 super(AubioSpecdesc, self).__init__() 35 self.input_blocksize = 1024 36 self.input_stepsize = self.input_blocksize / 4
37 38 @interfacedoc
39 - def setup(self, channels=None, samplerate=None, 40 blocksize=None, totalframes=None):
41 super( 42 AubioSpecdesc, 43 self).setup( 44 channels, 45 samplerate, 46 blocksize, 47 totalframes) 48 self.block_read = 0 49 self.pvoc = pvoc(self.input_blocksize, self.input_stepsize) 50 self.methods = [ 51 'default', 'energy', 'hfc', 'complex', 'phase', 'specdiff', 'kl', 52 'mkl', 'specflux', 'centroid', 'slope', 'rolloff', 'spread', 'skewness', 53 'kurtosis', 'decrease'] 54 self.specdesc = {} 55 self.specdesc_results = {} 56 for method in self.methods: 57 self.specdesc[method] = specdesc(method, self.input_blocksize) 58 self.specdesc_results[method] = []
59 60 @staticmethod 61 @interfacedoc
62 - def id():
63 return "aubio_specdesc"
64 65 @staticmethod 66 @interfacedoc
67 - def name():
68 return "Spectral Descriptor (aubio)"
69 70 @staticmethod 71 @interfacedoc
72 - def unit():
73 return ""
74 75 @downmix_to_mono 76 @frames_adapter
77 - def process(self, frames, eod=False):
78 fftgrain = self.pvoc(frames) 79 for method in self.methods: 80 self.specdesc_results[method] += [ 81 self.specdesc[method](fftgrain)[0]] 82 return frames, eod
83
84 - def post_process(self):
85 86 # For each method store results in container 87 for method in self.methods: 88 res_specdesc = self.new_result(data_mode='value', 89 time_mode='framewise') 90 # Set metadata 91 res_specdesc.id_metadata.id += '.' + method 92 res_specdesc.id_metadata.name = ' ' + method 93 res_specdesc.data_object.value = self.specdesc_results[method] 94 95 self.process_pipe.results.add(res_specdesc)
96