aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alc/ALc.c41
-rw-r--r--Alc/hrtf.c24
-rw-r--r--OpenAL32/Include/alMain.h5
3 files changed, 68 insertions, 2 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index be6b4227..cd408f89 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -1531,6 +1531,14 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
if(attrList[attrIdx] == ALC_MAX_AUXILIARY_SENDS)
numSends = attrList[attrIdx + 1];
+ if(attrList[attrIdx] == ALC_HRTF_SOFT)
+ {
+ if(attrList[attrIdx + 1] != ALC_FALSE)
+ device->Flags |= DEVICE_HRTF_REQUEST;
+ else
+ device->Flags &= ~DEVICE_HRTF_REQUEST;
+ }
+
attrIdx += 2;
}
@@ -1590,6 +1598,14 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
if(attrList[attrIdx] == ALC_MAX_AUXILIARY_SENDS)
numSends = attrList[attrIdx + 1];
+ if(attrList[attrIdx] == ALC_HRTF_SOFT)
+ {
+ if(attrList[attrIdx + 1] != ALC_FALSE)
+ device->Flags |= DEVICE_HRTF_REQUEST;
+ else
+ device->Flags &= ~DEVICE_HRTF_REQUEST;
+ }
+
attrIdx += 2;
}
@@ -1627,6 +1643,18 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
device->Frequency,
device->UpdateSize, device->NumUpdates);
+ if((device->Flags&DEVICE_HRTF_REQUEST))
+ {
+ enum DevFmtChannels chans;
+ ALCuint freq;
+
+ FindHrtfFormat(device, &chans, &freq);
+ device->Frequency = freq;
+ device->FmtChans = chans;
+ device->Flags |= DEVICE_CHANNELS_REQUEST |
+ DEVICE_FREQUENCY_REQUEST;
+ }
+
if(ALCdevice_ResetPlayback(device) == ALC_FALSE)
return ALC_INVALID_DEVICE;
@@ -1662,8 +1690,19 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
}
device->Hrtf = NULL;
- if(device->Type != Loopback && GetConfigValueBool(NULL, "hrtf", AL_FALSE))
+ if(device->Type != Loopback && ConfigValueExists(NULL, "hrtf"))
+ {
+ if(GetConfigValueBool(NULL, "hrtf", AL_FALSE))
+ device->Flags |= DEVICE_HRTF_REQUEST;
+ else
+ device->Flags &= ~DEVICE_HRTF_REQUEST;
+ }
+ if((device->Flags&DEVICE_HRTF_REQUEST))
+ {
device->Hrtf = GetHrtf(device);
+ if(!device->Hrtf)
+ device->Flags &= ~DEVICE_HRTF_REQUEST;
+ }
TRACE("HRTF %s\n", device->Hrtf?"enabled":"disabled");
if(!device->Hrtf && device->Bs2bLevel > 0 && device->Bs2bLevel <= 6)
diff --git a/Alc/hrtf.c b/Alc/hrtf.c
index 11922cc7..e772062a 100644
--- a/Alc/hrtf.c
+++ b/Alc/hrtf.c
@@ -783,6 +783,30 @@ const struct Hrtf *GetHrtf(ALCdevice *device)
return NULL;
}
+void FindHrtfFormat(const ALCdevice *device, enum DevFmtChannels *chans, ALCuint *srate)
+{
+ const struct Hrtf *hrtf = &DefaultHrtf;
+
+ if(device->Frequency != DefaultHrtf.sampleRate)
+ {
+ hrtf = LoadedHrtfs;
+ while(hrtf != NULL)
+ {
+ if(device->Frequency == hrtf->sampleRate)
+ break;
+ hrtf = hrtf->next;
+ }
+
+ if(hrtf == NULL)
+ hrtf = LoadHrtf(device->Frequency);
+ if(hrtf == NULL)
+ hrtf = &DefaultHrtf;
+ }
+
+ *chans = DevFmtStereo;
+ *srate = hrtf->sampleRate;
+}
+
void FreeHrtfs(void)
{
struct Hrtf *Hrtf = NULL;
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index d5e59321..9bee7399 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -684,6 +684,8 @@ struct ALCdevice_struct
#define DEVICE_CHANNELS_REQUEST (1<<2)
// Sample type was requested by the config file
#define DEVICE_SAMPLE_TYPE_REQUEST (1<<3)
+// HRTF was requested by the app
+#define DEVICE_HRTF_REQUEST (1<<4)
// Stereo sources cover 120-degree angles around +/-90
#define DEVICE_WIDE_STEREO (1<<16)
@@ -814,8 +816,9 @@ const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans);
#define HRTFDELAY_FRACONE (1<<HRTFDELAY_BITS)
#define HRTFDELAY_MASK (HRTFDELAY_FRACONE-1)
const struct Hrtf *GetHrtf(ALCdevice *device);
+void FindHrtfFormat(const ALCdevice *device, enum DevFmtChannels *chans, ALCuint *srate);
void FreeHrtfs(void);
-ALuint GetHrtfIrSize (const struct Hrtf *Hrtf);
+ALuint GetHrtfIrSize(const struct Hrtf *Hrtf);
ALfloat CalcHrtfDelta(ALfloat oldGain, ALfloat newGain, const ALfloat olddir[3], const ALfloat newdir[3]);
void GetLerpedHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat gain, ALfloat (*coeffs)[2], ALuint *delays);
ALuint GetMovingHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat gain, ALfloat delta, ALint counter, ALfloat (*coeffs)[2], ALuint *delays, ALfloat (*coeffStep)[2], ALint *delayStep);