diff options
author | Ellen Poe <ellen@ellenhp.me> | 2021-02-18 16:53:26 -0800 |
---|---|---|
committer | Ellen Poe <ellen@ellenhp.me> | 2021-02-18 16:53:26 -0800 |
commit | b6b97b86ab7f29bd9e5f81c6c76819fd6b4dbf10 (patch) | |
tree | aae23f4f822b20c46ee140ad695cd1fadf5922f7 /servers/audio/effects/audio_effect_distortion.cpp | |
parent | a59286f0198c7a3141fc9a8af4d458c7dcfbf653 (diff) |
Prevent distortion filter from introducing NaNs in the audio buffer.
Diffstat (limited to 'servers/audio/effects/audio_effect_distortion.cpp')
-rw-r--r-- | servers/audio/effects/audio_effect_distortion.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/servers/audio/effects/audio_effect_distortion.cpp b/servers/audio/effects/audio_effect_distortion.cpp index b79434e7c2..06d51776a3 100644 --- a/servers/audio/effects/audio_effect_distortion.cpp +++ b/servers/audio/effects/audio_effect_distortion.cpp @@ -58,7 +58,8 @@ void AudioEffectDistortionInstance::process(const AudioFrame *p_src_frames, Audi switch (base->mode) { case AudioEffectDistortion::MODE_CLIP: { - a = powf(a, 1.0001 - drive_f); + float a_sign = a < 0 ? -1.0f : 1.0f; + a = powf(abs(a), 1.0001 - drive_f) * a_sign; if (a > 1.0) { a = 1.0; } else if (a < (-1.0)) { |