Skip to content

fix: keep track INDEX offsets when merging BINs - #202

Open
jayhemnani9910 wants to merge 1 commit into
M5Devs:mainfrom
jayhemnani9910:fix/merge-bins-index-offsets
Open

jayhemnani9910 wants to merge 1 commit into
M5Devs:mainfrom
jayhemnani9910:fix/merge-bins-index-offsets

Conversation

@jayhemnani9910

@jayhemnani9910 jayhemnani9910 commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge BINs writes every INDEX of a track 2 seconds (150 sectors) early when the track has a pregap in its own file, which is how Redump multi-bin dumps with audio tracks are laid out:

FILE "Game (Track 1).bin" BINARY        # 1000 sectors
  TRACK 01 MODE2/2352
    INDEX 01 00:00:00
FILE "Game (Track 2).bin" BINARY        # 300 sectors
  TRACK 02 AUDIO
    INDEX 00 00:00:00
    INDEX 01 00:02:00
FILE "Game (Track 3).bin" BINARY
  TRACK 03 AUDIO
    INDEX 00 00:00:00
    INDEX 01 00:02:00

openrom --merge-bins Game.cue gives track 2 INDEX 00 00:11:25 / INDEX 01 00:13:25 and track 3 00:15:25 / 00:17:25. Track 2's file starts at sector 1000 (00:13:25) in the merged BIN, so the right values are 00:13:25 / 00:15:25 and 00:17:25 / 00:19:25. With the current cue the data track ends 150 sectors early and every audio track starts 2 seconds before its music. The merged BIN itself is correct; only the cue is off.

INDEX times in a cue are relative to the start of their FILE, but mergeBins subtracted each track's INDEX 01 offset before adding the file's position in the merged BIN. This adds the INDEX time as it is.

Tested with a new case in bin_merger_test.dart (a track with INDEX 00 and a 2 second INDEX 01), which fails before the change, the full dart test in core/ (228 passed), and the three-track disc above through the CLI.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected track positions in merged cue sheets when a later track has a pregap. The generated INDEX 00 and INDEX 01 timestamps now account for the preceding track’s length and the pregap, keeping offsets accurate across merged audio files. This improves the reliability of cue sheet timing for multi-track merges.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

mergeBins now adds each parsed index offset to accumulated sectors. A regression test checks the merged offsets for the second track, which has a two-second pregap.

Changes: Track index offset handling

Layer / File(s) Summary
Merge index offsets and verify results
core/lib/src/bin_merger.dart, core/test/bin_merger_test.dart
mergeBins adds each parsed index’s MSF sector offset to accumulated sectors. The regression test checks the merged INDEX 00 and INDEX 01 offsets for the second track.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: clausvalcatd, openhands-agent

Merge Risk: Minimal · up to 62d72

This fixes merged cue-sheet INDEX positions for tracks that have a pregap inside their own file. The change is small and covered by a regression test, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix: keep track INDEX offsets when merging BINs" names the main change. The change stops mergeBins from subtracting each track's INDEX 01 offset before computing merged positions, so track …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix: keep track INDEX offsets when merging BINs" names the main change. The change stops mergeBins from subtracting each track's INDEX 01 offset before computing merged positions, so track INDEX times are kept in the merged cue sheet. The title is specific, short, and matches the PR objective and the regression test for INDEX 00 and INDEX 01 offsets.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 32a356fa-5da9-4266-908d-358da133609d
Commits

Reviewing files that changed from the base of the PR and between e399f8b and 62d72d7.

Files selected for processing: 2

  • core/lib/src/bin_merger.dart
  • core/test/bin_merger_test.dart

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

This branch has not been deployed

No deployments
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.

1 participant