[vlcdevel] [PATCH] equalizer: Optimize calculations of alpha, beta, and gamma constants
Ronald Wright
logiconcepts819 at gmail.com
Thu Mar 28 23:58:47 CET 2013
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.

modules/audio_filter/equalizer.c  19 +++++++
1 file changed, 7 insertions(+), 12 deletions()
diff git a/modules/audio_filter/equalizer.c b/modules/audio_filter/equalizer.c
index 7e75583..4cf2196 100644
 a/modules/audio_filter/equalizer.c
+++ b/modules/audio_filter/equalizer.c
@@ 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 equxmms 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 equxmms,
 * 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
{

1.7.10.4
More information about the vlcdevel
mailing list