Commit e99896eb authored by Koen Vos's avatar Koen Vos Committed by Jean-Marc Valin
Browse files

SILK update

parent da301009
......@@ -30,18 +30,17 @@ src_common/SKP_Silk_code_signs.c \
src_common/SKP_Silk_create_init_destroy.c \
src_common/SKP_Silk_decode_core.c \
src_common/SKP_Silk_decode_frame.c \
src_common/SKP_Silk_decode_indices.c \
src_common/SKP_Silk_decode_parameters.c \
src_common/SKP_Silk_decode_indices.c \
src_common/SKP_Silk_decode_pulses.c \
src_common/SKP_Silk_decoder_set_fs.c \
src_common/SKP_Silk_dec_API.c \
src_common/SKP_Silk_detect_SWB_input.c \
src_common/SKP_Silk_enc_API.c \
src_common/SKP_Silk_encode_parameters.c \
src_common/SKP_Silk_encode_indices.c \
src_common/SKP_Silk_encode_pulses.c \
src_common/SKP_Silk_gain_quant.c \
src_common/SKP_Silk_interpolate.c \
src_common/SKP_Silk_LBRR_reset.c \
src_common/SKP_Silk_LP_variable_cutoff.c \
src_common/SKP_Silk_NLSF2A_stable.c \
src_common/SKP_Silk_NLSF_MSVQ_decode.c \
......@@ -49,7 +48,6 @@ src_common/SKP_Silk_NSQ.c \
src_common/SKP_Silk_NSQ_del_dec.c \
src_common/SKP_Silk_PLC.c \
src_common/SKP_Silk_pulses_to_bytes.c \
src_common/SKP_Silk_range_coder.c \
src_common/SKP_Silk_shell_coder.c \
src_common/SKP_Silk_tables_gain.c \
src_common/SKP_Silk_tables_LTP.c \
......@@ -60,7 +58,6 @@ src_common/SKP_Silk_tables_NLSF_CB1_16.c \
src_common/SKP_Silk_tables_other.c \
src_common/SKP_Silk_tables_pitch_lag.c \
src_common/SKP_Silk_tables_pulses_per_block.c \
src_common/SKP_Silk_tables_sign.c \
src_common/SKP_Silk_VAD.c \
src_common/SKP_Silk_control_audio_bandwidth.c \
src_common/SKP_Silk_quant_LTP_gains.c \
......
......@@ -39,16 +39,15 @@ extern "C"
{
#endif
#define SILK_MAX_FRAMES_PER_PACKET 5
#define SILK_MAX_FRAMES_PER_PACKET 3
/* Struct for TOC (Table of Contents) */
typedef struct {
SKP_int framesInPacket; /* Number of 20 ms frames in packet */
SKP_int fs_kHz; /* Sampling frequency in packet */
SKP_int inbandLBRR; /* Does packet contain LBRR information */
SKP_int corrupt; /* Packet is corrupt */
SKP_int vadFlags[ SILK_MAX_FRAMES_PER_PACKET ]; /* VAD flag for each frame in packet */
SKP_int sigtypeFlags[ SILK_MAX_FRAMES_PER_PACKET ]; /* Signal type for each frame in packet */
SKP_int framesInPacket; /* Number of 20 ms frames in packet */
SKP_int fs_kHz; /* Sampling frequency in packet */
SKP_int inbandLBRR; /* Does packet contain LBRR information */
SKP_int corrupt; /* Packet is corrupt */
SKP_int signalTypeFlags[ SILK_MAX_FRAMES_PER_PACKET ]; /* Signal type for each frame in packet */
} SKP_Silk_TOC_struct;
/****************************************/
......@@ -136,17 +135,11 @@ void SKP_Silk_SDK_search_for_LBRR(
/* Get table of contents for a packet */
/**************************************/
void SKP_Silk_SDK_get_TOC(
ec_dec *psRangeDec, /* I/O Compressor data structure */
ec_dec *psRangeDec, /* I/O Compressor data structure */
const SKP_int16 nBytesIn, /* I: Number of input bytes */
SKP_Silk_TOC_struct *Silk_TOC /* O: Table of contents */
);
/**************************/
/* Get the version number */
/**************************/
/* Return a pointer to string specifying the version */
const char *SKP_Silk_SDK_get_version();
#ifdef __cplusplus
}
#endif
......
......@@ -57,7 +57,7 @@ typedef struct {
/* I: Uplink packet loss in percent (0-100) */
SKP_int packetLossPercentage;
/* I: Complexity mode; 0 is lowest; 1 is medium and 2 is highest complexity */
/* I: Complexity mode; 0 is lowest, 10 is highest complexity */
SKP_int complexity;
/* I: Flag to enable in-band Forward Error Correction (FEC); 0/1 */
......
......@@ -42,7 +42,7 @@ extern "C"
/* Encoder error messages */
/**************************/
/* Input length is not a multiplum of 10 ms, or length is longer than the packet length */
/* Input length is not a multiple of 10 ms, or length is longer than the packet length */
#define SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES -101
/* Sampling frequency not 8000, 12000, 16000 or 24000 Hertz */
......@@ -57,7 +57,7 @@ extern "C"
/* Loss rate not between 0 and 100 percent */
#define SKP_SILK_ENC_INVALID_LOSS_RATE -105
/* Complexity setting not valid, use 0, 1 or 2 */
/* Complexity setting not valid, use 0...10 */
#define SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING -106
/* Inband FEC setting not valid, use 0 or 1 */
......
......@@ -25,15 +25,6 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
/* *
* SKP_debug.h *
* *
* This contains code to help debugging *
* *
* Copyright 2009 (c), Skype Limited *
* Date: 090629 *
* */
#ifndef _SKP_DEBUG_H_
#define _SKP_DEBUG_H_
......
......@@ -49,7 +49,7 @@ void SKP_Silk_HP_variable_cutoff_FIX(
/*********************************************/
/* Estimate Low End of Pitch Frequency Range */
/*********************************************/
if( psEnc->sCmn.prev_sigtype == SIG_TYPE_VOICED ) {
if( psEnc->sCmn.prevSignalType == TYPE_VOICED ) {
/* difference, in log domain */
pitch_freq_Hz_Q16 = SKP_DIV32_16( SKP_LSHIFT( SKP_MUL( psEnc->sCmn.fs_kHz, 1000 ), 16 ), psEnc->sCmn.prevLag );
pitch_freq_log_Q7 = SKP_Silk_lin2log( pitch_freq_Hz_Q16 ) - ( 16 << 7 ); //0x70
......
......@@ -78,7 +78,6 @@ void SKP_Silk_NLSF_MSVQ_encode_FIX(
SKP_assert( ( LOW_COMPLEXITY_ONLY == 0 ) || ( NLSF_MSVQ_Survivors <= MAX_NLSF_MSVQ_SURVIVORS_LC_MODE ) );
#ifdef SAVE_ALL_INTERNAL_DATA
/* Use sigtype.dat to seperate into signal types */
DEBUG_STORE_DATA( NLSF.dat, pNLSF_Q15, LPC_order * sizeof( SKP_int ) );
DEBUG_STORE_DATA( WNLSF.dat, pW_Q6, LPC_order * sizeof( SKP_int ) );
DEBUG_STORE_DATA( NLSF_mu.dat, &NLSF_mu_Q15, sizeof( SKP_int32 ) );
......
......@@ -55,7 +55,7 @@ SKP_int SKP_Silk_control_encoder_FIX(
const SKP_int PacketSize_ms, /* I Packet length (ms) */
const SKP_int32 TargetRate_bps, /* I Target max bitrate (bps) */
const SKP_int PacketLoss_perc, /* I Packet loss rate (in percent) */
const SKP_int Complexity /* I Complexity (0->low; 1->medium; 2->high) */
const SKP_int Complexity /* I Complexity (0-10) */
)
{
SKP_int fs_kHz, ret = 0;
......@@ -113,29 +113,6 @@ SKP_int SKP_Silk_control_encoder_FIX(
return ret;
}
/* Control low bitrate redundancy usage */
void SKP_Silk_LBRR_ctrl_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O encoder state */
SKP_Silk_encoder_control *psEncCtrlC /* I/O encoder control */
)
{
SKP_int LBRR_usage;
if( psEnc->sCmn.LBRR_enabled ) {
/* Control LBRR */
/* Usage Control based on sensitivity and packet loss caracteristics */
/* For now only enable adding to next for active frames. Make more complex later */
LBRR_usage = SKP_SILK_NO_LBRR;
if( psEnc->speech_activity_Q8 > SKP_FIX_CONST( LBRR_SPEECH_ACTIVITY_THRES, 8 ) && psEnc->sCmn.PacketLoss_perc > LBRR_LOSS_THRES ) {
LBRR_usage = SKP_SILK_LBRR;
}
psEncCtrlC->LBRR_usage = LBRR_usage;
} else {
psEncCtrlC->LBRR_usage = SKP_SILK_NO_LBRR;
}
}
SKP_INLINE SKP_int SKP_Silk_setup_resamplers(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O */
SKP_int fs_kHz /* I */
......@@ -208,25 +185,34 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
/* Only allowed when the payload buffer is empty */
psEnc->sCmn.nb_subfr = MAX_NB_SUBFR >> 1;
psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz );
if( psEnc->sCmn.fs_kHz == 8 ) {
psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_NB_iCDF;
} else {
psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_iCDF;
}
} else {
psEnc->sCmn.nb_subfr = MAX_NB_SUBFR;
psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz );
if( psEnc->sCmn.fs_kHz == 8 ) {
psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_NB_iCDF;
} else {
psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_iCDF;
}
}
/* Packet length changes. Reset LBRR buffer */
SKP_Silk_LBRR_reset( &psEnc->sCmn );
psEnc->sCmn.PacketSize_ms = PacketSize_ms;
psEnc->sCmn.LBRR_nBytes = 0;
}
/* Set internal sampling frequency */
if( psEnc->sCmn.fs_kHz != fs_kHz ) {
/* reset part of the state */
SKP_memset( &psEnc->sShape, 0, sizeof( SKP_Silk_shape_state_FIX ) );
SKP_memset( &psEnc->sPrefilt, 0, sizeof( SKP_Silk_prefilter_state_FIX ) );
SKP_memset( &psEnc->sNSQ, 0, sizeof( SKP_Silk_nsq_state ) );
SKP_memset( &psEnc->sPred, 0, sizeof( SKP_Silk_predict_state_FIX ) );
SKP_memset( psEnc->sNSQ.xq, 0, 2 * MAX_FRAME_LENGTH * sizeof( SKP_int16 ) );
SKP_memset( psEnc->sNSQ_LBRR.xq, 0, 2 * MAX_FRAME_LENGTH * sizeof( SKP_int16 ) );
SKP_memset( psEnc->sCmn.LBRR_buffer, 0, MAX_LBRR_DELAY * sizeof( SKP_SILK_LBRR_struct ) );
SKP_memset( &psEnc->sShape, 0, sizeof( SKP_Silk_shape_state_FIX ) );
SKP_memset( &psEnc->sPrefilt, 0, sizeof( SKP_Silk_prefilter_state_FIX ) );
SKP_memset( &psEnc->sNSQ, 0, sizeof( SKP_Silk_nsq_state ) );
SKP_memset( &psEnc->sPred, 0, sizeof( SKP_Silk_predict_state_FIX ) );
SKP_memset( psEnc->sNSQ.xq, 0, 2 * MAX_FRAME_LENGTH * sizeof( SKP_int16 ) );
SKP_memset( psEnc->sNSQ_LBRR.xq, 0, 2 * MAX_FRAME_LENGTH * sizeof( SKP_int16 ) );
SKP_memset( psEnc->sPred.prev_NLSFq_Q15, 0, MAX_LPC_ORDER * sizeof( SKP_int ) );
#if SWITCH_TRANSITION_FILTERING
SKP_memset( psEnc->sCmn.sLP.In_LP_State, 0, 2 * sizeof( SKP_int32 ) );
if( psEnc->sCmn.sLP.mode == 1 ) {
......@@ -237,17 +223,14 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
psEnc->sCmn.sLP.transition_frame_no = 0;
}
#endif
psEnc->sCmn.LBRR_nBytes = 0;
psEnc->sCmn.inputBufIx = 0;
psEnc->sCmn.nFramesInPayloadBuf = 0;
psEnc->sCmn.nBytesInPayloadBuf = 0;
psEnc->sCmn.oldest_LBRR_idx = 0;
psEnc->sCmn.TargetRate_bps = 0; /* Ensures that psEnc->SNR_dB is recomputed */
SKP_memset( psEnc->sPred.prev_NLSFq_Q15, 0, MAX_LPC_ORDER * sizeof( SKP_int ) );
/* Initialize non-zero parameters */
psEnc->sCmn.prevLag = 100;
psEnc->sCmn.prev_sigtype = SIG_TYPE_UNVOICED;
psEnc->sCmn.first_frame_after_reset = 1;
psEnc->sPrefilt.lagPrev = 100;
psEnc->sShape.LastGainIndex = 1;
......@@ -296,22 +279,22 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
SKP_assert( 0 );
}
if( psEnc->sCmn.fs_kHz == 24 ) {
psEnc->sCmn.mu_LTP_Q10 = SKP_FIX_CONST( MU_LTP_QUANT_SWB, 10 );
psEnc->sCmn.mu_LTP_Q9 = SKP_FIX_CONST( MU_LTP_QUANT_SWB, 9 );
psEnc->sCmn.bitrate_threshold_up = SKP_int32_MAX;
psEnc->sCmn.bitrate_threshold_down = SWB2WB_BITRATE_BPS;
psEnc->sCmn.pitch_lag_low_bits_iCDF = SKP_Silk_uniform12_iCDF;
} else if( psEnc->sCmn.fs_kHz == 16 ) {
psEnc->sCmn.mu_LTP_Q10 = SKP_FIX_CONST( MU_LTP_QUANT_WB, 10 );
psEnc->sCmn.mu_LTP_Q9 = SKP_FIX_CONST( MU_LTP_QUANT_WB, 9 );
psEnc->sCmn.bitrate_threshold_up = WB2SWB_BITRATE_BPS;
psEnc->sCmn.bitrate_threshold_down = WB2MB_BITRATE_BPS;
psEnc->sCmn.pitch_lag_low_bits_iCDF = SKP_Silk_uniform8_iCDF;
} else if( psEnc->sCmn.fs_kHz == 12 ) {
psEnc->sCmn.mu_LTP_Q10 = SKP_FIX_CONST( MU_LTP_QUANT_MB, 10 );
psEnc->sCmn.mu_LTP_Q9 = SKP_FIX_CONST( MU_LTP_QUANT_MB, 9 );
psEnc->sCmn.bitrate_threshold_up = MB2WB_BITRATE_BPS;
psEnc->sCmn.bitrate_threshold_down = MB2NB_BITRATE_BPS;
psEnc->sCmn.pitch_lag_low_bits_iCDF = SKP_Silk_uniform6_iCDF;
} else if( psEnc->sCmn.fs_kHz == 8 ) {
psEnc->sCmn.mu_LTP_Q10 = SKP_FIX_CONST( MU_LTP_QUANT_NB, 10 );
psEnc->sCmn.mu_LTP_Q9 = SKP_FIX_CONST( MU_LTP_QUANT_NB, 9 );
psEnc->sCmn.bitrate_threshold_up = NB2MB_BITRATE_BPS;
psEnc->sCmn.bitrate_threshold_down = 0;
psEnc->sCmn.pitch_lag_low_bits_iCDF = SKP_Silk_uniform4_iCDF;
......
......@@ -33,8 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/****************/
SKP_int SKP_Silk_encode_frame_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O Encoder state FIX */
SKP_int32 *pnBytesOut, /* I/O Number of payload bytes */
/* input: max length; output: used */
SKP_int32 *pnBytesOut, /* O Number of payload bytes */
ec_enc *psRangeEnc, /* I/O compressor data structure */
const SKP_int16 *pIn /* I Input speech frame */
)
......@@ -45,11 +44,7 @@ SKP_int SKP_Silk_encode_frame_FIX(
SKP_int16 xfw[ MAX_FRAME_LENGTH ];
SKP_int16 pIn_HP[ MAX_FRAME_LENGTH ];
SKP_int16 res_pitch[ 2 * MAX_FRAME_LENGTH + LA_PITCH_MAX ];
SKP_int LBRR_idx, frame_terminator, SNR_dB_Q7;
/* Low bitrate redundancy parameters */
SKP_uint8 LBRRpayload[ MAX_ARITHM_BYTES ];
SKP_int32 nBytesLBRR;
SKP_int frame_terminator, SNR_dB_Q7;
TIC(ENCODE_FRAME)
......@@ -70,6 +65,25 @@ TIC(VAD)
pIn, psEnc->sCmn.frame_length, psEnc->sCmn.fs_kHz );
TOC(VAD)
/**************************************************/
/* Convert speech activity into VAD and DTX flags */
/**************************************************/
if( psEnc->speech_activity_Q8 < SKP_FIX_CONST( SPEECH_ACTIVITY_DTX_THRES, 8 ) ) {
sEncCtrl.sCmn.signalType = TYPE_NO_VOICE_ACTIVITY;
psEnc->sCmn.noSpeechCounter++;
if( psEnc->sCmn.noSpeechCounter > NO_SPEECH_FRAMES_BEFORE_DTX ) {
psEnc->sCmn.inDTX = 1;
}
if( psEnc->sCmn.noSpeechCounter > MAX_CONSECUTIVE_DTX ) {
psEnc->sCmn.noSpeechCounter = 0;
psEnc->sCmn.inDTX = 0;
}
} else {
psEnc->sCmn.noSpeechCounter = 0;
psEnc->sCmn.inDTX = 0;
sEncCtrl.sCmn.signalType = TYPE_UNVOICED;
}
/*******************************************/
/* High-pass filtering of the input signal */
/*******************************************/
......@@ -124,15 +138,15 @@ TIC(PROCESS_GAINS)
SKP_Silk_process_gains_FIX( psEnc, &sEncCtrl );
TOC(PROCESS_GAINS)
psEnc->sCmn.sigtype[ psEnc->sCmn.nFramesInPayloadBuf ] = sEncCtrl.sCmn.sigtype;
psEnc->sCmn.QuantOffsetType[ psEnc->sCmn.nFramesInPayloadBuf ] = sEncCtrl.sCmn.QuantOffsetType;
psEnc->sCmn.quantOffsetType[ psEnc->sCmn.nFramesInPayloadBuf ] = sEncCtrl.sCmn.quantOffsetType;
psEnc->sCmn.signalType[ psEnc->sCmn.nFramesInPayloadBuf ] = sEncCtrl.sCmn.signalType;
/****************************************/
/* Low Bitrate Redundant Encoding */
/****************************************/
nBytesLBRR = MAX_ARITHM_BYTES;
psEnc->sCmn.LBRR_nBytes = MAX_ARITHM_BYTES;
TIC(LBRR)
//SKP_Silk_LBRR_encode_FIX( psEnc, &sEncCtrl, LBRRpayload, &nBytesLBRR, xfw );
//SKP_Silk_LBRR_encode_FIX( psEnc, &sEncCtrl, psEnc->sCmn.LBRR_payload, &psEnc->sCmn.LBRR_nBytes, xfw );
TOC(LBRR)
/*****************************************/
......@@ -154,25 +168,6 @@ TIC(NSQ)
}
TOC(NSQ)
/**************************************************/
/* Convert speech activity into VAD and DTX flags */
/**************************************************/
if( psEnc->speech_activity_Q8 < SKP_FIX_CONST( SPEECH_ACTIVITY_DTX_THRES, 8 ) ) {
psEnc->sCmn.vadFlag = NO_VOICE_ACTIVITY;
psEnc->sCmn.noSpeechCounter++;
if( psEnc->sCmn.noSpeechCounter > NO_SPEECH_FRAMES_BEFORE_DTX ) {
psEnc->sCmn.inDTX = 1;
}
if( psEnc->sCmn.noSpeechCounter > MAX_CONSECUTIVE_DTX ) {
psEnc->sCmn.noSpeechCounter = 0;
psEnc->sCmn.inDTX = 0;
}
} else {
psEnc->sCmn.noSpeechCounter = 0;
psEnc->sCmn.inDTX = 0;
psEnc->sCmn.vadFlag = VOICE_ACTIVITY;
}
/****************************************/
/* Initialize range coder */
/****************************************/
......@@ -184,7 +179,7 @@ TOC(NSQ)
/* Encode Parameters */
/****************************************/
TIC(ENCODE_PARAMS)
SKP_Silk_encode_parameters( &psEnc->sCmn, &sEncCtrl.sCmn, psRangeEnc );
SKP_Silk_encode_indices( &psEnc->sCmn, &sEncCtrl.sCmn, psRangeEnc );
TOC(ENCODE_PARAMS)
/****************************************/
......@@ -195,26 +190,18 @@ TOC(ENCODE_PARAMS)
( psEnc->sCmn.ltp_mem_length + LA_SHAPE_MS * psEnc->sCmn.fs_kHz ) * sizeof( SKP_int16 ) );
/* Parameters needed for next frame */
psEnc->sCmn.prev_sigtype = sEncCtrl.sCmn.sigtype;
psEnc->sCmn.prevLag = sEncCtrl.sCmn.pitchL[ psEnc->sCmn.nb_subfr - 1 ];
psEnc->sCmn.prevSignalType = sEncCtrl.sCmn.signalType;
psEnc->sCmn.first_frame_after_reset = 0;
if( 0 ) { //psEnc->sCmn.sRC.error ) {
/* Encoder returned error: clear payload buffer */
psEnc->sCmn.nFramesInPayloadBuf = 0;
} else {
psEnc->sCmn.nFramesInPayloadBuf++;
}
psEnc->sCmn.nFramesInPayloadBuf++;
/****************************************/
/* Finalize payload and copy to output */
/****************************************/
if( psEnc->sCmn.nFramesInPayloadBuf * SUB_FRAME_LENGTH_MS * psEnc->sCmn.nb_subfr >= psEnc->sCmn.PacketSize_ms ) {
LBRR_idx = ( psEnc->sCmn.oldest_LBRR_idx + 1 ) & LBRR_IDX_MASK;
/* Check if FEC information should be added */
//frame_terminator = psEnc->sCmn.LBRR_buffer[ LBRR_idx ].usage;
//frame_terminator = psEnc->sCmn.usage;
frame_terminator = SKP_SILK_NO_LBRR;
/* Add the frame termination info to stream */
......@@ -222,56 +209,13 @@ TOC(ENCODE_PARAMS)
/* Code excitation signal */
for( i = 0; i < psEnc->sCmn.nFramesInPayloadBuf; i++ ) {
SKP_Silk_encode_pulses( psRangeEnc, psEnc->sCmn.sigtype[ i ], psEnc->sCmn.QuantOffsetType[ i ],
SKP_Silk_encode_pulses( psRangeEnc, psEnc->sCmn.signalType[ i ], psEnc->sCmn.quantOffsetType[ i ],
&psEnc->sCmn.q[ i * psEnc->sCmn.frame_length ], psEnc->sCmn.frame_length );
}
/* Payload length so far */
nBytes = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 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( psRangeEnc, 0 );
//ec_enc_done( psRangeEnc );
#if 0
/* Fill up any remaining bits in the last byte with 1s */
if( bits_in_stream & 7 ) {
mask = SKP_RSHIFT( 0xFF, bits_in_stream & 7 );
if( nBytes - 1 < *pnBytesOut ) {
psEnc->sCmn.sRC.range_enc_celt_state.buf->buf[ nBytes - 1 ] |= mask;
}
}
SKP_memcpy( pCode, psEnc->sCmn.sRC.range_enc_celt_state.buf->buf, nBytes * sizeof( SKP_uint8 ) );
#endif
#if 0
if( frame_terminator > SKP_SILK_MORE_FRAMES &&
*pnBytesOut >= nBytes + psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes ) {
/* Get old packet and add to payload. */
SKP_memcpy( &pCode[ nBytes ],
psEnc->sCmn.LBRR_buffer[ LBRR_idx ].payload,
psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes * sizeof( SKP_uint8 ) );
nBytes += psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes;
}
#endif
*pnBytesOut = nBytes;
/* Update FEC buffer */
SKP_memcpy( psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].payload, LBRRpayload,
nBytesLBRR * sizeof( SKP_uint8 ) );
psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].nBytes = nBytesLBRR;
/* The line below describes how FEC should be used */
psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].usage = sEncCtrl.sCmn.LBRR_usage;
psEnc->sCmn.oldest_LBRR_idx = ( psEnc->sCmn.oldest_LBRR_idx + 1 ) & LBRR_IDX_MASK;
} else {
/* Not enough space: Payload will be discarded */
*pnBytesOut = 0;
nBytes = 0;
ret = SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT;
}
*pnBytesOut = nBytes;
/* Reset the number of frames in payload buffer */
psEnc->sCmn.nFramesInPayloadBuf = 0;
......@@ -287,11 +231,6 @@ TOC(ENCODE_PARAMS)
&psEnc->sCmn.q[ psEnc->sCmn.nFramesInPayloadBuf * psEnc->sCmn.frame_length ] );
}
/* Check for arithmetic coder errors */
if( 0 ) { //psEnc->sCmn.sRC.error ) {
ret = SKP_SILK_ENC_INTERNAL_ERROR;
}
/* Simulate number of ms buffered in channel because of exceeding TargetRate */
SKP_assert( ( 8 * 1000 * ( (SKP_int64)nBytes - (SKP_int64)psEnc->sCmn.nBytesInPayloadBuf ) ) ==
SKP_SAT32( 8 * 1000 * ( (SKP_int64)nBytes - (SKP_int64)psEnc->sCmn.nBytesInPayloadBuf ) ) );
......@@ -339,14 +278,14 @@ TOC(ENCODE_FRAME)
DEBUG_STORE_DATA( nBytes.dat, &nBytes, sizeof( SKP_int ) );
tmp[ 0 ] = (SKP_float)sEncCtrl.current_SNR_dB_Q7 / 128.0f;
DEBUG_STORE_DATA( current_SNR_db.dat, tmp, sizeof( SKP_float ) );
DEBUG_STORE_DATA( QuantOffsetType.dat, &sEncCtrl.sCmn.QuantOffsetType, sizeof( SKP_int ) );
DEBUG_STORE_DATA( quantOffsetType.dat, &sEncCtrl.sCmn.quantOffsetType, sizeof( SKP_int ) );
tmp[ 0 ] = (SKP_float)psEnc->speech_activity_Q8 / 256.0f;
DEBUG_STORE_DATA( speech_activity.dat, tmp, sizeof( SKP_float ) );
for( i = 0; i < VAD_N_BANDS; i++ ) {
tmp[ i ] = (SKP_float)sEncCtrl.input_quality_bands_Q15[ i ] / 32768.0f;
}
DEBUG_STORE_DATA( input_quality_bands.dat, tmp, VAD_N_BANDS * sizeof( SKP_float ) );
DEBUG_STORE_DATA( sigtype.dat, &sEncCtrl.sCmn.sigtype, sizeof( SKP_int ) );
DEBUG_STORE_DATA( signalType.dat, &sEncCtrl.sCmn.signalType, sizeof( SKP_int ) );
DEBUG_STORE_DATA( ratelevel.dat, &sEncCtrl.sCmn.RateLevelIndex, sizeof( SKP_int ) );
DEBUG_STORE_DATA( lag_index.dat, &sEncCtrl.sCmn.lagIndex, sizeof( SKP_int ) );
DEBUG_STORE_DATA( contour_index.dat, &sEncCtrl.sCmn.contourIndex, sizeof( SKP_int ) );
......@@ -375,7 +314,14 @@ void SKP_Silk_LBRR_encode_FIX(
/*******************************************/
/* Control use of inband LBRR */
/*******************************************/
SKP_Silk_LBRR_ctrl_FIX( psEnc, &psEncCtrl->sCmn );
psEnc->sCmn.LBRR_usage = SKP_SILK_NO_LBRR;
if( psEnc->sCmn.LBRR_enabled ) {
/* Control LBRR */
/* Usage Control based on sensitivity and packet loss caracteristics */
if( psEnc->speech_activity_Q8 > SKP_FIX_CONST( LBRR_SPEECH_ACTIVITY_THRES, 8 ) && psEnc->sCmn.PacketLoss_perc > LBRR_LOSS_THRES ) {
psEnc->sCmn.LBRR_usage = SKP_SILK_LBRR;
}
}
if( psEnc->sCmn.LBRR_enabled ) {
/* Save original gains */
......@@ -398,7 +344,7 @@ void SKP_Silk_LBRR_encode_FIX(
SKP_assert( 0 );
}
if( psEnc->sCmn.Complexity > 0 && psEnc->sCmn.TargetRate_bps > Rate_only_parameters ) {
if( psEnc->sCmn.Complexity >= 4 && psEnc->sCmn.TargetRate_bps > Rate_only_parameters ) {
if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) {
/* First frame in packet; copy everything */
SKP_memcpy( &psEnc->sNSQ_LBRR, &psEnc->sNSQ, sizeof( SKP_Silk_nsq_state ) );
......@@ -445,8 +391,7 @@ void SKP_Silk_LBRR_encode_FIX(
/****************************************/
/* Encode Parameters */
/****************************************/
SKP_Silk_encode_parameters( &psEnc->sCmn, &psEncCtrl->sCmn,
&psEnc->sCmn.sRC_LBRR );
SKP_Silk_encode_indices( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sCmn.sRC_LBRR );
/****************************************/
/* Encode Parameters */
......@@ -473,7 +418,7 @@ void SKP_Silk_LBRR_encode_FIX(
/* Encode quantization indices of excitation */
/*********************************************/
for( i = 0; i < nFramesInPayloadBuf; i++ ) {
SKP_Silk_encode_pulses( &psEnc->sCmn.sRC_LBRR, psEnc->sCmn.sigtype[ i ], psEnc->sCmn.QuantOffsetType[ i ],
SKP_Silk_encode_pulses( &psEnc->sCmn.sRC_LBRR, psEnc->sCmn.signalType[ i ], psEnc->sCmn.quantOffsetType[ i ],
&psEnc->sCmn.q_LBRR[ i * psEnc->sCmn.frame_length ], psEnc->sCmn.frame_length );
}
......
......@@ -108,20 +108,25 @@ void SKP_Silk_find_pitch_lags_FIX(
SKP_Silk_MA_Prediction( x_buf, A_Q12, FiltState, res, buf_len, psEnc->sCmn.pitchEstimationLPCOrder );
SKP_memset( res, 0, psEnc->sCmn.pitchEstimationLPCOrder * sizeof( SKP_int16 ) );
/* Threshold for pitch estimator */
thrhld_Q15 = SKP_FIX_CONST( 0.45, 15 );
thrhld_Q15 = SKP_SMLABB( thrhld_Q15, SKP_FIX_CONST( -0.004, 15 ), psEnc->sCmn.pitchEstimationLPCOrder );
thrhld_Q15 = SKP_SMLABB( thrhld_Q15, SKP_FIX_CONST( -0.1, 7 ), psEnc->speech_activity_Q8 );
thrhld_Q15 = SKP_SMLABB( thrhld_Q15, SKP_FIX_CONST( 0.15, 15 ), psEnc->sCmn.prev_sigtype );
thrhld_Q15 = SKP_SMLAWB( thrhld_Q15, SKP_FIX_CONST( -0.1, 16 ), psEncCtrl->input_tilt_Q15 );
thrhld_Q15 = SKP_SAT16( thrhld_Q15 );
if( psEncCtrl->sCmn.signalType != TYPE_NO_VOICE_ACTIVITY ) {
/* Threshold for pitch estimator */
thrhld_Q15 = SKP_FIX_CONST( 0.6, 15 );
thrhld_Q15 = SKP_SMLABB( thrhld_Q15, SKP_FIX_CONST( -0.004, 15 ), psEnc->sCmn.pitchEstimationLPCOrder );
thrhld_Q15 = SKP_SMLABB( thrhld_Q15, SKP_FIX_CONST( -0.1, 7 ), psEnc->speech_activity_Q8 );
thrhld_Q15 = SKP_SMLABB( thrhld_Q15, SKP_FIX_CONST( -0.15, 15 ), SKP_RSHIFT( psEnc->sCmn.prevSignalType, 1 ) );
thrhld_Q15 = SKP_SMLAWB( thrhld_Q15, SKP_FIX_CONST( -0.1, 16 ), psEncCtrl->input_tilt_Q15 );
thrhld_Q15 = SKP_SAT16( thrhld_Q15 );
/*****************************************/
/* Call pitch estimator */
/*****************************************/
TIC(pitch_analysis_core_FIX)
psEncCtrl->sCmn.sigtype = SKP_Silk_pitch_analysis_core( res, psEncCtrl->sCmn.pitchL, &psEncCtrl->sCmn.lagIndex,
&psEncCtrl->sCmn.contourIndex, &psEnc->LTPCorr_Q15, psEnc->sCmn.prevLag, psEnc->sCmn.pitchEstimationThreshold_Q16,
( SKP_int16 )thrhld_Q15, psEnc->sCmn.fs_kHz, psEnc->sCmn.pitchEstimationComplexity, psEnc->sCmn.nb_subfr );
TOC(pitch_analysis_core_FIX)
/*****************************************/
/* Call pitch estimator */
/*****************************************/
if( SKP_Silk_pitch_analysis_core( res, psEncCtrl->sCmn.pitchL, &psEncCtrl->sCmn.lagIndex,
&psEncCtrl->sCmn.contourIndex, &psEnc->LTPCorr_Q15, psEnc->sCmn.prevLag, psEnc->sCmn.pitchEstimationThreshold_Q16,
( SKP_int16 )thrhld_Q15, psEnc->sCmn.fs_kHz, psEnc->sCmn.pitchEstimationComplexity, psEnc->sCmn.nb_subfr ) == 0 )
{
psEncCtrl->sCmn.signalType = TYPE_VOICED;
} else {
psEncCtrl->sCmn.signalType = TYPE_UNVOICED;
}
}
}
......@@ -114,7 +114,7 @@ void SKP_Silk_find_pred_coefs_FIX(
local_gains[ i ] = SKP_DIV32( ( 1 << 16 ), invGains_Q16[ i ] );
}
if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {
if( psEncCtrl->sCmn.signalType == TYPE_VOICED ) {
/**********/
/* VOICED */
/**********/
......@@ -134,7 +134,7 @@ void SKP_Silk_find_pred_coefs_FIX(
/* Quantize LTP gain parameters */
SKP_Silk_quant_LTP_gains( psEncCtrl->LTPCoef_Q14, psEncCtrl->sCmn.LTPIndex, &psEncCtrl->sCmn.PERIndex,
WLTP, psEnc->sCmn.mu_LTP_Q10, psEnc->sCmn.LTPQuantLowComplexity, psEnc->sCmn.nb_subfr);
WLTP, psEnc->sCmn.mu_LTP_Q9, psEnc->sCmn.LTPQuantLowComplexity, psEnc->sCmn.nb_subfr);
/* Control LTP scaling */
SKP_Silk_LTP_scale_ctrl_FIX( psEnc, psEncCtrl );
......@@ -266,7 +266,7 @@ void SKP_Silk_find_pred_coefs_FIX(
in_ptr += psEnc->sCmn.subfr_length;
}