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

Source Code for Module timeside.analyzer.aubio_pitch

 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  from aubio import pitch 
27 28 29 -class AubioPitch(Analyzer):
30 implements(IAnalyzer) # TODO check if needed with inheritance 31
32 - def __init__(self):
33 super(AubioPitch, 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(AubioPitch, self).setup(channels, 41 samplerate, 42 blocksize, 43 totalframes) 44 self.aubio_pitch = pitch("default", self.input_blocksize, self.input_stepsize, 45 samplerate) 46 self.aubio_pitch.set_unit("freq") 47 self.block_read = 0 48 self.pitches = [] 49 self.pitch_confidences = []
50 51 @staticmethod 52 @interfacedoc
53 - def id():
54 return "aubio_pitch"
55 56 @staticmethod 57 @interfacedoc
58 - def name():
59 return "f0 (aubio)"
60 61 @staticmethod 62 @interfacedoc
63 - def unit():
64 return "Hz"
65
66 - def __str__(self):
67 return "pitch values"
68 69 @downmix_to_mono 70 @frames_adapter
71 - def process(self, frames, eod=False):
72 #time = self.block_read * self.input_stepsize * 1. / self.samplerate() 73 self.pitches += [self.aubio_pitch(frames)[0]] 74 self.pitch_confidences += [self.aubio_pitch.get_confidence()] 75 self.block_read += 1 76 return frames, eod
77
78 - def post_process(self):
79 pitch = self.new_result(data_mode='value', time_mode='framewise') 80 81 # parameters : None # TODO check with Piem "default" and "freq" in 82 # setup 83 84 pitch.id_metadata.id += '.' + "pitch" 85 pitch.id_metadata.name += ' ' + "pitch" 86 pitch.id_metadata.unit = "Hz" 87 pitch.data_object.value = self.pitches 88 self.process_pipe.results.add(pitch) 89 90 pitch_confidence = self.new_result(data_mode='value', time_mode='framewise') 91 pitch_confidence.id_metadata.id += '.' + "pitch_confidence" 92 pitch_confidence.id_metadata.name += ' ' + "pitch confidence" 93 pitch_confidence.id_metadata.unit = None 94 pitch_confidence.data_object.value = self.pitch_confidences 95 self.process_pipe.results.add(pitch_confidence)
96