Skip to content

Commit

Permalink
Fix #2065 Long sound keyframe can desync
Browse files Browse the repository at this point in the history
  • Loading branch information
JannisX11 committed Apr 20, 2024
1 parent 84d31ca commit e966713
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions js/animations/timeline_animators.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,10 +745,14 @@ class EffectAnimator extends GeneralAnimator {
displayFrame(in_loop) {
if (in_loop && !this.muted.sound) {
this.sound.forEach(kf => {
var diff = kf.time - this.animation.time;
if (diff >= 0 && diff < (1/60) * (Timeline.playback_speed/100)) {
let diff = this.animation.time - kf.time;
if (diff < 0) return;

let media = Timeline.playing_sounds.find(s => s.keyframe_id == kf.uuid);
if (diff >= 0 && diff < (1/60) * (Timeline.playback_speed/100) && !media) {
if (kf.data_points[0].file && !kf.cooldown) {
var media = new Audio(kf.data_points[0].file);
media = new Audio(kf.data_points[0].file);
media.keyframe_id = kf.uuid;
media.playbackRate = Math.clamp(Timeline.playback_speed/100, 0.1, 4.0);
media.volume = Math.clamp(settings.volume.value/100, 0, 1);
media.play().catch(() => {});
Expand All @@ -762,6 +766,14 @@ class EffectAnimator extends GeneralAnimator {
delete kf.cooldown;
}, 400)
}
} else if (diff > 0) {
media = Timeline.playing_sounds.find(s => s.keyframe_id == kf.uuid);
if (Math.abs(media.currentTime - diff) > 0.08) {
console.log('Resyncing sound')
// Resync
media.currentTime = diff;
media.playbackRate = Math.clamp(Timeline.playback_speed/100, 0.1, 4.0);
}
}
})
}
Expand Down Expand Up @@ -834,6 +846,7 @@ class EffectAnimator extends GeneralAnimator {
media.playbackRate = Math.clamp(Timeline.playback_speed/100, 0.1, 4.0);
media.volume = Math.clamp(settings.volume.value/100, 0, 1);
media.currentTime = -diff;
media.keyframe_id = kf.uuid;
media.play().catch(() => {});
Timeline.playing_sounds.push(media);
media.onended = function() {
Expand Down

0 comments on commit e966713

Please sign in to comment.