aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2015-10-07 03:29:53 -0700
committerChris Robinson <[email protected]>2015-10-07 03:29:53 -0700
commit4f4cadd756bc710792fb181e5093d6eb3c23c09d (patch)
tree1cf69c0d194401dee70dc95dcc3490c12e23a89f
parent0eef6d9d51f90e0066734f22cb49c27bee5ec64c (diff)
Allow apps to request a specific HRTF
-rw-r--r--Alc/ALc.c62
-rw-r--r--OpenAL32/Include/alMain.h5
2 files changed, 50 insertions, 17 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index d2f2e290..2610bf45 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -392,6 +392,7 @@ static const ALCenums enumeration[] = {
DECL(ALC_HRTF_UNSUPPORTED_FORMAT_SOFT),
DECL(ALC_NUM_HRTF_SPECIFIER_SOFT),
DECL(ALC_HRTF_SPECIFIER_SOFT),
+ DECL(ALC_HRTF_ID_SOFT),
DECL(ALC_NO_ERROR),
DECL(ALC_INVALID_DEVICE),
@@ -1705,6 +1706,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
enum DevFmtType oldType;
ALCuint oldFreq;
FPUCtl oldMode;
+ ALCsizei hrtf_id = -1;
size_t size;
// Check for attributes
@@ -1785,6 +1787,9 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
hrtf_appreq = Hrtf_Default;
}
+ if(attrList[attrIdx] == ALC_HRTF_ID_SOFT)
+ hrtf_id = attrList[attrIdx + 1];
+
attrIdx += 2;
}
@@ -1856,6 +1861,9 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
hrtf_appreq = Hrtf_Default;
}
+ if(attrList[attrIdx] == ALC_HRTF_ID_SOFT)
+ hrtf_id = attrList[attrIdx + 1];
+
attrIdx += 2;
}
@@ -1911,7 +1919,10 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
if(VECTOR_SIZE(device->Hrtf_List) > 0)
{
device->FmtChans = DevFmtStereo;
- device->Frequency = GetHrtfSampleRate(VECTOR_ELEM(device->Hrtf_List, 0).hrtf);
+ if(hrtf_id >= 0 && (size_t)hrtf_id < VECTOR_SIZE(device->Hrtf_List))
+ device->Frequency = GetHrtfSampleRate(VECTOR_ELEM(device->Hrtf_List, hrtf_id).hrtf);
+ else
+ device->Frequency = GetHrtfSampleRate(VECTOR_ELEM(device->Hrtf_List, 0).hrtf);
device->Flags |= DEVICE_CHANNELS_REQUEST | DEVICE_FREQUENCY_REQUEST;
}
else
@@ -1924,16 +1935,24 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
else if(hrtf_appreq == Hrtf_Enable)
{
size_t i;
- if(VECTOR_SIZE(device->Hrtf_List) == 0)
- {
- VECTOR_DEINIT(device->Hrtf_List);
- device->Hrtf_List = EnumerateHrtf(device->DeviceName);
- }
- for(i = 0;i < VECTOR_SIZE(device->Hrtf_List);i++)
+ /* Loopback device. We don't need to match to a specific HRTF entry
+ * here. If the requested ID matches, we'll pick that later, if not,
+ * we'll try to auto-select one anyway. */
+ if(device->FmtChans != DevFmtStereo)
+ i = VECTOR_SIZE(device->Hrtf_List);
+ else
{
- const struct Hrtf *hrtf = VECTOR_ELEM(device->Hrtf_List, i).hrtf;
- if(GetHrtfSampleRate(hrtf) == device->Frequency)
- break;
+ if(VECTOR_SIZE(device->Hrtf_List) == 0)
+ {
+ VECTOR_DEINIT(device->Hrtf_List);
+ device->Hrtf_List = EnumerateHrtf(device->DeviceName);
+ }
+ for(i = 0;i < VECTOR_SIZE(device->Hrtf_List);i++)
+ {
+ const struct Hrtf *hrtf = VECTOR_ELEM(device->Hrtf_List, i).hrtf;
+ if(GetHrtfSampleRate(hrtf) == device->Frequency)
+ break;
+ }
}
if(i == VECTOR_SIZE(device->Hrtf_List))
{
@@ -2063,14 +2082,27 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
VECTOR_DEINIT(device->Hrtf_List);
device->Hrtf_List = EnumerateHrtf(device->DeviceName);
}
- for(i = 0;i < VECTOR_SIZE(device->Hrtf_List);i++)
+
+ if(hrtf_id >= 0 && (size_t)hrtf_id < VECTOR_SIZE(device->Hrtf_List))
{
- const HrtfEntry *entry = &VECTOR_ELEM(device->Hrtf_List, i);
+ const HrtfEntry *entry = &VECTOR_ELEM(device->Hrtf_List, hrtf_id);
if(GetHrtfSampleRate(entry->hrtf) == device->Frequency)
{
device->Hrtf = entry->hrtf;
al_string_copy(&device->Hrtf_Name, entry->name);
- break;
+ }
+ }
+ if(!device->Hrtf)
+ {
+ for(i = 0;i < VECTOR_SIZE(device->Hrtf_List);i++)
+ {
+ const HrtfEntry *entry = &VECTOR_ELEM(device->Hrtf_List, i);
+ if(GetHrtfSampleRate(entry->hrtf) == device->Frequency)
+ {
+ device->Hrtf = entry->hrtf;
+ al_string_copy(&device->Hrtf_Name, entry->name);
+ break;
+ }
}
}
}
@@ -2078,7 +2110,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
{
device->Hrtf_Mode = hrtf_mode;
device->Hrtf_Status = hrtf_status;
- TRACE("HRTF enabled, using \"%s\"\n", al_string_get_cstr(device->Hrtf_Name));
+ TRACE("HRTF enabled, \"%s\"\n", al_string_get_cstr(device->Hrtf_Name));
free(device->Bs2b);
device->Bs2b = NULL;
}
@@ -4022,7 +4054,7 @@ ALC_API void ALC_APIENTRY alcDeviceResumeSOFT(ALCdevice *device)
*
* Gets a string parameter at the given index.
*/
-ALC_API const ALCchar* ALC_APIENTRY alcGetStringiSOFT(ALCdevice *device, ALenum paramName, ALsizei index)
+ALC_API const ALCchar* ALC_APIENTRY alcGetStringiSOFT(ALCdevice *device, ALCenum paramName, ALCsizei index)
{
const ALCchar *str = NULL;
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 077c0f95..523b63c1 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -52,10 +52,11 @@
#define ALC_HRTF_UNSUPPORTED_FORMAT_SOFT 0x0005
#define ALC_NUM_HRTF_SPECIFIER_SOFT 0x1994
#define ALC_HRTF_SPECIFIER_SOFT 0x1995
-typedef const ALCchar* (ALC_APIENTRY*LPALCGETSTRINGISOFT)(ALCdevice *device, ALenum paramName, ALsizei index);
+#define ALC_HRTF_ID_SOFT 0x1996
+typedef const ALCchar* (ALC_APIENTRY*LPALCGETSTRINGISOFT)(ALCdevice *device, ALCenum paramName, ALCsizei index);
typedef ALCboolean (ALC_APIENTRY*LPALCRESETDEVICESOFT)(ALCdevice *device, const ALCint *attribs);
#ifdef AL_ALEXT_PROTOTYPES
-ALC_API const ALCchar* ALC_APIENTRY alcGetStringiSOFT(ALCdevice *device, ALenum paramName, ALsizei index);
+ALC_API const ALCchar* ALC_APIENTRY alcGetStringiSOFT(ALCdevice *device, ALCenum paramName, ALCsizei index);
ALC_API ALCboolean ALC_APIENTRY alcResetDeviceSOFT(ALCdevice *device, const ALCint *attribs);
#endif
#endif