From 59b703c4f80253a64a2a13d76fb75ecd45fc3e86 Mon Sep 17 00:00:00 2001 From: Saracen Date: Tue, 31 Jul 2018 04:46:29 +0100 Subject: [PATCH] Add extra latency to microphone playback to reduce clipping. --- servers/audio/audio_stream.cpp | 2 +- servers/audio/audio_stream.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/servers/audio/audio_stream.cpp b/servers/audio/audio_stream.cpp index 618ebd526d5b..eef8aba0c436 100644 --- a/servers/audio/audio_stream.cpp +++ b/servers/audio/audio_stream.cpp @@ -138,7 +138,7 @@ void AudioStreamPlaybackMicrophone::_mix_internal(AudioFrame *p_buffer, int p_fr unsigned int input_size = AudioDriver::get_singleton()->get_input_size(); // p_frames is multipled by two since an AudioFrame is stereo - if ((p_frames * 2) > input_size) { + if ((p_frames + MICROPHONE_PLAYBACK_DELAY * 2) > input_size) { for (int i = 0; i < p_frames; i++) { p_buffer[i] = AudioFrame(0.0f, 0.0f); } diff --git a/servers/audio/audio_stream.h b/servers/audio/audio_stream.h index f0f756129e27..66e1b6ee2fd8 100644 --- a/servers/audio/audio_stream.h +++ b/servers/audio/audio_stream.h @@ -122,6 +122,8 @@ class AudioStreamPlaybackMicrophone : public AudioStreamPlaybackResampled { GDCLASS(AudioStreamPlaybackMicrophone, AudioStreamPlayback) friend class AudioStreamMicrophone; + const int MICROPHONE_PLAYBACK_DELAY = 256; + bool active; unsigned int input_ofs;