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, 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 i, j, l, order = f->order;
54 lsmp_t *a = f->a->data[0];
55 lsmp_t *b = f->b->data[0];
57 for (i = 0; i < in->channels; i++) {
60 for (j = 0; j < in->length; j++) {
62 x[0] = KILL_DENORMAL (in->data[i][j]);
64 for (l = 1; l < order; l++) {
69 in->data[i][j] = y[0];
70 /* store for next sample */
71 for (l = order - 1; l > 0; l--) {
76 /* store for next run */
84 * despite mirroring, end effects destroy both phse and amplitude. the longer
85 * the buffer, the less affected they are.
87 * replacing with zeros clicks.
89 * seems broken for order > 4 (see biquad_do_filtfilt for audible one)
91 void aubio_filter_do_filtfilt(aubio_filter_t * f, fvec_t * in, fvec_t * tmp) {
93 uint_t length = in->length;
94 //uint_t order = f->order;
97 //mir = 2*in->data[i][0];
98 //for (j=1;j<order;j++)
99 //f->x[j] = 0.;//mir - in->data[i][order-j];
100 /* apply filtering */
101 aubio_filter_do(f,in);
103 for (j = 0; j < length; j++)
104 tmp->data[i][length-j-1] = in->data[i][j];
105 /* mirror inverted */
106 //mir = 2*tmp->data[i][0];
107 //for (j=1;j<order;j++)
108 //f->x[j] = 0.;//mir - tmp->data[i][order-j];
109 /* apply filtering on inverted */
110 aubio_filter_do(f,tmp);
112 for (j = 0; j < length; j++)
113 in->data[i][j] = tmp->data[i][length-j-1];
117 aubio_filter_get_feedback (aubio_filter_t * f)
123 aubio_filter_get_feedforward (aubio_filter_t * f)
129 aubio_filter_get_order (aubio_filter_t * f)
135 aubio_filter_get_samplerate (aubio_filter_t * f)
137 return f->samplerate;
141 aubio_filter_set_samplerate (aubio_filter_t * f, uint_t samplerate)
143 f->samplerate = samplerate;
148 new_aubio_filter (uint_t order, uint_t channels)
150 aubio_filter_t *f = AUBIO_NEW (aubio_filter_t);
151 f->x = new_lvec (order, channels);
152 f->y = new_lvec (order, channels);
153 f->a = new_lvec (order, 1);
154 f->b = new_lvec (order, 1);
155 /* by default, samplerate is not set */
158 /* set default to identity */
159 f->a->data[0][1] = 1.;
164 del_aubio_filter (aubio_filter_t * f)