shithub: opus

Download patch

ref: f7479653be7649267fd9e2096adf47862cea1a95
parent: 20832a6c95a84e18da936228e4b15823d8b89728
author: Jean-Marc Valin <[email protected]>
date: Thu Mar 17 12:55:42 EDT 2011

Fixes a bug in the handling of the first packet after DTX

We were using the last frame's DTX decision at the beginning
of the encoding

--- a/src_FLP/SKP_Silk_encode_frame_FLP.c
+++ b/src_FLP/SKP_Silk_encode_frame_FLP.c
@@ -47,24 +47,6 @@
 
 TIC(ENCODE_FRAME)
 
-    if( psEnc->sCmn.nFramesAnalyzed == 0 && !psEnc->sCmn.prefillFlag && !( psEnc->sCmn.useDTX && psEnc->sCmn.inDTX ) ) {
-        /* Create space at start of payload for VAD and FEC flags */
-        SKP_uint8 iCDF[ 2 ] = { 0, 0 };
-        iCDF[ 0 ] = 256 - SKP_RSHIFT( 256, psEnc->sCmn.nFramesPerPacket + 1 );
-        ec_enc_icdf( psRangeEnc, 0, iCDF, 8 );
-
-        /* Encode any LBRR data from previous packet */
-        SKP_Silk_LBRR_embed( &psEnc->sCmn, psRangeEnc );
-
-        /* Reduce coding SNR depending on how many bits used by LBRR */
-        nBits = ec_tell( psRangeEnc );
-        psEnc->inBandFEC_SNR_comp = ( 6.0f * nBits ) / 
-            ( psEnc->sCmn.nFramesPerPacket * psEnc->sCmn.frame_length );
-
-        /* Reset LBRR flags */
-        SKP_memset( psEnc->sCmn.LBRR_flags, 0, sizeof( psEnc->sCmn.LBRR_flags ) );
-    }
-
     psEnc->sCmn.indices.Seed = psEnc->sCmn.frameCounter++ & 3;
 
     /**************************************************************/
@@ -101,6 +83,25 @@
         psEnc->sCmn.indices.signalType = TYPE_UNVOICED;
         psEnc->sCmn.VAD_flags[ psEnc->sCmn.nFramesAnalyzed ] = 1;
     }
+
+    if( psEnc->sCmn.nFramesAnalyzed == 0 && !psEnc->sCmn.prefillFlag && !( psEnc->sCmn.useDTX && psEnc->sCmn.inDTX ) ) {
+        /* Create space at start of payload for VAD and FEC flags */
+        SKP_uint8 iCDF[ 2 ] = { 0, 0 };
+        iCDF[ 0 ] = 256 - SKP_RSHIFT( 256, psEnc->sCmn.nFramesPerPacket + 1 );
+        ec_enc_icdf( psRangeEnc, 0, iCDF, 8 );
+
+        /* Encode any LBRR data from previous packet */
+        SKP_Silk_LBRR_embed( &psEnc->sCmn, psRangeEnc );
+
+        /* Reduce coding SNR depending on how many bits used by LBRR */
+        nBits = ec_tell( psRangeEnc );
+        psEnc->inBandFEC_SNR_comp = ( 6.0f * nBits ) /
+                ( psEnc->sCmn.nFramesPerPacket * psEnc->sCmn.frame_length );
+
+        /* Reset LBRR flags */
+        SKP_memset( psEnc->sCmn.LBRR_flags, 0, sizeof( psEnc->sCmn.LBRR_flags ) );
+    }
+
 
     /*******************************************/
     /* High-pass filtering of the input signal */