Changeset 212da72 for src/temporal/filter.c
- Timestamp:
- Dec 3, 2007, 10:57:52 AM (17 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 45f1f06
- Parents:
- dddf1f5 (diff), 6913434 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/temporal/filter.c
rdddf1f5 r212da72 24 24 #include "aubio_priv.h" 25 25 #include "fvec.h" 26 #include "lvec.h" 26 27 #include "mathutils.h" 27 28 #include "temporal/filter.h" 29 #include "temporal/filter_priv.h" 28 30 29 struct _aubio_filter_t {30 uint_t order;31 lsmp_t * a;32 lsmp_t * b;33 lsmp_t * y;34 lsmp_t * x;35 };36 37 /* bug: mono only */38 31 void aubio_filter_do(aubio_filter_t * f, fvec_t * in) { 39 uint_t i,j,l, order = f->order; 40 lsmp_t *x = f->x; 41 lsmp_t *y = f->y; 42 lsmp_t *a = f->a; 43 lsmp_t *b = f->b; 44 i=0;//for (i=0;i<in->channels;i++) { 45 for (j = 0; j < in->length; j++) { 46 /* new input */ 47 //AUBIO_DBG("befor %f\t", in->data[i][j]); 48 x[0] = in->data[i][j]; 49 y[0] = b[0] * x[0]; 50 for (l=1;l<order; l++) { 51 y[0] += b[l] * x[l]; 52 y[0] -= a[l] * y[l]; 53 } /* + 1e-37; for denormal ? */ 54 /* new output */ 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--){ 59 x[l] = x[l-1]; 60 y[l] = y[l-1]; 61 } 62 } 63 /* store states for next buffer */ 64 f->x = x; 65 f->y = y; 66 //} 32 aubio_filter_do_outplace(f, in, in); 67 33 } 68 34 69 35 void aubio_filter_do_outplace(aubio_filter_t * f, fvec_t * in, fvec_t * out) { 70 36 uint_t i,j,l, order = f->order; 71 lsmp_t *x = f->x;72 lsmp_t *y = f->y;73 lsmp_t *a = f->a ;74 lsmp_t *b = f->b ;37 lsmp_t *x; 38 lsmp_t *y; 39 lsmp_t *a = f->a->data[0]; 40 lsmp_t *b = f->b->data[0]; 75 41 76 i=0; // works in mono only !!! 77 //for (i=0;i<in->channels;i++) { 78 for (j = 0; j < in->length; j++) { 79 /* new input */ 80 x[0] = in->data[i][j]; 81 y[0] = b[0] * x[0]; 82 for (l=1;l<order; l++) { 83 y[0] += b[l] * x[l]; 84 y[0] -= a[l] * y[l]; 42 for (i = 0; i < in->channels; i++) { 43 x = f->x->data[i]; 44 y = f->y->data[i]; 45 for (j = 0; j < in->length; j++) { 46 /* new input */ 47 if (ISDENORMAL(in->data[i][j])) { 48 x[0] = y[0] = 0.; 49 } else { 50 x[0] = in->data[i][j]; 51 y[0] = b[0] * x[0]; 52 for (l=1;l<order; l++) { 53 y[0] += b[l] * x[l]; 54 y[0] -= a[l] * y[l]; 55 } 56 } 57 /* new output */ 58 out->data[i][j] = y[0]; 59 /* store for next sample */ 60 for (l=order-1; l>0; l--){ 61 x[l] = x[l-1]; 62 y[l] = y[l-1]; 63 } 85 64 } 86 // + 1e-37; 87 /* new output */ 88 out->data[i][j] = y[0]; 89 /* store for next sample */ 90 for (l=order-1; l>0; l--){ 91 x[l] = x[l-1]; 92 y[l] = y[l-1]; 93 } 65 /* store for next run */ 66 f->x->data[i] = x; 67 f->y->data[i] = y; 94 68 } 95 /* store for next run */96 f->x = x;97 f->y = y;98 //}99 69 } 100 70 … … 133 103 } 134 104 135 136 aubio_filter_t * new_aubio_adsgn_filter(uint_t samplerate) { 137 aubio_filter_t * f = new_aubio_filter(samplerate, 7); 138 lsmp_t * a = f->a; 139 lsmp_t * b = f->b; 140 /* uint_t l; */ 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 */ 157 /* 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]); 160 } 161 */ 162 f->a = a; 163 f->b = b; 164 return f; 165 } 166 167 aubio_filter_t * new_aubio_cdsgn_filter(uint_t samplerate) { 168 aubio_filter_t * f = new_aubio_filter(samplerate, 5); 169 lsmp_t * a = f->a; 170 lsmp_t * b = f->b; 171 /* uint_t l; */ 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 */ 184 /* 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]); 187 } 188 */ 189 f->a = a; 190 f->b = b; 191 return f; 192 } 193 194 aubio_filter_t * new_aubio_filter(uint_t samplerate UNUSED, uint_t order) { 105 aubio_filter_t * new_aubio_filter(uint_t samplerate UNUSED, uint_t order, uint_t channels) { 195 106 aubio_filter_t * f = AUBIO_NEW(aubio_filter_t); 196 lsmp_t * x = f->x;197 lsmp_t * y = f->y;198 lsmp_t * a = f->a;199 lsmp_t * b = f->b;200 uint_t l;107 f->x = new_lvec(order, channels); 108 f->y = new_lvec(order, channels); 109 f->a = new_lvec(order, 1); 110 f->b = new_lvec(order, 1); 111 f->a->data[0][1] = 1.; 201 112 f->order = order; 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++){208 x[l] = 0.;209 y[l] = 0.;210 }211 f->x = x;212 f->y = y;213 f->a = a;214 f->b = b;215 113 return f; 216 114 }
Note: See TracChangeset
for help on using the changeset viewer.