//* // ======================================================================================================================= // ======================================================================================================================= // 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; }
//* // ======================================================================================================================= // ======================================================================================================================= // bool sound_Play2DSample(TRACK *psTrack, AUDIO_SAMPLE *psSample, bool bQueued) { ALfloat zero[3] = { 0.0, 0.0, 0.0 }; ALfloat volume; ALint error; if (sfx_volume == 0.0) { return false; } volume = ((float)psTrack->iVol / 100.0f); // each object can have OWN volume! psSample->fVol = volume; // save computed volume volume *= sfx_volume; // and now take into account the Users sound Prefs. // We can't hear it, so don't bother creating 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... */ } alSourcef(psSample->iSample, AL_PITCH, 1.0f); alSourcef(psSample->iSample, AL_GAIN, volume); alSourcefv(psSample->iSample, AL_POSITION, zero); alSourcefv(psSample->iSample, AL_VELOCITY, zero); alSourcei(psSample->iSample, AL_BUFFER, psTrack->iBufferName); alSourcei(psSample->iSample, AL_SOURCE_RELATIVE, AL_TRUE); alSourcei(psSample->iSample, AL_LOOPING, (sound_SetupChannel(psSample)) ? AL_TRUE : AL_FALSE); // NOTE: this is only useful for debugging. #ifdef DEBUG psSample->is3d = false; 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(); if (bQueued) { current_queue_sample = psSample->iSample; } else if (current_queue_sample == psSample->iSample) { current_queue_sample = -1; } return true; }
static bool sound_SetupChannel(AUDIO_SAMPLE *psSample) { sound_AddActiveSample(psSample); return sound_TrackLooped(psSample->iTrack); }