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.cpp43
1 files changed, 28 insertions, 15 deletions
diff --git a/servers/audio/audio_stream.cpp b/servers/audio/audio_stream.cpp
index 02a0bed964..1a6430c499 100644
--- a/servers/audio/audio_stream.cpp
+++ b/servers/audio/audio_stream.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -30,6 +30,7 @@
#include "audio_stream.h"
#include "core/os/os.h"
+#include "core/project_settings.h"
//////////////////////////////
@@ -82,8 +83,8 @@ void AudioStreamPlaybackResampled::mix(AudioFrame *p_buffer, float p_rate_scale,
_mix_internal(internal_buffer + 4, INTERNAL_BUFFER_LEN);
} else {
//fill with silence, not playing
- for (int i = 0; i < INTERNAL_BUFFER_LEN; ++i) {
- internal_buffer[i + 4] = AudioFrame(0, 0);
+ for (int j = 0; j < INTERNAL_BUFFER_LEN; ++j) {
+ internal_buffer[j + 4] = AudioFrame(0, 0);
}
}
mix_offset -= (INTERNAL_BUFFER_LEN << FP_BITS);
@@ -137,7 +138,7 @@ void AudioStreamPlaybackMicrophone::_mix_internal(AudioFrame *p_buffer, int p_fr
Vector<int32_t> buf = AudioDriver::get_singleton()->get_input_buffer();
unsigned int input_size = AudioDriver::get_singleton()->get_input_size();
int mix_rate = AudioDriver::get_singleton()->get_mix_rate();
- int playback_delay = MIN(((50 * mix_rate) / 1000) * 2, buf.size() >> 1);
+ unsigned int playback_delay = MIN(((50 * mix_rate) / 1000) * 2, buf.size() >> 1);
#ifdef DEBUG_ENABLED
unsigned int input_position = AudioDriver::get_singleton()->get_input_position();
#endif
@@ -149,13 +150,13 @@ 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 (input_ofs >= buf.size()) {
+ if ((int)input_ofs >= buf.size()) {
input_ofs = 0;
}
float r = (buf[input_ofs++] >> 16) / 32768.f;
- if (input_ofs >= buf.size()) {
+ if ((int)input_ofs >= buf.size()) {
input_ofs = 0;
}
@@ -167,7 +168,7 @@ void AudioStreamPlaybackMicrophone::_mix_internal(AudioFrame *p_buffer, int p_fr
}
#ifdef DEBUG_ENABLED
- if (input_ofs > input_position && (input_ofs - input_position) < (p_frames * 2)) {
+ if (input_ofs > input_position && (int)(input_ofs - input_position) < (p_frames * 2)) {
print_verbose(String(get_class_name()) + " buffer underrun: input_position=" + itos(input_position) + " input_ofs=" + itos(input_ofs) + " input_size=" + itos(input_size));
}
#endif
@@ -184,17 +185,29 @@ float AudioStreamPlaybackMicrophone::get_stream_sampling_rate() {
}
void AudioStreamPlaybackMicrophone::start(float p_from_pos) {
- input_ofs = 0;
- AudioDriver::get_singleton()->capture_start();
+ 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;
+ }
+
+ input_ofs = 0;
- 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 {