Update of /cvsroot/pure-data/externals/vbap
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28823
Modified Files:
vbap.c
Log Message:
tracked down crasher bug due to an array index calculation resulting in a negative index. This was caused by running in 2D mode when that array calculation was set up for 3D mode. Also, I fixed basically all warnings by commenting out
Index: vbap.c
===================================================================
RCS file: /cvsroot/pure-data/externals/vbap/vbap.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** vbap.c 26 Nov 2002 10:28:17 -0000 1.3
--- vbap.c 14 Aug 2006 01:24:08 -0000 1.4
***************
*** 48,56 ****
static void additive_vbap(float *final_gs, float cartdir[3], t_vbap *x);
static void vbap_bang(t_vbap *x);
! static void vbap_int(t_vbap *x, t_float n);
static void vbap_matrix(t_vbap *x, t_symbol *s, int ac, t_atom *av);
static void vbap_in1(t_vbap *x, long n);
static void vbap_in2(t_vbap *x, long n);
static void vbap_in3(t_vbap *x, long n);
static void spread_it(t_vbap *x, float *final_gs);
static void *vbap_new(t_symbol *s, int ac, t_atom *av); /* using A_GIMME - typed message list */
--- 48,59 ----
static void additive_vbap(float *final_gs, float cartdir[3], t_vbap *x);
static void vbap_bang(t_vbap *x);
! /* static void vbap_int(t_vbap *x, t_float n); */
static void vbap_matrix(t_vbap *x, t_symbol *s, int ac, t_atom *av);
+ /*
+ * unused 2006-08-13 <hans(a)at.or.at>
static void vbap_in1(t_vbap *x, long n);
static void vbap_in2(t_vbap *x, long n);
static void vbap_in3(t_vbap *x, long n);
+ */
static void spread_it(t_vbap *x, float *final_gs);
static void *vbap_new(t_symbol *s, int ac, t_atom *av); /* using A_GIMME - typed message list */
***************
*** 66,70 ****
/* vbap_new = creation function, A_DEFLONG = its (optional) arguement is a long (32-bit) int */
! #if 0
/* max methods ... */
--- 69,73 ----
/* vbap_new = creation function, A_DEFLONG = its (optional) arguement is a long (32-bit) int */
! #ifdef MAXMSP
/* max methods ... */
***************
*** 79,83 ****
#endif
class_addbang(vbap_class, vbap_bang);
! class_addfloat(vbap_class, vbap_int);
class_addmethod(vbap_class, (t_method)vbap_matrix, gensym("loudspeaker-matrices"), A_GIMME, 0);
}
--- 82,86 ----
#endif
class_addbang(vbap_class, vbap_bang);
! /* class_addfloat(vbap_class, vbap_int); */
class_addmethod(vbap_class, (t_method)vbap_matrix, gensym("loudspeaker-matrices"), A_GIMME, 0);
}
***************
*** 96,103 ****
/* converts cartesian coordinates to angular */
{
! float tmp, tmp2, tmp3, tmp4;
float atorad = (2 * 3.1415927 / 360) ;
float pi = 3.1415927;
! float power;
float dist, atan_y_per_x, atan_x_pl_y_per_z;
float azi, ele;
--- 99,106 ----
/* converts cartesian coordinates to angular */
{
! // float tmp, tmp2, tmp3, tmp4; /* warning: unused variable */
float atorad = (2 * 3.1415927 / 360) ;
float pi = 3.1415927;
! // float power; /* warning: unused variable */
float dist, atan_y_per_x, atan_x_pl_y_per_z;
float azi, ele;
***************
*** 116,123 ****
--- 119,128 ----
atan_x_pl_y_per_z = atan(cvec[2] / dist);
if(dist == 0.0)
+ {
if(cvec[2]<0.0)
atan_x_pl_y_per_z = -pi/2.0;
else
atan_x_pl_y_per_z = pi/2.0;
+ }
ele = atan_x_pl_y_per_z / atorad;
dist = sqrtf(cvec[0] * cvec[0] +cvec[1] * cvec[1] +cvec[2]*cvec[2]);
***************
*** 135,139 ****
float small_g;
float big_sm_g, gtmp[3];
! long winner_set;
float cartdir[3];
float new_cartdir[3];
--- 140,144 ----
float small_g;
float big_sm_g, gtmp[3];
! long winner_set=0;
float cartdir[3];
float new_cartdir[3];
***************
*** 255,268 ****
float big_sm_g, gtmp[3];
long winner_set;
! float new_cartdir[3];
! float new_angle_dir[3];
long dim = x->x_dimension;
long neg_g_am, best_neg_g_am;
float g[3];
! long ls[3];
big_sm_g = -100000.0;
best_neg_g_am=3;
!
for(i=0;i<x->x_lsset_amount;i++){
small_g = 10000000.0;
--- 260,278 ----
float big_sm_g, gtmp[3];
long winner_set;
! // float new_cartdir[3]; /* warning: unused variable */
! // float new_angle_dir[3]; /* warning: unused variable */
long dim = x->x_dimension;
long neg_g_am, best_neg_g_am;
float g[3];
! long ls[3] = { 0, 0, 0 };
big_sm_g = -100000.0;
best_neg_g_am=3;
!
! /* BUG: there is a bug that sometimes causes x->x_lsset_amount to be a massive
! * number. I haven't tracked it down yet, but its probably an init
! * bug. 2006-08-13 <hans(a)at.or.at>
! */
! // post("x_lsset_amount: %li", x->x_lsset_amount);
for(i=0;i<x->x_lsset_amount;i++){
small_g = 10000000.0;
***************
*** 300,311 ****
if(gains_modified != 1){
! power=sqrt(g[0]*g[0] + g[1]*g[1] + g[2]*g[2]);
g[0] /= power;
g[1] /= power;
! g[2] /= power;
final_gs[ls[0]-1] += g[0];
final_gs[ls[1]-1] += g[1];
! final_gs[ls[2]-1] += g[2];
}
}
--- 310,329 ----
if(gains_modified != 1){
! if(dim==3)
! power=sqrt(g[0]*g[0] + g[1]*g[1] + g[2]*g[2]);
! else
! power=sqrt(g[0]*g[0] + g[1]*g[1]);
g[0] /= power;
g[1] /= power;
! if(dim==3)
! g[2] /= power;
final_gs[ls[0]-1] += g[0];
final_gs[ls[1]-1] += g[1];
! /* BUG FIX: this was causing negative indices with 2 dimensions so I
! * made it only try when using 3 dimensions.
! * 2006-08-13 <hans(a)at.or.at> */
! if(dim==3)
! final_gs[ls[2]-1] += g[2];
}
}
***************
*** 473,491 ****
/*--------------------------------------------------------------------------*/
! static void vbap_int(t_vbap *x, t_float n) /* x = the instance of the object, n = the int received in the right inlet */
{
! /* do something if an int comes in the left inlet??? */
}
static void vbap_matrix(t_vbap *x, t_symbol *s, int ac, t_atom *av)
/* read in loudspeaker matrices */
{
! long counter;
long datapointer=0;
long setpointer=0;
long i;
! long deb=0;
! if(ac>0)
/* if(av[datapointer].a_type == A_LONG){
x->x_dimension = av[datapointer++].a_w.w_long;
--- 491,511 ----
/*--------------------------------------------------------------------------*/
! /*
! static void vbap_int(t_vbap *x, t_float n) // x = the instance of the object, n = the int received in the right inlet
{
! // do something if an int comes in the left inlet???
}
+ */
static void vbap_matrix(t_vbap *x, t_symbol *s, int ac, t_atom *av)
/* read in loudspeaker matrices */
{
! long counter=0;
long datapointer=0;
long setpointer=0;
long i;
! // long deb=0;
! if(ac>0) {
/* if(av[datapointer].a_type == A_LONG){
x->x_dimension = av[datapointer++].a_w.w_long;
***************
*** 500,505 ****
return;
}
/* post("%d",deb++); */
! if(ac>1)
/* if(av[datapointer].a_type == A_LONG)
x->x_ls_amount = av[datapointer++].a_w.w_long;
--- 520,526 ----
return;
}
+ }
/* post("%d",deb++); */
! if(ac>1) {
/* if(av[datapointer].a_type == A_LONG)
x->x_ls_amount = av[datapointer++].a_w.w_long;
***************
*** 512,515 ****
--- 533,537 ----
return;
}
+ }
else
x->x_lsset_available=0;
***************
*** 522,526 ****
x->x_lsset_amount=counter;
! if(counter<=0){
post("vbap: Error in loudspeaker data!",0);
x->x_lsset_available=0;
--- 544,548 ----
x->x_lsset_amount=counter;
! if(counter<=0) {
post("vbap: Error in loudspeaker data!",0);
x->x_lsset_available=0;
***************
*** 572,599 ****
}
! static void vbap_in1(t_vbap *x, long n) /* x = the instance of the object, n = the int received in the right inlet */
! /* panning angle azimuth */
{
! x->x_azi = n; /* store n in a global variable */
}
! static void vbap_in2(t_vbap *x, long n) /* x = the instance of the object, n = the int received in the right inlet */
! /* panning angle elevation */
{
! x->x_ele = n; /* store n in a global variable */
}
- /*--------------------------------------------------------------------------*/
! static void vbap_in3(t_vbap *x, long n) /* x = the instance of the object, n = the int received in the right inlet */
! /* spread amount */
{
if (n<0) n = 0;
if (n>100) n = 100;
! x->x_spread = n; /* store n in a global variable */
}
!
static void *vbap_new(t_symbol *s, int ac, t_atom *av)
--- 594,622 ----
}
! /*
! * unused 2006-08-13 <hans(a)at.or.at>
! static void vbap_in1(t_vbap *x, long n) // x = the instance of the object, n = the int received in the right inlet
! // panning angle azimuth
{
! x->x_azi = n; // store n in a global variable
}
! static void vbap_in2(t_vbap *x, long n) // x = the instance of the object, n = the int received in the right inlet
! // panning angle elevation
{
! x->x_ele = n; // store n in a global variable
}
! static void vbap_in3(t_vbap *x, long n) // x = the instance of the object, n = the int received in the right inlet
! // spread amount
{
if (n<0) n = 0;
if (n>100) n = 100;
! x->x_spread = n; // store n in a global variable
}
! */
static void *vbap_new(t_symbol *s, int ac, t_atom *av)