Skip to content

✨ Write ReplayGain values through a typed API - #28

Merged
simonhull merged 1 commit into
mainfrom
feat/093-replaygain-write
Nov 17, 2026
Merged

simonhull merged 1 commit into
mainfrom
feat/093-replaygain-write

Conversation

@simonhull

Copy link
Copy Markdown
Owner

Plan 093, with design decisions D1–D5 as recommended.

File.SetTrackReplayGain(gain, peak), File.SetAlbumReplayGain(gain, peak), File.RemoveReplayGain() and the new ErrInvalidReplayGain.

  • Scale: gains are in dB on the ReplayGain 2 scale that Audio.ReplayGain reports. A peak of 0 means unknown and removes a stored peak. There are separate methods because ReplayGainInfo's "zero is unknown" rule can't express a 0.00 dB gain.
  • FLAC, Vorbis, MP3, WAV, AIFF, M4A: REPLAYGAIN_* tags formatted as rsgain writes them ("-6.50 dB", "0.988525"). A tag the file already holds keeps its stored spelling; a new one is written in upper case.
  • Opus: R128_TRACK_GAIN/R128_ALBUM_GAIN (Q7.8, gain − 5 dB, rounded half away from zero, refused outside int16). Peaks are not stored. Any REPLAYGAIN_* tags are removed (RFC 7845 §5.2.1). The header output gain is never touched.
  • When the change shows: the methods edit f.Tags immediately. Audio.ReplayGain reports the stored values until the file is reopened.
  • Code layout: the logic lives in internal/replaygain next to the reader, sharing its key constants. No writer changed: the existing raw-key write path handles every format.

Tests:

  • unit tests for formatting, R128 rounding and bounds, and validation;
  • round trips over the whole write corpus (22 files), including Ogg and Opus;
  • stored lower-case spelling kept on MP3, M4A, WAV and AIFF;
  • Opus R128 conversion and removal of REPLAYGAIN_*;
  • set, then a peak of 0, then remove;
  • a TestWriteOracle edit (ffprobe, ffmpeg, flac; opusinfo and ogginfo in CI);
  • ExampleFile_SetTrackReplayGain.

mise run ci passes locally.

@simonhull
simonhull merged commit 54a1d37 into main Nov 17, 2026
6 checks passed
@simonhull
simonhull deleted the feat/093-replaygain-write branch November 17, 2026 01:04
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