Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fix stereo headphone disambiguation #356

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fmod/src/mix_return_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion fmod/src/reverb_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions fmod/src/spatialize_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
Expand Down Expand Up @@ -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);

Expand All @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions fmod/src/steamaudio_fmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ std::atomic<bool> gNewHRTFWritten{ false };
std::atomic<bool> gIsSimulationSettingsValid{ false };
std::atomic<bool> gNewReverbSourceWritten{ false };
std::atomic<bool> gNewReflectionMixerWritten{ false };
std::atomic<bool> gHRTFDisabled{ false };

std::shared_ptr<SourceManager> gSourceManager;

Expand Down Expand Up @@ -512,3 +513,8 @@ void F_CALL iplFMODRemoveSource(IPLint32 handle)

gSourceManager->removeSource(handle);
}

void F_CALL iplFMODSetHRTFDisabled(bool disabled)
{
gHRTFDisabled = disabled;
}
4 changes: 4 additions & 0 deletions fmod/src/steamaudio_fmod.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ extern std::atomic<bool> gNewHRTFWritten;
extern std::atomic<bool> gIsSimulationSettingsValid;
extern std::atomic<bool> gNewReverbSourceWritten;
extern std::atomic<bool> gNewReflectionMixerWritten;
extern std::atomic<bool> gHRTFDisabled;


// --------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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);

}
2 changes: 1 addition & 1 deletion unity/src/native/mix_return_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion unity/src/native/reverb_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions unity/src/native/spatialize_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
Expand Down Expand Up @@ -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);

Expand All @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions unity/src/native/steamaudio_unity_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ std::atomic<bool> gNewPerspectiveCorrectionWritten{ false };
std::atomic<bool> gIsSimulationSettingsValid{ false };
std::atomic<bool> gNewReverbSourceWritten{ false };
std::atomic<bool> gNewReflectionMixerWritten{ false };
std::atomic<bool> gHRTFDisabled{ false };

std::shared_ptr<SourceManager> gSourceManager;

Expand Down Expand Up @@ -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 {

Expand Down
3 changes: 3 additions & 0 deletions unity/src/native/steamaudio_unity_native.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
Expand All @@ -102,6 +104,7 @@ extern std::atomic<bool> gNewPerspectiveCorrectionWritten;
extern std::atomic<bool> gIsSimulationSettingsValid;
extern std::atomic<bool> gNewReverbSourceWritten;
extern std::atomic<bool> gNewReflectionMixerWritten;
extern std::atomic<bool> gHRTFDisabled;


// --------------------------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace SteamAudio
public class SteamAudioSettingsInspector : Editor
{
SerializedProperty mAudioEngine;
SerializedProperty mHRTFDisabled;
SerializedProperty mPerspectiveCorrection;
SerializedProperty mPerspectiveCorrectionFactor;
SerializedProperty mHRTFVolumeNormalizationType;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ private void LateUpdate()
if (mAudioEngineState == null)
return;

mAudioEngineState.SetHRTFDisabled(SteamAudioSettings.Singleton.hrtfDisabled);
var perspectiveCorrection = GetPerspectiveCorrection();
mAudioEngineState.SetPerspectiveCorrection(perspectiveCorrection);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down