Fix clipping with Opus files without ReplayGain tags when there's less than 5 dB headroom#2526
Open
horazont wants to merge 2 commits into
Open
Fix clipping with Opus files without ReplayGain tags when there's less than 5 dB headroom#2526horazont wants to merge 2 commits into
horazont wants to merge 2 commits into
Conversation
The playback gain in the Opus header is not related to any reference like ReplayGain or EBU R128. It thus does not need converting into the ReplayGain "space". This patch thus removes the 5 dB offset from the fallback path in MPDOpusDecoder::HandleAudio (where the Opus header gain is converted into ReplayGain metadata). Otherwise, an Opus file without replay gain tags and with an output gain of 0 dB would get a gain of 5 dB. This leads to clipping if the audio data has less than 5 dB of headroom. The clipping can be reproduced with something as simple as an amplitude 1.0 sine file. One way to create such a file is via audacity: 1. Generate -> Tone... - Waveform = Sine - Frequency = 440 Hz - Amplitude = 1 - Duration = 1m 2. File -> Export Audio - Channels = mono - Sample rate = 48000 Hz - Encoding = signed 16-bit PCM 3. Run opusenc on the resulting file
Logically, the offset belongs to the conversion of Opus Ebu R128 metadata to the internal ReplayGain structures. Movin the code does not change change the logic at all (as addition is commutative), but by moving the conversion closer to the source of the data and avoiding EBU R128-scaled data as far as possible, I hope to reduce the chance of future logic errors.
8dff7a0 to
8fdd025
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.
Kindly see commit messages for what & why.
Here's some reproducer info:
Reproducer file
The file is also available here for download: https://sotecware.net/files/persistent/mpd-clipping.opus
Reproducer config
cat ~/.config/mpd/mpd.confReplay gain must be enabled and mpd's volume must be at 100% for the effect to be noticeable.
Let me know if you want more of the reproducer info included in the commit message.