diff options
Diffstat (limited to 'servers')
-rw-r--r-- | servers/audio/audio_stream.cpp | 16 | ||||
-rw-r--r-- | servers/audio/audio_stream.h | 2 | ||||
-rw-r--r-- | servers/audio_server.h | 5 |
3 files changed, 16 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; diff --git a/servers/audio_server.h b/servers/audio_server.h index f2c3aa0a6f..68a56c38f3 100644 --- a/servers/audio_server.h +++ b/servers/audio_server.h @@ -90,6 +90,7 @@ public: virtual unsigned int get_mix_rate() = 0; virtual Vector<AudioFrame> &get_buffer() = 0; + virtual int get_current_buffer_size() = 0; virtual int get_read_index() = 0; virtual void set_read_index(int p_temp_index) = 0; @@ -138,6 +139,7 @@ public: int read_index = -2048; unsigned int current_capture_index; + unsigned int current_capture_size; Vector<AudioFrame> buffer; unsigned int get_mix_rate() { @@ -148,6 +150,8 @@ public: return buffer; }; + int get_current_buffer_size() { return current_capture_size; } + int get_read_index() { return read_index; } @@ -174,6 +178,7 @@ public: void set_read_index(int p_read_index) { owner->set_read_index(p_read_index); } + int get_current_buffer_size() { return owner->get_current_buffer_size(); } }; MicrophoneDeviceOutputIndirect *default_microphone_device_output; |