]> git.parisson.com Git - timeside.git/commitdiff
feat(aubio_pitch.py): add blocksize and stepsize as input parameters
authorThomas Fillon <thomas@parisson.com>
Thu, 19 Jun 2014 13:57:12 +0000 (15:57 +0200)
committerThomas Fillon <thomas@parisson.com>
Thu, 19 Jun 2014 13:57:12 +0000 (15:57 +0200)
timeside/analyzer/aubio/aubio_pitch.py

index bcd7d6da26159774d52ed67174661975c0b203ca..378707b964ef9276619985e699d2ab1b830a71dc 100644 (file)
@@ -26,17 +26,19 @@ from timeside.api import IAnalyzer
 from timeside.analyzer.preprocessors import downmix_to_mono, frames_adapter
 from aubio import pitch
 import numpy as np
-
+from timeside.analyzer.utils import nextpow2
 
 class AubioPitch(Analyzer):
 
     """Aubio Pitch estimation analyzer"""
     implements(IAnalyzer)  # TODO check if needed with inheritance
 
-    def __init__(self):
+    def __init__(self, blocksize_s=None, stepsize_s=None):
+
         super(AubioPitch, self).__init__()
-        self.input_blocksize = 2048
-        self.input_stepsize = self.input_blocksize / 2
+
+        self._blocksize_s = blocksize_s
+        self._stepsize_s = stepsize_s
 
     @interfacedoc
     def setup(self, channels=None, samplerate=None,
@@ -45,6 +47,20 @@ class AubioPitch(Analyzer):
                                       samplerate,
                                       blocksize,
                                       totalframes)
+
+
+        # Frame parameters setup
+        if self._blocksize_s:
+            self.input_blocksize = nextpow2(self._blocksize_s * samplerate)
+        else:
+            self.input_blocksize = 2048
+
+        if self._stepsize_s:
+            self.input_stepsize = nextpow2(self._stepsize_s * samplerate)
+        else:
+            self.input_stepsize = self.input_blocksize / 2
+
+        # Aubio Pitch set-up
         self.aubio_pitch = pitch(
             "default", self.input_blocksize, self.input_stepsize,
             samplerate)