Repository navigation
Measure ReplayGain on device when the server sends no track gain - #241
Merged
Merged
Conversation
compute_replaygain existed but nothing called it: downloads only copied the server's track.replay_gain, so untagged tracks (and transcodes that drop the tags) played with no level correction, jumping mid-blend in AutoMix. Now a background worker thread measures the finished file once — the pin's download, or a complete stream-cache entry — and stores the result on the pin rows or the cache entry; Downloads::gain falls back to the cache entry so levelling works for untagged tracks that were never pinned. The scan runs off the playback path on its own thread, gated on the decode feature, injectable for tests. Co-authored-by: GLM-5.3-Flash <opencode-agent[bot]@users.noreply.github.com>
ingoau
force-pushed
the
t3/replaygain-scan-untagged-tracks
branch
from
November 10, 2026 12:07
9ebf5f2 to
24c1343
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #228 (desktop only for now: hocket-android builds hocket-core without the
decodefeature, so the scanner measures nothing on Android).compute_replaygain(a complete EBU R128 scan) existed but nothing called it: downloads only copied the server'strack.replay_gain, so tracks without ReplayGain tags — and transcodes that drop them — played with no level correction, which also made AutoMix jump in level mid-blend.What this does
GainScannertrait in the downloads module; the real implementation callscompute_replaygain(featuredecode), injectable for tests.Downloads::newspawns one thread that takes (server, track) requests from a channel, deduplicated while pending, and exits when theDownloadsis dropped. Nothing is measured on the playback or pin path.fetch_track), and a stream-cache entry is promoted to complete (cache_merge).run_gain_scanskips tracks the server tags or that already have a stored gain, measures the pin's file (else the newest complete cache entry), and stores the result viaset_gain(pin rows) or the newcache_entries.gain_db/peakcolumns (migration0010). A decode failure stores nothing; the startup catch-up retries it on the next launch.Downloads::gain_with_peak(andgainon top of it) reads a download's value, else the newest measured cache entry (original preferred over a transcode), soresolve/media_source_forlevel untagged tracks that were never pinned. Inmedia_source_for, the measured track gain fills what the server left out — a partial tag set (album gain, a bare peak) no longer shadows the on-device scan, and the measured peak reaches the clip clamp.compute_replaygaindoc now match reality.Tests
Five new tests around an injected fake scanner: untagged download measured once (with peak, and resolve picks the gain up); a server-reported gain never triggers a scan; a complete cache entry is measured for a non-pinned track (stored on the cache row, resolve picks it up); an undecodable file stays gainless without rescans; and a fresh process scans files completed while it was away.
cargo test -p hocket-core: 877 passed. Verified with and without thedecodefeature, fmt and clippy clean (only pre-existing warnings remain).Generated by GLM-5.3-Flash in OpenCode