From 6471d0a57ac36de62a798658b804efa4c5407b7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20T=2E=20Listwon?= Date: Fri, 11 Feb 2022 20:21:26 +0100 Subject: [PATCH] Pass audio samples untouched for pitch_scale around 1.0f (cherry picked from commit c02e979dbf6587e847b401b1b19702e2bc937d5a) --- servers/audio/effects/audio_effect_pitch_shift.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/servers/audio/effects/audio_effect_pitch_shift.cpp b/servers/audio/effects/audio_effect_pitch_shift.cpp index 8ce8f58f75d..fdac74ccd32 100644 --- a/servers/audio/effects/audio_effect_pitch_shift.cpp +++ b/servers/audio/effects/audio_effect_pitch_shift.cpp @@ -292,6 +292,14 @@ void SMBPitchShift::smbFft(float *fftBuffer, long fftFrameSize, long sign) void AudioEffectPitchShiftInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { float sample_rate = AudioServer::get_singleton()->get_mix_rate(); + // For pitch_scale 1.0 it's cheaper to just pass samples without processing them. + if (Math::is_equal_approx(base->pitch_scale, 1.0f)) { + for (int i = 0; i < p_frame_count; i++) { + p_dst_frames[i] = p_src_frames[i]; + } + return; + } + float *in_l = (float *)p_src_frames; float *in_r = in_l + 1;