[Speex-dev] st->nb_loudness_adapt removal patch

Thorvald Natvig speex at natvig.com
Thu Feb 21 06:57:36 PST 2008


Hi,

I've been looking a bit at the VAD/AGC situation. I noticed a leftover 
variable declaration. The AGC used to use nb_loudness_adapt to count the 
number of frames so far, but it now uses nb_adapt which is shared by all 
the functions. However, it still allocates and updates nb_loudness_adapt.

This patch saves 4 bytes of memory and a partial cycle of CPU power ;)
-------------- next part --------------
Index: libspeex/preprocess.c
===================================================================
--- libspeex/preprocess.c	(revision 14530)
+++ libspeex/preprocess.c	(working copy)
@@ -236,7 +236,6 @@
    float *loudness_weight;   /**< Perceptual loudness curve */
    float  loudness;          /**< Loudness estimate */
    float  agc_gain;          /**< Current AGC gain */
-   int    nb_loudness_adapt; /**< Number of frames used for loudness adaptation so far */
    float  max_gain;          /**< Maximum gain allowed */
    float  max_increase_step; /**< Maximum increase in gain from one frame to another */
    float  max_decrease_step; /**< Maximum decrease in gain from one frame to another */
@@ -516,7 +515,6 @@
    /*st->loudness = pow(AMP_SCALE*st->agc_level,LOUDNESS_EXP);*/
    st->loudness = 1e-15;
    st->agc_gain = 1;
-   st->nb_loudness_adapt = 0;
    st->max_gain = 30;
    st->max_increase_step = exp(0.11513f * 12.*st->frame_size / st->sampling_rate);
    st->max_decrease_step = exp(-0.11513f * 40.*st->frame_size / st->sampling_rate);
@@ -585,7 +583,6 @@
    loudness*2 > pow(st->loudness, 1.0/LOUDNESS_EXP))*/
    if (Pframe>.3f)
    {
-      st->nb_loudness_adapt++;
       /*rate=2.0f*Pframe*Pframe/(1+st->nb_loudness_adapt);*/
       rate = .03*Pframe*Pframe;
       st->loudness = (1-rate)*st->loudness + (rate)*pow(AMP_SCALE*loudness, LOUDNESS_EXP);


More information about the Speex-dev mailing list