decoder/mpcdec: merge duplicate code

This commit is contained in:
Max Kellermann 2019-09-13 19:45:26 +02:00
parent 496f88653d
commit b6243a9945

View File

@ -137,6 +137,15 @@ mpc_to_mpd_buffer(MpcdecSampleTraits::pointer_type dest,
*dest++ = mpc_to_mpd_sample(*src++);
}
static constexpr ReplayGainTuple
ImportMpcdecReplayGain(mpc_uint16_t gain, mpc_uint16_t peak) noexcept
{
auto t = ReplayGainTuple::Undefined();
t.gain = MPC_OLD_GAIN_REF - (gain / 256.);
t.peak = pow(10, peak / 256. / 20) / 32767;
return t;
}
static void
mpcdec_decode(DecoderClient &client, InputStream &is)
{
@ -169,10 +178,8 @@ mpcdec_decode(DecoderClient &client, InputStream &is)
ReplayGainInfo rgi;
rgi.Clear();
rgi.album.gain = MPC_OLD_GAIN_REF - (info.gain_album / 256.);
rgi.album.peak = pow(10, info.peak_album / 256. / 20) / 32767;
rgi.track.gain = MPC_OLD_GAIN_REF - (info.gain_title / 256.);
rgi.track.peak = pow(10, info.peak_title / 256. / 20) / 32767;
rgi.album = ImportMpcdecReplayGain(info.gain_album, info.peak_album);
rgi.track = ImportMpcdecReplayGain(info.gain_title, info.peak_title);
client.SubmitReplayGain(&rgi);