]> git.sesse.net Git - vlc/commitdiff
equalizer: Optimize calculations of alpha, beta, and gamma constants
authorRonald Wright <logiconcepts819@gmail.com>
Thu, 28 Mar 2013 22:58:47 +0000 (17:58 -0500)
committerJean-Baptiste Kempf <jb@videolan.org>
Fri, 5 Apr 2013 14:31:16 +0000 (16:31 +0200)
It is easy to see that the computation of the alpha constant is slightly
inefficient, as the root value can be close to 1 for the lower frequencies,
which would result in significant roundoff error if this value is subtracted
from 1.  In this patch, the computation of the alpha, beta, and gamma constants
has been simplified and refactored.

Acked-by: Ilkka Ollakka <ileoo@videolan.org>
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/audio_filter/equalizer.c

index 262639585bdd27bb313f5415f3c5e7a55e6dd8ca..623ea4cb88e8f1aa2001160d5b541d1ef146d0aa 100644 (file)
@@ -254,20 +254,15 @@ static void EqzCoeffs( int i_rate, float f_octave_percent,
         {
             float f_theta_1 = ( 2.0 * M_PI * f_freq ) / f_rate;
             float f_theta_2 = f_theta_1 / f_octave_factor;
-            float f_sin     = sin( f_theta_2 ) * 0.5;
+            float f_sin     = sin( f_theta_2 );
             float f_sin_prd = sin( f_theta_2 * f_octave_factor_1 )
                             * sin( f_theta_2 * f_octave_factor_2 );
-            /* The equation from equ-xmms simplifies to something similar to
-             * this when you restrict the domain to all valid frequencies at or
-             * below the Nyquist frequency (the interval 0 <= f_theta_1 <= Pi).
-             * (This result for the root is twice that returned by equ-xmms,
-             * but the more efficient calculations for alpha, beta, and gamma
-             * below compensate for this.) */
-            float f_root    = ( f_sin - f_sin_prd ) / ( f_sin + f_sin_prd );
-
-            p_eqz_config->band[i].f_alpha = ( 1.0 - f_root ) * 0.5;
-            p_eqz_config->band[i].f_beta  = f_root;
-            p_eqz_config->band[i].f_gamma = ( 1.0 + f_root ) * cos( f_theta_1 );
+            float f_sin_hlf = f_sin * 0.5;
+            float f_den     = f_sin_hlf + f_sin_prd;
+
+            p_eqz_config->band[i].f_alpha = f_sin_prd / f_den;
+            p_eqz_config->band[i].f_beta  = ( f_sin_hlf - f_sin_prd ) / f_den;
+            p_eqz_config->band[i].f_gamma = f_sin * cos( f_theta_1 ) / f_den;
         }
         else
         {