source: src/spectral/filterbank.c

Last change on this file was 117465d, checked in by Paul Brossier <piem@piem.org>, 5 years ago

[filterbank] fix get_power

  • Property mode set to 100644
File size: 3.0 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"
[d95ff38]24#include "fmat.h"
[6c7d49b]25#include "cvec.h"
[0e30a12]26#include "vecutils.h"
[32d6958]27#include "spectral/filterbank.h"
[17961b0]28#include "mathutils.h"
[88199ce]29
[8708556]30/** \brief A structure to store a set of n_filters filters of lenghts win_s */
[e6c11e3]31struct _aubio_filterbank_t
[3b3b03e]32{
33  uint_t win_s;
34  uint_t n_filters;
[d95ff38]35  fmat_t *filters;
[0e30a12]36  smpl_t norm;
37  smpl_t power;
[7c6c806d]38};
39
[3b3b03e]40aubio_filterbank_t *
41new_aubio_filterbank (uint_t n_filters, uint_t win_s)
42{
[06cae6c]43  /* allocate space for filterbank object */
[3b3b03e]44  aubio_filterbank_t *fb = AUBIO_NEW (aubio_filterbank_t);
[eda95c9]45
46  if ((sint_t)n_filters <= 0) {
47    AUBIO_ERR("filterbank: n_filters should be > 0, got %d\n", n_filters);
48    goto fail;
49  }
50  if ((sint_t)win_s <= 0) {
51    AUBIO_ERR("filterbank: win_s should be > 0, got %d\n", win_s);
52    goto fail;
53  }
[3b3b03e]54  fb->win_s = win_s;
55  fb->n_filters = n_filters;
[88199ce]56
[d95ff38]57  /* allocate filter tables, a matrix of length win_s and of height n_filters */
[4ed0ed1]58  fb->filters = new_fmat (n_filters, win_s / 2 + 1);
[88199ce]59
[0e30a12]60  fb->norm = 1;
61
62  fb->power = 1;
63
[b276dee]64  return fb;
[eda95c9]65fail:
66  AUBIO_FREE (fb);
67  return NULL;
[b276dee]68}
69
[3b3b03e]70void
71del_aubio_filterbank (aubio_filterbank_t * fb)
72{
[d95ff38]73  del_fmat (fb->filters);
[3b3b03e]74  AUBIO_FREE (fb);
[06cae6c]75}
[95a64c7]76
[3b3b03e]77void
[feb694b]78aubio_filterbank_do (aubio_filterbank_t * f, const cvec_t * in, fvec_t * out)
[3b3b03e]79{
[06cae6c]80  /* apply filter to all input channel, provided out has enough channels */
[fc2d7fb]81  //uint_t max_filters = MIN (f->n_filters, out->length);
82  //uint_t max_length = MIN (in->length, f->filters->length);
83
84  // view cvec->norm as fvec->data
85  fvec_t tmp;
86  tmp.length = in->length;
87  tmp.data = in->norm;
88
[0e30a12]89  if (f->power != 1.) fvec_pow(&tmp, f->power);
90
[fc2d7fb]91  fmat_vecmul(f->filters, &tmp, out);
[b276dee]92
93  return;
[fe28ff3]94}
[17961b0]95
[d95ff38]96fmat_t *
[feb694b]97aubio_filterbank_get_coeffs (const aubio_filterbank_t * f)
[3b3b03e]98{
[06cae6c]99  return f->filters;
[17961b0]100}
[33916b8]101
102uint_t
[feb694b]103aubio_filterbank_set_coeffs (aubio_filterbank_t * f, const fmat_t * filter_coeffs)
[33916b8]104{
[d95ff38]105  fmat_copy(filter_coeffs, f->filters);
[33916b8]106  return 0;
107}
[0e30a12]108
109uint_t
110aubio_filterbank_set_norm (aubio_filterbank_t *f, smpl_t norm)
111{
112  if (norm != 0 && norm != 1) return AUBIO_FAIL;
113  f->norm = norm;
114  return AUBIO_OK;
115}
116
117smpl_t
118aubio_filterbank_get_norm (aubio_filterbank_t *f)
119{
120  return f->norm;
121}
122
123uint_t
124aubio_filterbank_set_power (aubio_filterbank_t *f, smpl_t power)
125{
126  f->power = power;
127  return AUBIO_OK;
128}
129
130smpl_t
131aubio_filterbank_get_power (aubio_filterbank_t *f)
132{
[117465d]133  return f->power;
[0e30a12]134}
Note: See TracBrowser for help on using the repository browser.