/* * Performance stereo spatialization * of a channel in the frontends * sense. */ static void AL_Spatialize(channel_t *ch) { vec3_t origin; if ((ch->entnum == -1) || (ch->entnum == cl.playernum + 1) || !ch->dist_mult) { /* from view entity (player) => nothing to do, * position is still (0,0,0) and relative, * as set in AL_PlayChannel() */ return; } else if (ch->fixed_origin) { VectorCopy(ch->origin, origin); qalSource3f(ch->srcnum, AL_POSITION, AL_UnpackVector(origin)); return; } else { CL_GetEntitySoundOrigin(ch->entnum, origin); qalSource3f(ch->srcnum, AL_POSITION, AL_UnpackVector(origin)); return; } }
/* * Performance stereo spatialization * of a channel in the frontends * sense. */ static void AL_Spatialize(channel_t *ch) { vec3_t origin; /* anything coming from the view entity will always be full volume. no attenuation = no spatialization */ if ((ch->entnum == -1) || (ch->entnum == cl.playernum + 1) || !ch->dist_mult) { qalSource3f(ch->srcnum, AL_POSITION, 0,0,0); qalSourcei(ch->srcnum, AL_SOURCE_RELATIVE, AL_TRUE); return; } if (ch->fixed_origin) { VectorCopy(ch->origin, origin); } else { CL_GetEntitySoundOrigin(ch->entnum, origin); } qalSourcei(ch->srcnum, AL_SOURCE_RELATIVE, AL_FALSE); qalSource3f(ch->srcnum, AL_POSITION, AL_UnpackVector(origin)); }
void AL_Update(void) { int i; channel_t *ch; vec_t orientation[6]; if (!s_active) { return; } paintedtime = cl.time; // set listener parameters qalListener3f(AL_POSITION, AL_UnpackVector(listener_origin)); AL_CopyVector(listener_forward, orientation); AL_CopyVector(listener_up, orientation + 3); qalListenerfv(AL_ORIENTATION, orientation); qalListenerf(AL_GAIN, s_volume->value); qalDistanceModel(AL_LINEAR_DISTANCE_CLAMPED); // update spatialization for dynamic sounds ch = channels; for (i = 0; i < s_numchannels; i++, ch++) { if (!ch->sfx) continue; if (ch->autosound) { // autosounds are regenerated fresh each frame if (ch->autoframe != s_framecount) { AL_StopChannel(ch); continue; } } else { ALenum state; qalGetError(); qalGetSourcei(ch->srcnum, AL_SOURCE_STATE, &state); if (qalGetError() != AL_NO_ERROR || state == AL_STOPPED) { AL_StopChannel(ch); continue; } } #ifdef _DEBUG if (s_show->integer) { Com_Printf("%.1f %s\n", ch->master_vol, ch->sfx->name); // total++; } #endif AL_Spatialize(ch); // respatialize channel } s_framecount++; // add loopsounds AL_AddLoopSounds(); AL_IssuePlaysounds(); }
/* * Main update function. Called every frame, * performes all necessary calculations. */ void AL_Update ( void ) { q_int32_t i; channel_t *ch; vec_t orientation[6]; paintedtime = cl.time; /* set listener (player) parameters */ AL_CopyVector ( listener_forward, orientation ); AL_CopyVector ( listener_up, orientation + 3 ); qalListenerf ( AL_GAIN, s_volume->value ); qalListenerf ( AL_MAX_GAIN, s_openal_maxgain->value ); qalDistanceModel ( AL_LINEAR_DISTANCE_CLAMPED ); qalListener3f ( AL_POSITION, AL_UnpackVector ( listener_origin ) ); qalListenerfv ( AL_ORIENTATION, orientation ); /* update spatialization for dynamic sounds */ ch = channels; for ( i = 0; i < s_numchannels; i++, ch++ ) { if ( !ch->sfx ) { continue; } if ( ch->autosound ) { /* autosounds are regenerated fresh each frame */ if ( ch->autoframe != s_framecount ) { AL_StopChannel ( ch ); continue; } } else { ALenum state; qalGetError(); qalGetSourcei ( ch->srcnum, AL_SOURCE_STATE, &state ); if ( ( qalGetError() != AL_NO_ERROR ) || ( state == AL_STOPPED ) ) { AL_StopChannel ( ch ); continue; } } if ( s_show->value ) { Com_Printf ( "%3i %s\n", ch->master_vol, ch->sfx->name ); } /* respatialize channel */ AL_Spatialize ( ch ); } s_framecount++; /* add loopsounds */ AL_AddLoopSounds(); /* add music */ #ifdef HT_WITH_OGG OGG_Stream(); #endif AL_StreamUpdate(); AL_IssuePlaysounds(); }
static void AL_Spatialize( channel_t *ch ) { vec3_t origin; // anything coming from the view entity will always be full volume // no attenuation = no spatialization if( ch->entnum == -1 || ch->entnum == cl.playernum + 1 || !ch->dist_mult ) { VectorCopy( listener_origin, origin ); } else if( ch->fixed_origin ) { VectorCopy( ch->origin, origin ); } else { CL_GetEntitySoundOrigin( ch->entnum, origin ); } qalSource3f( ch->srcnum, AL_POSITION, AL_UnpackVector( origin ) ); }