From bcde1837866a7de3c6217009cfc6eaa2375857b1 Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Sat, 9 May 2026 12:02:01 +0100 Subject: [PATCH] hrtf working example working example of hrtf set the pref usehrtf to true to test For now any mhr file that is in the game directory can be used, just run once to get the index of that mhr and pass that index in to $pref::SFX::hrtfProfile --- Engine/source/sfx/openal/sfxALDevice.cpp | 24 ++++++++++++++++++++++++ Engine/source/sfx/sfxDevice.cpp | 6 ++++++ Engine/source/sfx/sfxDevice.h | 2 ++ 3 files changed, 32 insertions(+) diff --git a/Engine/source/sfx/openal/sfxALDevice.cpp b/Engine/source/sfx/openal/sfxALDevice.cpp index 6e75d754d..36372a58f 100644 --- a/Engine/source/sfx/openal/sfxALDevice.cpp +++ b/Engine/source/sfx/openal/sfxALDevice.cpp @@ -352,6 +352,30 @@ void SFXALDevice::printALInfo(ALCdevice* device) for (ALCint i = 0; i < profileCount; i++) Con::printf("| [%d] %s", i, alcGetStringiSOFT(device, ALC_HRTF_SPECIFIER_SOFT, i)); + + bool use_hrtf = Con::getBoolVariable("$pref::SFX::useHRTF"); + if (use_hrtf && (mCaps & CAPS_HotReconnect)) + { + ALCint attr[5]; + ALCint index = Con::getIntVariable("$pref::SFX::hrtfProfile"); + ALCint i; + + i = 0; + attr[i++] = ALC_HRTF_SOFT; + attr[i++] = ALC_TRUE; + // load the default device hrtf. + if (index >= 0 && index < profileCount) + { + attr[i++] = ALC_HRTF_ID_SOFT; + attr[i++] = index; + } + attr[i] = 0; + + if (!alcResetDeviceSOFT(mDevice, attr)) + { + Con::printf("Failed to reset device: %s", alcGetString(mDevice, alcGetError(mDevice))); + } + } } // --- EFX --- diff --git a/Engine/source/sfx/sfxDevice.cpp b/Engine/source/sfx/sfxDevice.cpp index e800ca420..0c5d2c8ee 100644 --- a/Engine/source/sfx/sfxDevice.cpp +++ b/Engine/source/sfx/sfxDevice.cpp @@ -33,6 +33,7 @@ S32 SFXDevice::smUpdateInterval = SFXInternal::DEFAULT_UPDATE_INTERVAL; S32 SFXDevice::smDeviceFrequency = 44100; S32 SFXDevice::smMaxSendsPerSource = 4; S32 SFXDevice::smMaxEffectSlots = 4; +S32 SFXDevice::smDeviceHRTFProfile = -1; S8 SFXDevice::smDeviceBitrate = 16; bool SFXDevice::smDeviceHRTF = false; @@ -51,6 +52,11 @@ void SFXDevice::initConsole() "The device uses hrtf.\n" "@ingroup SFX\n"); + Con::addVariable("$pref::SFX::hrtfProfile", TypeS32, &smDeviceHRTFProfile, + "Index of the HRTF profile to use. -1 = driver default. " + "Use sfxGetHRTFProfileCount/sfxGetHRTFProfileName to enumerate available profiles.\n" + "@ingroup SFX\n"); + Con::addVariable("$pref::SFX::updateInterval", TypeS32, &smUpdateInterval, "The update interval.\n" "@ingroup SFX\n"); diff --git a/Engine/source/sfx/sfxDevice.h b/Engine/source/sfx/sfxDevice.h index 5a7170e31..d75d6aacf 100644 --- a/Engine/source/sfx/sfxDevice.h +++ b/Engine/source/sfx/sfxDevice.h @@ -81,6 +81,8 @@ class SFXDevice static S32 smUpdateInterval; /// The device frequency, used when reading in buffers for the device. static S32 smDeviceFrequency; + /// The device hrtf profile to use. + static S32 smDeviceHRTFProfile; /// The device bitrate. static S8 smDeviceBitrate; /// Does the device use hrtf