Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AudioStreamSynchronized playing/finished state #90205

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions modules/interactive_music/audio_stream_synchronized.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,26 @@ int AudioStreamPlaybackSynchronized::mix(AudioFrame *p_buffer, float p_rate_scal
int todo = p_frames;

bool any_active = false;
int total_mixed = 0;
while (todo) {
int to_mix = MIN(todo, MIX_BUFFER_SIZE);
int max_mixed = 0;

bool first = true;
for (int i = 0; i < stream->stream_count; i++) {
if (playback[i].is_valid() && playback[i]->is_playing()) {
float volume = Math::db_to_linear(stream->audio_stream_volume_db[i]);
if (first) {
playback[i]->mix(p_buffer, p_rate_scale, to_mix);
int mixed = playback[i]->mix(p_buffer, p_rate_scale, to_mix);
max_mixed = MAX(max_mixed, mixed);
for (int j = 0; j < to_mix; j++) {
p_buffer[j] *= volume;
}
first = false;
any_active = true;
} else {
playback[i]->mix(mix_buffer, p_rate_scale, to_mix);
int mixed = playback[i]->mix(mix_buffer, p_rate_scale, to_mix);
max_mixed = MAX(max_mixed, mixed);
for (int j = 0; j < to_mix; j++) {
p_buffer[j] += mix_buffer[j] * volume;
}
Expand All @@ -246,12 +250,13 @@ int AudioStreamPlaybackSynchronized::mix(AudioFrame *p_buffer, float p_rate_scal

p_buffer += to_mix;
todo -= to_mix;
total_mixed += max_mixed;
}

if (!any_active) {
active = false;
}
return p_frames;
return total_mixed;
}

void AudioStreamPlaybackSynchronized::tag_used_streams() {
Expand Down
Loading