Skip to content

Fix stale sample-rate detection around track transitions - #225

Open
szb6668 wants to merge 1 commit into
vincentneo:mainfrom
szb6668:fix/track-transition-rate-detection
Open

szb6668 wants to merge 1 commit into
vincentneo:mainfrom
szb6668:fix/track-transition-rate-detection

Conversation

@szb6668

@szb6668 szb6668 commented Sep 20, 2026

Copy link
Copy Markdown

Apple Music could intermittently leave a USB DAC at the wrong sample rate after changing tracks; seeking a second or two restored detection. This change reduces stale and preloaded decoder-log selection around track transitions.

Changes

  • Share one OutputDevices and MediaRemoteController instance between the application delegate and menu.
  • Register the media callback before starting the listener, remove the fixed callback delay, and ignore non-Music or paused playback events.
  • Run bounded detection attempts on track changes, playback resume and seeks. Reject queued results from previous detection generations and apply device changes on the main queue.
  • Parse complete decoder lines independently and retain all candidates. Select the candidate nearest the playback event within a -1.5 to +2 second window, instead of always taking the newest log.
  • Compare against the device's actual nominal sample rate before writing and display the hardware readback. Preserve main's sample-rate-family fallback.

Validation

  • Release build passed using Xcode 27 / macOS 27 with the pinned dependencies resolved locally.
  • Added a runnable regression harness: 11 assertions cover stale/late logs, ordering, delayed logs, missing/invalid data, deterministic ties, per-line parsing and preloaded candidates.
  • Confirmed the installed test build runs a single media listener.
  • The affected user tested the 2.0-based build with an ONIX XP1 over USB on macOS 27 and reported the intermittent mismatch resolved. The submission preserves the newer fallback on main; that integration was build-tested, not separately device-tested.

Limits

This is a bounded temporal heuristic, not an exact association between a decoder and a track: decoder logs do not expose a reliable public track identifier. Prefetches near the event or missing decoder logs can still cause incorrect or absent detection. Broad device compatibility, USB reconnection, rapid shuffle and other transition patterns remain to be tested. It does not enable private logging, seek automatically or claim bit-perfect output.

Related to #159 and #191. The shared-listener change overlaps with #217, #218 and #224; this proposal targets the current main branch and includes the temporal selection and parser regression coverage.

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