bool FSoundManager::PlaySound( FSoundObject * lpSoundObj, bool bLoop ) { I32 i = GetFreeSource(); if( i == -1 ) return false; alSourcei( lpSources[i].iSourceID, AL_BUFFER, lpSoundObj->GetSoundID() ); LogOpenAL(); alSourcef( lpSources[i].iSourceID, AL_PITCH, 1.f ); LogOpenAL(); alSourcef( lpSources[i].iSourceID, AL_GAIN, 1.f ); LogOpenAL(); if( bLoop ) alSourcei( lpSources[i].iSourceID, AL_LOOPING, AL_TRUE ); else alSourcei( lpSources[i].iSourceID, AL_LOOPING, AL_FALSE ); LogOpenAL(); alSourcei( lpSources[i].iSourceID, AL_SOURCE_RELATIVE, AL_TRUE ); LogOpenAL(); alSourcef( lpSources[i].iSourceID, AL_ROLLOFF_FACTOR, 0.f ); LogOpenAL(); alSourcePlay( lpSources[i].iSourceID ); LogOpenAL(); lpSources[i].bBusy = true; lpSources[i].lpSoundObj = lpSoundObj; lpSoundObj->SetSourceInd( i ); return true; }
void PlaySound(const std::string& name, float gain) { const static ALfloat fz[] = { 0.0f, 0.0f, 0.0f }; ALuint buf = GetSound(name); ALuint source = GetFreeSource(); LOG("Sound", LOG_NOTICE, "playing sound %s on channel %d", name.c_str(), source); alSourcei(source, AL_BUFFER, buf); alSourcei(source, AL_SOURCE_RELATIVE, AL_TRUE); alSourcef(source, AL_GAIN, gain); alSourcefv(source, AL_POSITION, fz); alSourcefv(source, AL_VELOCITY, fz); alSourcePlay(source); }
void PlaySoundPositional(const std::string& name, vec2 pos, vec2 vel, float gain) { ALfloat fpos[] = {pos.X(), pos.Y(), 0.0f}; ALfloat fvel[] = {vel.X(), vel.Y(), 0.0f}; ALuint buf = GetSound(name); ALuint source = GetFreeSource(); alSourcei(source, AL_BUFFER, buf); alSourcei(source, AL_SOURCE_RELATIVE, AL_FALSE); alSourcefv(source, AL_POSITION, fpos); alSourcefv(source, AL_VELOCITY, fvel); alSourcef(source, AL_REFERENCE_DISTANCE, 50.0); alSourcef(source, AL_GAIN, gain); alSourcePlay(source); }
void PlaySoundPositional(const std::string& name, vec2 pos, vec2 vel, float gain) { ALfloat fpos[] = {pos.X(), pos.Y(), 0.0f}; ALfloat fvel[] = {vel.X(), vel.Y(), 0.0f}; ALuint buf = GetSound(name); ALuint source = GetFreeSource(); alSourcei(source, AL_BUFFER, buf); alSourcei(source, AL_SOURCE_RELATIVE, AL_FALSE); alSourcefv(source, AL_POSITION, fpos); alSourcefv(source, AL_VELOCITY, fvel); alSourcef(source, AL_REFERENCE_DISTANCE, 50.0); alSourcef(source, AL_GAIN, gain); alSourcePlay(source); #ifndef NDEBUG if (alGetError()) LOG("Sound", LOG_ERROR, "OpenAL error"); const ALchar* err = alureGetErrorString(); if (strcmp(err, "No error")) { LOG("Sound", LOG_ERROR, "ALURE error: %s", err); exit(1); } #endif }
void PlaySound(const std::string& name, float gain) { const static ALfloat fz[] = { 0.0f, 0.0f, 0.0f }; ALuint buf = GetSound(name); ALuint source = GetFreeSource(); LOG("Sound", LOG_NOTICE, "playing sound %s on channel %d", name.c_str(), source); const ALchar* err = alureGetErrorString(); alSourcei(source, AL_BUFFER, buf); alSourcei(source, AL_SOURCE_RELATIVE, AL_TRUE); alSourcef(source, AL_GAIN, gain); alSourcefv(source, AL_POSITION, fz); alSourcefv(source, AL_VELOCITY, fz); alSourcePlay(source); #ifndef NDEBUG if (alGetError()) LOG("Sound", LOG_ERROR, "OpenAL error"); err = alureGetErrorString(); if (strcmp(err, "No error")) { LOG("Sound", LOG_ERROR, "ALURE error: %s", err); exit(1); } #endif }