2 Copyright (C) 2003 Paul Brossier
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 /* Requires lsmp_t to be long or double. float will NOT give reliable
24 #include "aubio_priv.h"
26 #include "mathutils.h"
29 struct _aubio_filter_t {
38 void aubio_filter_do(aubio_filter_t * f, fvec_t * in) {
39 uint_t i,j,l, order = f->order;
44 i=0;//for (i=0;i<in->channels;i++) {
45 for (j = 0; j < in->length; j++) {
47 //AUBIO_DBG("befor %f\t", in->data[i][j]);
48 x[0] = in->data[i][j];
50 for (l=1;l<order; l++) {
53 } /* + 1e-37; for denormal ? */
55 in->data[i][j] = y[0];
56 //AUBIO_DBG("after %f\n", in->data[i][j]);
57 /* store states for next sample */
58 for (l=order-1; l>0; l--){
63 /* store states for next buffer */
69 void aubio_filter_do_outplace(aubio_filter_t * f, fvec_t * in, fvec_t * out) {
70 uint_t i,j,l, order = f->order;
76 i=0; // works in mono only !!!
77 //for (i=0;i<in->channels;i++) {
78 for (j = 0; j < in->length; j++) {
80 x[0] = in->data[i][j];
82 for (l=1;l<order; l++) {
88 out->data[i][j] = y[0];
89 /* store for next sample */
90 for (l=order-1; l>0; l--){
95 /* store for next run */
103 * despite mirroring, end effects destroy both phse and amplitude. the longer
104 * the buffer, the less affected they are.
106 * replacing with zeros clicks.
108 * seems broken for order > 4 (see biquad_do_filtfilt for audible one)
110 void aubio_filter_do_filtfilt(aubio_filter_t * f, fvec_t * in, fvec_t * tmp) {
112 uint_t length = in->length;
113 //uint_t order = f->order;
116 //mir = 2*in->data[i][0];
117 //for (j=1;j<order;j++)
118 //f->x[j] = 0.;//mir - in->data[i][order-j];
119 /* apply filtering */
120 aubio_filter_do(f,in);
122 for (j = 0; j < length; j++)
123 tmp->data[i][length-j-1] = in->data[i][j];
124 /* mirror inverted */
125 //mir = 2*tmp->data[i][0];
126 //for (j=1;j<order;j++)
127 //f->x[j] = 0.;//mir - tmp->data[i][order-j];
128 /* apply filtering on inverted */
129 aubio_filter_do(f,tmp);
131 for (j = 0; j < length; j++)
132 in->data[i][j] = tmp->data[i][length-j-1];
136 aubio_filter_t * new_aubio_adsgn_filter(uint_t samplerate) {
137 aubio_filter_t * f = new_aubio_filter(samplerate, 7);
141 /* for now, 44100, adsgn */
142 a[0] = 1.00000000000000000000000000000000000000000000000000000;
143 a[1] = -4.01957618111583236952810693765059113502502441406250000;
144 a[2] = 6.18940644292069386267485242569819092750549316406250000;
145 a[3] = -4.45319890354411640487342083360999822616577148437500000;
146 a[4] = 1.42084294962187751565352300531230866909027099609375000;
147 a[5] = -0.14182547383030480458998567883099894970655441284179688;
148 a[6] = 0.00435117723349511334451911181986361043527722358703613;
149 b[0] = 0.25574112520425740235907596797915175557136535644531250;
150 b[1] = -0.51148225040851391653973223583307117223739624023437500;
151 b[2] = -0.25574112520426162120656954357400536537170410156250000;
152 b[3] = 1.02296450081703405032840237254276871681213378906250000;
153 b[4] = -0.25574112520426051098354491841746494174003601074218750;
154 b[5] = -0.51148225040851369449512731080176308751106262207031250;
155 b[6] = 0.25574112520425729133677350546349771320819854736328125;
156 /* DBG: filter coeffs at creation time */
158 for (l=0; l<f->order; l++){
159 AUBIO_DBG("a[%d]=\t%1.16f\tb[%d]=\t%1.16f\n",l,a[l],l,b[l]);
167 aubio_filter_t * new_aubio_cdsgn_filter(uint_t samplerate) {
168 aubio_filter_t * f = new_aubio_filter(samplerate, 5);
172 /* for now, 44100, cdsgn */
173 a[0] = 1.000000000000000000000000000000000000000000000000000000000000;
174 a[1] = -2.134674963687040794013682898366823792457580566406250000000000;
175 a[2] = 1.279333533236063358273781886964570730924606323242187500000000;
176 a[3] = -0.149559846089396208945743182994192466139793395996093750000000;
177 a[4] = 0.004908700174624848651394604104325480875559151172637939453125;
178 b[0] = 0.217008561949218803377448239189106971025466918945312500000000;
179 b[1] = -0.000000000000000222044604925031308084726333618164062500000000;
180 b[2] = -0.434017123898438272888711253472138196229934692382812500000000;
181 b[3] = 0.000000000000000402455846426619245903566479682922363281250000;
182 b[4] = 0.217008561949218969910901932962588034570217132568359375000000;
183 /* DBG: filter coeffs at creation time */
185 for (l=0; l<f->order; l++){
186 AUBIO_DBG("a[%d]=\t%1.16f\tb[%d]=\t%1.16f\n",l,a[l],l,b[l]);
194 aubio_filter_t * new_aubio_filter(uint_t samplerate, uint_t order) {
195 aubio_filter_t * f = AUBIO_NEW(aubio_filter_t);
202 a = AUBIO_ARRAY(lsmp_t,f->order);
203 b = AUBIO_ARRAY(lsmp_t,f->order);
204 x = AUBIO_ARRAY(lsmp_t,f->order);
205 y = AUBIO_ARRAY(lsmp_t,f->order);
206 /* initial states to zeros */
207 for (l=0; l<f->order; l++){
218 void del_aubio_filter(aubio_filter_t * f) {