From 605c937572883913cf51fb52a6846dade8074d6c Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 13 Sep 2017 03:27:48 -0700 Subject: [PATCH] Ensure 3D sources are spatialized Standard OpenAL does not spatialize non-mono sounds, although the game has some stereo sounds meant to play in 3D. The desired behavior can be achieved with the AL_SOFT_source_spatialize extension. --- apps/openmw/mwsound/openal_output.cpp | 5 +++++ apps/openmw/mwsound/openal_output.hpp | 3 +++ 2 files changed, 8 insertions(+) diff --git a/apps/openmw/mwsound/openal_output.cpp b/apps/openmw/mwsound/openal_output.cpp index 1b6b435f2..146776442 100644 --- a/apps/openmw/mwsound/openal_output.cpp +++ b/apps/openmw/mwsound/openal_output.cpp @@ -622,6 +622,7 @@ void OpenAL_Output::init(const std::string &devname) } ALC.EXT_EFX = !!alcIsExtensionPresent(mDevice, "ALC_EXT_EFX"); + AL.SOFT_source_spatialize = !!alIsExtensionPresent("AL_SOFT_source_spatialize"); alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); throwALerror(); @@ -972,6 +973,8 @@ void OpenAL_Output::initCommon2D(ALuint source, const osg::Vec3f &pos, ALfloat g alSourcef(source, AL_ROLLOFF_FACTOR, 0.0f); alSourcei(source, AL_SOURCE_RELATIVE, AL_TRUE); alSourcei(source, AL_LOOPING, loop ? AL_TRUE : AL_FALSE); + if(AL.SOFT_source_spatialize) + alSourcei(source, AL_SOURCE_SPATIALIZE_SOFT, AL_FALSE); if(useenv) { @@ -1009,6 +1012,8 @@ void OpenAL_Output::initCommon3D(ALuint source, const osg::Vec3f &pos, ALfloat m alSourcef(source, AL_ROLLOFF_FACTOR, 1.0f); alSourcei(source, AL_SOURCE_RELATIVE, AL_FALSE); alSourcei(source, AL_LOOPING, loop ? AL_TRUE : AL_FALSE); + if(AL.SOFT_source_spatialize) + alSourcei(source, AL_SOURCE_SPATIALIZE_SOFT, AL_TRUE); if((pos - mListenerPos).length2() > maxdist*maxdist) gain = 0.0f; diff --git a/apps/openmw/mwsound/openal_output.hpp b/apps/openmw/mwsound/openal_output.hpp index fb832abc6..777b9207f 100644 --- a/apps/openmw/mwsound/openal_output.hpp +++ b/apps/openmw/mwsound/openal_output.hpp @@ -26,6 +26,9 @@ namespace MWSound struct { int EXT_EFX : 1; } ALC; + struct { + int SOFT_source_spatialize : 1; + } AL; typedef std::deque IDDq; IDDq mFreeSources;