1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-08 12:40:44 +00:00

Revert "Exposes capture methods to AudioServer + documentation" #30468

Reverts the following commits:

- c81ec6f26d:
  "Exposes capture methods to AudioServer, variable renames for
  consistency, added documentation."
- 47c558b98a:
  "Expose audio callbacks as signals."
- dabaa11b3c:
  "Fix to make sure the capture buffers are deallocated at shutdown.
  Silences warnings."

Some documentation improvements were kept for pre-existing methods.

See rationale for reverting these changes in #30468.
This commit is contained in:
Rémi Verschelde
2020-01-20 13:11:47 +01:00
parent c3fd1012de
commit 837adb30fd
9 changed files with 82 additions and 157 deletions

View File

@@ -134,31 +134,31 @@ AudioStreamMicrophone::AudioStreamMicrophone() {
void AudioStreamPlaybackMicrophone::_mix_internal(AudioFrame *p_buffer, int p_frames) {
AudioServer::get_singleton()->lock();
AudioDriver::get_singleton()->lock();
PoolVector<int32_t> capture_buffer = AudioServer::get_singleton()->get_capture_buffer();
unsigned int capture_size = AudioServer::get_singleton()->get_capture_size();
int mix_rate = AudioServer::get_singleton()->get_mix_rate();
unsigned int playback_delay = MIN(((50 * mix_rate) / 1000) * 2, capture_buffer.size() >> 1);
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();
unsigned int playback_delay = MIN(((50 * mix_rate) / 1000) * 2, buf.size() >> 1);
#ifdef DEBUG_ENABLED
unsigned int capture_position = AudioServer::get_singleton()->get_capture_position();
unsigned int input_position = AudioDriver::get_singleton()->get_input_position();
#endif
if (playback_delay > capture_size) {
if (playback_delay > input_size) {
for (int i = 0; i < p_frames; i++) {
p_buffer[i] = AudioFrame(0.0f, 0.0f);
}
capture_ofs = 0;
input_ofs = 0;
} else {
for (int i = 0; i < p_frames; i++) {
if (capture_size > capture_ofs && (int)capture_ofs < capture_buffer.size()) {
float l = (capture_buffer[capture_ofs++] >> 16) / 32768.f;
if ((int)capture_ofs >= capture_buffer.size()) {
capture_ofs = 0;
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;
}
float r = (capture_buffer[capture_ofs++] >> 16) / 32768.f;
if ((int)capture_ofs >= capture_buffer.size()) {
capture_ofs = 0;
float r = (buf[input_ofs++] >> 16) / 32768.f;
if ((int)input_ofs >= buf.size()) {
input_ofs = 0;
}
p_buffer[i] = AudioFrame(l, r);
@@ -169,12 +169,12 @@ void AudioStreamPlaybackMicrophone::_mix_internal(AudioFrame *p_buffer, int p_fr
}
#ifdef DEBUG_ENABLED
if (capture_ofs > capture_position && (int)(capture_ofs - capture_position) < (p_frames * 2)) {
print_verbose(String(get_class_name()) + " buffer underrun: capture_position=" + itos(capture_position) + " capture_ofs=" + itos(capture_ofs) + " capture_size=" + itos(capture_size));
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
AudioServer::get_singleton()->unlock();
AudioDriver::get_singleton()->unlock();
}
void AudioStreamPlaybackMicrophone::mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) {
@@ -196,9 +196,9 @@ void AudioStreamPlaybackMicrophone::start(float p_from_pos) {
return;
}
capture_ofs = 0;
input_ofs = 0;
if (AudioServer::get_singleton()->capture_start() == OK) {
if (AudioDriver::get_singleton()->capture_start() == OK) {
active = true;
_begin_resample();
}
@@ -206,7 +206,7 @@ void AudioStreamPlaybackMicrophone::start(float p_from_pos) {
void AudioStreamPlaybackMicrophone::stop() {
if (active) {
AudioServer::get_singleton()->capture_stop();
AudioDriver::get_singleton()->capture_stop();
active = false;
}
}