Przeglądaj źródła

Prevent distortion filter from introducing NaNs in the audio buffer.

(cherry picked from commit b6b97b86ab7f29bd9e5f81c6c76819fd6b4dbf10)
Ellen Poe 4 lat temu
rodzic
commit
9178f694ea

+ 2 - 2
servers/audio/effects/audio_effect_distortion.cpp

@@ -61,8 +61,8 @@ void AudioEffectDistortionInstance::process(const AudioFrame *p_src_frames, Audi
 		switch (base->mode) {
 		switch (base->mode) {
 
 
 			case AudioEffectDistortion::MODE_CLIP: {
 			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)
 				if (a > 1.0)
 					a = 1.0;
 					a = 1.0;
 				else if (a < (-1.0))
 				else if (a < (-1.0))