Merge pull request #28469 from godotengine/revert-25974-stream_stop_fade

Revert "Fix AudioStreams::stop possibly causing a small noise"
This commit is contained in:
Juan Linietsky 2019-04-27 12:18:10 -03:00 committed by GitHub
commit e5ed112d69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 64 deletions

View File

@ -37,7 +37,7 @@
void AudioStreamPlayer2D::_mix_audio() {
if (!stream_playback.is_valid() || !active ||
(stream_paused && !stream_fade_out)) {
(stream_paused && !stream_paused_fade_out)) {
return;
}
@ -50,7 +50,7 @@ void AudioStreamPlayer2D::_mix_audio() {
AudioFrame *buffer = mix_buffer.ptrw();
int buffer_size = mix_buffer.size();
if (stream_fade_out) {
if (stream_paused_fade_out) {
// Short fadeout ramp
buffer_size = MIN(buffer_size, 128);
}
@ -84,10 +84,10 @@ void AudioStreamPlayer2D::_mix_audio() {
}
//mix!
AudioFrame target_volume = stream_fade_out ? AudioFrame(0.f, 0.f) : current.vol;
AudioFrame vol_prev = stream_fade_in ? AudioFrame(0.f, 0.f) : prev_outputs[i].vol;
AudioFrame target_volume = stream_paused_fade_out ? AudioFrame(0.f, 0.f) : current.vol;
AudioFrame vol_prev = stream_paused_fade_in ? AudioFrame(0.f, 0.f) : prev_outputs[i].vol;
AudioFrame vol_inc = (target_volume - vol_prev) / float(buffer_size);
AudioFrame vol = stream_fade_in ? AudioFrame(0.f, 0.f) : current.vol;
AudioFrame vol = stream_paused_fade_in ? AudioFrame(0.f, 0.f) : current.vol;
int cc = AudioServer::get_singleton()->get_channel_count();
@ -139,15 +139,9 @@ void AudioStreamPlayer2D::_mix_audio() {
active = false;
}
if (stream_stop) {
active = false;
set_physics_process_internal(false);
setplay = -1;
}
output_ready = false;
stream_fade_in = false;
stream_fade_out = false;
stream_paused_fade_in = false;
stream_paused_fade_out = false;
}
void AudioStreamPlayer2D::_notification(int p_what) {
@ -329,7 +323,6 @@ void AudioStreamPlayer2D::play(float p_from_pos) {
}
if (stream_playback.is_valid()) {
stream_stop = false;
active = true;
setplay = p_from_pos;
output_ready = false;
@ -347,8 +340,9 @@ void AudioStreamPlayer2D::seek(float p_seconds) {
void AudioStreamPlayer2D::stop() {
if (stream_playback.is_valid()) {
stream_stop = true;
stream_fade_out = true;
active = false;
set_physics_process_internal(false);
setplay = -1;
}
}
@ -463,8 +457,8 @@ void AudioStreamPlayer2D::set_stream_paused(bool p_pause) {
if (p_pause != stream_paused) {
stream_paused = p_pause;
stream_fade_in = p_pause ? false : true;
stream_fade_out = p_pause ? true : false;
stream_paused_fade_in = p_pause ? false : true;
stream_paused_fade_out = p_pause ? true : false;
}
}
@ -549,9 +543,8 @@ AudioStreamPlayer2D::AudioStreamPlayer2D() {
output_ready = false;
area_mask = 1;
stream_paused = false;
stream_fade_in = false;
stream_fade_out = false;
stream_stop = false;
stream_paused_fade_in = false;
stream_paused_fade_out = false;
AudioServer::get_singleton()->connect("bus_layout_changed", this, "_bus_layout_changed");
}

View File

@ -73,9 +73,8 @@ private:
float pitch_scale;
bool autoplay;
bool stream_paused;
bool stream_fade_in;
bool stream_fade_out;
bool stream_stop;
bool stream_paused_fade_in;
bool stream_paused_fade_out;
StringName bus;
void _mix_audio();

View File

@ -38,7 +38,7 @@
void AudioStreamPlayer3D::_mix_audio() {
if (!stream_playback.is_valid() || !active ||
(stream_paused && !stream_fade_out)) {
(stream_paused && !stream_paused_fade_out)) {
return;
}
@ -53,7 +53,7 @@ void AudioStreamPlayer3D::_mix_audio() {
AudioFrame *buffer = mix_buffer.ptrw();
int buffer_size = mix_buffer.size();
if (stream_fade_out) {
if (stream_paused_fade_out) {
// Short fadeout ramp
buffer_size = MIN(buffer_size, 128);
}
@ -109,10 +109,10 @@ void AudioStreamPlayer3D::_mix_audio() {
int buffers = AudioServer::get_singleton()->get_channel_count();
for (int k = 0; k < buffers; k++) {
AudioFrame target_volume = stream_fade_out ? AudioFrame(0.f, 0.f) : current.vol[k];
AudioFrame vol_prev = stream_fade_in ? AudioFrame(0.f, 0.f) : prev_outputs[i].vol[k];
AudioFrame target_volume = stream_paused_fade_out ? AudioFrame(0.f, 0.f) : current.vol[k];
AudioFrame vol_prev = stream_paused_fade_in ? AudioFrame(0.f, 0.f) : prev_outputs[i].vol[k];
AudioFrame vol_inc = (target_volume - vol_prev) / float(buffer_size);
AudioFrame vol = stream_fade_in ? AudioFrame(0.f, 0.f) : current.vol[k];
AudioFrame vol = stream_paused_fade_in ? AudioFrame(0.f, 0.f) : current.vol[k];
if (!AudioServer::get_singleton()->thread_has_channel_mix_buffer(current.bus_index, k))
continue; //may have been deleted, will be updated on process
@ -198,15 +198,9 @@ void AudioStreamPlayer3D::_mix_audio() {
active = false;
}
if (stream_stop) {
active = false;
set_physics_process_internal(false);
setplay = -1;
}
output_ready = false;
stream_fade_in = false;
stream_fade_out = false;
stream_paused_fade_in = false;
stream_paused_fade_out = false;
}
float AudioStreamPlayer3D::_get_attenuation_db(float p_distance) const {
@ -663,7 +657,6 @@ float AudioStreamPlayer3D::get_pitch_scale() const {
void AudioStreamPlayer3D::play(float p_from_pos) {
if (stream_playback.is_valid()) {
stream_stop = false;
active = true;
setplay = p_from_pos;
output_ready = false;
@ -681,8 +674,9 @@ void AudioStreamPlayer3D::seek(float p_seconds) {
void AudioStreamPlayer3D::stop() {
if (stream_playback.is_valid()) {
stream_stop = true;
stream_fade_out = true;
active = false;
set_physics_process_internal(false);
setplay = -1;
}
}
@ -878,8 +872,8 @@ void AudioStreamPlayer3D::set_stream_paused(bool p_pause) {
if (p_pause != stream_paused) {
stream_paused = p_pause;
stream_fade_in = stream_paused ? false : true;
stream_fade_out = stream_paused ? true : false;
stream_paused_fade_in = stream_paused ? false : true;
stream_paused_fade_out = stream_paused ? true : false;
}
}
@ -1024,9 +1018,8 @@ AudioStreamPlayer3D::AudioStreamPlayer3D() {
out_of_range_mode = OUT_OF_RANGE_MIX;
doppler_tracking = DOPPLER_TRACKING_DISABLED;
stream_paused = false;
stream_fade_in = false;
stream_fade_out = false;
stream_stop = false;
stream_paused_fade_in = false;
stream_paused_fade_out = false;
velocity_tracker.instance();
AudioServer::get_singleton()->connect("bus_layout_changed", this, "_bus_layout_changed");

View File

@ -110,9 +110,8 @@ private:
float pitch_scale;
bool autoplay;
bool stream_paused;
bool stream_fade_in;
bool stream_fade_out;
bool stream_stop;
bool stream_paused_fade_in;
bool stream_paused_fade_out;
StringName bus;
void _mix_audio();

View File

@ -96,14 +96,10 @@ void AudioStreamPlayer::_mix_audio() {
return;
}
if (stream_fade) {
_mix_internal(true);
stream_fade = false;
if (stream_stop) {
stream_playback->stop();
active = false;
set_process_internal(false);
if (stream_paused) {
if (stream_paused_fade) {
_mix_internal(true);
stream_paused_fade = false;
}
return;
}
@ -209,7 +205,6 @@ void AudioStreamPlayer::play(float p_from_pos) {
if (stream_playback.is_valid()) {
//mix_volume_db = volume_db; do not reset volume ramp here, can cause clicks
stream_stop = false;
setseek = p_from_pos;
active = true;
set_process_internal(true);
@ -226,8 +221,9 @@ void AudioStreamPlayer::seek(float p_seconds) {
void AudioStreamPlayer::stop() {
if (stream_playback.is_valid()) {
stream_stop = true;
stream_fade = true;
stream_playback->stop();
active = false;
set_process_internal(false);
}
}
@ -301,7 +297,7 @@ void AudioStreamPlayer::set_stream_paused(bool p_pause) {
if (p_pause != stream_paused) {
stream_paused = p_pause;
stream_fade = p_pause ? true : false;
stream_paused_fade = p_pause ? true : false;
}
}
@ -397,8 +393,7 @@ AudioStreamPlayer::AudioStreamPlayer() {
setseek = -1;
active = false;
stream_paused = false;
stream_fade = false;
stream_stop = false;
stream_paused_fade = false;
mix_target = MIX_TARGET_STEREO;
AudioServer::get_singleton()->connect("bus_layout_changed", this, "_bus_layout_changed");

View File

@ -58,8 +58,7 @@ private:
float volume_db;
bool autoplay;
bool stream_paused;
bool stream_fade;
bool stream_stop;
bool stream_paused_fade;
StringName bus;
MixTarget mix_target;