From a1b3c0b4fa99bfd116f302fe74f1168c84d01f79 Mon Sep 17 00:00:00 2001 From: Jamie Bullock Date: Wed, 19 Apr 2006 17:48:38 +0000 Subject: Added frequency domain correlation to cross~ svn path=/trunk/externals/postlude/; revision=4940 --- flib/src/cross~.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++------- flib/src/flib.h | 2 +- 2 files changed, 91 insertions(+), 13 deletions(-) (limited to 'flib/src') diff --git a/flib/src/cross~.c b/flib/src/cross~.c index d7ea4bb..2d06d9b 100644 --- a/flib/src/cross~.c +++ b/flib/src/cross~.c @@ -17,8 +17,14 @@ */ -/*Calculate the (non optimized) cross correlation of two signal vectors*/ -/*Based on code by Phil Bourke */ +/*Calculate the cross correlation of two signal vectors*/ + +/*The time domain implementation is based on code by Phil Bourke + * the frequency domain version is based on code by Charles Henry + * + * Specify a time delay as an argument for the time domain implemenation, for example an argument of 32 will give the correlation coefficients for delays from -32 to 32 samples between the two input vectors + * + * Specify an argument of 'f' for the frequency domain implementation*/ #include "flib.h" @@ -30,9 +36,10 @@ typedef struct _cross { t_object x_obj; t_float f; t_int delay; + t_int is_freq_domain; } t_cross; -static t_int *cross_perform(t_int *w) +static t_int *cross_perform_time_domain(t_int *w) { t_sample *x = (t_sample *)(w[1]); t_sample *y = (t_sample *)(w[2]); @@ -45,12 +52,9 @@ static t_int *cross_perform(t_int *w) if(maxdelay > N * .5){ maxdelay = N * .5; post("cross~: invalid maxdelay, must be <= blocksize/2"); - } - else if (!maxdelay){ - maxdelay = N * .5; } - /* Calculate the mean of the two series x[], y[] */ +/* Calculate the mean of the two series x[], y[] */ mx = 0; my = 0; for (i=0;is_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n, x->delay); + if(!x->is_freq_domain) + dsp_add(cross_perform_time_domain, 5, + sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n, x->delay); + else + dsp_add(cross_perform_freq_domain, 5, x, + sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n); } -static void *cross_new(t_floatarg f) +static void *cross_new(t_symbol *s, t_int argc, t_atom *argv) { t_cross *x = (t_cross *)pd_new(cross_class); - x->delay = (t_int)f; + + if(atom_getsymbol(argv) == gensym("f")){ + x->is_freq_domain = 1; + post("flib: cross: Frequency domain selected"); + } + else { + x->delay = atom_getfloat(argv); + post("flib: cross: Time domain selected"); + } inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); outlet_new(&x->x_obj, &s_signal); return (void *)x; @@ -112,7 +190,7 @@ void cross_tilde_setup(void) { cross_class = class_new(gensym("cross~"), (t_newmethod)cross_new, 0, sizeof(t_cross), - CLASS_DEFAULT, A_DEFFLOAT, 0); + CLASS_DEFAULT, A_GIMME, 0); class_addmethod(cross_class, (t_method)cross_dsp, gensym("dsp"), 0); diff --git a/flib/src/flib.h b/flib/src/flib.h index fba78f0..868f683 100644 --- a/flib/src/flib.h +++ b/flib/src/flib.h @@ -21,7 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #include -#define VERSION "0.8" +#define VERSION "0.82" void sc_tilde_setup(void); void ss_tilde_setup(void); -- cgit v1.2.1