2 Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
4 This file is part of aubio.
6 aubio is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 aubio is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with aubio. If not, see <http://www.gnu.org/licenses/>.
22 /* Requires lsmp_t to be long or double. float will NOT give reliable
25 #include "aubio_priv.h"
28 #include "mathutils.h"
29 #include "temporal/filter.h"
31 struct _aubio_filter_t
42 aubio_filter_do_outplace (aubio_filter_t * f, const fvec_t * in, fvec_t * out)
45 aubio_filter_do (f, out);
49 aubio_filter_do (aubio_filter_t * f, fvec_t * in)
51 uint_t j, l, order = f->order;
52 lsmp_t *x = f->x->data;
53 lsmp_t *y = f->y->data;
54 lsmp_t *a = f->a->data;
55 lsmp_t *b = f->b->data;
57 for (j = 0; j < in->length; j++) {
59 x[0] = KILL_DENORMAL (in->data[j]);
61 for (l = 1; l < order; l++) {
67 /* store for next sample */
68 for (l = order - 1; l > 0; l--) {
75 /* The rough way: reset memory of filter between each run to avoid end effects. */
77 aubio_filter_do_filtfilt (aubio_filter_t * f, fvec_t * in, fvec_t * tmp)
80 uint_t length = in->length;
82 aubio_filter_do (f, in);
83 aubio_filter_do_reset (f);
85 for (j = 0; j < length; j++)
86 tmp->data[length - j - 1] = in->data[j];
87 /* apply filtering on mirrored */
88 aubio_filter_do (f, tmp);
89 aubio_filter_do_reset (f);
91 for (j = 0; j < length; j++)
92 in->data[j] = tmp->data[length - j - 1];
96 aubio_filter_get_feedback (const aubio_filter_t * f)
102 aubio_filter_get_feedforward (const aubio_filter_t * f)
108 aubio_filter_get_order (const aubio_filter_t * f)
114 aubio_filter_get_samplerate (const aubio_filter_t * f)
116 return f->samplerate;
120 aubio_filter_set_samplerate (aubio_filter_t * f, uint_t samplerate)
122 f->samplerate = samplerate;
127 aubio_filter_do_reset (aubio_filter_t * f)
134 new_aubio_filter (uint_t order)
136 aubio_filter_t *f = AUBIO_NEW (aubio_filter_t);
137 if ((sint_t)order < 1) {
141 f->x = new_lvec (order);
142 f->y = new_lvec (order);
143 f->a = new_lvec (order);
144 f->b = new_lvec (order);
145 /* by default, samplerate is not set */
148 /* set default to identity */
155 del_aubio_filter (aubio_filter_t * f)