#include "m_pd.h" #include "fftr4.h" #include 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); }