summaryrefslogtreecommitdiff
path: root/servers/audio/audio_stream.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'servers/audio/audio_stream.cpp')
-rw-r--r--servers/audio/audio_stream.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/servers/audio/audio_stream.cpp b/servers/audio/audio_stream.cpp
index 12ee98595d..1a6430c499 100644
--- a/servers/audio/audio_stream.cpp
+++ b/servers/audio/audio_stream.cpp
@@ -150,7 +150,7 @@ void AudioStreamPlaybackMicrophone::_mix_internal(AudioFrame *p_buffer, int p_fr
input_ofs = 0;
} else {
for (int i = 0; i < p_frames; i++) {
- if (input_size > input_ofs) {
+ if (input_size > input_ofs && (int)input_ofs < buf.size()) {
float l = (buf[input_ofs++] >> 16) / 32768.f;
if ((int)input_ofs >= buf.size()) {
input_ofs = 0;
@@ -186,6 +186,10 @@ float AudioStreamPlaybackMicrophone::get_stream_sampling_rate() {
void AudioStreamPlaybackMicrophone::start(float p_from_pos) {
+ if (active) {
+ return;
+ }
+
if (!GLOBAL_GET("audio/enable_audio_input")) {
WARN_PRINTS("Need to enable Project settings > Audio > Enable Audio Input option to use capturing.");
return;
@@ -193,15 +197,17 @@ void AudioStreamPlaybackMicrophone::start(float p_from_pos) {
input_ofs = 0;
- AudioDriver::get_singleton()->capture_start();
-
- active = true;
- _begin_resample();
+ if (AudioDriver::get_singleton()->capture_start() == OK) {
+ active = true;
+ _begin_resample();
+ }
}
void AudioStreamPlaybackMicrophone::stop() {
- AudioDriver::get_singleton()->capture_stop();
- active = false;
+ if (active) {
+ AudioDriver::get_singleton()->capture_stop();
+ active = false;
+ }
}
bool AudioStreamPlaybackMicrophone::is_playing() const {