aboutsummaryrefslogtreecommitdiff
path: root/src/bin_ambi_reduced_decode2.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin_ambi_reduced_decode2.c')
-rw-r--r--src/bin_ambi_reduced_decode2.c175
1 files changed, 88 insertions, 87 deletions
diff --git a/src/bin_ambi_reduced_decode2.c b/src/bin_ambi_reduced_decode2.c
index d8bc40a..cfb50eb 100644
--- a/src/bin_ambi_reduced_decode2.c
+++ b/src/bin_ambi_reduced_decode2.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"
#include "iemlib.h"
@@ -51,7 +51,7 @@ typedef struct _bin_ambi_reduced_decode2
BIN_AMBI_COMPLEX *x_spec;
BIN_AMBI_COMPLEX *x_sin_cos;
iemarray_t *x_beg_fade_out_hrir;
- float *x_beg_hrir;
+ t_float *x_beg_hrir;
iemarray_t **x_beg_hrtf_re;
iemarray_t **x_beg_hrtf_im;
t_symbol **x_hrir_filename;
@@ -79,20 +79,20 @@ static t_class *bin_ambi_reduced_decode2_class;
static void bin_ambi_reduced_decode2_init_cos(t_bin_ambi_reduced_decode2 *x)
{/* initialize a whole sine and cosine wave over a fftsize array */
int i, fftsize = x->x_fftsize;
- float f, g;
+ t_float f, g;
BIN_AMBI_COMPLEX *sincos = x->x_sin_cos;
- g = 2.0f * 3.1415926538f / (float)fftsize;
+ g = 2.0f * 3.1415926538f / (t_float)fftsize;
for(i=0; i<fftsize; i++)
{
- f = g * (float)i;
+ f = g * (t_float)i;
(*sincos).real = cos(f);
(*sincos).imag = -sin(f); /*FFT*/
sincos++;
}
}
-static void bin_ambi_reduced_decode2_quant(t_bin_ambi_reduced_decode2 *x, double *delta_deg2rad, double *phi_deg2rad, int index)
+static void bin_ambi_reduced_decode2_quant(t_bin_ambi_reduced_decode2 *x, double *delta_deg2rad, double *phi_deg2rad, int xindex)
{
double q = 1.0;
double d = *delta_deg2rad;
@@ -188,8 +188,8 @@ static void bin_ambi_reduced_decode2_quant(t_bin_ambi_reduced_decode2 *x, double
p = (double)i;
*phi_deg2rad = p;
- x->x_delta[index] = (int)(*delta_deg2rad);
- x->x_phi[index] = i;
+ x->x_delta[xindex] = (int)(*delta_deg2rad);
+ x->x_phi[xindex] = i;
*delta_deg2rad *= x->x_pi_over_180;
*phi_deg2rad *= x->x_pi_over_180;
@@ -199,7 +199,7 @@ static void bin_ambi_reduced_decode2_do_2d(t_bin_ambi_reduced_decode2 *x, int ar
{
double delta=0.0, phi;
double *dw = x->x_transp;
- int index;
+ int xindex;
int order=x->x_n_order;
int n_ls = x->x_n_ls;
@@ -208,17 +208,17 @@ static void bin_ambi_reduced_decode2_do_2d(t_bin_ambi_reduced_decode2 *x, int ar
post("bin_ambi_reduced_decode2 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(index >= n_ls)
- index = n_ls - 1;
+ if(xindex < 0)
+ xindex = 0;
+ if(xindex >= n_ls)
+ xindex = n_ls - 1;
- bin_ambi_reduced_decode2_quant(x, &delta, &phi, index);
+ bin_ambi_reduced_decode2_quant(x, &delta, &phi, xindex);
- dw += index * x->x_n_ambi;
+ dw += xindex * x->x_n_ambi;
*dw++ = 1.0;
*dw++ = cos(phi);
@@ -295,7 +295,7 @@ static void bin_ambi_reduced_decode2_do_3d(t_bin_ambi_reduced_decode2 *x, int ar
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 n_ls=x->x_n_ls;
int order=x->x_n_order;
@@ -304,23 +304,23 @@ static void bin_ambi_reduced_decode2_do_3d(t_bin_ambi_reduced_decode2 *x, int ar
post("bin_ambi_reduced_decode2 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(index >= n_ls)
- index = n_ls - 1;
+ if(xindex < 0)
+ xindex = 0;
+ if(xindex >= n_ls)
+ xindex = n_ls - 1;
- bin_ambi_reduced_decode2_quant(x, &delta, &phi, index);
+ bin_ambi_reduced_decode2_quant(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;
@@ -622,7 +622,7 @@ static void bin_ambi_reduced_decode2_inverse(t_bin_ambi_reduced_decode2 *x)
nz = bin_ambi_reduced_decode2_eval_which_element_of_col_not_zero(x, i, i);
if(nz < 0)
{
- post("bin_ambi_reduced_decode2 ERROR: matrix not regular !!!!");
+ post("bin_ambi_reduced_decode2 ERROR: matrix singular !!!!");
x->x_seq_ok = 0;
return;
}
@@ -690,38 +690,38 @@ n_ambi columns;
n_ambi rows;
*/
-static void bin_ambi_reduced_decode2_load_HRIR(t_bin_ambi_reduced_decode2 *x, float findex)
+static void bin_ambi_reduced_decode2_load_HRIR(t_bin_ambi_reduced_decode2 *x, t_float findex)
{
- int index=(int)findex - 1;
+ int xindex=(int)findex - 1;
int p;
char buf[60];
- if(index < 0)
- index = 0;
- if(index >= x->x_n_ls)
- index = x->x_n_ls - 1;
+ if(xindex < 0)
+ xindex = 0;
+ if(xindex >= x->x_n_ls)
+ xindex = x->x_n_ls - 1;
- p = x->x_phi[index];
+ p = x->x_phi[xindex];
if(p)/*change*/
p = 360 - p;
if(p < 10)
- sprintf(buf, "L%de00%da.wav", x->x_delta[index], p);
+ sprintf(buf, "L%de00%da.wav", x->x_delta[xindex], p);
else if(p < 100)
- sprintf(buf, "L%de0%da.wav", x->x_delta[index], p);
+ sprintf(buf, "L%de0%da.wav", x->x_delta[xindex], p);
else
- sprintf(buf, "L%de%da.wav", x->x_delta[index], p);
- x->x_hrir_filename[index] = gensym(buf);
+ sprintf(buf, "L%de%da.wav", x->x_delta[xindex], p);
+ x->x_hrir_filename[xindex] = gensym(buf);
- 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_decode2_check_HRIR_arrays(t_bin_ambi_reduced_decode2 *x, float findex)
+static void bin_ambi_reduced_decode2_check_HRIR_arrays(t_bin_ambi_reduced_decode2 *x, t_float findex)
{
- int index=(int)findex - 1;
+ int xindex=(int)findex - 1;
int j, k, n;
int fftsize = x->x_fftsize;
int fs2=fftsize/2;
@@ -730,14 +730,14 @@ static void bin_ambi_reduced_decode2_check_HRIR_arrays(t_bin_ambi_reduced_decode
t_symbol *hrir;
iemarray_t *vec_hrir, *vec_fade_out_hrir;
t_float *vec;
- float decr, sum;
+ t_float decr, sum;
- if(index < 0)
- index = 0;
- if(index >= x->x_n_ls)
- index = x->x_n_ls - 1;
+ if(xindex < 0)
+ xindex = 0;
+ if(xindex >= x->x_n_ls)
+ xindex = x->x_n_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))
@@ -749,7 +749,7 @@ static void bin_ambi_reduced_decode2_check_HRIR_arrays(t_bin_ambi_reduced_decode
post("bin_ambi_reduced_decode2-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)
{
@@ -765,7 +765,7 @@ static void bin_ambi_reduced_decode2_check_HRIR_arrays(t_bin_ambi_reduced_decode
for(j=0; j<n; j++)
vec[j] = iemarray_getfloat(vec_hrir,j);
sum = 1.0f;
- decr = 4.0f / (float)fs2;
+ decr = 4.0f / (t_float)fs2;
for(j=n, k=0; j<fs2; j++, k++)
{
sum -= decr;
@@ -775,22 +775,22 @@ static void bin_ambi_reduced_decode2_check_HRIR_arrays(t_bin_ambi_reduced_decode
}
}
-static void bin_ambi_reduced_decode2_check_HRTF_arrays(t_bin_ambi_reduced_decode2 *x, float findex)
+static void bin_ambi_reduced_decode2_check_HRTF_arrays(t_bin_ambi_reduced_decode2 *x, t_float 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);
@@ -806,14 +806,14 @@ static void bin_ambi_reduced_decode2_check_HRTF_arrays(t_bin_ambi_reduced_decode
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_decode2_calc_reduced(t_bin_ambi_reduced_decode2 *x, float findex)
+static void bin_ambi_reduced_decode2_calc_reduced(t_bin_ambi_reduced_decode2 *x, t_float 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;
@@ -824,20 +824,20 @@ static void bin_ambi_reduced_decode2_calc_reduced(t_bin_ambi_reduced_decode2 *x,
double *dv, *db=x->x_prod;
int n_ambi = x->x_n_ambi;
int n_ls = x->x_n_ls;
- float mul;
+ t_float mul;
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;
- mul = (float)(*dv);
+ 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*/
{
@@ -848,7 +848,7 @@ static void bin_ambi_reduced_decode2_calc_reduced(t_bin_ambi_reduced_decode2 *x,
for(j=1; j<n_ls; j++)
{
dv += n_ambi;
- mul = (float)(*dv);
+ mul = (t_float)(*dv);
vec_hrir = x->x_beg_hrir;
vec_hrir += j * fftsize;
for(k=0; k<fftsize; k++)
@@ -902,18 +902,19 @@ static void bin_ambi_reduced_decode2_calc_reduced(t_bin_ambi_reduced_decode2 *x,
val[i] = old1;
}
}
- for(i = 0; i<fs2; i++)
- {
- iemarray_getfloat(vec_hrtf_re,i) = val[i].real;
- iemarray_getfloat(vec_hrtf_im,i) = val[i].imag;
- }
- iemarray_getfloat(vec_hrtf_re,fs2) = val[fs2].real;
- iemarray_getfloat(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, 0, val[0].real);
+ for(i = 1; i<fs2; i++)
+ {
+ iemarray_setfloat(vec_hrtf_re, i, val[i].real);
+ iemarray_setfloat(vec_hrtf_im, i, val[i].imag);
+ }
+ 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_setfloat(vec_hrtf_re, i, 0.0f);
+ iemarray_setfloat(vec_hrtf_im, i, 0.0f);
+ }
}
}
@@ -1038,7 +1039,7 @@ static void bin_ambi_reduced_decode2_decoding(t_bin_ambi_reduced_decode2 *x)
SETFLOAT(x->x_at, 1.0f);
else if(plus_minus[i] == '-')
SETFLOAT(x->x_at, 2.0f);
- SETFLOAT(x->x_at+1, (float)(i+1));
+ SETFLOAT(x->x_at+1, (t_float)(i+1));
outlet_list(x->x_out_sign_sum, &s_list, 2, x->x_at);
}
}
@@ -1115,9 +1116,9 @@ static void bin_ambi_reduced_decode2_free(t_bin_ambi_reduced_decode2 *x)
freebytes(x->x_spec, x->x_fftsize * sizeof(BIN_AMBI_COMPLEX));
freebytes(x->x_sin_cos, x->x_fftsize * sizeof(BIN_AMBI_COMPLEX));
- freebytes(x->x_beg_hrir, x->x_fftsize * x->x_n_ls * sizeof(float));
- freebytes(x->x_beg_hrtf_re, x->x_n_ambi * sizeof(float *));
- freebytes(x->x_beg_hrtf_im, x->x_n_ambi * sizeof(float *));
+ freebytes(x->x_beg_hrir, x->x_fftsize * x->x_n_ls * 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 *));
}
/*
@@ -1287,7 +1288,7 @@ static void *bin_ambi_reduced_decode2_new(t_symbol *s, int argc, t_atom *argv)
x->x_sin_cos = (BIN_AMBI_COMPLEX *)getbytes(x->x_fftsize * sizeof(BIN_AMBI_COMPLEX));
x->x_beg_fade_out_hrir = 0;
- x->x_beg_hrir = (float *)getbytes(x->x_fftsize * x->x_n_ls * sizeof(float));
+ x->x_beg_hrir = (t_float *)getbytes(x->x_fftsize * x->x_n_ls * sizeof(t_float));
x->x_beg_hrtf_re = (iemarray_t **)getbytes(x->x_n_ambi * sizeof(iemarray_t *));
x->x_beg_hrtf_im = (iemarray_t **)getbytes(x->x_n_ambi * sizeof(iemarray_t *));