]> git.parisson.com Git - timeside.git/commitdiff
timeside/analyzer/aubio_*.py: use downsample_blocking
authorPaul Brossier <piem@piem.org>
Mon, 15 Apr 2013 19:26:31 +0000 (14:26 -0500)
committerPaul Brossier <piem@piem.org>
Mon, 15 Apr 2013 19:26:31 +0000 (14:26 -0500)
timeside/analyzer/aubio_melenergy.py
timeside/analyzer/aubio_mfcc.py
timeside/analyzer/aubio_pitch.py
timeside/analyzer/aubio_temporal.py
timeside/analyzer/core.py
timeside/analyzer/utils.py [new file with mode: 0644]

index 7ea44c82e51063d60424a34bf7d7a1ddda07e63b..dc39de03a5ae006547770420b790e26735777c7a 100644 (file)
@@ -53,13 +53,9 @@ class AubioMelEnergy(Processor):
         return "Mel Energy analysis (aubio)"
 
     def process(self, frames, eod=False):
-        i = 0
-        while i < frames.shape[0]:
-            downmixed_samples = frames[i:i+self.hop_s, :].sum(axis = -1)
-            time = self.block_read * self.hop_s * 1. / self.samplerate()
-            fftgrain = self.pvoc(downmixed_samples)
+        for samples in downsample_blocking(frames, self.hop_s):
+            fftgrain = self.pvoc(samples)
             self.melenergy_results = numpy.vstack( [ self.melenergy_results, self.melenergy(fftgrain) ])
-            i += self.hop_s
             self.block_read += 1
         return frames, eod
 
index 1de81f9558852f388958cedc454433af5b4c706b..432b2576ecdd52f5e034d9437f3bd2d17dcb6aac 100644 (file)
@@ -54,14 +54,11 @@ class AubioMfcc(Processor):
         return "MFCC analysis (aubio)"
 
     def process(self, frames, eod=False):
-        i = 0
-        while i < frames.shape[0]:
-            downmixed_samples = frames[i:i+self.hop_s, :].sum(axis = -1)
-            time = self.block_read * self.hop_s * 1. / self.samplerate()
-            fftgrain = self.pvoc(downmixed_samples)
+        for samples in downsample_blocking(frames, self.hop_s):
+            #time = self.block_read * self.hop_s * 1. / self.samplerate()
+            fftgrain = self.pvoc(samples)
             coeffs = self.mfcc(fftgrain)
             self.mfcc_results = numpy.vstack((self.mfcc_results, coeffs))
-            i += self.hop_s
             self.block_read += 1
         return frames, eod
 
index 334c7c1996182a530aa5b5767617c4effdf6d333..3beaa044ef5c9ce1bd0c1df83d6b6878f01272e1 100644 (file)
@@ -56,12 +56,9 @@ class AubioPitch(Processor):
         return "pitch values"
 
     def process(self, frames, eod=False):
-        i = 0
-        while i < frames.shape[0]:
-            downmixed = frames[i:i+self.hop_s, :].sum(axis = -1)
+        for samples in downsample_blocking(frames, self.hop_s):
             #time = self.block_read * self.hop_s * 1. / self.samplerate()
-            self.pitches += [self.p(downmixed)[0]]
-            i += self.hop_s
+            self.pitches += [self.p(samples)[0]]
             self.block_read += 1
         return frames, eod
 
index 16fad9f3d3d8789e494d35e2294a4953ccacf24d..34facbf5740b2ba9fc87c443cb15ce34e2c9c7c1 100644 (file)
@@ -57,14 +57,11 @@ class AubioTemporal(Processor):
         return "%s %s" % (str(self.value), unit())
 
     def process(self, frames, eod=False):
-        i = 0
-        while i < frames.shape[0]:
-            downmixed = frames[i:i+self.hop_s, :].sum(axis = -1)
-            if self.o(downmixed):
+        for samples in downsample_blocking(frames, self.hop_s):
+            if self.o(samples):
                 self.onsets += [self.o.get_last_s()]
-            if self.t(downmixed):
+            if self.t(samples):
                 self.beats += [self.t.get_last_s()]
-            i += self.hop_s
             self.block_read += 1
         return frames, eod
 
index 1328b0f630dc70fed5315951ecd13f55ec349cd7..7357c323b2c94b014c70f0aab1c181bf39f8e3c0 100644 (file)
@@ -20,6 +20,9 @@
 # Authors:
 #   Guillaume Pellerin <yomguy at parisson.com>
 #   Paul Brossier <piem@piem.org>
+
+from utils import *
+
 import numpy
 numpy_data_types = [
     #'float128',
diff --git a/timeside/analyzer/utils.py b/timeside/analyzer/utils.py
new file mode 100644 (file)
index 0000000..b7c8c61
--- /dev/null
@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2013 Paul Brossier <piem@piem.org>
+
+# This file is part of TimeSide.
+
+# TimeSide is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+
+# TimeSide is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with TimeSide.  If not, see <http://www.gnu.org/licenses/>.
+
+# Author: Paul Brossier <piem@piem.org>
+
+import numpy
+
+def downsample_blocking(frames, hop_s, dtype='float32'):
+    # downmixing to one channel
+    if len(frames.shape) != 1:
+        downsampled = frames.sum(axis = -1) / frames.shape[-1]
+    else:
+        downsampled = frames
+    # zero padding to have a multiple of hop_s
+    if downsampled.shape[0] % hop_s != 0:
+        pad_length = hop_s + downsampled.shape[0] / hop_s * hop_s - downsampled.shape[0]
+        downsampled = numpy.hstack([downsampled, numpy.zeros(pad_length, dtype = dtype)])
+    # blocking
+    return downsampled.reshape(downsampled.shape[0] / hop_s, hop_s)
+
+