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

Anatoliy Anischovich git at videolan.org
Sun Jan 4 00:48:35 CET 2015


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

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

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
(cherry picked from commit d5d3b2551d640efe27d5d70084b7235b3932cdfb)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 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 989eca4..838f7fe 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