[MPlayer-dev-eng] [BUG?][PATCH] af_equalizer too quiet

Reynaldo H. Verdejo Pinochet reynaldo at opendot.cl
Sat Mar 11 00:16:03 CET 2006


On Tue, Nov 22, 2005 at 08:08:13PM -0800, Corey Hickey wrote:
> I noticed that mplayer -af equalizer reduces the volume significantly.
> Consider this command:
> 
> $ mplayer file.mp3 -af equalizer
> 
> (this corresponds to -af equalizer=0:0:0:0:0:0:0:0:0:0)
> 
> Since the suboptions accept a range from -12 to 12 and 0 is the default,
> I would expect 0 to be the neutral position and to have no effect on the
> audio. Instead, the volume is reduced by a factor of 40 by line 193 of
> af_equalizer.c:
> 
> *out=yt/(4.0*10.0);
> 
> Is that a bug? If so, the attached patch fixes it.
> 
> -Corey

Ok, new patch made with the help of Benjamin Larsson. should take
care of avoiding the atenuation of unamplified signals and clipping 
when filtered output exceds dinamic range. please test, I will
apply this patch soon if no one complains.

Best regards

   Reynaldo
-------------- next part --------------
Index: libaf/af_equalizer.c
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/af_equalizer.c,v
retrieving revision 1.7
diff -a -u -r1.7 af_equalizer.c
--- libaf/af_equalizer.c	8 Mar 2006 13:00:51 -0000	1.7
+++ libaf/af_equalizer.c	10 Mar 2006 22:58:43 -0000
@@ -58,6 +58,7 @@
   float   g[AF_NCH][KM];      	// Gain factor for each channel and band
   int     K; 		   	// Number of used eq bands
   int     channels;        	// Number of channels
+  float   gain_factor;     // applied at output to avoid clipping
 } af_equalizer_t;
 
 // 2nd order Band-pass Filter design
@@ -79,9 +80,11 @@
 
   switch(cmd){
   case AF_CONTROL_REINIT:{
-    int k =0;
+    int k =0, i =0;
     float F[KM] = CF;
     
+    s->gain_factor=0.0;
+
     // Sanity check
     if(!arg) return AF_ERROR;
     
@@ -105,7 +108,25 @@
 
     // Calculate how much this plugin adds to the overall time delay
     af->delay += 2000.0/((float)af->data->rate);
+    
+    // Calculate gain factor to prevent clipping at output
+    for(k=0;k<AF_NCH;k++)
+    {
+        for(i=0;i<KM;i++)
+        {
+            if(s->gain_factor < s->g[k][i]) s->gain_factor=s->g[k][i];
+        }
+    }
 
+    s->gain_factor=log10(s->gain_factor + 1.0) * 20.0;
+	 
+    if(s->gain_factor > 0.0)
+    {
+        s->gain_factor=0.1+(s->gain_factor/12.0);
+    }else{
+        s->gain_factor=1;
+    }
+	
     return af_test_output(af,arg);
   }
   case AF_CONTROL_COMMAND_LINE:{
@@ -190,7 +211,7 @@
 	wq[0] = w;
       }
       // Calculate output 
-      *out=yt;
+      *out=yt*s->gain_factor;
       out+=nch;
     }
   }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20060310/8744af04/attachment.pgp>


More information about the MPlayer-dev-eng mailing list