aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2017-02-28 21:01:13 -0800
committerChris Robinson <[email protected]>2017-02-28 21:01:13 -0800
commit521abf2e0725cc4e4abfc17e75681e47fb372f68 (patch)
tree1082d544446782001c9f6a644955f9e510f60df6
parent51092a6315cf0a307efec2d76a32dde0f38873a3 (diff)
Dynamically allocate the channel delay buffers
-rw-r--r--Alc/ALc.c42
-rw-r--r--Alc/ALu.c12
-rw-r--r--Alc/panning.c16
-rw-r--r--OpenAL32/Include/alMain.h4
4 files changed, 66 insertions, 8 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index aedcd493..b46244aa 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -1807,6 +1807,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
ALCuint oldFreq;
FPUCtl oldMode;
size_t size;
+ ALCsizei i;
// Check for attributes
if(device->Type == Loopback)
@@ -2048,6 +2049,13 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
al_free(device->Bs2b);
device->Bs2b = NULL;
+ al_free(device->ChannelDelay[0].Buffer);
+ for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
+ {
+ device->ChannelDelay[i].Length = 0;
+ device->ChannelDelay[i].Buffer = NULL;
+ }
+
al_free(device->Dry.Buffer);
device->Dry.Buffer = NULL;
device->Dry.NumChannels = 0;
@@ -2329,6 +2337,8 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
*/
static ALCvoid FreeDevice(ALCdevice *device)
{
+ ALsizei i;
+
TRACE("%p\n", device);
V0(device->Backend,close)();
@@ -2382,6 +2392,14 @@ static ALCvoid FreeDevice(ALCdevice *device)
ambiup_free(device->AmbiUp);
device->AmbiUp = NULL;
+ al_free(device->ChannelDelay[0].Buffer);
+ for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
+ {
+ device->ChannelDelay[i].Gain = 1.0f;
+ device->ChannelDelay[i].Length = 0;
+ device->ChannelDelay[i].Buffer = NULL;
+ }
+
AL_STRING_DEINIT(device->DeviceName);
al_free(device->Dry.Buffer);
@@ -3687,6 +3705,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
const ALCchar *fmt;
ALCdevice *device;
ALCenum err;
+ ALCsizei i;
DO_INITCONFIG();
@@ -3748,6 +3767,13 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
InitUIntMap(&device->EffectMap, ~0);
InitUIntMap(&device->FilterMap, ~0);
+ for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
+ {
+ device->ChannelDelay[i].Gain = 1.0f;
+ device->ChannelDelay[i].Length = 0;
+ device->ChannelDelay[i].Buffer = NULL;
+ }
+
//Set output format
device->FmtChans = DevFmtChannelsDefault;
device->FmtType = DevFmtTypeDefault;
@@ -3991,6 +4017,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName,
{
ALCdevice *device = NULL;
ALCenum err;
+ ALCsizei i;
DO_INITCONFIG();
@@ -4036,6 +4063,13 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName,
InitUIntMap(&device->EffectMap, ~0);
InitUIntMap(&device->FilterMap, ~0);
+ for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
+ {
+ device->ChannelDelay[i].Gain = 1.0f;
+ device->ChannelDelay[i].Length = 0;
+ device->ChannelDelay[i].Buffer = NULL;
+ }
+
if(!CaptureBackend.getFactory)
device->Backend = create_backend_wrapper(device, &CaptureBackend.Funcs,
ALCbackend_Capture);
@@ -4198,6 +4232,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN
{
ALCbackendFactory *factory;
ALCdevice *device;
+ ALCsizei i;
DO_INITCONFIG();
@@ -4248,6 +4283,13 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN
InitUIntMap(&device->EffectMap, ~0);
InitUIntMap(&device->FilterMap, ~0);
+ for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
+ {
+ device->ChannelDelay[i].Gain = 1.0f;
+ device->ChannelDelay[i].Length = 0;
+ device->ChannelDelay[i].Buffer = NULL;
+ }
+
factory = ALCloopbackFactory_getFactory();
device->Backend = V(factory,createBackend)(device, ALCbackend_Loopback);
if(!device->Backend)
diff --git a/Alc/ALu.c b/Alc/ALu.c
index b4938152..9fe5712d 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -1332,24 +1332,24 @@ static void Write_##T(const ALfloatBUFFERSIZE *InBuffer, ALvoid *OutBuffer, \
T *restrict out = (T*)OutBuffer + j; \
const ALfloat gain = distcomp[j].Gain; \
const ALsizei base = distcomp[j].Length; \
+ ALfloat *restrict distbuf = ASSUME_ALIGNED(distcomp[j].Buffer, 16); \
if(base > 0 || gain != 1.0f) \
{ \
if(SamplesToDo >= base) \
{ \
for(i = 0;i < base;i++) \
- out[i*numchans] = func(distcomp[j].Buffer[i]*gain); \
+ out[i*numchans] = func(distbuf[i]*gain); \
for(;i < SamplesToDo;i++) \
out[i*numchans] = func(in[i-base]*gain); \
- memcpy(distcomp[j].Buffer, &in[SamplesToDo-base], \
- base*sizeof(ALfloat)); \
+ memcpy(distbuf, &in[SamplesToDo-base], base*sizeof(ALfloat)); \
} \
else \
{ \
for(i = 0;i < SamplesToDo;i++) \
- out[i*numchans] = func(distcomp[j].Buffer[i]*gain); \
- memmove(distcomp[j].Buffer, distcomp[j].Buffer+SamplesToDo, \
+ out[i*numchans] = func(distbuf[i]*gain); \
+ memmove(distbuf, distbuf+SamplesToDo, \
(base-SamplesToDo)*sizeof(ALfloat)); \
- memcpy(distcomp[j].Buffer+base-SamplesToDo, in, \
+ memcpy(distbuf+base-SamplesToDo, in, \
SamplesToDo*sizeof(ALfloat)); \
} \
} \
diff --git a/Alc/panning.c b/Alc/panning.c
index 84e1dbed..c4d3e43f 100644
--- a/Alc/panning.c
+++ b/Alc/panning.c
@@ -616,6 +616,7 @@ static void InitDistanceComp(ALCdevice *device, const AmbDecConf *conf, const AL
{
const char *devname = al_string_get_cstr(device->DeviceName);
ALfloat maxdist = 0.0f;
+ ALsizei total = 0;
ALsizei i;
for(i = 0;i < conf->NumSpeakers;i++)
@@ -649,6 +650,21 @@ static void InitDistanceComp(ALCdevice *device, const AmbDecConf *conf, const AL
al_string_get_cstr(conf->Speakers[i].Name), device->ChannelDelay[chan].Length,
device->ChannelDelay[chan].Gain
);
+
+ /* Round up to the next 4th sample, so each channel buffer starts
+ * 16-byte aligned.
+ */
+ total += RoundUp(device->ChannelDelay[chan].Length, 4);
+ }
+ }
+
+ if(total > 0)
+ {
+ device->ChannelDelay[0].Buffer = al_calloc(16, total * sizeof(ALfloat));
+ for(i = 1;i < MAX_OUTPUT_CHANNELS;i++)
+ {
+ size_t len = RoundUp(device->ChannelDelay[i-1].Length, 4);
+ device->ChannelDelay[i].Buffer = device->ChannelDelay[i-1].Buffer + len;
}
}
}
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 9407cdce..cc30dcef 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -631,12 +631,12 @@ TYPEDEF_VECTOR(HrtfEntry, vector_HrtfEntry)
/* Maximum delay in samples for speaker distance compensation. */
-#define MAX_DELAY_LENGTH 128
+#define MAX_DELAY_LENGTH 1024
typedef struct DistanceComp {
ALfloat Gain;
ALsizei Length; /* Valid range is [0...MAX_DELAY_LENGTH). */
- alignas(16) ALfloat Buffer[MAX_DELAY_LENGTH];
+ ALfloat *Buffer;
} DistanceComp;
/* Size for temporary storage of buffer data, in ALfloats. Larger values need