Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions src/decoder/plugins/OpusDecoderPlugin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,6 @@ IsOpusTags(const ogg_packet &packet) noexcept
return packet.bytes >= 8 && memcmp(packet.packet, "OpusTags", 8) == 0;
}

/**
* Convert an EBU R128 value to ReplayGain.
*/
static constexpr float
EbuR128ToReplayGain(float ebu_r128) noexcept
{
/* add 5dB to compensate for the different reference levels
between ReplayGain (89dB) and EBU R128 (-23 LUFS) */
return ebu_r128 + 5;
}

static bool
mpd_opus_init([[maybe_unused]] const ConfigBlock &block)
{
Expand Down Expand Up @@ -282,11 +271,12 @@ MPDOpusDecoder::HandleTags(const ogg_packet &packet)

if (rgi.IsDefined()) {
/* submit all valid EBU R128 values with output_gain
applied */
applied. conversion from EBU R128 -> ReplayGain
happened in ScanOpusTags already. */
if (rgi.track.IsDefined())
rgi.track.gain += EbuR128ToReplayGain(output_gain);
rgi.track.gain += output_gain;
if (rgi.album.IsDefined())
rgi.album.gain += EbuR128ToReplayGain(output_gain);
rgi.album.gain += output_gain;
client.SubmitReplayGain(&rgi);
submitted_replay_gain = true;
}
Expand All @@ -312,7 +302,7 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet)
gain" value */
ReplayGainInfo rgi;
rgi.Clear();
rgi.track.gain = EbuR128ToReplayGain(output_gain);
rgi.track.gain = output_gain;
client.SubmitReplayGain(&rgi);
submitted_replay_gain = true;
}
Expand Down
15 changes: 13 additions & 2 deletions src/decoder/plugins/OpusTags.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@

using std::string_view_literals::operator""sv;

/**
* Convert an EBU R128 value to ReplayGain.
*/
static constexpr float
EbuR128ToReplayGain(float ebu_r128) noexcept
{
/* add 5dB to compensate for the different reference levels
between ReplayGain (89dB) and EBU R128 (-23 LUFS) */
return ebu_r128 + 5;
}

[[gnu::pure]]
static TagType
ParseOpusTagName(std::string_view name) noexcept
Expand Down Expand Up @@ -47,14 +58,14 @@ ScanOneOpusTag(std::string_view name, std::string_view value,
dB */

if (const auto i = ParseInteger<int_least32_t>(value))
rgi->track.gain = float(*i) / 256.0f;
rgi->track.gain = EbuR128ToReplayGain(float(*i) / 256.0f);
} else if (rgi != nullptr &&
StringIsEqualIgnoreCase(name, "R128_ALBUM_GAIN"sv)) {
/* R128_ALBUM_GAIN is a Q7.8 fixed point number in
dB */

if (const auto i = ParseInteger<int_least32_t>(value))
rgi->album.gain = float(*i) / 256.0f;
rgi->album.gain = EbuR128ToReplayGain(float(*i) / 256.0f);
}

handler.OnPair(name, value);
Expand Down