[PD-dev] convolution code i'm working on
J. Scott Hildebrand
jshildebrand at ucdavis.edu
Fri Aug 30 22:05:18 CEST 2002
the gist of what's going on is in the perform function, and i have
some basic pd stuff in the subpatch. what i'm trying to do is bring in 256
samples at once, do my convolution and then send 4 64-size sample blocks
to the soundcard. i was told that the outlet~ from the subpatch would
convert the sample size and send each 4 blocks to the dac~ object. i
keep getting seg faults and i don't know why. it's not much code in the
external so if somebody could take a look at what i did i'd appreciate it.
thanks!
scott
--------------------------------------------------------------------
"640K ought to be enough for anybody." -- Bill Gates, 1981
--------------------------------------------------------------------
-------------- next part --------------
#include "m_pd.h"
#include "fftr4.h"
#include <stdio.h>
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 *convaudio_tilde_class;
typedef struct _convaudio_tilde {
t_object x_obj;
t_sample f_convaudio;
t_sample f;
t_float secondfloat;
t_float firstfloat;
} t_convaudio_tilde;
t_int *convaudio_tilde_perform(t_int *w)
{
t_convaudio_tilde *x = (t_convaudio_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]);
t_float *tempout1;
t_float *tempout2;
int n = (int)(w[6]);
int i;
t_int read;
t_int azi;
t_int ele;
t_int readpos;
t_float lsum = 0.0;
t_float rsum = 0.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=0; readpos<256; readpos++)
{
*(out2++) = aleftout[readpos];
*(out1++) = arightout[readpos];
}
}//endif
return (w+7);
} // endperform
void convaudio_tilde_dsp(t_convaudio_tilde *x, t_signal **sp)
{
dsp_add(convaudio_tilde_perform, 6, x,
sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[0]->s_n);
}
void *convaudio_tilde_new(t_floatarg f)
{
t_convaudio_tilde *x = (t_convaudio_tilde *)pd_new(convaudio_tilde_class);
x->f_convaudio = f;
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
floatinlet_new (&x->x_obj, &x->f_convaudio);
outlet_new(&x->x_obj, &s_signal);
outlet_new(&x->x_obj, &s_signal); /* second outlet for stereo */
return (void *)x;
}
void convaudio_tilde_setup(void) {
convaudio_tilde_class = class_new(gensym("convaudio~"),
(t_newmethod)convaudio_tilde_new,
0, sizeof(t_convaudio_tilde),
CLASS_DEFAULT,
A_DEFFLOAT, 0);
class_addmethod(convaudio_tilde_class,
(t_method)convaudio_tilde_dsp, gensym("dsp"), 0);
CLASS_MAINSIGNALIN(convaudio_tilde_class, t_convaudio_tilde, f);
}
-------------- next part --------------
#N canvas 101 140 712 638 10;
#X obj 388 350 dac~;
#N canvas 656 261 600 400 convolution 1;
#X obj 110 299 convaudio~;
#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 304 22 block~ 256;
#X connect 0 0 9 0;
#X connect 0 1 10 0;
#X connect 1 0 2 0;
#X connect 2 0 4 0;
#X connect 2 1 3 0;
#X connect 3 0 6 0;
#X connect 4 0 6 0;
#X connect 5 0 6 0;
#X connect 6 0 0 0;
#X connect 6 0 0 1;
#X restore 312 267 pd convolution;
More information about the Pd-dev
mailing list