source: src/spectral/filterbank.c @ 06cae6c

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

src/spectral/filterbank.c: refactorise filter bank, split mel frequency coefficients to src/spectral/filterbank_mel.c, start bumping license to GPLv3

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