25 int JAMOMA_EXPORT_MAXOBJ
main(
void)
29 common_symbols_init();
30 psRollOff = gensym(
"rolloff");
31 psSourcePosition = gensym(
"source_position");
32 psSourceGain = gensym(
"source_gain");
33 psSourceMute = gensym(
"src_mute");
34 psSourceBlur = gensym(
"blur");
35 psDestinationPosition = gensym(
"destination_position");
36 psNumberOfSources = gensym(
"num_sources");
37 psNumberOfDestinations = gensym(
"num_destinations");
40 c = class_new(
"j.dbap_bformat",(method)dbap_bformatNew, (method)0L,
sizeof(
t_dbap_bformat),
41 (method)0L, A_GIMME, 0);
57 class_addmethod(c, (method)object_obex_dumpout,
"dumpout", 0);
60 CLASS_ATTR_LONG(c,
"num_sources", 0,
t_dbap_bformat, attrNumberOfSources);
63 CLASS_ATTR_LONG(c,
"num_destinations", 0,
t_dbap_bformat, attrNumberOfDestinations);
73 class_register(CLASS_BOX, c);
82 #pragma mark object life
84 void *dbap_bformatNew(t_symbol *msg,
long argc, t_atom *argv)
92 object_obex_store(x, _sym_dumpout, (
object *)outlet_new(x,NULL));
93 x->outlet = outlet_new(x, 0);
102 for (i=0; i<MAX_NUM_SOURCES; i++) {
106 x->
blur[i] = 0.000001;
112 for (i=0; i<MAX_NUM_DESTINATIONS; i++) {
118 for (i=0;i<MAX_NUM_SOURCES;i++) {
119 for (j=0;j<MAX_NUM_DESTINATIONS;j++) {
129 attr_args_process(x, argc, argv);
151 if ((argc>=2) && argv) {
152 n = atom_getlong(argv)-1;
153 if ( (n<0) || (n>=MAX_NUM_SOURCES) ) {
154 error(
"Invalid argument(s) for blur");
158 f = atom_getfloat(argv);
165 error(
"Invalid argument(s) for blur");
187 if ((argc>=2) && argv) {
188 n = atom_getlong(argv)-1;
189 if ( (n<0) || (n>=MAX_NUM_SOURCES) ) {
190 error(
"Invalid argument(s) for blur");
194 f = atom_getfloat(argv);
203 error(
"Invalid argument(s) for blur");
228 n = atom_getlong(argv)-1;
229 if ( (n<0) || (n>=MAX_NUM_DESTINATIONS) ) {
230 error(
"Invalid arguments for source.");
241 error(
"Invalid arguments for source.");
251 n = atom_getlong(argv)-1;
252 if ( (n<0) || (n>=MAX_NUM_DESTINATIONS) ) {
253 error(
"Invalid arguments for destination.");
264 error(
"Invalid arguments for speaker.");
273 if ((argc>=2) && argv) {
274 n = atom_getlong(argv)-1;
275 if ( (n<0) || (n>=MAX_NUM_SOURCES) ) {
276 error(
"Invalid argument(s) for source_gain");
280 f = atom_getfloat(argv);
287 error(
"Invalid argument(s) for source_gain");
312 if (atom_gettype(argv) == A_LONG) {
313 source = atom_getlong(argv)-1;
316 object_error((t_object*)x,
"sourceWeight : the source n°%d doesn't exist", source+1);
321 object_error((t_object*)x,
"sourceWeight : no source id");
328 if (atom_gettype(&argv[i+1]) == A_LONG)
329 weight = (float)atom_getlong(&argv[i+1]);
331 if (atom_gettype(&argv[i+1]) == A_FLOAT)
332 weight = atom_getfloat(&argv[i+1]);
346 object_error((t_object*)x,
"sourceWeight : needs arguments");
353 if ((argc>=2) && argv) {
354 n = atom_getlong(argv)-1;
355 if ( (n<0) || (n>=MAX_NUM_SOURCES) ) {
356 error(
"Invalid argument(s) for source_gain");
364 error(
"Invalid argument(s) for source_gain");
373 object_obex_dumpout(x, psRollOff, 1, a);
376 object_obex_dumpout(x, psNumberOfSources, 1, a);
379 atom_setlong(&a[0], i+1);
383 object_obex_dumpout(x, psSourcePosition, 4, a);
385 object_obex_dumpout(x, psSourceGain, 2, a);
387 object_obex_dumpout(x, psSourceMute, 2, a);
388 atom_setfloat(&a[1], x->
blur[i]);
389 object_obex_dumpout(x, psSourceBlur, 1, a);
393 object_obex_dumpout(x, psNumberOfDestinations, 1, a);
396 atom_setlong(&a[0], i+1);
400 object_obex_dumpout(x, psDestinationPosition, 4, a);
413 strcpy(dst,
"set source and speaker positions");
422 strcpy(dst,
"(list) messages for matrix~");
425 strcpy(dst,
"dumpout");
435 #pragma mark attribute accessors
444 n = atom_getlong(argv);
447 if (n>MAX_NUM_SOURCES)
461 n = atom_getlong(argv);
464 if (n>MAX_NUM_DESTINATIONS)
465 n = MAX_NUM_DESTINATIONS;
481 f = atom_getfloat(argv);
483 error(
"Invalid argument for rolloff. Must be > 0");
484 return MAX_ERR_NONE;;
502 f = atom_getfloat(argv);
504 error(
"Invalid argument for vicinity. Must be > 0");
505 return MAX_ERR_NONE;;
519 #pragma mark calculations
524 double scalingCoefficient;
525 double scalingCoefficientSquareInverse;
528 double distanceAdjusted
529 [MAX_NUM_DESTINATIONS];
531 double sourceSpeakerWeight;
536 double horisontalDistance;
548 blurSquared = blurSquared*blurSquared;
552 scalingCoefficientSquareInverse = 0;
563 horisontalDistance = sqrt(dx*dx + dy*dy);
564 distance = sqrt(dx*dx + dy*dy + dz*dz);
578 if (distance<x->attrVicinity) {
580 d = (d*d*d*(d*(6*d-15)+10));
581 k1 = k1 * (d*d*d*(d*(6*d-15)+10));
591 if (horisontalDistance>0.0) {
592 cosAzimuth = dx/horisontalDistance;
593 sinAzimuth = dy/horisontalDistance;
600 cosElevation = horisontalDistance/distance;
601 sinElevation = dz/distance;
612 distanceAdjusted[i] = pow(
double(dx*dx + dy*dy + dz*dz + blurSquared),
double(0.5*x->
a));
614 scalingCoefficientSquareInverse = scalingCoefficientSquareInverse + (x->
sourceWeight[n][i]*x->
sourceWeight[n][i])/(distanceAdjusted[i]*distanceAdjusted[i]);
617 scalingCoefficient = sqrt(1./scalingCoefficientSquareInverse);
621 sourceSpeakerWeight = x->
sourceWeight[n][i] * scalingCoefficient / distanceAdjusted[i];
622 atom_setlong(&a[1], i);
625 atom_setlong(&a[0], n*4);
627 outlet_anything(x->outlet, _sym_list, 3, a);
630 atom_setlong(&a[0], n*4+1);
632 outlet_anything(x->outlet, _sym_list, 3, a);
635 atom_setlong(&a[0], n*4+2);
637 outlet_anything(x->outlet, _sym_list, 3, a);
640 atom_setlong(&a[0], n*4+3);
642 outlet_anything(x->outlet, _sym_list, 3, a);
685 d2 += dx*dx + dy*dy + dz*dz;
double w
Zero order W coefficient.
double y
First order Y coefficient.
double x
First order X coefficient.
double z
First order Z coefficient.
t_class * this_class
Required. Global pointing to this class.