[vlc-commits] equalizer: Optimize calculations of alpha, beta, and gamma constants
Ronald Wright
git at videolan.org
Fri Apr 5 16:32:02 CEST 2013
vlc | branch: master | Ronald Wright <logiconcepts819 at gmail.com> | Thu Mar 28 17:58:47 2013 -0500| [dff2e068adb49995628e61ce21a6f4ad073726b4] | committer: Jean-Baptiste Kempf
equalizer: Optimize calculations of alpha, beta, and gamma constants
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 at videolan.org>
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=dff2e068adb49995628e61ce21a6f4ad073726b4
---
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 2626395..623ea4c 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 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
{
More information about the vlc-commits
mailing list