Skip to content

Commit

Permalink
Add extra latency to microphone playback to reduce clipping.
Browse files Browse the repository at this point in the history
  • Loading branch information
SaracenOne committed Jul 31, 2018
1 parent d91183b commit 59b703c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion servers/audio/audio_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions servers/audio/audio_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 59b703c

Please sign in to comment.