summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
authorSaracen <SaracenOne@gmail.com>2018-07-31 04:46:29 +0100
committerSaracen <SaracenOne@gmail.com>2018-07-31 04:46:29 +0100
commit59b703c4f80253a64a2a13d76fb75ecd45fc3e86 (patch)
treed97525f9c085f83d274a6657aefa4b99e5680c4d /servers
parentd91183be524c2a2d13d5c40473297cbc713f43da (diff)
Add extra latency to microphone playback to reduce clipping.
Diffstat (limited to 'servers')
-rw-r--r--servers/audio/audio_stream.cpp2
-rw-r--r--servers/audio/audio_stream.h2
2 files changed, 3 insertions, 1 deletions
diff --git a/servers/audio/audio_stream.cpp b/servers/audio/audio_stream.cpp
index 618ebd526d..eef8aba0c4 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 f0f756129e..66e1b6ee2f 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;