From a7667ceb3c80615a37074899e5f62ec7251c4ba2 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sat, 1 Dec 2007 22:59:25 +0100 Subject: [PATCH] filter.c: add denormal, make multichannel using lvecs, update adsgn, cdsgn, pitchdetection --- src/pitch/pitchdetection.c | 4 +- src/temporal/adesign.c | 12 ++-- src/temporal/adesign.h | 2 +- src/temporal/cdesign.c | 12 ++-- src/temporal/cdesign.h | 2 +- src/temporal/filter.c | 110 +++++++++++++------------------------ src/temporal/filter.h | 3 +- src/temporal/filter_priv.h | 9 +-- swig/aubio.i | 7 +-- 9 files changed, 63 insertions(+), 98 deletions(-) diff --git a/src/pitch/pitchdetection.c b/src/pitch/pitchdetection.c index 5cc2985a..04e17faf 100644 --- a/src/pitch/pitchdetection.c +++ b/src/pitch/pitchdetection.c @@ -21,7 +21,7 @@ #include "cvec.h" #include "spectral/phasevoc.h" #include "mathutils.h" -#include "temporal/filter.h" +#include "temporal/cdesign.h" #include "pitch/pitchmcomb.h" #include "pitch/pitchyin.h" #include "pitch/pitchfcomb.h" @@ -102,7 +102,7 @@ aubio_pitchdetection_t * new_aubio_pitchdetection(uint_t bufsize, p->pv = new_aubio_pvoc(bufsize, hopsize, channels); p->fftgrain = new_cvec(bufsize, channels); p->mcomb = new_aubio_pitchmcomb(bufsize,hopsize,channels,samplerate); - p->filter = new_aubio_cdsgn_filter(samplerate); + p->filter = new_aubio_cdsgn_filter(samplerate, channels); p->callback = aubio_pitchdetection_mcomb; break; case aubio_pitch_fcomb: diff --git a/src/temporal/adesign.c b/src/temporal/adesign.c index a06cddae..8b6fd82d 100644 --- a/src/temporal/adesign.c +++ b/src/temporal/adesign.c @@ -25,10 +25,10 @@ #include "temporal/filter_priv.h" #include "temporal/adesign.h" -aubio_filter_t * new_aubio_adsgn_filter(uint_t samplerate) { - aubio_filter_t * f = new_aubio_filter(samplerate, 7); - lsmp_t * a = f->a; - lsmp_t * b = f->b; +aubio_filter_t * new_aubio_adsgn_filter(uint_t samplerate, uint_t channels) { + aubio_filter_t * f = new_aubio_filter(samplerate, 7, channels); + lsmp_t * a = f->a->data[0]; + lsmp_t * b = f->b->data[0]; /* uint_t l; */ /* for now, 44100, adsgn */ a[0] = 1.00000000000000000000000000000000000000000000000000000; @@ -51,8 +51,8 @@ aubio_filter_t * new_aubio_adsgn_filter(uint_t samplerate) { AUBIO_DBG("a[%d]=\t%1.16f\tb[%d]=\t%1.16f\n",l,a[l],l,b[l]); } */ - f->a = a; - f->b = b; + f->a->data[0] = a; + f->b->data[0] = b; return f; } diff --git a/src/temporal/adesign.h b/src/temporal/adesign.h index 2d8150b8..910d6f7e 100644 --- a/src/temporal/adesign.h +++ b/src/temporal/adesign.h @@ -22,7 +22,7 @@ \param samplerate sampling-rate of the signal to filter */ -aubio_filter_t * new_aubio_adsgn_filter(uint_t samplerate); +aubio_filter_t * new_aubio_adsgn_filter(uint_t samplerate, uint_t channels); #define aubio_adsgn_filter_do aubio_filter_do #define del_aubio_adsgn_filter del_aubio_filter diff --git a/src/temporal/cdesign.c b/src/temporal/cdesign.c index 84d89edf..7f303ac1 100644 --- a/src/temporal/cdesign.c +++ b/src/temporal/cdesign.c @@ -25,10 +25,10 @@ #include "temporal/filter_priv.h" #include "temporal/adesign.h" -aubio_filter_t * new_aubio_cdsgn_filter(uint_t samplerate) { - aubio_filter_t * f = new_aubio_filter(samplerate, 5); - lsmp_t * a = f->a; - lsmp_t * b = f->b; +aubio_filter_t * new_aubio_cdsgn_filter(uint_t samplerate, uint_t channels) { + aubio_filter_t * f = new_aubio_filter(samplerate, 5, channels); + lsmp_t * a = f->a->data[0]; + lsmp_t * b = f->b->data[0]; /* uint_t l; */ /* for now, 44100, cdsgn */ a[0] = 1.000000000000000000000000000000000000000000000000000000000000; @@ -47,8 +47,8 @@ aubio_filter_t * new_aubio_cdsgn_filter(uint_t samplerate) { AUBIO_DBG("a[%d]=\t%1.16f\tb[%d]=\t%1.16f\n",l,a[l],l,b[l]); } */ - f->a = a; - f->b = b; + f->a->data[0] = a; + f->b->data[0] = b; return f; } diff --git a/src/temporal/cdesign.h b/src/temporal/cdesign.h index 3e869132..dfced798 100644 --- a/src/temporal/cdesign.h +++ b/src/temporal/cdesign.h @@ -24,7 +24,7 @@ \param samplerate sampling-rate of the signal to filter */ -aubio_filter_t * new_aubio_cdsgn_filter(uint_t samplerate); +aubio_filter_t * new_aubio_cdsgn_filter(uint_t samplerate, uint_t channels); #define aubio_cdsgn_filter_do aubio_filter_do #define del_aubio_cdsgn_filter del_aubio_filter diff --git a/src/temporal/filter.c b/src/temporal/filter.c index 8e1726d2..3d958832 100644 --- a/src/temporal/filter.c +++ b/src/temporal/filter.c @@ -23,72 +23,49 @@ #include "aubio_priv.h" #include "fvec.h" +#include "lvec.h" #include "mathutils.h" #include "temporal/filter.h" #include "temporal/filter_priv.h" -/* bug: mono only */ void aubio_filter_do(aubio_filter_t * f, fvec_t * in) { - uint_t i,j,l, order = f->order; - lsmp_t *x = f->x; - lsmp_t *y = f->y; - lsmp_t *a = f->a; - lsmp_t *b = f->b; - i=0;//for (i=0;ichannels;i++) { - for (j = 0; j < in->length; j++) { - /* new input */ - //AUBIO_DBG("befor %f\t", in->data[i][j]); - x[0] = in->data[i][j]; - y[0] = b[0] * x[0]; - for (l=1;ldata[i][j] = y[0]; - //AUBIO_DBG("after %f\n", in->data[i][j]); - /* store states for next sample */ - for (l=order-1; l>0; l--){ - x[l] = x[l-1]; - y[l] = y[l-1]; - } - } - /* store states for next buffer */ - f->x = x; - f->y = y; - //} + aubio_filter_do_outplace(f, in, in); } void aubio_filter_do_outplace(aubio_filter_t * f, fvec_t * in, fvec_t * out) { uint_t i,j,l, order = f->order; - lsmp_t *x = f->x; - lsmp_t *y = f->y; - lsmp_t *a = f->a; - lsmp_t *b = f->b; + lsmp_t *x; + lsmp_t *y; + lsmp_t *a = f->a->data[0]; + lsmp_t *b = f->b->data[0]; - i=0; // works in mono only !!! - //for (i=0;ichannels;i++) { - for (j = 0; j < in->length; j++) { - /* new input */ - x[0] = in->data[i][j]; - y[0] = b[0] * x[0]; - for (l=1;ldata[i][j] = y[0]; - /* store for next sample */ - for (l=order-1; l>0; l--){ - x[l] = x[l-1]; - y[l] = y[l-1]; + for (i = 0; i < in->channels; i++) { + x = f->x->data[i]; + y = f->y->data[i]; + for (j = 0; j < in->length; j++) { + /* new input */ + if (ISDENORMAL(in->data[i][j])) { + x[0] = y[0] = 0.; + } else { + x[0] = in->data[i][j]; + y[0] = b[0] * x[0]; + for (l=1;ldata[i][j] = y[0]; + /* store for next sample */ + for (l=order-1; l>0; l--){ + x[l] = x[l-1]; + y[l] = y[l-1]; + } } + /* store for next run */ + f->x->data[i] = x; + f->y->data[i] = y; } - /* store for next run */ - f->x = x; - f->y = y; - //} } /* @@ -125,27 +102,14 @@ void aubio_filter_do_filtfilt(aubio_filter_t * f, fvec_t * in, fvec_t * tmp) { in->data[i][j] = tmp->data[i][length-j-1]; } -aubio_filter_t * new_aubio_filter(uint_t samplerate UNUSED, uint_t order) { +aubio_filter_t * new_aubio_filter(uint_t samplerate UNUSED, uint_t order, uint_t channels) { aubio_filter_t * f = AUBIO_NEW(aubio_filter_t); - lsmp_t * x = f->x; - lsmp_t * y = f->y; - lsmp_t * a = f->a; - lsmp_t * b = f->b; - uint_t l; + f->x = new_lvec(order, channels); + f->y = new_lvec(order, channels); + f->a = new_lvec(order, 1); + f->b = new_lvec(order, 1); + f->a->data[0][1] = 1.; f->order = order; - a = AUBIO_ARRAY(lsmp_t,f->order); - b = AUBIO_ARRAY(lsmp_t,f->order); - x = AUBIO_ARRAY(lsmp_t,f->order); - y = AUBIO_ARRAY(lsmp_t,f->order); - /* initial states to zeros */ - for (l=0; lorder; l++){ - x[l] = 0.; - y[l] = 0.; - } - f->x = x; - f->y = y; - f->a = a; - f->b = b; return f; } diff --git a/src/temporal/filter.h b/src/temporal/filter.h index 7567d418..c82e50db 100644 --- a/src/temporal/filter.h +++ b/src/temporal/filter.h @@ -68,9 +68,10 @@ void aubio_filter_do_filtfilt(aubio_filter_t * b, fvec_t * in, fvec_t * tmp); \param samplerate signal sampling rate \param order order of the filter (number of coefficients) + \param channels number of channels to allocate */ -aubio_filter_t * new_aubio_filter(uint_t samplerate, uint_t order); +aubio_filter_t * new_aubio_filter(uint_t samplerate, uint_t order, uint_t channels); /** delete a filter object \param f filter object to delete diff --git a/src/temporal/filter_priv.h b/src/temporal/filter_priv.h index 816515c2..e604c71e 100644 --- a/src/temporal/filter_priv.h +++ b/src/temporal/filter_priv.h @@ -17,12 +17,13 @@ */ +#include "lvec.h" struct _aubio_filter_t { uint_t order; - lsmp_t * a; - lsmp_t * b; - lsmp_t * y; - lsmp_t * x; + lvec_t * a; + lvec_t * b; + lvec_t * y; + lvec_t * x; }; diff --git a/swig/aubio.i b/swig/aubio.i index 271cf394..562d82b9 100644 --- a/swig/aubio.i +++ b/swig/aubio.i @@ -85,18 +85,17 @@ extern void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum); extern void aubio_fft_get_real(cvec_t * spectrum, fvec_t * compspec); /* filter */ -extern aubio_filter_t * new_aubio_filter(uint_t samplerate, uint_t order); -extern aubio_filter_t * new_aubio_cdsgn_filter(uint_t samplerate); +extern aubio_filter_t * new_aubio_filter(uint_t samplerate, uint_t order, uint_t channels); extern void aubio_filter_do(aubio_filter_t * b, fvec_t * in); extern void aubio_filter_do_outplace(aubio_filter_t * b, fvec_t * in, fvec_t * out); extern void aubio_filter_do_filtfilt(aubio_filter_t * b, fvec_t * in, fvec_t * tmp); extern void del_aubio_filter(aubio_filter_t * b); -extern aubio_filter_t * new_aubio_adsgn_filter(uint_t samplerate); +extern aubio_filter_t * new_aubio_adsgn_filter(uint_t samplerate, uint_t channels); extern void aubio_adsgn_filter_do(aubio_filter_t * b, fvec_t * in); extern void del_aubio_adsgn_filter(aubio_filter_t * b); -extern aubio_filter_t * new_aubio_cdsgn_filter(uint_t samplerate); +extern aubio_filter_t * new_aubio_cdsgn_filter(uint_t samplerate, uint_t channels); extern void aubio_cdsgn_filter_do(aubio_filter_t * b, fvec_t * in); extern void del_aubio_cdsgn_filter(aubio_filter_t * b); -- 2.26.2