source: src/spectral/filterbank.c @ 7a84b21

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 7a84b21 was 14a299e, checked in by Paul Brossier <piem@piem.org>, 15 years ago

filterbank.c: use base 10 logarithm

  • Property mode set to 100644
File size: 2.5 KB
RevLine 
[88199ce]1/*
[06cae6c]2  Copyright (C) 2007-2009 Paul Brossier <piem@aubio.org>
3                      and Amaury Hazan <ahazan@iua.upf.edu>
[88199ce]4
[06cae6c]5  This file is part of Aubio.
[88199ce]6
[06cae6c]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.
[88199ce]11
[06cae6c]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.
[88199ce]16
[06cae6c]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/>.
[88199ce]19
[06cae6c]20*/
[f918cb9]21
[7c6c806d]22#include "aubio_priv.h"
[6c7d49b]23#include "fvec.h"
24#include "cvec.h"
[32d6958]25#include "spectral/filterbank.h"
[17961b0]26#include "mathutils.h"
[88199ce]27
[b276dee]28#define VERY_SMALL_NUMBER 2e-42
[7c6c806d]29
[8708556]30/** \brief A structure to store a set of n_filters filters of lenghts win_s */
[3b3b03e]31struct aubio_filterbank_t_
32{
33  uint_t win_s;
34  uint_t n_filters;
35  fvec_t *filters;
[7c6c806d]36};
37
[3b3b03e]38aubio_filterbank_t *
39new_aubio_filterbank (uint_t n_filters, uint_t win_s)
40{
[06cae6c]41  /* allocate space for filterbank object */
[3b3b03e]42  aubio_filterbank_t *fb = AUBIO_NEW (aubio_filterbank_t);
43  fb->win_s = win_s;
44  fb->n_filters = n_filters;
[88199ce]45
[06cae6c]46  /* allocate filter tables, an fvec of length win_s and of filter_cnt channel */
[3b3b03e]47  fb->filters = new_fvec (win_s, n_filters);
[88199ce]48
[b276dee]49  return fb;
50}
51
[3b3b03e]52void
53del_aubio_filterbank (aubio_filterbank_t * fb)
54{
55  del_fvec (fb->filters);
56  AUBIO_FREE (fb);
[06cae6c]57}
[95a64c7]58
[3b3b03e]59void
60aubio_filterbank_do (aubio_filterbank_t * f, cvec_t * in, fvec_t * out)
61{
[06cae6c]62  uint_t i, j, fn;
[bc4ba75]63
[06cae6c]64  /* apply filter to all input channel, provided out has enough channels */
[3b3b03e]65  uint_t max_channels = MIN (in->channels, out->channels);
66  uint_t max_filters = MIN (f->n_filters, out->length);
[88199ce]67
[06cae6c]68  /* reset all values in output vector */
[3b3b03e]69  fvec_zeros (out);
[b276dee]70
[06cae6c]71  /* apply filters on all channels */
72  for (i = 0; i < max_channels; i++) {
[b276dee]73
[06cae6c]74    /* for each filter */
[3b3b03e]75    for (fn = 0; fn < max_filters; fn++) {
[88199ce]76
[06cae6c]77      /* for each sample */
[3b3b03e]78      for (j = 0; j < in->length; j++) {
79        out->data[i][fn] += in->norm[i][j] * f->filters->data[fn][j];
[06cae6c]80      }
[8708556]81
[06cae6c]82      /* threshold to VERY_SMALL_NUMBER to avoid log oveflow */
[3b3b03e]83      out->data[i][fn] = MAX (VERY_SMALL_NUMBER, out->data[i][fn]);
[88199ce]84
[06cae6c]85      /* compute logarithm */
[14a299e]86      out->data[i][fn] = LOG10 (out->data[i][fn]);
[06cae6c]87    }
[b276dee]88  }
89
90  return;
[fe28ff3]91}
[17961b0]92
[3b3b03e]93fvec_t *
94aubio_filterbank_get_coeffs (aubio_filterbank_t * f)
95{
[06cae6c]96  return f->filters;
[17961b0]97}
Note: See TracBrowser for help on using the repository browser.