Don't hardcode the limiter threshold

It's now calculated from the output sample type and dither depth.
This commit is contained in:
Chris Robinson 2018-09-25 10:29:38 -07:00
parent c69338bc0d
commit 2d6309d6fc

View File

@ -1704,11 +1704,11 @@ static void alcSetError(ALCdevice *device, ALCenum errorCode)
}
struct Compressor *CreateDeviceLimiter(const ALCdevice *device)
static struct Compressor *CreateDeviceLimiter(const ALCdevice *device, const ALfloat threshold)
{
return CompressorInit(device->RealOut.NumChannels, device->Frequency,
AL_TRUE, AL_TRUE, AL_TRUE, AL_TRUE, AL_TRUE, 0.001f, 0.002f,
0.0f, 0.0f, -0.0003f, INFINITY, 0.0f, 0.020f, 0.200f);
0.0f, 0.0f, threshold, INFINITY, 0.0f, 0.020f, 0.200f);
}
/* UpdateClockBase
@ -2232,12 +2232,27 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
*/
if(gainLimiter != ALC_FALSE)
{
if(!device->Limiter || device->Frequency != GetCompressorSampleRate(device->Limiter) ||
device->RealOut.NumChannels != GetCompressorChannelCount(device->Limiter))
ALfloat thrshld = 1.0f;
switch(device->FmtType)
{
al_free(device->Limiter);
device->Limiter = CreateDeviceLimiter(device);
case DevFmtByte:
case DevFmtUByte:
thrshld = 127.0f / 128.0f;
break;
case DevFmtShort:
case DevFmtUShort:
thrshld = 32767.0f / 32768.0f;
break;
case DevFmtInt:
case DevFmtUInt:
case DevFmtFloat:
break;
}
if(device->DitherDepth > 0.0f)
thrshld -= 1.0f / device->DitherDepth;
al_free(device->Limiter);
device->Limiter = CreateDeviceLimiter(device, log10f(thrshld) * 20.0f);
}
else
{
@ -4213,7 +4228,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
ERR("Unsupported ambi-format: %s\n", fmt);
}
device->Limiter = CreateDeviceLimiter(device);
device->Limiter = CreateDeviceLimiter(device, 0.0f);
{
ALCdevice *head = ATOMIC_LOAD_SEQ(&DeviceList);
@ -4542,7 +4557,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN
// Open the "backend"
V(device->Backend,open)("Loopback");
device->Limiter = CreateDeviceLimiter(device);
device->Limiter = CreateDeviceLimiter(device, 0.0f);
{
ALCdevice *head = ATOMIC_LOAD_SEQ(&DeviceList);