From 5f5eebc4df536daef7f68d02f7a0c751c8dc0f79 Mon Sep 17 00:00:00 2001
From: Chris Robinson <chris.kcat@gmail.com>
Date: Sun, 20 Sep 2015 04:10:21 -0700
Subject: Allow the hrtf_tables option to be device-specific

---
 Alc/ALc.c       |  7 ++++---
 Alc/hrtf.c      | 15 +++++++--------
 Alc/hrtf.h      |  6 ++++--
 alsoftrc.sample |  2 +-
 4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/Alc/ALc.c b/Alc/ALc.c
index d43b587c..6c963bf3 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -1924,7 +1924,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
 
         if(hrtf_userreq == Hrtf_Enable || (hrtf_userreq != Hrtf_Disable && hrtf_appreq == Hrtf_Enable))
         {
-            if(FindHrtfFormat(&device->FmtChans, &device->Frequency))
+            if(FindHrtfFormat(device->DeviceName, &device->FmtChans, &device->Frequency))
                 device->Flags |= DEVICE_CHANNELS_REQUEST | DEVICE_FREQUENCY_REQUEST;
             else
             {
@@ -1937,7 +1937,8 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
     {
         enum DevFmtChannels chans = device->FmtChans;
         ALCuint freq = device->Frequency;
-        if(!FindHrtfFormat(&chans, &freq) || chans != device->FmtChans || freq != device->Frequency)
+        if(!FindHrtfFormat(device->DeviceName, &chans, &freq) ||
+           chans != device->FmtChans || freq != device->Frequency)
         {
             ERR("Requested format not HRTF compatible: %s, %uhz\n",
                 DevFmtChannelsString(device->FmtChans), device->Frequency);
@@ -2057,7 +2058,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
         else
         {
             device->Hrtf_Status = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
-            device->Hrtf = GetHrtf(device->FmtChans, device->Frequency);
+            device->Hrtf = GetHrtf(device->DeviceName, device->FmtChans, device->Frequency);
         }
         if(device->Hrtf)
         {
diff --git a/Alc/hrtf.c b/Alc/hrtf.c
index ca372244..e69578a6 100644
--- a/Alc/hrtf.c
+++ b/Alc/hrtf.c
@@ -726,11 +726,11 @@ static struct Hrtf *LoadHrtf01(FILE *f, ALuint deviceRate)
 }
 
 
-static struct Hrtf *LoadHrtf(ALuint deviceRate)
+static struct Hrtf *LoadHrtf(const_al_string devname, ALuint deviceRate)
 {
     const char *fnamelist = "default-%r.mhr";
 
-    ConfigValueStr(NULL, NULL, "hrtf_tables", &fnamelist);
+    ConfigValueStr(al_string_get_cstr(devname), NULL, "hrtf_tables", &fnamelist);
     while(*fnamelist != '\0')
     {
         struct Hrtf *Hrtf = NULL;
@@ -823,7 +823,7 @@ static struct Hrtf *LoadHrtf(ALuint deviceRate)
     return NULL;
 }
 
-const struct Hrtf *GetHrtf(enum DevFmtChannels chans, ALCuint srate)
+const struct Hrtf *GetHrtf(const_al_string devname, enum DevFmtChannels chans, ALCuint srate)
 {
     if(chans == DevFmtStereo)
     {
@@ -835,15 +835,14 @@ const struct Hrtf *GetHrtf(enum DevFmtChannels chans, ALCuint srate)
             Hrtf = Hrtf->next;
         }
 
-        Hrtf = LoadHrtf(srate);
-        if(Hrtf != NULL)
-            return Hrtf;
+        Hrtf = LoadHrtf(devname, srate);
+        if(Hrtf != NULL) return Hrtf;
     }
     ERR("Incompatible format: %s %uhz\n", DevFmtChannelsString(chans), srate);
     return NULL;
 }
 
-ALCboolean FindHrtfFormat(enum DevFmtChannels *chans, ALCuint *srate)
+ALCboolean FindHrtfFormat(const_al_string devname, enum DevFmtChannels *chans, ALCuint *srate)
 {
     const struct Hrtf *hrtf = LoadedHrtfs;
     while(hrtf != NULL)
@@ -855,7 +854,7 @@ ALCboolean FindHrtfFormat(enum DevFmtChannels *chans, ALCuint *srate)
 
     if(hrtf == NULL)
     {
-        hrtf = LoadHrtf(*srate);
+        hrtf = LoadHrtf(devname, *srate);
         if(hrtf == NULL) return ALC_FALSE;
     }
 
diff --git a/Alc/hrtf.h b/Alc/hrtf.h
index ba72e45e..fed75173 100644
--- a/Alc/hrtf.h
+++ b/Alc/hrtf.h
@@ -4,6 +4,8 @@
 #include "AL/al.h"
 #include "AL/alc.h"
 
+#include "alstring.h"
+
 enum DevFmtChannels;
 
 struct Hrtf;
@@ -15,8 +17,8 @@ struct Hrtf;
 #define HRTFDELAY_FRACONE (1<<HRTFDELAY_BITS)
 #define HRTFDELAY_MASK    (HRTFDELAY_FRACONE-1)
 
-const struct Hrtf *GetHrtf(enum DevFmtChannels chans, ALCuint srate);
-ALCboolean FindHrtfFormat(enum DevFmtChannels *chans, ALCuint *srate);
+const struct Hrtf *GetHrtf(const_al_string devname, enum DevFmtChannels chans, ALCuint srate);
+ALCboolean FindHrtfFormat(const_al_string devname, enum DevFmtChannels *chans, ALCuint *srate);
 
 void FreeHrtfs(void);
 
diff --git a/alsoftrc.sample b/alsoftrc.sample
index af867428..cc45c892 100644
--- a/alsoftrc.sample
+++ b/alsoftrc.sample
@@ -96,7 +96,7 @@
 #  respectively.
 #hrtf = auto
 
-## hrtf_tables: (global)
+## hrtf_tables:
 #  Specifies a comma-separated list of files containing HRTF data sets. The
 #  format of the files are described in hrtf.txt. The filenames may contain
 #  these markers, which will be replaced as needed:
-- 
cgit v1.2.3