aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/panning.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2017-04-06 13:00:29 -0700
committerChris Robinson <[email protected]>2017-04-06 13:00:29 -0700
commit338d61f9072bfb811266012c2a9c0a290cf353d1 (patch)
tree0ef0b218db261569105a782824c5bf50ea3a3067 /Alc/panning.c
parent94f514ae5a0392f5f01f2b479d1d858af688ae24 (diff)
Reference count HRTFs and unload them when unused
Diffstat (limited to 'Alc/panning.c')
-rw-r--r--Alc/panning.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/Alc/panning.c b/Alc/panning.c
index bd550b32..8a8840fb 100644
--- a/Alc/panning.c
+++ b/Alc/panning.c
@@ -997,6 +997,8 @@ static void InitUhjPanning(ALCdevice *device)
void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf_appreq, enum HrtfRequestMode hrtf_userreq)
{
+ /* Hold the HRTF the device last used, in case it's used again. */
+ struct Hrtf *old_hrtf = device->HrtfHandle;
const char *mode;
bool headphones;
int bs2blevel;
@@ -1028,6 +1030,9 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf
const char *devname, *layout = NULL;
AmbDecConf conf, *pconf = NULL;
+ if(old_hrtf)
+ Hrtf_DecRef(old_hrtf);
+ old_hrtf = NULL;
if(hrtf_appreq == Hrtf_Enable)
device->HrtfStatus = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
@@ -1151,29 +1156,49 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf
if(hrtf_id >= 0 && (size_t)hrtf_id < VECTOR_SIZE(device->HrtfList))
{
const EnumeratedHrtf *entry = &VECTOR_ELEM(device->HrtfList, hrtf_id);
- const struct Hrtf *hrtf = GetLoadedHrtf(entry->hrtf);
+ struct Hrtf *hrtf = GetLoadedHrtf(entry->hrtf);
if(hrtf && hrtf->sampleRate == device->Frequency)
{
device->HrtfHandle = hrtf;
alstr_copy(&device->HrtfName, entry->name);
}
+ else if(hrtf)
+ Hrtf_DecRef(hrtf);
+ }
+
+ /* Reuse the old HRTF if its compatible and any desired HRTF isn't
+ * compatible.
+ */
+ if(!device->HrtfHandle && old_hrtf)
+ {
+ if(old_hrtf->sampleRate == device->Frequency)
+ {
+ device->HrtfHandle = old_hrtf;
+ old_hrtf = NULL;
+ }
}
for(i = 0;!device->HrtfHandle && i < VECTOR_SIZE(device->HrtfList);i++)
{
const EnumeratedHrtf *entry = &VECTOR_ELEM(device->HrtfList, i);
- const struct Hrtf *hrtf = GetLoadedHrtf(entry->hrtf);
+ struct Hrtf *hrtf = GetLoadedHrtf(entry->hrtf);
if(hrtf && hrtf->sampleRate == device->Frequency)
{
device->HrtfHandle = hrtf;
alstr_copy(&device->HrtfName, entry->name);
}
+ else if(hrtf)
+ Hrtf_DecRef(hrtf);
}
if(device->HrtfHandle)
{
bool hoa_mode;
+ if(old_hrtf)
+ Hrtf_DecRef(old_hrtf);
+ old_hrtf = NULL;
+
device->Render_Mode = HrtfRender;
if(ConfigValueStr(alstr_get_cstr(device->DeviceName), NULL, "hrtf-mode", &mode))
{
@@ -1211,6 +1236,9 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf
device->HrtfStatus = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
no_hrtf:
+ if(old_hrtf)
+ Hrtf_DecRef(old_hrtf);
+ old_hrtf = NULL;
TRACE("HRTF disabled\n");
device->Render_Mode = StereoPair;