shithub: opus

Download patch

ref: e4de8a9c769847110e94a030c5e7d40831da71f0
parent: 744e59ef01f228923f35a504d9552dd1c8d7a23c
author: Jean-Marc Valin <[email protected]>
date: Wed Sep 28 10:23:01 EDT 2011

Fixes a bug that was falsely triggering DTX for 60 ms stereo

There's still a range coder mismatch on the first frame when using FEC.

--- a/silk/enc_API.c
+++ b/silk/enc_API.c
@@ -139,6 +139,8 @@
     silk_encoder *psEnc = ( silk_encoder * )encState;
     opus_int16 buf[ MAX_FRAME_LENGTH_MS * MAX_API_FS_KHZ ];
 
+    psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded = psEnc->state_Fxx[ 1 ].sCmn.nFramesEncoded = 0;
+
     /* Check values in encoder control structure */
     if( ( ret = check_control_input( encControl ) != 0 ) ) {
         silk_assert( 0 );
@@ -358,13 +360,13 @@
                         silk_assert( 0 );
                     }
                 }
-
+                psEnc->state_Fxx[ n ].sCmn.nFramesEncoded++;
                 psEnc->state_Fxx[ n ].sCmn.controlled_since_last_payload = 0;
                 psEnc->state_Fxx[ n ].sCmn.inputBufIx = 0;
             }
 
             /* Insert VAD and FEC flags at beginning of bitstream */
-            if( *nBytesOut > 0 ) {
+            if( *nBytesOut > 0 && psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded == psEnc->state_Fxx[ 0 ].sCmn.nFramesPerPacket) {
                 flags = 0;
                 for( n = 0; n < encControl->nChannelsInternal; n++ ) {
                     for( i = 0; i < psEnc->state_Fxx[ n ].sCmn.nFramesPerPacket; i++ ) {
--- a/silk/fixed/encode_frame_FIX.c
+++ b/silk/fixed/encode_frame_FIX.c
@@ -189,16 +189,8 @@
     /* Finalize payload                     */
     /****************************************/
     psEnc->sCmn.first_frame_after_reset = 0;
-    if( ++psEnc->sCmn.nFramesEncoded >= psEnc->sCmn.nFramesPerPacket ) {
-        /* Payload size */
-        *pnBytesOut = silk_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
-
-        /* Reset the number of frames in payload buffer */
-        psEnc->sCmn.nFramesEncoded = 0;
-    } else {
-        /* No payload this time */
-        *pnBytesOut = 0;
-    }
+    /* Payload size */
+    *pnBytesOut = silk_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
 TOC(ENCODE_FRAME)
 
 #ifdef SAVE_ALL_INTERNAL_DATA
--- a/silk/float/encode_frame_FLP.c
+++ b/silk/float/encode_frame_FLP.c
@@ -186,16 +186,8 @@
     /* Finalize payload                     */
     /****************************************/
     psEnc->sCmn.first_frame_after_reset = 0;
-    if( ++psEnc->sCmn.nFramesEncoded >= psEnc->sCmn.nFramesPerPacket ) {
-        /* Payload size */
-        *pnBytesOut = silk_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
-
-        /* Reset the number of frames in payload buffer */
-        psEnc->sCmn.nFramesEncoded = 0;
-    } else {
-        /* No payload this time */
-        *pnBytesOut = 0;
-    }
+    /* Payload size */
+    *pnBytesOut = silk_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
 TOC(ENCODE_FRAME)
 
 #ifdef SAVE_ALL_INTERNAL_DATA