aboutsummaryrefslogtreecommitdiff
path: root/src/bin_ambi_reduced_decode_fft.c
diff options
context:
space:
mode:
authormusil <tmusil@users.sourceforge.net>2009-02-01 07:30:18 +0000
committermusil <tmusil@users.sourceforge.net>2009-02-01 07:30:18 +0000
commite9c0f3b6a6ec5ff6280c7955972cbbd6e336c4dd (patch)
tree8baa59caf1a4e08c718b56c44637d9224e1b52fb /src/bin_ambi_reduced_decode_fft.c
parenta30cbb586a36c7f3485b46e990ef485fd8a8da58 (diff)
changed for 64 bit array access
svn path=/trunk/externals/iem/iem_bin_ambi/; revision=10708
Diffstat (limited to 'src/bin_ambi_reduced_decode_fft.c')
-rw-r--r--src/bin_ambi_reduced_decode_fft.c219
1 files changed, 110 insertions, 109 deletions
diff --git a/src/bin_ambi_reduced_decode_fft.c b/src/bin_ambi_reduced_decode_fft.c
index 696f5ea..04b4e0c 100644
--- a/src/bin_ambi_reduced_decode_fft.c
+++ b/src/bin_ambi_reduced_decode_fft.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"
@@ -55,7 +55,7 @@ typedef struct _bin_ambi_reduced_decode_fft
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;
@@ -83,20 +83,20 @@ static t_class *bin_ambi_reduced_decode_fft_class;
static void bin_ambi_reduced_decode_fft_init_cos(t_bin_ambi_reduced_decode_fft *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_decode_fft_quant(t_bin_ambi_reduced_decode_fft *x, double *delta_deg2rad, double *phi_deg2rad, int index)
+static void bin_ambi_reduced_decode_fft_quant(t_bin_ambi_reduced_decode_fft *x, double *delta_deg2rad, double *phi_deg2rad, int xindex)
{
double q = 1.0;
double d = *delta_deg2rad;
@@ -192,8 +192,8 @@ static void bin_ambi_reduced_decode_fft_quant(t_bin_ambi_reduced_decode_fft *x,
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;
@@ -203,7 +203,7 @@ static void bin_ambi_reduced_decode_fft_do_2d(t_bin_ambi_reduced_decode_fft *x,
{
double delta=0.0, phi;
double *dw = x->x_transp;
- int index;
+ int xindex;
int order=x->x_n_order;
if(argc < 2)
@@ -211,23 +211,23 @@ static void bin_ambi_reduced_decode_fft_do_2d(t_bin_ambi_reduced_decode_fft *x,
post("bin_ambi_reduced_decode_fft 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_IND)
{
- if(index >= x->x_n_ind_ls)
- index = x->x_n_ind_ls - 1;
+ if(xindex >= x->x_n_ind_ls)
+ xindex = x->x_n_ind_ls - 1;
}
else if(mode == BIN_AMBI_LS_MRG)
{
if(x->x_n_mrg_mir_ls)
{
- if(index >= x->x_n_mrg_mir_ls)
- index = x->x_n_mrg_mir_ls - 1;
- index += x->x_n_ind_ls;
+ if(xindex >= x->x_n_mrg_mir_ls)
+ xindex = x->x_n_mrg_mir_ls - 1;
+ xindex += x->x_n_ind_ls;
}
else
return;
@@ -236,10 +236,10 @@ static void bin_ambi_reduced_decode_fft_do_2d(t_bin_ambi_reduced_decode_fft *x,
{
if(x->x_n_mrg_mir_ls)
{
- if(index >= x->x_n_mrg_mir_ls)
- index = x->x_n_mrg_mir_ls - 1;
- index += x->x_n_ind_ls;
- index += x->x_n_mrg_mir_ls;
+ if(xindex >= x->x_n_mrg_mir_ls)
+ xindex = x->x_n_mrg_mir_ls - 1;
+ xindex += x->x_n_ind_ls;
+ xindex += x->x_n_mrg_mir_ls;
}
else
return;
@@ -248,10 +248,10 @@ static void bin_ambi_reduced_decode_fft_do_2d(t_bin_ambi_reduced_decode_fft *x,
{
if(x->x_n_ph_ls)
{
- if(index >= x->x_n_ph_ls)
- index = x->x_n_ph_ls - 1;
- index += x->x_n_ind_ls;
- index += 2*x->x_n_mrg_mir_ls;
+ if(xindex >= x->x_n_ph_ls)
+ xindex = x->x_n_ph_ls - 1;
+ xindex += x->x_n_ind_ls;
+ xindex += 2*x->x_n_mrg_mir_ls;
}
else
return;
@@ -259,9 +259,9 @@ static void bin_ambi_reduced_decode_fft_do_2d(t_bin_ambi_reduced_decode_fft *x,
else
return;
- bin_ambi_reduced_decode_fft_quant(x, &delta, &phi, index);
+ bin_ambi_reduced_decode_fft_quant(x, &delta, &phi, xindex);
- dw += index * x->x_n_ambi;
+ dw += xindex * x->x_n_ambi;
*dw++ = 1.0;
*dw++ = cos(phi);
@@ -338,7 +338,7 @@ static void bin_ambi_reduced_decode_fft_do_3d(t_bin_ambi_reduced_decode_fft *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)
@@ -346,24 +346,24 @@ static void bin_ambi_reduced_decode_fft_do_3d(t_bin_ambi_reduced_decode_fft *x,
post("bin_ambi_reduced_decode_fft 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_IND)
{
- if(index >= x->x_n_ind_ls)
- index = x->x_n_ind_ls - 1;
+ if(xindex >= x->x_n_ind_ls)
+ xindex = x->x_n_ind_ls - 1;
}
else if(mode == BIN_AMBI_LS_MRG)
{
if(x->x_n_mrg_mir_ls)
{
- if(index >= x->x_n_mrg_mir_ls)
- index = x->x_n_mrg_mir_ls - 1;
- index += x->x_n_ind_ls;
+ if(xindex >= x->x_n_mrg_mir_ls)
+ xindex = x->x_n_mrg_mir_ls - 1;
+ xindex += x->x_n_ind_ls;
}
else
return;
@@ -372,10 +372,10 @@ static void bin_ambi_reduced_decode_fft_do_3d(t_bin_ambi_reduced_decode_fft *x,
{
if(x->x_n_mrg_mir_ls)
{
- if(index >= x->x_n_mrg_mir_ls)
- index = x->x_n_mrg_mir_ls - 1;
- index += x->x_n_ind_ls;
- index += x->x_n_mrg_mir_ls;
+ if(xindex >= x->x_n_mrg_mir_ls)
+ xindex = x->x_n_mrg_mir_ls - 1;
+ xindex += x->x_n_ind_ls;
+ xindex += x->x_n_mrg_mir_ls;
}
else
return;
@@ -384,10 +384,10 @@ static void bin_ambi_reduced_decode_fft_do_3d(t_bin_ambi_reduced_decode_fft *x,
{
if(x->x_n_ph_ls)
{
- if(index >= x->x_n_ph_ls)
- index = x->x_n_ph_ls - 1;
- index += x->x_n_ind_ls;
- index += 2*x->x_n_mrg_mir_ls;
+ if(xindex >= x->x_n_ph_ls)
+ xindex = x->x_n_ph_ls - 1;
+ xindex += x->x_n_ind_ls;
+ xindex += 2*x->x_n_mrg_mir_ls;
}
else
return;
@@ -395,14 +395,14 @@ static void bin_ambi_reduced_decode_fft_do_3d(t_bin_ambi_reduced_decode_fft *x,
else
return;
- bin_ambi_reduced_decode_fft_quant(x, &delta, &phi, index);
+ bin_ambi_reduced_decode_fft_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;
@@ -746,7 +746,7 @@ static void bin_ambi_reduced_decode_fft_inverse(t_bin_ambi_reduced_decode_fft *x
nz = bin_ambi_reduced_decode_fft_eval_which_element_of_col_not_zero(x, i, i);
if(nz < 0)
{
- post("bin_ambi_reduced_decode_fft ERROR: matrix not regular !!!!");
+ post("bin_ambi_reduced_decode_fft ERROR: matrix singular !!!!");
x->x_seq_ok = 0;
return;
}
@@ -815,38 +815,38 @@ n_ambi columns;
n_ambi rows;
*/
-static void bin_ambi_reduced_decode_fft_load_HRIR(t_bin_ambi_reduced_decode_fft *x, float findex)
+static void bin_ambi_reduced_decode_fft_load_HRIR(t_bin_ambi_reduced_decode_fft *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_ind_ls + x->x_n_mrg_mir_ls))
- index = x->x_n_ind_ls + x->x_n_mrg_mir_ls - 1;
+ if(xindex < 0)
+ xindex = 0;
+ if(xindex >= (x->x_n_ind_ls + x->x_n_mrg_mir_ls))
+ xindex = x->x_n_ind_ls + x->x_n_mrg_mir_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_decode_fft_check_HRIR_arrays(t_bin_ambi_reduced_decode_fft *x, float findex)
+static void bin_ambi_reduced_decode_fft_check_HRIR_arrays(t_bin_ambi_reduced_decode_fft *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;
@@ -855,14 +855,14 @@ static void bin_ambi_reduced_decode_fft_check_HRIR_arrays(t_bin_ambi_reduced_dec
t_symbol *hrir;
t_float *vec;
iemarray_t *vec_hrir, *vec_fade_out_hrir;
- float decr, sum;
+ t_float decr, sum;
- if(index < 0)
- index = 0;
- if(index >= (x->x_n_ind_ls + x->x_n_mrg_mir_ls))
- index = x->x_n_ind_ls + x->x_n_mrg_mir_ls - 1;
+ if(xindex < 0)
+ xindex = 0;
+ if(xindex >= (x->x_n_ind_ls + x->x_n_mrg_mir_ls))
+ xindex = x->x_n_ind_ls + x->x_n_mrg_mir_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))
@@ -874,7 +874,7 @@ static void bin_ambi_reduced_decode_fft_check_HRIR_arrays(t_bin_ambi_reduced_dec
post("bin_ambi_reduced_decode_fft-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)
{
@@ -890,7 +890,7 @@ static void bin_ambi_reduced_decode_fft_check_HRIR_arrays(t_bin_ambi_reduced_dec
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;
@@ -900,22 +900,22 @@ static void bin_ambi_reduced_decode_fft_check_HRIR_arrays(t_bin_ambi_reduced_dec
}
}
-static void bin_ambi_reduced_decode_fft_check_HRTF_arrays(t_bin_ambi_reduced_decode_fft *x, float findex)
+static void bin_ambi_reduced_decode_fft_check_HRTF_arrays(t_bin_ambi_reduced_decode_fft *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);
@@ -931,14 +931,14 @@ static void bin_ambi_reduced_decode_fft_check_HRTF_arrays(t_bin_ambi_reduced_dec
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_fft_calc_reduced(t_bin_ambi_reduced_decode_fft *x, float findex)
+static void bin_ambi_reduced_decode_fft_calc_reduced(t_bin_ambi_reduced_decode_fft *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;
@@ -949,20 +949,20 @@ static void bin_ambi_reduced_decode_fft_calc_reduced(t_bin_ambi_reduced_decode_f
double *dv, *db=x->x_prod3;
int n_ambi = x->x_n_ambi;
int n_ls = x->x_n_ind_ls + x->x_n_mrg_mir_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*/
{
@@ -973,7 +973,7 @@ static void bin_ambi_reduced_decode_fft_calc_reduced(t_bin_ambi_reduced_decode_f
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++)
@@ -1027,18 +1027,19 @@ static void bin_ambi_reduced_decode_fft_calc_reduced(t_bin_ambi_reduced_decode_f
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);
+ }
}
}
@@ -1163,7 +1164,7 @@ static void bin_ambi_reduced_decode_fft_calc_sym(t_bin_ambi_reduced_decode_fft *
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);
}
}
@@ -1246,9 +1247,9 @@ static void bin_ambi_reduced_decode_fft_free(t_bin_ambi_reduced_decode_fft *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_ind_ls+x->x_n_mrg_mir_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_ind_ls+x->x_n_mrg_mir_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 *));
}
/*
@@ -1433,7 +1434,7 @@ static void *bin_ambi_reduced_decode_fft_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_ind_ls+x->x_n_mrg_mir_ls) * sizeof(float));
+ x->x_beg_hrir = (t_float *)getbytes(x->x_fftsize * (x->x_n_ind_ls+x->x_n_mrg_mir_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 *));