aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-11-22 20:52:08 -0800
committerChris Robinson <[email protected]>2014-11-22 20:52:08 -0800
commit312330dbaae546bd0331c213dd55499f056091e7 (patch)
treee9b6a0dc9b332f66b463c90a209f0624e2068269 /Alc
parentf7d7afb7c13b1b99b932b776f127d2ff5048b7f6 (diff)
Rework HRTF decision logic
This way takes into account a new stereo-mode config option, which when set to "headphones" will default to using HRTF. Eventually the device will also be able to specify if headphones are being used.
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALc.c89
-rw-r--r--Alc/alcConfig.c10
2 files changed, 63 insertions, 36 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 9a5daab4..8b14746d 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -1891,28 +1891,21 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
UpdateClockBase(device);
- if(device->Type != Loopback)
- {
- bool usehrtf = !!(device->Flags&DEVICE_HRTF_REQUEST);
- if(GetConfigValueBool(NULL, "hrtf", usehrtf))
- device->Flags |= DEVICE_HRTF_REQUEST;
- else
- device->Flags &= ~DEVICE_HRTF_REQUEST;
- }
if((device->Flags&DEVICE_HRTF_REQUEST))
{
- enum DevFmtChannels chans = device->FmtChans;
- ALCuint freq = device->Frequency;
- if(FindHrtfFormat(&chans, &freq))
+ if(device->Type != Loopback)
{
- if(device->Type != Loopback)
- {
- device->Frequency = freq;
- device->FmtChans = chans;
+ if(!FindHrtfFormat(&device->FmtChans, &device->Frequency))
+ device->Flags &= ~DEVICE_HRTF_REQUEST;
+ else
device->Flags |= DEVICE_CHANNELS_REQUEST |
DEVICE_FREQUENCY_REQUEST;
- }
- else if(device->Frequency != freq || device->FmtChans != chans)
+ }
+ else
+ {
+ enum DevFmtChannels chans = device->FmtChans;
+ ALCuint freq = device->Frequency;
+ if(!FindHrtfFormat(&chans, &freq) || chans != device->FmtChans || freq != device->Frequency)
{
ERR("Requested format not HRTF compatible: %s, %uhz\n",
DevFmtChannelsString(device->FmtChans), device->Frequency);
@@ -1967,31 +1960,55 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
}
device->Hrtf = NULL;
- if((device->Flags&DEVICE_HRTF_REQUEST))
+ if(device->FmtChans != DevFmtStereo)
+ {
+ TRACE("HRTF %s\n", "disabled");
+ free(device->Bs2b);
+ device->Bs2b = NULL;
+ TRACE("BS2B disabled\n");
+ }
+ else
{
- device->Hrtf = GetHrtf(device->FmtChans, device->Frequency);
+ bool headphones = false;
+ const char *mode;
+ int usehrtf;
+
+ if(ConfigValueStr(NULL, "stereo-mode", &mode))
+ {
+ if(strcasecmp(mode, "headphones") == 0)
+ headphones = true;
+ else if(strcasecmp(mode, "speakers") == 0)
+ headphones = false;
+ else if(strcasecmp(mode, "auto") != 0)
+ ERR("Unexpected stereo-mode: %s\n", mode);
+ }
+
+ if(!ConfigValueBool(NULL, "hrtf", &usehrtf))
+ usehrtf = ((device->Flags&DEVICE_HRTF_REQUEST) || headphones);
+
+ if(usehrtf)
+ device->Hrtf = GetHrtf(device->FmtChans, device->Frequency);
if(!device->Hrtf)
device->Flags &= ~DEVICE_HRTF_REQUEST;
- }
- TRACE("HRTF %s\n", device->Hrtf?"enabled":"disabled");
+ TRACE("HRTF %s\n", device->Hrtf?"enabled":"disabled");
- if(!device->Hrtf && device->Bs2bLevel > 0 && device->Bs2bLevel <= 6 &&
- device->FmtChans == DevFmtStereo)
- {
- if(!device->Bs2b)
+ if(!device->Hrtf && device->Bs2bLevel > 0 && device->Bs2bLevel <= 6)
+ {
+ if(!device->Bs2b)
+ {
+ device->Bs2b = calloc(1, sizeof(*device->Bs2b));
+ bs2b_clear(device->Bs2b);
+ }
+ bs2b_set_srate(device->Bs2b, device->Frequency);
+ bs2b_set_level(device->Bs2b, device->Bs2bLevel);
+ TRACE("BS2B level %d\n", device->Bs2bLevel);
+ }
+ else
{
- device->Bs2b = calloc(1, sizeof(*device->Bs2b));
- bs2b_clear(device->Bs2b);
+ free(device->Bs2b);
+ device->Bs2b = NULL;
+ TRACE("BS2B disabled\n");
}
- bs2b_set_srate(device->Bs2b, device->Frequency);
- bs2b_set_level(device->Bs2b, device->Bs2bLevel);
- TRACE("BS2B level %d\n", device->Bs2bLevel);
- }
- else
- {
- free(device->Bs2b);
- device->Bs2b = NULL;
- TRACE("BS2B disabled\n");
}
aluInitPanning(device);
diff --git a/Alc/alcConfig.c b/Alc/alcConfig.c
index a7d36a84..c8928c3c 100644
--- a/Alc/alcConfig.c
+++ b/Alc/alcConfig.c
@@ -514,6 +514,16 @@ int ConfigValueFloat(const char *blockName, const char *keyName, float *ret)
return 1;
}
+int ConfigValueBool(const char *blockName, const char *keyName, int *ret)
+{
+ const char *val = GetConfigValue(blockName, keyName, "");
+ if(!val[0]) return 0;
+
+ *ret = (strcasecmp(val, "true") == 0 || strcasecmp(val, "yes") == 0 ||
+ strcasecmp(val, "on") == 0 || atoi(val) != 0);
+ return 1;
+}
+
int GetConfigValueBool(const char *blockName, const char *keyName, int def)
{
const char *val = GetConfigValue(blockName, keyName, "");