Imported Upstream version 0.1

parents
This diff is collapsed.
This diff is collapsed.
Porvides:
hammimng~, hanning~, blackman~, cosine~, connes~, bartlett~,
welch~, lanczos~, gaussian~, and kaiser~
Usage:
Windows inlet signal on each DSP block and sends to outlet
gaussian~ takes one optional argument (standard deviation)
May be set by float in left inlet
kaiser~ takes one option argument (alpha)
May be set by float in left inlet
See windowing.pd
To build:
Linux: make windowing_linux
Windows: nmake windowing_nt
#N canvas 256 141 557 517 10;
#X obj 4 479 cnv 15 550 20 empty \$0-pddp.cnv.footer empty 20 12 0
14 -228856 -66577 0;
#X obj 4 -17 cnv 15 550 40 empty \$0-pddp.cnv.header bartlett~ 3 12
0 18 -204280 -1 0;
#X obj 3 239 cnv 3 550 3 empty \$0-pddp.cnv.inlets inlets 15 12 0 13
-228856 -1 0;
#X obj 3 299 cnv 3 550 3 empty \$0-pddp.cnv.outlets outlet 15 12 0
13 -228856 -1 0;
#X obj 3 359 cnv 3 550 3 empty \$0-pddp.cnv.more_info more_info 15
12 0 13 -228856 -1 0;
#X obj 72 259 cnv 17 3 30 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856
-162280 0;
#X text 168 40 formula:;
#X obj 97 86 hsl 71 15 -1 1 0 0 empty empty empty -2 -6 0 10 -262144
-1 -1 7000 1;
#X msg 94 66 1;
#X obj 94 46 loadbang;
#X obj 102 365 pddp/pddplink http://en.wikipedia.org/wiki/Window_function
-text wikipedia: window functions;
#X obj 438 -14 import windowing;
#X msg 36 154 \; pd dsp 1;
#X text 21 85 height --->;
#X obj 127 109 sig~ 1;
#N canvas 0 0 450 300 graph3 0;
#X array \$0-bartlett 64 float 0;
#X coords 0 1 63 -1 200 140 1;
#X restore 326 65 graph;
#X text 102 394 Windowing functions are used with FFTs. These transform
the signal block-by-block into a spectral representation whose resolution
in both the frequency and time domains are proportional to their size
(as a power-of-two in PD). The different windows have different characteristics
in terms of stopband attenuation and noise bandwidth.;
#X text 102 258 SIGNAL: the height (amplitude) of the window is controlled
by the signal on its inlet.;
#X obj 127 158 tabsend~ \$0-bartlett;
#X obj 127 132 bartlett~;
#X text 169 53 1-x^2;
#X text 103 317 SIGNAL: a bartlett (triangle) window with size=dsp
blocksize;
#X obj 102 380 pddp/pddplink http://mathworld.wolfram.com/BartlettFunction.html
-text mathworld link;
#X obj 435 6 pddp/pddplink http://wiki.puredata.info/en/bartlett~ -text
pdpedia: bartlett~;
#X text 15 6 description: generates a bartlett window for each dsp
block;
#X obj 72 319 cnv 17 3 30 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856
-162280 0;
#X connect 7 0 14 0;
#X connect 8 0 7 0;
#X connect 9 0 8 0;
#X connect 14 0 19 0;
#X connect 19 0 18 0;
/* bartlett~ - bartlett windowing function for Pure Data
**
** Copyright (C) 2002 Joseph A. Sarlo
**
** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** jsarlo@mambo.peabody.jhu.edu
*/
#include "m_pd.h"
#include <stdlib.h>
#include <math.h>
#ifdef _MSC_VER
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#define DEFBLOCKSIZE 64
void fillBartlett(float *vec, int n) {
int i;
float xShift = (float)n / 2;
float x;
for (i = 0; i < n; i++) {
x = (i - xShift) / xShift;
vec[i] = (float)(1 - fabs(x));
}
}
static t_class *bartlett_class;
typedef struct _bartlett {
t_object x_obj;
int x_blocksize;
float *x_table;
} t_bartlett;
static t_int* bartlett_perform(t_int *w) {
t_bartlett *x = (t_bartlett *)(w[1]);
t_float *in = (t_float *)(w[2]);
t_float *out = (t_float *)(w[3]);
int n = (int)(w[4]);
int i;
if (x->x_blocksize != n) {
if (x->x_blocksize < n) {
x->x_table = realloc(x->x_table, n * sizeof(float));
}
x->x_blocksize = n;
fillBartlett(x->x_table, x->x_blocksize);
}
for (i = 0; i < n; i++) {
*out++ = *(in++) * x->x_table[i];
}
return (w + 5);
}
static void bartlett_dsp(t_bartlett *x, t_signal **sp) {
dsp_add(bartlett_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
}
static void* bartlett_new(void) {
t_bartlett *x = (t_bartlett *)pd_new(bartlett_class);
x->x_blocksize = DEFBLOCKSIZE;
x->x_table = malloc(x->x_blocksize * sizeof(float));
fillBartlett(x->x_table, x->x_blocksize);
outlet_new(&x->x_obj, gensym("signal"));
return (x);
}
static void bartlett_free(t_bartlett *x) {
free(x->x_table);
}
void bartlett_tilde_setup(void) {
bartlett_class = class_new(gensym("bartlett~"),
(t_newmethod)bartlett_new,
(t_method)bartlett_free,
sizeof(t_bartlett),
0,
A_DEFFLOAT,
0);
class_addmethod(bartlett_class, nullfn, gensym("signal"), 0);
class_addmethod(bartlett_class, (t_method)bartlett_dsp, gensym("dsp"), 0);
}
#N canvas 256 141 561 517 10;
#X obj 4 479 cnv 15 550 20 empty \$0-pddp.cnv.footer empty 20 12 0
14 -228856 -66577 0;
#X obj 4 -17 cnv 15 550 40 empty \$0-pddp.cnv.header blackman~ 3 12
0 18 -204280 -1 0;
#X obj 3 239 cnv 3 550 3 empty \$0-pddp.cnv.inlets inlets 15 12 0 13
-228856 -1 0;
#X obj 3 299 cnv 3 550 3 empty \$0-pddp.cnv.outlets outlet 15 12 0
13 -228856 -1 0;
#X obj 3 359 cnv 3 550 3 empty \$0-pddp.cnv.more_info more_info 15
12 0 13 -228856 -1 0;
#X obj 72 259 cnv 17 3 30 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856
-162280 0;
#X text 168 40 formula:;
#X obj 97 86 hsl 71 15 -1 1 0 0 empty empty empty -2 -6 0 10 -262144
-1 -1 7000 1;
#X msg 94 66 1;
#X obj 94 46 loadbang;
#X obj 102 365 pddp/pddplink http://en.wikipedia.org/wiki/Window_function
-text wikipedia: window functions;
#X obj 438 -14 import windowing;
#X msg 36 154 \; pd dsp 1;
#X text 21 85 height --->;
#X text 15 6 description: generates a blackman window for each dsp
block;
#X obj 127 109 sig~ 1;
#X obj 127 132 blackman~;
#N canvas 0 0 450 300 graph3 0;
#X array \$0-blackman 64 float 0;
#X coords 0 1 63 -1 200 140 1;
#X restore 326 65 graph;
#X text 168 70 0.8*cos(2*pi*x);
#X text 168 55 0.42+(0.5*cos(pi*x))+;
#X obj 102 380 pddp/pddplink http://mathworld.wolfram.com/BlackmanFunction.html
-text mathworld link;
#X text 103 317 SIGNAL: a blackman window with size=dsp blocksize;
#X obj 435 6 pddp/pddplink http://wiki.puredata.info/en/blackman~ -text
pdpedia: blackman~;
#X text 102 394 Windowing functions are used with FFTs. These transform
the signal block-by-block into a spectral representation whose resolution
in both the frequency and time domains are proportional to their size
(as a power-of-two in PD). The different windows have different characteristics
in terms of stopband attenuation and noise bandwidth.;
#X text 102 258 SIGNAL: the height (amplitude) of the window is controlled
by the signal on its inlet.;
#X obj 127 158 tabsend~ \$0-blackman;
#X obj 73 319 cnv 17 3 30 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856
-162280 0;
#X connect 7 0 15 0;
#X connect 8 0 7 0;
#X connect 9 0 8 0;
#X connect 15 0 16 0;
#X connect 16 0 25 0;
/* blackman~ - blackman windowing function for Pure Data
**
** Copyright (C) 2002 Joseph A. Sarlo
**
** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** jsarlo@mambo.peabody.jhu.edu
*/
#include "m_pd.h"
#include <stdlib.h>
#include <math.h>
#ifdef _WIN32
#define M_PI 3.14159265358979323846
#endif
#ifdef _MSC_VER
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#define DEFBLOCKSIZE 64
void fillBlackman(float *vec, int n) {
int i;
float xShift = (float)n / 2;
float x;
for (i = 0; i < n; i++) {
x = (i - xShift) / xShift;
vec[i] = (float)(0.42 + (0.5 * cos(M_PI * x)) + (0.08 * cos (2 * M_PI * x)));
}
}
static t_class *blackman_class;
typedef struct _blackman {
t_object x_obj;
int x_blocksize;
float *x_table;
} t_blackman;
static t_int* blackman_perform(t_int *w) {
t_blackman *x = (t_blackman *)(w[1]);
t_float *in = (t_float *)(w[2]);
t_float *out = (t_float *)(w[3]);
int n = (int)(w[4]);
int i;
if (x->x_blocksize != n) {
if (x->x_blocksize < n) {
x->x_table = realloc(x->x_table, n * sizeof(float));
}
x->x_blocksize = n;
fillBlackman(x->x_table, x->x_blocksize);
}
for (i = 0; i < n; i++) {
*out++ = *(in++) * x->x_table[i];
}
return (w + 5);
}
static void blackman_dsp(t_blackman *x, t_signal **sp) {
dsp_add(blackman_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
}
static void* blackman_new(void) {
t_blackman *x = (t_blackman *)pd_new(blackman_class);
x->x_blocksize = DEFBLOCKSIZE;
x->x_table = malloc(x->x_blocksize * sizeof(float));
fillBlackman(x->x_table, x->x_blocksize);
outlet_new(&x->x_obj, gensym("signal"));
return (x);
}
static void blackman_free(t_blackman *x) {
free(x->x_table);
}
void blackman_tilde_setup(void) {
blackman_class = class_new(gensym("blackman~"),
(t_newmethod)blackman_new,
(t_method)blackman_free,
sizeof(t_blackman),
0,
A_DEFFLOAT,
0);
class_addmethod(blackman_class, nullfn, gensym("signal"), 0);
class_addmethod(blackman_class, (t_method)blackman_dsp, gensym("dsp"), 0);
}
#N canvas 230 69 553 535 10;
#X obj 4 484 cnv 15 550 20 empty \$0-pddp.cnv.footer empty 20 12 0
14 -228856 -66577 0;
#X obj 4 -17 cnv 15 550 40 empty \$0-pddp.cnv.header connes~ 3 12 0
18 -204280 -1 0;
#X obj 3 239 cnv 3 550 3 empty \$0-pddp.cnv.inlets inlets 15 12 0 13
-228856 -1 0;
#X obj 3 299 cnv 3 550 3 empty \$0-pddp.cnv.outlets outlet 15 12 0
13 -228856 -1 0;
#X obj 3 359 cnv 3 550 3 empty \$0-pddp.cnv.more_info more_info 15
12 0 13 -228856 -1 0;
#X obj 72 259 cnv 17 3 30 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856
-162280 0;
#X text 168 40 formula:;
#X floatatom 170 104 5 0 0 0 - - -;
#X obj 97 86 hsl 71 15 -1 1 0 0 empty empty empty -2 -6 0 10 -262144
-1 -1 7000 1;
#X msg 94 66 1;
#X obj 94 46 loadbang;
#X obj 102 363 pddp/pddplink http://en.wikipedia.org/wiki/Window_function
-text wikipedia: window functions;
#X obj 438 -14 import windowing;
#X msg 36 154 \; pd dsp 1;
#X text 21 85 height --->;
#X text 103 407 Windowing functions are used with FFTs. These transform
the signal block-by-block into a spectral representation whose resolution
in both the frequency and time domains are proportional to their size
(as a power-of-two in PD). The different windows have different characteristics
in terms of stopband attenuation and noise bandwidth.;
#X obj 170 122 sig~ 1;
#N canvas 0 0 450 300 graph5 0;
#X array \$0-connes 64 float 0;
#X coords 0 1 63 -1 200 140 1;
#X restore 301 55 graph;
#X text 169 52 cos(pi*x/2);
#X obj 72 319 cnv 17 3 30 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856
-162280 0;
#X obj 170 169 tabsend~ \$0-connes;
#X obj 170 143 connes~;
#X text 102 258 SIGNAL: the height (amplitude) of the window is controlled
by the signal on its inlet.;
#X text 103 317 SIGNAL: a connes window with size=dsp blocksize;
#X obj 102 392 pddp/pddplink http://mathworld.wolfram.com/ConnesFunction.html
-text mathworld link;
#X obj 102 377 pddp/pddplink http://en.wikipedia.org/wiki/Connes -text
wikipedia: Alain Connes;
#X obj 435 6 pddp/pddplink http://wiki.puredata.info/en/connes~ -text
pdpedia: connes~;
#X text 15 6 description: generates a connes window for each dsp block
;
#X connect 7 0 16 0;
#X connect 8 0 7 0;
#X connect 9 0 8 0;
#X connect 10 0 9 0;
#X connect 16 0 21 0;
#X connect 21 0 20 0;
/* connes~ - connes windowing function for Pure Data
**
** Copyright (C) 2002 Joseph A. Sarlo
**
** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** jsarlo@mambo.peabody.jhu.edu
*/
#include "m_pd.h"
#include <stdlib.h>
#ifdef _MSC_VER
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#define DEFBLOCKSIZE 64
void fillConnes(float *vec, int n) {
int i;
float xShift = (float)n / 2;
float x;
for (i = 0; i < n; i++) {
x = (i - xShift) / xShift;
vec[i] = (float)((1 - (x * x)) * (1 - (x * x)));
}
}
static t_class *connes_class;
typedef struct _connes {
t_object x_obj;
int x_blocksize;
float *x_table;
} t_connes;
static t_int* connes_perform(t_int *w) {
t_connes *x = (t_connes *)(w[1]);
t_float *in = (t_float *)(w[2]);
t_float *out = (t_float *)(w[3]);
int n = (int)(w[4]);
int i;
if (x->x_blocksize != n) {
if (x->x_blocksize < n) {
x->x_table = realloc(x->x_table, n * sizeof(float));
}
x->x_blocksize = n;
fillConnes(x->x_table, x->x_blocksize);
}
for (i = 0; i < n; i++) {
*out++ = *(in++) * x->x_table[i];
}
return (w + 5);
}
static void connes_dsp(t_connes *x, t_signal **sp) {
dsp_add(connes_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
}
static void* connes_new(void) {
t_connes *x = (t_connes *)pd_new(connes_class);
x->x_blocksize = DEFBLOCKSIZE;
x->x_table = malloc(x->x_blocksize * sizeof(float));
fillConnes(x->x_table, x->x_blocksize);
outlet_new(&x->x_obj, gensym("signal"));
return (x);
}
static void connes_free(t_connes *x) {
free(x->x_table);
}
void connes_tilde_setup(void) {
connes_class = class_new(gensym("connes~"),
(t_newmethod)connes_new,
(t_method)connes_free,
sizeof(t_connes),
0,
A_DEFFLOAT,
0);
class_addmethod(connes_class, nullfn, gensym("signal"), 0);
class_addmethod(connes_class, (t_method)connes_dsp, gensym("dsp"), 0);
}
#N canvas 230 69 567 494 10;
#X obj 4 454 cnv 15 550 20 empty \$0-pddp.cnv.footer empty 20 12 0
14 -228856 -66577 0;
#X obj 4 -17 cnv 15 550 40 empty \$0-pddp.cnv.header cosine~ 3 12 0
18 -204280 -1 0;
#X obj 3 239 cnv 3 550 3 empty \$0-pddp.cnv.inlets inlets 15 12 0 13
-228856 -1 0;
#X obj 3 299 cnv 3 550 3 empty \$0-pddp.cnv.outlets outlet 15 12 0
13 -228856 -1 0;
#X obj 3 359 cnv 3 550 3 empty \$0-pddp.cnv.more_info more_info 15
12 0 13 -228856 -1 0;
#X obj 72 259 cnv 17 3 30 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856
-162280 0;
#X text 168 40 formula:;
#X floatatom 170 104 5 0 0 0 - - -;
#X obj 97 86 hsl 71 15 -1 1 0 0 empty empty empty -2 -6 0 10 -262144
-1 -1 7000 1;
#X msg 94 66 1;
#X obj 94 46 loadbang;
#X obj 102 363 pddp/pddplink http://en.wikipedia.org/wiki/Window_function
-text wikipedia: window functions;
#X obj 438 -14 import windowing;
#X msg 36 154 \; pd dsp 1;
#X text 21 85 height --->;
#X text 103 377 Windowing functions are used with FFTs. These transform
the signal block-by-block into a spectral representation whose resolution
in both the frequency and time domains are proportional to their size
(as a power-of-two in PD). The different windows have different characteristics
in terms of stopband attenuation and noise bandwidth.;
#X obj 170 122 sig~ 1;
#X obj 170 143 cosine~;
#N canvas 0 0 450 300 graph5 0;
#X array \$0-cosine 64 float 0;
#X coords 0 1 63 -1 200 140 1;
#X restore 301 55 graph;
#X text 169 52 cos(pi*x/2);
#X text 15 6 description: generates a cosine window for each dsp block
;
#X obj 435 6 pddp/pddplink http://wiki.puredata.info/en/cosine~ -text
pdpedia: cosine~;
#X obj 170 169 tabsend~ \$0-cosine;
#X obj 72 319 cnv 17 3 30 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856
-162280 0;
#X text 102 258 SIGNAL: the height (amplitude) of the window is controled
by the signal on its inlet.;
#X text 103 317 SIGNAL: a cosine (otherwise known as a sine - actually
it's half a sine) window with size=dsp blocksize;
#X connect 7 0 16 0;
#X connect 8 0 7 0;
#X connect 9 0 8 0;
#X connect 10 0 9 0;
#X connect 16 0 17 0;
#X connect 17 0 22 0;
/* cosine~ - cosine windowing function for Pure Data
**
** Copyright (C) 2002 Joseph A. Sarlo
**
** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** jsarlo@mambo.peabody.jhu.edu
*/
#include "m_pd.h"
#include <stdlib.h>
#include <math.h>
#ifdef _WIN32
#define M_PI 3.14159265358979323846
#endif
#ifdef _MSC_VER
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#define DEFBLOCKSIZE 64
void fillCosine(float *vec, int n) {
int i;
float xShift = (float)n / 2;
float x;
for (i = 0; i < n; i++) {
x = (i - xShift) / xShift;
vec[i] = (float)cos(M_PI * x / 2);
}
}
static t_class *cosine_class;
typedef struct _cosine {
t_object x_obj;
int x_blocksize;
float *x_table;
} t_cosine;
static t_int* cosine_perform(t_int *w) {
t_cosine *x = (t_cosine *)(w[1]);
t_float *in = (t_float *)(w[2]);
t_float *out = (t_float *)(w[3]);
int n = (int)(w[4]);
int i;
if (x->x_blocksize != n) {
if (x->x_blocksize < n) {
x->x_table = realloc(x->x_table, n * sizeof(float));
}
x->x_blocksize = n;
fillCosine(x->x_table, x->x_blocksize);
}
for (i = 0; i < n; i++) {
*out++ = *(in++) * x->x_table[i];
}
return (w + 5);
}
static void cosine_dsp(t_cosine *x, t_signal **sp) {
dsp_add(cosine_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
}
static void* cosine_new(void) {
t_cosine *x = (t_cosine *)pd_new(cosine_class);
x->x_blocksize = DEFBLOCKSIZE;
x->x_table = malloc(x->x_blocksize * sizeof(float));
fillCosine(x->x_table, x->x_blocksize);
outlet_new(&x->x_obj, gensym("signal"));
return (x);
}
static void cosine_free(t_cosine *x) {
free(x->x_table);
}
void cosine_tilde_setup(void) {
cosine_class = class_new(gensym("cosine~"),
(t_newmethod)cosine_new,
(t_method)cosine_free,
sizeof(t_cosine),
0,
A_DEFFLOAT,
0);
class_addmethod(cosine_class, nullfn, gensym("signal"), 0);
class_addmethod(cosine_class, (t_method)cosine_dsp, gensym("dsp"), 0);
}
#N canvas 256 141 559 517 10;
#X obj 4 479 cnv 15 550 20 empty \$0-pddp.cnv.footer empty 20 12 0
14 -228856 -66577 0;
#X obj 4 -17 cnv 15 550 40 empty \$0-pddp.cnv.header gaussian~ 3 12
0 18 -204280 -1 0;
#X obj 3 239 cnv 3 550 3 empty \$0-pddp.cnv.inlets inlets 15 12 0 13
-228856 -1 0;
#X obj 3 319 cnv 3 550 3 empty \$0-pddp.cnv.outlets outlet 15 12 0
13 -228856 -1 0;
#X obj 3 359 cnv 3 550 3 empty \$0-pddp.cnv.more_info more_info 15
12 0 13 -228856 -1 0;
#X obj 72 259 cnv 17 3 30 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856
-162280 0;
#X text 168 40 formula:;
#X obj 97 86 hsl 71 15 -1 1 0 0 empty empty empty -2 -6 0 10 -262144
-1 -1 7000 1;
#X msg 94 66 1;
#X obj 94 46 loadbang;
#X obj 102 365 pddp/pddplink http://en.wikipedia.org/wiki/Window_function
-text wikipedia: window functions;
#X obj 438 -14 import windowing;
#X msg 36 154 \; pd dsp 1;
#X text 21 85 height --->;
#X obj 127 109 sig~ 1;
#N canvas 0 0 450 300 graph3 0;
#X array \$0-gaussian 64 float 0;
#X coords 0 1 63 -1 200 140 1;
#X restore 326 65 graph;
#X text 103 405 Windowing functions are used with FFTs. These transform
the signal block-by-block into a spectral representation whose resolution
in both the frequency and time domains are proportional to their size
(as a power-of-two in PD). The different windows have different characteristics
in terms of stopband attenuation and noise bandwidth.;
#X text 102 258 SIGNAL: the height (amplitude) of the window is controlled
by the signal on its inlet.;
#X text 15 6 description: generates a gaussian window for each dsp
block;
#X obj 435 6 pddp/pddplink http://wiki.puredata.info/en/gaussian~ -text
pdpedia: gaussian~;
#X obj 127 132 gaussian~;
#X obj 127 158 tabsend~ \$0-gaussian;
#X text 103 327 SIGNAL: a gaussian window with size=dsp blocksize;
#X obj 197 86 hsl 71 15 0 2 0 0 empty empty empty -2 -6 0 10 -262144
-1 -1 1750 1;
#X floatatom 192 105 5 0 0 0 - - -;
#X msg 121 66 0.5;
#X text 102 284 FLOAT: the width of the gaussian distribution curve
is controlled by floats in the inlet;
#X text 169 54 2^(-(x/d)^2);
#X obj 102 378 pddp/pddplink http://en.wikipedia.org/wiki/Gaussian_function
-text wikipedia: gaussian function;
#X obj 102 392 pddp/pddplink http://mathworld.wolfram.com/GaussianFunction.html
-text mathworld link;
#X obj 73 326 cnv 17 3 30 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856
-162280 0;
#X connect 7 0 14 0;
#X connect 8 0 7 0;
#X connect 9 0 8 0;
#X connect 9 0 25 0;
#X connect 14 0 20 0;
#X connect 20 0 21 0;
#X connect 23 0 24 0;
#X connect 24 0 20 0;
#X connect 25 0 23 0;
/* gaussian~ - gaussian windowing function for Pure Data
**
** Copyright (C) 2002 Joseph A. Sarlo
**
** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** jsarlo@mambo.peabody.jhu.edu
*/
#include "m_pd.h"
#include <stdlib.h>
#include <math.h>
#ifdef _MSC_VER
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#define DEFDELTA 0.5
#define DEFBLOCKSIZE 64
/* MSW and OSX don't appear to have single-precision ANSI math */
#if defined(_WIN32) || defined(__APPLE__)
#define powf pow
#endif
void fillGaussian(float *vec, int n, float delta) {
int i;
float xShift = (float)n / 2;
float x;
if (delta == 0) {
delta = 1;
}
for (i = 0; i < n; i++) {
x = (i - xShift) / xShift;
vec[i] = (float)(pow(2, (-1 * (x / delta) * (x / delta))));
}
}
static t_class *gaussian_class;