[PD-dev] i need some help with this
J. Scott Hildebrand
jshildebrand at ucdavis.edu
Sat Aug 31 01:28:40 CEST 2002
first off i think you can forget about the first email i sent.
i've included the .c code and the pd patch. all the convolution
stuff is commented out so you can compile and it try this if you want. i
almost have a working convolver to put in there, but i first need to make
sure i can get 1 mono file go into my external, and have the two convolved
signals outputted. right now something screwy is going on and i can't get
the stereo signal. thanks for any help!
scott
--------------------------------------------------------------------
"640K ought to be enough for anybody." -- Bill Gates, 1981
--------------------------------------------------------------------
-------------- next part --------------
#include "m_pd.h"
#include "fftr4.h"
#include <stdio.h>
/* this part declares the 3-dimensional array of hrtf data in memory */
static float bhrir_l[25][50][256];
static float bhrir_r[25][50][256];
static int apple=0, times=0;
static void readfile(void)
{
t_int az, el, i;
FILE *fid;
fid = fopen("hrir.bin", "r");
for(az=0; az<=24; az++)
{
for(el=0; el<=49; el++) /*takes from hrir.bin all hrtfs and arrays them*/
{
fread(bhrir_l[az][el], sizeof(float), 200, fid);
for(i=200; i<=255; i++){bhrir_l[az][el][i]=0;} /*adds 56 zeroes*/
fread(bhrir_r[az][el], sizeof(float), 200, fid);
for(i=200; i<=255; i++){bhrir_r[az][el][i]=0;}
}
}
}
static float aleftout[256];
static float arightout[256];
static t_class *newconv_tilde_class;
typedef struct _newconv_tilde {
t_object x_obj;
t_sample f_newconv;
t_sample f;
t_float secondfloat;
t_float firstfloat;
} t_newconv_tilde;
static t_int *newconv_tilde_perform(t_int *w)
{
t_newconv_tilde *x = (t_newconv_tilde *)(w[1]);
t_float *in1 = (t_float *)(w[2]);
t_float *in2 = (t_float *)(w[3]);
t_float *out1 = (t_float *)(w[4]);
t_float *out2 = (t_float *)(w[5]);
int n = (int)(w[6]);
int i;
t_int azi=0;
t_int ele=0;
t_int read;
t_int readpos;
apple = 0;
while (n--)
{
aleftout[apple] = in1[n];
arightout[apple] = in2[n];
apple++;
}//endwhile
if(apple == 256)
{
/* azi = (x->firstfloat - 1);
ele = (x->secondfloat - 1);
fftr4_256(aleftout);
fftr4_256(bhrir_l[azi][ele]);
fftr4_mul256(aleftout,bhrir_l[azi][ele]);
fftr4_scale256(aleftout);
fftr4_un256(aleftout);
fftr4_256(arightout);
fftr4_256(bhrir_r[azi][ele]);
fftr4_mul256(arightout,bhrir_r[azi][ele]);
fftr4_scale256(arightout);
fftr4_un256(arightout);
*/
for(readpos=255; readpos<=0; readpos--)
{
*(out1++) = aleftout[readpos];
*(out2++) = arightout[readpos];
}
}//endif
return (w+7);
}
static void newconv_tilde_dsp(t_newconv_tilde *x, t_signal **sp)
{
dsp_add(newconv_tilde_perform, 6, x,
sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[0]->s_n);
}
static void newconv_first(t_newconv_tilde *x, t_floatarg f)
{
x->firstfloat = f;
post("firstfloat is: %f", x->firstfloat);
}
static void newconv_bound(t_newconv_tilde *x, t_floatarg f)
{
x->secondfloat = f;
post("secondfloat is: %f", x->secondfloat);
}
static void *newconv_tilde_new(t_floatarg f)
{
t_newconv_tilde *x = (t_newconv_tilde *)pd_new(newconv_tilde_class);
x->f_newconv = f;
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
/*floatinlet_new (&x->x_obj, &x->f_newconv); */ /* accessing x->x_newconv gives the (last) value of this input (float) */
/* just another float inlet: */
inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("first"));
inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("bound"));
outlet_new(&x->x_obj, &s_signal);
outlet_new(&x->x_obj, &s_signal); /* second outlet for stereo */
return (void *)x;
}
void newconv_tilde_setup(void) {
newconv_tilde_class = class_new(gensym("newconv~"),
(t_newmethod)newconv_tilde_new,
0, sizeof(t_newconv_tilde),
CLASS_DEFAULT,
A_DEFFLOAT, 0);
class_addmethod(newconv_tilde_class, (t_method)newconv_tilde_dsp, gensym("dsp"), 0);
class_addmethod(newconv_tilde_class, (t_method)newconv_first, gensym("first"), A_FLOAT, 0);
class_addmethod(newconv_tilde_class, (t_method)newconv_bound, gensym("bound"), A_FLOAT, 0); /* calls a function newconv_bound when a float arrives */
CLASS_MAINSIGNALIN(newconv_tilde_class, t_newconv_tilde, f);
}
-------------- next part --------------
#N canvas 12 165 276 380 10;
#X obj 103 322 dac~;
#N canvas 675 392 494 403 convolution 1;
#X obj 82 31 bng 15 250 50 0 empty empty empty 20 8 0 8 -262144 -1
-1;
#X obj 88 76 t b b;
#X msg 111 125 open archim20.WAV;
#X msg 93 175 1;
#X msg 68 206 0;
#X obj 144 236 readsf~;
#X obj 286 82 inlet;
#X obj 427 89 inlet;
#X obj 100 346 outlet~;
#X obj 213 347 outlet~;
#X obj 110 299 newconv~;
#X obj 304 22 block~ 256 1;
#X connect 0 0 1 0;
#X connect 1 0 3 0;
#X connect 1 1 2 0;
#X connect 2 0 5 0;
#X connect 3 0 5 0;
#X connect 4 0 5 0;
#X connect 5 0 10 0;
#X connect 5 0 10 1;
#X connect 6 0 10 2;
#X connect 7 0 10 3;
#X connect 10 0 8 0;
#X connect 10 1 9 0;
#X restore 27 239 pd convolution;
#X obj 41 52 vsl 15 128 1 25 0 0 empty empty empty 20 8 0 8 -260818
-1 -1 0 1;
#X obj 95 52 vsl 15 128 1 50 0 0 empty empty empty 20 8 0 8 -128992
-1 -1 0 1;
#X text 22 23 azimuth;
#X text 81 22 elevation;
#X connect 1 0 0 0;
#X connect 1 1 0 1;
#X connect 2 0 1 0;
#X connect 3 0 1 1;
More information about the Pd-dev
mailing list