diff --git a/fmod/src/mix_return_effect.cpp b/fmod/src/mix_return_effect.cpp index 6b031389..bd966baf 100644 --- a/fmod/src/mix_return_effect.cpp +++ b/fmod/src/mix_return_effect.cpp @@ -373,7 +373,7 @@ FMOD_RESULT F_CALL process(FMOD_DSP_STATE* state, ambisonicsParams.order = gSimulationSettings.maxOrder; ambisonicsParams.hrtf = gHRTF[0]; ambisonicsParams.orientation = listenerCoordinates; - ambisonicsParams.binaural = numChannelsOut == 2 && (effect->binaural) ? IPL_TRUE : IPL_FALSE; + ambisonicsParams.binaural = numChannelsOut == 2 && !gHRTFDisabled && (effect->binaural) ? IPL_TRUE : IPL_FALSE; iplAmbisonicsDecodeEffectApply(effect->ambisonicsEffect, &ambisonicsParams, &effect->reflectionsBuffer, &effect->outBuffer); diff --git a/fmod/src/reverb_effect.cpp b/fmod/src/reverb_effect.cpp index ddba0c5f..d198c37d 100644 --- a/fmod/src/reverb_effect.cpp +++ b/fmod/src/reverb_effect.cpp @@ -403,7 +403,7 @@ FMOD_RESULT F_CALL process(FMOD_DSP_STATE* state, ambisonicsParams.order = gSimulationSettings.maxOrder; ambisonicsParams.hrtf = gHRTF[0]; ambisonicsParams.orientation = listenerCoordinates; - ambisonicsParams.binaural = numChannelsOut == 2 && (effect->binaural) ? IPL_TRUE : IPL_FALSE; + ambisonicsParams.binaural = numChannelsOut == 2 && !gHRTFDisabled && (effect->binaural) ? IPL_TRUE : IPL_FALSE; iplAmbisonicsDecodeEffectApply(effect->ambisonicsEffect, &ambisonicsParams, &effect->reflectionsBuffer, &effect->outBuffer); diff --git a/fmod/src/spatialize_effect.cpp b/fmod/src/spatialize_effect.cpp index 784dd662..fc35edc9 100644 --- a/fmod/src/spatialize_effect.cpp +++ b/fmod/src/spatialize_effect.cpp @@ -1432,7 +1432,7 @@ FMOD_RESULT F_CALL process(FMOD_DSP_STATE* state, iplDirectEffectApply(effect->directEffect, &directParams, &effect->inBuffer, &effect->directBuffer); - bool directBinaural = numChannelsOut == 2 && effect->directBinaural; + bool directBinaural = numChannelsOut == 2 && effect->directBinaural && !gHRTFDisabled; if (directBinaural) { IPLBinauralEffectParams binauralParams{}; @@ -1494,7 +1494,7 @@ FMOD_RESULT F_CALL process(FMOD_DSP_STATE* state, ambisonicsParams.order = gSimulationSettings.maxOrder; ambisonicsParams.hrtf = gHRTF[0]; ambisonicsParams.orientation = listenerCoordinates; - ambisonicsParams.binaural = numChannelsOut == 2 && (effect->reflectionsBinaural) ? IPL_TRUE : IPL_FALSE; + ambisonicsParams.binaural = numChannelsOut == 2 && !gHRTFDisabled && (effect->reflectionsBinaural) ? IPL_TRUE : IPL_FALSE; iplAmbisonicsDecodeEffectApply(effect->ambisonicsEffect, &ambisonicsParams, &effect->reflectionsBuffer, &effect->reflectionsSpatializedBuffer); @@ -1512,7 +1512,7 @@ FMOD_RESULT F_CALL process(FMOD_DSP_STATE* state, IPLPathEffectParams pathParams = simulationOutputs.pathing; pathParams.order = gSimulationSettings.maxOrder; - pathParams.binaural = numChannelsOut == 2 && (effect->pathingBinaural) ? IPL_TRUE : IPL_FALSE; + pathParams.binaural = numChannelsOut == 2 && !gHRTFDisabled && (effect->pathingBinaural) ? IPL_TRUE : IPL_FALSE; pathParams.hrtf = gHRTF[0]; pathParams.listener = listenerCoordinates; diff --git a/fmod/src/steamaudio_fmod.cpp b/fmod/src/steamaudio_fmod.cpp index d128b6ea..6b00d8f1 100644 --- a/fmod/src/steamaudio_fmod.cpp +++ b/fmod/src/steamaudio_fmod.cpp @@ -42,6 +42,7 @@ std::atomic gNewHRTFWritten{ false }; std::atomic gIsSimulationSettingsValid{ false }; std::atomic gNewReverbSourceWritten{ false }; std::atomic gNewReflectionMixerWritten{ false }; +std::atomic gHRTFDisabled{ false }; std::shared_ptr gSourceManager; @@ -512,3 +513,8 @@ void F_CALL iplFMODRemoveSource(IPLint32 handle) gSourceManager->removeSource(handle); } + +void F_CALL iplFMODSetHRTFDisabled(bool disabled) +{ + gHRTFDisabled = disabled; +} diff --git a/fmod/src/steamaudio_fmod.h b/fmod/src/steamaudio_fmod.h index 1bb08b1c..a4171cfb 100644 --- a/fmod/src/steamaudio_fmod.h +++ b/fmod/src/steamaudio_fmod.h @@ -74,6 +74,7 @@ extern std::atomic gNewHRTFWritten; extern std::atomic gIsSimulationSettingsValid; extern std::atomic gNewReverbSourceWritten; extern std::atomic gNewReflectionMixerWritten; +extern std::atomic gHRTFDisabled; // -------------------------------------------------------------------------------------------------------------------- @@ -247,4 +248,7 @@ F_EXPORT void F_CALL iplFMODSetReverbSource(IPLSource reverbSource); F_EXPORT IPLint32 F_CALL iplFMODAddSource(IPLSource source); F_EXPORT void F_CALL iplFMODRemoveSource(IPLint32 handle); + +F_EXPORT void F_CALL iplFMODSetHRTFDisabled(bool disabled); + } diff --git a/unity/src/native/mix_return_effect.cpp b/unity/src/native/mix_return_effect.cpp index 6eb60b8c..05b97e42 100644 --- a/unity/src/native/mix_return_effect.cpp +++ b/unity/src/native/mix_return_effect.cpp @@ -298,7 +298,7 @@ UNITY_AUDIODSP_RESULT UNITY_AUDIODSP_CALLBACK process(UnityAudioEffectState* sta ambisonicsParams.order = gSimulationSettings.maxOrder; ambisonicsParams.hrtf = gHRTF[0]; ambisonicsParams.orientation = listenerCoordinates; - ambisonicsParams.binaural = numChannelsOut == 2 && (effect->binaural) ? IPL_TRUE : IPL_FALSE; + ambisonicsParams.binaural = numChannelsOut == 2 && !gHRTFDisabled && (effect->binaural) ? IPL_TRUE : IPL_FALSE; iplAmbisonicsDecodeEffectApply(effect->ambisonicsEffect, &ambisonicsParams, &effect->reflectionsBuffer, &effect->outBuffer); diff --git a/unity/src/native/reverb_effect.cpp b/unity/src/native/reverb_effect.cpp index d6852bca..d13ddb76 100644 --- a/unity/src/native/reverb_effect.cpp +++ b/unity/src/native/reverb_effect.cpp @@ -319,7 +319,7 @@ UNITY_AUDIODSP_RESULT UNITY_AUDIODSP_CALLBACK process(UnityAudioEffectState* sta ambisonicsParams.order = gSimulationSettings.maxOrder; ambisonicsParams.hrtf = gHRTF[0]; ambisonicsParams.orientation = listenerCoordinates; - ambisonicsParams.binaural = numChannelsOut == 2 && (effect->binaural) ? IPL_TRUE : IPL_FALSE; + ambisonicsParams.binaural = numChannelsOut == 2 && !gHRTFDisabled && (effect->binaural) ? IPL_TRUE : IPL_FALSE; iplAmbisonicsDecodeEffectApply(effect->ambisonicsEffect, &ambisonicsParams, &effect->reflectionsBuffer, &effect->outBuffer); diff --git a/unity/src/native/spatialize_effect.cpp b/unity/src/native/spatialize_effect.cpp index 55f5caf3..7df3c76b 100644 --- a/unity/src/native/spatialize_effect.cpp +++ b/unity/src/native/spatialize_effect.cpp @@ -863,7 +863,7 @@ UNITY_AUDIODSP_RESULT UNITY_AUDIODSP_CALLBACK process(UnityAudioEffectState* sta if (dot(direction, direction) < 1e-6f) direction = IPLVector3{ 0.0f, 1.0f, 0.0f }; - bool directBinaural = numChannelsOut == 2 && effect->directBinaural; + bool directBinaural = numChannelsOut == 2 && effect->directBinaural && !gHRTFDisabled; if (directBinaural) { IPLBinauralEffectParams binauralParams{}; @@ -925,7 +925,7 @@ UNITY_AUDIODSP_RESULT UNITY_AUDIODSP_CALLBACK process(UnityAudioEffectState* sta ambisonicsParams.order = gSimulationSettings.maxOrder; ambisonicsParams.hrtf = gHRTF[0]; ambisonicsParams.orientation = listenerCoordinates; - ambisonicsParams.binaural = numChannelsOut == 2 && (effect->reflectionsBinaural) ? IPL_TRUE : IPL_FALSE; + ambisonicsParams.binaural = numChannelsOut == 2 && !gHRTFDisabled && (effect->reflectionsBinaural) ? IPL_TRUE : IPL_FALSE; iplAmbisonicsDecodeEffectApply(effect->ambisonicsEffect, &ambisonicsParams, &effect->reflectionsBuffer, &effect->reflectionsSpatializedBuffer); @@ -943,7 +943,7 @@ UNITY_AUDIODSP_RESULT UNITY_AUDIODSP_CALLBACK process(UnityAudioEffectState* sta IPLPathEffectParams pathParams = simulationOutputs.pathing; pathParams.order = gSimulationSettings.maxOrder; - pathParams.binaural = numChannelsOut == 2 && (effect->pathingBinaural) ? IPL_TRUE : IPL_FALSE; + pathParams.binaural = numChannelsOut == 2 && !gHRTFDisabled && (effect->pathingBinaural) ? IPL_TRUE : IPL_FALSE; pathParams.hrtf = gHRTF[0]; pathParams.listener = listenerCoordinates; diff --git a/unity/src/native/steamaudio_unity_native.cpp b/unity/src/native/steamaudio_unity_native.cpp index 44107978..d9104d14 100644 --- a/unity/src/native/steamaudio_unity_native.cpp +++ b/unity/src/native/steamaudio_unity_native.cpp @@ -45,6 +45,7 @@ std::atomic gNewPerspectiveCorrectionWritten{ false }; std::atomic gIsSimulationSettingsValid{ false }; std::atomic gNewReverbSourceWritten{ false }; std::atomic gNewReflectionMixerWritten{ false }; +std::atomic gHRTFDisabled{ false }; std::shared_ptr gSourceManager; @@ -183,6 +184,11 @@ void UNITY_AUDIODSP_CALLBACK iplUnityRemoveSource(IPLint32 handle) SteamAudioUnity::gSourceManager->removeSource(handle); } +void UNITY_AUDIODSP_CALLBACK iplUnitySetHRTFDisabled(bool disabled) +{ + SteamAudioUnity::gHRTFDisabled = disabled; +} + namespace SteamAudioUnity { diff --git a/unity/src/native/steamaudio_unity_native.h b/unity/src/native/steamaudio_unity_native.h index 809d8bde..24f51fc1 100644 --- a/unity/src/native/steamaudio_unity_native.h +++ b/unity/src/native/steamaudio_unity_native.h @@ -78,6 +78,8 @@ UNITY_AUDIODSP_EXPORT_API IPLint32 UNITY_AUDIODSP_CALLBACK iplUnityAddSource(IPL UNITY_AUDIODSP_EXPORT_API void UNITY_AUDIODSP_CALLBACK iplUnityRemoveSource(IPLint32 handle); +UNITY_AUDIODSP_EXPORT_API void UNITY_AUDIODSP_CALLBACK iplUnitySetHRTFDisabled(bool disabled); + #endif } @@ -102,6 +104,7 @@ extern std::atomic gNewPerspectiveCorrectionWritten; extern std::atomic gIsSimulationSettingsValid; extern std::atomic gNewReverbSourceWritten; extern std::atomic gNewReflectionMixerWritten; +extern std::atomic gHRTFDisabled; // -------------------------------------------------------------------------------------------------------------------- diff --git a/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Editor/SteamAudioSettingsInspector.cs b/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Editor/SteamAudioSettingsInspector.cs index bbd176c8..3f43e804 100644 --- a/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Editor/SteamAudioSettingsInspector.cs +++ b/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Editor/SteamAudioSettingsInspector.cs @@ -23,6 +23,7 @@ namespace SteamAudio public class SteamAudioSettingsInspector : Editor { SerializedProperty mAudioEngine; + SerializedProperty mHRTFDisabled; SerializedProperty mPerspectiveCorrection; SerializedProperty mPerspectiveCorrectionFactor; SerializedProperty mHRTFVolumeNormalizationType; @@ -77,6 +78,7 @@ public class SteamAudioSettingsInspector : Editor private void OnEnable() { mAudioEngine = serializedObject.FindProperty("audioEngine"); + mHRTFDisabled = serializedObject.FindProperty("hrtfDisabled"); mPerspectiveCorrection = serializedObject.FindProperty("perspectiveCorrection"); mPerspectiveCorrectionFactor = serializedObject.FindProperty("perspectiveCorrectionFactor"); mHRTFVolumeGainDB = serializedObject.FindProperty("hrtfVolumeGainDB"); @@ -126,6 +128,7 @@ public override void OnInspectorGUI() serializedObject.Update(); EditorGUILayout.PropertyField(mAudioEngine); + EditorGUILayout.PropertyField(mHRTFDisabled, new UnityEngine.GUIContent("Disable HRTF Globally", "Disable HRTF rendering for all events/sources. Useful when the end user is using speakers instead of headphones.")); EditorGUILayout.PropertyField(mPerspectiveCorrection, new UnityEngine.GUIContent("Enable Perspective Correction")); if (mPerspectiveCorrection.boolValue) diff --git a/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/AudioEngineState.cs b/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/AudioEngineState.cs index e9a47aa5..097eee53 100644 --- a/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/AudioEngineState.cs +++ b/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/AudioEngineState.cs @@ -57,6 +57,9 @@ private static AudioEngineState CreateFMODStudioAudioEngineState() var type = Type.GetType("SteamAudio.FMODStudioAudioEngineState,SteamAudioUnity"); return (type != null) ? (AudioEngineState) Activator.CreateInstance(type) : null; } + + public virtual void SetHRTFDisabled(bool disabled) + { } } public abstract class AudioEngineStateHelpers diff --git a/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/FMODStudioAudioEngineState.cs b/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/FMODStudioAudioEngineState.cs index f162de6f..16361403 100644 --- a/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/FMODStudioAudioEngineState.cs +++ b/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/FMODStudioAudioEngineState.cs @@ -44,6 +44,13 @@ public override void SetReverbSource(Source reverbSource) { FMODStudioAPI.iplFMODSetReverbSource(reverbSource.Get()); } + + public override void SetHRTFDisabled(bool disabled) + { + base.SetHRTFDisabled(disabled); + + FMODStudioAPI.iplFMODSetHRTFDisabled(disabled); + } } public sealed class FMODStudioAudioEngineStateHelpers : AudioEngineStateHelpers diff --git a/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/SteamAudio.cs b/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/SteamAudio.cs index 9fbf1648..7a875b1a 100644 --- a/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/SteamAudio.cs +++ b/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/SteamAudio.cs @@ -1368,4 +1368,12 @@ public static class API [DllImport("audioplugin_phonon")] #endif public static extern void iplUnityTerminate(); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("audioplugin_phonon")] +#endif + public static extern void iplUnitySetHRTFDisabled(bool disabled); + } } diff --git a/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/SteamAudioFMODStudio.cs b/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/SteamAudioFMODStudio.cs index 77bc4d15..8ffc69b7 100644 --- a/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/SteamAudioFMODStudio.cs +++ b/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/SteamAudioFMODStudio.cs @@ -72,4 +72,12 @@ public static class FMODStudioAPI [DllImport("phonon_fmod")] #endif public static extern void iplFMODRemoveSource(int handle); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon_fmod")] +#endif + public static extern void iplFMODSetHRTFDisabled(bool disabled); + } } diff --git a/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/SteamAudioManager.cs b/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/SteamAudioManager.cs index f684fb76..b35e801b 100644 --- a/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/SteamAudioManager.cs +++ b/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/SteamAudioManager.cs @@ -506,6 +506,7 @@ private void LateUpdate() if (mAudioEngineState == null) return; + mAudioEngineState.SetHRTFDisabled(SteamAudioSettings.Singleton.hrtfDisabled); var perspectiveCorrection = GetPerspectiveCorrection(); mAudioEngineState.SetPerspectiveCorrection(perspectiveCorrection); diff --git a/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/SteamAudioSettings.cs b/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/SteamAudioSettings.cs index 54368e20..9c285469 100644 --- a/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/SteamAudioSettings.cs +++ b/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/SteamAudioSettings.cs @@ -34,6 +34,7 @@ public class SteamAudioSettings : ScriptableObject public AudioEngineType audioEngine = AudioEngineType.Unity; [Header("HRTF Settings")] + public bool hrtfDisabled = false; public bool perspectiveCorrection = false; [Range(.25f, 4.0f)] public float perspectiveCorrectionFactor = 1.0f; diff --git a/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/UnityAudioEngineState.cs b/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/UnityAudioEngineState.cs index 2f72e81d..2b00ef90 100644 --- a/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/UnityAudioEngineState.cs +++ b/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/Runtime/UnityAudioEngineState.cs @@ -49,6 +49,13 @@ public override void SetReverbSource(Source reverbSource) { API.iplUnitySetReverbSource(reverbSource.Get()); } + + public override void SetHRTFDisabled(bool disabled) + { + base.SetHRTFDisabled(disabled); + + API.iplUnitySetHRTFDisabled(disabled); + } } public sealed class UnityAudioEngineStateHelpers : AudioEngineStateHelpers