aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2009-05-27 16:51:48 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2009-05-27 16:51:48 +0000
commit9c6493714db02b8a88793bbe56d95656222e7b72 (patch)
treea8bb17acda3347880a24e5264a7ee76c2c6b100c
parent81e51efaff0d759e7f1b1e67e0e5b3c8b4a49e26 (diff)
- replaced crack smoking while/-= statement with fmod() to ensure that the CPU
doesn't get spiked when large values get sent to vbap's azimuth or elevation - added simple 5.1 example to the help patch - made the Max ifdef include the 3 argument vbap_new() function with 'spread' svn path=/trunk/externals/vbap/; revision=11531
-rw-r--r--vbap-help.pd129
-rw-r--r--vbap.c27
2 files changed, 118 insertions, 38 deletions
diff --git a/vbap-help.pd b/vbap-help.pd
index a73a224..24e4b72 100644
--- a/vbap-help.pd
+++ b/vbap-help.pd
@@ -1,7 +1,7 @@
-#N canvas 121 22 818 496 10;
-#X floatatom 129 208 5 0 0 2 - - -;
-#X floatatom 167 227 5 0 0 2 - - -;
-#X msg 101 158 bang;
+#N canvas 126 22 818 496 10;
+#X floatatom 149 218 5 0 0 2 - - -;
+#X floatatom 187 237 5 0 0 2 - - -;
+#X msg 115 163 bang;
#X obj 102 396 route 0 1 2 3;
#X floatatom 102 445 10 0 0 0 - - -;
#X floatatom 181 445 10 0 0 0 - - -;
@@ -20,7 +20,6 @@ positions "visible". The range is 0 to 100;
location. Bang the first inlet and vbap will output gain-factors for
each speaker and the actual location produced. This can be different
from the desired one depending where your speakers are.;
-#X obj 599 370 vbap-demo;
#X msg 25 115 define_loudspeakers 2 -45 45 -135 135;
#X text 24 64 loudspeaker position definition can also be sent directly
to a vbap object. This changes the setup information only in a single
@@ -35,32 +34,110 @@ and elevation. Here we have speakers front left and right with no elevation
180 45). Send the data to vbap.;
#X msg 51 135 define_loudspeakers 3 -45 45 -135 135 32 5 94 34 34 11
;
-#X obj 132 192 hsl 100 13 0 360 0 0 empty empty azimuth 10 7 0 10 -262144
--1 -1 3800 1;
-#X obj 170 210 hsl 100 13 0 360 0 0 empty empty elevation 10 7 0 10
--262144 -1 -1 5100 1;
-#X floatatom 207 247 5 0 0 2 - - -;
-#X obj 210 230 hsl 100 13 0 360 0 0 empty empty spread 10 7 0 10 -262144
--1 -1 2500 1;
-#X text 135 158 to output updated values;
-#X obj 102 277 vbap 90 0 30;
+#X obj 152 202 hsl 100 13 0 360 0 0 empty empty azimuth 10 7 0 10 -262144
+-1 -1 0 1;
+#X obj 190 220 hsl 100 13 0 360 0 0 empty empty elevation 10 7 0 10
+-262144 -1 -1 0 1;
+#X floatatom 227 257 5 0 0 2 - - -;
+#X obj 230 240 hsl 100 13 0 100 0 0 empty empty spread 10 7 0 10 -262144
+-1 -1 0 1;
+#X text 149 163 to output updated values;
+#X obj 102 287 vbap 90 0 30;
#X text 450 417 You can also use [vbap] to control Cyclone's [matrix~]
;
#X obj 543 440 cyclone/matrix~ 1 4 1;
+#X obj 83 185 metro 100;
+#X obj 83 163 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
+1;
+#N canvas 283 22 628 620 simple 0;
+#X floatatom 159 198 5 0 0 2 - - -;
+#X floatatom 112 425 10 0 0 0 - - -;
+#X floatatom 181 425 10 0 0 0 - - -;
+#X floatatom 209 349 0 0 0 3 actual_azimuth - -;
+#X floatatom 221 315 0 0 0 3 actual_elevation - -;
+#X floatatom 231 294 7 0 0 1 actual_spreading - -;
+#X obj 162 182 hsl 100 13 -180 180 0 1 empty empty azimuth 10 7 0 10
+-262144 -1 -1 1500 1;
+#X floatatom 237 237 5 0 0 2 - - -;
+#X obj 240 220 hsl 100 13 0 100 0 1 empty empty spread 10 7 0 10 -262144
+-1 -1 700 1;
+#X text 130 134 to output updated values;
+#X obj 112 155 metro 100;
+#X obj 112 133 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
+1;
+#X text 197 200 (ignore elevation in 2D \, that's for 3D);
+#X obj 63 524 *~;
+#X obj 92 525 *~;
+#X msg 454 145 dsp 1;
+#X obj 454 169 send pd;
+#X floatatom 250 425 10 0 0 0 - - -;
+#X floatatom 319 425 10 0 0 0 - - -;
+#X obj 123 524 *~;
+#X obj 152 525 *~;
+#X msg 17 48 define_loudspeakers 2 -135 -45 0 45 135;
+#X text 263 37 Define 2D speaker arrangement with speakers at -135
+\, -45 \, 0 \, 45 and 135 degree positions (0 degrees is the center
+front). This is a classic 5.1 setup.;
+#X floatatom 389 425 10 0 0 0 - - -;
+#X obj 72 558 dac~ 1 2 3 4 5;
+#X obj 182 525 *~;
+#X obj 112 267 vbap 0 0 30;
+#X obj 112 376 route 0 1 2 3 4;
+#X obj 13 396 *~ 0.2;
+#X obj 13 374 noise~;
#X connect 0 0 26 1;
-#X connect 1 0 26 2;
-#X connect 2 0 26 0;
+#X connect 1 0 13 1;
+#X connect 2 0 14 1;
+#X connect 6 0 0 0;
+#X connect 7 0 26 3;
+#X connect 8 0 7 0;
+#X connect 10 0 26 0;
+#X connect 11 0 10 0;
+#X connect 13 0 24 0;
+#X connect 14 0 24 1;
+#X connect 15 0 16 0;
+#X connect 17 0 19 1;
+#X connect 18 0 20 1;
+#X connect 19 0 24 2;
+#X connect 20 0 24 3;
+#X connect 21 0 26 0;
+#X connect 23 0 25 1;
+#X connect 25 0 24 4;
+#X connect 26 0 27 0;
+#X connect 26 1 3 0;
+#X connect 26 2 4 0;
+#X connect 26 3 5 0;
+#X connect 27 0 1 0;
+#X connect 27 1 2 0;
+#X connect 27 2 17 0;
+#X connect 27 3 18 0;
+#X connect 27 4 23 0;
+#X connect 28 0 13 0;
+#X connect 28 0 14 0;
+#X connect 28 0 19 0;
+#X connect 28 0 20 0;
+#X connect 28 0 25 0;
+#X connect 29 0 28 0;
+#X restore 539 378 pd simple 5.1 example;
+#X text 337 238 (0-100);
+#X text 297 217 (0-360);
+#X text 257 199 (0-360);
+#X connect 0 0 25 1;
+#X connect 1 0 25 2;
+#X connect 2 0 25 0;
#X connect 3 0 4 0;
#X connect 3 1 5 0;
#X connect 3 2 6 0;
#X connect 3 3 7 0;
-#X connect 16 0 26 0;
-#X connect 20 0 26 0;
-#X connect 21 0 0 0;
-#X connect 22 0 1 0;
-#X connect 23 0 26 3;
-#X connect 24 0 23 0;
-#X connect 26 0 3 0;
-#X connect 26 1 11 0;
-#X connect 26 2 12 0;
-#X connect 26 3 13 0;
+#X connect 15 0 25 0;
+#X connect 19 0 25 0;
+#X connect 20 0 0 0;
+#X connect 21 0 1 0;
+#X connect 22 0 25 3;
+#X connect 23 0 22 0;
+#X connect 25 0 3 0;
+#X connect 25 1 11 0;
+#X connect 25 2 12 0;
+#X connect 25 3 13 0;
+#X connect 28 0 25 0;
+#X connect 29 0 28 0;
diff --git a/vbap.c b/vbap.c
index ef84219..7cf4a64 100644
--- a/vbap.c
+++ b/vbap.c
@@ -139,9 +139,9 @@ void vbap_ft4(t_vbap *x, double g) { x->x_gain = g; }
/*--------------------------------------------------------------------------*/
// create new instance of object...
-#ifdef PD
static void *vbap_new(t_float azi, t_float ele, t_float spread)
{
+#ifdef PD
t_vbap *x = (t_vbap *)newobject(vbap_class);
floatinlet_new(&x->x_obj, &x->x_azi);
@@ -153,8 +153,6 @@ static void *vbap_new(t_float azi, t_float ele, t_float spread)
x->x_outlet2 = outlet_new(&x->x_obj, &s_float);
x->x_outlet3 = outlet_new(&x->x_obj, &s_float);
#else /* Max */
-void *vbap_new(float azi,float ele)
-{
t_vbap *x = (t_vbap *)newobject(vbap_class);
floatin(x,4);
@@ -172,11 +170,11 @@ void *vbap_new(float azi,float ele)
x->x_spread_base[0] = 0.0;
x->x_spread_base[1] = 1.0;
x->x_spread_base[2] = 0.0;
- x->x_spread = spread;
x->x_lsset_available =0;
x->x_azi = azi;
x->x_ele = ele;
+ x->x_spread = spread;
return(x); /* return a reference to the object instance */
}
@@ -240,17 +238,22 @@ static void vbap(float g[3], long ls[3], t_vbap *x)
long neg_g_am, best_neg_g_am;
// transfering the azimuth angle to a decent value
- while(x->x_azi > 180.0)
- x->x_azi -= 360.0;
- while(x->x_azi < -179.0)
- x->x_azi += 360.0;
+ if(x->x_azi > 360.0 || x->x_azi < -360.0)
+ x->x_azi = fmod(x->x_azi, 360.0);
+ if(x->x_azi > 180.0)
+ x->x_azi -= 360.0;
+ if(x->x_azi < -179.0)
+ x->x_azi += 360.0;
+
// transferring the elevation to a decent value
if(dim == 3){
- while(x->x_ele > 180.0)
- x->x_ele -= 360.0;
- while(x->x_ele < -179.0)
- x->x_ele += 360.0;
+ if(x->x_ele > 360.0 || x->x_ele < -360.0)
+ x->x_ele = fmod(x->x_ele, 360.0);
+ if(x->x_ele > 180.0)
+ x->x_ele -= 360.0;
+ if(x->x_ele < -179.0)
+ x->x_ele += 360.0;
} else
x->x_ele = 0.0;