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
This commit is contained in:
marauder2k7 2026-05-09 12:02:01 +01:00
parent 345ce3f1d3
commit bcde183786
3 changed files with 32 additions and 0 deletions

View file

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

View file

@ -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");

View file

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