Fixes a minor bug introduced in 43a0de4af15
authorKoen Vos <koen.vos@skype.net>
Tue, 25 Oct 2011 05:19:29 +0000 (01:19 -0400)
committerJean-Marc Valin <jmvalin@jmvalin.ca>
Tue, 25 Oct 2011 05:19:29 +0000 (01:19 -0400)
silk/fixed/encode_frame_FIX.c
silk/fixed/pitch_analysis_core_FIX.c
silk/float/encode_frame_FLP.c

index ab1b1a6..34a480c 100644 (file)
@@ -249,13 +249,16 @@ TOC(ENCODE_PULSES)
             }
 
             if( nBits > maxBits ) {
-                found_upper = 1;
-                nBits_upper = nBits;
-                gainMult_upper = gainMult_Q8;
-                gainsID_upper = gainsID;
                 if( found_lower == 0 && iter >= 2 ) {
-                    /* Adjust the quantizer's rate/distortion tradeoff */
+                    /* Adjust the quantizer's rate/distortion tradeoff and discard previous "upper" results */
                     sEncCtrl.Lambda_Q10 = silk_ADD_RSHIFT32( sEncCtrl.Lambda_Q10, sEncCtrl.Lambda_Q10, 1 );
+                    found_upper = 0;
+                    gainsID_upper = -1;
+                } else {
+                    found_upper = 1;
+                    nBits_upper = nBits;
+                    gainMult_upper = gainMult_Q8;
+                    gainsID_upper = gainsID;
                 }
             } else if( nBits < maxBits - 5 ) {
                 found_lower = 1;
@@ -279,7 +282,7 @@ TOC(ENCODE_PULSES)
                 /* Adjust gain according to high-rate rate/distortion curve */
                 opus_int32 gain_factor_Q16;
                 gain_factor_Q16 = silk_log2lin( silk_LSHIFT( nBits - maxBits, 7 ) / psEnc->sCmn.frame_length + SILK_FIX_CONST( 16, 7 ) );
-                gain_factor_Q16 = silk_min_32(gain_factor_Q16, SILK_FIX_CONST( 2, 16 ) );
+                gain_factor_Q16 = silk_min_32( gain_factor_Q16, SILK_FIX_CONST( 2, 16 ) );
                 if( nBits > maxBits ) {
                     gain_factor_Q16 = silk_max_32( gain_factor_Q16, SILK_FIX_CONST( 1.3, 16 ) );
                 }
index bec5fde..e5ea07b 100644 (file)
@@ -326,7 +326,6 @@ opus_int silk_pitch_analysis_core(        /* O    Voicing estimate: 0 voiced, 1
         silk_assert( target_ptr + sf_length_8kHz <= frame_8kHz + frame_length_8kHz );
 
         energy_target = silk_inner_prod_aligned( target_ptr, target_ptr, sf_length_8kHz );
-        /* ToDo: Calculate 1 / energy_target here and save one division inside next for loop*/
         for( j = 0; j < length_d_comp; j++ ) {
             d = d_comp[ j ];
             basis_ptr = target_ptr - d;
index 2330476..635b964 100644 (file)
@@ -243,13 +243,16 @@ TOC(ENCODE_PULSES)
             }
 
             if( nBits > maxBits ) {
-                found_upper = 1;
-                nBits_upper = nBits;
-                gainMult_upper = gainMult_Q8;
-                gainsID_upper = gainsID;
                 if( found_lower == 0 && iter >= 2 ) {
-                    /* Adjust the quantizer's rate/distortion tradeoff */
+                    /* Adjust the quantizer's rate/distortion tradeoff and discard previous "upper" results */
                     sEncCtrl.Lambda *= 1.5f;
+                    found_upper = 0;
+                    gainsID_upper = -1;
+                } else {
+                    found_upper = 1;
+                    nBits_upper = nBits;
+                    gainMult_upper = gainMult_Q8;
+                    gainsID_upper = gainsID;
                 }
             } else if( nBits < maxBits - 5 ) {
                 found_lower = 1;
@@ -273,7 +276,7 @@ TOC(ENCODE_PULSES)
                 /* Adjust gain according to high-rate rate/distortion curve */
                 opus_int32 gain_factor_Q16;
                 gain_factor_Q16 = silk_log2lin( silk_LSHIFT( nBits - maxBits, 7 ) / psEnc->sCmn.frame_length + SILK_FIX_CONST( 16, 7 ) );
-                gain_factor_Q16 = silk_min_32(gain_factor_Q16, SILK_FIX_CONST( 2, 16 ) );
+                gain_factor_Q16 = silk_min_32( gain_factor_Q16, SILK_FIX_CONST( 2, 16 ) );
                 if( nBits > maxBits ) {
                     gain_factor_Q16 = silk_max_32( gain_factor_Q16, SILK_FIX_CONST( 1.3, 16 ) );
                 }