From c56a043c7b42ee7dec7b54790eb16057f97959b2 Mon Sep 17 00:00:00 2001 From: Jamie Bullock Date: Wed, 19 Apr 2006 18:00:40 +0000 Subject: renamed cross~ to cc~ svn path=/trunk/externals/postlude/; revision=4941 --- flib/makefile | 12 ++-- flib/src/cc~.c | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ flib/src/flib.c | 4 +- flib/src/flib.h | 2 +- 4 files changed, 208 insertions(+), 9 deletions(-) create mode 100644 flib/src/cc~.c diff --git a/flib/makefile b/flib/makefile index babda2f..eef602d 100644 --- a/flib/makefile +++ b/flib/makefile @@ -12,7 +12,7 @@ INSTALL_PREFIX = /usr/local PDLIBDIR = /lib/pd PDDIR = $(INSTALL_PREFIX)$(PDLIBDIR) -TARGETS = sc~ ss~ irreg~ mspec~ peak~ pspec~ sfm~ trist~ pp~ bmax~ melf~ clean~ wdv~ hca~ cross~ +TARGETS = sc~ ss~ irreg~ mspec~ peak~ pspec~ sfm~ trist~ pp~ bmax~ melf~ clean~ wdv~ hca~ cc~ # ----------------------- NT ----------------------- @@ -53,7 +53,7 @@ PDNTLIB = $(PDNTLDIR)\msvcrt.lib \ $(CC) $(PDNTCFLAGS) $(PDNTINCLUDE) -c src/clean~.c $(CC) $(PDNTCFLAGS) $(PDNTINCLUDE) -c src/wdv~.c $(CC) $(PDNTCFLAGS) $(PDNTINCLUDE) -c src/hca~.c - $(CC) $(PDNTCFLAGS) $(PDNTINCLUDE) -c src/cross~.c + $(CC) $(PDNTCFLAGS) $(PDNTINCLUDE) -c src/cc~.c $(CC) $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c link /dll /export:$(CSYM)_setup $(NAME).obj $(PDNTOBJECTS) $(PDNTLIB) @@ -89,7 +89,7 @@ DARWINOBJECTS = $(TARGETS:%=%.o) $(CC) $(DARWINCFLAGS) $(DARWININCLUDE) -c src/clean~.c $(CC) $(DARWINCFLAGS) $(DARWININCLUDE) -c src/wdv~.c $(CC) $(DARWINCFLAGS) $(DARWININCLUDE) -c src/hca~.c - $(CC) $(DARWINCFLAGS) $(DARWININCLUDE) -c src/cross~.c + $(CC) $(DARWINCFLAGS) $(DARWININCLUDE) -c src/cc~.c $(CC) $(DARWINCFLAGS) $(DARWININCLUDE) -c $*.c $(CC) -bundle -undefined suppress -flat_namespace -o $(NAME).pd_darwin $(NAME).o $(DARWINOBJECTS) rm -f $(NAME).o ../$(NAME).pd_darwin @@ -147,7 +147,7 @@ LINUXINCLUDE = -I/usr/include $(CC) $(LINUXCFLAGS) $(LINUXINCLUDE) -c src/clean~.c $(CC) $(LINUXCFLAGS) $(LINUXINCLUDE) -c src/wdv~.c $(CC) $(LINUXCFLAGS) $(LINUXINCLUDE) -c src/hca~.c - $(CC) $(LINUXCFLAGS) $(LINUXINCLUDE) -c src/cross~.c + $(CC) $(LINUXCFLAGS) $(LINUXINCLUDE) -c src/cc~.c $(CC) $(LINUXCFLAGS) $(LINUXINCLUDE) -c $*.c ld -export_dynamic -shared -o $(NAME).pd_linux $(NAME).o $(LINUXOBJECTS) -lc -lm strip --strip-unneeded $(NAME).pd_linux @@ -179,7 +179,7 @@ SGIINCLUDE = -I/usr/include/ -I/usr/local/include/ $(CC) $(SGICFLAGS) $(SGIINCLUDE) -c src/clean~.c $(CC) $(SGICFLAGS) $(SGIINCLUDE) -c src/wdv~.c $(CC) $(SGICFLAGS) $(SGIINCLUDE) -c src/hca~.c - $(CC) $(SGICFLAGS) $(SGIINCLUDE) -c src/cross~.c + $(CC) $(SGICFLAGS) $(SGIINCLUDE) -c src/cc~.c $(CC) $(SGICFLAGS) $(SGIINCLUDE) -c $*.c ld -elf -shared -rdata_shared -o $(NAME).pd_irix5 $(NAME).o $(LINUXOBJECTS) -lm -lc rm $*.o @@ -212,7 +212,7 @@ SGIINCLUDE = -I/usr/include/ -I/usr/local/include/ $(CC) $(SGICFLAGS) $(SGIINCLUDE) -c src/clean~.c $(CC) $(SGICFLAGS) $(SGIINCLUDE) -c src/wdv~.c $(CC) $(SGICFLAGS) $(SGIINCLUDE) -c src/hca~.c - $(CC) $(SGICFLAGS) $(SGIINCLUDE) -c src/cross~.c + $(CC) $(SGICFLAGS) $(SGIINCLUDE) -c src/cc~.c $(CC) $(SGICFLAGS) $(SGIINCLUDE) -c $*.c ld -n32 -IPA -shared -rdata_shared -o $*.pd_irix6 $(NAME).o $(LINUXOBJECTS) -lm -lc rm $*.o diff --git a/flib/src/cc~.c b/flib/src/cc~.c new file mode 100644 index 0000000..2d06d9b --- /dev/null +++ b/flib/src/cc~.c @@ -0,0 +1,199 @@ +/* flib - PD library for feature extraction + Copyright (C) 2005 Jamie Bullock + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +/*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" +#define SQ(a) (a * a) + +static t_class *cross_class; + +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_time_domain(t_int *w) +{ + t_sample *x = (t_sample *)(w[1]); + t_sample *y = (t_sample *)(w[2]); + t_sample *out = (t_sample *)(w[3]); + t_int N = (t_int)(w[4]), + i, j, delay; + t_int maxdelay = (t_int)(w[5]); + t_float mx, my, sx, sy, sxy, denom, r; + + if(maxdelay > N * .5){ + maxdelay = N * .5; + post("cross~: invalid maxdelay, must be <= blocksize/2"); + } + +/* Calculate the mean of the two series x[], y[] */ + mx = 0; + my = 0; + for (i=0;iis_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); + return (void *)x; +} + + +void cross_tilde_setup(void) { + cross_class = class_new(gensym("cross~"), + (t_newmethod)cross_new, + 0, sizeof(t_cross), + CLASS_DEFAULT, A_GIMME, 0); + + class_addmethod(cross_class, + (t_method)cross_dsp, gensym("dsp"), 0); + CLASS_MAINSIGNALIN(cross_class, t_cross,f); + class_sethelpsymbol(cross_class, gensym("help-flib")); +} diff --git a/flib/src/flib.c b/flib/src/flib.c index 8db11f4..1cdcfb0 100644 --- a/flib/src/flib.c +++ b/flib/src/flib.c @@ -36,7 +36,7 @@ void flib_setup(void) { int i; - char *ext[] = {"sc~\t\tSpectral Centroid", "ss~\t\tSpectral Smoothness", "irreg~\t\tSpectral Irregularity (methods 1 and 2)", "mspec~\t\tMagnitude Spectrum", "peak~\t\tAmplitude and Frequency of Spectral Peaks", "pspec~\t\tPhase Spectrum", "sfm~\t\tSpectral Flatness Measure", "trist~\t\tTristimulus (x,y,z)", "++~\t\tSum of the samples in each block", "bmax~\t\tThe maximum value and location(s) each block", "melf~\t\tGenerate a mel spaced filter for fft", "clean~\t\tRemoves NaN, inf and -inf from a signal vector", "wdv~\t\tCalculate a wavelet dispersion vector (requires creb)", "hca~\t\tHarmonic component analysis", "cross~\t\tCross correlation"}; + char *ext[] = {"sc~\t\tSpectral Centroid", "ss~\t\tSpectral Smoothness", "irreg~\t\tSpectral Irregularity (methods 1 and 2)", "mspec~\t\tMagnitude Spectrum", "peak~\t\tAmplitude and Frequency of Spectral Peaks", "pspec~\t\tPhase Spectrum", "sfm~\t\tSpectral Flatness Measure", "trist~\t\tTristimulus (x,y,z)", "++~\t\tSum of the samples in each block", "bmax~\t\tThe maximum value and location(s) each block", "melf~\t\tGenerate a mel spaced filter for fft", "clean~\t\tRemoves NaN, inf and -inf from a signal vector", "wdv~\t\tCalculate a wavelet dispersion vector (requires creb)", "hca~\t\tHarmonic component analysis", "cc~\t\tCross correlation"}; sc_tilde_setup(); ss_tilde_setup(); pp_tilde_setup(); @@ -51,7 +51,7 @@ void flib_setup(void) clean_tilde_setup(); wdv_tilde_setup(); hca_tilde_setup(); - cross_tilde_setup(); + cc_tilde_setup(); post("\n\tflib "VERSION" Feature Extraction Library\n\tby Jamie Bullock\n"); diff --git a/flib/src/flib.h b/flib/src/flib.h index 868f683..c43f63b 100644 --- a/flib/src/flib.h +++ b/flib/src/flib.h @@ -37,5 +37,5 @@ void melf_tilde_setup(void); void clean_tilde_setup(void); void wdv_tilde_setup(void); void hca_tilde_setup(void); -void cross_tilde_setup(void); +void cc_tilde_setup(void); -- cgit v1.2.1