diff options
author | Chris Robinson <[email protected]> | 2017-04-26 18:38:09 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2017-04-26 18:38:09 -0700 |
commit | ca5c732261bfacdb4702fcc253b3ef0dad357a35 (patch) | |
tree | 9d9ff19e5bc80a3a5d44ba2c7a464b85097d37f1 /Alc/ALc.c | |
parent | 1754d54c18b58995718d2695151a945ee232b0f1 (diff) |
Implement a limiter on the device output
This reduces the output volume when the mixed samples extend outside of -1,+1,
to prevent excessive clipping. It can reduce the volume by -80dB in 50ms, and
increase it by +80dB in 1s (it will not go below -80dB or above 0dB).
Diffstat (limited to 'Alc/ALc.c')
-rw-r--r-- | Alc/ALc.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -2192,13 +2192,19 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) device->FOAOut.NumChannels = device->Dry.NumChannels; } - /* Need to delay returning failure until replacement Send arrays have been - * allocated with the appropriate size. - */ device->NumAuxSends = new_sends; TRACE("Max sources: %d (%d + %d), effect slots: %d, sends: %d\n", device->SourcesMax, device->NumMonoSources, device->NumStereoSources, device->AuxiliaryEffectSlotMax, device->NumAuxSends); + + if(GetConfigValueBool(alstr_get_cstr(device->DeviceName), NULL, "output-limiter", 1)) + device->LimiterGain = 1.0f; + else + device->LimiterGain = 0.0f; + + /* Need to delay returning failure until replacement Send arrays have been + * allocated with the appropriate size. + */ update_failed = AL_FALSE; SetMixerFPUMode(&oldMode); if(device->DefaultSlot) @@ -3794,6 +3800,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) device->FOAOut.NumChannels = 0; device->RealOut.Buffer = NULL; device->RealOut.NumChannels = 0; + device->LimiterGain = 1.0f; device->AvgSpeakerDist = 0.0f; ATOMIC_INIT(&device->ContextList, NULL); @@ -4322,6 +4329,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN device->FOAOut.NumChannels = 0; device->RealOut.Buffer = NULL; device->RealOut.NumChannels = 0; + device->LimiterGain = 1.0f; device->AvgSpeakerDist = 0.0f; ATOMIC_INIT(&device->ContextList, NULL); |