Commit fc06bda8 authored by Timothy B. Terriberry's avatar Timothy B. Terriberry
Browse files

Update SILK range coder due to CELT refactoring.

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