[PD-cvs] externals/postlude/flib/src cross~.c, 1.3, 1.4 flib.h, 1.2, 1.3
Jamie Bullock
postlude at users.sourceforge.net
Wed Apr 19 19:48:40 CEST 2006
Update of /cvsroot/pure-data/externals/postlude/flib/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28768/src
Modified Files:
cross~.c flib.h
Log Message:
Added frequency domain correlation to cross~
Index: flib.h
===================================================================
RCS file: /cvsroot/pure-data/externals/postlude/flib/src/flib.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** flib.h 7 Apr 2006 20:11:49 -0000 1.2
--- flib.h 19 Apr 2006 17:48:38 -0000 1.3
***************
*** 22,26 ****
#include <string.h>
! #define VERSION "0.8"
void sc_tilde_setup(void);
--- 22,26 ----
#include <string.h>
! #define VERSION "0.82"
void sc_tilde_setup(void);
Index: cross~.c
===================================================================
RCS file: /cvsroot/pure-data/externals/postlude/flib/src/cross~.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** cross~.c 7 Apr 2006 20:11:49 -0000 1.3
--- cross~.c 19 Apr 2006 17:48:38 -0000 1.4
***************
*** 18,23 ****
! /*Calculate the (non optimized) cross correlation of two signal vectors*/
! /*Based on code by Phil Bourke */
--- 18,29 ----
! /*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*/
***************
*** 31,37 ****
t_float f;
t_int delay;
} t_cross;
! static t_int *cross_perform(t_int *w)
{
t_sample *x = (t_sample *)(w[1]);
--- 37,44 ----
t_float f;
t_int delay;
+ t_int is_freq_domain;
} t_cross;
! static t_int *cross_perform_time_domain(t_int *w)
{
t_sample *x = (t_sample *)(w[1]);
***************
*** 46,55 ****
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[] */
mx = 0;
my = 0;
--- 53,59 ----
maxdelay = N * .5;
post("cross~: invalid maxdelay, must be <= blocksize/2");
}
! /* Calculate the mean of the two series x[], y[] */
mx = 0;
my = 0;
***************
*** 93,106 ****
}
static void cross_dsp(t_cross *x, t_signal **sp)
{
! dsp_add(cross_perform, 5,
! sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n, x->delay);
}
! static void *cross_new(t_floatarg f)
{
t_cross *x = (t_cross *)pd_new(cross_class);
! x->delay = (t_int)f;
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
outlet_new(&x->x_obj, &s_signal);
--- 97,184 ----
}
+
+ t_int *cross_perform_freq_domain(t_int *w)
+ {
+ t_cross *x = (t_cross *)(w[1]);
+
+ t_sample *sig1 = (t_sample *)(w[2]);
+ t_sample *sig2 = (t_sample *)(w[3]);
+ t_sample *out = (t_sample *)(w[4]);
+ long int size = (long int) w[5];
+ long int k = size/2;
+ float *expsig1 = NULL;
+ float *revsig2 = NULL;
+ float temp, temp2;
+ long int i=0;
+ int well_defined=1;
+ int qtr, thrqtr;
+
+ // The two signals are created, nonzero on 0 to N/4 and 3N/4 to N
+ // This will be revised
+
+ expsig1=(float *) alloca(size*sizeof(float));
+ revsig2=(float *) alloca(size*sizeof(float));
+ qtr = size/4;
+ thrqtr = 3*size/4;
+ for (i=0; i < qtr ; i++)
+ {
+ expsig1[i]=sig1[i];
+ revsig2[i]=0;
+ }
+ for (i=qtr; i < thrqtr ; i++)
+ {
+ expsig1[i]=sig1[i];
+ revsig2[i]=sig2[size-i];
+ }
+ for (i=thrqtr; i < size ; i++)
+ {
+ expsig1[i]=sig1[i];
+ revsig2[i]=0;
+ }
+
+ mayer_realfft(size, expsig1);
+ mayer_realfft(size, revsig2);
+ expsig1[0]*=revsig2[0];
+ expsig1[k]*=revsig2[k];
+ for(i=1; i < k; i++)
+ {
+ temp=expsig1[i];
+ temp2=expsig1[size-i];
+ expsig1[i]=temp*revsig2[i]-temp2*revsig2[size-i];
+ expsig1[size-i]=temp*revsig2[size-i]+temp2*revsig2[i];
+ }
+
+ mayer_realifft(size, expsig1);
+ for(i=0; i < size; i++)
+ {
+ out[i]=expsig1[i];
+ }
+
+ return(w+6);
+
+ }
+
static void cross_dsp(t_cross *x, t_signal **sp)
{
! 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_symbol *s, t_int argc, t_atom *argv)
{
t_cross *x = (t_cross *)pd_new(cross_class);
!
! 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);
***************
*** 113,117 ****
(t_newmethod)cross_new,
0, sizeof(t_cross),
! CLASS_DEFAULT, A_DEFFLOAT, 0);
class_addmethod(cross_class,
--- 191,195 ----
(t_newmethod)cross_new,
0, sizeof(t_cross),
! CLASS_DEFAULT, A_GIMME, 0);
class_addmethod(cross_class,
More information about the Pd-cvs
mailing list