Set pulses to zero if we can't meet rate target
authorJean-Marc Valin <jmvalin@jmvalin.ca>
Fri, 3 Jun 2016 19:49:11 +0000 (15:49 -0400)
committerJean-Marc Valin <jmvalin@jmvalin.ca>
Tue, 19 Jul 2016 20:11:50 +0000 (16:11 -0400)
silk/fixed/encode_frame_FIX.c
silk/float/encode_frame_FLP.c

index af5ad86..5bc94c3 100644 (file)
@@ -206,6 +206,9 @@ opus_int silk_encode_frame_FIX(
                 /****************************************/
                 silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFramesEncoded, 0, condCoding );
 
+                if ( iter == maxIter && !found_lower ) {
+                    silk_memcpy( &sRangeEnc_copy2, psRangeEnc, sizeof( ec_enc ) );
+                }
                 /****************************************/
                 /* Encode Excitation Signal             */
                 /****************************************/
@@ -214,6 +217,16 @@ opus_int silk_encode_frame_FIX(
 
                 nBits = ec_tell( psRangeEnc );
 
+                if ( iter == maxIter && !found_lower && nBits > maxBits ) {
+                    silk_memcpy( psRangeEnc, &sRangeEnc_copy2, sizeof( ec_enc ) );
+                    for ( i = 0; i < psEnc->sCmn.frame_length; i++ ) {
+                        psEnc->sCmn.pulses[ i ] = 0;
+                    }
+                    silk_encode_pulses( psRangeEnc, psEnc->sCmn.indices.signalType, psEnc->sCmn.indices.quantOffsetType,
+                        psEnc->sCmn.pulses, psEnc->sCmn.frame_length );
+                    nBits = ec_tell( psRangeEnc );
+                }
+
                 if( useCBR == 0 && iter == 0 && nBits <= maxBits ) {
                     break;
                 }
index b654ddc..59efcb4 100644 (file)
@@ -192,6 +192,9 @@ opus_int silk_encode_frame_FLP(
                 /****************************************/
                 silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFramesEncoded, 0, condCoding );
 
+                if ( iter == maxIter && !found_lower ) {
+                    silk_memcpy( &sRangeEnc_copy2, psRangeEnc, sizeof( ec_enc ) );
+                }
                 /****************************************/
                 /* Encode Excitation Signal             */
                 /****************************************/
@@ -200,6 +203,16 @@ opus_int silk_encode_frame_FLP(
 
                 nBits = ec_tell( psRangeEnc );
 
+                if ( iter == maxIter && !found_lower && nBits > maxBits ) {
+                    silk_memcpy( psRangeEnc, &sRangeEnc_copy2, sizeof( ec_enc ) );
+                    for ( i = 0; i < psEnc->sCmn.frame_length; i++ ) {
+                        psEnc->sCmn.pulses[ i ] = 0;
+                    }
+                    silk_encode_pulses( psRangeEnc, psEnc->sCmn.indices.signalType, psEnc->sCmn.indices.quantOffsetType,
+                        psEnc->sCmn.pulses, psEnc->sCmn.frame_length );
+                    nBits = ec_tell( psRangeEnc );
+                }
+
                 if( useCBR == 0 && iter == 0 && nBits <= maxBits ) {
                     break;
                 }