summaryrefslogtreecommitdiff
path: root/servers/audio
diff options
context:
space:
mode:
authorSaracen <SaracenOne@gmail.com>2018-05-24 21:35:39 +0100
committerSaracen <SaracenOne@gmail.com>2018-07-27 16:50:10 +0100
commit76fd9d215c25874b1c5d33355de0ed983922c32d (patch)
tree6f3e731835a97e2ed0db12fc1de8e463028b34c6 /servers/audio
parentf85062495c3ee477b7ab38f4de435435aedaf375 (diff)
Fixes for microphone clipping and latency (marcelofg55)
Diffstat (limited to 'servers/audio')
-rw-r--r--servers/audio/audio_stream.cpp16
-rw-r--r--servers/audio/audio_stream.h2
2 files changed, 11 insertions, 7 deletions
diff --git a/servers/audio/audio_stream.cpp b/servers/audio/audio_stream.cpp
index 8efcb5bf07..206f1861a3 100644
--- a/servers/audio/audio_stream.cpp
+++ b/servers/audio/audio_stream.cpp
@@ -155,19 +155,22 @@ void AudioStreamPlaybackMicrophone::_mix_internal(AudioFrame *p_buffer, int p_fr
AudioDriver::MicrophoneDeviceOutput *microphone_device_output = reciever->owner;
const Vector<AudioFrame> &source_buffer = microphone_device_output->get_buffer();
+ int current_buffer_size = microphone_device_output->get_current_buffer_size();
- if (microphone_device_output->get_read_index() >= 0) {
- for (int i = 0; i < p_frames; i++) {
- p_buffer[i] = source_buffer[internal_mic_offset + microphone_device_output->get_read_index() + i];
+ for (int i = 0; i < p_frames; i++) {
+ if (current_buffer_size >= internal_mic_offset) {
+ if (internal_mic_offset >= source_buffer.size()) {
+ internal_mic_offset = 0;
+ }
+ p_buffer[i] = source_buffer[internal_mic_offset++];
+ } else {
+ p_buffer[i] = AudioFrame(0.f, 0.f);
}
}
-
- internal_mic_offset += p_frames;
}
void AudioStreamPlaybackMicrophone::mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) {
AudioStreamPlaybackResampled::mix(p_buffer, p_rate_scale, p_frames);
- internal_mic_offset = 0; // Reset
}
float AudioStreamPlaybackMicrophone::get_stream_sampling_rate() {
@@ -175,6 +178,7 @@ float AudioStreamPlaybackMicrophone::get_stream_sampling_rate() {
}
void AudioStreamPlaybackMicrophone::start(float p_from_pos) {
+ internal_mic_offset = 0;
active = true;
// note: can this be called twice?
diff --git a/servers/audio/audio_stream.h b/servers/audio/audio_stream.h
index cb3b999ceb..352cb8c507 100644
--- a/servers/audio/audio_stream.h
+++ b/servers/audio/audio_stream.h
@@ -127,7 +127,7 @@ class AudioStreamPlaybackMicrophone : public AudioStreamPlaybackResampled {
friend class AudioStreamMicrophone;
bool active;
- uint64_t internal_mic_offset;
+ uint32_t internal_mic_offset;
Ref<AudioStreamMicrophone> microphone;
AudioDriver::MicrophoneReciever *reciever;