source: src/spectral/filterbank.c @ ed73bc6

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

src/spectral/filterbank.c: make sure we don't read outside of boundaries

  • Property mode set to 100644
File size: 2.4 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
[1c2e186]5  This file is part of aubio.
[88199ce]6
[1c2e186]7  aubio is free software: you can redistribute it and/or modify
[06cae6c]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
[1c2e186]12  aubio is distributed in the hope that it will be useful,
[06cae6c]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
[1c2e186]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
[8708556]28/** \brief A structure to store a set of n_filters filters of lenghts win_s */
[e6c11e3]29struct _aubio_filterbank_t
[3b3b03e]30{
31  uint_t win_s;
32  uint_t n_filters;
33  fvec_t *filters;
[7c6c806d]34};
35
[3b3b03e]36aubio_filterbank_t *
37new_aubio_filterbank (uint_t n_filters, uint_t win_s)
38{
[06cae6c]39  /* allocate space for filterbank object */
[3b3b03e]40  aubio_filterbank_t *fb = AUBIO_NEW (aubio_filterbank_t);
41  fb->win_s = win_s;
42  fb->n_filters = n_filters;
[88199ce]43
[06cae6c]44  /* allocate filter tables, an fvec of length win_s and of filter_cnt channel */
[2062e48]45  fb->filters = new_fvec (win_s / 2 + 1, n_filters);
[88199ce]46
[b276dee]47  return fb;
48}
49
[3b3b03e]50void
51del_aubio_filterbank (aubio_filterbank_t * fb)
52{
53  del_fvec (fb->filters);
54  AUBIO_FREE (fb);
[06cae6c]55}
[95a64c7]56
[3b3b03e]57void
58aubio_filterbank_do (aubio_filterbank_t * f, cvec_t * in, fvec_t * out)
59{
[06cae6c]60  uint_t i, j, fn;
[bc4ba75]61
[06cae6c]62  /* apply filter to all input channel, provided out has enough channels */
[3b3b03e]63  uint_t max_channels = MIN (in->channels, out->channels);
64  uint_t max_filters = MIN (f->n_filters, out->length);
[8fe9c10]65  uint_t max_length = MIN (in->length, f->filters->length);
[88199ce]66
[06cae6c]67  /* reset all values in output vector */
[3b3b03e]68  fvec_zeros (out);
[b276dee]69
[06cae6c]70  /* apply filters on all channels */
71  for (i = 0; i < max_channels; i++) {
[b276dee]72
[06cae6c]73    /* for each filter */
[3b3b03e]74    for (fn = 0; fn < max_filters; fn++) {
[88199ce]75
[06cae6c]76      /* for each sample */
[8fe9c10]77      for (j = 0; j < max_length; j++) {
[3b3b03e]78        out->data[i][fn] += in->norm[i][j] * f->filters->data[fn][j];
[06cae6c]79      }
80    }
[b276dee]81  }
82
83  return;
[fe28ff3]84}
[17961b0]85
[3b3b03e]86fvec_t *
87aubio_filterbank_get_coeffs (aubio_filterbank_t * f)
88{
[06cae6c]89  return f->filters;
[17961b0]90}
[33916b8]91
92uint_t
93aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fvec_t * filters)
94{
95  fvec_copy(filters, f->filters);
96  return 0;
97}
Note: See TracBrowser for help on using the repository browser.