[vlc-commits] demux: mpc: fix replaygain calculation (fixes #13176)

Anatoliy Anischovich git at videolan.org
Mon Dec 29 22:28:00 CET 2014


vlc | branch: master | Anatoliy Anischovich <lin.aaa.lin at gmail.com> | Mon Dec 29 09:49:57 2014 +0000| [d5d3b2551d640efe27d5d70084b7235b3932cdfb] | committer: Jean-Baptiste Kempf

demux: mpc: fix replaygain calculation (fixes #13176)

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d5d3b2551d640efe27d5d70084b7235b3932cdfb
---

 modules/demux/mpc.c |   20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/modules/demux/mpc.c b/modules/demux/mpc.c
index a450c11..a3b657a 100644
--- a/modules/demux/mpc.c
+++ b/modules/demux/mpc.c
@@ -192,21 +192,33 @@ static int Open( vlc_object_t * p_this )
     fmt.audio.i_bitspersample = 32;
     fmt.i_bitrate = fmt.i_bitrate * fmt.audio.i_channels *
                     fmt.audio.i_bitspersample;
+
+#ifdef HAVE_MPC_MPCDEC_H
+#   define CONVERT_PEAK( mpc_peak ) (pow( 10, (mpc_peak) / 256.0 / 20.0 ) / 32767.0)
+#   define CONVERT_GAIN( mpc_gain ) (MPC_OLD_GAIN_REF - (mpc_gain) / 256.0)
+#else
+#   define CONVERT_PEAK( mpc_peak ) ((mpc_peak) / 32767.0)
+#   define CONVERT_GAIN( mpc_gain ) ((mpc_gain) / 100.0)
+#endif
+
     if( p_sys->info.peak_title > 0 )
     {
         fmt.audio_replay_gain.pb_peak[AUDIO_REPLAY_GAIN_TRACK] = true;
-        fmt.audio_replay_gain.pf_peak[AUDIO_REPLAY_GAIN_TRACK] = (float)p_sys->info.peak_title / 32767.0;
+        fmt.audio_replay_gain.pf_peak[AUDIO_REPLAY_GAIN_TRACK] = (float) CONVERT_PEAK( p_sys->info.peak_title );
         fmt.audio_replay_gain.pb_gain[AUDIO_REPLAY_GAIN_TRACK] = true;
-        fmt.audio_replay_gain.pf_gain[AUDIO_REPLAY_GAIN_TRACK] = (float)p_sys->info.gain_title / 100.0;
+        fmt.audio_replay_gain.pf_gain[AUDIO_REPLAY_GAIN_TRACK] = (float) CONVERT_GAIN( p_sys->info.gain_title );
     }
     if( p_sys->info.peak_album > 0 )
     {
         fmt.audio_replay_gain.pb_peak[AUDIO_REPLAY_GAIN_ALBUM] = true;
-        fmt.audio_replay_gain.pf_peak[AUDIO_REPLAY_GAIN_ALBUM] = (float)p_sys->info.peak_album / 32767.0;
+        fmt.audio_replay_gain.pf_peak[AUDIO_REPLAY_GAIN_ALBUM] = (float) CONVERT_PEAK( p_sys->info.peak_album );
         fmt.audio_replay_gain.pb_gain[AUDIO_REPLAY_GAIN_ALBUM] = true;
-        fmt.audio_replay_gain.pf_gain[AUDIO_REPLAY_GAIN_ALBUM] = (float)p_sys->info.gain_album / 100.0;
+        fmt.audio_replay_gain.pf_gain[AUDIO_REPLAY_GAIN_ALBUM] = (float) CONVERT_GAIN( p_sys->info.gain_album );
     }
 
+#undef CONVERT_GAIN
+#undef CONVERT_PEAK
+
     p_sys->p_es = es_out_Add( p_demux->out, &fmt );
     if( !p_sys->p_es )
         goto error;



More information about the vlc-commits mailing list