34#include <libFreeWRL.h>
36#include "../vrml_parser/Structs.h"
37#include "../vrml_parser/CRoutes.h"
38#include "../main/headers.h"
39#include "../opengl/OpenGL_Utils.h"
41#include "LinearAlgebra.h"
43#define BADAUDIOSOURCE -9999
57typedef struct icset {
int p;
int d;
int ld;
int n;
int s;
int ls; }
icset;
67 device = alcOpenDevice(NULL);
70 fprintf(stderr,
"Could not open a device!\n");
74 ctx = alcCreateContext(device, NULL);
75 if(ctx == NULL || alcMakeContextCurrent(ctx) == ALC_FALSE)
78 alcDestroyContext(ctx);
79 alcCloseDevice(device);
80 fprintf(stderr,
"Could not set a context!\n");
84 printf(
"Opened \"%s\"\n", alcGetString(device, ALC_DEVICE_SPECIFIER));
90void fwCloseAL(
void *alctx)
100 device = alcGetContextsDevice(ctx);
102 alcMakeContextCurrent(NULL);
103 alcDestroyContext(ctx);
104 alcCloseDevice(device);
109#include "../../libsound/libsound.h"
118 Stack *audio_context_stack;
119 Stack *audio_parent_stack;
120 Stack* doppler_factor_stack;
121 Stack* splitter_source_stack;
123void *Component_Sound_constructor(){
128void Component_Sound_init(
struct tComponent_Sound *t){
132 t->sound_from_audioclip= 0;
135 t->SoundEngineStarted = FALSE;
137 t->prv = Component_Sound_constructor();
139 ppComponent_Sound p = (ppComponent_Sound)t->prv;
141 p->audio_context_stack = newStack(
int);
142 stack_push(
int, p->audio_context_stack, 0);
143 p->audio_parent_stack = newStack(
icset);
144 icset aps = { 0, 0, 0, 0, 0, 0 };
145 stack_push(
icset, p->audio_parent_stack, aps);
146 p->doppler_factor_stack = newStack(
float);
147 stack_push(
float, p->doppler_factor_stack, 1.0f);
148 p->splitter_source_stack = newStack(
ivec2);
149 ivec2 sss = { 0, 0 };
150 stack_push(
ivec2, p->splitter_source_stack, sss);
157void Component_Sound_clear(
struct tComponent_Sound *t){
158 ppComponent_Sound p = (ppComponent_Sound)t->prv;
159 deleteVector(
struct X3D_Node*,p->audio_context_stack);
164float ListenerPos[] = { 0.0, 0.0, 0.0 };
166float ListenerVel[] = { 0.0, 0.0, 0.0 };
168float ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 };
170int SoundEngineInit(
void)
176 ppComponent_Sound p = (ppComponent_Sound)gglobal()->Component_Sound.prv;
181 ConsoleMessage(
"initAL failed\n");
184 p->alContext = alctx;
186 if(!alutInitWithoutContext(NULL,NULL))
188 ALenum error = alutGetError ();
189 ConsoleMessage(
"%s\n", alutGetErrorString (error));
199 alListenerfv(AL_POSITION, ListenerPos);
200 alListenerfv(AL_VELOCITY, ListenerVel);
201 alListenerfv(AL_ORIENTATION, ListenerOri);
205 alSpeedOfSound(345.0f);
207 alSpeedOfSound(1132.0f);
208 alDopplerFactor(1.0f);
211 alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);
220 gglobal()->Component_Sound.SoundEngineStarted = retval;
224int haveSoundEngine(){
225 ttglobal tg = gglobal();
227 if (!tg->Component_Sound.SoundEngineStarted) {
229 printf (
"SetAudioActive: initializing SoundEngine\n");
231 tg->Component_Sound.SoundEngineStarted = SoundEngineInit();
233 return tg->Component_Sound.SoundEngineStarted;
237#define LOAD_INITIAL_STATE 0
238#define LOAD_REQUEST_RESOURCE 1
239#define LOAD_FETCHING_RESOURCE 2
241#define LOAD_STABLE 10
244 resource_item_t *res;
248 if(debug) printf(
"\nurl %s\n", node->url.p[0]->strptr);
249 switch (node->__loadstatus) {
250 case LOAD_INITIAL_STATE:
252 if (node->url.n == 0) {
253 node->__loadstatus = LOAD_STABLE;
256 res = resource_create_multi(&(node->url));
257 if(node->_nodeType == NODE_MovieTexture)
258 res->media_type = resm_movie;
260 res->media_type = resm_audio;
261 node->__loadstatus = LOAD_REQUEST_RESOURCE;
262 node->__loadResource = res;
264 if(debug) printf(
"1");
267 case LOAD_REQUEST_RESOURCE:
268 res = node->__loadResource;
269 resource_identify(node->_parentResource, res);
270 res->actions = resa_download | resa_load;
271 res->ectx = (
void*)node->_executionContext;
272 res->whereToPlaceData = X3D_NODE(node);
274 resitem_enqueue(ml_new(res));
275 node->__loadstatus = LOAD_FETCHING_RESOURCE;
276 if(debug) printf(
"2");
279 case LOAD_FETCHING_RESOURCE:
280 res = node->__loadResource;
284 if (res->status == ress_loaded) {
285 if (res->actions != resa_process) {
286 res->actions = resa_process;
287 res->complete = FALSE;
288 resitem_enqueue(ml_new(res));
290 }
else if ((res->status == ress_failed) || (res->status == ress_invalid)) {
292 printf (
"resource failed to load\n");
293 for(
int ii=0;ii<node->url.n;ii++)
294 printf (
"-- url[%d]=%s\n",ii,node->url.p[ii]->strptr);
295 node->__loadstatus = LOAD_STABLE;
296 node->__sourceNumber = BADAUDIOSOURCE;
297 }
else if (res->status == ress_parsed) {
298 node->__loadstatus = LOAD_STABLE;
302 if(debug) printf(
"3");
306 if(debug) printf(
"4");
313 if(node->__loadstatus > LOAD_INITIAL_STATE && node->__loadstatus < LOAD_STABLE)
315 if(node->__loadstatus == LOAD_STABLE)
327int parse_audioclip(
struct X3D_AudioClip* node,
char* bbuffer,
int len,
char* url) {
329 ALint buffer = AL_NONE;
331 buffer = alutCreateBufferFromFileImage(bbuffer, len);
334 if (buffer == AL_NONE)
335 buffer = BADAUDIOSOURCE;
339 buffer = libsound_createBusFromBuffer0(bbuffer, len);
343 int buffer = BADAUDIOSOURCE;
349double compute_duration(
int ibuffer) {
357 double framesizebytes, bytespersecond;
358 alGetBufferi(ibuffer, AL_FREQUENCY, &ifreq);
359 alGetBufferi(ibuffer, AL_BITS, &ibits);
360 alGetBufferi(ibuffer, AL_CHANNELS, &ichannels);
361 alGetBufferi(ibuffer, AL_SIZE, &ibytes);
362 framesizebytes = (double)(ibits * ichannels) / 8.0;
363 bytespersecond = framesizebytes * (double)ifreq;
364 if (bytespersecond > 0.0)
365 retval = (double)(ibytes) / bytespersecond;
370 retval = libsound_computeDuration0(ibuffer);
374bool process_res_audio(resource_item_t* res) {
390 buffer = res->URLrequest;
402 of = res->openned_files;
408 buffer = of->fileData;
409 len = of->fileDataSize;
415 node->__sourceNumber = parse_audioclip(node, buffer, len, res->actual_file);
416 if (node->__sourceNumber > -1 ) {
417 if (node->_nodeType == NODE_AudioClip) {
418 node->duration_changed = compute_duration(node->__sourceNumber);
419 MARK_EVENT(X3D_NODE(node), offsetof(
struct X3D_AudioClip, duration_changed));
431 indx = node->__sourceNumber;
432 if (indx < 0) retval = 1.0;
433 else if (indx > 50) retval = 1.0;
436#if defined(HAVE_OPENAL) || defined(HAVE_LIBSOUND)
437 retval = node->duration_changed;
454 if (node->__loadstatus != LOAD_STABLE) {
455 locateAudioSource(node);
457 if (node->__loadstatus != LOAD_STABLE)
return;
461 if (node->__sourceNumber == BADAUDIOSOURCE)
return;
465void render_Sound (
struct X3D_Sound *node) {
472 int sound_from_audioclip;
480 if (node->source == NULL)
486 POSSIBLE_PROTO_EXPANSION(
struct X3D_Node *, node->source,tmpN)
489 if (tmpN == NULL)
return;
491 sound_from_audioclip = FALSE;
492 if (tmpN->_nodeType == NODE_AudioClip) {
494 sound_from_audioclip = TRUE;
495 }
else if (tmpN->_nodeType == NODE_MovieTexture){
500 ConsoleMessage (
"Sound node- source type of %s invalid",stringNodeType(tmpN->_nodeType));
514 if(haveSoundEngine()){
515 if( acp->__sourceNumber < 0){
516 render_AudioClip(acp);
518 if( acp->__sourceNumber > -1 ){
521 GLDOUBLE modelMatrix[16];
522 GLDOUBLE SourcePosd[3] = { 0.0f, 0.0f, 0.0f };
523 ALfloat SourcePos[3];
526 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX, modelMatrix);
527 transformAFFINEd(SourcePosd,SourcePosd,modelMatrix);
528 for(i=0;i<3;i++) SourcePos[i] = (ALfloat)SourcePosd[i];
530 if( node->__sourceNumber < 0){
534 alGenSources(1, (ALuint *)&source);
535 alSourcei(source, AL_BUFFER, acp->__sourceNumber);
536 alSourcef (source, AL_PITCH, acp->pitch);
537 alSourcef (source, AL_GAIN, node->intensity );
538 alSourcei (source, AL_LOOPING, acp->loop);
539 alSourcei (source, AL_SOURCE_RELATIVE, AL_TRUE);
541 alSourcef (source, AL_MAX_DISTANCE, node->maxFront);
544 node->__lasttime = TickTime();
545 veccopy3f(node->__lastlocation.c,SourcePos);
547 node->__sourceNumber = source;
549 if(alGetError()!=AL_NO_ERROR) {
552 ConsoleMessage(
"Failed to setup sound source\n");
555 node->__sourceNumber = BADAUDIOSOURCE;
558 if( node->__sourceNumber > -1){
560 ALfloat SourceVel[3] = { 0.0f, 0.0f, 0.0f };
565 alSourcefv(node->__sourceNumber, AL_POSITION, SourcePos);
568 vecdif3f(travelled,node->__lastlocation.c,SourcePos);
569 traveltime = TickTime() - node->__lasttime;
571 vecscale3f(SourceVel,travelled,1.0f/(
float)traveltime);
572 alSourcefv(node->__sourceNumber, AL_VELOCITY, SourceVel);
574 node->__lasttime = TickTime();
575 veccopy3f(node->__lastlocation.c,SourcePos);
581 if(node->spatialize){
585 for(i=0;i<3;i++) dird[i] = node->direction.c[i];
586 transformAFFINEd(dird,dird,modelMatrix);
587 for(i=0;i<3;i++) dirf[i] = (
float)dird[i];
589 alSourcefv(node->__sourceNumber, AL_DIRECTION, dirf);
591 alSource3f(node->__sourceNumber, AL_DIRECTION, dirf[0], dirf[1], dirf[2]);
592 alSourcef(node->__sourceNumber, AL_CONE_OUTER_GAIN, .5f);
593 alSourcef(node->__sourceNumber,AL_CONE_INNER_ANGLE,90.0f);
594 alSourcef(node->__sourceNumber,AL_CONE_OUTER_ANGLE,135.0f);
598 alSourcef (node->__sourceNumber, AL_PITCH, acp->pitch);
599 alSourcef (node->__sourceNumber, AL_GAIN, node->intensity );
600 alSourcei (node->__sourceNumber, AL_LOOPING, acp->loop);
602 if(acp->isPaused) alSourcePause(node->__sourceNumber);
604 alGetSourcei(node->__sourceNumber, AL_SOURCE_STATE,&istate);
606 if(istate != AL_PLAYING && !acp->isPaused){
607 alSourcePlay(node->__sourceNumber);
611 if(istate != AL_STOPPED)
612 alSourceStop(node->__sourceNumber);
620void visit_check_sound(
struct X3D_Node* node,
unsigned int iframe) {}
624void register_visit_check(
struct X3D_Node* node);
625void visit_check_sound(
struct X3D_Node* node,
unsigned int iframe) {
627 if (srep->icontext) {
628 if (iframe == srep->iframe) {
629 libsound_resumeContext0(srep->icontext);
634 libsound_pauseContext0(srep->icontext);
640void push_audio_context(
int audio_context) {
641 ppComponent_Sound p = (ppComponent_Sound)gglobal()->Component_Sound.prv;
642 stack_push(
int, p->audio_context_stack, audio_context);
644int peek_audio_context() {
645 ppComponent_Sound p = (ppComponent_Sound)gglobal()->Component_Sound.prv;
646 return stack_top(
int, p->audio_context_stack);
648void create_and_push_audio_context(
struct X3D_Node* node) {
651 if (!srep->icontext) {
652 int jcontext = peek_audio_context();
654 jcontext = libsound_createContext0();
656 srep->icontext = jcontext;
657 register_visit_check(node);
659 push_audio_context(srep->icontext);
661void pop_audio_context() {
662 ppComponent_Sound p = (ppComponent_Sound)gglobal()->Component_Sound.prv;
663 stack_pop(
int, p->audio_context_stack);
665void push_audio_parent(
int inode) {
666 ppComponent_Sound p = (ppComponent_Sound)gglobal()->Component_Sound.prv;
667 icset aps = { 0, 0, 0, 0, 0, 0 };
671 stack_push(
icset, p->audio_parent_stack, aps);
673void push_audio_parent3(
int inode,
int dstChan,
int lstDst) {
674 ppComponent_Sound p = (ppComponent_Sound)gglobal()->Component_Sound.prv;
675 icset aps = { 0, 0, 0, 0, 0, 0 };
679 stack_push(
icset, p->audio_parent_stack, aps);
681void push_audio_parentnode(
struct X3D_Node* node) {
682 ppComponent_Sound p = (ppComponent_Sound)gglobal()->Component_Sound.prv;
684 push_audio_parent(srep->inode);
686void pop_audio_parent() {
687 ppComponent_Sound p = (ppComponent_Sound)gglobal()->Component_Sound.prv;
688 stack_pop(
icset, p->audio_parent_stack);
690icset peek_audio_parent() {
691 ppComponent_Sound p = (ppComponent_Sound)gglobal()->Component_Sound.prv;
692 return stack_top(
icset, p->audio_parent_stack);
694void push_doppler_factor(
float dopplerFactor) {
695 ppComponent_Sound p = (ppComponent_Sound)gglobal()->Component_Sound.prv;
696 stack_push(
float, p->doppler_factor_stack, dopplerFactor);
699void pop_doppler_factor() {
700 ppComponent_Sound p = (ppComponent_Sound)gglobal()->Component_Sound.prv;
701 stack_pop(
float, p->doppler_factor_stack);
703float peek_doppler_factor() {
704 ppComponent_Sound p = (ppComponent_Sound)gglobal()->Component_Sound.prv;
705 return stack_top(
float, p->doppler_factor_stack);
708void push_splitter_source_index(
int source_index,
int last_source_index) {
709 ppComponent_Sound p = (ppComponent_Sound)gglobal()->Component_Sound.prv;
711 ssi.x = source_index;
712 ssi.y = last_source_index;
713 stack_push(
ivec2, p->splitter_source_stack, ssi);
716void pop_splitter_source_index() {
717 ppComponent_Sound p = (ppComponent_Sound)gglobal()->Component_Sound.prv;
718 stack_pop(
ivec2, p->splitter_source_stack);
720ivec2 peek_splitter_source_index() {
721 ppComponent_Sound p = (ppComponent_Sound)gglobal()->Component_Sound.prv;
722 return stack_top(
ivec2, p->splitter_source_stack);
726 if (!srep->connections) srep->connections = newStack(
ivec3);
728 for (
int i = 0; i < vectorSize(srep->connections); i++) {
729 icset conn = vector_get(
icset, srep->connections, i);
730 if (conn.p == iparent.p && conn.n == iparent.n && conn.d == iparent.d && conn.s == iparent.s)
734 stack_push(
icset, srep->connections, iparent);
736 return 1 - duplicate;
739 if (iparent.d == iparent.ld && iparent.s == iparent.ls)
return 0;
740 if (!srep->connections)
return 0;
742 for (
int i = 0; i < vectorSize(srep->connections); i++) {
743 icset conn = vector_get(
icset, srep->connections, i);
748 if (conn.p == iparent.p && conn.n == iparent.n) {
749 if (iparent.d != iparent.ld && conn.d == iparent.ld)
750 if (conn.s == iparent.s || conn.s == iparent.ls) found_old = i;
751 if (iparent.s != iparent.ls && conn.s == iparent.ls)
752 if (conn.d == iparent.d || conn.d == iparent.ld) found_old = i;
755 if (found_old > -1) {
756 vector_remove_elem(
icset, srep->connections, found_old);
758 return found_old > -1 ? 1 : 0;
762 if (newconnect(srep, iparent)) {
763 libsound_connect(srep->icontext, iparent);
766 if (disconnect(srep, iparent)) {
767 libsound_disconnect(srep->icontext, iparent);
777 if (node->__loadstatus != LOAD_STABLE) {
780 if (node->__loadstatus != LOAD_STABLE)
return;
784 if (node->__sourceNumber == BADAUDIOSOURCE)
return;
785 if (node->__sourceNumber < 0)
return;
786 int icontext = peek_audio_context();
787 if (icontext == 0)
return;
789 struct X3D_SoundRep* srep = getSoundRep(X3D_NODE(node));
790 srep->iframe = gglobal()->Mainloop.iframe;
791 srep->ibuffer = node->__sourceNumber;
792 srep->dopplerFactor = peek_doppler_factor();
794 icset iparent = peek_audio_parent();
798 libsound_updateNode3(icontext, iparent, X3D_NODE(node));
800 iparent.n = srep->inode;
801 update_connections(srep, iparent);
814 struct X3D_SoundRep* srep = getSoundRep(X3D_NODE(node));
815 srep->iframe = gglobal()->Mainloop.iframe;
816 if (node->__loadstatus == LOAD_STABLE)
return;
817 if (node->url.n == 0) {
819 if (node->__loadstatus != LOAD_STABLE) {
821 if (node->buffer.n) {
822 node->__sourceNumber = libsound_createBusFromPCM32(node->buffer.p, node->bufferChannels, node->buffer.n);
823 srep->ibuffer = node->__sourceNumber;
824 node->__loadstatus = LOAD_STABLE;
832 if (node->__loadstatus != LOAD_STABLE) {
833 locateAudioSource(node);
835 if (node->__loadstatus != LOAD_STABLE)
return;
839 if (node->__sourceNumber == BADAUDIOSOURCE)
return;
840 srep->ibuffer = node->__sourceNumber;
848 struct X3D_SoundRep* srep = getSoundRep(X3D_NODE(node));
849 srep->iframe = gglobal()->Mainloop.iframe;
850 if (node->buffer && node->buffer->_nodeType == NODE_AudioBuffer) {
852 render_AudioBuffer(AB);
853 if (AB->_ichange != AB->_change)
855 AB->_ichange = AB->_change;
856 srep->ibuffer = max(0,AB->__sourceNumber);
857 node->__sourceNumber = AB->__sourceNumber;
860 icset iparent = peek_audio_parent();
861 if (node->_ichange != node->_change) {
864 int icontext = peek_audio_context();
865 libsound_updateNode3(icontext, iparent, anode);
867 node->_ichange = node->_change;
870 iparent.n = srep->inode;
871 update_connections(srep, iparent);
884 icset have_parent = peek_audio_parent();
885 create_and_push_audio_context(anode);
887 push_audio_parent(1);
894 struct X3D_SoundRep* srep = getSoundRep(X3D_NODE(node));
895 srep->iframe = gglobal()->Mainloop.iframe;
896 if (node->children.n) {
897 for (
int i = 0; i < node->children.n; i++)
899 render_node(X3D_NODE(node->children.p[i]));
907static double listenerpoint_matrix[16];
911 singleton_listenerpoint = node;
912 double modelview[16];
913 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX, modelview);
920 double matt[16], matr[16], mat[16], matinv[16], mattot[16];
922 float2double(cc, node->orientation.c,4);
923 float2double(pp, node->position.c,3);
925 matrixFromAxisAngle4d(matr, cc[3], cc[0], cc[1], cc[2]);
926 mattranslate(matt, pp[0], pp[1], pp[2]);
927 matmultiplyAFFINE(mat, matr, matt);
928 matmultiplyAFFINE(mattot, mat, modelview);
930 matinverseAFFINE(matinv, mattot);
931 matcopy(listenerpoint_matrix, matinv);
934 matcopy(listenerpoint_matrix, mattot);
939 if (node->visualization) {
941 FW_GL_TRANSFORM_D(mat);
942 render_node(X3D_NODE(node->visualization));
947 double position[3], direction[3], up[3];
948 float posf[3], dirf[3], upf[3];
949 int trackview = node->trackCurrentView ? 1 : 0;
950 vecsetd(position, 0.0, 0.0, 0.0);
951 transformAFFINEd(position, position, listenerpoint_matrix);
953 vecsetd(direction, 1.0,0.0, 0.0);
954 vecsetd(up, 0.0, 1.0, 0.0);
955 transformAFFINEd(direction, direction, listenerpoint_matrix);
956 vecdifd(direction, direction, position);
957 vecnormald(direction, direction);
958 transformAFFINEd(up, up, listenerpoint_matrix);
959 vecdifd(up, up, position);
962 double2float(posf, position, 3);
963 double2float(dirf, direction, 3);
964 double2float(upf, up, 3);
965 libsound_setListenerPose(posf, dirf, upf, trackview);
968void update_Sound_pose(
struct X3D_Sound* node){
974 GLDOUBLE modelMatrix[16];
975 GLDOUBLE SourcePosd[3] = { 0.0f, 0.0f, 0.0f };
979 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX, modelMatrix);
981 transformAFFINEd(SourcePosd, SourcePosd, modelMatrix);
982 for (i = 0; i < 3; i++) SourcePos[i] = (
float)SourcePosd[i];
984 if (node->__sourceNumber < 0) {
985 node->__lasttime = TickTime();
986 veccopy3f(node->__lastlocation.c, SourcePos);
988 node->__sourceNumber = 0;
990 if (node->__sourceNumber > -1) {
992 float SourceVel[3] = { 0.0f, 0.0f, 0.0f };
997 vecdif3f(travelled, SourcePos, node->__lastlocation.c);
998 traveltime = TickTime() - node->__lasttime;
999 if (traveltime > 0.0)
1000 vecscale3f(node->__velocity.c, travelled, 1.0f / (
float)traveltime);
1003 node->__lasttime = TickTime();
1004 veccopy3f(node->__lastlocation.c, SourcePos);
1014 float2double(dird, node->direction.c, 3);
1015 vecsetd(zero, 0.0, 0.0, 0.0);
1018 transformAFFINEd(dird, dird, modelMatrix);
1019 transformAFFINEd(zero, zero, modelMatrix);
1021 vecdifd(dird, dird, zero);
1022 vecnormald(dird, dird);
1024 double2float(node->__lastdirection.c, dird, 3);
1039void render_Sound(
struct X3D_Sound* node) {
1041 icset have_parent = peek_audio_parent();
1042 create_and_push_audio_context(anode);
1043 update_Sound_pose(node);
1045 push_audio_parent(1);
1046 int icontext = peek_audio_context();
1047 libsound_updateNode3(icontext,peek_audio_parent(), anode);
1048 push_audio_parentnode(anode);
1049 struct X3D_SoundRep* srep = getSoundRep(X3D_NODE(node));
1050 srep->iframe = gglobal()->Mainloop.iframe;
1054 render_node(node->source);
1055 if (node->children.n) {
1056 for (
int i = 0; i < node->children.n; i++)
1058 render_node(X3D_NODE(node->children.p[i]));
1063 pop_audio_context();
1068 icset have_parent = peek_audio_parent();
1069 create_and_push_audio_context(anode);
1070 update_Sound_pose((
struct X3D_Sound*)node);
1072 push_audio_parent(1);
1073 int icontext = peek_audio_context();
1074 libsound_updateNode3(icontext, peek_audio_parent(), anode);
1075 push_doppler_factor(node->__dopplerFactor);
1076 push_audio_parentnode(anode);
1079 struct X3D_SoundRep* srep = getSoundRep(X3D_NODE(node));
1080 srep->iframe = gglobal()->Mainloop.iframe;
1081 if (node->children.n) {
1082 for (
int i = 0; i < node->children.n; i++)
1084 render_node(X3D_NODE(node->children.p[i]));
1087 pop_doppler_factor(node->__dopplerFactor);
1090 pop_audio_context();
1101 struct X3D_SoundRep* srep = getSoundRep(X3D_NODE(node));
1102 srep->iframe = gglobal()->Mainloop.iframe;
1106 icset iparent = peek_audio_parent();
1107 if (node->_ichange != node->_change) {
1111 int icontext = peek_audio_context();
1112 libsound_updateNode3(icontext, iparent, anode);
1114 node->_ichange = node->_change;
1117 iparent.n = srep->inode;
1118 update_connections(srep, iparent);
1124 if (node->periodicWave) {
1125 push_audio_parent(srep->inode);
1133 struct X3D_SoundRep* srep = getSoundRep(X3D_NODE(node));
1134 srep->iframe = gglobal()->Mainloop.iframe;
1135 if (node->_ichange != node->_change) {
1139 int icontext = peek_audio_context();
1140 icset iparent = peek_audio_parent();
1141 libsound_updateNode3(icontext, iparent, anode);
1149 struct X3D_SoundRep* srep = getSoundRep(X3D_NODE(node));
1150 srep->iframe = gglobal()->Mainloop.iframe;
1152 icset iparent = peek_audio_parent();
1153 if (node->_ichange != node->_change) {
1154 int icontext = peek_audio_context();
1155 libsound_updateNode3(icontext, iparent, anode);
1157 node->_ichange = node->_change;
1160 iparent.n = srep->inode;
1161 update_connections(srep, iparent);
1170 int inode = srep->inode;
1172 if (node->children.n) {
1174 if (noisy) printf(
"render_merger nchan %d\n", node->indexDestination.n);
1175 if (noisy) libsound_print_connections();
1176 if (node->selectors.n) {
1180 for (
int i = 0; i < node->selectors.n; i++) {
1182 if (!selector->_initialized) {
1183 selector->_lastChannelDestination = selector->channelDestination;
1184 selector->_lastChannelSource = selector->channelSource;
1185 selector->_lastStream = selector->stream;
1186 selector->_initialized = TRUE;
1189 int destination_index = selector->channelDestination;
1190 int last_destination_index = selector->_lastChannelDestination;
1191 int source_index = selector->channelSource;
1192 int last_source_index = selector->_lastChannelSource;
1193 if (noisy) printf(
"%d indxDst %d indxSrc %d\n", i, destination_index, source_index);
1194 if (source_index > -1) push_splitter_source_index(source_index, last_source_index);
1195 if (destination_index != last_destination_index)
1196 printf(
"changing destination\n");
1197 push_audio_parent3(inode, destination_index, last_destination_index);
1201 int ichild = selector->stream;
1202 render_node(X3D_NODE(node->children.p[ichild]));
1204 if (source_index > -1) pop_splitter_source_index();
1205 if (noisy) libsound_print_connections();
1206 if (noisy) printf(
"\n");
1207 selector->_lastChannelDestination = selector->channelDestination;
1208 selector->_lastChannelSource = selector->channelSource;
1209 selector->_lastStream = selector->stream;
1211 }
else if (node->indexDestination.n && node->indexSource.n && node->indexStream.n) {
1213 for (
int i = 0; i < node->indexDestination.n; i++) {
1214 int destination_index = node->indexDestination.p[i];
1215 int last_destination_index = srep->last_indexDestination[i];
1216 int source_index = node->indexSource.p[i];
1217 int last_source_index = srep->last_indexSource[i];
1218 if (noisy) printf(
"%d indxDst %d indxSrc %d\n", i, destination_index, source_index);
1219 if (source_index > -1) push_splitter_source_index(source_index, last_source_index);
1220 push_audio_parent3(inode, destination_index, last_destination_index);
1224 int ichild = node->indexStream.p[min(i, node->indexStream.n - 1)];
1225 render_node(X3D_NODE(node->children.p[ichild]));
1227 if (source_index > -1) pop_splitter_source_index();
1228 if (noisy) libsound_print_connections();
1229 if (noisy) printf(
"\n");
1231 memcpy(srep->last_indexSource, node->indexSource.p, node->indexSource.n *
sizeof(
int));
1232 memcpy(srep->last_indexDestination, node->indexDestination.p, node->indexDestination.n *
sizeof(
int));
1233 srep->last_count = node->indexDestination.n;
1236 for (
int i = 0; i < node->children.n; i++) {
1237 int destination_index = i;
1238 if (noisy) printf(
"%d indxDst %d \n", i, destination_index);
1239 push_audio_parent3(inode, destination_index, 0);
1243 render_node(X3D_NODE(node->children.p[ichild]));
1245 if (noisy) libsound_print_connections();
1246 if (noisy) printf(
"\n");
1257 if (!selector->_initialized) {
1258 selector->_lastChannelSource = selector->channelSource;
1259 selector->_initialized = TRUE;
1262 int source_index = selector->channelSource;
1263 int last_source_index = selector->_lastChannelSource;
1264 if (source_index > -1) push_splitter_source_index(source_index, last_source_index);
1265 if (node->children.n) {
1266 for (
int i = 0; i < node->children.n; i++)
1268 render_node(X3D_NODE(node->children.p[i]));
1270 pop_splitter_source_index();
1271 selector->_lastChannelSource = selector->channelSource;
1275 struct X3D_SoundRep* srep = getSoundRep(X3D_NODE(node));
1276 srep->iframe = gglobal()->Mainloop.iframe;
1278 ivec2 splitter_source_index = peek_splitter_source_index();
1279 icset iparent = peek_audio_parent();
1280 iparent.s = splitter_source_index.x;
1281 iparent.ls = splitter_source_index.y;
1282 if (node->_ichange != node->_change) {
1283 int icontext = peek_audio_context();
1284 libsound_updateNode3(icontext, iparent, anode);
1286 node->_ichange = node->_change;
1288 iparent.n = srep->inode;
1289 update_connections(srep, iparent);
1299 push_audio_parentnode(anode);
1302 if (node->children.n) {
1303 for (
int i = 0; i < node->children.n; i++)
1305 render_node(X3D_NODE(node->children.p[i]));
1311void render_Gain(
struct X3D_Gain* node) {
1312 struct X3D_SoundRep* srep = getSoundRep(X3D_NODE(node));
1313 srep->iframe = gglobal()->Mainloop.iframe;
1315 icset iparent = peek_audio_parent();
1317 if (node->_ichange != node->_change) {
1319 int icontext = peek_audio_context();
1320 libsound_updateNode3(icontext, iparent, anode);
1322 node->_ichange = node->_change;
1324 iparent.n = srep->inode;
1326 update_connections(srep, iparent);
1332 push_audio_parentnode(anode);
1334 if (node->children.n) {
1335 for (
int i = 0; i < node->children.n; i++)
1337 render_node(X3D_NODE(node->children.p[i]));
1343void render_Delay(
struct X3D_Delay* node) {
1344 struct X3D_SoundRep* srep = getSoundRep(X3D_NODE(node));
1345 srep->iframe = gglobal()->Mainloop.iframe;
1347 icset iparent = peek_audio_parent();
1349 if (node->_ichange != node->_change) {
1353 int icontext = peek_audio_context();
1354 libsound_updateNode3(icontext, iparent, anode);
1356 node->_ichange = node->_change;
1358 iparent.n = srep->inode;
1360 update_connections(srep, iparent);
1367 push_audio_parentnode(anode);
1369 if (node->children.n) {
1370 for (
int i = 0; i < node->children.n; i++)
1372 render_node(X3D_NODE(node->children.p[i]));
1379 struct X3D_SoundRep* srep = getSoundRep(X3D_NODE(node));
1380 srep->iframe = gglobal()->Mainloop.iframe;
1382 icset iparent = peek_audio_parent();
1383 if (node->_ichange != node->_change) {
1387 int icontext = peek_audio_context();
1388 libsound_updateNode3(icontext, iparent, anode);
1390 node->_ichange = node->_change;
1392 MARK_EVENT(X3D_NODE(node), offsetof(
struct X3D_Analyser, floatFrequencyData));
1394 MARK_EVENT(X3D_NODE(node), offsetof(
struct X3D_Analyser, floatTimeDomainData));
1399 iparent.n = srep->inode;
1401 update_connections(srep, iparent);
1407 push_audio_parentnode(anode);
1409 if (node->children.n) {
1410 for (
int i = 0; i < node->children.n; i++)
1412 render_node(X3D_NODE(node->children.p[i]));
1418 struct X3D_SoundRep* srep = getSoundRep(X3D_NODE(node));
1419 srep->iframe = gglobal()->Mainloop.iframe;
1421 icset iparent = peek_audio_parent();
1422 if (node->_ichange != node->_change) {
1426 int icontext = peek_audio_context();
1427 libsound_updateNode3(icontext, iparent, anode);
1429 node->_ichange = node->_change;
1431 iparent.n = srep->inode;
1433 update_connections(srep, iparent);
1439 push_audio_parentnode(anode);
1441 if (node->children.n) {
1442 for (
int i = 0; i < node->children.n; i++)
1444 render_node(X3D_NODE(node->children.p[i]));
1451 struct X3D_SoundRep* srep = getSoundRep(X3D_NODE(node));
1452 srep->iframe = gglobal()->Mainloop.iframe;
1454 icset iparent = peek_audio_parent();
1456 if (node->_ichange != node->_change) {
1460 int icontext = peek_audio_context();
1461 libsound_updateNode3(icontext, iparent, anode);
1463 node->_ichange = node->_change;
1467 iparent.n = srep->inode;
1469 update_connections(srep, iparent);
1475 push_audio_parentnode(anode);
1477 if (node->children.n) {
1478 for (
int i = 0; i < node->children.n; i++)
1480 render_node(X3D_NODE(node->children.p[i]));
1486 struct X3D_SoundRep* srep = getSoundRep(X3D_NODE(node));
1487 srep->iframe = gglobal()->Mainloop.iframe;
1489 icset iparent = peek_audio_parent();
1491 if (node->_ichange != node->_change) {
1494 int icontext = peek_audio_context();
1495 libsound_updateNode3(icontext, iparent, anode);
1497 node->_ichange = node->_change;
1500 iparent.n = srep->inode;
1502 update_connections(srep, iparent);
1508 push_audio_parentnode(anode);
1510 if (node->children.n) {
1511 for (
int i = 0; i < node->children.n; i++)
1513 render_node(X3D_NODE(node->children.p[i]));
1522 struct X3D_SoundRep* srep = getSoundRep(X3D_NODE(node));
1523 srep->iframe = gglobal()->Mainloop.iframe;
1525 icset iparent = peek_audio_parent();
1526 if (node->buffer && node->buffer->_nodeType == NODE_AudioBuffer) {
1528 if (node->buffer->_ichange != node->buffer->_change)
1530 node->buffer->_ichange = node->buffer->_change;
1532 if (node->_ichange != node->_change) {
1535 int icontext = peek_audio_context();
1536 libsound_updateNode3(icontext, iparent, anode);
1538 node->_ichange = node->_change;
1541 iparent.n = srep->inode;
1543 update_connections(srep, iparent);
1548 push_audio_parentnode(anode);
1550 if (node->children.n) {
1551 for (
int i = 0; i < node->children.n; i++)
1553 render_node(X3D_NODE(node->children.p[i]));
1561 struct X3D_SoundRep* srep = getSoundRep(X3D_NODE(node));
1562 srep->iframe = gglobal()->Mainloop.iframe;
1564 icset iparent = peek_audio_parent();
1566 if (node->_ichange != node->_change) {
1569 int icontext = peek_audio_context();
1570 libsound_updateNode3(icontext, iparent, anode);
1572 node->_ichange = node->_change;
1575 iparent.n = srep->inode;
1577 update_connections(srep, iparent);
1623void render_Delay(
struct X3D_Delay* node) {}
1625void render_Gain(
struct X3D_Gain* node) {}