Added an interface to encode/decode from a CELT range coder
authorKoen Vos <koen.vos@skype.net>
Sun, 4 Jul 2010 13:14:17 +0000 (09:14 -0400)
committerJean-Marc Valin <jean-marc.valin@usherbrooke.ca>
Sun, 4 Jul 2010 13:14:17 +0000 (09:14 -0400)
26 files changed:
interface/SKP_Silk_SDK_API.h
src_FLP/SKP_Silk_encode_frame_FLP.c
src_FLP/SKP_Silk_main_FLP.h
src_common/SKP_Silk_code_signs.c
src_common/SKP_Silk_dec_SDK_API.c
src_common/SKP_Silk_decode_frame.c
src_common/SKP_Silk_decode_indices.c [moved from src_common/SKP_Silk_decode_indices_v4.c with 72% similarity]
src_common/SKP_Silk_decode_parameters.c [moved from src_common/SKP_Silk_decode_parameters_v4.c with 90% similarity]
src_common/SKP_Silk_decode_pulses.c
src_common/SKP_Silk_enc_API.c
src_common/SKP_Silk_encode_parameters.c [moved from src_common/SKP_Silk_encode_parameters_v4.c with 59% similarity]
src_common/SKP_Silk_encode_pulses.c
src_common/SKP_Silk_main.h
src_common/SKP_Silk_range_coder.c
src_common/SKP_Silk_shell_coder.c
src_common/SKP_Silk_structs.h
src_common/SKP_Silk_tables.h
src_common/SKP_Silk_tables_other.c
src_common/Silk_CommonFLP.vcproj
test/Dec_SDK.vcproj
test/Dec_SDK.vcproj.SKYPE-KOEN.koen.user [deleted file]
test/Decoder.c
test/Enc_SDK.vcproj
test/Enc_SDK.vcproj.SKYPE-KOEN.koen.user [deleted file]
test/Encoder.c
test/SignalCompare.vcproj.SKYPE-KOEN.koen.user [deleted file]

index e266780..e112526 100644 (file)
@@ -31,6 +31,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "SKP_Silk_control.h"\r
 #include "SKP_Silk_typedef.h"\r
 #include "SKP_Silk_errors.h"\r
+#include "entenc.h"\r
+#include "entdec.h"\r
 \r
 #ifdef __cplusplus\r
 extern "C"\r
@@ -84,8 +86,8 @@ SKP_int SKP_Silk_SDK_Encode(                            /* O:   Returns error co
     const SKP_SILK_SDK_EncControlStruct *encControl,    /* I:   Control status                                  */\r
     const SKP_int16                     *samplesIn,     /* I:   Speech sample input vector                      */\r
     SKP_int                             nSamplesIn,     /* I:   Number of samples in input vector               */\r
-    SKP_uint8                           *outData,       /* O:   Encoded output vector                           */\r
-    SKP_int16                           *nBytesOut      /* I/O: Number of bytes in outData (input: Max bytes)   */\r
+    ec_enc                              *psRangeEnc,    /* I/O  Compressor data structure                       */\r
+    SKP_int16                           *nBytesOut      /* I/O: Number of bytes in payload (input: Max bytes)   */\r
 );\r
 \r
 /****************************************/\r
@@ -113,7 +115,7 @@ SKP_int SKP_Silk_SDK_Decode(                            /* O:   Returns error co
     void*                               decState,       /* I/O: State                                           */\r
     SKP_SILK_SDK_DecControlStruct*      decControl,     /* I/O: Control Structure                               */\r
     SKP_int                             lostFlag,       /* I:   0: no loss, 1 loss                              */\r
-    const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */\r
+    ec_dec                              *psRangeDec,    /* I/O  Compressor data structure                       */\r
     const SKP_int                       nBytesIn,       /* I:   Number of input bytes                           */\r
     SKP_int16                           *samplesOut,    /* O:   Decoded output speech vector                    */\r
     SKP_int16                           *nSamplesOut    /* I/O: Number of samples (vector/decoded)              */\r
@@ -134,7 +136,7 @@ void SKP_Silk_SDK_search_for_LBRR(
 /* Get table of contents for a packet */\r
 /**************************************/\r
 void SKP_Silk_SDK_get_TOC(\r
-    const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */\r
+    ec_dec                              *psRangeDec,    /* I/O  Compressor data structure                   */\r
     const SKP_int16                     nBytesIn,       /* I:   Number of input bytes                           */\r
     SKP_Silk_TOC_struct                 *Silk_TOC       /* O:   Table of contents                               */\r
 );\r
index 8fb954a..62e7612 100644 (file)
@@ -6,9 +6,9 @@
 /****************/\r
 SKP_int SKP_Silk_encode_frame_FLP( \r
     SKP_Silk_encoder_state_FLP      *psEnc,             /* I/O  Encoder state FLP                       */\r
-          SKP_uint8                 *pCode,             /* O    Payload                                 */\r
-          SKP_int16                 *pnBytesOut,        /* I/O  Number of payload bytes;                */\r
+    SKP_int16                       *pnBytesOut,        /* I/O  Number of payload bytes;                */\r
                                                         /*      input: max length; output: used         */\r
+    ec_enc                          *psRangeEnc,        /* I/O  compressor data structure                */\r
     const SKP_int16                 *pIn                /* I    Input speech frame                      */\r
 )\r
 {\r
@@ -25,8 +25,6 @@ SKP_int SKP_Silk_encode_frame_FLP(
     SKP_uint8   LBRRpayload[ MAX_ARITHM_BYTES ];\r
     SKP_int16   nBytesLBRR;\r
 \r
-    ec_byte_buffer range_enc_celt_buf;\r
-\r
     const SKP_uint16 *FrameTermination_CDF;\r
 \r
 TIC(ENCODE_FRAME)\r
@@ -117,7 +115,7 @@ TOC(PROCESS_GAINS)
     /****************************************/\r
     nBytesLBRR = MAX_ARITHM_BYTES;\r
 TIC(LBRR)\r
-    SKP_Silk_LBRR_encode_FLP( psEnc, &sEncCtrl, LBRRpayload, &nBytesLBRR, xfw );\r
+    //SKP_Silk_LBRR_encode_FLP( psEnc, &sEncCtrl, LBRRpayload, &nBytesLBRR, xfw );\r
 TOC(LBRR)\r
 \r
     /*****************************************/\r
@@ -148,13 +146,9 @@ TOC(NSQ)
     }\r
 \r
     /****************************************/\r
-    /* Initialize arithmetic coder          */\r
+    /* Initialize range coder               */\r
     /****************************************/\r
     if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) {\r
-        ec_byte_writeinit_buffer( &range_enc_celt_buf, psEnc->sCmn.sRC.buffer, MAX_ARITHM_BYTES );\r
-        ec_enc_init( &psEnc->sCmn.sRC.range_enc_celt_state, &range_enc_celt_buf );\r
-\r
-        SKP_Silk_range_enc_init( &psEnc->sCmn.sRC );\r
         psEnc->sCmn.nBytesInPayloadBuf = 0;\r
     }\r
 \r
@@ -162,8 +156,8 @@ TOC(NSQ)
     /* Encode Parameters                    */\r
     /****************************************/\r
 TIC(ENCODE_PARAMS)\r
-    SKP_Silk_encode_parameters_v4( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sCmn.sRC );\r
-    FrameTermination_CDF = SKP_Silk_FrameTermination_v4_CDF;\r
+    SKP_Silk_encode_parameters( &psEnc->sCmn, &sEncCtrl.sCmn, psRangeEnc );\r
+    FrameTermination_CDF = SKP_Silk_FrameTermination_CDF;\r
 TOC(ENCODE_PARAMS)\r
 \r
     /****************************************/\r
@@ -178,7 +172,7 @@ TOC(ENCODE_PARAMS)
     psEnc->sCmn.prevLag      = sEncCtrl.sCmn.pitchL[ psEnc->sCmn.nb_subfr - 1 ];\r
     psEnc->sCmn.first_frame_after_reset = 0;\r
 \r
-    if( psEnc->sCmn.sRC.error ) {\r
+    if( 0 ) { //psEnc->sCmn.sRC.error ) {\r
         /* Encoder returned error: Clear payload buffer */\r
         psEnc->sCmn.nFramesInPayloadBuf = 0;\r
     } else {\r
@@ -203,21 +197,23 @@ TOC(ENCODE_PARAMS)
         }\r
 \r
         /* Add the frame termination info to stream */\r
-        SKP_Silk_range_encoder( &psEnc->sCmn.sRC, frame_terminator, FrameTermination_CDF );\r
+        ec_encode_bin( psRangeEnc, FrameTermination_CDF[ frame_terminator ], \r
+            FrameTermination_CDF[ frame_terminator + 1 ], 16 );\r
         for( i = 0; i < psEnc->sCmn.nFramesInPayloadBuf; i++ ) {\r
-            SKP_Silk_encode_pulses( &psEnc->sCmn.sRC, psEnc->sCmn.sigtype[ i ], psEnc->sCmn.QuantOffsetType[ i ], \r
+            SKP_Silk_encode_pulses( psRangeEnc, psEnc->sCmn.sigtype[ i ], psEnc->sCmn.QuantOffsetType[ i ], \r
                 &psEnc->sCmn.q[ i * psEnc->sCmn.frame_length ], psEnc->sCmn.frame_length );\r
         }\r
 \r
         /* Payload length so far */\r
-        SKP_Silk_range_encoder_get_length( &psEnc->sCmn.sRC, &nBytes );\r
+        nBytes = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );\r
 \r
         /* Check that there is enough space in external output buffer, and move data */\r
         if( *pnBytesOut >= nBytes ) {\r
-            SKP_int bits_in_stream, mask;\r
-            bits_in_stream = ec_enc_tell( &psEnc->sCmn.sRC.range_enc_celt_state, 0 );\r
-            ec_enc_done( &psEnc->sCmn.sRC.range_enc_celt_state );\r
+            //SKP_int bits_in_stream, mask;\r
+            //bits_in_stream = ec_enc_tell( psRangeEnc, 0 );\r
+            ec_enc_done( psRangeEnc );\r
             \r
+#if 0\r
             /* Fill up any remaining bits in the last byte with 1s */\r
             if( bits_in_stream & 7 ) {\r
                 mask = SKP_RSHIFT( 0xFF, bits_in_stream & 7 );\r
@@ -226,7 +222,9 @@ TOC(ENCODE_PARAMS)
                 }\r
             }\r
             SKP_memcpy( pCode, psEnc->sCmn.sRC.range_enc_celt_state.buf->buf, nBytes * sizeof( SKP_uint8 ) );\r
+#endif\r
 \r
+#if 0\r
             if( frame_terminator > SKP_SILK_MORE_FRAMES && \r
                     *pnBytesOut >= nBytes + psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes ) {\r
                 /* Get old packet and add to payload. */\r
@@ -235,8 +233,9 @@ TOC(ENCODE_PARAMS)
                     psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes * sizeof( SKP_uint8 ) );\r
                 nBytes += psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes;\r
             }\r
+#endif\r
             *pnBytesOut = nBytes;\r
-        \r
+\r
             /* Update FEC buffer */\r
             SKP_memcpy( psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].payload, LBRRpayload, \r
                 nBytesLBRR * sizeof( SKP_uint8 ) );\r
@@ -245,36 +244,32 @@ TOC(ENCODE_PARAMS)
             psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].usage = sEncCtrl.sCmn.LBRR_usage;\r
             psEnc->sCmn.oldest_LBRR_idx = ( ( psEnc->sCmn.oldest_LBRR_idx + 1 ) & LBRR_IDX_MASK );\r
 \r
-            /* Reset the number of frames in payload buffer */\r
-            psEnc->sCmn.nFramesInPayloadBuf = 0;\r
         } else {\r
             /* Not enough space: Payload will be discarded */\r
             *pnBytesOut = 0;\r
             nBytes      = 0;\r
-            psEnc->sCmn.nFramesInPayloadBuf = 0;\r
             ret = SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT;\r
         }\r
+\r
+        /* Reset the number of frames in payload buffer */         \r
+        psEnc->sCmn.nFramesInPayloadBuf = 0;\r
     } else {\r
         /* No payload for you this time */\r
         *pnBytesOut = 0;\r
 \r
         /* Encode that more frames follows */\r
         frame_terminator = SKP_SILK_MORE_FRAMES;\r
-        SKP_Silk_range_encoder( &psEnc->sCmn.sRC, frame_terminator, FrameTermination_CDF );\r
+        ec_encode_bin( psRangeEnc, FrameTermination_CDF[ frame_terminator ], \r
+            FrameTermination_CDF[ frame_terminator + 1 ], 16 );\r
 \r
         /* Payload length so far */\r
-        SKP_Silk_range_encoder_get_length( &psEnc->sCmn.sRC, &nBytes );\r
+        nBytes = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );\r
 \r
         /* Take into account the q signal that isn't in the bitstream yet */\r
         nBytes += SKP_Silk_pulses_to_bytes( &psEnc->sCmn, \r
             &psEnc->sCmn.q[ psEnc->sCmn.nFramesInPayloadBuf * psEnc->sCmn.frame_length ] );\r
     }\r
 \r
-    /* Check for arithmetic coder errors */\r
-    if( psEnc->sCmn.sRC.error ) {\r
-        ret = SKP_SILK_ENC_INTERNAL_ERROR;\r
-    }\r
-\r
     /* simulate number of ms buffered in channel because of exceeding TargetRate */\r
     psEnc->BufferedInChannel_ms   += ( 8.0f * 1000.0f * ( nBytes - psEnc->sCmn.nBytesInPayloadBuf ) ) / psEnc->sCmn.TargetRate_bps;\r
     psEnc->BufferedInChannel_ms   -= SUB_FRAME_LENGTH_MS * psEnc->sCmn.nb_subfr;\r
@@ -314,6 +309,7 @@ TOC(ENCODE_FRAME)
     return( ret );\r
 }\r
 \r
+#if 0  //tmp\r
 /* Low Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode with lower bitrate           */\r
 void SKP_Silk_LBRR_encode_FLP(\r
     SKP_Silk_encoder_state_FLP      *psEnc,             /* I/O  Encoder state FLP                       */\r
@@ -397,7 +393,7 @@ void SKP_Silk_LBRR_encode_FLP(
         /****************************************/\r
         /* Encode Parameters                    */\r
         /****************************************/\r
-        SKP_Silk_encode_parameters_v4( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sCmn.sRC_LBRR );\r
+        SKP_Silk_encode_parameters( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sCmn.sRC_LBRR );\r
         \r
         /****************************************/\r
         /* Encode Parameters                    */\r
@@ -418,7 +414,8 @@ void SKP_Silk_LBRR_encode_FLP(
             frame_terminator = SKP_SILK_LAST_FRAME;\r
 \r
             /* Add the frame termination info to stream */\r
-            SKP_Silk_range_encoder( &psEnc->sCmn.sRC_LBRR, frame_terminator, SKP_Silk_FrameTermination_v4_CDF );\r
+            ec_encode_bin( psRangeEnc_LBRR, FrameTermination_CDF[ frame_terminator ], \r
+                FrameTermination_CDF[ frame_terminator + 1 ], 16 );\r
 \r
             /*********************************************/\r
             /* Encode quantization indices of excitation */\r
@@ -429,7 +426,7 @@ void SKP_Silk_LBRR_encode_FLP(
             }\r
 \r
             /* Payload length so far */\r
-            SKP_Silk_range_encoder_get_length( &psEnc->sCmn.sRC_LBRR, &nBytes );\r
+            nBytes = SKP_RSHIFT( ec_enc_tell( psRangeEnc_LBRR, 0 ) + 7, 3 );\r
 \r
             /* Check that there is enough space in external output buffer and move data */\r
             if( *pnBytesOut >= nBytes ) {\r
@@ -458,7 +455,8 @@ void SKP_Silk_LBRR_encode_FLP(
 \r
             /* Encode that more frames follows */\r
             frame_terminator = SKP_SILK_MORE_FRAMES;\r
-            SKP_Silk_range_encoder( &psEnc->sCmn.sRC_LBRR, frame_terminator, SKP_Silk_FrameTermination_v4_CDF );\r
+            ec_encode_bin( psRangeEnc_LBRR, FrameTermination_CDF[ frame_terminator ], \r
+                FrameTermination_CDF[ frame_terminator + 1 ], 16 );\r
         }\r
 \r
         /* Restore original Gains */\r
@@ -470,3 +468,4 @@ void SKP_Silk_LBRR_encode_FLP(
         psEnc->sCmn.typeOffsetPrev     = typeOffset;\r
     }\r
 }\r
+#endif
\ No newline at end of file
index 1612e09..f06cd79 100644 (file)
@@ -78,9 +78,9 @@ void SKP_Silk_HP_variable_cutoff_FLP(
 /* Encoder main function */\r
 SKP_int SKP_Silk_encode_frame_FLP( \r
     SKP_Silk_encoder_state_FLP      *psEnc,             /* I/O  Encoder state FLP                       */\r
-          SKP_uint8                 *pCode,             /* O    Payload                                 */\r
-          SKP_int16                 *pnBytesOut,        /* I/O  Number of payload bytes;                */\r
+    SKP_int16                       *pnBytesOut,        /* I/O  Number of payload bytes;                */\r
                                                         /*      input: max length; output: used         */\r
+    ec_enc                          *psRangeEnc,        /* I/O  compressor data structure                */\r
     const SKP_int16                 *pIn                /* I    Input speech frame                      */\r
 );\r
 \r
index aa076ed..4bcd82a 100644 (file)
@@ -35,34 +35,32 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 \r
 /* Encodes signs of excitation */\r
 void SKP_Silk_encode_signs(\r
-    SKP_Silk_range_coder_state      *sRC,               /* I/O  Range coder state                       */\r
-    const SKP_int8                  q[],                /* I    Pulse signal                            */\r
-    const SKP_int                   length,             /* I    Length of input                         */\r
-    const SKP_int                   sigtype,            /* I    Signal type                             */\r
-    const SKP_int                   QuantOffsetType,    /* I    Quantization offset type                */\r
-    const SKP_int                   RateLevelIndex      /* I    Rate level index                        */\r
+    ec_enc                      *psRangeEnc,        /* I/O  Compressor data structure                   */\r
+    const SKP_int8              q[],                /* I    pulse signal                                */\r
+    const SKP_int               length,             /* I    length of input                             */\r
+    const SKP_int               sigtype,            /* I    Signal type                                 */\r
+    const SKP_int               QuantOffsetType,    /* I    Quantization offset type                    */\r
+    const SKP_int               RateLevelIndex      /* I    Rate Level Index                            */\r
 )\r
 {\r
     SKP_int i;\r
     SKP_int inData;\r
-    SKP_uint16 cdf[ 3 ];\r
+    SKP_uint16 prob;\r
 \r
     i = SKP_SMULBB( N_RATE_LEVELS - 1, SKP_LSHIFT( sigtype, 1 ) + QuantOffsetType ) + RateLevelIndex;\r
-    cdf[ 0 ] = 0;\r
-    cdf[ 1 ] = SKP_Silk_sign_CDF[ i ];\r
-    cdf[ 2 ] = 65535;\r
+    prob = 65536 - SKP_Silk_sign_CDF[ i ];\r
     \r
     for( i = 0; i < length; i++ ) {\r
         if( q[ i ] != 0 ) {\r
             inData = SKP_enc_map( q[ i ] ); /* - = 0, + = 1 */\r
-            SKP_Silk_range_encoder( sRC, inData, cdf );\r
+            ec_enc_bit_prob( psRangeEnc, inData, prob );\r
         }\r
     }\r
 }\r
 \r
 /* Decodes signs of excitation */\r
 void SKP_Silk_decode_signs(\r
-    SKP_Silk_range_coder_state      *sRC,               /* I/O  Range coder state                           */\r
+    ec_dec                          *psRangeDec,        /* I/O  Compressor data structure                   */\r
     SKP_int                         q[],                /* I/O  pulse signal                                */\r
     const SKP_int                   length,             /* I    length of output                            */\r
     const SKP_int                   sigtype,            /* I    Signal type                                 */\r
@@ -81,7 +79,7 @@ void SKP_Silk_decode_signs(
     \r
     for( i = 0; i < length; i++ ) {\r
         if( q[ i ] > 0 ) {\r
-            SKP_Silk_range_decoder( &data, sRC, cdf, 1 );\r
+            SKP_Silk_range_decoder( &data, psRangeDec, cdf, 1 );\r
             /* attach sign */\r
             /* implementation with shift, subtraction, multiplication */\r
             q[ i ] *= SKP_dec_map( data );\r
index fddce15..9d3a1f7 100644 (file)
@@ -32,10 +32,10 @@ SKP_int SKP_Silk_SDK_InitDecoder(
 /* Decode a frame */\r
 SKP_int SKP_Silk_SDK_Decode(\r
     void*                               decState,       /* I/O: State                                           */\r
-    SKP_SILK_SDK_DecControlStruct*      decControl,     /* I/O: Control structure                               */\r
+    SKP_SILK_SDK_DecControlStruct*      decControl,     /* I/O: Control Structure                               */\r
     SKP_int                             lostFlag,       /* I:   0: no loss, 1 loss                              */\r
-    const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */\r
-    const SKP_int                       nBytesIn,       /* I:   Number of input Bytes                           */\r
+    ec_dec                              *psRangeDec,    /* I/O  Compressor data structure                       */\r
+    const SKP_int                       nBytesIn,       /* I:   Number of input bytes                           */\r
     SKP_int16                           *samplesOut,    /* O:   Decoded output speech vector                    */\r
     SKP_int16                           *nSamplesOut    /* I/O: Number of samples (vector/decoded)              */\r
 )\r
@@ -65,8 +65,7 @@ SKP_int SKP_Silk_SDK_Decode(
     prev_fs_kHz = psDec->fs_kHz;\r
     \r
     /* Call decoder for one frame */\r
-    ret += SKP_Silk_decode_frame( psDec, samplesOut, nSamplesOut, inData, nBytesIn, \r
-            lostFlag, &used_bytes );\r
+    ret += SKP_Silk_decode_frame( psDec, psRangeDec, samplesOut, nSamplesOut, nBytesIn, lostFlag, &used_bytes );\r
     \r
     if( used_bytes ) { /* Only Call if not a packet loss */\r
         if( psDec->nBytesLeft > 0 && psDec->FrameTermination == SKP_SILK_MORE_FRAMES && psDec->nFramesDecoded < 5 ) {\r
@@ -132,6 +131,7 @@ SKP_int SKP_Silk_SDK_Decode(
     return ret;\r
 }\r
 \r
+#if 0\r
 /* Function to find LBRR information in a packet */\r
 void SKP_Silk_SDK_search_for_LBRR(\r
     const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */\r
@@ -155,17 +155,16 @@ void SKP_Silk_SDK_search_for_LBRR(
     sDec.nFramesDecoded = 0;\r
     sDec.fs_kHz         = 0; /* Force update parameters LPC_order etc */\r
     SKP_memset( sDec.prevNLSF_Q15, 0, MAX_LPC_ORDER * sizeof( SKP_int ) );\r
-    SKP_Silk_range_dec_init( &sDec.sRC, inData, ( SKP_int32 )nBytesIn );\r
 \r
     /* Decode all parameter indices for the whole packet*/\r
-    SKP_Silk_decode_indices_v4( &sDec );\r
+    SKP_Silk_decode_indices( &sDec, psRangeDec );\r
 \r
     /* Is there usable LBRR in this packet */\r
     *nLBRRBytes = 0;\r
     if( ( sDec.FrameTermination - 1 ) & lost_offset && sDec.FrameTermination > 0 && sDec.nBytesLeft >= 0 ) {\r
         /* The wanted FEC is present in the packet */\r
         for( i = 0; i < sDec.nFramesInPacket; i++ ) {\r
-            SKP_Silk_decode_parameters_v4( &sDec, &sDecCtrl, TempQ, 0 );\r
+            SKP_Silk_decode_parameters( &sDec, &sDecCtrl, psRangeDec, TempQ, 0 );\r
             \r
             if( sDec.nBytesLeft <= 0 || sDec.sRC.error ) {\r
                 /* Corrupt stream */\r
@@ -184,10 +183,12 @@ void SKP_Silk_SDK_search_for_LBRR(
         }\r
     }\r
 }\r
+#endif\r
 \r
+#if 0  // todo: clean up, make efficient\r
 /* Getting type of content for a packet */\r
 void SKP_Silk_SDK_get_TOC(\r
-    const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */\r
+    ec_dec                              *psRangeDec,    /* I/O  Compressor data structure                   */\r
     const SKP_int16                     nBytesIn,       /* I:   Number of input bytes                           */\r
     SKP_Silk_TOC_struct                 *Silk_TOC       /* O:   Type of content                                 */\r
 )\r
@@ -197,10 +198,9 @@ void SKP_Silk_SDK_get_TOC(
 \r
     sDec.nFramesDecoded = 0;\r
     sDec.fs_kHz         = 0; /* Force update parameters LPC_order etc */\r
-    SKP_Silk_range_dec_init( &sDec.sRC, inData, ( SKP_int32 )nBytesIn );\r
 \r
     /* Decode all parameter indices for the whole packet*/\r
-    SKP_Silk_decode_indices_v4( &sDec );\r
+    SKP_Silk_decode_indices( &sDec );\r
     \r
     if( sDec.nFramesInPacket > SILK_MAX_FRAMES_PER_PACKET || sDec.sRC.error ) {\r
         /* Corrupt packet */\r
@@ -222,6 +222,7 @@ void SKP_Silk_SDK_get_TOC(
         }\r
     }\r
 }\r
+#endif\r
 \r
 /**************************/\r
 /* Get the version number */\r
index c3a5339..c38a806 100644 (file)
@@ -33,19 +33,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 /* Decode frame */\r
 /****************/\r
 SKP_int SKP_Silk_decode_frame(\r
-    SKP_Silk_decoder_state          *psDec,             /* I/O  Pointer to Silk decoder state               */\r
-    SKP_int16                       pOut[],             /* O    Pointer to output speech frame              */\r
-    SKP_int16                       *pN,                /* O    Pointer to size of output frame             */\r
-    const SKP_uint8                 pCode[],            /* I    Pointer to payload                          */\r
-    const SKP_int                   nBytes,             /* I    Payload length                              */\r
-    SKP_int                         action,             /* I    Action from Jitter Buffer                   */\r
-    SKP_int                         *decBytes           /* O    Used bytes to decode this frame             */\r
+    SKP_Silk_decoder_state      *psDec,             /* I/O  Pointer to Silk decoder state               */\r
+    ec_dec                      *psRangeDec,        /* I/O  Compressor data structure                   */\r
+    SKP_int16                   pOut[],             /* O    Pointer to output speech frame              */\r
+    SKP_int16                   *pN,                /* O    Pointer to size of output frame             */\r
+    const SKP_int               nBytes,             /* I    Payload length                              */\r
+    SKP_int                     action,             /* I    Action from Jitter Buffer                   */\r
+    SKP_int                     *decBytes           /* O    Used bytes to decode this frame             */\r
 )\r
 {\r
     SKP_Silk_decoder_control sDecCtrl;\r
     SKP_int         L, fs_Khz_old, nb_subfr_old, mv_len, ret = 0;\r
     SKP_int         Pulses[ MAX_FRAME_LENGTH ];\r
-    ec_byte_buffer range_dec_celt_buf;\r
 \r
 TIC(decode_frame)\r
 \r
@@ -66,41 +65,33 @@ TIC(decode_frame)
         fs_Khz_old    = psDec->fs_kHz;\r
         nb_subfr_old  = psDec->nb_subfr;\r
         if( psDec->nFramesDecoded == 0 ) {\r
-            /* Initialize range decoder state */\r
-            /* check input */\r
-            psDec->sRC.error = 0;\r
-            if( nBytes > MAX_ARITHM_BYTES ) {\r
-                psDec->sRC.error = RANGE_CODER_DEC_PAYLOAD_TOO_LONG;\r
-            }\r
-            ec_byte_writeinit_buffer( &range_dec_celt_buf, psDec->sRC.buffer, nBytes );\r
-            SKP_memcpy( psDec->sRC.buffer, pCode, nBytes * sizeof( SKP_uint8 ) );\r
-            ec_dec_init( &psDec->sRC.range_dec_celt_state, &range_dec_celt_buf );\r
-\r
-            SKP_Silk_decode_indices_v4( psDec );\r
+            SKP_Silk_decode_indices( psDec, psRangeDec );\r
         }\r
 \r
         /********************************************/\r
         /* Decode parameters and pulse signal       */\r
         /********************************************/\r
 TIC(decode_params)\r
-        SKP_Silk_decode_parameters_v4( psDec, &sDecCtrl, Pulses, 1 );\r
+        SKP_Silk_decode_parameters( psDec, &sDecCtrl, psRangeDec, Pulses, 1 );\r
 TOC(decode_params)\r
 \r
-        if( psDec->sRC.error ) {\r
+        if( 0 ) { //psDec->sRC.error ) {\r
             psDec->nBytesLeft = 0;\r
 \r
             action              = 1; /* PLC operation */\r
             SKP_Silk_decoder_set_fs( psDec, fs_Khz_old, nb_subfr_old );\r
 \r
             /* Avoid crashing */\r
-            *decBytes = psDec->sRC.range_dec_celt_state.buf->storage; \r
+            *decBytes = psRangeDec->buf->storage; \r
+            /*\r
             if( psDec->sRC.error == RANGE_CODER_DEC_PAYLOAD_TOO_LONG ) {\r
                 ret = SKP_SILK_DEC_PAYLOAD_TOO_LARGE;\r
             } else {\r
                 ret = SKP_SILK_DEC_PAYLOAD_ERROR;\r
             }\r
+            */\r
         } else {\r
-            *decBytes = psDec->sRC.range_dec_celt_state.buf->storage - psDec->nBytesLeft;\r
+            *decBytes = psRangeDec->buf->storage - psDec->nBytesLeft;\r
             psDec->nFramesDecoded++;\r
         \r
             /* Update lengths. Sampling frequency could have changed */\r
similarity index 72%
rename from src_common/SKP_Silk_decode_indices_v4.c
rename to src_common/SKP_Silk_decode_indices.c
index e41797b..3ba8a77 100644 (file)
@@ -28,31 +28,26 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "SKP_Silk_main.h"\r
 \r
 /* Decode indices from payload */\r
-void SKP_Silk_decode_indices_v4(\r
-    SKP_Silk_decoder_state      *psDec            /* I/O    State                              */\r
+void SKP_Silk_decode_indices(\r
+    SKP_Silk_decoder_state      *psDec,             /* I/O  State                                       */\r
+    ec_dec                      *psRangeDec         /* I/O  Compressor data structure                   */\r
 )\r
 {\r
     SKP_int   i, k, Ix, fs_kHz_dec, nb_subfr, FrameIndex = 0, FrameTermination;\r
     SKP_int   sigtype, QuantOffsetType, seed_int, nBytesUsed;\r
     SKP_int   decode_absolute_lagIndex, delta_lagIndex, prev_lagIndex = 0;\r
     const SKP_Silk_NLSF_CB_struct *psNLSF_CB = NULL;\r
-    SKP_Silk_range_coder_state  *psRC = &psDec->sRC;\r
+\r
     /************************/\r
     /* Decode sampling rate */\r
     /************************/\r
     /* only done for first frame of packet */\r
     if( psDec->nFramesDecoded == 0 ) {\r
-        SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_SamplingRates_CDF, SKP_Silk_SamplingRates_offset );\r
-\r
-        /* check that sampling rate is supported */\r
-        if( Ix < 0 || Ix > 3 ) {\r
-            psRC->error = RANGE_CODER_ILLEGAL_SAMPLING_RATE;\r
-            return;\r
-        }\r
+        SKP_Silk_range_decoder( &Ix, psRangeDec, SKP_Silk_SamplingRates_CDF, SKP_Silk_SamplingRates_offset );\r
         fs_kHz_dec = SKP_Silk_SamplingRates_table[ Ix ];\r
 \r
         /* Convert number of subframes to index */\r
-        SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_NbSubframes_CDF, SKP_Silk_NbSubframes_offset );\r
+        SKP_Silk_range_decoder( &Ix, psRangeDec, SKP_Silk_NbSubframes_CDF, SKP_Silk_NbSubframes_offset );\r
         nb_subfr = (Ix + 1) << 1;\r
         SKP_assert( nb_subfr == MAX_NB_SUBFR >> 1 || nb_subfr == MAX_NB_SUBFR );\r
         \r
@@ -66,17 +61,17 @@ void SKP_Silk_decode_indices_v4(
         /*******************/\r
         /* Decode VAD flag */\r
         /*******************/\r
-        SKP_Silk_range_decoder( &psDec->vadFlagBuf[ FrameIndex ], psRC, SKP_Silk_vadflag_CDF, SKP_Silk_vadflag_offset );\r
+        SKP_Silk_range_decoder( &psDec->vadFlagBuf[ FrameIndex ], psRangeDec, SKP_Silk_vadflag_CDF, SKP_Silk_vadflag_offset );\r
 \r
         /*******************************************/\r
         /* Decode signal type and quantizer offset */\r
         /*******************************************/\r
         if( FrameIndex == 0 ) {\r
             /* first frame in packet: independent coding */\r
-            SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_type_offset_CDF, SKP_Silk_type_offset_CDF_offset );\r
+            SKP_Silk_range_decoder( &Ix, psRangeDec, SKP_Silk_type_offset_CDF, SKP_Silk_type_offset_CDF_offset );\r
         } else {\r
             /* condidtional coding */\r
-            SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_type_offset_joint_CDF[ psDec->typeOffsetPrev ], \r
+            SKP_Silk_range_decoder( &Ix, psRangeDec, SKP_Silk_type_offset_joint_CDF[ psDec->typeOffsetPrev ], \r
                     SKP_Silk_type_offset_CDF_offset );\r
         }\r
         sigtype               = SKP_RSHIFT( Ix, 1 );\r
@@ -89,15 +84,15 @@ void SKP_Silk_decode_indices_v4(
         /* first subframe */    \r
         if( FrameIndex == 0 ) {\r
             /* first frame in packet: independent coding */\r
-            SKP_Silk_range_decoder( &psDec->GainsIndices[ FrameIndex ][ 0 ], psRC, SKP_Silk_gain_CDF[ sigtype ], SKP_Silk_gain_CDF_offset );\r
+            SKP_Silk_range_decoder( &psDec->GainsIndices[ FrameIndex ][ 0 ], psRangeDec, SKP_Silk_gain_CDF[ sigtype ], SKP_Silk_gain_CDF_offset );\r
         } else {\r
             /* condidtional coding */\r
-            SKP_Silk_range_decoder( &psDec->GainsIndices[ FrameIndex ][ 0 ], psRC, SKP_Silk_delta_gain_CDF, SKP_Silk_delta_gain_CDF_offset );\r
+            SKP_Silk_range_decoder( &psDec->GainsIndices[ FrameIndex ][ 0 ], psRangeDec, SKP_Silk_delta_gain_CDF, SKP_Silk_delta_gain_CDF_offset );\r
         }\r
 \r
         /* remaining subframes */\r
         for( i = 1; i < psDec->nb_subfr; i++ ) {\r
-            SKP_Silk_range_decoder( &psDec->GainsIndices[ FrameIndex ][ i ], psRC, SKP_Silk_delta_gain_CDF, SKP_Silk_delta_gain_CDF_offset );\r
+            SKP_Silk_range_decoder( &psDec->GainsIndices[ FrameIndex ][ i ], psRangeDec, SKP_Silk_delta_gain_CDF, SKP_Silk_delta_gain_CDF_offset );\r
         }\r
         \r
         /**********************/\r
@@ -108,12 +103,14 @@ void SKP_Silk_decode_indices_v4(
         psNLSF_CB = psDec->psNLSF_CB[ sigtype ];\r
 \r
         /* Arithmetically decode NLSF path */\r
-        SKP_Silk_range_decoder_multi( psDec->NLSFIndices[ FrameIndex ], psRC, psNLSF_CB->StartPtr, psNLSF_CB->MiddleIx, psNLSF_CB->nStages );\r
+        for( i = 0; i < psNLSF_CB->nStages; i++ ) {\r
+            SKP_Silk_range_decoder( &psDec->NLSFIndices[ FrameIndex ][ i ], psRangeDec, psNLSF_CB->StartPtr[ i ], psNLSF_CB->MiddleIx[ i ] );\r
+        }\r
         \r
         /***********************************/\r
         /* Decode LSF interpolation factor */\r
         /***********************************/\r
-        SKP_Silk_range_decoder( &psDec->NLSFInterpCoef_Q2[ FrameIndex ], psRC, SKP_Silk_NLSF_interpolation_factor_CDF, \r
+        SKP_Silk_range_decoder( &psDec->NLSFInterpCoef_Q2[ FrameIndex ], psRangeDec, SKP_Silk_NLSF_interpolation_factor_CDF, \r
             SKP_Silk_NLSF_interpolation_factor_offset );\r
         \r
         if( sigtype == SIG_TYPE_VOICED ) {\r
@@ -124,7 +121,7 @@ void SKP_Silk_decode_indices_v4(
             decode_absolute_lagIndex = 1;\r
             if( FrameIndex > 0 && psDec->sigtype[ FrameIndex - 1 ] == SIG_TYPE_VOICED ) {\r
                 /* Decode Delta index */\r
-                SKP_Silk_range_decoder( &delta_lagIndex,psRC, SKP_Silk_pitch_delta_CDF,  SKP_Silk_pitch_delta_CDF_offset );\r
+                SKP_Silk_range_decoder( &delta_lagIndex, psRangeDec, SKP_Silk_pitch_delta_CDF,  SKP_Silk_pitch_delta_CDF_offset );\r
                 if( delta_lagIndex < ( MAX_DELTA_LAG << 1 ) + 1 ) {\r
                     delta_lagIndex = delta_lagIndex - MAX_DELTA_LAG;\r
                     psDec->lagIndex[ FrameIndex ] = prev_lagIndex + delta_lagIndex;\r
@@ -134,13 +131,13 @@ void SKP_Silk_decode_indices_v4(
             if( decode_absolute_lagIndex ) {\r
                 /* Absolute decoding */\r
                 if( psDec->fs_kHz == 8 ) {\r
-                    SKP_Silk_range_decoder( &psDec->lagIndex[ FrameIndex ], psRC, SKP_Silk_pitch_lag_NB_CDF,  SKP_Silk_pitch_lag_NB_CDF_offset );\r
+                    SKP_Silk_range_decoder( &psDec->lagIndex[ FrameIndex ], psRangeDec, SKP_Silk_pitch_lag_NB_CDF,  SKP_Silk_pitch_lag_NB_CDF_offset );\r
                 } else if( psDec->fs_kHz == 12 ) {\r
-                    SKP_Silk_range_decoder( &psDec->lagIndex[ FrameIndex ], psRC, SKP_Silk_pitch_lag_MB_CDF,  SKP_Silk_pitch_lag_MB_CDF_offset );\r
+                    SKP_Silk_range_decoder( &psDec->lagIndex[ FrameIndex ], psRangeDec, SKP_Silk_pitch_lag_MB_CDF,  SKP_Silk_pitch_lag_MB_CDF_offset );\r
                 } else if( psDec->fs_kHz == 16 ) {\r
-                    SKP_Silk_range_decoder( &psDec->lagIndex[ FrameIndex ], psRC, SKP_Silk_pitch_lag_WB_CDF,  SKP_Silk_pitch_lag_WB_CDF_offset );\r
+                    SKP_Silk_range_decoder( &psDec->lagIndex[ FrameIndex ], psRangeDec, SKP_Silk_pitch_lag_WB_CDF,  SKP_Silk_pitch_lag_WB_CDF_offset );\r
                 } else {\r
-                    SKP_Silk_range_decoder( &psDec->lagIndex[ FrameIndex ], psRC, SKP_Silk_pitch_lag_SWB_CDF, SKP_Silk_pitch_lag_SWB_CDF_offset );\r
+                    SKP_Silk_range_decoder( &psDec->lagIndex[ FrameIndex ], psRangeDec, SKP_Silk_pitch_lag_SWB_CDF, SKP_Silk_pitch_lag_SWB_CDF_offset );\r
                 }\r
             }\r
             prev_lagIndex = psDec->lagIndex[ FrameIndex ];\r
@@ -148,38 +145,38 @@ void SKP_Silk_decode_indices_v4(
             /* Get countour index */\r
             if( psDec->fs_kHz == 8 ) {\r
                 /* Less codevectors used in 8 khz mode */\r
-                SKP_Silk_range_decoder( &psDec->contourIndex[ FrameIndex ], psRC, SKP_Silk_pitch_contour_NB_CDF, SKP_Silk_pitch_contour_NB_CDF_offset );\r
+                SKP_Silk_range_decoder( &psDec->contourIndex[ FrameIndex ], psRangeDec, SKP_Silk_pitch_contour_NB_CDF, SKP_Silk_pitch_contour_NB_CDF_offset );\r
             } else {\r
                 /* Joint for 12, 16, and 24 khz */\r
-                SKP_Silk_range_decoder( &psDec->contourIndex[ FrameIndex ], psRC, SKP_Silk_pitch_contour_CDF, SKP_Silk_pitch_contour_CDF_offset );\r
+                SKP_Silk_range_decoder( &psDec->contourIndex[ FrameIndex ], psRangeDec, SKP_Silk_pitch_contour_CDF, SKP_Silk_pitch_contour_CDF_offset );\r
             }\r
             \r
             /********************/\r
             /* Decode LTP gains */\r
             /********************/\r
             /* Decode PERIndex value */\r
-            SKP_Silk_range_decoder( &psDec->PERIndex[ FrameIndex ], psRC, SKP_Silk_LTP_per_index_CDF, SKP_Silk_LTP_per_index_CDF_offset );\r
+            SKP_Silk_range_decoder( &psDec->PERIndex[ FrameIndex ], psRangeDec, SKP_Silk_LTP_per_index_CDF, SKP_Silk_LTP_per_index_CDF_offset );\r
             \r
             for( k = 0; k < psDec->nb_subfr; k++ ) {\r
-                SKP_Silk_range_decoder( &psDec->LTPIndex[ FrameIndex ][ k ], psRC, SKP_Silk_LTP_gain_CDF_ptrs[ psDec->PERIndex[ FrameIndex ] ], \r
+                SKP_Silk_range_decoder( &psDec->LTPIndex[ FrameIndex ][ k ], psRangeDec, SKP_Silk_LTP_gain_CDF_ptrs[ psDec->PERIndex[ FrameIndex ] ], \r
                     SKP_Silk_LTP_gain_CDF_offsets[ psDec->PERIndex[ FrameIndex ] ] );\r
             }\r
 \r
             /**********************/\r
             /* Decode LTP scaling */\r
             /**********************/\r
-            SKP_Silk_range_decoder( &psDec->LTP_scaleIndex[ FrameIndex ], psRC, SKP_Silk_LTPscale_CDF, SKP_Silk_LTPscale_offset );\r
+            SKP_Silk_range_decoder( &psDec->LTP_scaleIndex[ FrameIndex ], psRangeDec, SKP_Silk_LTPscale_CDF, SKP_Silk_LTPscale_offset );\r
         }\r
 \r
         /***************/\r
         /* Decode seed */\r
         /***************/\r
-        SKP_Silk_range_decoder( &seed_int, psRC, SKP_Silk_Seed_CDF, SKP_Silk_Seed_offset );\r
+        SKP_Silk_range_decoder( &seed_int, psRangeDec, SKP_Silk_Seed_CDF, SKP_Silk_Seed_offset );\r
         psDec->Seed[ FrameIndex ] = ( SKP_int32 )seed_int;\r
         /**************************************/\r
         /* Decode Frame termination indicator */\r
         /**************************************/\r
-        SKP_Silk_range_decoder( &FrameTermination, psRC, SKP_Silk_FrameTermination_v4_CDF, SKP_Silk_FrameTermination_v4_offset );\r
+        SKP_Silk_range_decoder( &FrameTermination, psRangeDec, SKP_Silk_FrameTermination_CDF, SKP_Silk_FrameTermination_offset );\r
 \r
         psDec->sigtype[ FrameIndex ]         = sigtype;\r
         psDec->QuantOffsetType[ FrameIndex ] = QuantOffsetType;\r
@@ -190,12 +187,8 @@ void SKP_Silk_decode_indices_v4(
     /****************************************/\r
     /* get number of bytes used so far      */\r
     /****************************************/\r
-    SKP_Silk_range_decoder_get_length( psRC, &nBytesUsed );\r
-    psDec->nBytesLeft = psRC->range_dec_celt_state.buf->storage - nBytesUsed;\r
-\r
-    if( psDec->nBytesLeft < 0 ) {\r
-        psRC->error = RANGE_CODER_READ_BEYOND_BUFFER;\r
-    }\r
+    nBytesUsed = SKP_RSHIFT( ec_dec_tell( psRangeDec, 0 ) + 7, 3 );\r
+    psDec->nBytesLeft = psRangeDec->buf->storage - nBytesUsed;\r
 \r
     psDec->nFramesInPacket  = FrameIndex;\r
     psDec->FrameTermination = FrameTermination;\r
similarity index 90%
rename from src_common/SKP_Silk_decode_parameters_v4.c
rename to src_common/SKP_Silk_decode_parameters.c
index 6702742..eb9077b 100644 (file)
@@ -28,9 +28,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "SKP_Silk_main.h"\r
 \r
 /* Decode parameters from payload */\r
-void SKP_Silk_decode_parameters_v4(\r
+void SKP_Silk_decode_parameters(\r
     SKP_Silk_decoder_state      *psDec,                                 /* I/O  State                                    */\r
     SKP_Silk_decoder_control    *psDecCtrl,                             /* I/O  Decoder control                          */\r
+    ec_dec                      *psRangeDec,                            /* I/O  Compressor data structure                */\r
     SKP_int                     q[ MAX_FRAME_LENGTH ],                  /* O    Excitation signal                        */\r
     const SKP_int               fullDecoding                            /* I    Flag to tell if only arithmetic decoding */\r
 )\r
@@ -39,7 +40,6 @@ void SKP_Silk_decode_parameters_v4(
     SKP_int   pNLSF_Q15[ MAX_LPC_ORDER ], pNLSF0_Q15[ MAX_LPC_ORDER ];\r
     const SKP_int16 *cbk_ptr_Q14;\r
     const SKP_Silk_NLSF_CB_struct *psNLSF_CB = NULL;\r
-    SKP_Silk_range_coder_state  *psRC = &psDec->sRC;\r
     \r
     psDec->FrameTermination       = SKP_SILK_MORE_FRAMES;\r
     psDecCtrl->sigtype            = psDec->sigtype[ psDec->nFramesDecoded ];\r
@@ -135,25 +135,14 @@ void SKP_Silk_decode_parameters_v4(
     /* Decode quantization indices of excitation */\r
     /*********************************************/\r
 TIC(decode_pulses)\r
-    SKP_Silk_decode_pulses( psRC, psDecCtrl, q, psDec->frame_length );\r
+    SKP_Silk_decode_pulses( psRangeDec, psDecCtrl, q, psDec->frame_length );\r
 TOC(decode_pulses)\r
 \r
     /****************************************/\r
     /* get number of bytes used so far      */\r
     /****************************************/\r
-    SKP_Silk_range_decoder_get_length( psRC, &nBytesUsed );\r
-    psDec->nBytesLeft = psRC->range_dec_celt_state.buf->storage - nBytesUsed;\r
-\r
-    if( psDec->nBytesLeft < 0 ) {\r
-        psRC->error = RANGE_CODER_READ_BEYOND_BUFFER;\r
-    }\r
-\r
-    /****************************************/\r
-    /* check remaining bits in last byte    */\r
-    /****************************************/\r
-    if( psDec->nBytesLeft == 0 ) {\r
-        SKP_Silk_range_coder_check_after_decoding( psRC );\r
-    }\r
+    nBytesUsed = SKP_RSHIFT( ec_dec_tell( psRangeDec, 0 ) + 7, 3 );\r
+    psDec->nBytesLeft = psRangeDec->buf->storage - nBytesUsed;\r
 \r
     if( psDec->nFramesInPacket == (psDec->nFramesDecoded + 1)) {\r
         /* To indicate the packet has been fully decoded */\r
index bdcd37c..503757a 100644 (file)
@@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 /* Decode quantization indices of excitation */\r
 /*********************************************/\r
 void SKP_Silk_decode_pulses(\r
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  Range coder state                           */\r
+    ec_dec                          *psRangeDec,        /* I/O  Compressor data structure                   */\r
     SKP_Silk_decoder_control        *psDecCtrl,         /* I/O  Decoder control                             */\r
     SKP_int                         q[],                /* O    Excitation signal                           */\r
     const SKP_int                   frame_length        /* I    Frame length (preliminary)                  */\r
@@ -45,7 +45,7 @@ void SKP_Silk_decode_pulses(
     /*********************/\r
     /* Decode rate level */\r
     /*********************/\r
-    SKP_Silk_range_decoder( &psDecCtrl->RateLevelIndex, psRC\r
+    SKP_Silk_range_decoder( &psDecCtrl->RateLevelIndex, psRangeDec\r
             SKP_Silk_rate_levels_CDF[ psDecCtrl->sigtype ], SKP_Silk_rate_levels_CDF_offset );\r
 \r
     /* Calculate number of shell blocks */\r
@@ -61,12 +61,12 @@ void SKP_Silk_decode_pulses(
     cdf_ptr = SKP_Silk_pulses_per_block_CDF[ psDecCtrl->RateLevelIndex ];\r
     for( i = 0; i < iter; i++ ) {\r
         nLshifts[ i ] = 0;\r
-        SKP_Silk_range_decoder( &sum_pulses[ i ], psRC, cdf_ptr, SKP_Silk_pulses_per_block_CDF_offset );\r
+        SKP_Silk_range_decoder( &sum_pulses[ i ], psRangeDec, cdf_ptr, SKP_Silk_pulses_per_block_CDF_offset );\r
 \r
         /* LSB indication */\r
         while( sum_pulses[ i ] == ( MAX_PULSES + 1 ) ) {\r
             nLshifts[ i ]++;\r
-            SKP_Silk_range_decoder( &sum_pulses[ i ], psRC\r
+            SKP_Silk_range_decoder( &sum_pulses[ i ], psRangeDec\r
                     SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS - 1 ], SKP_Silk_pulses_per_block_CDF_offset );\r
         }\r
     }\r
@@ -76,7 +76,7 @@ void SKP_Silk_decode_pulses(
     /***************************************************/\r
     for( i = 0; i < iter; i++ ) {\r
         if( sum_pulses[ i ] > 0 ) {\r
-            SKP_Silk_shell_decoder( &q[ SKP_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], psRC, sum_pulses[ i ] );\r
+            SKP_Silk_shell_decoder( &q[ SKP_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], psRangeDec, sum_pulses[ i ] );\r
         } else {\r
             SKP_memset( &q[ SKP_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], 0, SHELL_CODEC_FRAME_LENGTH * sizeof( SKP_int ) );\r
         }\r
@@ -93,7 +93,7 @@ void SKP_Silk_decode_pulses(
                 abs_q = pulses_ptr[ k ];\r
                 for( j = 0; j < nLS; j++ ) {\r
                     abs_q = SKP_LSHIFT( abs_q, 1 ); \r
-                    SKP_Silk_range_decoder( &bit, psRC, SKP_Silk_lsb_CDF, 1 );\r
+                    SKP_Silk_range_decoder( &bit, psRangeDec, SKP_Silk_lsb_CDF, 1 );\r
                     abs_q += bit;\r
                 }\r
                 pulses_ptr[ k ] = abs_q;\r
@@ -104,6 +104,6 @@ void SKP_Silk_decode_pulses(
     /****************************************/\r
     /* Decode and add signs to pulse signal */\r
     /****************************************/\r
-    SKP_Silk_decode_signs( psRC, q, frame_length, psDecCtrl->sigtype, \r
+    SKP_Silk_decode_signs( psRangeDec, q, frame_length, psDecCtrl->sigtype, \r
         psDecCtrl->QuantOffsetType, psDecCtrl->RateLevelIndex);\r
 }\r
index 7926527..fa74059 100644 (file)
@@ -121,8 +121,8 @@ SKP_int SKP_Silk_SDK_Encode(
     const SKP_Silk_EncodeControlStruct  *encControl,    /* I:   Control structure                               */\r
     const SKP_int16                     *samplesIn,     /* I:   Speech sample input vector                      */\r
     SKP_int                             nSamplesIn,     /* I:   Number of samples in input vector               */\r
-    SKP_uint8                           *outData,       /* O:   Encoded output vector                           */\r
-    SKP_int16                           *nBytesOut      /* I/O: Number of bytes in outData (input: Max bytes)   */\r
+    ec_enc                              *psRangeEnc,    /* I/O  Compressor data structure                       */\r
+    SKP_int16                           *nBytesOut      /* I/O: Number of bytes in payload (input: Max bytes)   */\r
 )\r
 {\r
     SKP_int   max_internal_fs_kHz, PacketSize_ms, PacketLoss_perc, UseInBandFEC, UseDTX, ret = SKP_SILK_NO_ERROR;\r
@@ -214,12 +214,12 @@ SKP_int SKP_Silk_SDK_Encode(
             if( MaxBytesOut == 0 ) {\r
                 /* No payload obtained so far */\r
                 MaxBytesOut = *nBytesOut;\r
-                if( ( ret = SKP_Silk_encode_frame_Fxx( psEnc, outData, &MaxBytesOut, psEnc->sCmn.inputBuf ) ) != 0 ) {\r
+                if( ( ret = SKP_Silk_encode_frame_Fxx( psEnc, &MaxBytesOut, psRangeEnc, psEnc->sCmn.inputBuf ) ) != 0 ) {\r
                     SKP_assert( 0 );\r
                 }\r
             } else {\r
-                /* outData already contains a payload */\r
-                if( ( ret = SKP_Silk_encode_frame_Fxx( psEnc, outData, nBytesOut, psEnc->sCmn.inputBuf ) ) != 0 ) {\r
+                /* Already contains a payload */\r
+                if( ( ret = SKP_Silk_encode_frame_Fxx( psEnc, nBytesOut, psRangeEnc, psEnc->sCmn.inputBuf ) ) != 0 ) {\r
                     SKP_assert( 0 );\r
                 }\r
                 /* Check that no second payload was created */\r
similarity index 59%
rename from src_common/SKP_Silk_encode_parameters_v4.c
rename to src_common/SKP_Silk_encode_parameters.c
index 07c6e04..dd66154 100644 (file)
@@ -30,10 +30,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 /*******************************************/\r
 /* Encode parameters to create the payload */\r
 /*******************************************/\r
-void SKP_Silk_encode_parameters_v4(\r
-    SKP_Silk_encoder_state          *psEncC,        /* I/O  Encoder state                   */\r
-    SKP_Silk_encoder_control        *psEncCtrlC,    /* I/O  Encoder control                 */\r
-    SKP_Silk_range_coder_state      *psRC           /* I/O  Range encoder state             */\r
+void SKP_Silk_encode_parameters(\r
+    SKP_Silk_encoder_state      *psEncC,            /* I/O  Encoder state                               */\r
+    SKP_Silk_encoder_control    *psEncCtrlC,        /* I/O  Encoder control                             */\r
+    ec_enc                      *psRangeEnc         /* I/O  Compressor data structure                   */\r
 )\r
 {\r
     SKP_int   i, k, typeOffset;\r
@@ -57,18 +57,18 @@ void SKP_Silk_encode_parameters_v4(
                 break;\r
             }\r
         }\r
-        SKP_Silk_range_encoder( psRC, i, SKP_Silk_SamplingRates_CDF );\r
+        ec_encode_bin( psRangeEnc, SKP_Silk_SamplingRates_CDF[ i ], SKP_Silk_SamplingRates_CDF[ i + 1 ], 16 );\r
 \r
         /* Convert number of subframes to index */\r
         SKP_assert( psEncC->nb_subfr == MAX_NB_SUBFR >> 1 || psEncC->nb_subfr == MAX_NB_SUBFR );\r
         i = (psEncC->nb_subfr >> 1) - 1;\r
-        SKP_Silk_range_encoder( psRC, i, SKP_Silk_NbSubframes_CDF );\r
+        ec_enc_bit_prob( psRangeEnc, i, 65536 - SKP_Silk_NbSubframes_CDF[ 1 ] );\r
     }\r
 \r
     /*********************************************/\r
     /* Encode VAD flag                           */\r
     /*********************************************/\r
-    SKP_Silk_range_encoder( psRC, psEncC->vadFlag, SKP_Silk_vadflag_CDF );\r
+    ec_enc_bit_prob( psRangeEnc, psEncC->vadFlag, 65536 - SKP_Silk_vadflag_CDF[ 1 ] );\r
 \r
     /*******************************************/\r
     /* Encode signal type and quantizer offset */\r
@@ -76,10 +76,12 @@ void SKP_Silk_encode_parameters_v4(
     typeOffset = 2 * psEncCtrlC->sigtype + psEncCtrlC->QuantOffsetType;\r
     if( psEncC->nFramesInPayloadBuf == 0 ) {\r
         /* first frame in packet: independent coding */\r
-        SKP_Silk_range_encoder( psRC, typeOffset, SKP_Silk_type_offset_CDF );\r
+        ec_encode_bin( psRangeEnc, SKP_Silk_type_offset_CDF[ typeOffset ], \r
+            SKP_Silk_type_offset_CDF[ typeOffset + 1 ], 16 );\r
     } else {\r
         /* condidtional coding */\r
-        SKP_Silk_range_encoder( psRC, typeOffset, SKP_Silk_type_offset_joint_CDF[ psEncC->typeOffsetPrev ] );\r
+        ec_encode_bin( psRangeEnc, SKP_Silk_type_offset_joint_CDF[ psEncC->typeOffsetPrev ][ typeOffset ], \r
+            SKP_Silk_type_offset_joint_CDF[ psEncC->typeOffsetPrev ][ typeOffset + 1 ], 16 );\r
     }\r
     psEncC->typeOffsetPrev = typeOffset;\r
 \r
@@ -87,24 +89,27 @@ void SKP_Silk_encode_parameters_v4(
     /* Encode gains */\r
     /****************/\r
 #ifdef SAVE_ALL_INTERNAL_DATA\r
-    SKP_Silk_range_encoder_get_length( psRC, &nBytes_before );\r
+    nBytes_before = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );\r
 #endif\r
     /* first subframe */\r
     if( psEncC->nFramesInPayloadBuf == 0 ) {\r
         /* first frame in packet: independent coding */\r
-        SKP_Silk_range_encoder( psRC, psEncCtrlC->GainsIndices[ 0 ], SKP_Silk_gain_CDF[ psEncCtrlC->sigtype ] );\r
+        ec_encode_bin( psRangeEnc, SKP_Silk_gain_CDF[ psEncCtrlC->sigtype ][ psEncCtrlC->GainsIndices[ 0 ] ], \r
+            SKP_Silk_gain_CDF[ psEncCtrlC->sigtype ][ psEncCtrlC->GainsIndices[ 0 ] + 1 ], 16 );\r
     } else {\r
         /* condidtional coding */\r
-        SKP_Silk_range_encoder( psRC, psEncCtrlC->GainsIndices[ 0 ], SKP_Silk_delta_gain_CDF );\r
+        ec_encode_bin( psRangeEnc, SKP_Silk_delta_gain_CDF[ psEncCtrlC->GainsIndices[ 0 ] ], \r
+            SKP_Silk_delta_gain_CDF[ psEncCtrlC->GainsIndices[ 0 ] + 1 ], 16 );\r
     }\r
 \r
     /* remaining subframes */\r
     for( i = 1; i < psEncC->nb_subfr; i++ ) {\r
-        SKP_Silk_range_encoder( psRC, psEncCtrlC->GainsIndices[ i ], SKP_Silk_delta_gain_CDF );\r
+        ec_encode_bin( psRangeEnc, SKP_Silk_delta_gain_CDF[ psEncCtrlC->GainsIndices[ i ] ], \r
+            SKP_Silk_delta_gain_CDF[ psEncCtrlC->GainsIndices[ i ] + 1 ], 16 );\r
     }\r
 \r
 #ifdef SAVE_ALL_INTERNAL_DATA\r
-    SKP_Silk_range_encoder_get_length( psRC, &nBytes_after );\r
+    nBytes_after = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );\r
     nBytes_after -= nBytes_before; // bytes just added\r
     DEBUG_STORE_DATA( nBytes_gains.dat, &nBytes_after, sizeof( SKP_int ) );\r
 #endif\r
@@ -113,18 +118,22 @@ void SKP_Silk_encode_parameters_v4(
     /* Encode NLSFs */\r
     /****************/\r
 #ifdef SAVE_ALL_INTERNAL_DATA\r
-    SKP_Silk_range_encoder_get_length( psRC, &nBytes_before );\r
+    nBytes_before = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );\r
 #endif\r
     /* Range encoding of the NLSF path */\r
     psNLSF_CB = psEncC->psNLSF_CB[ psEncCtrlC->sigtype ];\r
-    SKP_Silk_range_encoder_multi( psRC, psEncCtrlC->NLSFIndices, psNLSF_CB->StartPtr, psNLSF_CB->nStages );\r
+    for( i = 0; i < psNLSF_CB->nStages; i++ ) {\r
+        ec_encode_bin( psRangeEnc, psNLSF_CB->StartPtr[ i ][ psEncCtrlC->NLSFIndices[ i ] ], \r
+            psNLSF_CB->StartPtr[ i ][ psEncCtrlC->NLSFIndices[ i ] + 1 ], 16 );\r
+    }\r
 \r
     /* Encode NLSF interpolation factor */\r
     SKP_assert( psEncC->useInterpolatedNLSFs == 1 || psEncCtrlC->NLSFInterpCoef_Q2 == ( 1 << 2 ) );\r
-    SKP_Silk_range_encoder( psRC, psEncCtrlC->NLSFInterpCoef_Q2, SKP_Silk_NLSF_interpolation_factor_CDF );\r
+    ec_encode_bin( psRangeEnc, SKP_Silk_NLSF_interpolation_factor_CDF[ psEncCtrlC->NLSFInterpCoef_Q2 ], \r
+        SKP_Silk_NLSF_interpolation_factor_CDF[ psEncCtrlC->NLSFInterpCoef_Q2 + 1 ], 16 );\r
 \r
 #ifdef SAVE_ALL_INTERNAL_DATA\r
-    SKP_Silk_range_encoder_get_length( psRC, &nBytes_after );\r
+    nBytes_after = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );\r
     nBytes_after -= nBytes_before; // bytes just added\r
     DEBUG_STORE_DATA( nBytes_LSF.dat, &nBytes_after, sizeof( SKP_int ) );\r
 #endif\r
@@ -134,7 +143,7 @@ void SKP_Silk_encode_parameters_v4(
         /* Encode pitch lags */\r
         /*********************/\r
 #ifdef SAVE_ALL_INTERNAL_DATA\r
-        SKP_Silk_range_encoder_get_length( psRC, &nBytes_before );\r
+        nBytes_before = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );\r
 #endif\r
         /* lag index */\r
         encode_absolute_lagIndex = 1;\r
@@ -149,40 +158,47 @@ void SKP_Silk_encode_parameters_v4(
                 delta_lagIndex = delta_lagIndex + MAX_DELTA_LAG;\r
                 encode_absolute_lagIndex = 0; /* Only use delta */\r
             }\r
-            SKP_Silk_range_encoder( psRC, delta_lagIndex, SKP_Silk_pitch_delta_CDF );\r
+            ec_encode_bin( psRangeEnc, SKP_Silk_pitch_delta_CDF[ delta_lagIndex ], \r
+                SKP_Silk_pitch_delta_CDF[ delta_lagIndex + 1 ], 16 );\r
         }\r
         if( encode_absolute_lagIndex ) {\r
             /* Absolute encoding */\r
             if( psEncC->fs_kHz == 8 ) {\r
-                SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_NB_CDF );\r
+                ec_encode_bin( psRangeEnc, SKP_Silk_pitch_lag_NB_CDF[ psEncCtrlC->lagIndex ], \r
+                    SKP_Silk_pitch_lag_NB_CDF[ psEncCtrlC->lagIndex + 1 ], 16 );\r
             } else if( psEncC->fs_kHz == 12 ) {\r
-                SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_MB_CDF );\r
+                ec_encode_bin( psRangeEnc, SKP_Silk_pitch_lag_MB_CDF[ psEncCtrlC->lagIndex ], \r
+                    SKP_Silk_pitch_lag_MB_CDF[ psEncCtrlC->lagIndex + 1 ], 16 );\r
             } else if( psEncC->fs_kHz == 16 ) {\r
-                SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_WB_CDF );\r
+                ec_encode_bin( psRangeEnc, SKP_Silk_pitch_lag_WB_CDF[ psEncCtrlC->lagIndex ], \r
+                    SKP_Silk_pitch_lag_WB_CDF[ psEncCtrlC->lagIndex + 1 ], 16 );\r
             } else {\r
-                SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_SWB_CDF );\r
+                ec_encode_bin( psRangeEnc, SKP_Silk_pitch_lag_SWB_CDF[ psEncCtrlC->lagIndex ], \r
+                    SKP_Silk_pitch_lag_SWB_CDF[ psEncCtrlC->lagIndex + 1 ], 16 );\r
             }\r
         }\r
         psEncC->prev_lagIndex = psEncCtrlC->lagIndex;\r
 \r
 #ifdef SAVE_ALL_INTERNAL_DATA\r
-        SKP_Silk_range_encoder_get_length( psRC, &nBytes_after );\r
+        nBytes_after = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );\r
         nBytes_lagIndex = nBytes_after - nBytes_before; // bytes just added\r
 #endif\r
 \r
 #ifdef SAVE_ALL_INTERNAL_DATA\r
-        SKP_Silk_range_encoder_get_length( psRC, &nBytes_before );\r
+        nBytes_before = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );\r
 #endif\r
         /* countour index */\r
         if( psEncC->fs_kHz == 8 ) {\r
             /* Less codevectors used in 8 khz mode */\r
-            SKP_Silk_range_encoder( psRC, psEncCtrlC->contourIndex, SKP_Silk_pitch_contour_NB_CDF );\r
+            ec_encode_bin( psRangeEnc, SKP_Silk_pitch_contour_NB_CDF[ psEncCtrlC->contourIndex ], \r
+                SKP_Silk_pitch_contour_NB_CDF[ psEncCtrlC->contourIndex + 1 ], 16 );\r
         } else {\r
             /* Joint for 12, 16, 24 khz */\r
-            SKP_Silk_range_encoder( psRC, psEncCtrlC->contourIndex, SKP_Silk_pitch_contour_CDF );\r
+            ec_encode_bin( psRangeEnc, SKP_Silk_pitch_contour_CDF[ psEncCtrlC->contourIndex ], \r
+                SKP_Silk_pitch_contour_CDF[ psEncCtrlC->contourIndex + 1 ], 16 );\r
         }\r
 #ifdef SAVE_ALL_INTERNAL_DATA\r
-        SKP_Silk_range_encoder_get_length( psRC, &nBytes_after ); \r
+        nBytes_after = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );\r
         nBytes_contourIndex = nBytes_after - nBytes_before; // bytes just added\r
 #endif\r
 \r
@@ -190,22 +206,25 @@ void SKP_Silk_encode_parameters_v4(
         /* Encode LTP gains */\r
         /********************/\r
 #ifdef SAVE_ALL_INTERNAL_DATA\r
-        SKP_Silk_range_encoder_get_length( psRC, &nBytes_before );\r
+        nBytes_before = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );\r
 #endif\r
         /* PERIndex value */\r
-        SKP_Silk_range_encoder( psRC, psEncCtrlC->PERIndex, SKP_Silk_LTP_per_index_CDF );\r
+        ec_encode_bin( psRangeEnc, SKP_Silk_LTP_per_index_CDF[ psEncCtrlC->PERIndex ], \r
+            SKP_Silk_LTP_per_index_CDF[ psEncCtrlC->PERIndex + 1 ], 16 );\r
 \r
         /* Codebook Indices */\r
         for( k = 0; k < psEncC->nb_subfr; k++ ) {\r
-            SKP_Silk_range_encoder( psRC, psEncCtrlC->LTPIndex[ k ], SKP_Silk_LTP_gain_CDF_ptrs[ psEncCtrlC->PERIndex ] );\r
+            ec_encode_bin( psRangeEnc, SKP_Silk_LTP_gain_CDF_ptrs[ psEncCtrlC->PERIndex ][ psEncCtrlC->LTPIndex[ k ] ], \r
+                SKP_Silk_LTP_gain_CDF_ptrs[ psEncCtrlC->PERIndex ][ psEncCtrlC->LTPIndex[ k ] + 1 ], 16 );\r
         }\r
 \r
         /**********************/\r
         /* Encode LTP scaling */\r
         /**********************/\r
-        SKP_Silk_range_encoder( psRC, psEncCtrlC->LTP_scaleIndex, SKP_Silk_LTPscale_CDF );\r
+        ec_encode_bin( psRangeEnc, SKP_Silk_LTPscale_CDF[ psEncCtrlC->LTP_scaleIndex ], \r
+            SKP_Silk_LTPscale_CDF[ psEncCtrlC->LTP_scaleIndex + 1 ], 16 );\r
 #ifdef SAVE_ALL_INTERNAL_DATA\r
-        SKP_Silk_range_encoder_get_length( psRC, &nBytes_after );\r
+        nBytes_after = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );\r
         nBytes_LTP = nBytes_after - nBytes_before; // bytes just added\r
 #endif\r
     }\r
@@ -222,11 +241,12 @@ void SKP_Silk_encode_parameters_v4(
 #endif\r
 \r
 #ifdef SAVE_ALL_INTERNAL_DATA\r
-    SKP_Silk_range_encoder_get_length( psRC, &nBytes_before );\r
+    nBytes_before = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );\r
 #endif\r
 \r
     /***************/\r
     /* Encode seed */\r
     /***************/\r
-    SKP_Silk_range_encoder( psRC, psEncCtrlC->Seed, SKP_Silk_Seed_CDF );\r
+    ec_encode_bin( psRangeEnc, SKP_Silk_Seed_CDF[ psEncCtrlC->Seed ], \r
+        SKP_Silk_Seed_CDF[ psEncCtrlC->Seed + 1 ], 16 );\r
 }\r
index 8292337..80ce453 100644 (file)
@@ -71,11 +71,11 @@ SKP_INLINE SKP_int combine_and_check(       /* return ok */
 \r
 /* Encode quantization indices of excitation */\r
 void SKP_Silk_encode_pulses(\r
-    SKP_Silk_range_coder_state      *psRC,          /* I/O  Range coder state               */\r
-    const SKP_int                   sigtype,        /* I    Sigtype                         */\r
-    const SKP_int                   QuantOffsetType,/* I    QuantOffsetType                 */\r
-    SKP_int8                        q[],            /* I    quantization indices            */\r
-    const SKP_int                   frame_length    /* I    Frame length                    */\r
+    ec_enc                      *psRangeEnc,        /* I/O  compressor data structure                   */\r
+    const SKP_int               sigtype,            /* I    Sigtype                                     */\r
+    const SKP_int               QuantOffsetType,    /* I    QuantOffsetType                             */\r
+    SKP_int8                    q[],                /* I    quantization indices                        */\r
+    const SKP_int               frame_length        /* I    Frame length                                */\r
 )\r
 {\r
     SKP_int   i, k, j, iter, bit, nLS, scale_down, RateLevelIndex = 0;\r
@@ -167,7 +167,8 @@ void SKP_Silk_encode_pulses(
             RateLevelIndex = k;\r
         }\r
     }\r
-    SKP_Silk_range_encoder( psRC, RateLevelIndex, SKP_Silk_rate_levels_CDF[ sigtype ] );\r
+    ec_encode_bin( psRangeEnc, SKP_Silk_rate_levels_CDF[ sigtype ][ RateLevelIndex ], \r
+        SKP_Silk_rate_levels_CDF[ sigtype ][ RateLevelIndex + 1 ], 16 );\r
 \r
     /***************************************************/\r
     /* Sum-Weighted-Pulses Encoding                    */\r
@@ -175,13 +176,15 @@ void SKP_Silk_encode_pulses(
     cdf_ptr = SKP_Silk_pulses_per_block_CDF[ RateLevelIndex ];\r
     for( i = 0; i < iter; i++ ) {\r
         if( nRshifts[ i ] == 0 ) {\r
-            SKP_Silk_range_encoder( psRC, sum_pulses[ i ], cdf_ptr );\r
+            ec_encode_bin( psRangeEnc, cdf_ptr[ sum_pulses[ i ] ], cdf_ptr[ sum_pulses[ i ] + 1 ], 16 );\r
         } else {\r
-            SKP_Silk_range_encoder( psRC, MAX_PULSES + 1, cdf_ptr );\r
+            ec_encode_bin( psRangeEnc, cdf_ptr[ MAX_PULSES + 1 ], cdf_ptr[ MAX_PULSES + 2 ], 16 );\r
             for( k = 0; k < nRshifts[ i ] - 1; k++ ) {\r
-                SKP_Silk_range_encoder( psRC, MAX_PULSES + 1, SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS - 1 ] );\r
+                ec_encode_bin( psRangeEnc, SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS - 1 ][ sum_pulses[ i ] ], \r
+                    SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS - 1 ][ sum_pulses[ i ] + 1 ], 16 );\r
             }\r
-            SKP_Silk_range_encoder( psRC, sum_pulses[ i ], SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS - 1 ] );\r
+            ec_encode_bin( psRangeEnc, SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS - 1 ][ sum_pulses[ i ] ], \r
+                SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS - 1 ][ sum_pulses[ i ] + 1 ], 16 );\r
         }\r
     }\r
 \r
@@ -190,7 +193,7 @@ void SKP_Silk_encode_pulses(
     /******************/\r
     for( i = 0; i < iter; i++ ) {\r
         if( sum_pulses[ i ] > 0 ) {\r
-            SKP_Silk_shell_encoder( psRC, &abs_pulses[ i * SHELL_CODEC_FRAME_LENGTH ] );\r
+            SKP_Silk_shell_encoder( psRangeEnc, &abs_pulses[ i * SHELL_CODEC_FRAME_LENGTH ] );\r
         }\r
     }\r
 \r
@@ -205,10 +208,10 @@ void SKP_Silk_encode_pulses(
                 abs_q = (SKP_int8)SKP_abs( pulses_ptr[ k ] );\r
                 for( j = nLS; j > 0; j-- ) {\r
                     bit = SKP_RSHIFT( abs_q, j ) & 1;\r
-                    SKP_Silk_range_encoder( psRC, bit, SKP_Silk_lsb_CDF );\r
+                    ec_enc_bit_prob( psRangeEnc, bit, 65536 - SKP_Silk_lsb_CDF[ 1 ] );\r
                 }\r
                 bit = abs_q & 1;\r
-                SKP_Silk_range_encoder( psRC, bit, SKP_Silk_lsb_CDF );\r
+                ec_enc_bit_prob( psRangeEnc, bit, 65536 - SKP_Silk_lsb_CDF[ 1 ] );\r
             }\r
         }\r
     }\r
@@ -217,6 +220,6 @@ void SKP_Silk_encode_pulses(
     /****************/\r
     /* Encode signs */\r
     /****************/\r
-    SKP_Silk_encode_signs( psRC, q, frame_length, sigtype, QuantOffsetType, RateLevelIndex );\r
+    SKP_Silk_encode_signs( psRangeEnc, q, frame_length, sigtype, QuantOffsetType, RateLevelIndex );\r
 #endif\r
 }\r
index eddcddc..f9610cf 100644 (file)
@@ -44,7 +44,7 @@ extern "C"
 \r
 /* Encodes signs of excitation */\r
 void SKP_Silk_encode_signs(\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */\r
+    ec_enc                      *psRangeEnc,        /* I/O  Compressor data structure                   */\r
     const SKP_int8              q[],                /* I    pulse signal                                */\r
     const SKP_int               length,             /* I    length of input                             */\r
     const SKP_int               sigtype,            /* I    Signal type                                 */\r
@@ -54,7 +54,7 @@ void SKP_Silk_encode_signs(
 \r
 /* Decodes signs of excitation */\r
 void SKP_Silk_decode_signs(\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */\r
+    ec_dec                      *psRangeDec,        /* I/O  Compressor data structure                   */\r
     SKP_int                     q[],                /* I/O  pulse signal                                */\r
     const SKP_int               length,             /* I    length of output                            */\r
     const SKP_int               sigtype,            /* I    Signal type                                 */\r
@@ -68,7 +68,7 @@ void SKP_Silk_decode_signs(
 \r
 /* Encode quantization indices of excitation */\r
 void SKP_Silk_encode_pulses(\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */\r
+    ec_enc                      *psRangeEnc,        /* I/O  compressor data structure                   */\r
     const SKP_int               sigtype,            /* I    Sigtype                                     */\r
     const SKP_int               QuantOffsetType,    /* I    QuantOffsetType                             */\r
     SKP_int8                    q[],                /* I    quantization indices                        */\r
@@ -77,95 +77,28 @@ void SKP_Silk_encode_pulses(
 \r
 /* Shell encoder, operates on one shell code frame of 16 pulses */\r
 void SKP_Silk_shell_encoder(\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */\r
+    ec_enc                      *psRangeEnc,        /* I/O  compressor data structure                   */\r
     const SKP_int               *pulses0            /* I    data: nonnegative pulse amplitudes          */\r
 );\r
 \r
 /* Shell decoder, operates on one shell code frame of 16 pulses */\r
 void SKP_Silk_shell_decoder(\r
     SKP_int                     *pulses0,           /* O    data: nonnegative pulse amplitudes          */\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */\r
+    ec_dec                      *psRangeDec,        /* I/O  Compressor data structure                   */\r
     const SKP_int               pulses4             /* I    number of pulses per pulse-subframe         */\r
 );\r
 \r
 /***************/\r
 /* Range coder */\r
 /***************/\r
-/* Range encoder for one symbol */\r
-void SKP_Silk_range_encoder(\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */\r
-    const SKP_int               data,               /* I    uncompressed data                           */\r
-    const SKP_uint16            prob[]              /* I    cumulative density functions                */\r
-);\r
-    \r
-/* Range encoder for one symbol, with uniform PDF*/\r
-void SKP_Silk_range_encode_uniform(\r
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */\r
-    const SKP_int                   data,               /* I    uncompressed data                           */\r
-    const SKP_int                   N                   /* I    number of possible outcomes                 */\r
-);\r
-\r
-/* Range encoder for multiple symbols */\r
-void SKP_Silk_range_encoder_multi(\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */\r
-    const SKP_int               data[],             /* I    uncompressed data    [nSymbols]             */\r
-    const SKP_uint16 * const    prob[],             /* I    cumulative density functions                */\r
-    const SKP_int               nSymbols            /* I    number of data symbols                      */\r
-);\r
-\r
 /* Range decoder for one symbol */\r
 void SKP_Silk_range_decoder(\r
     SKP_int                     data[],             /* O    uncompressed data                           */\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */\r
+    ec_dec                      *psRangeDec,        /* I/O  Compressor data structure                   */\r
     const SKP_uint16            prob[],             /* I    cumulative density function                 */\r
     SKP_int                     probIx              /* I    initial (middle) entry of cdf               */\r
 );\r
 \r
-/* Range decoder for one symbol, with uniform PDF*/\r
-void SKP_Silk_range_decode_uniform(\r
-    SKP_int                         data[],             /* O    uncompressed data                           */\r
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */\r
-    const SKP_int                   N                   /* I    number of possible outcomes                 */\r
-);\r
-\r
-/* Range decoder for multiple symbols */\r
-void SKP_Silk_range_decoder_multi(\r
-    SKP_int                     data[],             /* O    uncompressed data                [nSymbols] */\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */\r
-    const SKP_uint16 * const    prob[],             /* I    cumulative density functions                */\r
-    const SKP_int               probStartIx[],      /* I    initial (middle) entries of cdfs [nSymbols] */\r
-    const SKP_int               nSymbols            /* I    number of data symbols                      */\r
-);\r
-\r
-/* Initialize range coder structure for encoder */\r
-void SKP_Silk_range_enc_init(\r
-    SKP_Silk_range_coder_state  *psRC               /* O    compressor data structure                   */\r
-);\r
-\r
-/* Initialize range coder structure for decoder */\r
-void SKP_Silk_range_dec_init(\r
-    SKP_Silk_range_coder_state  *psRC,              /* O    compressor data structure                   */\r
-    const SKP_uint8             buffer[],           /* I    buffer for compressed data [bufferLength]   */\r
-    const SKP_int32             bufferLength        /* I    buffer length (in bytes)                    */\r
-);\r
-\r
-/* Determine length of bitstream */\r
-SKP_int SKP_Silk_range_encoder_get_length(          /* O    returns number of BITS in stream            */\r
-    SKP_Silk_range_coder_state          *psRC,      /* I    compressed data structure                   */\r
-    SKP_int                             *nBytes     /* O    number of BYTES in stream                   */\r
-);\r
-\r
-/* Determine length of bitstream */\r
-SKP_int SKP_Silk_range_decoder_get_length(          /* O    returns number of BITS in stream            */\r
-    SKP_Silk_range_coder_state          *psRC,      /* I    compressed data structure                   */\r
-    SKP_int                             *nBytes     /* O    number of BYTES in stream                   */\r
-);\r
-\r
-/* Check that any remaining bits in the last byte are set to 1 */\r
-void SKP_Silk_range_coder_check_after_decoding(\r
-    SKP_Silk_range_coder_state  *psRC               /* I/O  compressed data structure                   */\r
-);\r
-\r
 /* Gain scalar quantization with hysteresis, uniform on log scale */\r
 void SKP_Silk_gains_quant(\r
     SKP_int                         ind[ MAX_NB_SUBFR ],        /* O    gain indices                            */\r
@@ -311,23 +244,25 @@ void SKP_Silk_decoder_set_fs(
 /****************/\r
 SKP_int SKP_Silk_decode_frame(\r
     SKP_Silk_decoder_state      *psDec,             /* I/O  Pointer to Silk decoder state               */\r
+    ec_dec                      *psRangeDec,        /* I/O  Compressor data structure                   */\r
     SKP_int16                   pOut[],             /* O    Pointer to output speech frame              */\r
     SKP_int16                   *pN,                /* O    Pointer to size of output frame             */\r
-    const SKP_uint8             pCode[],            /* I    Pointer to payload                          */\r
     const SKP_int               nBytes,             /* I    Payload length                              */\r
     SKP_int                     action,             /* I    Action from Jitter Buffer                   */\r
     SKP_int                     *decBytes           /* O    Used bytes to decode this frame             */\r
 );\r
 \r
 /* Decode indices from payload v4 Bitstream */\r
-void SKP_Silk_decode_indices_v4(\r
-    SKP_Silk_decoder_state      *psDec              /* I/O  State                                       */\r
+void SKP_Silk_decode_indices(\r
+    SKP_Silk_decoder_state      *psDec,             /* I/O  State                                       */\r
+    ec_dec                      *psRangeDec         /* I/O  Compressor data structure                   */\r
 );\r
 \r
 /* Decode parameters from payload v4 Bitstream */\r
-void SKP_Silk_decode_parameters_v4(\r
+void SKP_Silk_decode_parameters(\r
     SKP_Silk_decoder_state      *psDec,                                 /* I/O  State                                    */\r
     SKP_Silk_decoder_control    *psDecCtrl,                             /* I/O  Decoder control                          */\r
+    ec_dec                      *psRangeDec,                            /* I/O  Compressor data structure                */\r
     SKP_int                     q[ MAX_FRAME_LENGTH ],                  /* O    Excitation signal                        */\r
     const SKP_int               fullDecoding                            /* I    Flag to tell if only arithmetic decoding */\r
 );\r
@@ -354,7 +289,7 @@ void SKP_Silk_NLSF_MSVQ_decode(
 \r
 /* Decode quantization indices of excitation (Shell coding) */\r
 void SKP_Silk_decode_pulses(\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */\r
+    ec_dec                      *psRangeDec,        /* I/O  Compressor data structure                   */\r
     SKP_Silk_decoder_control    *psDecCtrl,         /* I/O  Decoder control                             */\r
     SKP_int                     q[],                /* O    Excitation signal                           */\r
     const SKP_int               frame_length        /* I    Frame length (preliminary)                  */\r
@@ -378,10 +313,10 @@ void SKP_Silk_CNG(
 );\r
 \r
 /* Encoding of various parameters */\r
-void SKP_Silk_encode_parameters_v4(\r
+void SKP_Silk_encode_parameters(\r
     SKP_Silk_encoder_state      *psEncC,            /* I/O  Encoder state                               */\r
     SKP_Silk_encoder_control    *psEncCtrlC,        /* I/O  Encoder control                             */\r
-    SKP_Silk_range_coder_state  *psRC               /* I/O  Range encoder state                         */\r
+    ec_enc                      *psRangeEnc         /* I/O  Compressor data structure                   */\r
 );\r
 \r
 /* Extract lowest layer encoding */\r
index a9dcc7e..b731f19 100644 (file)
@@ -27,77 +27,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 \r
 #include "SKP_Silk_main.h"\r
 \r
-#define MAX_SIZE 10000\r
-\r
-/* Range encoder for one symbol */\r
-void SKP_Silk_range_encoder(\r
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */\r
-    const SKP_int                   data,               /* I    uncompressed data                           */\r
-    const SKP_uint16                prob[]              /* I    cumulative density functions                */\r
-)\r
-{\r
-    SKP_uint32 low_Q16, high_Q16;\r
-\r
-    if( psRC->error ) {\r
-        return;\r
-    }\r
-    low_Q16  = prob[ data ];\r
-    high_Q16 = prob[ data + 1 ];\r
-    \r
-#ifdef SAVE_ALL_INTERNAL_DATA\r
-    DEBUG_STORE_DATA( enc_l.dat, &low_Q16,  sizeof(SKP_uint32) );\r
-    DEBUG_STORE_DATA( enc_h.dat, &high_Q16, sizeof(SKP_uint32) );\r
-    DEBUG_STORE_DATA( enc.dat,   &data,     sizeof(SKP_int) );\r
-#endif\r
-\r
-    if( prob[ 2 ] == 65535 ) {\r
-        /* Instead of detection, we could add a separate function and call when we know that input is a bit */\r
-        ec_enc_bit_prob( &psRC->range_enc_celt_state, data, 65536 - prob[ 1 ] );\r
-    } else {\r
-        ec_encode_bin( &psRC->range_enc_celt_state, low_Q16, high_Q16, 16 );\r
-    }\r
-}\r
-\r
-/* Range encoder for one symbol, with uniform PDF*/\r
-void SKP_Silk_range_encode_uniform(\r
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */\r
-    const SKP_int                   data,               /* I    uncompressed data                           */\r
-    const SKP_int                   N                   /* I    number of possible outcomes                 */\r
-)\r
-{\r
-    SKP_int i;\r
-    SKP_uint16 delta, prob[ MAX_SIZE + 1 ];\r
-\r
-    SKP_assert( N < MAX_SIZE );\r
-\r
-    delta = ( SKP_uint16 )SKP_DIV32_16( 65535, N );\r
-    prob[ 0 ] = 0;\r
-    for( i = 0; i < N - 1; i++ ) {\r
-        prob[ i + 1 ] = prob[ i ] + delta;\r
-    }\r
-    prob[ N ] = 65535;\r
-\r
-    SKP_Silk_range_encoder( psRC, data, prob );\r
-}\r
-\r
-/* Range encoder for multiple symbols */\r
-void SKP_Silk_range_encoder_multi(\r
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */\r
-    const SKP_int                   data[],             /* I    uncompressed data    [nSymbols]             */\r
-    const SKP_uint16 * const        prob[],             /* I    cumulative density functions                */\r
-    const SKP_int                   nSymbols            /* I    number of data symbols                      */\r
-)\r
-{\r
-    SKP_int k;\r
-    for( k = 0; k < nSymbols; k++ ) {\r
-        SKP_Silk_range_encoder( psRC, data[ k ], prob[ k ] );\r
-    }\r
-}\r
-\r
 /* Range decoder for one symbol */\r
 void SKP_Silk_range_decoder(\r
     SKP_int                         data[],             /* O    uncompressed data                           */\r
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */\r
+    ec_dec                          *psRangeDec,        /* I/O  Compressor data structure                   */\r
     const SKP_uint16                prob[],             /* I    cumulative density function                 */\r
     SKP_int                         probIx              /* I    initial (middle) entry of cdf               */\r
 )\r
@@ -107,21 +40,12 @@ void SKP_Silk_range_decoder(
     SKP_uint32 low_Q16_returned;\r
     SKP_int    temp;\r
 \r
-    if( psRC->error ) {\r
-        /* Set output to zero */\r
-        *data = 0;\r
-        return;\r
-    }\r
-\r
     if( prob[ 2 ] == 65535 ) {\r
         /* Instead of detection, we could add a separate function and call when we know that output is a bit */\r
-        *data = ec_dec_bit_prob( &psRC->range_dec_celt_state, 65536 - prob[ 1 ] );\r
+        *data = ec_dec_bit_prob( psRangeDec, 65536 - prob[ 1 ] );\r
     } else {\r
-        low_Q16_returned = ec_decode_bin( &psRC->range_dec_celt_state, 16 );\r
-    }\r
+        low_Q16_returned = ec_decode_bin( psRangeDec, 16 );\r
 \r
-    /* OPTIMIZE ME WITH BI-SECTION */\r
-    if( prob[ 2 ] != 65535 ) {\r
 #if 1\r
         temp = 0;\r
         while( low_Q16_returned >= prob[ ++temp ] ) {}\r
@@ -150,141 +74,9 @@ void SKP_Silk_range_decoder(
         DEBUG_STORE_DATA( dec_l.dat,  &low_Q16,           sizeof( SKP_uint32 ) );\r
         DEBUG_STORE_DATA( dec_h.dat,  &high_Q16,          sizeof( SKP_uint32 ) );\r
 #endif  \r
-        ec_dec_update( &psRC->range_dec_celt_state, low_Q16, high_Q16,( 1 << 16 ) );\r
+        ec_dec_update( psRangeDec, low_Q16, high_Q16,( 1 << 16 ) );\r
     }\r
 #ifdef SAVE_ALL_INTERNAL_DATA\r
     DEBUG_STORE_DATA( dec.dat, data, sizeof( SKP_int ) );\r
 #endif\r
 }\r
-\r
-/* Range decoder for one symbol, with uniform PDF*/\r
-void SKP_Silk_range_decode_uniform(\r
-    SKP_int                         data[],             /* O    uncompressed data                           */\r
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */\r
-    const SKP_int                   N                   /* I    number of possible outcomes                 */\r
-)\r
-{\r
-    SKP_int i;\r
-    SKP_uint16 delta, prob[ MAX_SIZE + 1 ];\r
-\r
-    SKP_assert( N < MAX_SIZE );\r
-\r
-    delta = ( SKP_uint16 )SKP_DIV32_16( 65535, N );\r
-    prob[ 0 ] = 0;\r
-    for( i = 0; i < N - 1; i++ ) {\r
-        prob[ i + 1 ] = prob[ i ] + delta;\r
-    }\r
-    prob[ N ] = 65535;\r
-\r
-    SKP_Silk_range_decoder( data, psRC, prob, ( N >> 1 ) );\r
-}\r
-\r
-/* Range decoder for multiple symbols */\r
-void SKP_Silk_range_decoder_multi(\r
-    SKP_int                         data[],             /* O    uncompressed data                [nSymbols] */\r
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */\r
-    const SKP_uint16 * const        prob[],             /* I    cumulative density functions                */\r
-    const SKP_int                   probStartIx[],      /* I    initial (middle) entries of cdfs [nSymbols] */\r
-    const SKP_int                   nSymbols            /* I    number of data symbols                      */\r
-)\r
-{\r
-    SKP_int k;\r
-    for( k = 0; k < nSymbols; k++ ) {\r
-        SKP_Silk_range_decoder( &data[ k ], psRC, prob[ k ], probStartIx[ k ] );\r
-    }\r
-}\r
-\r
-/* Initialize range encoder */\r
-void SKP_Silk_range_enc_init(\r
-    SKP_Silk_range_coder_state      *psRC               /* O    compressor data structure                   */\r
-)\r
-{\r
-    psRC->error        = 0;\r
-}\r
-\r
-/* Initialize range decoder */\r
-void SKP_Silk_range_dec_init(\r
-    SKP_Silk_range_coder_state      *psRC,              /* O    compressor data structure                   */\r
-    const SKP_uint8                 buffer[],           /* I    buffer for compressed data [bufferLength]   */\r
-    const SKP_int32                 bufferLength        /* I    buffer length (in bytes)                    */\r
-)\r
-{\r
-    /* check input */\r
-    if( bufferLength > MAX_ARITHM_BYTES ) {\r
-        psRC->error = RANGE_CODER_DEC_PAYLOAD_TOO_LONG;\r
-        return;\r
-    }\r
-    /* Initialize structure */\r
-    /* Copy to internal buffer */\r
-    SKP_memcpy( psRC->buffer, buffer, bufferLength * sizeof( SKP_uint8 ) ); \r
-    psRC->bufferLength = bufferLength;\r
-    psRC->bufferIx = 0;\r
-    psRC->base_Q32 = \r
-        SKP_LSHIFT_uint( ( SKP_uint32 )buffer[ 0 ], 24 ) | \r
-        SKP_LSHIFT_uint( ( SKP_uint32 )buffer[ 1 ], 16 ) | \r
-        SKP_LSHIFT_uint( ( SKP_uint32 )buffer[ 2 ],  8 ) | \r
-                         ( SKP_uint32 )buffer[ 3 ];\r
-    psRC->range_Q16 = 0x0000FFFF;\r
-    psRC->error     = 0;\r
-}\r
-\r
-/* Determine length of bitstream */\r
-SKP_int SKP_Silk_range_encoder_get_length(              /* O    returns number of BITS in stream            */\r
-    SKP_Silk_range_coder_state          *psRC,          /* I    compressed data structure                   */\r
-    SKP_int                             *nBytes         /* O    number of BYTES in stream                   */\r
-)\r
-{\r
-    SKP_int nBits;\r
-\r
-    /* Get number of bits in bitstream */\r
-    nBits = ec_enc_tell( &psRC->range_enc_celt_state, 0 );\r
-\r
-    /* Round up to an integer number of bytes */\r
-    *nBytes = SKP_RSHIFT( nBits + 7, 3 );\r
-\r
-    /* Return number of bits in bitstream */\r
-    return nBits;\r
-}\r
-\r
-/* Determine length of bitstream */\r
-SKP_int SKP_Silk_range_decoder_get_length(              /* O    returns number of BITS in stream            */\r
-    SKP_Silk_range_coder_state          *psRC,          /* I    compressed data structure                   */\r
-    SKP_int                             *nBytes         /* O    number of BYTES in stream                   */\r
-)\r
-{\r
-    SKP_int nBits;\r
-\r
-    /* Get number of bits in bitstream */\r
-    nBits = ec_dec_tell( &psRC->range_dec_celt_state, 0 );\r
-\r
-    /* Round up to an integer number of bytes */\r
-    *nBytes = SKP_RSHIFT( nBits + 7, 3 );\r
-\r
-    /* Return number of bits in bitstream */\r
-    return nBits;\r
-}\r
-\r
-/* Check that any remaining bits in the last byte are set to 1 */\r
-void SKP_Silk_range_coder_check_after_decoding(\r
-    SKP_Silk_range_coder_state      *psRC               /* I/O  compressed data structure                   */\r
-)\r
-{\r
-    SKP_int bits_in_stream, nBytes, mask;\r
-\r
-    bits_in_stream = SKP_Silk_range_decoder_get_length( psRC, &nBytes );\r
-\r
-    /* Make sure not to read beyond buffer */\r
-    if( nBytes - 1 >= psRC->range_dec_celt_state.buf->storage ) {\r
-        psRC->error = RANGE_CODER_DECODER_CHECK_FAILED;\r
-        return;\r
-    }\r
-\r
-    /* Test any remaining bits in last byte */\r
-    if( bits_in_stream & 7 ) {\r
-        mask = SKP_RSHIFT( 0xFF, bits_in_stream & 7 );\r
-        if( ( psRC->range_dec_celt_state.buf->buf[ nBytes - 1 ] & mask ) != mask ) {\r
-            psRC->error = RANGE_CODER_DECODER_CHECK_FAILED;\r
-            return;\r
-        }\r
-    }\r
-}\r
index 8e39582..15a2628 100644 (file)
@@ -42,7 +42,7 @@ SKP_INLINE void combine_pulses(
 }\r
 \r
 SKP_INLINE void encode_split(\r
-    SKP_Silk_range_coder_state  *sRC,           /* I/O: compressor data structure                   */\r
+    ec_enc                      *psRangeEnc,    /* I/O  compressor data structure                   */\r
     const SKP_int               p_child1,       /* I:   pulse amplitude of first child subframe     */\r
     const SKP_int               p,              /* I:   pulse amplitude of current subframe         */\r
     const SKP_uint16            *shell_table    /* I:   table of shell cdfs                         */\r
@@ -52,14 +52,18 @@ SKP_INLINE void encode_split(
 \r
     if( p > 0 ) {\r
         cdf = &shell_table[ SKP_Silk_shell_code_table_offsets[ p ] ];\r
-        SKP_Silk_range_encoder( sRC, p_child1, cdf );\r
+        if( cdf[ 2 ] == 65535 ) {\r
+            ec_enc_bit_prob( psRangeEnc, p_child1, 65536 - cdf[ 1 ] );\r
+        } else {\r
+            ec_encode_bin( psRangeEnc, cdf[ p_child1 ], cdf[ p_child1 + 1 ], 16 );\r
+        }\r
     }\r
 }\r
 \r
 SKP_INLINE void decode_split(\r
     SKP_int                     *p_child1,      /* O:   pulse amplitude of first child subframe     */\r
     SKP_int                     *p_child2,      /* O:   pulse amplitude of second child subframe    */\r
-    SKP_Silk_range_coder_state  *sRC,           /* I/O: compressor data structure                   */\r
+    ec_dec                      *psRangeDec,    /* I/O  Compressor data structure                   */\r
     const SKP_int               p,              /* I:   pulse amplitude of current subframe         */\r
     const SKP_uint16            *shell_table    /* I:   table of shell cdfs                         */\r
 )\r
@@ -70,7 +74,7 @@ SKP_INLINE void decode_split(
     if( p > 0 ) {\r
         cdf_middle = SKP_RSHIFT( p, 1 );\r
         cdf = &shell_table[ SKP_Silk_shell_code_table_offsets[ p ] ];\r
-        SKP_Silk_range_decoder( p_child1, sRC, cdf, cdf_middle );\r
+        SKP_Silk_range_decoder( p_child1, psRangeDec, cdf, cdf_middle );\r
         p_child2[ 0 ] = p - p_child1[ 0 ];\r
     } else {\r
         p_child1[ 0 ] = 0;\r
@@ -80,8 +84,8 @@ SKP_INLINE void decode_split(
 \r
 /* Shell encoder, operates on one shell code frame of 16 pulses */\r
 void SKP_Silk_shell_encoder(\r
-    SKP_Silk_range_coder_state      *sRC,               /* I/O  compressor data structure                   */\r
-    const SKP_int                   *pulses0            /* I    data: nonnegative pulse amplitudes          */\r
+    ec_enc                      *psRangeEnc,        /* I/O  compressor data structure                   */\r
+    const SKP_int               *pulses0            /* I    data: nonnegative pulse amplitudes          */\r
 )\r
 {\r
     SKP_int pulses1[ 8 ], pulses2[ 4 ], pulses3[ 2 ], pulses4[ 1 ];\r
@@ -95,34 +99,34 @@ void SKP_Silk_shell_encoder(
     combine_pulses( pulses3, pulses2, 2 );\r
     combine_pulses( pulses4, pulses3, 1 );\r
 \r
-    encode_split( sRC, pulses3[  0 ], pulses4[ 0 ], SKP_Silk_shell_code_table3 );\r
+    encode_split( psRangeEnc, pulses3[  0 ], pulses4[ 0 ], SKP_Silk_shell_code_table3 );\r
 \r
-    encode_split( sRC, pulses2[  0 ], pulses3[ 0 ], SKP_Silk_shell_code_table2 );\r
+    encode_split( psRangeEnc, pulses2[  0 ], pulses3[ 0 ], SKP_Silk_shell_code_table2 );\r
 \r
-    encode_split( sRC, pulses1[  0 ], pulses2[ 0 ], SKP_Silk_shell_code_table1 );\r
-    encode_split( sRC, pulses0[  0 ], pulses1[ 0 ], SKP_Silk_shell_code_table0 );\r
-    encode_split( sRC, pulses0[  2 ], pulses1[ 1 ], SKP_Silk_shell_code_table0 );\r
+    encode_split( psRangeEnc, pulses1[  0 ], pulses2[ 0 ], SKP_Silk_shell_code_table1 );\r
+    encode_split( psRangeEnc, pulses0[  0 ], pulses1[ 0 ], SKP_Silk_shell_code_table0 );\r
+    encode_split( psRangeEnc, pulses0[  2 ], pulses1[ 1 ], SKP_Silk_shell_code_table0 );\r
 \r
-    encode_split( sRC, pulses1[  2 ], pulses2[ 1 ], SKP_Silk_shell_code_table1 );\r
-    encode_split( sRC, pulses0[  4 ], pulses1[ 2 ], SKP_Silk_shell_code_table0 );\r
-    encode_split( sRC, pulses0[  6 ], pulses1[ 3 ], SKP_Silk_shell_code_table0 );\r
+    encode_split( psRangeEnc, pulses1[  2 ], pulses2[ 1 ], SKP_Silk_shell_code_table1 );\r
+    encode_split( psRangeEnc, pulses0[  4 ], pulses1[ 2 ], SKP_Silk_shell_code_table0 );\r
+    encode_split( psRangeEnc, pulses0[  6 ], pulses1[ 3 ], SKP_Silk_shell_code_table0 );\r
 \r
-    encode_split( sRC, pulses2[  2 ], pulses3[ 1 ], SKP_Silk_shell_code_table2 );\r
+    encode_split( psRangeEnc, pulses2[  2 ], pulses3[ 1 ], SKP_Silk_shell_code_table2 );\r
 \r
-    encode_split( sRC, pulses1[  4 ], pulses2[ 2 ], SKP_Silk_shell_code_table1 );\r
-    encode_split( sRC, pulses0[  8 ], pulses1[ 4 ], SKP_Silk_shell_code_table0 );\r
-    encode_split( sRC, pulses0[ 10 ], pulses1[ 5 ], SKP_Silk_shell_code_table0 );\r
+    encode_split( psRangeEnc, pulses1[  4 ], pulses2[ 2 ], SKP_Silk_shell_code_table1 );\r
+    encode_split( psRangeEnc, pulses0[  8 ], pulses1[ 4 ], SKP_Silk_shell_code_table0 );\r
+    encode_split( psRangeEnc, pulses0[ 10 ], pulses1[ 5 ], SKP_Silk_shell_code_table0 );\r
 \r
-    encode_split( sRC, pulses1[  6 ], pulses2[ 3 ], SKP_Silk_shell_code_table1 );\r
-    encode_split( sRC, pulses0[ 12 ], pulses1[ 6 ], SKP_Silk_shell_code_table0 );\r
-    encode_split( sRC, pulses0[ 14 ], pulses1[ 7 ], SKP_Silk_shell_code_table0 );\r
+    encode_split( psRangeEnc, pulses1[  6 ], pulses2[ 3 ], SKP_Silk_shell_code_table1 );\r
+    encode_split( psRangeEnc, pulses0[ 12 ], pulses1[ 6 ], SKP_Silk_shell_code_table0 );\r
+    encode_split( psRangeEnc, pulses0[ 14 ], pulses1[ 7 ], SKP_Silk_shell_code_table0 );\r
 }\r
 \r
 \r
 /* Shell decoder, operates on one shell code frame of 16 pulses */\r
 void SKP_Silk_shell_decoder(\r
     SKP_int                         *pulses0,           /* O    data: nonnegative pulse amplitudes          */\r
-    SKP_Silk_range_coder_state      *sRC,               /* I/O  compressor data structure                   */\r
+    ec_dec                          *psRangeDec,        /* I/O  Compressor data structure                   */\r
     const SKP_int                   pulses4             /* I    number of pulses per pulse-subframe         */\r
 )\r
 {\r
@@ -131,25 +135,25 @@ void SKP_Silk_shell_decoder(
     /* this function operates on one shell code frame of 16 pulses */\r
     SKP_assert( SHELL_CODEC_FRAME_LENGTH == 16 );\r
 \r
-    decode_split( &pulses3[  0 ], &pulses3[  1 ], sRC, pulses4,      SKP_Silk_shell_code_table3 );\r
+    decode_split( &pulses3[  0 ], &pulses3[  1 ], psRangeDec, pulses4,      SKP_Silk_shell_code_table3 );\r
 \r
-    decode_split( &pulses2[  0 ], &pulses2[  1 ], sRC, pulses3[ 0 ], SKP_Silk_shell_code_table2 );\r
+    decode_split( &pulses2[  0 ], &pulses2[  1 ], psRangeDec, pulses3[ 0 ], SKP_Silk_shell_code_table2 );\r
 \r
-    decode_split( &pulses1[  0 ], &pulses1[  1 ], sRC, pulses2[ 0 ], SKP_Silk_shell_code_table1 );\r
-    decode_split( &pulses0[  0 ], &pulses0[  1 ], sRC, pulses1[ 0 ], SKP_Silk_shell_code_table0 );\r
-    decode_split( &pulses0[  2 ], &pulses0[  3 ], sRC, pulses1[ 1 ], SKP_Silk_shell_code_table0 );\r
+    decode_split( &pulses1[  0 ], &pulses1[  1 ], psRangeDec, pulses2[ 0 ], SKP_Silk_shell_code_table1 );\r
+    decode_split( &pulses0[  0 ], &pulses0[  1 ], psRangeDec, pulses1[ 0 ], SKP_Silk_shell_code_table0 );\r
+    decode_split( &pulses0[  2 ], &pulses0[  3 ], psRangeDec, pulses1[ 1 ], SKP_Silk_shell_code_table0 );\r
 \r
-    decode_split( &pulses1[  2 ], &pulses1[  3 ], sRC, pulses2[ 1 ], SKP_Silk_shell_code_table1 );\r
-    decode_split( &pulses0[  4 ], &pulses0[  5 ], sRC, pulses1[ 2 ], SKP_Silk_shell_code_table0 );\r
-    decode_split( &pulses0[  6 ], &pulses0[  7 ], sRC, pulses1[ 3 ], SKP_Silk_shell_code_table0 );\r
+    decode_split( &pulses1[  2 ], &pulses1[  3 ], psRangeDec, pulses2[ 1 ], SKP_Silk_shell_code_table1 );\r
+    decode_split( &pulses0[  4 ], &pulses0[  5 ], psRangeDec, pulses1[ 2 ], SKP_Silk_shell_code_table0 );\r
+    decode_split( &pulses0[  6 ], &pulses0[  7 ], psRangeDec, pulses1[ 3 ], SKP_Silk_shell_code_table0 );\r
 \r
-    decode_split( &pulses2[  2 ], &pulses2[  3 ], sRC, pulses3[ 1 ], SKP_Silk_shell_code_table2 );\r
+    decode_split( &pulses2[  2 ], &pulses2[  3 ], psRangeDec, pulses3[ 1 ], SKP_Silk_shell_code_table2 );\r
 \r
-    decode_split( &pulses1[  4 ], &pulses1[  5 ], sRC, pulses2[ 2 ], SKP_Silk_shell_code_table1 );\r
-    decode_split( &pulses0[  8 ], &pulses0[  9 ], sRC, pulses1[ 4 ], SKP_Silk_shell_code_table0 );\r
-    decode_split( &pulses0[ 10 ], &pulses0[ 11 ], sRC, pulses1[ 5 ], SKP_Silk_shell_code_table0 );\r
+    decode_split( &pulses1[  4 ], &pulses1[  5 ], psRangeDec, pulses2[ 2 ], SKP_Silk_shell_code_table1 );\r
+    decode_split( &pulses0[  8 ], &pulses0[  9 ], psRangeDec, pulses1[ 4 ], SKP_Silk_shell_code_table0 );\r
+    decode_split( &pulses0[ 10 ], &pulses0[ 11 ], psRangeDec, pulses1[ 5 ], SKP_Silk_shell_code_table0 );\r
 \r
-    decode_split( &pulses1[  6 ], &pulses1[  7 ], sRC, pulses2[ 3 ], SKP_Silk_shell_code_table1 );\r
-    decode_split( &pulses0[ 12 ], &pulses0[ 13 ], sRC, pulses1[ 6 ], SKP_Silk_shell_code_table0 );\r
-    decode_split( &pulses0[ 14 ], &pulses0[ 15 ], sRC, pulses1[ 7 ], SKP_Silk_shell_code_table0 );\r
+    decode_split( &pulses1[  6 ], &pulses1[  7 ], psRangeDec, pulses2[ 3 ], SKP_Silk_shell_code_table1 );\r
+    decode_split( &pulses0[ 12 ], &pulses0[ 13 ], psRangeDec, pulses1[ 6 ], SKP_Silk_shell_code_table0 );\r
+    decode_split( &pulses0[ 14 ], &pulses0[ 15 ], psRangeDec, pulses1[ 7 ], SKP_Silk_shell_code_table0 );\r
 }\r
index cd6ed25..13e2ae6 100644 (file)
@@ -83,6 +83,7 @@ typedef struct {
 /*******************************/\r
 /* Range encoder/decoder state */\r
 /*******************************/\r
+#if 0\r
 typedef struct {\r
     SKP_int32   bufferLength;\r
     SKP_int32   bufferIx;\r
@@ -90,10 +91,10 @@ typedef struct {
     SKP_uint32  range_Q16;\r
     SKP_int32   error;\r
     SKP_uint8   buffer[ MAX_ARITHM_BYTES ];     /* Buffer containing payload                                */\r
-    /* The CELT entropy encoder + decoder */\r
-    ec_enc      range_enc_celt_state;\r
+    /* The CELT entropy decoder */\r
     ec_dec      range_dec_celt_state;\r
 } SKP_Silk_range_coder_state;\r
+#endif\r
 \r
 /* Input frequency range detection struct */\r
 typedef struct {\r
@@ -138,8 +139,8 @@ typedef struct {
 /* Encoder state                */\r
 /********************************/\r
 typedef struct {\r
-    SKP_Silk_range_coder_state      sRC;                            /* Range coder state                                                    */\r
-    SKP_Silk_range_coder_state      sRC_LBRR;                       /* Range coder state (for low bitrate redundancy)                       */\r
+    //SKP_Silk_range_coder_state      sRC;                            /* Range coder state                                                    */\r
+    //SKP_Silk_range_coder_state      sRC_LBRR;                       /* Range coder state (for low bitrate redundancy)                       */\r
 #if HIGH_PASS_INPUT\r
     SKP_int32                       In_HP_State[ 2 ];               /* High pass filter state                                               */\r
 #endif\r
@@ -277,7 +278,7 @@ typedef struct {
 /* Decoder state                */\r
 /********************************/\r
 typedef struct {\r
-    SKP_Silk_range_coder_state  sRC;                            /* Range coder state                                                    */\r
+    //SKP_Silk_range_coder_state  sRC;                            /* Range coder state                                                    */\r
     SKP_int32       prev_inv_gain_Q16;\r
     SKP_int32       sLTP_Q16[ 2 * MAX_FRAME_LENGTH ];\r
     SKP_int32       sLPC_Q14[ MAX_FRAME_LENGTH / MAX_NB_SUBFR + MAX_LPC_ORDER ];\r
index 404820f..126c7db 100644 (file)
@@ -148,8 +148,8 @@ extern const SKP_int16  SKP_Silk_Dec_A_HP_8[ DEC_HP_ORDER ];
 extern const SKP_int16  SKP_Silk_Dec_B_HP_8[ DEC_HP_ORDER + 1 ];                                    /*   3 */\r
 \r
 /* Table for frame termination indication */\r
-extern const SKP_uint16 SKP_Silk_FrameTermination_v4_CDF[ 6 ];\r
-extern const SKP_int    SKP_Silk_FrameTermination_v4_offset;\r
+extern const SKP_uint16 SKP_Silk_FrameTermination_CDF[ 6 ];\r
+extern const SKP_int    SKP_Silk_FrameTermination_offset;\r
 \r
 /* Table for random seed */\r
 extern const SKP_uint16 SKP_Silk_Seed_CDF[ 5 ];\r
index b29c8dc..678a5e1 100644 (file)
@@ -105,8 +105,8 @@ const SKP_uint16 SKP_Silk_NLSF_interpolation_factor_CDF[ 6 ] = {0,   3706,   870
 const SKP_int    SKP_Silk_NLSF_interpolation_factor_offset   = 4;\r
 \r
 /* Table for frame termination indication */\r
-const SKP_uint16 SKP_Silk_FrameTermination_v4_CDF[ 6 ] = {0,   13107,   26214,   39321,   52428,   65535};\r
-const SKP_int    SKP_Silk_FrameTermination_v4_offset   = 4;\r
+const SKP_uint16 SKP_Silk_FrameTermination_CDF[ 6 ] = {0,   13107,   26214,   39321,   52428,   65535};\r
+const SKP_int    SKP_Silk_FrameTermination_offset   = 4;\r
 \r
 /* Table for random seed */\r
 const SKP_uint16 SKP_Silk_Seed_CDF[ 5 ] = {0, 16384, 32768, 49152, 65535};\r
index ca32163..3a4bb39 100644 (file)
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\SKP_Silk_decode_indices_v4.c"\r
+                               RelativePath=".\SKP_Silk_decode_indices.c"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\SKP_Silk_decode_parameters_v4.c"\r
+                               RelativePath=".\SKP_Silk_decode_parameters.c"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\SKP_Silk_encode_parameters_v4.c"\r
+                               RelativePath=".\SKP_Silk_encode_parameters.c"\r
                                >\r
                        </File>\r
                        <File\r
index fecbc19..d2c2b18 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="Windows-1252"?>\r
 <VisualStudioProject\r
        ProjectType="Visual C++"\r
-       Version="8,00"\r
+       Version="8.00"\r
        Name="Dec"\r
        ProjectGUID="{82685D7F-0589-42BD-877C-31A952D53A8E}"\r
        RootNamespace="Test"\r
@@ -40,7 +40,7 @@
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                                Optimization="0"\r
-                               AdditionalIncludeDirectories="../interface;../src_SigProc_FIX"\r
+                               AdditionalIncludeDirectories="../../../celt-0.8.0/libcelt;../interface;../src_SigProc_FIX"\r
                                PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;COMPILE_SDK"\r
                                MinimalRebuild="true"\r
                                BasicRuntimeChecks="3"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
-                               AdditionalIncludeDirectories="../interface;../src_SigProc_FIX"\r
+                               AdditionalIncludeDirectories="../../../celt-0.8.0/libcelt;../interface;../src_SigProc_FIX"\r
                                PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;COMPILE_SDK"\r
                                RuntimeLibrary="0"\r
                                FloatingPointModel="2"\r
diff --git a/test/Dec_SDK.vcproj.SKYPE-KOEN.koen.user b/test/Dec_SDK.vcproj.SKYPE-KOEN.koen.user
deleted file mode 100644 (file)
index 64fb3c3..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-<?xml version="1.0" encoding="Windows-1252"?>\r
-<VisualStudioUserFile\r
-       ProjectType="Visual C++"\r
-       Version="8.00"\r
-       ShowAllFiles="false"\r
-       >\r
-       <Configurations>\r
-               <Configuration\r
-                       Name="Debug|Win32"\r
-                       >\r
-                       <DebugSettings\r
-                               Command="$(TargetPath)"\r
-                               WorkingDirectory=""\r
-                               CommandArguments=""\r
-                               Attach="false"\r
-                               DebuggerType="3"\r
-                               Remote="1"\r
-                               RemoteMachine="SKYPE-KOEN"\r
-                               RemoteCommand=""\r
-                               HttpUrl=""\r
-                               PDBPath=""\r
-                               SQLDebugging=""\r
-                               Environment=""\r
-                               EnvironmentMerge="true"\r
-                               DebuggerFlavor=""\r
-                               MPIRunCommand=""\r
-                               MPIRunArguments=""\r
-                               MPIRunWorkingDirectory=""\r
-                               ApplicationCommand=""\r
-                               ApplicationArguments=""\r
-                               ShimCommand=""\r
-                               MPIAcceptMode=""\r
-                               MPIAcceptFilter=""\r
-                       />\r
-               </Configuration>\r
-               <Configuration\r
-                       Name="Release|Win32"\r
-                       >\r
-                       <DebugSettings\r
-                               Command="$(TargetPath)"\r
-                               WorkingDirectory=""\r
-                               CommandArguments=""\r
-                               Attach="false"\r
-                               DebuggerType="3"\r
-                               Remote="1"\r
-                               RemoteMachine="SKYPE-KOEN"\r
-                               RemoteCommand=""\r
-                               HttpUrl=""\r
-                               PDBPath=""\r
-                               SQLDebugging=""\r
-                               Environment=""\r
-                               EnvironmentMerge="true"\r
-                               DebuggerFlavor=""\r
-                               MPIRunCommand=""\r
-                               MPIRunArguments=""\r
-                               MPIRunWorkingDirectory=""\r
-                               ApplicationCommand=""\r
-                               ApplicationArguments=""\r
-                               ShimCommand=""\r
-                               MPIAcceptMode=""\r
-                               MPIAcceptFilter=""\r
-                       />\r
-               </Configuration>\r
-       </Configurations>\r
-</VisualStudioUserFile>\r
index 1e0cbe8..d4c4cc0 100644 (file)
@@ -47,7 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #define MAX_FRAME_LENGTH        480\r
 #define MAX_FRAME_LENGTH_MS     20\r
 #define MAX_API_FS_KHZ          48\r
-#define MAX_LBRR_DELAY          2\r
+#define MAX_LBRR_DELAY          0\r
 \r
 #ifdef _SYSTEM_IS_BIG_ENDIAN\r
 /* Function to convert a little endian int16 to a */\r
@@ -108,6 +108,8 @@ int main( int argc, char* argv[] )
     float     loss_prob;\r
     SKP_int32 frames, lost, quiet;\r
     SKP_SILK_SDK_DecControlStruct DecControl;\r
+    ec_byte_buffer range_dec_celt_buf;\r
+    ec_dec         range_dec_celt_state;\r
 \r
     if( argc < 3 ) {\r
         print_usage( argv );\r
@@ -217,6 +219,10 @@ int main( int argc, char* argv[] )
             break;\r
         }\r
 \r
+        /* Initialize range decoder state */\r
+        ec_byte_writeinit_buffer( &range_dec_celt_buf, payloadEnd, nBytes );\r
+        ec_dec_init( &range_dec_celt_state, &range_dec_celt_buf );\r
+\r
         /* Simulate losses */\r
         if( ( (float)rand() / (float)RAND_MAX >= loss_prob / 100 ) && counter > 0 ) {\r
             nBytesPerPacket[ MAX_LBRR_DELAY ] = nBytes;\r
@@ -234,7 +240,7 @@ int main( int argc, char* argv[] )
             for( i = 0; i < MAX_LBRR_DELAY; i++ ) {\r
                 if( nBytesPerPacket[ i + 1 ] > 0 ) {\r
                     starttime = GetHighResolutionTime();\r
-                    SKP_Silk_SDK_search_for_LBRR( payloadPtr, nBytesPerPacket[ i + 1 ], i + 1, FECpayload, &nBytesFEC );\r
+                    //SKP_Silk_SDK_search_for_LBRR( payloadPtr, nBytesPerPacket[ i + 1 ], i + 1, FECpayload, &nBytesFEC );\r
                     tottime += GetHighResolutionTime() - starttime;\r
                     if( nBytesFEC > 0 ) {\r
                         payloadToDec = FECpayload;\r
@@ -261,7 +267,7 @@ int main( int argc, char* argv[] )
             do {\r
                 /* Decode 20 ms */\r
                 starttime = GetHighResolutionTime();\r
-                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, payloadToDec, nBytes, outPtr, &len );\r
+                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, &range_dec_celt_state, nBytes, outPtr, &len );\r
                 tottime += GetHighResolutionTime() - starttime;\r
                 if( ret ) {\r
                     printf( "\nSKP_Silk_SDK_Decode returned %d", ret );\r
@@ -287,7 +293,7 @@ int main( int argc, char* argv[] )
             for( i = 0; i < DecControl.framesPerPacket; i++ ) {\r
                 /* Generate 20 ms */\r
                 starttime = GetHighResolutionTime();\r
-                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, payloadToDec, nBytes, outPtr, &len );\r
+                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, &range_dec_celt_state, nBytes, outPtr, &len );\r
                 tottime += GetHighResolutionTime() - starttime;\r
                 if( ret ) {\r
                     printf( "\nSKP_Silk_Decode returned %d", ret );\r
@@ -335,7 +341,7 @@ int main( int argc, char* argv[] )
             for( i = 0; i < MAX_LBRR_DELAY; i++ ) {\r
                 if( nBytesPerPacket[ i + 1 ] > 0 ) {\r
                     starttime = GetHighResolutionTime();\r
-                    SKP_Silk_SDK_search_for_LBRR( payloadPtr, nBytesPerPacket[ i + 1 ], i + 1, FECpayload, &nBytesFEC );\r
+                    //SKP_Silk_SDK_search_for_LBRR( payloadPtr, nBytesPerPacket[ i + 1 ], i + 1, FECpayload, &nBytesFEC );\r
                     tottime += GetHighResolutionTime() - starttime;\r
                     if( nBytesFEC > 0 ) {\r
                         payloadToDec = FECpayload;\r
@@ -362,7 +368,7 @@ int main( int argc, char* argv[] )
             do {\r
                 /* Decode 20 ms */\r
                 starttime = GetHighResolutionTime();\r
-                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, payloadToDec, nBytes, outPtr, &len );\r
+                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, &range_dec_celt_state, nBytes, outPtr, &len );\r
                 tottime += GetHighResolutionTime() - starttime;\r
                 if( ret ) {\r
                     printf( "\nSKP_Silk_SDK_Decode returned %d", ret );\r
@@ -385,7 +391,7 @@ int main( int argc, char* argv[] )
             /* Generate 20 ms */\r
             for( i = 0; i < DecControl.framesPerPacket; i++ ) {\r
                 starttime = GetHighResolutionTime();\r
-                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, payloadToDec, nBytes, outPtr, &len );\r
+                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, &range_dec_celt_state, nBytes, outPtr, &len );\r
                 tottime += GetHighResolutionTime() - starttime;\r
                 if( ret ) {\r
                     printf( "\nSKP_Silk_Decode returned %d", ret );\r
index 8d877f8..b3269b9 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="Windows-1252"?>\r
 <VisualStudioProject\r
        ProjectType="Visual C++"\r
-       Version="8,00"\r
+       Version="8.00"\r
        Name="Enc"\r
        ProjectGUID="{6D97A8EF-5724-4D85-8BF4-C583714BBA78}"\r
        RootNamespace="Enc"\r
@@ -40,7 +40,7 @@
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                                Optimization="0"\r
-                               AdditionalIncludeDirectories="../interface;../src_SigProc_FIX"\r
+                               AdditionalIncludeDirectories="../../../celt-0.8.0/libcelt;../interface;../src_SigProc_FIX"\r
                                PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"\r
                                MinimalRebuild="true"\r
                                BasicRuntimeChecks="3"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
-                               AdditionalIncludeDirectories="../interface;../src_SigProc_FIX"\r
+                               AdditionalIncludeDirectories="../../../celt-0.8.0/libcelt;../interface;../src_SigProc_FIX"\r
                                PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"\r
                                RuntimeLibrary="0"\r
                                FloatingPointModel="2"\r
diff --git a/test/Enc_SDK.vcproj.SKYPE-KOEN.koen.user b/test/Enc_SDK.vcproj.SKYPE-KOEN.koen.user
deleted file mode 100644 (file)
index 64fb3c3..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-<?xml version="1.0" encoding="Windows-1252"?>\r
-<VisualStudioUserFile\r
-       ProjectType="Visual C++"\r
-       Version="8.00"\r
-       ShowAllFiles="false"\r
-       >\r
-       <Configurations>\r
-               <Configuration\r
-                       Name="Debug|Win32"\r
-                       >\r
-                       <DebugSettings\r
-                               Command="$(TargetPath)"\r
-                               WorkingDirectory=""\r
-                               CommandArguments=""\r
-                               Attach="false"\r
-                               DebuggerType="3"\r
-                               Remote="1"\r
-                               RemoteMachine="SKYPE-KOEN"\r
-                               RemoteCommand=""\r
-                               HttpUrl=""\r
-                               PDBPath=""\r
-                               SQLDebugging=""\r
-                               Environment=""\r
-                               EnvironmentMerge="true"\r
-                               DebuggerFlavor=""\r
-                               MPIRunCommand=""\r
-                               MPIRunArguments=""\r
-                               MPIRunWorkingDirectory=""\r
-                               ApplicationCommand=""\r
-                               ApplicationArguments=""\r
-                               ShimCommand=""\r
-                               MPIAcceptMode=""\r
-                               MPIAcceptFilter=""\r
-                       />\r
-               </Configuration>\r
-               <Configuration\r
-                       Name="Release|Win32"\r
-                       >\r
-                       <DebugSettings\r
-                               Command="$(TargetPath)"\r
-                               WorkingDirectory=""\r
-                               CommandArguments=""\r
-                               Attach="false"\r
-                               DebuggerType="3"\r
-                               Remote="1"\r
-                               RemoteMachine="SKYPE-KOEN"\r
-                               RemoteCommand=""\r
-                               HttpUrl=""\r
-                               PDBPath=""\r
-                               SQLDebugging=""\r
-                               Environment=""\r
-                               EnvironmentMerge="true"\r
-                               DebuggerFlavor=""\r
-                               MPIRunCommand=""\r
-                               MPIRunArguments=""\r
-                               MPIRunWorkingDirectory=""\r
-                               ApplicationCommand=""\r
-                               ApplicationArguments=""\r
-                               ShimCommand=""\r
-                               MPIAcceptMode=""\r
-                               MPIAcceptFilter=""\r
-                       />\r
-               </Configuration>\r
-       </Configurations>\r
-</VisualStudioUserFile>\r
index 6a0deda..fe675c5 100644 (file)
@@ -99,7 +99,6 @@ int main( int argc, char* argv[] )
     SKP_int32 k, args, totPackets, totActPackets, ret;\r
     SKP_int16 nBytes;\r
     double    sumBytes, sumActBytes, avg_rate, act_rate, nrg;\r
-    SKP_uint8 payload[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES ];\r
     SKP_int16 in[ MAX_FRAME_LENGTH_MS * MAX_API_FS_KHZ * MAX_INPUT_FRAMES ];\r
     char      speechInFileName[ 150 ], bitOutFileName[ 150 ];\r
     FILE      *bitOutFile, *speechInFile;\r
@@ -111,6 +110,9 @@ int main( int argc, char* argv[] )
 #ifdef _SYSTEM_IS_BIG_ENDIAN\r
     SKP_int16 nBytes_LE;\r
 #endif\r
+    SKP_uint8      range_buf[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES ];\r
+    ec_byte_buffer range_enc_celt_buf;\r
+    ec_enc         range_enc_celt_state;\r
 \r
     /* default settings */\r
     SKP_int32 API_fs_Hz = 24000;\r
@@ -121,6 +123,7 @@ int main( int argc, char* argv[] )
     SKP_int32 packetLoss_perc = 0, complexity_mode = 2, smplsSinceLastPacket;\r
     SKP_int32 INBandFEC_enabled = 0, DTX_enabled = 0, quiet = 0;\r
     SKP_SILK_SDK_EncControlStruct encControl; // Struct for input to encoder\r
+\r
         \r
     if( argc < 3 ) {\r
         print_usage( argv );\r
@@ -235,8 +238,12 @@ int main( int argc, char* argv[] )
     smplsSinceLastPacket = 0;\r
     sumBytes             = 0.0;\r
     sumActBytes          = 0.0;\r
-    \r
+\r
     while( 1 ) {\r
+        /* Init range coder */\r
+        ec_byte_writeinit_buffer( &range_enc_celt_buf, range_buf, MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES );\r
+        ec_enc_init( &range_enc_celt_state, &range_enc_celt_buf );\r
+        \r
         /* Read input from file */\r
         counter = fread( in, sizeof( SKP_int16 ), ( frameSizeReadFromFile_ms * API_fs_Hz ) / 1000, speechInFile );\r
 #ifdef _SYSTEM_IS_BIG_ENDIAN\r
@@ -251,7 +258,7 @@ int main( int argc, char* argv[] )
 \r
         starttime = GetHighResolutionTime();\r
         /* Silk Encoder */\r
-        ret = SKP_Silk_SDK_Encode( psEnc, &encControl, in, (SKP_int16)counter, payload, &nBytes );\r
+        ret = SKP_Silk_SDK_Encode( psEnc, &encControl, in, (SKP_int16)counter, &range_enc_celt_state, &nBytes );\r
         if( ret ) {\r
             printf( "\nSKP_Silk_Encode returned %d", ret );\r
             break;\r
@@ -294,7 +301,7 @@ int main( int argc, char* argv[] )
 #endif\r
 \r
             /* Write payload */\r
-            fwrite( payload, sizeof( SKP_uint8 ), nBytes, bitOutFile );\r
+            fwrite( range_buf, sizeof( SKP_uint8 ), nBytes, bitOutFile );\r
         \r
             if( !quiet ) {\r
                 fprintf( stderr, "\rPackets encoded:              %d", totPackets );\r
diff --git a/test/SignalCompare.vcproj.SKYPE-KOEN.koen.user b/test/SignalCompare.vcproj.SKYPE-KOEN.koen.user
deleted file mode 100644 (file)
index 64fb3c3..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-<?xml version="1.0" encoding="Windows-1252"?>\r
-<VisualStudioUserFile\r
-       ProjectType="Visual C++"\r
-       Version="8.00"\r
-       ShowAllFiles="false"\r
-       >\r
-       <Configurations>\r
-               <Configuration\r
-                       Name="Debug|Win32"\r
-                       >\r
-                       <DebugSettings\r
-                               Command="$(TargetPath)"\r
-                               WorkingDirectory=""\r
-                               CommandArguments=""\r
-                               Attach="false"\r
-                               DebuggerType="3"\r
-                               Remote="1"\r
-                               RemoteMachine="SKYPE-KOEN"\r
-                               RemoteCommand=""\r
-                               HttpUrl=""\r
-                               PDBPath=""\r
-                               SQLDebugging=""\r
-                               Environment=""\r
-                               EnvironmentMerge="true"\r
-                               DebuggerFlavor=""\r
-                               MPIRunCommand=""\r
-                               MPIRunArguments=""\r
-                               MPIRunWorkingDirectory=""\r
-                               ApplicationCommand=""\r
-                               ApplicationArguments=""\r
-                               ShimCommand=""\r
-                               MPIAcceptMode=""\r
-                               MPIAcceptFilter=""\r
-                       />\r
-               </Configuration>\r
-               <Configuration\r
-                       Name="Release|Win32"\r
-                       >\r
-                       <DebugSettings\r
-                               Command="$(TargetPath)"\r
-                               WorkingDirectory=""\r
-                               CommandArguments=""\r
-                               Attach="false"\r
-                               DebuggerType="3"\r
-                               Remote="1"\r
-                               RemoteMachine="SKYPE-KOEN"\r
-                               RemoteCommand=""\r
-                               HttpUrl=""\r
-                               PDBPath=""\r
-                               SQLDebugging=""\r
-                               Environment=""\r
-                               EnvironmentMerge="true"\r
-                               DebuggerFlavor=""\r
-                               MPIRunCommand=""\r
-                               MPIRunArguments=""\r
-                               MPIRunWorkingDirectory=""\r
-                               ApplicationCommand=""\r
-                               ApplicationArguments=""\r
-                               ShimCommand=""\r
-                               MPIAcceptMode=""\r
-                               MPIAcceptFilter=""\r
-                       />\r
-               </Configuration>\r
-       </Configurations>\r
-</VisualStudioUserFile>\r