Skip to content

Fix SRT/ASS subtitle sync at non-1x editor playback rates - #13

Merged
Brollyy merged 6 commits into
masterfrom
copilot/fix-srt-ass-subtitles-sync
Mar 25, 2026
Merged

Brollyy merged 6 commits into
masterfrom
copilot/fix-srt-ass-subtitles-sync

Conversation

Copilot AI commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

SRT/ASS subtitles always appeared at 1x wall-clock timing regardless of the editor's playback rate, because JukeboxScript.CurrentBeat advances based on wall-clock time and does not account for AudioSource.pitch.

Changes

  • GetContentBeat(jukebox) — new helper that derives the current beat from AudioSource.time (which always reflects the true audio content position regardless of pitch) via SecondsToBeats(), instead of relying on jukebox.CurrentBeat. Falls back to CurrentBeat when no AudioSource or clip is available.

  • Beat query in Update() — replaced jukebox.CurrentBeat with GetContentBeat(jukebox) so subtitle cue matching uses the actual audio content position at any editor playback rate.

Subtitle cues remain stored as simple beat values, converted once at session start via the original SecondsToBeats() call with no rate adjustments. The fix is entirely in how the current playback position is queried — not in how cue timing is resolved.

Original prompt

This section details on the original issue you should resolve

<issue_title>SRT/ASS subtitles playback rate handling</issue_title>
<issue_description>When playback rate in the editor is not 1, SRT/ASS subs show up using the normal timing, while the playback is slowed/sped up, so they're not in sync</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

When the editor's playback rate was not 1x, SRT/ASS subtitles appeared
at "normal" 1x timing because ResolveCueTiming() called
jukebox.SecondsToBeats(seconds) without accounting for the AudioSource
pitch (which controls the editor's playback rate).

Fix: Add GetJukeboxPlaybackRate() helper that reads AudioSource.pitch
from the jukebox's component and divide the subtitle seconds by this
rate before calling SecondsToBeats(). At 0.5x playback, SecondsToBeats
(10 / 0.5) = SecondsToBeats(20) correctly returns the beat that
CurrentBeat reaches at real-time second 20 (when audio-content second
10 plays at 0.5x speed).

Also fix a secondary bug where karaoke segment beats from SRT/ASS were
not recomputed on session restart (stale from previous session): remove
the !segment.Beat.HasValue guard so seconds-based segments always get
their beat recomputed. JSON-based segments (Beat set, Seconds unset)
are unaffected.

Co-authored-by: Brollyy <12004018+Brollyy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix SRT/ASS subtitles playback rate handling Fix SRT/ASS subtitle sync at non-1x editor playback rates Mar 18, 2026
Copilot AI requested a review from Brollyy March 18, 2026 06:18
@Brollyy

This comment was marked as outdated.

The previous fix read the playback rate once at session start, which
was wrong because the editor allows changing the rate mid-session.

Add _resolvedPlaybackRate field to track which rate was used for the
last ResolveCueTiming() call. In Update(), read the current
AudioSource.pitch each frame; if it differs from _resolvedPlaybackRate,
re-run ResolveCueTiming() with the new rate and reset _activeCue and
the karaoke cache so the display is immediately re-evaluated.

ResolveCueTiming now accepts the pre-read playbackRate parameter to
avoid reading AudioSource.pitch twice per frame.

Co-authored-by: Brollyy <12004018+Brollyy@users.noreply.github.com>

This comment was marked as outdated.

@Brollyy

This comment was marked as outdated.

…ntBeat

JukeboxScript.CurrentBeat advances based on wall-clock time and does not
account for AudioSource.pitch, causing subtitles to drift from the audio
at non-1x playback rates.

Replace CurrentBeat with GetContentBeat() which reads AudioSource.time
(the true content position regardless of pitch) and converts to beats
via SecondsToBeats(). Falls back to CurrentBeat when no AudioSource is
available.

This removes all previous rate-division hacks and keeps cues as simple
beat values converted once at session start.

Co-authored-by: Brollyy <12004018+Brollyy@users.noreply.github.com>

This comment was marked as outdated.

@Brollyy
Brollyy marked this pull request as ready for review March 25, 2026 19:41
@Brollyy

Brollyy commented Mar 25, 2026

Copy link
Copy Markdown
Owner

@codex[agent] review this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6fa7b717b4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread BopSubtitleReader/Core/SubtitleRuntimeController.cs
@Brollyy
Brollyy merged commit fef189f into master Mar 25, 2026
6 of 7 checks passed
@Brollyy
Brollyy deleted the copilot/fix-srt-ass-subtitles-sync branch March 25, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SRT/ASS subtitles playback rate handling

2 participants