[PATCH] Fixing incoherent mono lowpass

Max <[email protected]>
Newsgroups gmane.comp.audio.mp3.lame
Message-ID <[email protected]>
Hi

Regarding the bug I previously reported here :
http://sourceforge.net/tracker/?func=detail&atid=100290&aid=3498760&group_id=290 
<http://sourceforge.net/tracker/?func=detail&atid=100290&aid=3498760&group_id=290>
<http://www.hydrogenaudio.org/forums/index.php?showtopic=93864&st=0&gopid=788612>http://www.hydrogenaudio.org/forums/index.php?showtopic=93864

I wrote a small patch to fix it, it basically adds a third parameter to 
/optimum_bandwidth/ function to inform that the track is in mono/stereo 
and change the lowpass frequency calculation accordingly.

Here is the patch :

diff -rupN lame-3.99.5/libmp3lame/lame.c 
lame-3.99.5-lowpassfix/libmp3lame/lame.c
--- lame-3.99.5/libmp3lame/lame.c    2011-10-18 23:51:20.000000000 +0200
+++ lame-3.99.5-lowpassfix/libmp3lame/lame.c    2012-03-08 
20:33:53.981285364 +0100
@@ -191,11 +191,12 @@ lame_init_params_ppflt(lame_internal_fla


  static void
-optimum_bandwidth(double *const lowerlimit, double *const upperlimit, 
const unsigned bitrate)
+optimum_bandwidth(double *const lowerlimit, double *const upperlimit, 
const unsigned bitrate, const int stereo)
  {
  /*
   *  Input:
   *      bitrate     total bitrate in kbps
+ *      stereo      0 for mono channel calculation, non 0 for stereo
   *
   *   Output:
   *      lowerlimit: best lowpass frequency limit for input filter in Hz
@@ -228,8 +229,10 @@ optimum_bandwidth(double *const lowerlim
          {320, 20500}
      };

-
-    table_index = nearestBitrateFullIndex(bitrate);
+    if(stereo)
+        table_index = nearestBitrateFullIndex(bitrate);
+    else
+        table_index = nearestBitrateFullIndex(bitrate*2);

      (void) freq_map[table_index].bitrate;
      *lowerlimit = freq_map[table_index].lowpass;
@@ -711,11 +714,11 @@ lame_init_params(lame_global_flags * gfp

          switch (gfp->VBR) {
          case vbr_off:{
-                optimum_bandwidth(&lowpass, &highpass, gfp->brate);
+                optimum_bandwidth(&lowpass, &highpass, gfp->brate, 
gfp->mode!=MONO);
                  break;
              }
          case vbr_abr:{
-                optimum_bandwidth(&lowpass, &highpass, 
gfp->VBR_mean_bitrate_kbps);
+                optimum_bandwidth(&lowpass, &highpass, 
gfp->VBR_mean_bitrate_kbps, gfp->mode!=MONO);
                  break;
              }
          case vbr_rh:{
@@ -759,9 +762,6 @@ lame_init_params(lame_global_flags * gfp
              }
          }

-        if (gfp->mode == MONO && (gfp->VBR == vbr_off || gfp->VBR == 
vbr_abr))
-            lowpass *= 1.5;
-
          gfp->lowpassfreq = lowpass;
      }


------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.