aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alc/ALc.c1
-rw-r--r--Alc/hrtf.c52
-rw-r--r--OpenAL32/Include/alMain.h1
3 files changed, 47 insertions, 7 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index d53829ea..07d6fe3d 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -528,6 +528,7 @@ static void alc_deinit_safe(void)
{
ReleaseALC(ALC_FALSE);
+ FreeHrtf();
FreeALConfig();
ThunkExit();
diff --git a/Alc/hrtf.c b/Alc/hrtf.c
index 3d780c93..98caff3f 100644
--- a/Alc/hrtf.c
+++ b/Alc/hrtf.c
@@ -20,6 +20,8 @@
#include "config.h"
+#include <stdlib.h>
+
#include "AL/al.h"
#include "AL/alc.h"
#include "alMain.h"
@@ -49,15 +51,20 @@ static const ALchar magicMarker[8] = "MinPHR00";
static const ALushort evOffset[ELEV_COUNT] = { 0, 1, 13, 37, 73, 118, 174, 234, 306, 378, 450, 522, 594, 654, 710, 755, 791, 815, 827 };
static const ALubyte azCount[ELEV_COUNT] = { 1, 12, 24, 36, 45, 56, 60, 72, 72, 72, 72, 72, 60, 56, 45, 36, 24, 12, 1 };
-static struct Hrtf {
+
+static const struct Hrtf {
ALuint sampleRate;
ALshort coeffs[HRIR_COUNT][HRIR_LENGTH];
ALubyte delays[HRIR_COUNT];
-} LoadedHrtf = {
+} DefaultHrtf = {
44100,
#include "hrtf_tables.inc"
};
+static struct Hrtf *LoadedHrtfs = NULL;
+static ALuint NumLoadedHrtfs = 0;
+
+
// Calculate the elevation indices given the polar elevation in radians.
// This will return two indices between 0 and (ELEV_COUNT-1) and an
// interpolation factor between 0.0 and 1.0.
@@ -289,8 +296,15 @@ ALuint GetMovingHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat a
const struct Hrtf *GetHrtf(ALCdevice *device)
{
- if(device->FmtChans == DevFmtStereo && device->Frequency == LoadedHrtf.sampleRate)
- return &LoadedHrtf;
+ if(device->FmtChans == DevFmtStereo)
+ {
+ ALuint i;
+ for(i = 0;i < NumLoadedHrtfs;i++)
+ {
+ if(device->Frequency == LoadedHrtfs[i].sampleRate)
+ return &LoadedHrtfs[i];
+ }
+ }
ERR("Incompatible format: %s %uhz\n",
DevFmtChannelsString(device->FmtChans), device->Frequency);
return NULL;
@@ -404,10 +418,34 @@ void InitHrtf(void)
f = NULL;
if(!failed)
- LoadedHrtf = newdata;
+ {
+ void *temp = realloc(LoadedHrtfs, (NumLoadedHrtfs+1)*sizeof(LoadedHrtfs[0]));
+ if(temp != NULL)
+ {
+ LoadedHrtfs = temp;
+ TRACE("HRTF support for format: %s %uhz\n",
+ DevFmtChannelsString(DevFmtStereo), newdata.sampleRate);
+ LoadedHrtfs[NumLoadedHrtfs++] = newdata;
+ }
+ }
else
ERR("Failed to load %s\n", fname);
}
- TRACE("HRTF support for format: %s %uhz\n",
- DevFmtChannelsString(DevFmtStereo), LoadedHrtf.sampleRate);
+ if(NumLoadedHrtfs == 0)
+ {
+ LoadedHrtfs = malloc(sizeof(LoadedHrtfs[0]));
+ if(LoadedHrtfs != NULL)
+ {
+ TRACE("Default HRTF support for format: %s %uhz\n",
+ DevFmtChannelsString(DevFmtStereo), DefaultHrtf.sampleRate);
+ LoadedHrtfs[NumLoadedHrtfs++] = DefaultHrtf;
+ }
+ }
+}
+
+void FreeHrtf(void)
+{
+ NumLoadedHrtfs = 0;
+ free(LoadedHrtfs);
+ LoadedHrtfs = NULL;
}
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index a5a96e81..67974cb3 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -685,6 +685,7 @@ const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans);
#define HRIR_LENGTH (1<<HRIR_BITS)
#define HRIR_MASK (HRIR_LENGTH-1)
void InitHrtf(void);
+void FreeHrtf(void);
const struct Hrtf *GetHrtf(ALCdevice *device);
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);