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
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
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
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
# Authors:
# Guillaume Pellerin <yomguy at parisson.com>
# Paul Brossier <piem@piem.org>
+
+from utils import *
+
import numpy
numpy_data_types = [
#'float128',
--- /dev/null
+# -*- 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)
+
+