]> git.parisson.com Git - timeside.git/commitdiff
Refactor : In Irit Monopoly, Implement aubio_pitch as a parent analyzer
authorThomas Fillon <thomas@parisson.com>
Thu, 19 Jun 2014 11:08:18 +0000 (13:08 +0200)
committerThomas Fillon <thomas@parisson.com>
Thu, 19 Jun 2014 11:08:18 +0000 (13:08 +0200)
This also fixes NaN issue in Irit Monopoly

timeside/analyzer/irit_monopoly.py

index 5bd487135200427bfc59c1e80ea30457210ae571..fffd09e2c0a9f6a858b2c1226ecabe2d98fa6b2e 100644 (file)
 # Author: Maxime Le Coz <lecoz@irit.fr>
 from __future__ import absolute_import
 from timeside.analyzer.utils import segmentFromValues
-from timeside.core import implements, interfacedoc
+from timeside.core import implements, interfacedoc, get_processor
 from timeside.analyzer.core import Analyzer
 from timeside.api import IAnalyzer
-from aubio import pitch
 import numpy
 from timeside.analyzer.preprocessors import frames_adapter
 
@@ -36,6 +35,17 @@ class IRITMonopoly(Analyzer):
     """
     implements(IAnalyzer)
 
+    @interfacedoc
+    def __init__(self):
+        super(IRITMonopoly, self).__init__()
+
+        self.parents.append(get_processor('aubio_pitch')())
+
+        # Irit Monopoly parameters
+        self.decisionLen = 1.0
+        self.wLen = 0.1
+        self.wStep = 0.05
+
     @interfacedoc
     def setup(self, channels=None, samplerate=None,
               blocksize=None, totalframes=None):
@@ -43,17 +53,7 @@ class IRITMonopoly(Analyzer):
                                         samplerate,
                                         blocksize,
                                         totalframes)
-        self.aubio_pitch = pitch(
-            "default", self.input_blocksize, self.input_stepsize,
-            samplerate)
-        self.aubio_pitch.set_unit("freq")
-        self.block_read = 0
-        self.pitches = []
-        self.pitch_confidences = []
-        self.decisionLen = 1.0
 
-        self.wLen = 0.1
-        self.wStep = 0.05
         self.input_blocksize = int(self.wLen * samplerate)
         self.input_stepsize = int(self.wStep * samplerate)
 
@@ -77,24 +77,22 @@ class IRITMonopoly(Analyzer):
 
     @frames_adapter
     def process(self, frames, eod=False):
-        # in seconds
-        pf = self.aubio_pitch(frames[0])
-        self.pitches += [pf[0]]
-        self.pitch_confidences += [self.aubio_pitch.get_confidence()]
-        self.block_read += 1
         return frames, eod
 
     def post_process(self):
         '''
 
         '''
+        aubio_res_id = 'aubio_pitch.pitch_confidence'
+        pitch_confidences = self.process_pipe.results[aubio_res_id].data
+
         nb_frameDecision = int(self.decisionLen / self.wStep)
-        epsilon = numpy.spacing(self.pitch_confidences[0])
+        epsilon = numpy.spacing(pitch_confidences[0])
         w = int(nb_frameDecision/2)
 
         is_mono = []
-        for i in range(w, len(self.pitch_confidences) - w, nb_frameDecision):
-            d = self.pitch_confidences[i - w:i + w]
+        for i in range(w, len(pitch_confidences) - w, nb_frameDecision):
+            d = pitch_confidences[i - w:i + w]
             conf_mean = numpy.mean(d)
             conf_var = numpy.var(d + epsilon)
             if self.monoLikelihood(conf_mean, conf_var) > self.polyLikelihood(conf_mean, conf_var):
@@ -106,7 +104,7 @@ class IRITMonopoly(Analyzer):
         conf = self.new_result(data_mode='value', time_mode='framewise')
         conf.id_metadata.id += '.' + 'yin_confidence'
         conf.id_metadata.name += ' ' + 'Yin Confidence'
-        conf.data_object.value = self.pitch_confidences
+        conf.data_object.value = pitch_confidences
 
         self.process_pipe.results.add(conf)