//* // ======================================================================================================================= // ======================================================================================================================= // BOOL sound_Play3DSample( TRACK *psTrack, AUDIO_SAMPLE *psSample ) { #ifndef WZ_NOSOUND ALfloat zero[3] = { 0.0, 0.0, 0.0 }; ALfloat volume; ALint error; if (sfx3d_volume == 0.0) { return false; } volume = ((float)psTrack->iVol / 100.f); // max range is 0-100 psSample->fVol = volume; // store results for later // If we can't hear it, then don't bother playing it. if (volume == 0.0f) { return false; } // Clear error codes alGetError(); alGenSources( 1, &(psSample->iSample) ); error = sound_GetError(); if (error != AL_NO_ERROR) { /* FIXME: We run out of OpenAL sources very quickly, so we * should handle the case where we've ran out of them. * Currently we don't do this, causing some unpleasant side * effects, e.g. crashing... */ } // HACK: this is a workaround for a bug in the 64bit implementation of OpenAL on GNU/Linux // The AL_PITCH value really should be 1.0. alSourcef(psSample->iSample, AL_PITCH, 1.001f); sound_SetObjectPosition( psSample ); alSourcefv( psSample->iSample, AL_VELOCITY, zero ); alSourcei( psSample->iSample, AL_BUFFER, psTrack->iBufferName ); alSourcei( psSample->iSample, AL_LOOPING, (sound_SetupChannel(psSample)) ? AL_TRUE : AL_FALSE ); // NOTE: this is only useful for debugging. #ifdef DEBUG psSample->is3d = true; psSample->isLooping = sound_TrackLooped(psSample->iTrack)? AL_TRUE : AL_FALSE; memcpy(psSample->filename,psTrack->fileName, strlen(psTrack->fileName)); psSample->filename[strlen(psTrack->fileName)]='\0'; #endif // Clear error codes alGetError(); alSourcePlay( psSample->iSample ); sound_GetError(); #endif return true; }
void audio_Update() { //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Vector3f playerPos; float angle; AUDIO_SAMPLE *psSample, *psSampleTemp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // if audio not enabled return true to carry on game without audio if ( g_bAudioEnabled == false ) { return; } #ifndef WZ_NOSOUND alGetError(); // clear error codes #endif audio_UpdateQueue(); #ifndef WZ_NOSOUND alGetError(); // clear error codes #endif // get player position playerPos = audio_GetPlayerPos(); audio_Get3DPlayerRotAboutVerticalAxis(&angle); sound_SetPlayerPos(playerPos); sound_SetPlayerOrientation(angle); // loop through 3D sounds and remove if finished or update position psSample = g_psSampleList; while ( psSample != NULL ) { // remove finished samples from list if ( psSample->bFinishedPlaying == true ) { psSampleTemp = psSample->psNext; audio_RemoveSample( &g_psSampleList, psSample ); free(psSample); psSample = psSampleTemp; } // check looping sound callbacks for finished condition else { if ( psSample->psObj != NULL ) { if ( audio_ObjectDead(psSample->psObj) || (psSample->pCallback != NULL && psSample->pCallback(psSample->psObj) == false) ) { sound_StopTrack( psSample ); psSample->psObj = NULL; } else { // update sample position { audio_GetObjectPos( psSample->psObj, &psSample->x, &psSample->y, &psSample->z ); #ifndef WZ_NOSOUND sound_SetObjectPosition(psSample); #endif } } } // next sample psSample = psSample->psNext; } } sound_Update(); return; }