Implement get_bar_beats() for AudioStreamSynchronized, fix division by zero

This commit is contained in:
colinator27
2024-11-16 11:41:35 -05:00
parent 5efd124ca1
commit 0a4dd371b7
3 changed files with 21 additions and 3 deletions

View File

@ -691,9 +691,14 @@ void AudioStreamPlaybackInteractive::_queue(int p_to_clip_index, bool p_is_auto_
src_fade_wait = beat_sec - remainder;
} break;
case AudioStreamInteractive::TRANSITION_FROM_TIME_NEXT_BAR: {
float bar_sec = beat_sec * from_state.stream->get_bar_beats();
float remainder = Math::fmod(current_pos, bar_sec);
src_fade_wait = bar_sec - remainder;
if (from_state.stream->get_bar_beats() > 0) {
float bar_sec = beat_sec * from_state.stream->get_bar_beats();
float remainder = Math::fmod(current_pos, bar_sec);
src_fade_wait = bar_sec - remainder;
} else {
// Stream does not have a number of beats per bar - avoid NaN, and play immediately.
src_fade_wait = 0;
}
} break;
case AudioStreamInteractive::TRANSITION_FROM_TIME_END: {
float end = from_state.stream->get_beat_count() > 0 ? float(from_state.stream->get_beat_count() * beat_sec) : from_state.stream->get_length();