/* * S_SetListener */ static void S_SetListener( const vec3_t origin, const vec3_t velocity, const mat3_t axis ) { float orientation[6]; orientation[0] = axis[AXIS_FORWARD+0]; orientation[1] = axis[AXIS_FORWARD+1]; orientation[2] = axis[AXIS_FORWARD+2]; orientation[3] = axis[AXIS_UP+0]; orientation[4] = axis[AXIS_UP+1]; orientation[5] = axis[AXIS_UP+2]; qalListenerfv( AL_POSITION, origin ); qalListenerfv( AL_VELOCITY, velocity ); qalListenerfv( AL_ORIENTATION, orientation ); }
void SndAl_Respatialize( int entityNum, const vec3_t origin, vec3_t axis[ 3 ], int inwater ) { // Axis[0] = Forward // Axis[2] = Up float velocity[] = { 0.0f, 0.0f, 0.0f }; float orientation[] = { axis[ 0 ][ 0 ], axis[ 0 ][ 1 ], axis[ 0 ][ 2 ], axis[ 2 ][ 0 ], axis[ 2 ][ 1 ], axis[ 2 ][ 2 ] }; vec3_t sorigin; // Set OpenAL listener paramaters VectorScale( origin, POSITION_SCALE, sorigin ); qalListenerfv( AL_POSITION, sorigin ); qalListenerfv( AL_VELOCITY, velocity ); qalListenerfv( AL_ORIENTATION, orientation ); }
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(); }
/* * S_Update */ void S_Update( const vec3_t origin, const vec3_t velocity, const vec3_t forward, const vec3_t right, const vec3_t up, qboolean avidump ) { float orientation[6]; orientation[0] = forward[0]; orientation[1] = forward[1]; orientation[2] = forward[2]; orientation[3] = up[0]; orientation[4] = up[1]; orientation[5] = up[2]; qalListenerfv( AL_POSITION, origin ); qalListenerfv( AL_VELOCITY, velocity ); qalListenerfv( AL_ORIENTATION, orientation ); S_UpdateSources(); S_UpdateStream(); S_UpdateMusic(); s_volume->modified = qfalse; // Checked by src and stream s_musicvolume->modified = qfalse; // Checked by stream and music if( s_doppler->modified ) { if( s_doppler->value > 0.0f ) qalDopplerFactor( s_doppler->value ); else qalDopplerFactor( 0.0f ); s_doppler->modified = qfalse; } if( s_sound_velocity->modified ) { qalDopplerVelocity( s_sound_velocity->value > 0.0f ? s_sound_velocity->value : 0.0f ); if( qalSpeedOfSound ) qalSpeedOfSound( s_sound_velocity->value > 0.0f ? s_sound_velocity->value : 0.0f ); s_sound_velocity->modified = qfalse; } }
/* ================= S_AL_Respatialize ================= */ static void S_AL_Respatialize( int entityNum, const vec3_t origin, vec3_t axis[3], int inwater ) { float velocity[3] = {0.0f, 0.0f, 0.0f}; float orientation[6]; vec3_t sorigin; VectorCopy( origin, sorigin ); S_AL_SanitiseVector( sorigin ); S_AL_SanitiseVector( axis[ 0 ] ); S_AL_SanitiseVector( axis[ 1 ] ); S_AL_SanitiseVector( axis[ 2 ] ); orientation[0] = axis[0][0]; orientation[1] = axis[0][1]; orientation[2] = axis[0][2]; orientation[3] = axis[2][0]; orientation[4] = axis[2][1]; orientation[5] = axis[2][2]; VectorCopy( sorigin, lastListenerOrigin ); // Set OpenAL listener paramaters qalListenerfv(AL_POSITION, (ALfloat *)sorigin); qalListenerfv(AL_VELOCITY, velocity); qalListenerfv(AL_ORIENTATION, orientation); }