From: Paul Brossier Date: Sun, 13 Jul 2008 19:57:55 +0000 (+0200) Subject: plugins/puredata/aubiozcr~.c: add aubiozcr~, computing zero crossing rate X-Git-Tag: bzr2git~379 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6f9615c3e875100ef293f2d15eee00b0d97b25e6;p=aubio.git plugins/puredata/aubiozcr~.c: add aubiozcr~, computing zero crossing rate --- diff --git a/plugins/puredata/Makefile.am b/plugins/puredata/Makefile.am index 12037a98..e95a8c47 100644 --- a/plugins/puredata/Makefile.am +++ b/plugins/puredata/Makefile.am @@ -27,7 +27,8 @@ ALLSOURCES = \ aubiotempo~.c \ aubiotss~.c \ aubioquiet~.c \ - aubiopitch~.c + aubiopitch~.c \ + aubiozcr~.c aubio_pd_linux_SOURCES = $(ALLSOURCES) aubio_pd_darwin_SOURCES = $(ALLSOURCES) diff --git a/plugins/puredata/aubio_setup.c b/plugins/puredata/aubio_setup.c index 31f474ae..31c1a2bb 100644 --- a/plugins/puredata/aubio_setup.c +++ b/plugins/puredata/aubio_setup.c @@ -17,6 +17,7 @@ extern void aubiotempo_tilde_setup (void); extern void aubiotss_tilde_setup (void); extern void aubioquiet_tilde_setup (void); extern void aubiopitch_tilde_setup (void); +extern void aubiozcr_tilde_setup (void); void *aubio_new (void) { @@ -32,6 +33,7 @@ void aubio_setup (void) aubiotss_tilde_setup(); aubioquiet_tilde_setup(); aubiopitch_tilde_setup(); + aubiozcr_tilde_setup(); aubio_class = class_new(gensym("aubio"), (t_newmethod)aubio_new, 0, sizeof(t_aubio), 0, 0); } diff --git a/plugins/puredata/aubiozcr~.c b/plugins/puredata/aubiozcr~.c new file mode 100644 index 00000000..a34dd404 --- /dev/null +++ b/plugins/puredata/aubiozcr~.c @@ -0,0 +1,91 @@ + +/** + * + * a puredata wrapper for aubio zero crossing rate function + * + * Thanks to Johannes M Zmolnig for writing the excellent HOWTO: + * http://iem.kug.ac.at/pd/externals-HOWTO/ + * + * */ + +#include +#include + +char aubiozcr_version[] = "aubiozcr~ version 0.1"; + +static t_class *aubiozcr_tilde_class; + +void aubiozcr_tilde_setup (void); + +typedef struct _aubiozcr_tilde +{ + t_object x_obj; + t_int pos; /*frames%dspblocksize*/ + t_int bufsize; + t_float f; + fvec_t *vec; + t_outlet *zcr; +} t_aubiozcr_tilde; + +static t_int *aubiozcr_tilde_perform(t_int *w) +{ + t_aubiozcr_tilde *x = (t_aubiozcr_tilde *)(w[1]); + t_sample *in = (t_sample *)(w[2]); + int n = (int)(w[3]); + int j; + for (j=0;jvec, in[j], 0, x->pos); + /*time for fft*/ + if (x->pos == x->bufsize-1) { + /* block loop */ + outlet_float(x->zcr, aubio_zero_crossing_rate(x->vec)); + /* end of block loop */ + x->pos = -1; /* so it will be zero next j loop */ + } + x->pos++; + } + return (w+4); +} + +static void aubiozcr_tilde_dsp(t_aubiozcr_tilde *x, t_signal **sp) +{ + dsp_add(aubiozcr_tilde_perform, 3, x, sp[0]->s_vec, sp[0]->s_n); +} + +static void aubiozcr_tilde_debug(t_aubiozcr_tilde *x) +{ + post("aubiozcr~ bufsize:\t%d", x->bufsize); + post("aubiozcr~ audio in:\t%f", x->vec->data[0][0]); +} + +static void *aubiozcr_tilde_new (void) +{ + t_aubiozcr_tilde *x = + (t_aubiozcr_tilde *)pd_new(aubiozcr_tilde_class); + + x->bufsize = 1024; + + x->vec = (fvec_t *)new_fvec(x->bufsize,1); + + x->zcr = outlet_new (&x->x_obj, &s_float); + post(aubiozcr_version); + return (void *)x; +} + +void aubiozcr_tilde_setup (void) +{ + aubiozcr_tilde_class = class_new (gensym ("aubiozcr~"), + (t_newmethod)aubiozcr_tilde_new, + 0, sizeof (t_aubiozcr_tilde), + CLASS_DEFAULT, 0); + class_addmethod(aubiozcr_tilde_class, + (t_method)aubiozcr_tilde_dsp, + gensym("dsp"), 0); + class_addmethod(aubiozcr_tilde_class, + (t_method)aubiozcr_tilde_debug, + gensym("debug"), 0); + CLASS_MAINSIGNALIN(aubiozcr_tilde_class, + t_aubiozcr_tilde, f); +} + diff --git a/plugins/puredata/help/aubiozcr~-help.pd b/plugins/puredata/help/aubiozcr~-help.pd new file mode 100644 index 00000000..70f4118a --- /dev/null +++ b/plugins/puredata/help/aubiozcr~-help.pd @@ -0,0 +1,11 @@ +#N canvas 0 22 580 309 10; +#X obj 37 71 aubiozcr~; +#X obj 37 43 osc~ 441; +#X floatatom 36 98 5 0 0 0 - - -; +#X text 153 36 aubiozcr~ computes the zero-crossing rate; +#X text 152 95 For a sine tone at 441Hz sampled at 44100Hz signal \, +the ZCR is 0.02.; +#X text 153 59 This value represents the number of times where the +signal changes sign.; +#X connect 0 0 2 0; +#X connect 1 0 0 0;