/* * 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)); }
static void AL_InitStreamSource() { qalSourcei (streamSource, AL_BUFFER, 0 ); qalSourcei (streamSource, AL_LOOPING, AL_FALSE ); qalSource3f(streamSource, AL_POSITION, 0.0, 0.0, 0.0); qalSource3f(streamSource, AL_VELOCITY, 0.0, 0.0, 0.0); qalSource3f(streamSource, AL_DIRECTION, 0.0, 0.0, 0.0); qalSourcef (streamSource, AL_ROLLOFF_FACTOR, 0.0 ); qalSourcei (streamSource, AL_SOURCE_RELATIVE, AL_TRUE ); }
static void music_source_get( void ) { // Allocate a source at high priority src = S_AllocSource( SRCPRI_STREAM, -2, 0 ); if( !src ) return; S_LockSource( src ); source = S_GetALSource( src ); qalSource3f( source, AL_POSITION, 0.0, 0.0, 0.0 ); qalSource3f( source, AL_VELOCITY, 0.0, 0.0, 0.0 ); qalSource3f( source, AL_DIRECTION, 0.0, 0.0, 0.0 ); qalSourcef( source, AL_ROLLOFF_FACTOR, 0.0 ); qalSourcei( source, AL_SOURCE_RELATIVE, AL_TRUE ); qalSourcef( source, AL_GAIN, s_musicvolume->value ); }
/* ================= S_AL_MusicSourceGet ================= */ static void S_AL_MusicSourceGet( void ) { // Allocate a musicSource at high priority musicSourceHandle = S_AL_SrcAlloc(SRCPRI_STREAM, -2, 0); if(musicSourceHandle == -1) return; // Lock the musicSource so nobody else can use it, and get the raw musicSource S_AL_SrcLock(musicSourceHandle); musicSource = S_AL_SrcGet(musicSourceHandle); // Set some musicSource parameters qalSource3f(musicSource, AL_POSITION, 0.0, 0.0, 0.0); qalSource3f(musicSource, AL_VELOCITY, 0.0, 0.0, 0.0); qalSource3f(musicSource, AL_DIRECTION, 0.0, 0.0, 0.0); qalSourcef (musicSource, AL_ROLLOFF_FACTOR, 0.0 ); qalSourcei (musicSource, AL_SOURCE_RELATIVE, AL_TRUE ); }
/* * Plays a channel (in the frontends * sense) with OpenAL. */ void AL_PlayChannel(channel_t *ch) { sfxcache_t *sc; float vol; /* Debug */ if (s_show->value > 1) { Com_Printf("%s: %s\n", __func__, ch->sfx->name); } /* Clamp volume */ vol = ch->oal_vol; if (vol > 1.0f) { vol = 1.0f; } sc = ch->sfx->cache; ch->srcnum = s_srcnums[ch - channels]; qalGetError(); qalSourcef(ch->srcnum, AL_REFERENCE_DISTANCE, SOUND_FULLVOLUME); qalSourcef(ch->srcnum, AL_MAX_DISTANCE, 8192); qalSourcef(ch->srcnum, AL_ROLLOFF_FACTOR, ch->dist_mult * (8192 - SOUND_FULLVOLUME)); qalSourcef(ch->srcnum, AL_GAIN, vol); qalSourcei(ch->srcnum, AL_BUFFER, sc->bufnum); qalSourcei(ch->srcnum, AL_LOOPING, ch->autosound ? AL_TRUE : AL_FALSE); if ((ch->entnum == -1) || (ch->entnum == cl.playernum + 1) || !ch->dist_mult) { /* anything coming from the view entity will always * be full volume and at the listeners position */ qalSource3f(ch->srcnum, AL_POSITION, 0.0f, 0.0f, 0.0f); qalSourcei(ch->srcnum, AL_SOURCE_RELATIVE, AL_TRUE); } else { /* all other sources are *not* relative */ qalSourcei(ch->srcnum, AL_SOURCE_RELATIVE, AL_FALSE); } /* Spatialize it */ AL_Spatialize(ch); /* Play it */ qalSourcePlay(ch->srcnum); /* Do not play broken channels */ if (qalGetError() != AL_NO_ERROR) { AL_StopChannel(ch); } }
/* ================= S_AL_AllocateStreamChannel ================= */ static void S_AL_AllocateStreamChannel( void ) { // Allocate a streamSource at high priority streamSourceHandle = S_AL_SrcAlloc(SRCPRI_STREAM, -2, 0); if(streamSourceHandle == -1) return; // Lock the streamSource so nobody else can use it, and get the raw streamSource S_AL_SrcLock(streamSourceHandle); streamSource = S_AL_SrcGet(streamSourceHandle); // Set some streamSource parameters qalSourcei (streamSource, AL_BUFFER, 0 ); qalSourcei (streamSource, AL_LOOPING, AL_FALSE ); qalSource3f(streamSource, AL_POSITION, 0.0, 0.0, 0.0); qalSource3f(streamSource, AL_VELOCITY, 0.0, 0.0, 0.0); qalSource3f(streamSource, AL_DIRECTION, 0.0, 0.0, 0.0); qalSourcef (streamSource, AL_ROLLOFF_FACTOR, 0.0 ); qalSourcei (streamSource, AL_SOURCE_RELATIVE, AL_TRUE ); }
/** * Source aquire / release */ static void al_mus_source_get( void ) { // Allocate a source at high priority source_handle = al_src_alloc( SRCPRI_STREAM, -2, 0 ); if ( source_handle == -1 ) { return; } // Lock the source so nobody else can use it, and get the raw source al_src_lock( source_handle ); source = al_src_get( source_handle ); // Set some source parameters qalSource3f( source, AL_POSITION, 0.0, 0.0, 0.0 ); qalSource3f( source, AL_VELOCITY, 0.0, 0.0, 0.0 ); qalSource3f( source, AL_DIRECTION, 0.0, 0.0, 0.0 ); qalSourcef( source, AL_ROLLOFF_FACTOR, 0.0 ); qalSourcei( source, AL_SOURCE_RELATIVE, AL_TRUE ); }
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 ) ); }