diff --git a/Flax.sln.DotSettings b/Flax.sln.DotSettings index 655924b88..8478d97b5 100644 --- a/Flax.sln.DotSettings +++ b/Flax.sln.DotSettings @@ -278,6 +278,7 @@ True True True + True True True True diff --git a/Source/Engine/Audio/Audio.cpp b/Source/Engine/Audio/Audio.cpp index 95e1e2ba1..14639a6a2 100644 --- a/Source/Engine/Audio/Audio.cpp +++ b/Source/Engine/Audio/Audio.cpp @@ -57,7 +57,7 @@ namespace float Volume = 1.0f; int32 ActiveDeviceIndex = -1; bool MuteOnFocusLoss = true; - bool UseHRTFWhenAvailable = true; + bool EnableHRTF = true; } class AudioService : public EngineService @@ -95,7 +95,7 @@ void AudioSettings::Apply() if (AudioBackend::Instance != nullptr) { Audio::SetDopplerFactor(DopplerFactor); - Audio::SetUseHRTFWhenAvailable(UseHRTFWhenAvailable); + Audio::SetEnableHRTF(EnableHRTF); } } @@ -143,14 +143,16 @@ void Audio::SetDopplerFactor(float value) AudioBackend::SetDopplerFactor(value); } -bool Audio::GetUseHRTFWhenAvailable() +bool Audio::GetEnableHRTF() { - return UseHRTFWhenAvailable; + return EnableHRTF; } -void Audio::SetUseHRTFWhenAvailable(bool value) +void Audio::SetEnableHRTF(bool value) { - UseHRTFWhenAvailable = value; + if (EnableHRTF == value) + return; + EnableHRTF = value; AudioBackend::Listener::ReinitializeAll(); } diff --git a/Source/Engine/Audio/Audio.h b/Source/Engine/Audio/Audio.h index 53de3a7e4..64a288466 100644 --- a/Source/Engine/Audio/Audio.h +++ b/Source/Engine/Audio/Audio.h @@ -18,7 +18,6 @@ API_CLASS(Static) class FLAXENGINE_API Audio friend class AudioClip; public: - /// /// The audio listeners collection registered by the service. /// @@ -45,7 +44,6 @@ public: API_EVENT() static Action ActiveDeviceChanged; public: - /// /// Gets the active device. /// @@ -65,7 +63,6 @@ public: API_PROPERTY() static void SetActiveDeviceIndex(int32 index); public: - /// /// Gets the master volume applied to all the audio sources (normalized to range 0-1). /// @@ -91,18 +88,17 @@ public: API_PROPERTY() static void SetDopplerFactor(float value); /// - /// Gets the preference to use HRTF audio when available. Default is true. + /// Gets the preference to use HRTF audio (when available on platform). Default is true. /// - API_PROPERTY() static bool GetUseHRTFWhenAvailable(); + API_PROPERTY() static bool GetEnableHRTF(); /// - /// Sets the preference to use HRTF audio when available. Default is true. + /// Sets the preference to use HRTF audio (when available on platform). Default is true. /// /// The value. - API_PROPERTY() static void SetUseHRTFWhenAvailable(bool value); + API_PROPERTY() static void SetEnableHRTF(bool value); public: - static void OnAddListener(AudioListener* listener); static void OnRemoveListener(AudioListener* listener); diff --git a/Source/Engine/Audio/AudioSettings.h b/Source/Engine/Audio/AudioSettings.h index 255924a1e..e600d4216 100644 --- a/Source/Engine/Audio/AudioSettings.h +++ b/Source/Engine/Audio/AudioSettings.h @@ -10,9 +10,9 @@ /// API_CLASS(sealed, Namespace="FlaxEditor.Content.Settings") class FLAXENGINE_API AudioSettings : public SettingsBase { -DECLARE_SCRIPTING_TYPE_MINIMAL(AudioSettings); -public: + DECLARE_SCRIPTING_TYPE_MINIMAL(AudioSettings); +public: /// /// If checked, audio playback will be disabled in build game. Can be used if game uses custom audio playback engine. /// @@ -32,15 +32,13 @@ public: bool MuteOnFocusLoss = true; /// - /// Enables/disables HRTF audio for in-engine processing of 3d audio. + /// Enables or disables HRTF audio for in-engine processing of 3D audio (if supported by platform). /// If enabled, the user should be using two-channel/headphones audio output and have all other surround virtualization disabled (Atmos, DTS:X, vendor specific, etc.) - /// Note: this is currently only available with the OpenAL audio backend. /// API_FIELD(Attributes="EditorOrder(300), DefaultValue(true), EditorDisplay(\"Spatial Audio\")") - bool UseHRTFWhenAvailable = true; + bool EnableHRTF = true; public: - /// /// Gets the instance of the settings asset (default value if missing). Object returned by this method is always loaded with valid data to use. /// @@ -54,6 +52,6 @@ public: DESERIALIZE(DisableAudio); DESERIALIZE(DopplerFactor); DESERIALIZE(MuteOnFocusLoss); - DESERIALIZE(UseHRTFWhenAvailable); + DESERIALIZE(EnableHRTF); } }; diff --git a/Source/Engine/Audio/OpenAL/AudioBackendOAL.cpp b/Source/Engine/Audio/OpenAL/AudioBackendOAL.cpp index 5fcd71379..e5f97c376 100644 --- a/Source/Engine/Audio/OpenAL/AudioBackendOAL.cpp +++ b/Source/Engine/Audio/OpenAL/AudioBackendOAL.cpp @@ -156,7 +156,7 @@ namespace ALC void RebuildContexts(bool isChangingDevice) { - LOG(Info, "Audio: Rebuilding audio contexts"); + LOG(Info, "Rebuilding audio contexts"); if (!isChangingDevice) { @@ -169,29 +169,26 @@ namespace ALC if (Device == nullptr) return; + ALCint attrsHrtf[] = { ALC_HRTF_SOFT, ALC_TRUE }; + const ALCint* attrList = nullptr; + if (Audio::GetEnableHRTF()) + { + LOG(Info, "Enabling OpenAL HRTF"); + attrList = attrsHrtf; + } + #if ALC_MULTIPLE_LISTENERS const int32 numListeners = Audio::Listeners.Count(); const int32 numContexts = numListeners > 1 ? numListeners : 1; Contexts.Resize(numContexts); ALC_FOR_EACH_CONTEXT() - ALCcontext* context = alcCreateContext(Device, nullptr); + ALCcontext* context = alcCreateContext(Device, attrList); Contexts[i] = context; } #else Contexts.Resize(1); - - if (Audio::GetUseHRTFWhenAvailable()) - { - LOG(Info, "Audio: Enabling OpenAL HRTF"); - - ALCint attrs[] = { ALC_HRTF_SOFT, ALC_TRUE }; - Contexts[0] = alcCreateContext(Device, attrs); - } - else - { - Contexts[0] = alcCreateContext(Device, nullptr); - } + Contexts[0] = alcCreateContext(Device, attrList); #endif // If only one context is available keep it active as an optimization.