diff options
-rw-r--r-- | Alc/ALc.c | 31 |
1 files changed, 23 insertions, 8 deletions
@@ -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); |