opusenc: Improve FLAC ReplayGain support.
The initial implementation for reading FLAC ReplayGain data was written based on the then (2012) current Ogg Opus draft. That version of the standard did not include an R128_ALBUM_GAIN
tag, and thus the implementation did the following:
- Set the header's output gain to the R128 adjusted album gain.
- Set the
R128_TRACK_GAIN
tag relative to the album loudness.
This produces acceptable results, and was likely the best that could be done given the lack of supported tags. However, the version of the standard that got published (RFC 7845, in 2016) did include an R128_ALBUM_GAIN
tag. This commit implements support for that tag, and does not by default set the header gain, which is more in line with other formats. An option was added to support this, so that the functionality is not completely removed.
I've structured the new command line argument (--output-gain
) to allow for potential future values, though I can make it a simple on/off switch if this isn't desired. The potential other values I had in mind were:
-
album
: Uses the album gain if present, does not fallback to track gain if absent -
track
: Opposite ofalbum
-
N
: An arbitrary gain to be set, in dB.
I didn't implement this functionality yet since I wasn't sure if it would be out of scope for this tool. If it isn't, I would like to implement this in either this MR or a subsequent one. Similarly, I would like to add a --target-loudness
option; --output-gain=replaygain
currently results in a file that plays at -23 LUFS, which contrasts from the more common -18 LUFS that may be desirable to someone who would use the --output-gain
option. The R128 tags would still be based on the -23 LUFS level, but the header gain would be set such that it meets the user's desired loudness.