From 8e731bee1d70cafc41f8d529e5eddf740aa30561 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Mon, 15 Apr 2013 14:26:31 -0500 Subject: [PATCH] timeside/analyzer/aubio_*.py: use downsample_blocking --- timeside/analyzer/utils.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 timeside/analyzer/utils.py 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) + + -- 2.39.5