From 1db533c8cfe2b76c6914d6ac3d490f5057611b35 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 16 Oct 2020 18:32:30 +0200 Subject: [PATCH] decoder/opus: move formula to EbuR128ToReplayGain() --- src/decoder/plugins/OpusDecoderPlugin.cxx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/decoder/plugins/OpusDecoderPlugin.cxx b/src/decoder/plugins/OpusDecoderPlugin.cxx index 05200e07a..4257b31e5 100644 --- a/src/decoder/plugins/OpusDecoderPlugin.cxx +++ b/src/decoder/plugins/OpusDecoderPlugin.cxx @@ -63,6 +63,17 @@ IsOpusTags(const ogg_packet &packet) noexcept return packet.bytes >= 8 && memcmp(packet.packet, "OpusTags", 8) == 0; } +/** + * Convert an EBU R128 value to ReplayGain. + */ +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; +} + bool mpd_opus_init([[maybe_unused]] const ConfigBlock &block) { @@ -249,13 +260,7 @@ MPDOpusDecoder::HandleTags(const ogg_packet &packet) { ReplayGainInfo rgi; rgi.Clear(); - - /** - * Add 5dB to compensate for the different - * reference levels between ReplayGain (89dB) and EBU R128 (-23 LUFS). - */ - rgi.track.gain = output_gain + 5; - rgi.album.gain = output_gain + 5; + rgi.track.gain = rgi.album.gain = EbuR128ToReplayGain(output_gain); TagBuilder tag_builder; AddTagHandler h(tag_builder);