From: Paul Brossier Date: Mon, 15 Apr 2013 19:26:31 +0000 (-0500) Subject: timeside/analyzer/aubio_*.py: use downsample_blocking X-Git-Tag: 0.5.0~115^2~17 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=25d7682ff91ecbfb2cf0f65d86204aaeb3841aa2;p=timeside.git timeside/analyzer/aubio_*.py: use downsample_blocking --- diff --git a/timeside/analyzer/aubio_melenergy.py b/timeside/analyzer/aubio_melenergy.py index 7ea44c8..dc39de0 100644 --- a/timeside/analyzer/aubio_melenergy.py +++ b/timeside/analyzer/aubio_melenergy.py @@ -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 diff --git a/timeside/analyzer/aubio_mfcc.py b/timeside/analyzer/aubio_mfcc.py index 1de81f9..432b257 100644 --- a/timeside/analyzer/aubio_mfcc.py +++ b/timeside/analyzer/aubio_mfcc.py @@ -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 diff --git a/timeside/analyzer/aubio_pitch.py b/timeside/analyzer/aubio_pitch.py index 334c7c1..3beaa04 100644 --- a/timeside/analyzer/aubio_pitch.py +++ b/timeside/analyzer/aubio_pitch.py @@ -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 diff --git a/timeside/analyzer/aubio_temporal.py b/timeside/analyzer/aubio_temporal.py index 16fad9f..34facbf 100644 --- a/timeside/analyzer/aubio_temporal.py +++ b/timeside/analyzer/aubio_temporal.py @@ -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 diff --git a/timeside/analyzer/core.py b/timeside/analyzer/core.py index 1328b0f..7357c32 100644 --- a/timeside/analyzer/core.py +++ b/timeside/analyzer/core.py @@ -20,6 +20,9 @@ # Authors: # Guillaume Pellerin # Paul Brossier + +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 index 0000000..b7c8c61 --- /dev/null +++ b/timeside/analyzer/utils.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# +# Copyright (c) 2013 Paul Brossier + +# 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 . + +# Author: Paul Brossier + +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) + +