aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-09-25 10:29:38 -0700
committerChris Robinson <[email protected]>2018-09-25 10:33:20 -0700
commit2d6309d6fc68e5c2f658b48e6e44ba10be42848e (patch)
tree019a0ad46004179747023f82b26ccc09832c702d /Alc
parentc69338bc0dc338db7077a2c6759222ca4703f4eb (diff)
Don't hardcode the limiter threshold
It's now calculated from the output sample type and dither depth.
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALc.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index ecacf8c5..a65a56b6 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -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);