2 Copyright (C) 2007-2009 Paul Brossier <piem@aubio.org>
3 and Amaury Hazan <ahazan@iua.upf.edu>
5 This file is part of Aubio.
7 Aubio is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 Aubio is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Aubio. If not, see <http://www.gnu.org/licenses/>.
22 #include "aubio_priv.h"
25 #include "spectral/filterbank.h"
26 #include "mathutils.h"
28 #define VERY_SMALL_NUMBER 2e-42
30 /** \brief A structure to store a set of n_filters filters of lenghts win_s */
31 struct aubio_filterbank_t_
39 new_aubio_filterbank (uint_t n_filters, uint_t win_s)
41 /* allocate space for filterbank object */
42 aubio_filterbank_t *fb = AUBIO_NEW (aubio_filterbank_t);
44 fb->n_filters = n_filters;
46 /* allocate filter tables, an fvec of length win_s and of filter_cnt channel */
47 fb->filters = new_fvec (win_s / 2 + 1, n_filters);
53 del_aubio_filterbank (aubio_filterbank_t * fb)
55 del_fvec (fb->filters);
60 aubio_filterbank_do (aubio_filterbank_t * f, cvec_t * in, fvec_t * out)
64 /* apply filter to all input channel, provided out has enough channels */
65 uint_t max_channels = MIN (in->channels, out->channels);
66 uint_t max_filters = MIN (f->n_filters, out->length);
68 /* reset all values in output vector */
71 /* apply filters on all channels */
72 for (i = 0; i < max_channels; i++) {
75 for (fn = 0; fn < max_filters; fn++) {
78 for (j = 0; j < in->length; j++) {
79 out->data[i][fn] += in->norm[i][j] * f->filters->data[fn][j];
82 /* threshold to VERY_SMALL_NUMBER to avoid log oveflow */
83 out->data[i][fn] = MAX (VERY_SMALL_NUMBER, out->data[i][fn]);
85 /* compute logarithm */
86 out->data[i][fn] = LOG10 (out->data[i][fn]);
94 aubio_filterbank_get_coeffs (aubio_filterbank_t * f)