Cleanup HRTF support code #963

This commit is contained in:
Wojtek Figat
2023-04-19 13:12:27 +02:00
parent 1b278f5c56
commit 1e1c296300
5 changed files with 29 additions and 35 deletions

View File

@@ -278,6 +278,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=heightfield/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Heightmap/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=HLSL/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=HRTF/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Inlines/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Inscattering/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Interpolants/@EntryIndexedValue">True</s:Boolean>

View File

@@ -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();
}

View File

@@ -18,7 +18,6 @@ API_CLASS(Static) class FLAXENGINE_API Audio
friend class AudioClip;
public:
/// <summary>
/// The audio listeners collection registered by the service.
/// </summary>
@@ -45,7 +44,6 @@ public:
API_EVENT() static Action ActiveDeviceChanged;
public:
/// <summary>
/// Gets the active device.
/// </summary>
@@ -65,7 +63,6 @@ public:
API_PROPERTY() static void SetActiveDeviceIndex(int32 index);
public:
/// <summary>
/// Gets the master volume applied to all the audio sources (normalized to range 0-1).
/// </summary>
@@ -91,18 +88,17 @@ public:
API_PROPERTY() static void SetDopplerFactor(float value);
/// <summary>
/// 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.
/// </summary>
API_PROPERTY() static bool GetUseHRTFWhenAvailable();
API_PROPERTY() static bool GetEnableHRTF();
/// <summary>
/// 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.
/// </summary>
/// <param name="value">The value.</param>
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);

View File

@@ -10,9 +10,9 @@
/// </summary>
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:
/// <summary>
/// If checked, audio playback will be disabled in build game. Can be used if game uses custom audio playback engine.
/// </summary>
@@ -32,15 +32,13 @@ public:
bool MuteOnFocusLoss = true;
/// <summary>
/// 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.
/// </summary>
API_FIELD(Attributes="EditorOrder(300), DefaultValue(true), EditorDisplay(\"Spatial Audio\")")
bool UseHRTFWhenAvailable = true;
bool EnableHRTF = true;
public:
/// <summary>
/// Gets the instance of the settings asset (default value if missing). Object returned by this method is always loaded with valid data to use.
/// </summary>
@@ -54,6 +52,6 @@ public:
DESERIALIZE(DisableAudio);
DESERIALIZE(DopplerFactor);
DESERIALIZE(MuteOnFocusLoss);
DESERIALIZE(UseHRTFWhenAvailable);
DESERIALIZE(EnableHRTF);
}
};

View File

@@ -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.