1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
30 implements(IAnalyzer)
31
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):
50
51 @staticmethod
52 @interfacedoc
55
56 @staticmethod
57 @interfacedoc
60
61 @staticmethod
62 @interfacedoc
65
68
69 @downmix_to_mono
70 @frames_adapter
71 - def process(self, frames, eod=False):
72
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
82
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