shithub: opus

Download patch

ref: fc06bda89e40f8adfa1af9cebf869e63ef693bb5
parent: 111b23f648a45d3a034050e579a531d0592dc720
author: Timothy B. Terriberry <[email protected]>
date: Thu Feb 3 09:51:37 EST 2011

Update SILK range coder due to CELT refactoring.

The byte buffer is now part of the range coder struct itself, and
 ec_{enc|dec}_tell have been replaced by a unified ec_tell() with
 no precision parameter.

--- a/src_FIX/SKP_Silk_encode_frame_FIX.c
+++ b/src_FIX/SKP_Silk_encode_frame_FIX.c
@@ -214,7 +214,7 @@
         }
 
         /* Payload length so far */
-        nBytes = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
+        nBytes = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
         *pnBytesOut = nBytes;
 
         /* Reset the number of frames in payload buffer */
@@ -224,7 +224,7 @@
         *pnBytesOut = 0;
 
         /* Payload length so far */
-        nBytes = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
+        nBytes = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
 
         /* Take into account the q signal that isn't in the bitstream yet */
         nBytes += SKP_Silk_pulses_to_bytes( &psEnc->sCmn, 
@@ -305,7 +305,6 @@
     SKP_int     nBytes, nFramesInPayloadBuf;
     SKP_int32   TempGains_Q16[ MAX_NB_SUBFR ];
     SKP_int     typeOffset, LTP_scaleIndex, Rate_only_parameters = 0;
-    ec_byte_buffer range_enc_celt_buf;
 
     /*******************************************/
     /* Control use of inband LBRR              */
@@ -375,8 +374,7 @@
         /* Initialize arithmetic coder          */
         /****************************************/
         if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) {
-            ec_byte_writeinit_buffer( &range_enc_celt_buf, psEnc->sCmn.sRC_LBRR.buffer, MAX_ARITHM_BYTES );
-            ec_enc_init( &psEnc->sCmn.sRC_LBRR.range_enc_celt_state, &range_enc_celt_buf );
+            ec_enc_init( &psEnc->sCmn.sRC_LBRR.range_enc_celt_state, psEnc->sCmn.sRC_LBRR.buffer, MAX_ARITHM_BYTES );
 
             SKP_Silk_range_enc_init( &psEnc->sCmn.sRC_LBRR );
             psEnc->sCmn.nBytesInPayloadBuf = 0;
@@ -417,12 +415,12 @@
             }
 
             /* Payload length so far */
-            nBytes = SKP_RSHIFT( ec_enc_tell( psRangeEnc_LBRR, 0 ) + 7, 3 );
+            nBytes = SKP_RSHIFT( ec_tell( psRangeEnc_LBRR ) + 7, 3 );
 
             /* Check that there is enough space in external output buffer and move data */
             if( *pnBytesOut >= nBytes ) {
                 SKP_int bits_in_stream, mask;
-                bits_in_stream = ec_enc_tell( &psEnc->sCmn.sRC_LBRR.range_enc_celt_state, 0 );
+                bits_in_stream = ec_tell( &psEnc->sCmn.sRC_LBRR.range_enc_celt_state );
                 ec_enc_done( &psEnc->sCmn.sRC_LBRR.range_enc_celt_state );
 
                 /* Fill up any remaining bits in the last byte with 1s */
--- a/src_FLP/SKP_Silk_encode_frame_FLP.c
+++ b/src_FLP/SKP_Silk_encode_frame_FLP.c
@@ -211,7 +211,7 @@
         }
 
         /* Payload length so far */
-        nBytes = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
+        nBytes = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
         *pnBytesOut = nBytes;
 
         /* Reset the number of frames in payload buffer */
@@ -221,7 +221,7 @@
         *pnBytesOut = 0;
 
         /* Payload length so far */
-        nBytes = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
+        nBytes = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
 
         /* Take into account the q signal that isn't in the bitstream yet */
         nBytes += SKP_Silk_pulses_to_bytes( &psEnc->sCmn, 
@@ -337,8 +337,7 @@
         /* Initialize arithmetic coder          */
         /****************************************/
         if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) {
-            ec_byte_writeinit_buffer( &range_enc_celt_buf, psEnc->sCmn.sRC_LBRR.buffer, MAX_ARITHM_BYTES );
-            ec_enc_init( &psEnc->sCmn.sRC_LBRR.range_enc_celt_state, &range_enc_celt_buf );
+            ec_enc_init( &psEnc->sCmn.sRC_LBRR.range_enc_celt_state, psEnc->sCmn.sRC_LBRR.buffer, MAX_ARITHM_BYTES );
 
             SKP_Silk_range_enc_init( &psEnc->sCmn.sRC_LBRR );
             psEnc->sCmn.nBytesInPayloadBuf = 0;
@@ -377,12 +376,12 @@
             }
 
             /* Payload length so far */
-            nBytes = SKP_RSHIFT( ec_enc_tell( psRangeEnc_LBRR, 0 ) + 7, 3 );
+            nBytes = SKP_RSHIFT( ec_tell( psRangeEnc_LBRR ) + 7, 3 );
 
             /* Check that there is enough space in external output buffer and move data */
             if( *pnBytesOut >= nBytes ) {
                 SKP_int bits_in_stream, mask;
-                bits_in_stream = ec_enc_tell( &psEnc->sCmn.sRC_LBRR.range_enc_celt_state, 0 );
+                bits_in_stream = ec_tell( &psEnc->sCmn.sRC_LBRR.range_enc_celt_state );
                 ec_enc_done( &psEnc->sCmn.sRC_LBRR.range_enc_celt_state );
 
                 /* Fill up any remaining bits in the last byte with 1s */
--- a/src_common/SKP_Silk_decode_frame.c
+++ b/src_common/SKP_Silk_decode_frame.c
@@ -74,7 +74,7 @@
         SKP_Silk_decode_parameters( psDec, &sDecCtrl, psRangeDec, Pulses );
 TOC(decode_params)
 
-        *decBytes = psRangeDec->buf->storage - psDec->nBytesLeft;
+        *decBytes = psRangeDec->storage - psDec->nBytesLeft;
         psDec->nFramesDecoded++;
 
         /* Update length. Sampling frequency may have changed */
--- a/src_common/SKP_Silk_decode_indices.c
+++ b/src_common/SKP_Silk_decode_indices.c
@@ -149,6 +149,6 @@
     /****************************************/
     /* Get number of bytes used so far      */
     /****************************************/
-    nBytesUsed = SKP_RSHIFT( ec_dec_tell( psRangeDec, 0 ) + 7, 3 );
-    psDec->nBytesLeft = psRangeDec->buf->storage - nBytesUsed;
+    nBytesUsed = SKP_RSHIFT( ec_tell( psRangeDec ) + 7, 3 );
+    psDec->nBytesLeft = psRangeDec->storage - nBytesUsed;
 }
--- a/src_common/SKP_Silk_decode_parameters.c
+++ b/src_common/SKP_Silk_decode_parameters.c
@@ -138,6 +138,6 @@
     /****************************************/
     /* get number of bytes used so far      */
     /****************************************/
-    nBytesUsed = SKP_RSHIFT( ec_dec_tell( psRangeDec, 0 ) + 7, 3 );
-    psDec->nBytesLeft = psRangeDec->buf->storage - nBytesUsed;
+    nBytesUsed = SKP_RSHIFT( ec_tell( psRangeDec ) + 7, 3 );
+    psDec->nBytesLeft = psRangeDec->storage - nBytesUsed;
 }
--- a/src_common/SKP_Silk_encode_indices.c
+++ b/src_common/SKP_Silk_encode_indices.c
@@ -62,7 +62,7 @@
     /* Encode gains */
     /****************/
 #ifdef SAVE_ALL_INTERNAL_DATA
-    nBytes_before = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
+    nBytes_before = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
 #endif
     /* first subframe */
     if( psEncC->nFramesInPayloadBuf == 0 ) {
@@ -80,7 +80,7 @@
     }
 
 #ifdef SAVE_ALL_INTERNAL_DATA
-    nBytes_after = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
+    nBytes_after = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
     nBytes_after -= nBytes_before; // bytes just added
     DEBUG_STORE_DATA( nBytes_gains.dat, &nBytes_after, sizeof( SKP_int ) );
 #endif
@@ -89,7 +89,7 @@
     /* Encode NLSFs */
     /****************/
 #ifdef SAVE_ALL_INTERNAL_DATA
-    nBytes_before = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
+    nBytes_before = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
 #endif
     /* Range encoding of the NLSF path */
     psNLSF_CB = psEncC->psNLSF_CB[ 1 - (psEncCtrlC->signalType>>1) ];
@@ -105,7 +105,7 @@
 
 #ifdef SAVE_ALL_INTERNAL_DATA
     DEBUG_STORE_DATA( lsf_interpol.dat, &psEncCtrlC->NLSFInterpCoef_Q2, sizeof(int) );
-    nBytes_after = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
+    nBytes_after = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
     nBytes_after -= nBytes_before; // bytes just added
     DEBUG_STORE_DATA( nBytes_LSF.dat, &nBytes_after, sizeof( SKP_int ) );
 #endif
@@ -115,7 +115,7 @@
         /* Encode pitch lags */
         /*********************/
 #ifdef SAVE_ALL_INTERNAL_DATA
-        nBytes_before = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
+        nBytes_before = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
 #endif
         /* lag index */
         encode_absolute_lagIndex = 1;
@@ -144,12 +144,12 @@
         psEncC->prev_lagIndex = psEncCtrlC->lagIndex;
 
 #ifdef SAVE_ALL_INTERNAL_DATA
-        nBytes_after = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
+        nBytes_after = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
         nBytes_lagIndex = nBytes_after - nBytes_before; // bytes just added
 #endif
 
 #ifdef SAVE_ALL_INTERNAL_DATA
-        nBytes_before = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
+        nBytes_before = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
 #endif
         /* Countour index */
         SKP_assert( ( psEncCtrlC->contourIndex < 34 && psEncC->fs_kHz  > 8 && psEncC->nb_subfr == 4 ) ||
@@ -158,7 +158,7 @@
                     ( psEncCtrlC->contourIndex <  3 && psEncC->fs_kHz == 8 && psEncC->nb_subfr == 2 ) );
         ec_enc_icdf( psRangeEnc, psEncCtrlC->contourIndex, psEncC->pitch_contour_iCDF, 8 );
 #ifdef SAVE_ALL_INTERNAL_DATA
-        nBytes_after = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
+        nBytes_after = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
         nBytes_contourIndex = nBytes_after - nBytes_before; // bytes just added
 #endif
 
@@ -166,7 +166,7 @@
         /* Encode LTP gains */
         /********************/
 #ifdef SAVE_ALL_INTERNAL_DATA
-        nBytes_before = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
+        nBytes_before = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
 #endif
 
         /* PERIndex value */
@@ -182,7 +182,7 @@
         /**********************/
         ec_enc_icdf( psRangeEnc, psEncCtrlC->LTP_scaleIndex, SKP_Silk_LTPscale_iCDF, 8 );
 #ifdef SAVE_ALL_INTERNAL_DATA
-        nBytes_after = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
+        nBytes_after = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
         nBytes_LTP = nBytes_after - nBytes_before; // bytes just added
 #endif
     }
@@ -199,7 +199,7 @@
 #endif
 
 #ifdef SAVE_ALL_INTERNAL_DATA
-    nBytes_before = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
+    nBytes_before = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
 #endif
 
     /***************/
--- a/test/Decoder.c
+++ b/test/Decoder.c
@@ -109,7 +109,6 @@
     float     loss_prob;
     SKP_int32 frames, lost, quiet;
     SKP_SILK_SDK_DecControlStruct DecControl;
-    ec_byte_buffer range_dec_celt_buf;
     ec_dec         range_dec_celt_state;
 
     if( argc < 3 ) {
@@ -225,8 +224,7 @@
         }
 
         /* Initialize range decoder state */
-        ec_byte_writeinit_buffer( &range_dec_celt_buf, payloadEnd, nBytes );
-        ec_dec_init( &range_dec_celt_state, &range_dec_celt_buf );
+        ec_dec_init( &range_dec_celt_state, payloadEnd, nBytes );
 
         /* Simulate losses */
         if( ( (float)rand() / (float)RAND_MAX >= loss_prob / 100 ) && counter > 0 ) {
--- a/test/Encoder.c
+++ b/test/Encoder.c
@@ -108,7 +108,6 @@
     SKP_int16 nBytes_LE;
 #endif
     SKP_uint8      range_buf[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES ];
-    ec_byte_buffer range_enc_celt_buf;
     ec_enc         range_enc_celt_state;
 
     /* default settings */
@@ -239,8 +238,7 @@
     while( 1 ) {
         if( smplsSinceLastPacket == 0 ) {
             /* Init range coder */
-            ec_byte_writeinit_buffer( &range_enc_celt_buf, range_buf, MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES );
-            ec_enc_init( &range_enc_celt_state, &range_enc_celt_buf );
+            ec_enc_init( &range_enc_celt_state, range_buf, MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES );
         }
 
         /* Read input from file */