aboutsummaryrefslogtreecommitdiff
path: root/src/bin_ambi_reduced_decode_fft2.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin_ambi_reduced_decode_fft2.c')
-rw-r--r--src/bin_ambi_reduced_decode_fft2.c141
1 files changed, 71 insertions, 70 deletions
diff --git a/src/bin_ambi_reduced_decode_fft2.c b/src/bin_ambi_reduced_decode_fft2.c
index d629787..9d0e11d 100644
--- a/src/bin_ambi_reduced_decode_fft2.c
+++ b/src/bin_ambi_reduced_decode_fft2.c
@@ -1,7 +1,7 @@
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
-iem_bin_ambi written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */
+iem_bin_ambi written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2009 */
#include "m_pd.h"
@@ -95,7 +95,7 @@ static void bin_ambi_reduced_decode_fft2_init_cos(t_bin_ambi_reduced_decode_fft2
}
}
-static void bin_ambi_reduced_decode_fft2_convert(t_bin_ambi_reduced_decode_fft2 *x, double *delta_deg2rad, double *phi_deg2rad, int index)
+static void bin_ambi_reduced_decode_fft2_convert(t_bin_ambi_reduced_decode_fft2 *x, double *delta_deg2rad, double *phi_deg2rad, int xindex)
{
double q = 1.0;
double d = *delta_deg2rad;
@@ -111,8 +111,8 @@ static void bin_ambi_reduced_decode_fft2_convert(t_bin_ambi_reduced_decode_fft2
while(p >= 360.0)
p -= 360.0;
- x->x_delta[index] = (int)(d);
- x->x_phi[index] = (int)(p);
+ x->x_delta[xindex] = (int)(d);
+ x->x_phi[xindex] = (int)(p);
*delta_deg2rad = d*x->x_pi_over_180;
*phi_deg2rad = p*x->x_pi_over_180;
@@ -122,7 +122,7 @@ static void bin_ambi_reduced_decode_fft2_do_2d(t_bin_ambi_reduced_decode_fft2 *x
{
double delta=0.0, phi;
double *dw = x->x_transp;
- int index;
+ int xindex;
int order=x->x_n_order;
if(argc < 2)
@@ -130,23 +130,23 @@ static void bin_ambi_reduced_decode_fft2_do_2d(t_bin_ambi_reduced_decode_fft2 *x
post("bin_ambi_reduced_decode_fft2 ERROR: ls-input needs 1 index and 1 angle: ls_index + phi [degree]");
return;
}
- index = (int)atom_getint(argv++) - 1;
+ xindex = (int)atom_getint(argv++) - 1;
phi = (double)atom_getfloat(argv);
- if(index < 0)
- index = 0;
+ if(xindex < 0)
+ xindex = 0;
if(mode == BIN_AMBI_LS_REAL)
{
- if(index >= x->x_n_real_ls)
- index = x->x_n_real_ls - 1;
+ if(xindex >= x->x_n_real_ls)
+ xindex = x->x_n_real_ls - 1;
}
else if(mode == BIN_AMBI_LS_PHT)
{
if(x->x_n_pht_ls)
{
- if(index >= x->x_n_pht_ls)
- index = x->x_n_pht_ls - 1;
- index += x->x_n_real_ls;
+ if(xindex >= x->x_n_pht_ls)
+ xindex = x->x_n_pht_ls - 1;
+ xindex += x->x_n_real_ls;
}
else
return;
@@ -154,9 +154,9 @@ static void bin_ambi_reduced_decode_fft2_do_2d(t_bin_ambi_reduced_decode_fft2 *x
else
return;
- bin_ambi_reduced_decode_fft2_convert(x, &delta, &phi, index);
+ bin_ambi_reduced_decode_fft2_convert(x, &delta, &phi, xindex);
- dw += index * x->x_n_ambi;
+ dw += xindex * x->x_n_ambi;
*dw++ = 1.0;
*dw++ = cos(phi);
@@ -233,7 +233,7 @@ static void bin_ambi_reduced_decode_fft2_do_3d(t_bin_ambi_reduced_decode_fft2 *x
double delta, phi;
double cd, sd, cd2, cd3, sd2, csd, cp, sp, cp2, sp2, cp3, sp3, cp4, sp4;
double *dw = x->x_transp;
- int index;
+ int xindex;
int order=x->x_n_order;
if(argc < 3)
@@ -241,24 +241,24 @@ static void bin_ambi_reduced_decode_fft2_do_3d(t_bin_ambi_reduced_decode_fft2 *x
post("bin_ambi_reduced_decode_fft2 ERROR: ls-input needs 1 index and 2 angles: ls index + delta [degree] + phi [degree]");
return;
}
- index = (int)atom_getint(argv++) - 1;
+ xindex = (int)atom_getint(argv++) - 1;
delta = atom_getfloat(argv++);
phi = atom_getfloat(argv);
- if(index < 0)
- index = 0;
+ if(xindex < 0)
+ xindex = 0;
if(mode == BIN_AMBI_LS_REAL)
{
- if(index >= x->x_n_real_ls)
- index = x->x_n_real_ls - 1;
+ if(xindex >= x->x_n_real_ls)
+ xindex = x->x_n_real_ls - 1;
}
else if(mode == BIN_AMBI_LS_PHT)
{
if(x->x_n_pht_ls)
{
- if(index >= x->x_n_pht_ls)
- index = x->x_n_pht_ls - 1;
- index += x->x_n_real_ls;
+ if(xindex >= x->x_n_pht_ls)
+ xindex = x->x_n_pht_ls - 1;
+ xindex += x->x_n_real_ls;
}
else
return;
@@ -266,14 +266,14 @@ static void bin_ambi_reduced_decode_fft2_do_3d(t_bin_ambi_reduced_decode_fft2 *x
else
return;
- bin_ambi_reduced_decode_fft2_convert(x, &delta, &phi, index);
+ bin_ambi_reduced_decode_fft2_convert(x, &delta, &phi, xindex);
cd = cos(delta);
sd = sin(delta);
cp = cos(phi);
sp = sin(phi);
- dw += index * x->x_n_ambi;
+ dw += xindex * x->x_n_ambi;
*dw++ = 1.0;
@@ -637,7 +637,7 @@ static void bin_ambi_reduced_decode_fft2_inverse(t_bin_ambi_reduced_decode_fft2
}
}
- post("matrix_inverse nonsingular");
+ post("matrix_inverse regular");
x->x_seq_ok = 1;
}
@@ -715,7 +715,7 @@ static void bin_ambi_reduced_decode_fft2_ipht_ireal_muladd(t_bin_ambi_reduced_de
static void bin_ambi_reduced_decode_fft2_load_HRIR(t_bin_ambi_reduced_decode_fft2 *x, t_symbol *s, int argc, t_atom *argv)
{
- int index;
+ int xindex;
t_symbol *hrirname;
if(argc < 2)
@@ -723,38 +723,38 @@ static void bin_ambi_reduced_decode_fft2_load_HRIR(t_bin_ambi_reduced_decode_fft
post("bin_ambi_reduced_decode_fft2 ERROR: load_HRIR needs 1 index and 1 HRIR-wav");
return;
}
- index = (int)atom_getint(argv++) - 1;
+ xindex = (int)atom_getint(argv++) - 1;
hrirname = atom_getsymbol(argv);
- if(index < 0)
- index = 0;
- if(index >= x->x_n_real_ls)
- index = x->x_n_real_ls - 1;
- x->x_hrir_filename[index] = hrirname;
+ if(xindex < 0)
+ xindex = 0;
+ if(xindex >= x->x_n_real_ls)
+ xindex = x->x_n_real_ls - 1;
+ x->x_hrir_filename[xindex] = hrirname;
- SETSYMBOL(x->x_at, x->x_hrir_filename[index]);
- SETSYMBOL(x->x_at+1, x->x_s_hrir[index]);
+ SETSYMBOL(x->x_at, x->x_hrir_filename[xindex]);
+ SETSYMBOL(x->x_at+1, x->x_s_hrir[xindex]);
outlet_list(x->x_obj.ob_outlet, &s_list, 2, x->x_at);
}
static void bin_ambi_reduced_decode_fft2_check_HRIR_arrays(t_bin_ambi_reduced_decode_fft2 *x, t_floatarg findex)
{
- int index=(int)findex - 1;
+ int xindex=(int)findex - 1;
int j, k, n;
int fftsize = x->x_fftsize;
int fs2=fftsize/2;
t_garray *a;
int npoints;
t_symbol *hrir;
- t_float*vec;
+ t_float *vec;
iemarray_t *vec_hrir, *vec_fade_out_hrir;
t_float decr, sum;
- if(index < 0)
- index = 0;
- if(index >= x->x_n_real_ls)
- index = x->x_n_real_ls - 1;
+ if(xindex < 0)
+ xindex = 0;
+ if(xindex >= x->x_n_real_ls)
+ xindex = x->x_n_real_ls - 1;
- hrir = x->x_s_hrir[index];
+ hrir = x->x_s_hrir[xindex];
if (!(a = (t_garray *)pd_findbyclass(hrir, garray_class)))
error("%s: no such array", hrir->s_name);
else if (!iemarray_getarray(a, &npoints, &vec_hrir))
@@ -766,7 +766,7 @@ static void bin_ambi_reduced_decode_fft2_check_HRIR_arrays(t_bin_ambi_reduced_de
post("bin_ambi_reduced_decode_fft2-WARNING: %s-array-size: %d < FFT-size: %d", hrir->s_name, npoints, fftsize);
}
vec = x->x_beg_hrir;
- vec += index * fftsize;
+ vec += xindex * fftsize;
if(x->x_beg_fade_out_hrir)
{
@@ -794,20 +794,20 @@ static void bin_ambi_reduced_decode_fft2_check_HRIR_arrays(t_bin_ambi_reduced_de
static void bin_ambi_reduced_decode_fft2_check_HRTF_arrays(t_bin_ambi_reduced_decode_fft2 *x, t_floatarg findex)
{
- int index=(int)findex - 1;
+ int xindex=(int)findex - 1;
t_garray *a;
int npoints;
int fftsize = x->x_fftsize;
iemarray_t *vec_hrtf_re, *vec_hrtf_im;
t_symbol *hrtf_re, *hrtf_im;
- if(index < 0)
- index = 0;
- if(index >= x->x_n_ambi)
- index = x->x_n_ambi - 1;
+ if(xindex < 0)
+ xindex = 0;
+ if(xindex >= x->x_n_ambi)
+ xindex = x->x_n_ambi - 1;
- hrtf_re = x->x_s_hrtf_re[index];
- hrtf_im = x->x_s_hrtf_im[index];
+ hrtf_re = x->x_s_hrtf_re[xindex];
+ hrtf_im = x->x_s_hrtf_im[xindex];
if (!(a = (t_garray *)pd_findbyclass(hrtf_re, garray_class)))
error("%s: no such array", hrtf_re->s_name);
@@ -823,14 +823,14 @@ static void bin_ambi_reduced_decode_fft2_check_HRTF_arrays(t_bin_ambi_reduced_de
error("%s: bad array-size: %d", hrtf_im->s_name, npoints);
else
{
- x->x_beg_hrtf_re[index] = vec_hrtf_re;
- x->x_beg_hrtf_im[index] = vec_hrtf_im;
+ x->x_beg_hrtf_re[xindex] = vec_hrtf_re;
+ x->x_beg_hrtf_im[xindex] = vec_hrtf_im;
}
}
static void bin_ambi_reduced_decode_fft2_calc_reduced(t_bin_ambi_reduced_decode_fft2 *x, t_floatarg findex)
{
- int index=(int)findex - 1;
+ int xindex=(int)findex - 1;
int i, j, k, w_index, w_inc, i_inc, v_index, fs1, fs2;
int fftsize = x->x_fftsize;
BIN_AMBI_COMPLEX old1, old2, w;
@@ -845,15 +845,15 @@ static void bin_ambi_reduced_decode_fft2_calc_reduced(t_bin_ambi_reduced_decode_
if(x->x_seq_ok)
{
- if(index < 0)
- index = 0;
- if(index >= n_ambi)
- index = n_ambi - 1;
+ if(xindex < 0)
+ xindex = 0;
+ if(xindex >= n_ambi)
+ xindex = n_ambi - 1;
- vec_hrtf_re = x->x_beg_hrtf_re[index];
- vec_hrtf_im = x->x_beg_hrtf_im[index];
+ vec_hrtf_re = x->x_beg_hrtf_re[xindex];
+ vec_hrtf_im = x->x_beg_hrtf_im[xindex];
- dv = db + index;
+ dv = db + xindex;
mul = (t_float)(*dv);
vec_hrir = x->x_beg_hrir;
for(k=0; k<fftsize; k++)/*first step of acumulating the HRIRs*/
@@ -919,17 +919,18 @@ static void bin_ambi_reduced_decode_fft2_calc_reduced(t_bin_ambi_reduced_decode_
val[i] = old1;
}
}
- for(i = 0; i<fs2; i++)
+ iemarray_setfloat(vec_hrtf_re, 0, val[0].real);
+ for(i = 1; i<fs2; i++)
{
- iemarray_getfloat(vec_hrtf_re, i) = val[i].real;
- iemarray_getfloat(vec_hrtf_im, i) = val[i].imag;
+ iemarray_setfloat(vec_hrtf_re, i, val[i].real);
+ iemarray_setfloat(vec_hrtf_im, i, val[i].imag);
}
- iemarray_getfloat(vec_hrtf_re, fs2) = val[fs2].real;
- iemarray_getfloat(vec_hrtf_im, fs2) = 0.0f;
+ iemarray_setfloat(vec_hrtf_re, fs2, val[fs2].real);
+ iemarray_setfloat(vec_hrtf_im, fs2, 0.0f);
for(i = fs2+1; i < fftsize; i++)
{
- iemarray_getfloat(vec_hrtf_re, i) = 0.0f;
- iemarray_getfloat(vec_hrtf_im, i) = 0.0f;
+ iemarray_setfloat(vec_hrtf_re, i, 0.0f);
+ iemarray_setfloat(vec_hrtf_im, i, 0.0f);
}
}
}
@@ -1134,8 +1135,8 @@ static void bin_ambi_reduced_decode_fft2_free(t_bin_ambi_reduced_decode_fft2 *x)
freebytes(x->x_sin_cos, x->x_fftsize * sizeof(BIN_AMBI_COMPLEX));
freebytes(x->x_beg_hrir, x->x_fftsize * x->x_n_real_ls * sizeof(t_float));
- freebytes(x->x_beg_hrtf_re, x->x_n_ambi * sizeof(t_float *));
- freebytes(x->x_beg_hrtf_im, x->x_n_ambi * sizeof(t_float *));
+ freebytes(x->x_beg_hrtf_re, x->x_n_ambi * sizeof(iemarray_t *));
+ freebytes(x->x_beg_hrtf_im, x->x_n_ambi * sizeof(iemarray_t *));
}
/*