diff --git a/apps/openmw/mwsound/openal_output.cpp b/apps/openmw/mwsound/openal_output.cpp index 62a7076e9..d63482273 100644 --- a/apps/openmw/mwsound/openal_output.cpp +++ b/apps/openmw/mwsound/openal_output.cpp @@ -583,6 +583,50 @@ Sound* OpenAL_Output::streamSound(const std::string &fname, float volume, float return sound.release(); } +Sound* OpenAL_Output::streamSound3D(const std::string &fname, const float *pos, float volume, float pitch, + float min, float max) +{ + throwALerror(); + + std::auto_ptr sound; + ALuint src; + + if(mFreeSources.empty()) + fail("No free sources"); + src = mFreeSources.back(); + mFreeSources.pop_back(); + + try + { + DecoderPtr decoder = mManager.getDecoder(); + decoder->open(fname); + sound.reset(new OpenAL_SoundStream(*this, src, decoder)); + } + catch(std::exception &e) + { + mFreeSources.push_back(src); + throw; + } + + alSource3f(src, AL_POSITION, pos[0], pos[2], -pos[1]); + alSource3f(src, AL_DIRECTION, 0.0f, 0.0f, 0.0f); + alSource3f(src, AL_VELOCITY, 0.0f, 0.0f, 0.0f); + + alSourcef(src, AL_REFERENCE_DISTANCE, min); + alSourcef(src, AL_MAX_DISTANCE, max); + alSourcef(src, AL_ROLLOFF_FACTOR, 1.0f); + + alSourcef(src, AL_GAIN, volume); + alSourcef(src, AL_PITCH, pitch); + + alSourcei(src, AL_SOURCE_RELATIVE, AL_FALSE); + alSourcei(src, AL_LOOPING, AL_FALSE); + throwALerror(); + + sound->play(); + return sound.release(); +} + void OpenAL_Output::updateListener(const float *pos, const float *atdir, const float *updir) { diff --git a/apps/openmw/mwsound/openal_output.hpp b/apps/openmw/mwsound/openal_output.hpp index 80c6db851..dddd1d6dc 100644 --- a/apps/openmw/mwsound/openal_output.hpp +++ b/apps/openmw/mwsound/openal_output.hpp @@ -30,6 +30,8 @@ namespace MWSound float min, float max, bool loop); virtual Sound *streamSound(const std::string &fname, float volume, float pitch); + virtual Sound *streamSound3D(const std::string &fname, const float *pos, float volume, float pitch, + float min, float max); virtual void updateListener(const float *pos, const float *atdir, const float *updir); diff --git a/apps/openmw/mwsound/sound_output.hpp b/apps/openmw/mwsound/sound_output.hpp index be721831f..a2a035e71 100644 --- a/apps/openmw/mwsound/sound_output.hpp +++ b/apps/openmw/mwsound/sound_output.hpp @@ -23,6 +23,8 @@ namespace MWSound virtual Sound *playSound3D(const std::string &fname, const float *pos, float volume, float pitch, float min, float max, bool loop) = 0; virtual Sound *streamSound(const std::string &fname, float volume, float pitch) = 0; + virtual Sound *streamSound3D(const std::string &fname, const float *pos, float volume, float pitch, + float min, float max) = 0; virtual void updateListener(const float *pos, const float *atdir, const float *updir) = 0;