From 32e228d1ca60d479025f5c10479ac866208e11ae Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 27 Aug 2008 22:27:30 +0000 Subject: merged in relevant changes from the v0-40 pd-extended release branch svn path=/trunk/externals/creb/; revision=10266 --- modules/bmatrix~.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++ modules/bwin~.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++++ modules/cmath~.c | 16 ++--- modules/dwt~.c | 4 +- modules/ffpoly.c | 2 +- modules/matrix~.c | 154 ----------------------------------------------- modules/window~.c | 168 ---------------------------------------------------- 7 files changed, 336 insertions(+), 333 deletions(-) create mode 100644 modules/bmatrix~.c create mode 100644 modules/bwin~.c delete mode 100644 modules/matrix~.c delete mode 100644 modules/window~.c (limited to 'modules') diff --git a/modules/bmatrix~.c b/modules/bmatrix~.c new file mode 100644 index 0000000..b59d4d6 --- /dev/null +++ b/modules/bmatrix~.c @@ -0,0 +1,154 @@ +/* + * matrix.c - applies a matrix transform to a signal block + * intended for spectral processing, dynwav + * + * Copyright (c) 2000-2003 by Tom Schouten + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "m_pd.h" +#include +#include +#include +#include + +#define MAXORDER 1024 + +typedef struct matrixctl +{ + t_float *c_A; /* matrix */ + t_float *c_x; /* vector */ + t_int c_order; + +} t_matrixctl; + +typedef struct matrix +{ + t_object x_obj; + t_float x_f; + t_matrixctl x_ctl; +} t_matrix; + +static void matrix_load(t_matrix *x, t_symbol *s) +{ + FILE *matrix; + + if(s && s->s_name) + { + post("matrix: loading %s",s->s_name); + if(matrix = fopen(s->s_name, "r")) + { + int n = x->x_ctl.c_order; + fread(x->x_ctl.c_A, sizeof(float), n*n, matrix); + } + else post("matrix: error, cant open file."); + } +} + + +static t_int *matrix_perform(t_int *w) +{ + + + t_float *in = (float *)(w[3]); + t_float *out = (float *)(w[4]); + t_matrixctl *ctl = (t_matrixctl *)(w[1]); + t_int n = (t_int)(w[2]); + + t_int i,j; + t_float *A = ctl->c_A; + t_float *x = ctl->c_x; + + if (in == out) /* store input if ness. */ + { + memcpy(x, in, sizeof(t_float)*n); + in = x; + } + bzero(out, sizeof(t_float)*n); /* init output */ + + for (j=0; js_n; + int k,i; + + if (x->x_ctl.c_order != n) + { + if (x->x_ctl.c_A) free (x->x_ctl.c_A); + + x->x_ctl.c_A = (t_float *)calloc(n*n,sizeof(t_float)); + x->x_ctl.c_x = (t_float *)calloc(n,sizeof(t_float)); + x->x_ctl.c_order = n; + } + + for (i=0;ix_ctl.c_A[i] = 1; + + dsp_add(matrix_perform, 4, &x->x_ctl, sp[0]->s_n, sp[0]->s_vec, sp[1]->s_vec); + + +} +static void matrix_free(t_matrix *x) +{ + + if (x->x_ctl.c_A) free (x->x_ctl.c_A); + if (x->x_ctl.c_x) free (x->x_ctl.c_x); + +} + +t_class *matrix_class; + +static void *matrix_new(t_floatarg order) +{ + t_matrix *x = (t_matrix *)pd_new(matrix_class); + int iorder = (int)order; + int i, n=64, k; + + + /* out 1 */ + outlet_new(&x->x_obj, gensym("signal")); + + + + /* init data */ + + x->x_ctl.c_A = (t_float *)calloc(n*n,sizeof(t_float)); + x->x_ctl.c_x = (t_float *)calloc(n,sizeof(t_float)); + + + for (i=0;ix_ctl.c_A[i] = 1; + x->x_ctl.c_order = n; + + return (void *)x; +} + +void bmatrix_tilde_setup(void) +{ + //post("matrix~ v0.1"); + matrix_class = class_new(gensym("bmatrix~"), (t_newmethod)matrix_new, + (t_method)matrix_free, sizeof(t_matrix), 0, A_DEFFLOAT, 0); + CLASS_MAINSIGNALIN(matrix_class, t_matrix, x_f); + class_addmethod(matrix_class, (t_method)matrix_dsp, gensym("dsp"), 0); + class_addmethod(matrix_class, (t_method)matrix_load, gensym("load"), A_SYMBOL,0); + + +} + diff --git a/modules/bwin~.c b/modules/bwin~.c new file mode 100644 index 0000000..90a9e2a --- /dev/null +++ b/modules/bwin~.c @@ -0,0 +1,171 @@ +/* + * window.c - window generation abstraction + * Copyright (c) 2000-2003 by Tom Schouten + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "m_pd.h" +#include +#include + + +static t_class *window_class; + +typedef struct _window +{ + t_object x_obj; + t_float x_f; + t_float *x_window; + t_int x_size; + t_symbol *x_type; + t_float x_typearg; + +} t_window; + +static t_int *window_perform(t_int *w) +{ + t_window *x = (t_window *)(w[1]); + t_float *in = (t_float *)(w[2]); + t_float *out = (t_float *)(w[3]); + t_float *window = x->x_window; + int n = (int)(w[4]); + while (n--) + { + *out++ = (*in++) * (*window++); + } + return (w+5); +} + +static void window_size(t_window *x, t_int n) +{ + if (x->x_size != n){ + if (x->x_window) free(x->x_window); + x->x_window = malloc(sizeof(float)*n); + x->x_size = n; + } +} + + +static void window_type(t_window *x, t_symbol *s, t_float f) +{ + int i; + float a = 0; + float a_inc = 2 * M_PI / (float)(x->x_size); + if (!s) s = gensym("hamming"); + if (s == gensym("hamming")){ + for (i=0; ix_size; i++){ + float c = cos(a); + x->x_window[i] = (0.54 - 0.46 * c); + a += a_inc; + } + } + else if (s == gensym("hann")){ + for (i=0; ix_size; i++){ + float c = cos(a); + x->x_window[i] = (0.5 - 0.5 * c); + a += a_inc; + } + } + else if (s == gensym("hann/hamming")){ + for (i=0; ix_size; i++) { + float c = cos(a); + x->x_window[i] = (0.5 - 0.5 * c) / (0.54 - 0.46 * c); + a += a_inc; + } + } + else if (s == gensym("bfft_pink")){ + x->x_window[0] = 1.0f; //DC + x->x_window[1] = 1.0f / sqrt((double)(x->x_size>>1)); //NY + for (i=2; ix_size; i+=2) { + double freq = (double)(i>>1); + float amp = sqrt(1.0 / freq); + x->x_window[i] = amp; + x->x_window[i+1] = amp; + } + } + else if (s == gensym("bfft_blue")){ + x->x_window[0] = 1.0f; //DC + x->x_window[1] = sqrt((double)(x->x_size>>1)); //NY + for (i=2; ix_size; i+=2) { + double freq = (double)(i>>1); + float amp = sqrt(freq); + x->x_window[i] = amp; + x->x_window[i+1] = amp; + } + } + else if (s == gensym("bfft_db/octave")){ + float power = f/6.0; + x->x_window[0] = 1.0f; //DC + x->x_window[1] = pow((double)(x->x_size>>1), power); //NY + for (i=2; ix_size; i+=2) { + double freq = (double)(i>>1); + float amp = pow(freq, power); + x->x_window[i] = amp; + x->x_window[i+1] = amp; + } + } + + + /* default is no window */ + else{ + post("bwin~: unknown window type, using rectangular"); + for (i=0; ix_size; i++) x->x_window[i] = 1.0f; + } + + x->x_type = s; + x->x_typearg = f; + +} + +static void window_dsp(t_window *x, t_signal **sp) +{ + int n = sp[0]->s_n; + if (x->x_size != n){ + window_size(x, n); + window_type(x, x->x_type, x->x_typearg); + } + + dsp_add(window_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, n); +} + +static void window_free(t_window *x) +{ + free(x->x_window); +} + + +static void *window_new(t_symbol *s) +{ + t_window *x = (t_window *)pd_new(window_class); + outlet_new(&x->x_obj, &s_signal); + x->x_window = 0; + window_size(x, 64); + window_type(x, s, 0); + return (x); +} + +void bwin_tilde_setup(void) +{ + window_class = class_new(gensym("bwin~"), + (t_newmethod)window_new, (t_method)window_free, + sizeof(t_window), 0, A_DEFSYMBOL, A_NULL); + CLASS_MAINSIGNALIN(window_class, t_window, x_f); + class_addmethod(window_class, (t_method)window_dsp, + gensym("dsp"), A_NULL); + class_addmethod(window_class, (t_method)window_type, + gensym("type"), A_SYMBOL, A_DEFFLOAT, A_NULL); +} + diff --git a/modules/cmath~.c b/modules/cmath~.c index 3bd63a9..5526b9f 100644 --- a/modules/cmath~.c +++ b/modules/cmath~.c @@ -35,8 +35,8 @@ static t_int *cmath_perform_clog(t_int *w) { t_float *inx = (float *)(w[2]); t_float *iny = (float *)(w[3]); - t_float *outx = (float *)(w[4]); - t_float *outy = (float *)(w[5]); + t_float *outx = (float *)(w[5]); // clockwize addressing + t_float *outy = (float *)(w[4]); t_int i; t_int n = (t_int)(w[1]); t_float x; @@ -61,8 +61,8 @@ static t_int *cmath_perform_cexp(t_int *w) { t_float *inx = (float *)(w[2]); t_float *iny = (float *)(w[3]); - t_float *outx = (float *)(w[4]); - t_float *outy = (float *)(w[5]); + t_float *outx = (float *)(w[5]); // clockwize addressing + t_float *outy = (float *)(w[4]); t_int i; t_int n = (t_int)(w[1]); t_float x; @@ -82,8 +82,8 @@ static t_int *cmath_perform_nfft(t_int *w) { t_float *inx = (float *)(w[2]); t_float *iny = (float *)(w[3]); - t_float *outx = (float *)(w[4]); - t_float *outy = (float *)(w[5]); + t_float *outx = (float *)(w[5]); // clockwize addressing + t_float *outy = (float *)(w[4]); t_int i; t_int n = (t_int)(w[1]); t_float x; @@ -105,8 +105,8 @@ static t_int *cmath_perform_nifft(t_int *w) { t_float *inx = (float *)(w[2]); t_float *iny = (float *)(w[3]); - t_float *outx = (float *)(w[4]); - t_float *outy = (float *)(w[5]); + t_float *outx = (float *)(w[5]); // clockwize addressing + t_float *outy = (float *)(w[4]); t_int i; t_int n = (t_int)(w[1]); t_float x; diff --git a/modules/dwt~.c b/modules/dwt~.c index 327732c..9ab3bcc 100644 --- a/modules/dwt~.c +++ b/modules/dwt~.c @@ -190,9 +190,9 @@ static void dwt_permutation(t_dwt *x, t_int n){ /* debug */ for(k=0; kc_clutter[k]); + printf("clutter[%d] = %d\n", (int)k, (int)ctl->c_clutter[k]); for(k=0; kc_unclutter[k]); + printf("unclutter[%d] = %d\n", (int)k, (int)ctl->c_unclutter[k]); exit(1); } diff --git a/modules/ffpoly.c b/modules/ffpoly.c index c325969..097891c 100644 --- a/modules/ffpoly.c +++ b/modules/ffpoly.c @@ -1,6 +1,6 @@ /* * ffpoly.c - compute a finite field polynomial - * Copyright (c) by Tom Schouten + * Copyright (c) by Tom Schouten * * 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 diff --git a/modules/matrix~.c b/modules/matrix~.c deleted file mode 100644 index b59d4d6..0000000 --- a/modules/matrix~.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - * matrix.c - applies a matrix transform to a signal block - * intended for spectral processing, dynwav - * - * Copyright (c) 2000-2003 by Tom Schouten - * - * 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., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include "m_pd.h" -#include -#include -#include -#include - -#define MAXORDER 1024 - -typedef struct matrixctl -{ - t_float *c_A; /* matrix */ - t_float *c_x; /* vector */ - t_int c_order; - -} t_matrixctl; - -typedef struct matrix -{ - t_object x_obj; - t_float x_f; - t_matrixctl x_ctl; -} t_matrix; - -static void matrix_load(t_matrix *x, t_symbol *s) -{ - FILE *matrix; - - if(s && s->s_name) - { - post("matrix: loading %s",s->s_name); - if(matrix = fopen(s->s_name, "r")) - { - int n = x->x_ctl.c_order; - fread(x->x_ctl.c_A, sizeof(float), n*n, matrix); - } - else post("matrix: error, cant open file."); - } -} - - -static t_int *matrix_perform(t_int *w) -{ - - - t_float *in = (float *)(w[3]); - t_float *out = (float *)(w[4]); - t_matrixctl *ctl = (t_matrixctl *)(w[1]); - t_int n = (t_int)(w[2]); - - t_int i,j; - t_float *A = ctl->c_A; - t_float *x = ctl->c_x; - - if (in == out) /* store input if ness. */ - { - memcpy(x, in, sizeof(t_float)*n); - in = x; - } - bzero(out, sizeof(t_float)*n); /* init output */ - - for (j=0; js_n; - int k,i; - - if (x->x_ctl.c_order != n) - { - if (x->x_ctl.c_A) free (x->x_ctl.c_A); - - x->x_ctl.c_A = (t_float *)calloc(n*n,sizeof(t_float)); - x->x_ctl.c_x = (t_float *)calloc(n,sizeof(t_float)); - x->x_ctl.c_order = n; - } - - for (i=0;ix_ctl.c_A[i] = 1; - - dsp_add(matrix_perform, 4, &x->x_ctl, sp[0]->s_n, sp[0]->s_vec, sp[1]->s_vec); - - -} -static void matrix_free(t_matrix *x) -{ - - if (x->x_ctl.c_A) free (x->x_ctl.c_A); - if (x->x_ctl.c_x) free (x->x_ctl.c_x); - -} - -t_class *matrix_class; - -static void *matrix_new(t_floatarg order) -{ - t_matrix *x = (t_matrix *)pd_new(matrix_class); - int iorder = (int)order; - int i, n=64, k; - - - /* out 1 */ - outlet_new(&x->x_obj, gensym("signal")); - - - - /* init data */ - - x->x_ctl.c_A = (t_float *)calloc(n*n,sizeof(t_float)); - x->x_ctl.c_x = (t_float *)calloc(n,sizeof(t_float)); - - - for (i=0;ix_ctl.c_A[i] = 1; - x->x_ctl.c_order = n; - - return (void *)x; -} - -void bmatrix_tilde_setup(void) -{ - //post("matrix~ v0.1"); - matrix_class = class_new(gensym("bmatrix~"), (t_newmethod)matrix_new, - (t_method)matrix_free, sizeof(t_matrix), 0, A_DEFFLOAT, 0); - CLASS_MAINSIGNALIN(matrix_class, t_matrix, x_f); - class_addmethod(matrix_class, (t_method)matrix_dsp, gensym("dsp"), 0); - class_addmethod(matrix_class, (t_method)matrix_load, gensym("load"), A_SYMBOL,0); - - -} - diff --git a/modules/window~.c b/modules/window~.c deleted file mode 100644 index 777c8c5..0000000 --- a/modules/window~.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - * window.c - window generation abstraction - * Copyright (c) 2000-2003 by Tom Schouten - * - * 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., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include "m_pd.h" -#include -#include - - -static t_class *window_class; - -typedef struct _window -{ - t_object x_obj; - t_float x_f; - t_float *x_window; - t_int x_size; - t_symbol *x_type; - t_float x_typearg; - -} t_window; - -static t_int *window_perform(t_int *w) -{ - t_window *x = (t_window *)(w[1]); - t_float *in = (t_float *)(w[2]); - t_float *out = (t_float *)(w[3]); - t_float *window = x->x_window; - int n = (int)(w[4]); - while (n--) - { - *out++ = (*in++) * (*window++); - } - return (w+5); -} - -static void window_size(t_window *x, t_int n) -{ - if (x->x_size != n){ - if (x->x_window) free(x->x_window); - x->x_window = malloc(sizeof(float)*n); - x->x_size = n; - } -} - - -static void window_type(t_window *x, t_symbol *s, t_float f) -{ - int i; - float a = 0; - float a_inc = 2 * M_PI / (float)(x->x_size); - if (!s) s = gensym("hamming"); - if (s == gensym("hamming")){ - for (i=0; ix_size; i++){ - float c = cos(a); - x->x_window[i] = (0.54 - 0.46 * c); - a += a_inc; - } - } - else if (s == gensym("hann")){ - for (i=0; ix_size; i++){ - float c = cos(a); - x->x_window[i] = (0.5 - 0.5 * c); - a += a_inc; - } - } - else if (s == gensym("hann/hamming")){ - for (i=0; ix_size; i++) { - float c = cos(a); - x->x_window[i] = (0.5 - 0.5 * c) / (0.54 - 0.46 * c); - a += a_inc; - } - } - else if (s == gensym("bfft_pink")){ - x->x_window[0] = 1.0f; //DC - x->x_window[1] = 1.0f / sqrt((double)(x->x_size>>1)); //NY - for (i=2; ix_size; i+=2) { - double freq = (double)(i>>1); - float amp = sqrt(1.0 / freq); - x->x_window[i] = amp; - x->x_window[i+1] = amp; - } - } - else if (s == gensym("bfft_blue")){ - x->x_window[0] = 1.0f; //DC - x->x_window[1] = sqrt((double)(x->x_size>>1)); //NY - for (i=2; ix_size; i+=2) { - double freq = (double)(i>>1); - float amp = sqrt(freq); - x->x_window[i] = amp; - x->x_window[i+1] = amp; - } - } - else if (s == gensym("bfft_db/octave")){ - float power = f/6.0; - x->x_window[0] = 1.0f; //DC - x->x_window[1] = pow((double)(x->x_size>>1), power); //NY - for (i=2; ix_size; i+=2) { - double freq = (double)(i>>1); - float amp = pow(freq, power); - x->x_window[i] = amp; - x->x_window[i+1] = amp; - } - } - - - /* default is no window */ - else{ - post("bwin~: unknown window type, using rectangular"); - for (i=0; ix_size; i++) x->x_window[i] = 1.0f; - } - - x->x_type = s; - x->x_typearg = f; - -} - -static void window_dsp(t_window *x, t_signal **sp) -{ - int n = sp[0]->s_n; - if (x->x_size != n){ - window_size(x, n); - window_type(x, x->x_type, x->x_typearg); - } - - dsp_add(window_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, n); -} - -static void window_free(t_window *x) -{ - free(x->x_window); -} - - -static void *window_new(t_symbol *s) -{ - t_window *x = (t_window *)pd_new(window_class); - outlet_new(&x->x_obj, &s_signal); - x->x_window = 0; - window_size(x, 64); - window_type(x, s, 0); - return (x); -} - -void window_tilde_setup(void) -{ - window_class = class_new(gensym("bwin~"), (t_newmethod)window_new, (t_method)window_free, - sizeof(t_window), 0, A_DEFSYMBOL, A_NULL); - CLASS_MAINSIGNALIN(window_class, t_window, x_f); - class_addmethod(window_class, (t_method)window_dsp, gensym("dsp"), A_NULL); - class_addmethod(window_class, (t_method)window_type, gensym("type"), A_SYMBOL, A_DEFFLOAT, A_NULL); -} - -- cgit v1.2.1