ref: 1bf4f9715a93209f681664f2c46cb5a25ee7aaf8
parent: 6df6db1391c78dbafd75cda7c6872f9c44982e31
author: Koen Vos <[email protected]>
date: Mon Feb 28 11:07:58 EST 2011
Squashed commit of the following: commit 7721daf733c6986cb2c2511c81e6fc14fea1ec6a Author: Jean-Marc Valin <[email protected]> Date: Mon Feb 28 16:00:52 2011 -0500 Makefile.am update commit 47dcc4edad849f57240b0c364036a378b5d22a9a Author: Koen Vos <[email protected]> Date: Mon Feb 28 15:46:23 2011 -0500 SILK update (prefill, new LSF quant)
--- a/Makefile.am
+++ b/Makefile.am
@@ -42,7 +42,7 @@
src_common/SKP_Silk_LBRR_embed.c \
src_common/SKP_Silk_LP_variable_cutoff.c \
src_common/SKP_Silk_NLSF2A_stable.c \
-src_common/SKP_Silk_NLSF_MSVQ_decode.c \
+src_common/SKP_Silk_NLSF_decode.c \
src_common/SKP_Silk_NSQ.c \
src_common/SKP_Silk_NSQ_del_dec.c \
src_common/SKP_Silk_PLC.c \
@@ -49,10 +49,8 @@
src_common/SKP_Silk_shell_coder.c \
src_common/SKP_Silk_tables_gain.c \
src_common/SKP_Silk_tables_LTP.c \
-src_common/SKP_Silk_tables_NLSF_CB0_10.c \
-src_common/SKP_Silk_tables_NLSF_CB0_16.c \
-src_common/SKP_Silk_tables_NLSF_CB1_10.c \
-src_common/SKP_Silk_tables_NLSF_CB1_16.c \
+src_common/SKP_Silk_tables_NLSF_CB_NB_MB.c \
+src_common/SKP_Silk_tables_NLSF_CB_WB.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 \
@@ -61,12 +59,12 @@
src_common/SKP_Silk_quant_LTP_gains.c \
src_common/SKP_Silk_VQ_WMat_EC.c \
src_common/SKP_Silk_HP_variable_cutoff.c \
-src_common/SKP_Silk_NLSF_MSVQ_encode.c \
-src_common/SKP_Silk_NLSF_VQ_rate_distortion.c \
-src_common/SKP_Silk_NLSF_VQ_sum_error.c \
+src_common/SKP_Silk_NLSF_encode.c \
+src_common/SKP_Silk_NLSF_VQ.c \
+src_common/SKP_Silk_NLSF_unpack.c \
+src_common/SKP_Silk_NLSF_del_dec_quant.c \
src_common/SKP_Silk_process_NLSFs.c \
src_SigProc_FIX/SKP_Silk_A2NLSF.c \
-src_SigProc_FIX/SKP_Silk_allpass_int.c \
src_SigProc_FIX/SKP_Silk_ana_filt_bank_1.c \
src_SigProc_FIX/SKP_Silk_apply_sine_window.c \
src_SigProc_FIX/SKP_Silk_array_maxabs.c \
@@ -82,8 +80,6 @@
src_SigProc_FIX/SKP_Silk_k2a_Q16.c \
src_SigProc_FIX/SKP_Silk_lin2log.c \
src_SigProc_FIX/SKP_Silk_log2lin.c \
-src_SigProc_FIX/SKP_Silk_lowpass_int.c \
-src_SigProc_FIX/SKP_Silk_lowpass_short.c \
src_SigProc_FIX/SKP_Silk_LPC_analysis_filter.c \
src_SigProc_FIX/SKP_Silk_LPC_inv_pred_gain.c \
src_SigProc_FIX/SKP_Silk_LPC_stabilize.c \
@@ -188,7 +184,6 @@
src_common/SKP_Silk_PLC.h \
src_common/SKP_Silk_structs.h \
src_common/SKP_Silk_tables.h \
-src_common/SKP_Silk_tables_NLSF_CB.h \
src_common/SKP_Silk_tuning_parameters.h \
src_common/SKP_Silk_setup.h \
src_FIX/SKP_Silk_main_FIX.h \
--- a/interface/SKP_Silk_SDK_API.h
+++ b/interface/SKP_Silk_SDK_API.h
@@ -75,19 +75,11 @@
SKP_SILK_SDK_EncControlStruct *encStatus /* O: Encoder Status */
);
-/*****************************/
-/* Prefill look-ahead buffer */
-/*****************************/
-SKP_int SKP_Silk_SDK_Encoder_prefill_buffer(
- void *encState, /* I/O: State */
- SKP_SILK_SDK_EncControlStruct *encControl, /* I: Control structure */
- const SKP_int16 *samplesIn, /* I: Speech sample input vector (last part will be used) */
- SKP_int nSamplesIn /* I: Number of samples in input vector */
-);
-
/**************************/
/* Encode frame with Silk */
/**************************/
+/* Note: if prefillFlag is set, the input must contain 10 ms of audio, irrespective of what */
+/* encControl->payloadSize_ms is set to */
SKP_int SKP_Silk_SDK_Encode( /* O: Returns error code */
void *encState, /* I/O: State */
SKP_SILK_SDK_EncControlStruct *encControl, /* I: Control status */
@@ -94,7 +86,8 @@
const SKP_int16 *samplesIn, /* I: Speech sample input vector */
SKP_int nSamplesIn, /* I: Number of samples in input vector */
ec_enc *psRangeEnc, /* I/O Compressor data structure */
- SKP_int32 *nBytesOut /* I/O: Number of bytes in payload (input: Max bytes) */
+ SKP_int32 *nBytesOut, /* I/O: Number of bytes in payload (input: Max bytes) */
+ const SKP_int prefillFlag /* I: Flag to indicate prefilling buffers no coding */
);
/****************************************/
@@ -113,6 +106,16 @@
/*************************/
SKP_int SKP_Silk_SDK_InitDecoder( /* O: Returns error code */
void *decState /* I/O: State */
+);
+
+/************************************************************************************************/
+/* Prefill LPC synthesis buffer, HP filter and upsampler. Input must be exactly 10 ms of audio. */
+/************************************************************************************************/
+SKP_int SKP_Silk_SDK_Decoder_prefill_buffers( /* O: Returns error code */
+ void* decState, /* I/O: State */
+ SKP_SILK_SDK_DecControlStruct* decControl, /* I/O: Control Structure */
+ const SKP_int16 *samplesIn, /* I: Speech sample input vector (10 ms) */
+ SKP_int nSamplesIn /* I: Number of samples in input vector */
);
/******************/
--- a/src_FIX/SKP_Silk_control_codec_FIX.c
+++ b/src_FIX/SKP_Silk_control_codec_FIX.c
@@ -55,7 +55,7 @@
{
SKP_int fs_kHz, ret = 0;
- if( psEnc->sCmn.controlled_since_last_payload != 0 ) {
+ if( psEnc->sCmn.controlled_since_last_payload != 0 && psEnc->sCmn.prefillFlag == 0 ) {
if( psEnc->sCmn.API_fs_Hz != psEnc->sCmn.prev_API_fs_Hz && psEnc->sCmn.fs_kHz > 0 ) {
/* Change in API sampling rate in the middle of encoding a packet */
ret += SKP_Silk_setup_resamplers( psEnc, psEnc->sCmn.fs_kHz );
@@ -176,9 +176,10 @@
( PacketSize_ms != 60 ) ) {
ret = SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED;
}
- if( PacketSize_ms == 10 ) {
+ if( PacketSize_ms <= 10 ) {
psEnc->sCmn.nFramesPerPacket = 1;
- psEnc->sCmn.nb_subfr = MAX_NB_SUBFR >> 1;
+ psEnc->sCmn.nb_subfr = PacketSize_ms == 10 ? 2 : 1;
+ psEnc->sCmn.frame_length = SKP_SMULBB( PacketSize_ms, fs_kHz );
psEnc->sCmn.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;
@@ -188,6 +189,7 @@
} else {
psEnc->sCmn.nFramesPerPacket = SKP_DIV32_16( PacketSize_ms, MAX_FRAME_LENGTH_MS );
psEnc->sCmn.nb_subfr = MAX_NB_SUBFR;
+ psEnc->sCmn.frame_length = SKP_SMULBB( 20, fs_kHz );
psEnc->sCmn.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;
@@ -195,10 +197,13 @@
psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_iCDF;
}
}
- psEnc->sCmn.PacketSize_ms = PacketSize_ms;
+ psEnc->sCmn.PacketSize_ms = PacketSize_ms;
+ psEnc->sCmn.TargetRate_bps = 0; /* trigger new SNR computation */
}
/* Set internal sampling frequency */
+ SKP_assert( fs_kHz == 8 || fs_kHz == 12 || fs_kHz == 16 );
+ SKP_assert( psEnc->sCmn.nb_subfr == 2 || psEnc->sCmn.nb_subfr == 4 );
if( psEnc->sCmn.fs_kHz != fs_kHz ) {
/* reset part of the state */
SKP_memset( &psEnc->sShape, 0, sizeof( SKP_Silk_shape_state_FIX ) );
@@ -220,42 +225,34 @@
psEnc->sCmn.fs_kHz = fs_kHz;
if( psEnc->sCmn.fs_kHz == 8 ) {
- psEnc->sCmn.predictLPCOrder = MIN_LPC_ORDER;
- psEnc->sCmn.psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_10;
- psEnc->sCmn.psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_10;
- if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ){
+ if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) {
psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_NB_iCDF;
- } else if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR / 2 ){
- psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_NB_iCDF;
} else {
- /* Unsupported number of frames */
- SKP_assert( 0 );
+ psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_NB_iCDF;
}
} else {
- psEnc->sCmn.predictLPCOrder = MAX_LPC_ORDER;
- psEnc->sCmn.psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_16;
- psEnc->sCmn.psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_16;
- if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ){
+ if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) {
psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_iCDF;
- } else if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR / 2 ){
- psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_iCDF;
} else {
- /* Unsupported number of frames */
- SKP_assert( 0 );
+ psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_iCDF;
}
}
+ if( psEnc->sCmn.fs_kHz == 8 || psEnc->sCmn.fs_kHz == 12 ) {
+ psEnc->sCmn.predictLPCOrder = MIN_LPC_ORDER;
+ psEnc->sCmn.psNLSF_CB = &SKP_Silk_NLSF_CB_NB_MB;
+ } else {
+ psEnc->sCmn.predictLPCOrder = MAX_LPC_ORDER;
+ psEnc->sCmn.psNLSF_CB = &SKP_Silk_NLSF_CB_WB;
+ }
psEnc->sCmn.subfr_length = SUB_FRAME_LENGTH_MS * fs_kHz;
psEnc->sCmn.frame_length = SKP_SMULBB( psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr );
psEnc->sCmn.ltp_mem_length = SKP_SMULBB( LTP_MEM_LENGTH_MS, fs_kHz );
psEnc->sCmn.la_pitch = SKP_SMULBB( LA_PITCH_MS, fs_kHz );
psEnc->sCmn.max_pitch_lag = SKP_SMULBB( 18, fs_kHz );
- if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ){
+ if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) {
psEnc->sCmn.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz );
- } else if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR / 2 ){
- psEnc->sCmn.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz );
} else {
- /* Unsupported number of frames */
- SKP_assert( 0 );
+ psEnc->sCmn.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz );
}
if( psEnc->sCmn.fs_kHz == 16 ) {
psEnc->sCmn.mu_LTP_Q9 = SKP_FIX_CONST( MU_LTP_QUANT_WB, 9 );
@@ -263,12 +260,9 @@
} else if( psEnc->sCmn.fs_kHz == 12 ) {
psEnc->sCmn.mu_LTP_Q9 = SKP_FIX_CONST( MU_LTP_QUANT_MB, 9 );
psEnc->sCmn.pitch_lag_low_bits_iCDF = SKP_Silk_uniform6_iCDF;
- } else if( psEnc->sCmn.fs_kHz == 8 ) {
+ } else {
psEnc->sCmn.mu_LTP_Q9 = SKP_FIX_CONST( MU_LTP_QUANT_NB, 9 );
psEnc->sCmn.pitch_lag_low_bits_iCDF = SKP_Silk_uniform4_iCDF;
- } else {
- /* unsupported sampling rate */
- SKP_assert( 0 );
}
}
--- a/src_FIX/SKP_Silk_encode_frame_FIX.c
+++ b/src_FIX/SKP_Silk_encode_frame_FIX.c
@@ -46,7 +46,7 @@
TIC(ENCODE_FRAME)
- if( psEnc->sCmn.nFramesAnalyzed == 0 ) {
+ if( psEnc->sCmn.nFramesAnalyzed == 0 && !psEnc->sCmn.prefillFlag && !( psEnc->sCmn.useDTX && psEnc->sCmn.inDTX ) ) {
/* Create space at start of payload for VAD and FEC flags */
SKP_uint8 iCDF[ 2 ] = { 0, 0 };
iCDF[ 0 ] = 256 - SKP_RSHIFT( 256, psEnc->sCmn.nFramesPerPacket + 1 );
@@ -105,12 +105,7 @@
/* High-pass filtering of the input signal */
/*******************************************/
TIC(HP_IN)
-#if HIGH_PASS_INPUT
- /* Variable high-pass filter */
SKP_Silk_HP_variable_cutoff( &psEnc->sCmn, x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.inputBuf, psEnc->sCmn.frame_length );
-#else
- SKP_memcpy( x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.inputBuf, psEnc->sCmn.frame_length * sizeof( SKP_int16 ) );
-#endif
TOC(HP_IN)
#if SWITCH_TRANSITION_FILTERING
@@ -175,6 +170,21 @@
}
TOC(NSQ)
+ /* Update input buffer */
+ SKP_memmove( psEnc->x_buf, &psEnc->x_buf[ psEnc->sCmn.frame_length ],
+ ( psEnc->sCmn.ltp_mem_length + LA_SHAPE_MS * psEnc->sCmn.fs_kHz ) * sizeof( SKP_int16 ) );
+
+ /* Parameters needed for next frame */
+ psEnc->sCmn.prevLag = sEncCtrl.pitchL[ psEnc->sCmn.nb_subfr - 1 ];
+ psEnc->sCmn.prevSignalType = psEnc->sCmn.indices.signalType;
+
+ /* Exit without entropy coding */
+ if( psEnc->sCmn.prefillFlag || ( psEnc->sCmn.useDTX && psEnc->sCmn.inDTX ) ) {
+ /* No payload */
+ *pnBytesOut = 0;
+ return ret;
+ }
+
/****************************************/
/* Encode Parameters */
/****************************************/
@@ -199,24 +209,12 @@
psEnc->BufferedInChannel_ms -= psEnc->sCmn.PacketSize_ms;
psEnc->BufferedInChannel_ms = SKP_LIMIT_int( psEnc->BufferedInChannel_ms, 0, 100 );
psEnc->sCmn.prev_nBits = nBits;
-
- /****************************************/
- /* Update Buffers and State */
- /****************************************/
- /* Update input buffer */
- SKP_memmove( psEnc->x_buf, &psEnc->x_buf[ psEnc->sCmn.frame_length ],
- ( psEnc->sCmn.ltp_mem_length + LA_SHAPE_MS * psEnc->sCmn.fs_kHz ) * sizeof( SKP_int16 ) );
-
- /* Parameters needed for next frame */
- psEnc->sCmn.prevLag = sEncCtrl.pitchL[ psEnc->sCmn.nb_subfr - 1 ];
- psEnc->sCmn.prevSignalType = psEnc->sCmn.indices.signalType;
psEnc->sCmn.first_frame_after_reset = 0;
- psEnc->sCmn.nFramesAnalyzed++;
/****************************************/
/* Finalize payload */
/****************************************/
- if( psEnc->sCmn.nFramesAnalyzed >= psEnc->sCmn.nFramesPerPacket ) {
+ if( ++psEnc->sCmn.nFramesAnalyzed >= psEnc->sCmn.nFramesPerPacket ) {
/* Insert VAD flags and FEC flag at beginning of bitstream */
flags = 0;
for( i = 0; i < psEnc->sCmn.nFramesPerPacket; i++ ) {
@@ -270,20 +268,19 @@
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, &psEnc->sCmn.indices.quantOffsetType, sizeof( SKP_int ) );
- tmp[ 0 ] = (SKP_float)psEnc->speech_activity_Q8 / 256.0f;
+ tmp[ 0 ] = (SKP_float)psEnc->sCmn.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)psEnc->sCmn.input_quality_bands_Q15[ i ] / 32768.0f;
}
DEBUG_STORE_DATA( input_quality_bands.dat, tmp, VAD_N_BANDS * sizeof( SKP_float ) );
- DEBUG_STORE_DATA( signalType.dat, &psEnc->sCmn.indices.signalType, sizeof( SKP_int ) );
- DEBUG_STORE_DATA( ratelevel.dat, &psEnc->sCmn.indices.RateLevelIndex, sizeof( SKP_int ) );
+ DEBUG_STORE_DATA( signalType.dat, &psEnc->sCmn.indices.signalType, sizeof( SKP_int8) );
DEBUG_STORE_DATA( lag_index.dat, &psEnc->sCmn.indices.lagIndex, sizeof( SKP_int16 ) );
DEBUG_STORE_DATA( contour_index.dat, &psEnc->sCmn.indices.contourIndex, sizeof( SKP_int8 ) );
- DEBUG_STORE_DATA( per_index.dat, &psEnc->sCmn.indices.PERIndex, sizeof( SKP_int ) );
+ DEBUG_STORE_DATA( per_index.dat, &psEnc->sCmn.indices.PERIndex, sizeof( SKP_int8) );
}
#endif
- return( ret );
+ return ret;
}
/* Low-Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode excitation at lower bitrate */
--- a/src_FIX/SKP_Silk_find_LPC_FIX.c
+++ b/src_FIX/SKP_Silk_find_LPC_FIX.c
@@ -30,14 +30,15 @@
/* Finds LPC vector from correlations, and converts to NLSF */
void SKP_Silk_find_LPC_FIX(
- SKP_int NLSF_Q15[], /* O NLSFs */
- SKP_int8 *interpIndex, /* O NLSF interpolation index, only used for NLSF interpolation */
- const SKP_int prev_NLSFq_Q15[], /* I previous NLSFs, only used for NLSF interpolation */
- const SKP_int useInterpolatedNLSFs, /* I Flag */
- const SKP_int LPC_order, /* I LPC order */
- const SKP_int16 x[], /* I Input signal */
- const SKP_int subfr_length, /* I Input signal subframe length including preceeding samples */
- const SKP_int nb_subfr /* I: Number of subframes */
+ SKP_int16 NLSF_Q15[], /* O NLSFs */
+ SKP_int8 *interpIndex, /* O NLSF interpolation index, only used for NLSF interpolation */
+ const SKP_int16 prev_NLSFq_Q15[], /* I previous NLSFs, only used for NLSF interpolation */
+ const SKP_int useInterpNLSFs, /* I Flag */
+ const SKP_int firstFrameAfterReset, /* I Flag */
+ const SKP_int LPC_order, /* I LPC order */
+ const SKP_int16 x[], /* I Input signal */
+ const SKP_int subfr_length, /* I Input signal subframe length including preceeding samples */
+ const SKP_int nb_subfr /* I: Number of subframes */
)
{
SKP_int k;
@@ -50,7 +51,7 @@
SKP_int32 a_tmp_Q16[ MAX_LPC_ORDER ], res_nrg_interp, res_nrg, res_tmp_nrg, res_nrg_2nd;
SKP_int res_nrg_interp_Q, res_nrg_Q, res_tmp_nrg_Q, res_nrg_2nd_Q;
SKP_int16 a_tmp_Q12[ MAX_LPC_ORDER ];
- SKP_int NLSF0_Q15[ MAX_LPC_ORDER ];
+ SKP_int16 NLSF0_Q15[ MAX_LPC_ORDER ];
SKP_int16 LPC_res[ ( MAX_FRAME_LENGTH + MAX_NB_SUBFR * MAX_LPC_ORDER ) / 2 ];
/* Default: no interpolation */
@@ -59,9 +60,13 @@
/* Burg AR analysis for the full frame */
SKP_Silk_burg_modified( &res_nrg, &res_nrg_Q, a_Q16, x, subfr_length, nb_subfr, SKP_FIX_CONST( FIND_LPC_COND_FAC, 32 ), LPC_order );
- SKP_Silk_bwexpander_32( a_Q16, LPC_order, SKP_FIX_CONST( FIND_LPC_CHIRP, 16 ) );
+ if( firstFrameAfterReset ) {
+ SKP_Silk_bwexpander_32( a_Q16, LPC_order, SKP_FIX_CONST( FIND_LPC_CHIRP_FIRST_FRAME, 16 ) );
+ } else {
+ SKP_Silk_bwexpander_32( a_Q16, LPC_order, SKP_FIX_CONST( FIND_LPC_CHIRP, 16 ) );
+ }
- if( useInterpolatedNLSFs == 1 && nb_subfr == MAX_NB_SUBFR ) {
+ if( useInterpNLSFs && !firstFrameAfterReset && nb_subfr == MAX_NB_SUBFR ) {
/* Optimal solution for last 10 ms */
SKP_Silk_burg_modified( &res_tmp_nrg, &res_tmp_nrg_Q, a_tmp_Q16, x + ( MAX_NB_SUBFR >> 1 ) * subfr_length,
@@ -147,4 +152,6 @@
/* NLSF interpolation is currently inactive, calculate NLSFs from full frame AR coefficients */
SKP_Silk_A2NLSF( NLSF_Q15, a_Q16, LPC_order );
}
+
+ SKP_assert( *interpIndex == 4 || ( useInterpNLSFs && !firstFrameAfterReset && nb_subfr == MAX_NB_SUBFR ) );
}
--- a/src_FIX/SKP_Silk_find_LTP_FIX.c
+++ b/src_FIX/SKP_Silk_find_LTP_FIX.c
@@ -89,7 +89,10 @@
}
SKP_assert( rr[ k ] >= 0 );
- regu = SKP_SMULWB( rr[ k ] + 1, SKP_FIX_CONST( LTP_DAMPING, 16 ) );
+ regu = 1;
+ regu = SKP_SMLAWB( regu, rr[ k ], SKP_FIX_CONST( LTP_DAMPING/3, 16 ) );
+ regu = SKP_SMLAWB( regu, matrix_ptr( WLTP_ptr, 0, 0, LTP_ORDER ), SKP_FIX_CONST( LTP_DAMPING/3, 16 ) );
+ regu = SKP_SMLAWB( regu, matrix_ptr( WLTP_ptr, LTP_ORDER-1, LTP_ORDER-1, LTP_ORDER ), SKP_FIX_CONST( LTP_DAMPING/3, 16 ) );
SKP_Silk_regularize_correlations_FIX( WLTP_ptr, &rr[k], regu, LTP_ORDER );
SKP_Silk_solve_LDL_FIX( WLTP_ptr, LTP_ORDER, Rr, b_Q16 ); /* WLTP_fix_ptr and Rr_fix_ptr both in Q(-corr_rshifts[k]) */
@@ -122,7 +125,7 @@
SKP_Silk_scale_vector32_Q26_lshift_18( WLTP_ptr, temp32, LTP_ORDER * LTP_ORDER ); /* WLTP_ptr in Q( 18 - corr_rshifts[ k ] ) */
- w[ k ] = matrix_ptr( WLTP_ptr, ( LTP_ORDER >> 1 ), ( LTP_ORDER >> 1 ), LTP_ORDER ); /* w in Q( 18 - corr_rshifts[ k ] ) */
+ w[ k ] = matrix_ptr( WLTP_ptr, LTP_ORDER/2, LTP_ORDER/2, LTP_ORDER ); /* w in Q( 18 - corr_rshifts[ k ] ) */
SKP_assert( w[k] >= 0 );
r_ptr += subfr_length;
--- a/src_FIX/SKP_Silk_find_pred_coefs_FIX.c
+++ b/src_FIX/SKP_Silk_find_pred_coefs_FIX.c
@@ -37,7 +37,7 @@
SKP_int i;
SKP_int32 WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ];
SKP_int32 invGains_Q16[ MAX_NB_SUBFR ], local_gains[ MAX_NB_SUBFR ], Wght_Q15[ MAX_NB_SUBFR ];
- SKP_int NLSF_Q15[ MAX_LPC_ORDER ];
+ SKP_int16 NLSF_Q15[ MAX_LPC_ORDER ];
const SKP_int16 *x_ptr;
SKP_int16 *x_pre_ptr, LPC_in_pre[ MAX_NB_SUBFR * MAX_LPC_ORDER + MAX_FRAME_LENGTH ];
SKP_int32 tmp, min_gain_Q16;
@@ -109,7 +109,7 @@
/* LPC_in_pre contains the LTP-filtered input for voiced, and the unfiltered input for unvoiced */
TIC(FIND_LPC)
SKP_Silk_find_LPC_FIX( NLSF_Q15, &psEnc->sCmn.indices.NLSFInterpCoef_Q2, psEnc->sCmn.prev_NLSFq_Q15,
- psEnc->sCmn.useInterpolatedNLSFs * ( 1 - psEnc->sCmn.first_frame_after_reset ), psEnc->sCmn.predictLPCOrder,
+ psEnc->sCmn.useInterpolatedNLSFs, psEnc->sCmn.first_frame_after_reset, psEnc->sCmn.predictLPCOrder,
LPC_in_pre, psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder, psEnc->sCmn.nb_subfr );
TOC(FIND_LPC)
--- a/src_FIX/SKP_Silk_init_encoder_FIX.c
+++ b/src_FIX/SKP_Silk_init_encoder_FIX.c
@@ -37,10 +37,8 @@
/* Clear the entire encoder state */
SKP_memset( psEnc, 0, sizeof( SKP_Silk_encoder_state_FIX ) );
-#if HIGH_PASS_INPUT
psEnc->sCmn.variable_HP_smth1_Q15 = 200844; /* = SKP_Silk_log2(70)_Q0; */
psEnc->sCmn.variable_HP_smth2_Q15 = 200844; /* = SKP_Silk_log2(70)_Q0; */
-#endif
/* Used to deactivate LSF interpolation, fluctuation reduction, pitch prediction */
psEnc->sCmn.first_frame_after_reset = 1;
--- a/src_FIX/SKP_Silk_main_FIX.h
+++ b/src_FIX/SKP_Silk_main_FIX.h
@@ -132,14 +132,15 @@
/* LPC analysis */
void SKP_Silk_find_LPC_FIX(
- SKP_int NLSF_Q15[], /* O NLSFs */
- SKP_int8 *interpIndex, /* O NLSF interpolation index, only used for NLSF interpolation */
- const SKP_int prev_NLSFq_Q15[], /* I previous NLSFs, only used for NLSF interpolation */
- const SKP_int useInterpolatedNLSFs, /* I Flag */
- const SKP_int LPC_order, /* I LPC order */
- const SKP_int16 x[], /* I Input signal */
- const SKP_int subfr_length, /* I Input signal subframe length including preceeding samples */
- const SKP_int nb_subfr /* I: Number of subframes */
+ SKP_int16 NLSF_Q15[], /* O NLSFs */
+ SKP_int8 *interpIndex, /* O NLSF interpolation index, only used for NLSF interpolation */
+ const SKP_int16 prev_NLSFq_Q15[], /* I previous NLSFs, only used for NLSF interpolation */
+ const SKP_int useInterpNLSFs, /* I Flag */
+ const SKP_int firstFrameAfterReset, /* I Flag */
+ const SKP_int LPC_order, /* I LPC order */
+ const SKP_int16 x[], /* I Input signal */
+ const SKP_int subfr_length, /* I Input signal subframe length including preceeding samples */
+ const SKP_int nb_subfr /* I: Number of subframes */
);
/* LTP analysis */
--- a/src_FLP/SKP_Silk_control_codec_FLP.c
+++ b/src_FLP/SKP_Silk_control_codec_FLP.c
@@ -55,7 +55,7 @@
{
SKP_int fs_kHz, ret = 0;
- if( psEnc->sCmn.controlled_since_last_payload != 0 ) {
+ if( psEnc->sCmn.controlled_since_last_payload != 0 && psEnc->sCmn.prefillFlag == 0 ) {
if( psEnc->sCmn.API_fs_Hz != psEnc->sCmn.prev_API_fs_Hz && psEnc->sCmn.fs_kHz > 0 ) {
/* Change in API sampling rate in the middle of encoding a packet */
ret += SKP_Silk_setup_resamplers( psEnc, psEnc->sCmn.fs_kHz );
@@ -180,10 +180,10 @@
( PacketSize_ms != 60 ) ) {
ret = SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED;
}
- if( PacketSize_ms == 10 ) {
- /* Only allowed when the payload buffer is empty */
+ if( PacketSize_ms <= 10 ) {
psEnc->sCmn.nFramesPerPacket = 1;
- psEnc->sCmn.nb_subfr = MAX_NB_SUBFR >> 1;
+ psEnc->sCmn.nb_subfr = PacketSize_ms == 10 ? 2 : 1;
+ psEnc->sCmn.frame_length = PacketSize_ms * fs_kHz;
psEnc->sCmn.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;
@@ -193,6 +193,7 @@
} else {
psEnc->sCmn.nFramesPerPacket = SKP_DIV32_16( PacketSize_ms, MAX_FRAME_LENGTH_MS );
psEnc->sCmn.nb_subfr = MAX_NB_SUBFR;
+ psEnc->sCmn.frame_length = 20 * fs_kHz;
psEnc->sCmn.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;
@@ -200,10 +201,13 @@
psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_iCDF;
}
}
- psEnc->sCmn.PacketSize_ms = PacketSize_ms;
+ psEnc->sCmn.PacketSize_ms = PacketSize_ms;
+ psEnc->sCmn.TargetRate_bps = 0; /* trigger new SNR computation */
}
/* Set internal sampling frequency */
+ SKP_assert( fs_kHz == 8 || fs_kHz == 12 || fs_kHz == 16 );
+ SKP_assert( psEnc->sCmn.nb_subfr == 2 || psEnc->sCmn.nb_subfr == 4 );
if( psEnc->sCmn.fs_kHz != fs_kHz ) {
/* reset part of the state */
SKP_memset( &psEnc->sShape, 0, sizeof( SKP_Silk_shape_state_FLP ) );
@@ -225,42 +229,34 @@
psEnc->sCmn.fs_kHz = fs_kHz;
if( psEnc->sCmn.fs_kHz == 8 ) {
- psEnc->sCmn.predictLPCOrder = MIN_LPC_ORDER;
- psEnc->sCmn.psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_10;
- psEnc->sCmn.psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_10;
- if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ){
+ if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) {
psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_NB_iCDF;
- } else if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR / 2 ){
- psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_NB_iCDF;
} else {
- /* Unsupported number of frames */
- SKP_assert( 0 );
+ psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_NB_iCDF;
}
} else {
- psEnc->sCmn.predictLPCOrder = MAX_LPC_ORDER;
- psEnc->sCmn.psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_16;
- psEnc->sCmn.psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_16;
- if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ){
+ if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) {
psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_iCDF;
- } else if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR / 2 ){
- psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_iCDF;
} else {
- /* Unsupported number of frames */
- SKP_assert( 0 );
+ psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_iCDF;
}
}
+ if( psEnc->sCmn.fs_kHz == 8 || psEnc->sCmn.fs_kHz == 12 ) {
+ psEnc->sCmn.predictLPCOrder = MIN_LPC_ORDER;
+ psEnc->sCmn.psNLSF_CB = &SKP_Silk_NLSF_CB_NB_MB;
+ } else {
+ psEnc->sCmn.predictLPCOrder = MAX_LPC_ORDER;
+ psEnc->sCmn.psNLSF_CB = &SKP_Silk_NLSF_CB_WB;
+ }
psEnc->sCmn.subfr_length = SUB_FRAME_LENGTH_MS * fs_kHz;
psEnc->sCmn.frame_length = psEnc->sCmn.subfr_length * psEnc->sCmn.nb_subfr;
psEnc->sCmn.ltp_mem_length = LTP_MEM_LENGTH_MS * fs_kHz;
psEnc->sCmn.la_pitch = LA_PITCH_MS * fs_kHz;
psEnc->sCmn.max_pitch_lag = 18 * fs_kHz;
- if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ){
+ if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) {
psEnc->sCmn.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz );
- } else if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR / 2 ){
- psEnc->sCmn.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz );
} else {
- /* Unsupported number of frames */
- SKP_assert( 0 );
+ psEnc->sCmn.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz );
}
if( psEnc->sCmn.fs_kHz == 16 ) {
psEnc->sCmn.mu_LTP_Q9 = SKP_FIX_CONST( MU_LTP_QUANT_WB, 9 );
@@ -268,12 +264,9 @@
} else if( psEnc->sCmn.fs_kHz == 12 ) {
psEnc->sCmn.mu_LTP_Q9 = SKP_FIX_CONST( MU_LTP_QUANT_MB, 9 );
psEnc->sCmn.pitch_lag_low_bits_iCDF = SKP_Silk_uniform6_iCDF;
- } else if( psEnc->sCmn.fs_kHz == 8 ) {
+ } else {
psEnc->sCmn.mu_LTP_Q9 = SKP_FIX_CONST( MU_LTP_QUANT_NB, 9 );
psEnc->sCmn.pitch_lag_low_bits_iCDF = SKP_Silk_uniform4_iCDF;
- } else {
- /* unsupported sampling rate */
- SKP_assert( 0 );
}
}
--- a/src_FLP/SKP_Silk_encode_frame_FLP.c
+++ b/src_FLP/SKP_Silk_encode_frame_FLP.c
@@ -47,7 +47,7 @@
TIC(ENCODE_FRAME)
- if( psEnc->sCmn.nFramesAnalyzed == 0 ) {
+ if( psEnc->sCmn.nFramesAnalyzed == 0 && !psEnc->sCmn.prefillFlag && !( psEnc->sCmn.useDTX && psEnc->sCmn.inDTX ) ) {
/* Create space at start of payload for VAD and FEC flags */
SKP_uint8 iCDF[ 2 ] = { 0, 0 };
iCDF[ 0 ] = 256 - SKP_RSHIFT( 256, psEnc->sCmn.nFramesPerPacket + 1 );
@@ -106,12 +106,7 @@
/* High-pass filtering of the input signal */
/*******************************************/
TIC(HP_IN)
-#if HIGH_PASS_INPUT
- /* Variable high-pass filter */
SKP_Silk_HP_variable_cutoff( &psEnc->sCmn, pIn_HP, psEnc->sCmn.inputBuf, psEnc->sCmn.frame_length );
-#else
- SKP_memcpy( pIn_HP, psEnc->sCmn.inputBuf, psEnc->sCmn.frame_length * sizeof( SKP_int16 ) );
-#endif
TOC(HP_IN)
#if SWITCH_TRANSITION_FILTERING
@@ -178,6 +173,21 @@
SKP_Silk_NSQ_wrapper_FLP( psEnc, &sEncCtrl, &psEnc->sCmn.indices, &psEnc->sCmn.sNSQ, psEnc->sCmn.pulses, xfw );
TOC(NSQ)
+ /* Update input buffer */
+ SKP_memmove( psEnc->x_buf, &psEnc->x_buf[ psEnc->sCmn.frame_length ],
+ ( psEnc->sCmn.ltp_mem_length + LA_SHAPE_MS * psEnc->sCmn.fs_kHz ) * sizeof( SKP_float ) );
+
+ /* Parameters needed for next frame */
+ psEnc->sCmn.prevLag = sEncCtrl.pitchL[ psEnc->sCmn.nb_subfr - 1 ];
+ psEnc->sCmn.prevSignalType = psEnc->sCmn.indices.signalType;
+
+ /* Exit without entropy coding */
+ if( psEnc->sCmn.prefillFlag || ( psEnc->sCmn.useDTX && psEnc->sCmn.inDTX ) ) {
+ /* No payload */
+ *pnBytesOut = 0;
+ return ret;
+ }
+
/****************************************/
/* Encode Parameters */
/****************************************/
@@ -202,24 +212,12 @@
psEnc->BufferedInChannel_ms -= psEnc->sCmn.nb_subfr * SUB_FRAME_LENGTH_MS;
psEnc->BufferedInChannel_ms = SKP_LIMIT_float( psEnc->BufferedInChannel_ms, 0.0f, 100.0f );
psEnc->sCmn.prev_nBits = nBits;
-
- /****************************************/
- /* Update Buffers and State */
- /****************************************/
- /* Update input buffer */
- SKP_memmove( psEnc->x_buf, &psEnc->x_buf[ psEnc->sCmn.frame_length ],
- ( psEnc->sCmn.ltp_mem_length + LA_SHAPE_MS * psEnc->sCmn.fs_kHz ) * sizeof( SKP_float ) );
-
- /* Parameters needed for next frame */
- psEnc->sCmn.prevLag = sEncCtrl.pitchL[ psEnc->sCmn.nb_subfr - 1 ];
- psEnc->sCmn.prevSignalType = psEnc->sCmn.indices.signalType;
psEnc->sCmn.first_frame_after_reset = 0;
- psEnc->sCmn.nFramesAnalyzed++;
/****************************************/
/* Finalize payload */
/****************************************/
- if( psEnc->sCmn.nFramesAnalyzed >= psEnc->sCmn.nFramesPerPacket ) {
+ if( ++psEnc->sCmn.nFramesAnalyzed >= psEnc->sCmn.nFramesPerPacket ) {
/* Insert VAD flags and FEC flag at beginning of bitstream */
flags = 0;
for( i = 0; i < psEnc->sCmn.nFramesPerPacket; i++ ) {
@@ -248,24 +246,21 @@
DEBUG_STORE_DATA( pitchL.dat, sEncCtrl.pitchL, MAX_NB_SUBFR * sizeof( SKP_int ) );
DEBUG_STORE_DATA( pitchG_quantized.dat, sEncCtrl.LTPCoef, psEnc->sCmn.nb_subfr * LTP_ORDER * sizeof( SKP_float ) );
DEBUG_STORE_DATA( LTPcorr.dat, &psEnc->LTPCorr, sizeof( SKP_float ) );
- DEBUG_STORE_DATA( tilt.dat, &sEncCtrl.input_tilt, sizeof( SKP_float ) );
DEBUG_STORE_DATA( gains.dat, sEncCtrl.Gains, psEnc->sCmn.nb_subfr * sizeof( SKP_float ) );
- DEBUG_STORE_DATA( gains_indices.dat, &sEncCtrl.sCmn.GainsIndices, psEnc->sCmn.nb_subfr * sizeof( SKP_int ) );
+ DEBUG_STORE_DATA( gains_indices.dat, &psEnc->sCmn.indices.GainsIndices, psEnc->sCmn.nb_subfr * sizeof( SKP_int8 ) );
DEBUG_STORE_DATA( nBits.dat, &nBits, sizeof( SKP_int ) );
DEBUG_STORE_DATA( current_SNR_db.dat, &sEncCtrl.current_SNR_dB, sizeof( SKP_float ) );
- DEBUG_STORE_DATA( quantOffsetType.dat, &sEncCtrl.sCmn.quantOffsetType, sizeof( SKP_int ) );
- DEBUG_STORE_DATA( speech_activity_q8.dat, &psEnc->speech_activity_Q8, sizeof( SKP_in ) );
- DEBUG_STORE_DATA( input_quality_bands.dat, sEncCtrl.input_quality_bands, VAD_N_BANDS * sizeof( SKP_float ) );
- 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 ) );
- DEBUG_STORE_DATA( per_index.dat, &sEncCtrl.sCmn.PERIndex, sizeof( SKP_int ) );
+ DEBUG_STORE_DATA( quantOffsetType.dat, &psEnc->sCmn.indices.quantOffsetType, sizeof( SKP_int8 ) );
+ DEBUG_STORE_DATA( speech_activity_q8.dat, &psEnc->sCmn.speech_activity_Q8, sizeof( SKP_int ) );
+ DEBUG_STORE_DATA( signalType.dat, &psEnc->sCmn.indices.signalType, sizeof( SKP_int8 ) );
+ DEBUG_STORE_DATA( lag_index.dat, &psEnc->sCmn.indices.lagIndex, sizeof( SKP_int16 ) );
+ DEBUG_STORE_DATA( contour_index.dat, &psEnc->sCmn.indices.contourIndex, sizeof( SKP_int8 ) );
+ DEBUG_STORE_DATA( per_index.dat, &psEnc->sCmn.indices.PERIndex, sizeof( SKP_int8 ) );
DEBUG_STORE_DATA( PredCoef.dat, &sEncCtrl.PredCoef[ 1 ], psEnc->sCmn.predictLPCOrder * sizeof( SKP_float ) );
- DEBUG_STORE_DATA( ltp_scale_idx.dat, &sEncCtrl.sCmn.LTP_scaleIndex, sizeof( SKP_int ) );
+ DEBUG_STORE_DATA( ltp_scale_idx.dat, &psEnc->sCmn.indices.LTP_scaleIndex, sizeof( SKP_int8 ) );
// DEBUG_STORE_DATA( xq.dat, psEnc->sCmn.sNSQ.xqBuf, psEnc->sCmn.frame_length * sizeof( SKP_float ) );
#endif
- return( ret );
+ return ret;
}
/* Low-Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode excitation at lower bitrate */
--- a/src_FLP/SKP_Silk_find_LPC_FLP.c
+++ b/src_FLP/SKP_Silk_find_LPC_FLP.c
@@ -29,14 +29,15 @@
#include "SKP_Silk_tuning_parameters.h"
void SKP_Silk_find_LPC_FLP(
- SKP_int NLSF_Q15[], /* O NLSFs */
- SKP_int8 *interpIndex, /* O NLSF interp. index for NLSF interp. */
- const SKP_int prev_NLSFq_Q15[], /* I Previous NLSFs, for NLSF interpolation */
- const SKP_int useInterpNLSFs, /* I Flag */
- const SKP_int LPC_order, /* I LPC order */
- const SKP_float x[], /* I Input signal */
- const SKP_int subfr_length, /* I Subframe length incl preceeding samples */
- const SKP_int nb_subfr /* I: Number of subframes */
+ SKP_int16 NLSF_Q15[], /* O NLSFs */
+ SKP_int8 *interpIndex, /* O NLSF interp. index for NLSF interp. */
+ const SKP_int16 prev_NLSFq_Q15[], /* I Previous NLSFs, for NLSF interpolation */
+ const SKP_int useInterpNLSFs, /* I Flag */
+ const SKP_int firstFrameAfterReset, /* I Flag */
+ const SKP_int LPC_order, /* I LPC order */
+ const SKP_float x[], /* I Input signal */
+ const SKP_int subfr_length, /* I Subframe length incl preceeding samples */
+ const SKP_int nb_subfr /* I: Number of subframes */
)
{
SKP_int k;
@@ -44,7 +45,7 @@
/* Used only for NLSF interpolation */
double res_nrg, res_nrg_2nd, res_nrg_interp;
- SKP_int NLSF0_Q15[ MAX_LPC_ORDER ];
+ SKP_int16 NLSF0_Q15[ MAX_LPC_ORDER ];
SKP_float a_tmp[ MAX_LPC_ORDER ];
SKP_float LPC_res[ ( MAX_FRAME_LENGTH + MAX_NB_SUBFR * MAX_LPC_ORDER ) / 2 ];
@@ -54,11 +55,18 @@
/* Burg AR analysis for the full frame */
res_nrg = SKP_Silk_burg_modified_FLP( a, x, subfr_length, nb_subfr, FIND_LPC_COND_FAC, LPC_order );
- if( useInterpNLSFs == 1 && nb_subfr == MAX_NB_SUBFR ) {
+ if( firstFrameAfterReset ) {
+ SKP_Silk_bwexpander_FLP( a, LPC_order, FIND_LPC_CHIRP_FIRST_FRAME );
+ } else {
+ SKP_Silk_bwexpander_FLP( a_tmp, LPC_order, FIND_LPC_CHIRP );
+ }
+
+ if( useInterpNLSFs && !firstFrameAfterReset && nb_subfr == MAX_NB_SUBFR ) {
/* Optimal solution for last 10 ms; subtract residual energy here, as that's easier than */
/* adding it to the residual energy of the first 10 ms in each iteration of the search below */
res_nrg -= SKP_Silk_burg_modified_FLP( a_tmp, x + ( MAX_NB_SUBFR / 2 ) * subfr_length,
subfr_length, MAX_NB_SUBFR / 2, FIND_LPC_COND_FAC, LPC_order );
+
SKP_Silk_bwexpander_FLP( a_tmp, LPC_order, FIND_LPC_CHIRP );
/* Convert to NLSFs */
@@ -97,4 +105,5 @@
SKP_Silk_A2NLSF_FLP( NLSF_Q15, a, LPC_order );
}
+ SKP_assert( *interpIndex == 4 || ( useInterpNLSFs && !firstFrameAfterReset && nb_subfr == MAX_NB_SUBFR ) );
}
--- a/src_FLP/SKP_Silk_find_LTP_FLP.c
+++ b/src_FLP/SKP_Silk_find_LTP_FLP.c
@@ -58,7 +58,10 @@
SKP_Silk_corrVector_FLP( lag_ptr, r_ptr, subfr_length, LTP_ORDER, Rr );
rr[ k ] = ( SKP_float )SKP_Silk_energy_FLP( r_ptr, subfr_length );
- regu = LTP_DAMPING * ( rr[ k ] + 1.0f );
+ regu = 1.0f + rr[ k ] +
+ matrix_ptr( WLTP_ptr, 0, 0, LTP_ORDER ) +
+ matrix_ptr( WLTP_ptr, LTP_ORDER-1, LTP_ORDER-1, LTP_ORDER );
+ regu *= LTP_DAMPING / 3;
SKP_Silk_regularize_correlations_FLP( WLTP_ptr, &rr[ k ], regu, LTP_ORDER );
SKP_Silk_solve_LDL_FLP( WLTP_ptr, LTP_ORDER, Rr, b_ptr );
--- a/src_FLP/SKP_Silk_find_pred_coefs_FLP.c
+++ b/src_FLP/SKP_Silk_find_pred_coefs_FLP.c
@@ -38,7 +38,7 @@
SKP_int i;
SKP_float WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ];
SKP_float invGains[ MAX_NB_SUBFR ], Wght[ MAX_NB_SUBFR ];
- SKP_int NLSF_Q15[ MAX_LPC_ORDER ];
+ SKP_int16 NLSF_Q15[ MAX_LPC_ORDER ];
const SKP_float *x_ptr;
SKP_float *x_pre_ptr, LPC_in_pre[ MAX_NB_SUBFR * MAX_LPC_ORDER + MAX_FRAME_LENGTH ];
@@ -95,7 +95,7 @@
/* LPC_in_pre contains the LTP-filtered input for voiced, and the unfiltered input for unvoiced */
SKP_Silk_find_LPC_FLP( NLSF_Q15, &psEnc->sCmn.indices.NLSFInterpCoef_Q2, psEnc->sCmn.prev_NLSFq_Q15,
- psEnc->sCmn.useInterpolatedNLSFs * ( 1 - psEnc->sCmn.first_frame_after_reset ), psEnc->sCmn.predictLPCOrder,
+ psEnc->sCmn.useInterpolatedNLSFs, psEnc->sCmn.first_frame_after_reset, psEnc->sCmn.predictLPCOrder,
LPC_in_pre, psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder, psEnc->sCmn.nb_subfr );
--- a/src_FLP/SKP_Silk_init_encoder_FLP.c
+++ b/src_FLP/SKP_Silk_init_encoder_FLP.c
@@ -39,10 +39,8 @@
/* Clear the entire encoder state */
SKP_memset( psEnc, 0, sizeof( SKP_Silk_encoder_state_FLP ) );
-#if HIGH_PASS_INPUT
psEnc->sCmn.variable_HP_smth1_Q15 = 200844; /* = SKP_Silk_log2(70)_Q0; */
psEnc->sCmn.variable_HP_smth2_Q15 = 200844; /* = SKP_Silk_log2(70)_Q0; */
-#endif
/* Used to deactivate e.g. LSF interpolation and fluctuation reduction */
psEnc->sCmn.first_frame_after_reset = 1;
--- a/src_FLP/SKP_Silk_main_FLP.h
+++ b/src_FLP/SKP_Silk_main_FLP.h
@@ -133,14 +133,15 @@
/* LPC analysis */
void SKP_Silk_find_LPC_FLP(
- SKP_int NLSF_Q15[], /* O NLSFs */
- SKP_int8 *interpIndex, /* O NLSF interp. index for NLSF interp. */
- const SKP_int prev_NLSFq_Q15[], /* I Previous NLSFs, for NLSF interpolation */
- const SKP_int useInterpNLSFs, /* I Flag */
- const SKP_int LPC_order, /* I LPC order */
- const SKP_float x[], /* I Input signal */
- const SKP_int subfr_length, /* I Subframe length incl preceeding samples */
- const SKP_int nb_subfr /* I: Number of subframes */
+ SKP_int16 NLSF_Q15[], /* O NLSFs */
+ SKP_int8 *interpIndex, /* O NLSF interp. index for NLSF interp. */
+ const SKP_int16 prev_NLSFq_Q15[], /* I Previous NLSFs, for NLSF interpolation */
+ const SKP_int useInterpNLSFs, /* I Flag */
+ const SKP_int firstFrameAfterReset, /* I Flag */
+ const SKP_int LPC_order, /* I LPC order */
+ const SKP_float x[], /* I Input signal */
+ const SKP_int subfr_length, /* I Subframe length incl preceeding samples */
+ const SKP_int nb_subfr /* I: Number of subframes */
);
/* LTP analysis */
@@ -206,8 +207,8 @@
void SKP_Silk_process_NLSFs_FLP(
SKP_Silk_encoder_state *psEncC, /* I/O Encoder state */
SKP_float PredCoef[ 2 ][ MAX_LPC_ORDER ], /* O Prediction coefficients */
- SKP_int NLSF_Q15[ MAX_LPC_ORDER ], /* I/O Normalized LSFs (quant out) (0 - (2^15-1)) */
- const SKP_int prev_NLSF_Q15[ MAX_LPC_ORDER ] /* I Previous Normalized LSFs (0 - (2^15-1)) */
+ SKP_int16 NLSF_Q15[ MAX_LPC_ORDER ], /* I/O Normalized LSFs (quant out) (0 - (2^15-1)) */
+ const SKP_int16 prev_NLSF_Q15[ MAX_LPC_ORDER ] /* I Previous Normalized LSFs (0 - (2^15-1)) */
);
/* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */
@@ -288,7 +289,7 @@
/* Convert AR filter coefficients to NLSF parameters */
void SKP_Silk_A2NLSF_FLP(
- SKP_int *NLSF_Q15, /* O NLSF vector [ LPC_order ] */
+ SKP_int16 *NLSF_Q15, /* O NLSF vector [ LPC_order ] */
const SKP_float *pAR, /* I LPC coefficients [ LPC_order ] */
const SKP_int LPC_order /* I LPC order */
);
@@ -296,17 +297,8 @@
/* Convert NLSF parameters to AR prediction filter coefficients */
void SKP_Silk_NLSF2A_stable_FLP(
SKP_float *pAR, /* O LPC coefficients [ LPC_order ] */
- const SKP_int *NLSF_Q15, /* I NLSF vector [ LPC_order ] */
+ const SKP_int16 *NLSF_Q15, /* I NLSF vector [ LPC_order ] */
const SKP_int LPC_order /* I LPC order */
-);
-
-/* Interpolation function with fixed point rounding */
-void SKP_Silk_interpolate_wrapper_FLP(
- SKP_float xi[], /* O Interpolated vector */
- const SKP_float x0[], /* I First vector */
- const SKP_float x1[], /* I Second vector */
- const SKP_float ifact, /* I Interp. factor, weight on second vector */
- const SKP_int d /* I Number of parameters */
);
/****************************************/
--- a/src_FLP/SKP_Silk_wrappers_FLP.c
+++ b/src_FLP/SKP_Silk_wrappers_FLP.c
@@ -31,7 +31,7 @@
/* Convert AR filter coefficients to NLSF parameters */
void SKP_Silk_A2NLSF_FLP(
- SKP_int *NLSF_Q15, /* O NLSF vector [ LPC_order ] */
+ SKP_int16 *NLSF_Q15, /* O NLSF vector [ LPC_order ] */
const SKP_float *pAR, /* I LPC coefficients [ LPC_order ] */
const SKP_int LPC_order /* I LPC order */
)
@@ -49,7 +49,7 @@
/* Convert LSF parameters to AR prediction filter coefficients */
void SKP_Silk_NLSF2A_stable_FLP(
SKP_float *pAR, /* O LPC coefficients [ LPC_order ] */
- const SKP_int *NLSF_Q15, /* I NLSF vector [ LPC_order ] */
+ const SKP_int16 *NLSF_Q15, /* I NLSF vector [ LPC_order ] */
const SKP_int LPC_order /* I LPC order */
)
{
@@ -69,8 +69,8 @@
void SKP_Silk_process_NLSFs_FLP(
SKP_Silk_encoder_state *psEncC, /* I/O Encoder state */
SKP_float PredCoef[ 2 ][ MAX_LPC_ORDER ], /* O Prediction coefficients */
- SKP_int NLSF_Q15[ MAX_LPC_ORDER ], /* I/O Normalized LSFs (quant out) (0 - (2^15-1)) */
- const SKP_int prev_NLSF_Q15[ MAX_LPC_ORDER ] /* I Previous Normalized LSFs (0 - (2^15-1)) */
+ SKP_int16 NLSF_Q15[ MAX_LPC_ORDER ], /* I/O Normalized LSFs (quant out) (0 - (2^15-1)) */
+ const SKP_int16 prev_NLSF_Q15[ MAX_LPC_ORDER ] /* I Previous Normalized LSFs (0 - (2^15-1)) */
)
{
SKP_int i, j;
--- a/src_SigProc_FIX/SKP_Silk_A2NLSF.c
+++ b/src_SigProc_FIX/SKP_Silk_A2NLSF.c
@@ -117,7 +117,7 @@
/* Compute Normalized Line Spectral Frequencies (NLSFs) from whitening filter coefficients */
/* If not all roots are found, the a_Q16 coefficients are bandwidth expanded until convergence. */
void SKP_Silk_A2NLSF(
- SKP_int *NLSF, /* O Normalized Line Spectral Frequencies, Q15 (0 - (2^15-1)), [d] */
+ SKP_int16 *NLSF, /* O Normalized Line Spectral Frequencies, Q15 (0 - (2^15-1)), [d] */
SKP_int32 *a_Q16, /* I/O Monic whitening filter coefficients in Q16 [d] */
const SKP_int d /* I Filter order (must be even) */
)
@@ -210,9 +210,9 @@
ffrac += SKP_DIV32( ylo, SKP_RSHIFT( ylo - yhi, 8 - BIN_DIV_STEPS_A2NLSF_FIX ) );
}
#if OVERSAMPLE_COSINE_TABLE
- NLSF[ root_ix ] = (SKP_int)SKP_min_32( SKP_LSHIFT( (SKP_int32)k, 7 ) + ffrac, SKP_int16_MAX );
+ NLSF[ root_ix ] = (SKP_int16)SKP_min_32( SKP_LSHIFT( (SKP_int32)k, 7 ) + ffrac, SKP_int16_MAX );
#else
- NLSF[ root_ix ] = (SKP_int)SKP_min_32( SKP_LSHIFT( (SKP_int32)k, 8 ) + ffrac, SKP_int16_MAX );
+ NLSF[ root_ix ] = (SKP_int16)SKP_min_32( SKP_LSHIFT( (SKP_int32)k, 8 ) + ffrac, SKP_int16_MAX );
#endif
SKP_assert( NLSF[ root_ix ] >= 0 );
@@ -249,9 +249,9 @@
i++;
if( i > MAX_ITERATIONS_A2NLSF_FIX ) {
/* Set NLSFs to white spectrum and exit */
- NLSF[ 0 ] = SKP_DIV32_16( 1 << 15, d + 1 );
+ NLSF[ 0 ] = (SKP_int16)SKP_DIV32_16( 1 << 15, d + 1 );
for( k = 1; k < d; k++ ) {
- NLSF[ k ] = SKP_SMULBB( k + 1, NLSF[ 0 ] );
+ NLSF[ k ] = (SKP_int16)SKP_SMULBB( k + 1, NLSF[ 0 ] );
}
return;
}
--- a/src_SigProc_FIX/SKP_Silk_Inlines.h
+++ b/src_SigProc_FIX/SKP_Silk_Inlines.h
@@ -205,69 +205,6 @@
}
}
-#define SKP_SIN_APPROX_CONST0 (1073735400)
-#define SKP_SIN_APPROX_CONST1 (-82778932)
-#define SKP_SIN_APPROX_CONST2 (1059577)
-#define SKP_SIN_APPROX_CONST3 (-5013)
-
-/* Sine approximation; an input of 65536 corresponds to 2 * pi */
-/* Uses polynomial expansion of the input to the power 0, 2, 4 and 6 */
-/* The relative error is below 1e-5 */
-SKP_INLINE SKP_int32 SKP_Silk_SIN_APPROX_Q24( /* O returns approximately 2^24 * sin(x * 2 * pi / 65536) */
- SKP_int32 x
-)
-{
- SKP_int y_Q30;
-
- /* Keep only bottom 16 bits (the function repeats itself with period 65536) */
- x &= 65535;
-
- /* Split range in four quadrants */
- if( x <= 32768 ) {
- if( x < 16384 ) {
- /* Return cos(pi/2 - x) */
- x = 16384 - x;
- } else {
- /* Return cos(x - pi/2) */
- x -= 16384;
- }
- if( x < 1100 ) {
- /* Special case: high accuracy */
- return SKP_SMLAWB( 1 << 24, SKP_MUL( x, x ), -5053 );
- }
- x = SKP_SMULWB( SKP_LSHIFT( x, 8 ), x ); /* contains x^2 in Q20 */
- y_Q30 = SKP_SMLAWB( SKP_SIN_APPROX_CONST2, x, SKP_SIN_APPROX_CONST3 );
- y_Q30 = SKP_SMLAWW( SKP_SIN_APPROX_CONST1, x, y_Q30 );
- y_Q30 = SKP_SMLAWW( SKP_SIN_APPROX_CONST0 + 66, x, y_Q30 );
- } else {
- if( x < 49152 ) {
- /* Return -cos(3*pi/2 - x) */
- x = 49152 - x;
- } else {
- /* Return -cos(x - 3*pi/2) */
- x -= 49152;
- }
- if( x < 1100 ) {
- /* Special case: high accuracy */
- return SKP_SMLAWB( -1 << 24, SKP_MUL( x, x ), 5053 );
- }
- x = SKP_SMULWB( SKP_LSHIFT( x, 8 ), x ); /* contains x^2 in Q20 */
- y_Q30 = SKP_SMLAWB( -SKP_SIN_APPROX_CONST2, x, -SKP_SIN_APPROX_CONST3 );
- y_Q30 = SKP_SMLAWW( -SKP_SIN_APPROX_CONST1, x, y_Q30 );
- y_Q30 = SKP_SMLAWW( -SKP_SIN_APPROX_CONST0, x, y_Q30 );
- }
- return SKP_RSHIFT_ROUND( y_Q30, 6 );
-}
-
-/* Cosine approximation; an input of 65536 corresponds to 2 * pi */
-/* The relative error is below 1e-5 */
-SKP_INLINE SKP_int32 SKP_Silk_COS_APPROX_Q24( /* O returns approximately 2^24 * cos(x * 2 * pi / 65536) */
- SKP_int32 x
-)
-{
- return SKP_Silk_SIN_APPROX_Q24( x + 16384 );
-}
-
#ifdef __cplusplus
}
#endif
--- a/src_SigProc_FIX/SKP_Silk_NLSF2A.c
+++ b/src_SigProc_FIX/SKP_Silk_NLSF2A.c
@@ -35,7 +35,7 @@
/* helper function for NLSF2A(..) */
SKP_INLINE void SKP_Silk_NLSF2A_find_poly(
- SKP_int32 *out, /* o intermediate polynomial, Q20 */
+ SKP_int32 *out, /* o intermediate polynomial, Q20 */
const SKP_int32 *cLSF, /* i vector of interleaved 2*cos(LSFs), Q20 */
SKP_int dd /* i polynomial order (= 1/2 * filter order) */
)
@@ -57,8 +57,8 @@
/* compute whitening filter coefficients from normalized line spectral frequencies */
void SKP_Silk_NLSF2A(
- SKP_int16 *a, /* o monic whitening filter coefficients in Q12, [d] */
- const SKP_int *NLSF, /* i normalized line spectral frequencies in Q15, [d] */
+ SKP_int16 *a, /* o monic whitening filter coefficients in Q12, [d] */
+ const SKP_int16 *NLSF, /* i normalized line spectral frequencies in Q15, [d] */
const SKP_int d /* i filter order (should be even) */
)
{
--- a/src_SigProc_FIX/SKP_Silk_NLSF_VQ_weights_laroia.c
+++ b/src_SigProc_FIX/SKP_Silk_NLSF_VQ_weights_laroia.c
@@ -37,8 +37,8 @@
/* Laroia low complexity NLSF weights */
void SKP_Silk_NLSF_VQ_weights_laroia(
- SKP_int *pNLSFW_Q5, /* O: Pointer to input vector weights [D x 1] */
- const SKP_int *pNLSF_Q15, /* I: Pointer to input vector [D x 1] */
+ SKP_int16 *pNLSFW_Q5, /* O: Pointer to input vector weights [D x 1] */
+ const SKP_int16 *pNLSF_Q15, /* I: Pointer to input vector [D x 1] */
const SKP_int D /* I: Input vector dimension (even) */
)
{
@@ -53,7 +53,7 @@
tmp1_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp1_int );
tmp2_int = SKP_max_int( pNLSF_Q15[ 1 ] - pNLSF_Q15[ 0 ], 1 );
tmp2_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp2_int );
- pNLSFW_Q5[ 0 ] = (SKP_int)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX );
+ pNLSFW_Q5[ 0 ] = (SKP_int16)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX );
SKP_assert( pNLSFW_Q5[ 0 ] > 0 );
/* Main loop */
@@ -60,12 +60,12 @@
for( k = 1; k < D - 1; k += 2 ) {
tmp1_int = SKP_max_int( pNLSF_Q15[ k + 1 ] - pNLSF_Q15[ k ], 1 );
tmp1_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp1_int );
- pNLSFW_Q5[ k ] = (SKP_int)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX );
+ pNLSFW_Q5[ k ] = (SKP_int16)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX );
SKP_assert( pNLSFW_Q5[ k ] > 0 );
tmp2_int = SKP_max_int( pNLSF_Q15[ k + 2 ] - pNLSF_Q15[ k + 1 ], 1 );
tmp2_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp2_int );
- pNLSFW_Q5[ k + 1 ] = (SKP_int)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX );
+ pNLSFW_Q5[ k + 1 ] = (SKP_int16)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX );
SKP_assert( pNLSFW_Q5[ k + 1 ] > 0 );
}
@@ -72,6 +72,6 @@
/* Last value */
tmp1_int = SKP_max_int( ( 1 << 15 ) - pNLSF_Q15[ D - 1 ], 1 );
tmp1_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp1_int );
- pNLSFW_Q5[ D - 1 ] = (SKP_int)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX );
+ pNLSFW_Q5[ D - 1 ] = (SKP_int16)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX );
SKP_assert( pNLSFW_Q5[ D - 1 ] > 0 );
}
--- a/src_SigProc_FIX/SKP_Silk_NLSF_stabilize.c
+++ b/src_SigProc_FIX/SKP_Silk_NLSF_stabilize.c
@@ -40,12 +40,12 @@
/* NLSF stabilizer, for a single input data vector */
void SKP_Silk_NLSF_stabilize(
- SKP_int *NLSF_Q15, /* I/O: Unstable/stabilized normalized LSF vector in Q15 [L] */
- const SKP_int *NDeltaMin_Q15, /* I: Normalized delta min vector in Q15, NDeltaMin_Q15[L] must be >= 1 [L+1] */
+ SKP_int16 *NLSF_Q15, /* I/O: Unstable/stabilized normalized LSF vector in Q15 [L] */
+ const SKP_int16 *NDeltaMin_Q15, /* I: Normalized delta min vector in Q15, NDeltaMin_Q15[L] must be >= 1 [L+1] */
const SKP_int L /* I: Number of NLSF parameters in the input vector */
)
{
- SKP_int center_freq_Q15, diff_Q15, min_center_Q15, max_center_Q15;
+ SKP_int16 center_freq_Q15, diff_Q15, min_center_Q15, max_center_Q15;
SKP_int32 min_diff_Q15;
SKP_int loops;
SKP_int i, I=0, k;
@@ -106,7 +106,7 @@
max_center_Q15 -= ( NDeltaMin_Q15[I] - SKP_RSHIFT( NDeltaMin_Q15[I], 1 ) );
/* Move apart, sorted by value, keeping the same center frequency */
- center_freq_Q15 = SKP_LIMIT_32( SKP_RSHIFT_ROUND( (SKP_int32)NLSF_Q15[I-1] + (SKP_int32)NLSF_Q15[I], 1 ),
+ center_freq_Q15 = (SKP_int16)SKP_LIMIT_32( SKP_RSHIFT_ROUND( (SKP_int32)NLSF_Q15[I-1] + (SKP_int32)NLSF_Q15[I], 1 ),
min_center_Q15, max_center_Q15 );
NLSF_Q15[I-1] = center_freq_Q15 - SKP_RSHIFT( NDeltaMin_Q15[I], 1 );
NLSF_Q15[I] = NLSF_Q15[I-1] + NDeltaMin_Q15[I];
@@ -119,7 +119,7 @@
/* Insertion sort (fast for already almost sorted arrays): */
/* Best case: O(n) for an already sorted array */
/* Worst case: O(n^2) for an inversely sorted array */
- SKP_Silk_insertion_sort_increasing_all_values(&NLSF_Q15[0], L);
+ SKP_Silk_insertion_sort_increasing_all_values_int16( &NLSF_Q15[0], L );
/* First NLSF should be no less than NDeltaMin[0] */
NLSF_Q15[0] = SKP_max_int( NLSF_Q15[0], NDeltaMin_Q15[0] );
@@ -134,21 +134,5 @@
/* Keep NDeltaMin distance between the NLSFs */
for( i = L-2; i >= 0; i-- )
NLSF_Q15[i] = SKP_min_int( NLSF_Q15[i], NLSF_Q15[i+1] - NDeltaMin_Q15[i+1] );
- }
-}
-
-/* NLSF stabilizer, over multiple input column data vectors */
-void SKP_Silk_NLSF_stabilize_multi(
- SKP_int *NLSF_Q15, /* I/O: Unstable/stabilized normalized LSF vectors in Q15 [LxN] */
- const SKP_int *NDeltaMin_Q15, /* I: Normalized delta min vector in Q15, NDeltaMin_Q15[L] must be >= 1 [L+1] */
- const SKP_int N, /* I: Number of input vectors to be stabilized */
- const SKP_int L /* I: NLSF vector dimension */
-)
-{
- SKP_int n;
-
- /* loop over input data */
- for( n = 0; n < N; n++ ) {
- SKP_Silk_NLSF_stabilize( &NLSF_Q15[n * L], NDeltaMin_Q15, L );
}
}
--- a/src_SigProc_FIX/SKP_Silk_SigProc_FIX.h
+++ b/src_SigProc_FIX/SKP_Silk_SigProc_FIX.h
@@ -119,37 +119,6 @@
SKP_int32 inLen /* I: Number of input samples */
);
-/*!
- * First order low-pass filter, with input as SKP_int16, running at 48 kHz
- */
-void SKP_Silk_lowpass_short(
- const SKP_int16 *in, /* I: Q15 48 kHz signal; [len] */
- SKP_int32 *S, /* I/O: Q25 state; length = 1 */
- SKP_int32 *out, /* O: Q25 48 kHz signal; [len] */
- const SKP_int32 len /* O: Signal length */
-);
-
-/*!
- * First order low-pass filter, with input as SKP_int32, running at 48 kHz
- */
-void SKP_Silk_lowpass_int(
- const SKP_int32 *in, /* I: Q25 48 kHz signal; length = len */
- SKP_int32 *S, /* I/O: Q25 state; length = 1 */
- SKP_int32 *out, /* O: Q25 48 kHz signal; length = len */
- const SKP_int32 len /* I: Number of samples */
-);
-
-/*!
- * First-order allpass filter
- */
-void SKP_Silk_allpass_int(
- const SKP_int32 *in, /* I: Q25 input signal [len] */
- SKP_int32 *S, /* I/O: Q25 state [1] */
- SKP_int A, /* I: Q15 coefficient (0 <= A < 32768) */
- SKP_int32 *out, /* O: Q25 output signal [len] */
- const SKP_int32 len /* I: Number of samples */
-);
-
/*!
* second order ARMA filter;
* slower than biquad() but uses more precise coefficients
@@ -373,7 +342,7 @@
/* Compute Normalized Line Spectral Frequencies (NLSFs) from whitening filter coefficients */
/* If not all roots are found, the a_Q16 coefficients are bandwidth expanded until convergence. */
void SKP_Silk_A2NLSF(
- SKP_int *NLSF, /* O Normalized Line Spectral Frequencies, Q15 (0 - (2^15-1)), [d] */
+ SKP_int16 *NLSF, /* O Normalized Line Spectral Frequencies, Q15 (0 - (2^15-1)), [d] */
SKP_int32 *a_Q16, /* I/O Monic whitening filter coefficients in Q16 [d] */
const SKP_int d /* I Filter order (must be even) */
);
@@ -381,7 +350,7 @@
/* compute whitening filter coefficients from normalized line spectral frequencies */
void SKP_Silk_NLSF2A(
SKP_int16 *a, /* o monic whitening filter coefficients in Q12, [d] */
- const SKP_int *NLSF, /* i normalized line spectral frequencies in Q15, [d] */
+ const SKP_int16 *NLSF, /* i normalized line spectral frequencies in Q15, [d] */
const SKP_int d /* i filter order (should be even) */
);
@@ -392,13 +361,6 @@
const SKP_int K /* I: Number of correctly sorted positions */
);
-void SKP_Silk_insertion_sort_decreasing(
- SKP_int *a, /* I/O: Unsorted / Sorted vector */
- SKP_int *index, /* O: Index vector for the sorted elements */
- const SKP_int L, /* I: Vector length */
- const SKP_int K /* I: Number of correctly sorted positions */
-);
-
void SKP_Silk_insertion_sort_decreasing_int16(
SKP_int16 *a, /* I/O: Unsorted / Sorted vector */
SKP_int *index, /* O: Index vector for the sorted elements */
@@ -406,30 +368,22 @@
const SKP_int K /* I: Number of correctly sorted positions */
);
-void SKP_Silk_insertion_sort_increasing_all_values(
- SKP_int *a, /* I/O: Unsorted / Sorted vector */
+void SKP_Silk_insertion_sort_increasing_all_values_int16(
+ SKP_int16 *a, /* I/O: Unsorted / Sorted vector */
const SKP_int L /* I: Vector length */
);
/* NLSF stabilizer, for a single input data vector */
void SKP_Silk_NLSF_stabilize(
- SKP_int *NLSF_Q15, /* I/O: Unstable/stabilized normalized LSF vector in Q15 [L] */
- const SKP_int *NDeltaMin_Q15, /* I: Normalized delta min vector in Q15, NDeltaMin_Q15[L] must be >= 1 [L+1] */
+ SKP_int16 *NLSF_Q15, /* I/O: Unstable/stabilized normalized LSF vector in Q15 [L] */
+ const SKP_int16 *NDeltaMin_Q15, /* I: Normalized delta min vector in Q15, NDeltaMin_Q15[L] must be >= 1 [L+1] */
const SKP_int L /* I: Number of NLSF parameters in the input vector */
);
-/* NLSF stabilizer, over multiple input column data vectors */
-void SKP_Silk_NLSF_stabilize_multi(
- SKP_int *NLSF_Q15, /* I/O: Unstable/stabilized normalized LSF vectors in Q15 [LxN] */
- const SKP_int *NDeltaMin_Q15, /* I: Normalized delta min vector in Q15, NDeltaMin_Q15[L] must be >= 1 [L+1] */
- const SKP_int N, /* I: Number of input vectors to be stabilized */
- const SKP_int L /* I: NLSF vector dimension */
-);
-
/* Laroia low complexity NLSF weights */
void SKP_Silk_NLSF_VQ_weights_laroia(
- SKP_int *pNLSFW_Q5, /* O: Pointer to input vector weights [D x 1] */
- const SKP_int *pNLSF_Q15, /* I: Pointer to input vector [D x 1] */
+ SKP_int16 *pNLSFW_Q5, /* O: Pointer to input vector weights [D x 1] */
+ const SKP_int16 *pNLSF_Q15, /* I: Pointer to input vector [D x 1] */
const SKP_int D /* I: Input vector dimension (even) */
);
--- a/src_SigProc_FIX/SKP_Silk_inner_prod_aligned.c
+++ b/src_SigProc_FIX/SKP_Silk_inner_prod_aligned.c
@@ -25,13 +25,6 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
-/* *
- * SKP_Silk_inner_prod_aligned.c *
- * *
- * *
- * Copyright 2008-2010 (c), Skype Limited *
- * Date: 080601 *
- * */
#include "SKP_Silk_SigProc_FIX.h"
/* sum= for(i=0;i<len;i++)inVec1[i]*inVec2[i]; --- inner product */
--- a/src_SigProc_FIX/SKP_Silk_k2a.c
+++ b/src_SigProc_FIX/SKP_Silk_k2a.c
@@ -25,15 +25,6 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
-/* *
- * SKP_Silk_k2a.c *
- * *
- * Step up function, converts reflection coefficients to prediction *
- * coefficients *
- * *
- * Copyright 2008 (c), Skype Limited *
- * Date: 080103 *
- * */
#include "SKP_Silk_SigProc_FIX.h"
/* Step up function, converts reflection coefficients to prediction coefficients */
--- a/src_SigProc_FIX/SKP_Silk_k2a_Q16.c
+++ b/src_SigProc_FIX/SKP_Silk_k2a_Q16.c
@@ -25,15 +25,6 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
-/* *
- * SKP_Silk_k2a.c *
- * *
- * Step up function, converts reflection coefficients to prediction *
- * coefficients *
- * *
- * Copyright 2008 (c), Skype Limited *
- * Date: 080103 *
- * */
#include "SKP_Silk_SigProc_FIX.h"
/* Step up function, converts reflection coefficients to prediction coefficients */
--- a/src_SigProc_FIX/SKP_Silk_lin2log.c
+++ b/src_SigProc_FIX/SKP_Silk_lin2log.c
@@ -25,15 +25,6 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
-/* *
- * SKP_Silk_lin2log.c *
- * *
- * Convert input to a log scale *
- * Approximation of 128 * log2() *
- * *
- * Copyright 2006 (c), Skype Limited *
- * Date: 060221 *
- * */
#include "SKP_Silk_SigProc_FIX.h"
/* Approximation of 128 * log2() (very close inverse of approx 2^() below) */
/* Convert input to a log scale */
--- a/src_SigProc_FIX/SKP_Silk_log2lin.c
+++ b/src_SigProc_FIX/SKP_Silk_log2lin.c
@@ -25,14 +25,6 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
-/* *
- * SKP_Silk_log2lin.c *
- * *
- * Convert input to a linear scale *
- * *
- * Copyright 2006 (c), Skype Limited *
- * Date: 060221 *
- * */
#include "SKP_Silk_SigProc_FIX.h"
/* Approximation of 2^() (very close inverse of SKP_Silk_lin2log()) */
--- a/src_SigProc_FIX/SKP_Silk_sort.c
+++ b/src_SigProc_FIX/SKP_Silk_sort.c
@@ -79,52 +79,6 @@
}
}
-void SKP_Silk_insertion_sort_decreasing(
- SKP_int *a, /* I/O: Unsorted / Sorted vector */
- SKP_int *index, /* O: Index vector for the sorted elements */
- const SKP_int L, /* I: Vector length */
- const SKP_int K /* I: Number of correctly sorted positions */
-)
-{
- SKP_int value;
- SKP_int i, j;
-
- /* Safety checks */
- SKP_assert( K > 0 );
- SKP_assert( L > 0 );
- SKP_assert( L >= K );
-
- /* Write start indices in index vector */
- for( i = 0; i < K; i++ ) {
- index[ i ] = i;
- }
-
- /* Sort vector elements by value, decreasing order */
- for( i = 1; i < K; i++ ) {
- value = a[ i ];
- for( j = i - 1; ( j >= 0 ) && ( value > a[ j ] ); j-- ) {
- a[ j + 1 ] = a[ j ]; /* Shift value */
- index[ j + 1 ] = index[ j ]; /* Shift index */
- }
- a[ j + 1 ] = value; /* Write value */
- index[ j + 1 ] = i; /* Write index */
- }
-
- /* If less than L values are asked for, check the remaining values, */
- /* but only spend CPU to ensure that the K first values are correct */
- for( i = K; i < L; i++ ) {
- value = a[ i ];
- if( value > a[ K - 1 ] ) {
- for( j = K - 2; ( j >= 0 ) && ( value > a[ j ] ); j-- ) {
- a[ j + 1 ] = a[ j ]; /* Shift value */
- index[ j + 1 ] = index[ j ]; /* Shift index */
- }
- a[ j + 1 ] = value; /* Write value */
- index[ j + 1 ] = i; /* Write index */
- }
- }
-}
-
void SKP_Silk_insertion_sort_decreasing_int16(
SKP_int16 *a, /* I/O: Unsorted / Sorted vector */
SKP_int *index, /* O: Index vector for the sorted elements */
@@ -171,8 +125,8 @@
}
}
-void SKP_Silk_insertion_sort_increasing_all_values(
- SKP_int *a, /* I/O: Unsorted / Sorted vector */
+void SKP_Silk_insertion_sort_increasing_all_values_int16(
+ SKP_int16 *a, /* I/O: Unsorted / Sorted vector */
const SKP_int L /* I: Vector length */
)
{
@@ -189,99 +143,5 @@
a[ j + 1 ] = a[ j ]; /* Shift value */
}
a[ j + 1 ] = value; /* Write value */
- }
-}
-
-void SKP_Silk_shell_insertion_sort_increasing(
- SKP_int32 *a, /* I/O: Unsorted / Sorted vector */
- SKP_int *index, /* O: Index vector for the sorted elements */
- const SKP_int L, /* I: Vector length */
- const SKP_int K /* I: Number of correctly sorted positions */
-)
-{
- SKP_int32 value, inc_Q16_tmp;
- SKP_int i, j, inc, idx;
-
- /* Safety checks */
- SKP_assert( K > 0 );
- SKP_assert( L > 0 );
- SKP_assert( L >= K );
-
- /* Calculate initial step size */
- inc_Q16_tmp = SKP_LSHIFT( (SKP_int32)L, 15 );
- inc = SKP_RSHIFT( inc_Q16_tmp, 16 );
-
- /* Write start indices in index vector */
- for( i = 0; i < K; i++ ) {
- index[ i ] = i;
- }
-
- /* Shell sort first values */
- while( inc > 0 ) {
- for( i = inc; i < K; i++ ) {
- value = a[ i ];
- idx = index[ i ];
- for( j = i - inc; ( j >= 0 ) && ( value < a[ j ] ); j -= inc ) {
- a[ j + inc ] = a[ j ]; /* Shift value */
- index[ j + inc ] = index[ j ]; /* Shift index */
- }
- a[ j + inc ] = value; /* Write value */
- index[ j + inc ] = idx; /* Write index */
- }
- inc_Q16_tmp = SKP_SMULWB( inc_Q16_tmp, 29789 ); // 29789_Q16 = 2.2^(-1)_Q0
- inc = SKP_RSHIFT_ROUND( inc_Q16_tmp, 16 );
- }
-
- /* If less than L values are asked for, check the remaining values, */
- /* but only spend CPU to ensure that the K first values are correct */
- /* Insertion sort remaining values */
- for( i = K; i < L; i++ ) {
- value = a[ i ];
- if( value < a[ K - 1 ] ) {
- for( j = K - 2; ( j >= 0 ) && ( value < a[ j ] ); j-- ) {
- a[ j + 1 ] = a[ j ]; /* Shift value */
- index[ j + 1 ] = index[ j ]; /* Shift index */
- }
- a[ j + 1 ] = value; /* Write value */
- index[ j + 1 ] = i; /* Write index */
- }
- }
-}
-
-void SKP_Silk_shell_sort_increasing_all_values(
- SKP_int32 *a, /* I/O: Unsorted / Sorted vector */
- SKP_int *index, /* O: Index vector for the sorted elements */
- const SKP_int L /* I: Vector length */
-)
-{
- SKP_int32 value, inc_Q16_tmp;
- SKP_int i, j, inc, idx;
-
- /* Safety checks */
- SKP_assert( L > 0 );
-
- /* Calculate initial step size */
- inc_Q16_tmp = SKP_LSHIFT( (SKP_int32)L, 15 );
- inc = SKP_RSHIFT( inc_Q16_tmp, 16 );
-
- /* Write start indices in index vector */
- for( i = 0; i < L; i++ ) {
- index[ i ] = i;
- }
-
- /* Sort vector elements by value, increasing order */
- while( inc > 0 ) {
- for( i = inc; i < L; i++ ) {
- value = a[ i ];
- idx = index[ i ];
- for( j = i - inc; ( j >= 0 ) && ( value < a[ j ] ); j -= inc ) {
- a[ j + inc ] = a[ j ]; /* Shift value */
- index[ j + inc ] = index[ j ]; /* Shift index */
- }
- a[ j + inc ] = value; /* Write value */
- index[ j + inc ] = idx; /* Write index */
- }
- inc_Q16_tmp = SKP_SMULWB( inc_Q16_tmp, 29789 ); // 29789_Q16 = 2.2^(-1)_Q0
- inc = SKP_RSHIFT_ROUND( inc_Q16_tmp, 16 );
}
}
--- a/src_SigProc_FIX/src_SigProc_FIX.vcxproj
+++ b/src_SigProc_FIX/src_SigProc_FIX.vcxproj
@@ -87,7 +87,6 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="SKP_Silk_A2NLSF.c" />
- <ClCompile Include="SKP_Silk_allpass_int.c" />
<ClCompile Include="SKP_Silk_ana_filt_bank_1.c" />
<ClCompile Include="SKP_Silk_apply_sine_window.c" />
<ClCompile Include="SKP_Silk_array_maxabs.c" />
@@ -103,8 +102,6 @@
<ClCompile Include="SKP_Silk_k2a_Q16.c" />
<ClCompile Include="SKP_Silk_lin2log.c" />
<ClCompile Include="SKP_Silk_log2lin.c" />
- <ClCompile Include="SKP_Silk_lowpass_int.c" />
- <ClCompile Include="SKP_Silk_lowpass_short.c" />
<ClCompile Include="SKP_Silk_LPC_inv_pred_gain.c" />
<ClCompile Include="SKP_Silk_LPC_stabilize.c" />
<ClCompile Include="SKP_Silk_LPC_synthesis_filter.c" />
--- a/src_SigProc_FIX/src_SigProc_FIX.vcxproj.filters
+++ b/src_SigProc_FIX/src_SigProc_FIX.vcxproj.filters
@@ -53,9 +53,6 @@
<ClCompile Include="SKP_Silk_A2NLSF.c">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="SKP_Silk_allpass_int.c">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="SKP_Silk_ana_filt_bank_1.c">
<Filter>Source Files</Filter>
</ClCompile>
@@ -96,12 +93,6 @@
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SKP_Silk_log2lin.c">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="SKP_Silk_lowpass_int.c">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="SKP_Silk_lowpass_short.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SKP_Silk_LPC_inv_pred_gain.c">
--- a/src_common/SKP_Silk_HP_variable_cutoff.c
+++ b/src_common/SKP_Silk_HP_variable_cutoff.c
@@ -28,8 +28,6 @@
#include "SKP_Silk_main_FIX.h"
#include "SKP_Silk_tuning_parameters.h"
-#if HIGH_PASS_INPUT
-
#define SKP_RADIANS_CONSTANT_Q19 1482 // 0.45f * 2.0f * 3.14159265359 / 1000
#define SKP_LOG2_VARIABLE_HP_MIN_FREQ_Q7 809 // log(80) in Q7
@@ -117,5 +115,3 @@
/********************************/
SKP_Silk_biquad_alt( in, B_Q28, A_Q28, psEncC->In_HP_State, out, frame_length );
}
-
-#endif // HIGH_PASS_INPUT
--- a/src_common/SKP_Silk_LP_variable_cutoff.c
+++ b/src_common/SKP_Silk_LP_variable_cutoff.c
@@ -98,9 +98,9 @@
/* Start by setting psEncC->mode <> 0; */
/* Deactivate by setting psEncC->mode = 0; */
void SKP_Silk_LP_variable_cutoff(
- SKP_Silk_LP_state *psLP, /* I/O LP filter state */
- SKP_int16 *signal, /* I/O Low-pass filtered output signal */
- const SKP_int frame_length /* I Frame length */
+ SKP_Silk_LP_state *psLP, /* I/O LP filter state */
+ SKP_int16 *signal, /* I/O Low-pass filtered output signal */
+ const SKP_int frame_length /* I Frame length */
)
{
SKP_int32 B_Q28[ TRANSITION_NB ], A_Q28[ TRANSITION_NA ], fac_Q16 = 0;
--- a/src_common/SKP_Silk_NLSF2A_stable.c
+++ b/src_common/SKP_Silk_NLSF2A_stable.c
@@ -30,7 +30,7 @@
/* Convert NLSF parameters to stable AR prediction filter coefficients */
void SKP_Silk_NLSF2A_stable(
SKP_int16 pAR_Q12[ MAX_LPC_ORDER ], /* O Stabilized AR coefs [LPC_order] */
- const SKP_int pNLSF[ MAX_LPC_ORDER ], /* I NLSF vector [LPC_order] */
+ const SKP_int16 pNLSF[ MAX_LPC_ORDER ], /* I NLSF vector [LPC_order] */
const SKP_int LPC_order /* I LPC/LSF order */
)
{
--- /dev/null
+++ b/src_common/SKP_Silk_NLSF_VQ.c
@@ -1,0 +1,64 @@
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved.
+Redistribution and use in source and binary forms, with or without
+modification, (subject to the limitations in the disclaimer below)
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific
+contributors, may be used to endorse or promote products derived from
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+/* Compute quantization errors for an LPC_order element input vector for a VQ codebook */
+void SKP_Silk_NLSF_VQ(
+ SKP_int32 err_Q26[], /* O Quantization errors [K] */
+ const SKP_int16 in_Q15[], /* I Input vectors to be quantized [LPC_order] */
+ const SKP_uint8 pCB_Q8[], /* I Codebook vectors [K*LPC_order] */
+ const SKP_int K, /* I Number of codebook vectors */
+ const SKP_int LPC_order /* I Number of LPCs */
+)
+{
+ SKP_int i, m;
+ SKP_int32 diff_Q15, sum_error_Q30, sum_error_Q26;
+
+ SKP_assert( LPC_order <= 16 );
+ SKP_assert( ( LPC_order & 1 ) == 0 );
+
+ /* Loop over codebook */
+ for( i = 0; i < K; i++ ) {
+ sum_error_Q26 = 0;
+ for( m = 0; m < LPC_order; m += 2 ) {
+ /* Compute weighted squared quantization error for index m */
+ diff_Q15 = SKP_SUB_LSHIFT32( in_Q15[ m ], ( SKP_int32 )*pCB_Q8++, 7 ); // range: [ -32767 : 32767 ]
+ sum_error_Q30 = SKP_SMULBB( diff_Q15, diff_Q15 );
+
+ /* Compute weighted squared quantization error for index m + 1 */
+ diff_Q15 = SKP_SUB_LSHIFT32( in_Q15[m + 1], ( SKP_int32 )*pCB_Q8++, 7 ); // range: [ -32767 : 32767 ]
+ sum_error_Q30 = SKP_SMLABB( sum_error_Q30, diff_Q15, diff_Q15 );
+
+ sum_error_Q26 = SKP_ADD_RSHIFT32( sum_error_Q26, sum_error_Q30, 4 );
+
+ SKP_assert( sum_error_Q26 >= 0 );
+ SKP_assert( sum_error_Q30 >= 0 );
+ }
+ err_Q26[ i ] = sum_error_Q26;
+ }
+}
--- /dev/null
+++ b/src_common/SKP_Silk_NLSF_decode.c
@@ -1,0 +1,96 @@
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved.
+Redistribution and use in source and binary forms, with or without
+modification, (subject to the limitations in the disclaimer below)
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific
+contributors, may be used to endorse or promote products derived from
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+/* Predictive dequantizer for NLSF residuals */
+void SKP_Silk_NLSF_residual_dequant( /* O Returns RD value in Q30 */
+ SKP_int16 x_Q10[], /* O Output [ order ] */
+ const SKP_int8 indices[], /* I Quantization indices [ order ] */
+ const SKP_uint8 pred_coef_Q8[], /* I Backward predictor coefs [ order ] */
+ const SKP_int quant_step_size_Q16, /* I Quantization step size */
+ const SKP_int16 order /* I Number of input values */
+)
+{
+ SKP_int i, out_Q10, pred_Q10;
+
+ out_Q10 = 0;
+ for( i = order-1; i >= 0; i-- ) {
+ pred_Q10 = SKP_RSHIFT( SKP_SMULBB( out_Q10, (SKP_int16)pred_coef_Q8[ i ] ), 8 );
+ out_Q10 = SKP_LSHIFT( indices[ i ], 10 );
+ if( out_Q10 > 0 ) {
+ out_Q10 = SKP_SUB16( out_Q10, SKP_FIX_CONST( NLSF_QUANT_LEVEL_ADJ, 10 ) );
+ } else if( out_Q10 < 0 ) {
+ out_Q10 = SKP_ADD16( out_Q10, SKP_FIX_CONST( NLSF_QUANT_LEVEL_ADJ, 10 ) );
+ }
+ out_Q10 = SKP_SMLAWB( pred_Q10, out_Q10, quant_step_size_Q16 );
+ x_Q10[ i ] = out_Q10;
+ }
+}
+
+
+/***********************/
+/* NLSF vector decoder */
+/***********************/
+void SKP_Silk_NLSF_decode(
+ SKP_int16 *pNLSF_Q15, /* O Quantized NLSF vector [ LPC_ORDER ] */
+ SKP_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */
+ const SKP_Silk_NLSF_CB_struct *psNLSF_CB /* I Codebook object */
+)
+{
+ SKP_int i;
+ SKP_uint8 pred_Q8[ MAX_LPC_ORDER ];
+ SKP_int16 ec_ix[ MAX_LPC_ORDER ];
+ SKP_int16 res_Q10[ MAX_LPC_ORDER ];
+ SKP_int16 W_tmp_Q5[ MAX_LPC_ORDER ];
+ SKP_int32 W_tmp_Q9;
+ const SKP_uint8 *pCB_element;
+
+ /* Decode first stage */
+ pCB_element = &psNLSF_CB->CB1_NLSF_Q8[ NLSFIndices[ 0 ] * psNLSF_CB->order ];
+ for( i = 0; i < psNLSF_CB->order; i++ ) {
+ pNLSF_Q15[ i ] = SKP_LSHIFT( ( SKP_int16 )pCB_element[ i ], 7 );
+ }
+
+ /* Unpack entropy table indices and predictor for current CB1 index */
+ SKP_Silk_NLSF_unpack( ec_ix, pred_Q8, psNLSF_CB, NLSFIndices[ 0 ] );
+
+ /* Trellis dequantizer */
+ SKP_Silk_NLSF_residual_dequant( res_Q10, &NLSFIndices[ 1 ], pred_Q8, psNLSF_CB->quantStepSize_Q16, psNLSF_CB->order );
+
+ /* Weights from codebook vector */
+ SKP_Silk_NLSF_VQ_weights_laroia( W_tmp_Q5, pNLSF_Q15, psNLSF_CB->order );
+
+ /* Apply inverse square-rooted weights and add to output */
+ for( i = 0; i < psNLSF_CB->order; i++ ) {
+ W_tmp_Q9 = SKP_Silk_SQRT_APPROX( SKP_LSHIFT( ( SKP_int32 )W_tmp_Q5[ i ], 13 ) );
+ pNLSF_Q15[ i ] = SKP_ADD16( pNLSF_Q15[ i ], (SKP_int16)SKP_DIV32_16( SKP_LSHIFT( ( SKP_int32 )res_Q10[ i ], 14 ), W_tmp_Q9 ) );
+ }
+
+ /* NLSF stabilization */
+ SKP_Silk_NLSF_stabilize( pNLSF_Q15, psNLSF_CB->deltaMin_Q15, psNLSF_CB->order );
+}
--- /dev/null
+++ b/src_common/SKP_Silk_NLSF_del_dec_quant.c
@@ -1,0 +1,201 @@
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved.
+Redistribution and use in source and binary forms, with or without
+modification, (subject to the limitations in the disclaimer below)
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific
+contributors, may be used to endorse or promote products derived from
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+/* Delayed-decision quantizer for NLSF residuals */
+SKP_int32 SKP_Silk_NLSF_del_dec_quant( /* O Returns RD value in Q25 */
+ SKP_int8 indices[], /* O Quantization indices [ order ] */
+ const SKP_int16 x_Q10[], /* I Input [ order ] */
+ const SKP_int16 w_Q5[], /* I Weights [ order ] */
+ const SKP_uint8 pred_coef_Q8[], /* I Backward predictor coefs [ order ] */
+ const SKP_int16 ec_ix[], /* I Indices to entropy coding tables [ order ] */
+ const SKP_uint8 ec_rates_Q5[], /* I Rates [] */
+ const SKP_int quant_step_size_Q16, /* I Quantization step size */
+ const SKP_int16 inv_quant_step_size_Q6, /* I Inverse quantization step size */
+ const SKP_int32 mu_Q20, /* I R/D tradeoff */
+ const SKP_int16 order /* I Number of input values */
+)
+{
+ SKP_int i, j, nStates, ind_tmp, ind_min_max, ind_max_min, in_Q10, res_Q10;
+ SKP_int pred_Q10, diff_Q10, out0_Q10, out1_Q10, rate0_Q5, rate1_Q5;
+ SKP_int32 RD_tmp_Q25, min_Q25, min_max_Q25, max_min_Q25, pred_coef_Q16;
+ SKP_int ind_sort[ NLSF_QUANT_DEL_DEC_STATES ];
+ SKP_int8 ind[ NLSF_QUANT_DEL_DEC_STATES ][ MAX_LPC_ORDER ];
+ SKP_int16 prev_out_Q10[ 2 * NLSF_QUANT_DEL_DEC_STATES ];
+ SKP_int32 RD_Q25[ 2 * NLSF_QUANT_DEL_DEC_STATES ];
+ SKP_int32 RD_min_Q25[ NLSF_QUANT_DEL_DEC_STATES ];
+ SKP_int32 RD_max_Q25[ NLSF_QUANT_DEL_DEC_STATES ];
+ const SKP_uint8 *rates_Q5;
+
+ SKP_assert( (NLSF_QUANT_DEL_DEC_STATES & (NLSF_QUANT_DEL_DEC_STATES-1)) == 0 ); /* must be power of two */
+
+ nStates = 1;
+ RD_Q25[ 0 ] = 0;
+ prev_out_Q10[ 0 ] = 0;
+ for( i = order - 1; ; i-- ) {
+ rates_Q5 = &ec_rates_Q5[ ec_ix[ i ] ];
+ pred_coef_Q16 = SKP_LSHIFT( (SKP_int32)pred_coef_Q8[ i ], 8 );
+ in_Q10 = x_Q10[ i ];
+ for( j = 0; j < nStates; j++ ) {
+ pred_Q10 = SKP_SMULWB( pred_coef_Q16, prev_out_Q10[ j ] );
+ res_Q10 = SKP_SUB16( in_Q10, pred_Q10 );
+ ind_tmp = SKP_SMULWB( inv_quant_step_size_Q6, res_Q10 );
+ ind_tmp = SKP_LIMIT( ind_tmp, -NLSF_QUANT_MAX_AMPLITUDE_EXT, NLSF_QUANT_MAX_AMPLITUDE_EXT-1 );
+ ind[ j ][ i ] = (SKP_int8)ind_tmp;
+
+ /* compute outputs for ind_tmp and ind_tmp + 1 */
+ out0_Q10 = SKP_LSHIFT( ind_tmp, 10 );
+ out1_Q10 = SKP_ADD16( out0_Q10, 1024 );
+ if( ind_tmp > 0 ) {
+ out0_Q10 = SKP_SUB16( out0_Q10, SKP_FIX_CONST( NLSF_QUANT_LEVEL_ADJ, 10 ) );
+ out1_Q10 = SKP_SUB16( out1_Q10, SKP_FIX_CONST( NLSF_QUANT_LEVEL_ADJ, 10 ) );
+ } else if( ind_tmp == 0 ) {
+ out1_Q10 = SKP_SUB16( out1_Q10, SKP_FIX_CONST( NLSF_QUANT_LEVEL_ADJ, 10 ) );
+ } else if( ind_tmp == -1 ) {
+ out0_Q10 = SKP_ADD16( out0_Q10, SKP_FIX_CONST( NLSF_QUANT_LEVEL_ADJ, 10 ) );
+ } else {
+ out0_Q10 = SKP_ADD16( out0_Q10, SKP_FIX_CONST( NLSF_QUANT_LEVEL_ADJ, 10 ) );
+ out1_Q10 = SKP_ADD16( out1_Q10, SKP_FIX_CONST( NLSF_QUANT_LEVEL_ADJ, 10 ) );
+ }
+ out0_Q10 = SKP_SMULWB( out0_Q10, quant_step_size_Q16 );
+ out1_Q10 = SKP_SMULWB( out1_Q10, quant_step_size_Q16 );
+ out0_Q10 = SKP_ADD16( out0_Q10, pred_Q10 );
+ out1_Q10 = SKP_ADD16( out1_Q10, pred_Q10 );
+ prev_out_Q10[ j ] = out0_Q10;
+ prev_out_Q10[ j + nStates ] = out1_Q10;
+
+ /* compute RD for ind_tmp and ind_tmp + 1 */
+ if( ind_tmp + 1 >= NLSF_QUANT_MAX_AMPLITUDE ) {
+ if( ind_tmp + 1 == NLSF_QUANT_MAX_AMPLITUDE ) {
+ rate0_Q5 = rates_Q5[ ind_tmp + NLSF_QUANT_MAX_AMPLITUDE ];
+ rate1_Q5 = 280;
+ } else {
+ rate0_Q5 = SKP_SMLABB( 280 - 43 * NLSF_QUANT_MAX_AMPLITUDE, 43, ind_tmp );
+ rate1_Q5 = SKP_ADD16( rate0_Q5, 43 );
+ }
+ } else if( ind_tmp <= -NLSF_QUANT_MAX_AMPLITUDE ) {
+ if( ind_tmp == -NLSF_QUANT_MAX_AMPLITUDE ) {
+ rate0_Q5 = 280;
+ rate1_Q5 = rates_Q5[ ind_tmp + 1 + NLSF_QUANT_MAX_AMPLITUDE ];
+ } else {
+ rate0_Q5 = SKP_SMLABB( 280 - 43 * NLSF_QUANT_MAX_AMPLITUDE, -43, ind_tmp );
+ rate1_Q5 = SKP_SUB16( rate0_Q5, 43 );
+ }
+ } else {
+ rate0_Q5 = rates_Q5[ ind_tmp + NLSF_QUANT_MAX_AMPLITUDE ];
+ rate1_Q5 = rates_Q5[ ind_tmp + 1 + NLSF_QUANT_MAX_AMPLITUDE ];
+ }
+ RD_tmp_Q25 = RD_Q25[ j ];
+ diff_Q10 = SKP_SUB16( in_Q10, out0_Q10 );
+ RD_Q25[ j ] = SKP_SMLABB( SKP_MLA( RD_tmp_Q25, SKP_SMULBB( diff_Q10, diff_Q10 ), w_Q5[ i ] ), mu_Q20, rate0_Q5 );
+ diff_Q10 = SKP_SUB16( in_Q10, out1_Q10 );
+ RD_Q25[ j + nStates ] = SKP_SMLABB( SKP_MLA( RD_tmp_Q25, SKP_SMULBB( diff_Q10, diff_Q10 ), w_Q5[ i ] ), mu_Q20, rate1_Q5 );
+ }
+
+ if( nStates < NLSF_QUANT_DEL_DEC_STATES ) {
+ /* double number of states and copy */
+ for( j = 0; j < nStates; j++ ) {
+ ind[ j + nStates ][ i ] = ind[ j ][ i ] + 1;
+ }
+ nStates = SKP_LSHIFT( nStates, 1 );
+ for( j = nStates; j < NLSF_QUANT_DEL_DEC_STATES; j++ ) {
+ ind[ j ][ i ] = ind[ j - nStates ][ i ];
+ }
+ } else if( i > 0 ) {
+ /* sort lower and upper half of RD_Q25, pairwise */
+ for( j = 0; j < NLSF_QUANT_DEL_DEC_STATES; j++ ) {
+ if( RD_Q25[ j ] > RD_Q25[ j + NLSF_QUANT_DEL_DEC_STATES ] ) {
+ RD_max_Q25[ j ] = RD_Q25[ j ];
+ RD_min_Q25[ j ] = RD_Q25[ j + NLSF_QUANT_DEL_DEC_STATES ];
+ RD_Q25[ j ] = RD_min_Q25[ j ];
+ RD_Q25[ j + NLSF_QUANT_DEL_DEC_STATES ] = RD_max_Q25[ j ];
+ /* swap prev_out values */
+ out0_Q10 = prev_out_Q10[ j ];
+ prev_out_Q10[ j ] = prev_out_Q10[ j + NLSF_QUANT_DEL_DEC_STATES ];
+ prev_out_Q10[ j + NLSF_QUANT_DEL_DEC_STATES ] = out0_Q10;
+ ind_sort[ j ] = j + NLSF_QUANT_DEL_DEC_STATES;
+ } else {
+ RD_min_Q25[ j ] = RD_Q25[ j ];
+ RD_max_Q25[ j ] = RD_Q25[ j + NLSF_QUANT_DEL_DEC_STATES ];
+ ind_sort[ j ] = j;
+ }
+ }
+ /* compare the highest RD values of the winning half with the lowest one in the losing half, and copy if necessary */
+ /* afterwards ind_sort[] will contain the indices of the NLSF_QUANT_DEL_DEC_STATES winning RD values */
+ while( 1 ) {
+ min_max_Q25 = SKP_int32_MAX;
+ max_min_Q25 = 0;
+ ind_min_max = 0;
+ ind_max_min = 0;
+ for( j = 0; j < NLSF_QUANT_DEL_DEC_STATES; j++ ) {
+ if( min_max_Q25 > RD_max_Q25[ j ] ) {
+ min_max_Q25 = RD_max_Q25[ j ];
+ ind_min_max = j;
+ }
+ if( max_min_Q25 < RD_min_Q25[ j ] ) {
+ max_min_Q25 = RD_min_Q25[ j ];
+ ind_max_min = j;
+ }
+ }
+ if( min_max_Q25 >= max_min_Q25 ) {
+ break;
+ }
+ /* copy ind_min_max to ind_max_min */
+ ind_sort[ ind_max_min ] = ind_sort[ ind_min_max ] ^ NLSF_QUANT_DEL_DEC_STATES;
+ RD_Q25[ ind_max_min ] = RD_Q25[ ind_min_max + NLSF_QUANT_DEL_DEC_STATES ];
+ prev_out_Q10[ ind_max_min ] = prev_out_Q10[ ind_min_max + NLSF_QUANT_DEL_DEC_STATES ];
+ RD_min_Q25[ ind_max_min ] = 0;
+ RD_max_Q25[ ind_min_max ] = SKP_int32_MAX;
+ SKP_memcpy( ind[ ind_max_min ], ind[ ind_min_max ], MAX_LPC_ORDER * sizeof( SKP_int8 ) );
+ }
+ /* increment index if it comes from the upper half */
+ for( j = 0; j < NLSF_QUANT_DEL_DEC_STATES; j++ ) {
+ ind[ j ][ i ] += SKP_RSHIFT( ind_sort[ j ], NLSF_QUANT_DEL_DEC_STATES_LOG2 );
+ }
+ } else { /* i == 0 */
+ /* last sample: find winner, copy indices and return RD value */
+ ind_tmp = 0;
+ min_Q25 = SKP_int32_MAX;
+ for( j = 0; j < 2 * NLSF_QUANT_DEL_DEC_STATES; j++ ) {
+ if( min_Q25 > RD_Q25[ j ] ) {
+ min_Q25 = RD_Q25[ j ];
+ ind_tmp = j;
+ }
+ }
+ for( j = 0; j < order; j++ ) {
+ indices[ j ] = ind[ ind_tmp & ( NLSF_QUANT_DEL_DEC_STATES - 1 ) ][ j ];
+ SKP_assert( indices[ j ] >= -NLSF_QUANT_MAX_AMPLITUDE_EXT );
+ SKP_assert( indices[ j ] <= NLSF_QUANT_MAX_AMPLITUDE_EXT );
+ }
+ indices[ 0 ] += SKP_RSHIFT( ind_tmp, NLSF_QUANT_DEL_DEC_STATES_LOG2 );
+ SKP_assert( indices[ 0 ] <= NLSF_QUANT_MAX_AMPLITUDE_EXT );
+ SKP_assert( min_Q25 >= 0 );
+ return min_Q25;
+ }
+ }
+}
--- /dev/null
+++ b/src_common/SKP_Silk_NLSF_encode.c
@@ -1,0 +1,183 @@
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved.
+Redistribution and use in source and binary forms, with or without
+modification, (subject to the limitations in the disclaimer below)
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific
+contributors, may be used to endorse or promote products derived from
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+#define STORE_LSF_DATA_FOR_TRAINING 0
+
+/***********************/
+/* NLSF vector encoder */
+/***********************/
+SKP_int32 SKP_Silk_NLSF_encode( /* O Returns RD value in Q25 */
+ SKP_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */
+ SKP_int16 *pNLSF_Q15, /* I/O Quantized NLSF vector [ LPC_ORDER ] */
+ const SKP_Silk_NLSF_CB_struct *psNLSF_CB, /* I Codebook object */
+ const SKP_int16 *pW_Q5, /* I NLSF weight vector [ LPC_ORDER ] */
+ const SKP_int NLSF_mu_Q20, /* I Rate weight for the RD optimization */
+ const SKP_int nSurvivors, /* I Max survivors after first stage */
+ const SKP_int signalType /* I Signal type: 0/1/2 */
+)
+{
+ SKP_int i, s, ind1, bestIndex, prob_Q8, bits_q7;
+ SKP_int32 W_tmp_Q9;
+ SKP_int32 err_Q26[ NLSF_VQ_MAX_VECTORS ];
+ SKP_int32 RD_Q25[ NLSF_VQ_MAX_SURVIVORS ];
+ SKP_int tempIndices1[ NLSF_VQ_MAX_SURVIVORS ];
+ SKP_int8 tempIndices2[ NLSF_VQ_MAX_SURVIVORS * MAX_LPC_ORDER ];
+ SKP_int16 res_Q15[ MAX_LPC_ORDER ];
+ SKP_int16 res_Q10[ MAX_LPC_ORDER ];
+ SKP_int16 NLSF_tmp_Q15[ MAX_LPC_ORDER ];
+ SKP_int16 W_tmp_Q5[ MAX_LPC_ORDER ];
+ SKP_int16 W_adj_Q5[ MAX_LPC_ORDER ];
+ SKP_uint8 pred_Q8[ MAX_LPC_ORDER ];
+ SKP_int16 ec_ix[ MAX_LPC_ORDER ];
+ const SKP_uint8 *pCB_element, *iCDF_ptr;
+
+#if STORE_LSF_DATA_FOR_TRAINING
+ SKP_int16 pNLSF_Q15_orig[MAX_LPC_ORDER ];
+ DEBUG_STORE_DATA( NLSF.dat, pNLSF_Q15, psNLSF_CB->order * sizeof( SKP_int16 ) );
+ DEBUG_STORE_DATA( WNLSF.dat, pW_Q5, psNLSF_CB->order * sizeof( SKP_int16 ) );
+ DEBUG_STORE_DATA( NLSF_mu.dat, &NLSF_mu_Q20, sizeof( SKP_int ) );
+ DEBUG_STORE_DATA( sigType.dat, &signalType, sizeof( SKP_int ) );
+ SKP_memcpy(pNLSF_Q15_orig, pNLSF_Q15, sizeof( pNLSF_Q15_orig ));
+#endif
+
+ SKP_assert( nSurvivors <= NLSF_VQ_MAX_SURVIVORS );
+ SKP_assert( signalType >= 0 && signalType <= 2 );
+ SKP_assert( NLSF_mu_Q20 <= 32767 && NLSF_mu_Q20 >= 0 );
+
+ /* NLSF stabilization */
+ SKP_Silk_NLSF_stabilize( pNLSF_Q15, psNLSF_CB->deltaMin_Q15, psNLSF_CB->order );
+
+ /* First stage: VQ */
+ SKP_Silk_NLSF_VQ( err_Q26, pNLSF_Q15, psNLSF_CB->CB1_NLSF_Q8, psNLSF_CB->nVectors, psNLSF_CB->order );
+
+ /* Sort the quantization errors */
+ SKP_Silk_insertion_sort_increasing( err_Q26, tempIndices1, psNLSF_CB->nVectors, nSurvivors );
+
+ /* Loop over survivors */
+ for( s = 0; s < nSurvivors; s++ ) {
+ ind1 = tempIndices1[ s ];
+
+ /* Residual after first stage */
+ pCB_element = &psNLSF_CB->CB1_NLSF_Q8[ ind1 * psNLSF_CB->order ];
+ for( i = 0; i < psNLSF_CB->order; i++ ) {
+ NLSF_tmp_Q15[ i ] = SKP_LSHIFT16( ( SKP_int16 )pCB_element[ i ], 7 );
+ res_Q15[ i ] = pNLSF_Q15[ i ] - NLSF_tmp_Q15[ i ];
+ }
+
+ /* Weights from codebook vector */
+ SKP_Silk_NLSF_VQ_weights_laroia( W_tmp_Q5, NLSF_tmp_Q15, psNLSF_CB->order );
+
+ /* Apply square-rooted weights */
+ for( i = 0; i < psNLSF_CB->order; i++ ) {
+ W_tmp_Q9 = SKP_Silk_SQRT_APPROX( SKP_LSHIFT( ( SKP_int32 )W_tmp_Q5[ i ], 13 ) );
+ res_Q10[ i ] = ( SKP_int16 )SKP_RSHIFT( SKP_SMULBB( res_Q15[ i ], W_tmp_Q9 ), 14 );
+ }
+
+ /* Modify input weights accordingly */
+ for( i = 0; i < psNLSF_CB->order; i++ ) {
+ W_adj_Q5[ i ] = SKP_DIV32_16( SKP_LSHIFT( ( SKP_int32 )pW_Q5[ i ], 5 ), W_tmp_Q5[ i ] );
+ }
+
+ /* Unpack entropy table indices and predictor for current CB1 index */
+ SKP_Silk_NLSF_unpack( ec_ix, pred_Q8, psNLSF_CB, ind1 );
+
+ /* Trellis quantizer */
+ RD_Q25[ s ] = SKP_Silk_NLSF_del_dec_quant( &tempIndices2[ s * MAX_LPC_ORDER ], res_Q10, W_adj_Q5, pred_Q8, ec_ix,
+ psNLSF_CB->ec_Rates_Q5, psNLSF_CB->quantStepSize_Q16, psNLSF_CB->invQuantStepSize_Q6, NLSF_mu_Q20, psNLSF_CB->order );
+
+ /* Add rate for first stage */
+ iCDF_ptr = &psNLSF_CB->CB1_iCDF[ ( signalType >> 1 ) * psNLSF_CB->nVectors ];
+ if( ind1 == 0 ) {
+ prob_Q8 = 256 - iCDF_ptr[ ind1 ];
+ } else {
+ prob_Q8 = iCDF_ptr[ ind1 - 1 ] - iCDF_ptr[ ind1 ];
+ }
+ bits_q7 = ( 8 << 7 ) - SKP_Silk_lin2log( prob_Q8 );
+ RD_Q25[ s ] = SKP_SMLABB( RD_Q25[ s ], bits_q7, SKP_RSHIFT( NLSF_mu_Q20, 2 ) );
+ }
+
+ /* Find the lowest rate-distortion error */
+ SKP_Silk_insertion_sort_increasing( RD_Q25, &bestIndex, nSurvivors, 1 );
+
+ NLSFIndices[ 0 ] = ( SKP_int8 )tempIndices1[ bestIndex ];
+ SKP_memcpy( &NLSFIndices[ 1 ], &tempIndices2[ bestIndex * MAX_LPC_ORDER ], psNLSF_CB->order * sizeof( SKP_int8 ) );
+
+ /* Decode */
+ SKP_Silk_NLSF_decode( pNLSF_Q15, NLSFIndices, psNLSF_CB );
+
+#if STORE_LSF_DATA_FOR_TRAINING
+ {
+ /* code for training the codebooks */
+ SKP_int32 RD_dec_Q22, Dist_Q22_dec, Rate_Q7, diff_Q15;
+ ind1 = NLSFIndices[ 0 ];
+ SKP_Silk_NLSF_unpack( ec_ix, pred_Q8, psNLSF_CB, ind1 );
+
+ pCB_element = &psNLSF_CB->CB1_NLSF_Q8[ ind1 * psNLSF_CB->order ];
+ for( i = 0; i < psNLSF_CB->order; i++ ) {
+ NLSF_tmp_Q15[ i ] = SKP_LSHIFT16( ( SKP_int16 )pCB_element[ i ], 7 );
+ }
+ SKP_Silk_NLSF_VQ_weights_laroia( W_tmp_Q5, NLSF_tmp_Q15, psNLSF_CB->order );
+ for( i = 0; i < psNLSF_CB->order; i++ ) {
+ W_tmp_Q9 = SKP_Silk_SQRT_APPROX( SKP_LSHIFT( ( SKP_int32 )W_tmp_Q5[ i ], 13 ) );
+ res_Q15[ i ] = pNLSF_Q15_orig[ i ] - NLSF_tmp_Q15[ i ];
+ res_Q10[ i ] = (SKP_int16)SKP_RSHIFT( SKP_SMULBB( res_Q15[ i ], W_tmp_Q9 ), 14 );
+ DEBUG_STORE_DATA( NLSF_res_q10.dat, &res_Q10[ i ], sizeof( SKP_int16 ) );
+ res_Q15[ i ] = pNLSF_Q15[ i ] - NLSF_tmp_Q15[ i ];
+ res_Q10[ i ] = (SKP_int16)SKP_RSHIFT( SKP_SMULBB( res_Q15[ i ], W_tmp_Q9 ), 14 );
+ DEBUG_STORE_DATA( NLSF_resq_q10.dat, &res_Q10[ i ], sizeof( SKP_int16 ) );
+ }
+
+ Dist_Q22_dec = 0;
+ for( i = 0; i < psNLSF_CB->order; i++ ) {
+ diff_Q15 = pNLSF_Q15_orig[ i ] - pNLSF_Q15[ i ];
+ Dist_Q22_dec += ( ( (diff_Q15 >> 5) * (diff_Q15 >> 5) ) * pW_Q5[ i ] ) >> 3;
+ }
+ iCDF_ptr = &psNLSF_CB->CB1_iCDF[ ( signalType >> 1 ) * psNLSF_CB->nVectors ];
+ if( ind1 == 0 ) {
+ prob_Q8 = 256 - iCDF_ptr[ ind1 ];
+ } else {
+ prob_Q8 = iCDF_ptr[ ind1 - 1 ] - iCDF_ptr[ ind1 ];
+ }
+ Rate_Q7 = ( 8 << 7 ) - SKP_Silk_lin2log( prob_Q8 );
+ for( i = 0; i < psNLSF_CB->order; i++ ) {
+ Rate_Q7 += ((int)psNLSF_CB->ec_Rates_Q5[ ec_ix[ i ] + SKP_LIMIT( NLSFIndices[ i + 1 ] + NLSF_QUANT_MAX_AMPLITUDE, 0, 2 * NLSF_QUANT_MAX_AMPLITUDE ) ] ) << 2;
+ if( SKP_abs( NLSFIndices[ i + 1 ] ) >= NLSF_QUANT_MAX_AMPLITUDE ) {
+ Rate_Q7 += 128 << ( SKP_abs( NLSFIndices[ i + 1 ] ) - NLSF_QUANT_MAX_AMPLITUDE );
+ }
+ }
+ RD_dec_Q22 = Dist_Q22_dec + Rate_Q7 * NLSF_mu_Q20 >> 5;
+ DEBUG_STORE_DATA( dec_dist_q22.dat, &Dist_Q22_dec, sizeof( SKP_int32 ) );
+ DEBUG_STORE_DATA( dec_rate_q7.dat, &Rate_Q7, sizeof( SKP_int32 ) );
+ DEBUG_STORE_DATA( dec_rd_q22.dat, &RD_dec_Q22, sizeof( SKP_int32 ) );
+ }
+ DEBUG_STORE_DATA( NLSF_ind.dat, NLSFIndices, (psNLSF_CB->order+1) * sizeof( SKP_int8 ) );
+#endif
+
+ return RD_Q25[ 0 ];
+}
--- /dev/null
+++ b/src_common/SKP_Silk_NLSF_unpack.c
@@ -1,0 +1,51 @@
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved.
+Redistribution and use in source and binary forms, with or without
+modification, (subject to the limitations in the disclaimer below)
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific
+contributors, may be used to endorse or promote products derived from
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_main.h"
+
+/* Unpack predictor values and indices for entropy coding tables */
+void SKP_Silk_NLSF_unpack(
+ SKP_int16 ec_ix[], /* O Indices to entropy tales [ LPC_ORDER ] */
+ SKP_uint8 pred_Q8[], /* O LSF predictor [ LPC_ORDER ] */
+ const SKP_Silk_NLSF_CB_struct *psNLSF_CB, /* I Codebook object */
+ const SKP_int CB1_index /* I Index of vector in first LSF codebook */
+)
+{
+ SKP_int i;
+ SKP_uint8 entry;
+ const SKP_uint8 *ec_sel_ptr;
+
+ ec_sel_ptr = &psNLSF_CB->ec_sel[ CB1_index * psNLSF_CB->order / 2 ];
+ for( i = 0; i < psNLSF_CB->order; i += 2 ) {
+ entry = *ec_sel_ptr++;
+ ec_ix [ i ] = SKP_SMULBB( SKP_RSHIFT( entry, 1 ) & 7, 2 * NLSF_QUANT_MAX_AMPLITUDE + 1 );
+ pred_Q8[ i ] = psNLSF_CB->pred_Q8[ i + ( entry & 1 ) * ( psNLSF_CB->order - 1 ) ];
+ ec_ix [ i + 1 ] = SKP_SMULBB( SKP_RSHIFT( entry, 5 ) & 7, 2 * NLSF_QUANT_MAX_AMPLITUDE + 1 );
+ pred_Q8[ i + 1 ] = psNLSF_CB->pred_Q8[ i + ( SKP_RSHIFT( entry, 4 ) & 1 ) * ( psNLSF_CB->order - 1 ) + 1 ];
+ }
+}
+
--- a/src_common/SKP_Silk_NSQ.c
+++ b/src_common/SKP_Silk_NSQ.c
@@ -189,8 +189,7 @@
{
SKP_int i, j;
SKP_int32 LTP_pred_Q14, LPC_pred_Q10, n_AR_Q10, n_LTP_Q14;
- SKP_int32 n_LF_Q10, r_Q10, q_Q0, q_Q10;
- SKP_int32 thr1_Q10, thr2_Q10, thr3_Q10;
+ SKP_int32 n_LF_Q10, r_Q10, rr_Q10, q1_Q10, q2_Q10, rd1_Q10, rd2_Q10;
SKP_int32 dither, exc_Q10, LPC_exc_Q10, xq_Q10;
SKP_int32 tmp1, tmp2, sLF_AR_shp_Q10;
SKP_int32 *psLPC_Q14, *shp_lag_ptr, *pred_lag_ptr;
@@ -201,12 +200,6 @@
/* Setup short term AR state */
psLPC_Q14 = &NSQ->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - 1 ];
- /* Quantization thresholds */
- thr1_Q10 = SKP_SUB_RSHIFT32( -1536, Lambda_Q10, 1 );
- thr2_Q10 = SKP_SUB_RSHIFT32( -512, Lambda_Q10, 1 );
- thr2_Q10 = SKP_ADD_RSHIFT32( thr2_Q10, SKP_SMULBB( offset_Q10, Lambda_Q10 ), 10 );
- thr3_Q10 = SKP_ADD_RSHIFT32( 512, Lambda_Q10, 1 );
-
for( i = 0; i < length; i++ ) {
/* Generate dither */
NSQ->rand_seed = SKP_RAND( NSQ->rand_seed );
@@ -280,46 +273,62 @@
n_LTP_Q14 = SKP_LSHIFT( n_LTP_Q14, 6 );
shp_lag_ptr++;
- tmp1 = SKP_SUB32( LTP_pred_Q14, n_LTP_Q14 ); /* Add Q14 stuff */
- tmp1 = SKP_RSHIFT( tmp1, 4 ); /* convert to Q10 */
- tmp1 = SKP_ADD32( tmp1, LPC_pred_Q10 ); /* add Q10 stuff */
- tmp1 = SKP_SUB32( tmp1, n_AR_Q10 ); /* subtract Q10 stuff */
+ tmp1 = SKP_SUB32( LTP_pred_Q14, n_LTP_Q14 ); /* Add Q14 stuff */
+ tmp1 = SKP_RSHIFT( tmp1, 4 ); /* convert to Q10 */
+ tmp1 = SKP_ADD32( tmp1, LPC_pred_Q10 ); /* add Q10 stuff */
+ tmp1 = SKP_SUB32( tmp1, n_AR_Q10 ); /* subtract Q10 stuff */
} else {
- tmp1 = SKP_SUB32( LPC_pred_Q10, n_AR_Q10 ); /* subtract Q10 stuff */
+ tmp1 = SKP_SUB32( LPC_pred_Q10, n_AR_Q10 ); /* subtract Q10 stuff */
}
/* Input minus prediction plus noise feedback */
//r = x[ i ] - LTP_pred - LPC_pred + n_AR + n_Tilt + n_LF + n_LTP;
- tmp1 = SKP_SUB32( tmp1, n_LF_Q10 ); /* subtract Q10 stuff */
+ tmp1 = SKP_SUB32( tmp1, n_LF_Q10 ); /* subtract Q10 stuff */
r_Q10 = SKP_SUB32( x_sc_Q10[ i ], tmp1 );
/* Flip sign depending on dither */
- r_Q10 = ( r_Q10 ^ dither ) - dither;
- r_Q10 = SKP_SUB32( r_Q10, offset_Q10 );
- r_Q10 = SKP_LIMIT_32( r_Q10, -64 << 10, 64 << 10 );
+ r_Q10 = r_Q10 ^ dither;
+ r_Q10 = SKP_LIMIT_32( r_Q10, -31 << 10, 30 << 10 );
- /* Quantize */
- q_Q0 = 0;
- q_Q10 = 0;
- if( r_Q10 < thr2_Q10 ) {
- if( r_Q10 < thr1_Q10 ) {
- q_Q0 = SKP_RSHIFT_ROUND( SKP_ADD_RSHIFT32( r_Q10, Lambda_Q10, 1 ), 10 );
- q_Q10 = SKP_LSHIFT( q_Q0, 10 );
- } else {
- q_Q0 = -1;
- q_Q10 = -1024;
- }
- } else {
- if( r_Q10 > thr3_Q10 ) {
- q_Q0 = SKP_RSHIFT_ROUND( SKP_SUB_RSHIFT32( r_Q10, Lambda_Q10, 1 ), 10 );
- q_Q10 = SKP_LSHIFT( q_Q0, 10 );
- }
+ /* Find two quantization level candidates and measure their rate-distortion */
+ q1_Q10 = SKP_SUB32( r_Q10, offset_Q10 );
+ q1_Q10 = SKP_RSHIFT( q1_Q10, 10 );
+ if( q1_Q10 > 0 ) {
+ q1_Q10 = SKP_SUB32( SKP_LSHIFT( q1_Q10, 10 ), QUANT_LEVEL_ADJUST_Q10 );
+ q1_Q10 = SKP_ADD32( q1_Q10, offset_Q10 );
+ q2_Q10 = SKP_ADD32( q1_Q10, 1024 );
+ rd1_Q10 = SKP_SMULBB( q1_Q10, Lambda_Q10 );
+ rd2_Q10 = SKP_SMULBB( q2_Q10, Lambda_Q10 );
+ } else if( q1_Q10 == 0 ) {
+ q1_Q10 = offset_Q10;
+ q2_Q10 = SKP_ADD32( q1_Q10, 1024 - QUANT_LEVEL_ADJUST_Q10 );
+ rd1_Q10 = SKP_SMULBB( q1_Q10, Lambda_Q10 );
+ rd2_Q10 = SKP_SMULBB( q2_Q10, Lambda_Q10 );
+ } else if( q1_Q10 == -1 ) {
+ q2_Q10 = offset_Q10;
+ q1_Q10 = SKP_SUB32( q2_Q10, 1024 - QUANT_LEVEL_ADJUST_Q10 );
+ rd1_Q10 = SKP_SMULBB( -q1_Q10, Lambda_Q10 );
+ rd2_Q10 = SKP_SMULBB( q2_Q10, Lambda_Q10 );
+ } else { /* Q1_Q10 < -1 */
+ q1_Q10 = SKP_ADD32( SKP_LSHIFT( q1_Q10, 10 ), QUANT_LEVEL_ADJUST_Q10 );
+ q1_Q10 = SKP_ADD32( q1_Q10, offset_Q10 );
+ q2_Q10 = SKP_ADD32( q1_Q10, 1024 );
+ rd1_Q10 = SKP_SMULBB( -q1_Q10, Lambda_Q10 );
+ rd2_Q10 = SKP_SMULBB( -q2_Q10, Lambda_Q10 );
}
- pulses[ i ] = ( SKP_int8 )q_Q0; /* No saturation needed because max is 64 */
+ rr_Q10 = SKP_SUB32( r_Q10, q1_Q10 );
+ rd1_Q10 = SKP_RSHIFT( SKP_SMLABB( rd1_Q10, rr_Q10, rr_Q10 ), 10 );
+ rr_Q10 = SKP_SUB32( r_Q10, q2_Q10 );
+ rd2_Q10 = SKP_RSHIFT( SKP_SMLABB( rd2_Q10, rr_Q10, rr_Q10 ), 10 );
+ if( rd2_Q10 < rd1_Q10 ) {
+ q1_Q10 = q2_Q10;
+ }
+
+ pulses[ i ] = ( SKP_int8 )SKP_RSHIFT_ROUND( q1_Q10, 10 );
+
/* Excitation */
- exc_Q10 = SKP_ADD32( q_Q10, offset_Q10 );
- exc_Q10 = ( exc_Q10 ^ dither ) - dither;
+ exc_Q10 = q1_Q10 ^ dither;
/* Add predictions */
LPC_exc_Q10 = SKP_ADD32( exc_Q10, SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 ) );
--- a/src_common/SKP_Silk_NSQ_del_dec.c
+++ b/src_common/SKP_Silk_NSQ_del_dec.c
@@ -215,7 +215,7 @@
last_smple_idx = smpl_buf_idx + decisionDelay;
for( i = 0; i < decisionDelay; i++ ) {
last_smple_idx = ( last_smple_idx - 1 ) & DECISION_DELAY_MASK;
- pulses[ i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 );
+ pulses[ i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT_ROUND( psDD->Q_Q10[ last_smple_idx ], 10 );
pxq[ i - decisionDelay ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND(
SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ], Gains_Q16[ 1 ] ), 10 ) );
NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay + i ] = psDD->Shape_Q10[ last_smple_idx ];
@@ -265,7 +265,7 @@
last_smple_idx = smpl_buf_idx + decisionDelay;
for( i = 0; i < decisionDelay; i++ ) {
last_smple_idx = ( last_smple_idx - 1 ) & DECISION_DELAY_MASK;
- pulses[ i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 );
+ pulses[ i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT_ROUND( psDD->Q_Q10[ last_smple_idx ], 10 );
pxq[ i - decisionDelay ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND(
SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ], Gains_Q16[ psEncC->nb_subfr - 1 ] ), 10 ) );
NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay + i ] = psDD->Shape_Q10[ last_smple_idx ];
@@ -324,7 +324,7 @@
SKP_int i, j, k, Winner_ind, RDmin_ind, RDmax_ind, last_smple_idx;
SKP_int32 Winner_rand_state;
SKP_int32 LTP_pred_Q14, LPC_pred_Q10, n_AR_Q10, n_LTP_Q14, LTP_Q10;
- SKP_int32 n_LF_Q10, r_Q10, rr_Q20, rd1_Q10, rd2_Q10, RDmin_Q10, RDmax_Q10;
+ SKP_int32 n_LF_Q10, r_Q10, rr_Q10, rd1_Q10, rd2_Q10, RDmin_Q10, RDmax_Q10;
SKP_int32 q1_Q10, q2_Q10, dither, exc_Q10, LPC_exc_Q10, xq_Q10;
SKP_int32 tmp1, tmp2, sLF_AR_shp_Q10;
SKP_int32 *pred_lag_ptr, *shp_lag_ptr, *psLPC_Q14;
@@ -434,33 +434,39 @@
r_Q10 = SKP_SUB32( x_Q10[ i ], tmp1 ); /* residual error Q10 */
/* Flip sign depending on dither */
- r_Q10 = ( r_Q10 ^ dither ) - dither;
- r_Q10 = SKP_SUB32( r_Q10, offset_Q10 );
- r_Q10 = SKP_LIMIT_32( r_Q10, -64 << 10, 64 << 10 );
+ r_Q10 = r_Q10 ^ dither;
+ r_Q10 = SKP_LIMIT_32( r_Q10, -31 << 10, 30 << 10 );
/* Find two quantization level candidates and measure their rate-distortion */
- if( r_Q10 < -1536 ) {
- q1_Q10 = SKP_LSHIFT( SKP_RSHIFT_ROUND( r_Q10, 10 ), 10 );
- r_Q10 = SKP_SUB32( r_Q10, q1_Q10 );
- rd1_Q10 = SKP_RSHIFT( SKP_SMLABB( SKP_MUL( -SKP_ADD32( q1_Q10, offset_Q10 ), Lambda_Q10 ), r_Q10, r_Q10 ), 10 );
- rd2_Q10 = SKP_ADD32( rd1_Q10, 1024 );
- rd2_Q10 = SKP_SUB32( rd2_Q10, SKP_ADD_LSHIFT32( Lambda_Q10, r_Q10, 1 ) );
+ q1_Q10 = SKP_SUB32( r_Q10, offset_Q10 );
+ q1_Q10 = SKP_RSHIFT( q1_Q10, 10 );
+ if( q1_Q10 > 0 ) {
+ q1_Q10 = SKP_SUB32( SKP_LSHIFT( q1_Q10, 10 ), QUANT_LEVEL_ADJUST_Q10 );
+ q1_Q10 = SKP_ADD32( q1_Q10, offset_Q10 );
q2_Q10 = SKP_ADD32( q1_Q10, 1024 );
- } else if( r_Q10 > 512 ) {
- q1_Q10 = SKP_LSHIFT( SKP_RSHIFT_ROUND( r_Q10, 10 ), 10 );
- r_Q10 = SKP_SUB32( r_Q10, q1_Q10 );
- rd1_Q10 = SKP_RSHIFT( SKP_SMLABB( SKP_MUL( SKP_ADD32( q1_Q10, offset_Q10 ), Lambda_Q10 ), r_Q10, r_Q10 ), 10 );
- rd2_Q10 = SKP_ADD32( rd1_Q10, 1024 );
- rd2_Q10 = SKP_SUB32( rd2_Q10, SKP_SUB_LSHIFT32( Lambda_Q10, r_Q10, 1 ) );
- q2_Q10 = SKP_SUB32( q1_Q10, 1024 );
- } else { /* r_Q10 >= -1536 && q1_Q10 <= 512 */
- rr_Q20 = SKP_SMULBB( offset_Q10, Lambda_Q10 );
- rd2_Q10 = SKP_RSHIFT( SKP_SMLABB( rr_Q20, r_Q10, r_Q10 ), 10 );
- rd1_Q10 = SKP_ADD32( rd2_Q10, 1024 );
- rd1_Q10 = SKP_ADD32( rd1_Q10, SKP_SUB_RSHIFT32( SKP_ADD_LSHIFT32( Lambda_Q10, r_Q10, 1 ), rr_Q20, 9 ) );
- q1_Q10 = -1024;
- q2_Q10 = 0;
+ rd1_Q10 = SKP_SMULBB( q1_Q10, Lambda_Q10 );
+ rd2_Q10 = SKP_SMULBB( q2_Q10, Lambda_Q10 );
+ } else if( q1_Q10 == 0 ) {
+ q1_Q10 = offset_Q10;
+ q2_Q10 = SKP_ADD32( q1_Q10, 1024 - QUANT_LEVEL_ADJUST_Q10 );
+ rd1_Q10 = SKP_SMULBB( q1_Q10, Lambda_Q10 );
+ rd2_Q10 = SKP_SMULBB( q2_Q10, Lambda_Q10 );
+ } else if( q1_Q10 == -1 ) {
+ q2_Q10 = offset_Q10;
+ q1_Q10 = SKP_SUB32( q2_Q10, 1024 - QUANT_LEVEL_ADJUST_Q10 );
+ rd1_Q10 = SKP_SMULBB( -q1_Q10, Lambda_Q10 );
+ rd2_Q10 = SKP_SMULBB( q2_Q10, Lambda_Q10 );
+ } else { /* Q1_Q10 < -1 */
+ q1_Q10 = SKP_ADD32( SKP_LSHIFT( q1_Q10, 10 ), QUANT_LEVEL_ADJUST_Q10 );
+ q1_Q10 = SKP_ADD32( q1_Q10, offset_Q10 );
+ q2_Q10 = SKP_ADD32( q1_Q10, 1024 );
+ rd1_Q10 = SKP_SMULBB( -q1_Q10, Lambda_Q10 );
+ rd2_Q10 = SKP_SMULBB( -q2_Q10, Lambda_Q10 );
}
+ rr_Q10 = SKP_SUB32( r_Q10, q1_Q10 );
+ rd1_Q10 = SKP_RSHIFT( SKP_SMLABB( rd1_Q10, rr_Q10, rr_Q10 ), 10 );
+ rr_Q10 = SKP_SUB32( r_Q10, q2_Q10 );
+ rd2_Q10 = SKP_RSHIFT( SKP_SMLABB( rd2_Q10, rr_Q10, rr_Q10 ), 10 );
if( rd1_Q10 < rd2_Q10 ) {
psSS[ 0 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd1_Q10 );
@@ -477,8 +483,7 @@
/* Update states for best quantization */
/* Quantized excitation */
- exc_Q10 = SKP_ADD32( offset_Q10, psSS[ 0 ].Q_Q10 );
- exc_Q10 = ( exc_Q10 ^ dither ) - dither;
+ exc_Q10 = psSS[ 0 ].Q_Q10 ^ dither;
/* Add predictions */
LPC_exc_Q10 = exc_Q10 + SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 );
@@ -494,8 +499,7 @@
/* Update states for second best quantization */
/* Quantized excitation */
- exc_Q10 = SKP_ADD32( offset_Q10, psSS[ 1 ].Q_Q10 );
- exc_Q10 = ( exc_Q10 ^ dither ) - dither;
+ exc_Q10 = psSS[ 1 ].Q_Q10 ^ dither;
/* Add predictions */
LPC_exc_Q10 = exc_Q10 + SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 );
@@ -560,7 +564,7 @@
/* Write samples from winner to output and long-term filter states */
psDD = &psDelDec[ Winner_ind ];
if( subfr > 0 || i >= decisionDelay ) {
- pulses[ i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 );
+ pulses[ i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT_ROUND( psDD->Q_Q10[ last_smple_idx ], 10 );
xq[ i - decisionDelay ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND(
SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ], delayedGain_Q16[ last_smple_idx ] ), 10 ) );
NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay ] = psDD->Shape_Q10[ last_smple_idx ];
@@ -579,7 +583,7 @@
psDD->Q_Q10[ *smpl_buf_idx ] = psSS->Q_Q10;
psDD->Pred_Q16[ *smpl_buf_idx ] = psSS->LPC_exc_Q16;
psDD->Shape_Q10[ *smpl_buf_idx ] = psSS->sLTP_shp_Q10;
- psDD->Seed = SKP_ADD_RSHIFT32( psDD->Seed, psSS->Q_Q10, 10 );
+ psDD->Seed = SKP_ADD32( psDD->Seed, SKP_RSHIFT_ROUND( psSS->Q_Q10, 10 ) );
psDD->RandState[ *smpl_buf_idx ] = psDD->Seed;
psDD->RD_Q10 = psSS->RD_Q10;
}
--- a/src_common/SKP_Silk_VAD.c
+++ b/src_common/SKP_Silk_VAD.c
@@ -241,8 +241,6 @@
if( psEncC->frame_length == 10 * psEncC->fs_kHz ) {
smooth_coef_Q16 >>= 1;
- } else {
- SKP_assert( psEncC->frame_length == 20 * psEncC->fs_kHz );
}
for( b = 0; b < VAD_N_BANDS; b++ ) {
--- a/src_common/SKP_Silk_control_audio_bandwidth.c
+++ b/src_common/SKP_Silk_control_audio_bandwidth.c
@@ -26,6 +26,7 @@
***********************************************************************/
#include "SKP_Silk_main.h"
+#include "SKP_Silk_tuning_parameters.h"
/* Control internal sampling rate */
SKP_int SKP_Silk_control_audio_bandwidth(
--- a/src_common/SKP_Silk_dec_API.c
+++ b/src_common/SKP_Silk_dec_API.c
@@ -56,6 +56,54 @@
return ret;
}
+/* Prefill LPC synthesis buffer, HP filter and upsampler. Input must be exactly 10 ms of audio. */
+SKP_int SKP_Silk_SDK_Decoder_prefill_buffers( /* O: Returns error code */
+ void* decState, /* I/O: State */
+ SKP_SILK_SDK_DecControlStruct* decControl, /* I/O: Control Structure */
+ const SKP_int16 *samplesIn, /* I: Speech sample input vector (10 ms) */
+ SKP_int nSamplesIn /* I: Number of samples in input vector */
+)
+{
+ SKP_int i, nSamples, ret = 0;
+ SKP_Silk_decoder_state *psDec = ( SKP_Silk_decoder_state *)decState;
+ SKP_Silk_resampler_state_struct resampler_state;
+ SKP_int16 buf[ 10 * MAX_FS_KHZ ];
+ SKP_int16 buf_out[ 10 * MAX_API_FS_KHZ ];
+ const SKP_int16 *in_ptr;
+
+ /* Compute some numbers at API sampling rate */
+ if( nSamplesIn != SKP_DIV32_16( decControl->API_sampleRate, 100 ) ) {
+ return -1;
+ }
+
+ /* Resample input if necessary */
+ if( decControl->API_sampleRate != SKP_SMULBB( 1000, psDec->fs_kHz ) ) {
+ ret += SKP_Silk_resampler_init( &resampler_state, decControl->API_sampleRate, SKP_SMULBB( 1000, psDec->fs_kHz ) );
+ ret += SKP_Silk_resampler( &resampler_state, buf, samplesIn, nSamplesIn );
+ in_ptr = buf;
+ nSamples = SKP_SMULBB( 10, psDec->fs_kHz );
+ } else {
+ in_ptr = samplesIn;
+ nSamples = nSamplesIn;
+ }
+
+ /* Set synthesis filter state */
+ for( i = 0; i < psDec->LPC_order; i++ ) {
+ //psDec->sLPC_Q14[ MAX_LPC_ORDER - i ] = SKP_LSHIFT( SKP_SMULWB( psDec->prev_inv_gain_Q16, in_ptr[ nSamples - i ] ), 14 );
+ }
+
+ /* HP filter */
+ SKP_Silk_biquad_alt( in_ptr, psDec->HP_B, psDec->HP_A, psDec->HPState, buf, nSamples );
+
+ /* Output upsampler */
+ SKP_Silk_resampler( &psDec->resampler_state, buf_out, buf, nSamples );
+
+ /* Avoid using LSF interpolation or pitch prediction in first next frame */
+ psDec->first_frame_after_reset = 1;
+
+ return ret;
+}
+
/* Decode a frame */
SKP_int SKP_Silk_SDK_Decode(
void* decState, /* I/O: State */
--- a/src_common/SKP_Silk_decode_core.c
+++ b/src_common/SKP_Silk_decode_core.c
@@ -40,7 +40,7 @@
SKP_int i, j, k, lag = 0, start_idx, sLTP_buf_idx, NLSF_interpolation_flag, signalType;
SKP_int16 *A_Q12, *B_Q14, *pxq, A_Q12_tmp[ MAX_LPC_ORDER ];
SKP_int16 sLTP[ MAX_FRAME_LENGTH ];
- SKP_int32 LTP_pred_Q14, LPC_pred_Q10, Gain_Q16, inv_gain_Q16, inv_gain_Q32, gain_adj_Q16, rand_seed, offset_Q10, dither;
+ SKP_int32 LTP_pred_Q14, LPC_pred_Q10, Gain_Q16, inv_gain_Q16, inv_gain_Q32, gain_adj_Q16, rand_seed, offset_Q10;
SKP_int32 *pred_lag_ptr, *pexc_Q10, *pres_Q10;
SKP_int32 res_Q10[ MAX_SUB_FRAME_LENGTH ];
SKP_int32 vec_Q10[ MAX_SUB_FRAME_LENGTH ];
@@ -59,17 +59,21 @@
rand_seed = psDec->indices.Seed;
for( i = 0; i < psDec->frame_length; i++ ) {
rand_seed = SKP_RAND( rand_seed );
- /* dither = rand_seed < 0 ? 0xFFFFFFFF : 0; */
- dither = SKP_RSHIFT( rand_seed, 31 );
+ psDec->exc_Q10[ i ] = SKP_LSHIFT( ( SKP_int32 )pulses[ i ], 10 );
+ if( psDec->exc_Q10[ i ] > 0 ) {
+ psDec->exc_Q10[ i ] -= QUANT_LEVEL_ADJUST_Q10;
+ } else
+ if( psDec->exc_Q10[ i ] < 0 ) {
+ psDec->exc_Q10[ i ] += QUANT_LEVEL_ADJUST_Q10;
+ }
+ psDec->exc_Q10[ i ] += offset_Q10;
+ psDec->exc_Q10[ i ] ^= SKP_RSHIFT( rand_seed, 31 );
- psDec->exc_Q10[ i ] = SKP_LSHIFT( ( SKP_int32 )pulses[ i ], 10 ) + offset_Q10;
- psDec->exc_Q10[ i ] = ( psDec->exc_Q10[ i ] ^ dither ) - dither;
-
rand_seed += pulses[ i ];
}
#ifdef SAVE_ALL_INTERNAL_DATA
- DEBUG_STORE_DATA( dec_q.dat, q, psDec->frame_length * sizeof( SKP_int ) );
+ DEBUG_STORE_DATA( dec_q.dat, pulses, psDec->frame_length * sizeof( SKP_int ) );
#endif
pexc_Q10 = psDec->exc_Q10;
--- a/src_common/SKP_Silk_decode_indices.c
+++ b/src_common/SKP_Silk_decode_indices.c
@@ -37,7 +37,8 @@
{
SKP_int i, k, Ix, condCoding;
SKP_int decode_absolute_lagIndex, delta_lagIndex;
- const SKP_Silk_NLSF_CB_struct *psNLSF_CB = NULL;
+ SKP_int16 ec_ix[ MAX_LPC_ORDER ];
+ SKP_uint8 pred_Q8[ MAX_LPC_ORDER ];
if( FrameIndex > 0 && ( decode_LBRR == 0 || psDec->LBRR_flags[ FrameIndex - 1 ] == 1 ) ) {
condCoding = 1;
@@ -77,17 +78,20 @@
/**********************/
/* Decode LSF Indices */
/**********************/
- /* Set pointer to LSF VQ CB for the current signal type */
- psNLSF_CB = psDec->psNLSF_CB[ 1 - ( psDec->indices.signalType >> 1 ) ];
-
- /* Range decoding of the NLSF path */
- for( i = 0; i < psNLSF_CB->nStages; i++ ) {
- psDec->indices.NLSFIndices[ i ] = (SKP_int8)ec_dec_icdf( psRangeDec, psNLSF_CB->StartPtr[ i ], 8 );
+ psDec->indices.NLSFIndices[ 0 ] = (SKP_int8)ec_dec_icdf( psRangeDec, &psDec->psNLSF_CB->CB1_iCDF[ ( psDec->indices.signalType >> 1 ) * psDec->psNLSF_CB->nVectors ], 8 );
+ SKP_Silk_NLSF_unpack( ec_ix, pred_Q8, psDec->psNLSF_CB, psDec->indices.NLSFIndices[ 0 ] );
+ SKP_assert( psDec->psNLSF_CB->order == psDec->LPC_order );
+ for( i = 0; i < psDec->psNLSF_CB->order; i++ ) {
+ Ix = ec_dec_icdf( psRangeDec, &psDec->psNLSF_CB->ec_iCDF[ ec_ix[ i ] ], 8 );
+ if( Ix == 0 ) {
+ Ix -= ec_dec_icdf( psRangeDec, SKP_Silk_NLSF_EXT_iCDF, 8 );
+ } else if( Ix == 2 * NLSF_QUANT_MAX_AMPLITUDE ) {
+ Ix += ec_dec_icdf( psRangeDec, SKP_Silk_NLSF_EXT_iCDF, 8 );
+ }
+ psDec->indices.NLSFIndices[ i+1 ] = (SKP_int8)( Ix - NLSF_QUANT_MAX_AMPLITUDE );
}
-
- /***********************************/
+
/* Decode LSF interpolation factor */
- /***********************************/
if( psDec->nb_subfr == MAX_NB_SUBFR ) {
psDec->indices.NLSFInterpCoef_Q2 = (SKP_int8)ec_dec_icdf( psRangeDec, SKP_Silk_NLSF_interpolation_factor_iCDF, 8 );
} else {
--- a/src_common/SKP_Silk_decode_parameters.c
+++ b/src_common/SKP_Silk_decode_parameters.c
@@ -34,9 +34,8 @@
)
{
SKP_int i, k, Ix;
- SKP_int pNLSF_Q15[ MAX_LPC_ORDER ], pNLSF0_Q15[ MAX_LPC_ORDER ];
+ SKP_int16 pNLSF_Q15[ MAX_LPC_ORDER ], pNLSF0_Q15[ MAX_LPC_ORDER ];
const SKP_int8 *cbk_ptr_Q7;
- const SKP_Silk_NLSF_CB_struct *psNLSF_CB = NULL;
/* Dequant Gains */
SKP_Silk_gains_dequant( psDecCtrl->Gains_Q16, psDec->indices.GainsIndices,
@@ -45,12 +44,8 @@
/****************/
/* Decode NLSFs */
/****************/
- /* Set pointer to NLSF VQ CB for the current signal type */
- psNLSF_CB = psDec->psNLSF_CB[ 1 - (psDec->indices.signalType >> 1) ];
+ SKP_Silk_NLSF_decode( pNLSF_Q15, psDec->indices.NLSFIndices, psDec->psNLSF_CB );
- /* From the NLSF path, decode an NLSF vector */
- SKP_Silk_NLSF_MSVQ_decode( pNLSF_Q15, psNLSF_CB, psDec->indices.NLSFIndices, psDec->LPC_order );
-
/* Convert NLSF parameters to AR prediction filter coefficients */
SKP_Silk_NLSF2A_stable( psDecCtrl->PredCoef_Q12[ 1 ], pNLSF_Q15, psDec->LPC_order );
@@ -76,7 +71,7 @@
psDec->LPC_order * sizeof( SKP_int16 ) );
}
- SKP_memcpy( psDec->prevNLSF_Q15, pNLSF_Q15, psDec->LPC_order * sizeof( SKP_int ) );
+ SKP_memcpy( psDec->prevNLSF_Q15, pNLSF_Q15, psDec->LPC_order * sizeof( SKP_int16 ) );
/* After a packet loss do BWE of LPC coefs */
if( psDec->lossCnt ) {
--- a/src_common/SKP_Silk_decoder_set_fs.c
+++ b/src_common/SKP_Silk_decoder_set_fs.c
@@ -35,6 +35,9 @@
{
SKP_int frame_length;
+ SKP_assert( fs_kHz == 8 || fs_kHz == 12 || fs_kHz == 16 );
+ SKP_assert( psDec->nb_subfr == MAX_NB_SUBFR || psDec->nb_subfr == MAX_NB_SUBFR/2 );
+
psDec->subfr_length = SKP_SMULBB( SUB_FRAME_LENGTH_MS, fs_kHz );
frame_length = SKP_SMULBB( psDec->nb_subfr, psDec->subfr_length );
if( psDec->fs_kHz != fs_kHz || frame_length != psDec->frame_length ) {
@@ -42,34 +45,30 @@
psDec->frame_length = frame_length;
psDec->ltp_mem_length = SKP_SMULBB( LTP_MEM_LENGTH_MS, fs_kHz );
if( psDec->fs_kHz == 8 ) {
- psDec->LPC_order = MIN_LPC_ORDER;
- psDec->psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_10;
- psDec->psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_10;
- if( psDec->nb_subfr == MAX_NB_SUBFR ){
+ if( psDec->nb_subfr == MAX_NB_SUBFR ) {
psDec->pitch_contour_iCDF = SKP_Silk_pitch_contour_NB_iCDF;
- } else if( psDec->nb_subfr == MAX_NB_SUBFR / 2 ){
- psDec->pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_NB_iCDF;
} else {
- /* Unsupported number of frames */
- SKP_assert( 0 );
+ psDec->pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_NB_iCDF;
}
} else {
- psDec->LPC_order = MAX_LPC_ORDER;
- psDec->psNLSF_CB[ 0 ] = &SKP_Silk_NLSF_CB0_16;
- psDec->psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_16;
- if( psDec->nb_subfr == MAX_NB_SUBFR ){
+ if( psDec->nb_subfr == MAX_NB_SUBFR ) {
psDec->pitch_contour_iCDF = SKP_Silk_pitch_contour_iCDF;
- } else if( psDec->nb_subfr == MAX_NB_SUBFR / 2 ){
- psDec->pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_iCDF;
} else {
- /* Unsupported number of frames */
- SKP_assert( 0 );
+ psDec->pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_iCDF;
}
}
+ if( psDec->fs_kHz == 8 || psDec->fs_kHz == 12 ) {
+ psDec->LPC_order = MIN_LPC_ORDER;
+ psDec->psNLSF_CB = &SKP_Silk_NLSF_CB_NB_MB;
+ } else {
+ psDec->LPC_order = MAX_LPC_ORDER;
+ psDec->psNLSF_CB = &SKP_Silk_NLSF_CB_WB;
+ }
+
/* Reset part of the decoder state */
- SKP_memset( psDec->sLPC_Q14, 0, MAX_LPC_ORDER * sizeof( SKP_int32 ) );
- SKP_memset( psDec->outBuf, 0, MAX_FRAME_LENGTH * sizeof( SKP_int16 ) );
- SKP_memset( psDec->prevNLSF_Q15, 0, MAX_LPC_ORDER * sizeof( SKP_int ) );
+ SKP_memset( psDec->sLPC_Q14, 0, sizeof( psDec->sLPC_Q14 ) );
+ SKP_memset( psDec->outBuf, 0, MAX_FRAME_LENGTH * sizeof( SKP_int16 ) );
+ SKP_memset( psDec->prevNLSF_Q15, 0, sizeof( psDec->prevNLSF_Q15 ) );
psDec->lagPrev = 100;
psDec->LastGainIndex = 10;
--- a/src_common/SKP_Silk_define.h
+++ b/src_common/SKP_Silk_define.h
@@ -49,26 +49,17 @@
/* Limits on bitrate */
#define MIN_TARGET_RATE_BPS 5000
#define MAX_TARGET_RATE_BPS 80000
-
-/* Compensation in bitrate calculations for 10 ms modes */
-#define REDUCE_BITRATE_10_MS_BPS 2200
-
-/* Transition bitrates between modes */
-#define WB2MB_BITRATE_BPS 12000
-#define MB2WB_BITRATE_BPS 16000
-#define MB2NB_BITRATE_BPS 9000
-#define NB2MB_BITRATE_BPS 12000
#define TARGET_RATE_TAB_SZ 8
-/* DTX settings */
-#define NO_SPEECH_FRAMES_BEFORE_DTX 5 /* eq 100 ms */
-#define MAX_CONSECUTIVE_DTX 20 /* eq 400 ms */
-
/* LBRR thresholds */
#define LBRR_NB_MIN_RATE_BPS 9000
#define LBRR_MB_MIN_RATE_BPS 12000
#define LBRR_WB_MIN_RATE_BPS 15000
+/* DTX settings */
+#define NO_SPEECH_FRAMES_BEFORE_DTX 5 /* eq 100 ms */
+#define MAX_CONSECUTIVE_DTX 20 /* eq 400 ms */
+
/* Activate bandwidth transition filtering for mode switching */
#define SWITCH_TRANSITION_FILTERING 1
@@ -130,6 +121,8 @@
#define OFFSET_UVL_Q10 100
#define OFFSET_UVH_Q10 240
+#define QUANT_LEVEL_ADJUST_Q10 80
+
/* Maximum numbers of iterations used to stabilize a LPC vector */
#define MAX_LPC_STABILIZE_ITERATIONS 20
@@ -204,30 +197,13 @@
/******************/
/* NLSF quantizer */
/******************/
-#define NLSF_MSVQ_MAX_CB_STAGES 10 /* Update manually when changing codebooks */
-#define NLSF_MSVQ_MAX_VECTORS_IN_STAGE 64 /* Update manually when changing codebooks */
-#define NLSF_MSVQ_MAX_VECTORS_IN_STAGE_TWO_TO_END 16 /* Update manually when changing codebooks */
-
-#define NLSF_MSVQ_FLUCTUATION_REDUCTION 1
-#define MAX_NLSF_MSVQ_SURVIVORS 16
-
-#define NLSF_Q_DOMAIN_STAGE_0 8
-#define NLSF_Q_DOMAIN_STAGE_2_TO_LAST 8
-
-/* Based on above defines, calculate how much memory is necessary to allocate */
-#if( NLSF_MSVQ_MAX_VECTORS_IN_STAGE > ( MAX_NLSF_MSVQ_SURVIVORS_LC_MODE * NLSF_MSVQ_MAX_VECTORS_IN_STAGE_TWO_TO_END ) )
-# define NLSF_MSVQ_TREE_SEARCH_MAX_VECTORS_EVALUATED_LC_MODE NLSF_MSVQ_MAX_VECTORS_IN_STAGE
-#else
-# define NLSF_MSVQ_TREE_SEARCH_MAX_VECTORS_EVALUATED_LC_MODE MAX_NLSF_MSVQ_SURVIVORS_LC_MODE * NLSF_MSVQ_MAX_VECTORS_IN_STAGE_TWO_TO_END
-#endif
-
-#if( NLSF_MSVQ_MAX_VECTORS_IN_STAGE > ( MAX_NLSF_MSVQ_SURVIVORS * NLSF_MSVQ_MAX_VECTORS_IN_STAGE_TWO_TO_END ) )
-# define NLSF_MSVQ_TREE_SEARCH_MAX_VECTORS_EVALUATED NLSF_MSVQ_MAX_VECTORS_IN_STAGE
-#else
-# define NLSF_MSVQ_TREE_SEARCH_MAX_VECTORS_EVALUATED MAX_NLSF_MSVQ_SURVIVORS * NLSF_MSVQ_MAX_VECTORS_IN_STAGE_TWO_TO_END
-#endif
-
-#define NLSF_MSVQ_SURV_MAX_REL_RD 0.1f /* Must be < 0.5 */
+#define NLSF_VQ_MAX_VECTORS 32
+#define NLSF_VQ_MAX_SURVIVORS 16
+#define NLSF_QUANT_MAX_AMPLITUDE 4
+#define NLSF_QUANT_MAX_AMPLITUDE_EXT 10
+#define NLSF_QUANT_LEVEL_ADJ 0.1
+#define NLSF_QUANT_DEL_DEC_STATES_LOG2 2
+#define NLSF_QUANT_DEL_DEC_STATES ( 1 << NLSF_QUANT_DEL_DEC_STATES_LOG2 )
/* Transition filtering for mode switching */
#if SWITCH_TRANSITION_FILTERING
--- a/src_common/SKP_Silk_enc_API.c
+++ b/src_common/SKP_Silk_enc_API.c
@@ -183,76 +183,6 @@
return ret;
}
-/*****************************/
-/* Prefill look-ahead buffer */
-/*****************************/
-#define MAX_PREFILL_LENGTH_MS 10
-SKP_int SKP_Silk_SDK_Encoder_prefill_buffer(
- void *encState, /* I/O: State */
- SKP_Silk_EncodeControlStruct *encControl, /* I: Control structure */
- const SKP_int16 *samplesIn, /* I: Speech sample input vector (last part will be used) */
- SKP_int nSamplesIn /* I: Number of samples in input vector */
-)
-{
- SKP_int start_ix, offset, nSamples, ret;
- SKP_Silk_encoder_state_Fxx *psEnc = ( SKP_Silk_encoder_state_Fxx* )encState;
- SKP_int16 buf[ MAX_PREFILL_LENGTH_MS * MAX_FS_KHZ ];
- const SKP_int16 *in_ptr;
-
- ret = process_enc_control_struct( psEnc, encControl );
-
- /* Compute some numbers at API sampling rate */
- start_ix = nSamplesIn - SKP_DIV32_16( psEnc->sCmn.API_fs_Hz, 1000 / MAX_PREFILL_LENGTH_MS ); /* 10 ms */
- if( start_ix < 0 ) {
- offset = -start_ix;
- start_ix = 0;
- } else {
- offset = 0;
- }
- nSamples = nSamplesIn - start_ix;
-
- if( psEnc->sCmn.API_fs_Hz != SKP_SMULBB( 1000, psEnc->sCmn.fs_kHz ) ) {
- /* resample input */
- ret += SKP_Silk_resampler( &psEnc->sCmn.resampler_state, buf, samplesIn + start_ix, nSamples );
- in_ptr = buf;
- /* Convert to internal sampling rate */
- offset = SKP_DIV32( SKP_MUL( offset, SKP_SMULBB( 1000, psEnc->sCmn.fs_kHz ) ), psEnc->sCmn.API_fs_Hz );
- nSamples = SKP_DIV32( SKP_MUL( nSamples, SKP_SMULBB( 1000, psEnc->sCmn.fs_kHz ) ), psEnc->sCmn.API_fs_Hz );
- } else {
- in_ptr = samplesIn + start_ix;
- }
-
-#if HIGH_PASS_INPUT
- /* Variable high-pass filter */
- SKP_Silk_HP_variable_cutoff( &psEnc->sCmn, buf, in_ptr, nSamples );
-#else
- SKP_memcpy( buf, in_ptr, nSamples * sizeof( SKP_int16 ) );
-#endif
-
-#if SWITCH_TRANSITION_FILTERING
- /* Ensure smooth bandwidth transitions */
- SKP_Silk_LP_variable_cutoff( &psEnc->sCmn.sLP, buf, nSamples );
-#endif
-
-#if FIXED_POINT
-{
- SKP_int16 *buf_ptr = psEnc->x_buf + psEnc->sCmn.ltp_mem_length + ( LA_SHAPE_MS - MAX_PREFILL_LENGTH_MS ) * psEnc->sCmn.fs_kHz + offset;
- SKP_memcpy( buf_ptr, buf, nSamples * sizeof( SKP_int16 ) );
-}
-#else
-{
- SKP_float *buf_ptr;
- buf_ptr = psEnc->x_buf + psEnc->sCmn.ltp_mem_length + ( LA_SHAPE_MS - MAX_PREFILL_LENGTH_MS ) * psEnc->sCmn.fs_kHz + offset;
- SKP_short2float_array( buf_ptr, buf, nSamples );
-}
-#endif
-
- /* Avoid using LSF interpolation or pitch prediction in first next frame */
- psEnc->sCmn.first_frame_after_reset = 1;
-
- return ret;
-}
-
/**************************/
/* Encode frame with Silk */
/**************************/
@@ -262,30 +192,49 @@
const SKP_int16 *samplesIn, /* I: Speech sample input vector */
SKP_int nSamplesIn, /* I: Number of samples in input vector */
ec_enc *psRangeEnc, /* I/O Compressor data structure */
- SKP_int32 *nBytesOut /* I/O: Number of bytes in payload (input: Max bytes) */
+ SKP_int32 *nBytesOut, /* I/O: Number of bytes in payload (input: Max bytes) */
+ const SKP_int prefillFlag /* I: Flag to indicate prefilling buffers no coding */
)
{
- SKP_int ret;
- SKP_int nSamplesToBuffer, input_10ms, nSamplesFromInput = 0;
+ SKP_int tmp_payloadSize_ms, tmp_complexity, ret = 0;
+ SKP_int nSamplesToBuffer, nBlocksOf10ms, nSamplesFromInput = 0;
SKP_Silk_encoder_state_Fxx *psEnc = ( SKP_Silk_encoder_state_Fxx* )encState;
ret = process_enc_control_struct( psEnc, encControl );
- /* Only accept input lengths that are a multiple of 10 ms */
- input_10ms = SKP_DIV32( 100 * nSamplesIn, psEnc->sCmn.API_fs_Hz );
- if( input_10ms * psEnc->sCmn.API_fs_Hz != 100 * nSamplesIn || nSamplesIn < 0 ) {
- ret = SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES;
- SKP_assert( 0 );
- return( ret );
+ nBlocksOf10ms = SKP_DIV32( 100 * nSamplesIn, psEnc->sCmn.API_fs_Hz );
+ if( prefillFlag ) {
+ /* Only accept input length of 10 ms */
+ if( nBlocksOf10ms != 1 ) {
+ ret = SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES;
+ SKP_assert( 0 );
+ return( ret );
+ }
+ /* Reset Encoder */
+ if( ret = SKP_Silk_init_encoder_Fxx( psEnc ) ) {
+ SKP_assert( 0 );
+ }
+ tmp_payloadSize_ms = encControl->payloadSize_ms;
+ encControl->payloadSize_ms = 10;
+ tmp_complexity = encControl->complexity;
+ encControl->complexity = 0;
+ ret = process_enc_control_struct( psEnc, encControl );
+ psEnc->sCmn.prefillFlag = 1;
+ } else {
+ /* Only accept input lengths that are a multiple of 10 ms */
+ if( nBlocksOf10ms * psEnc->sCmn.API_fs_Hz != 100 * nSamplesIn || nSamplesIn < 0 ) {
+ ret = SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES;
+ SKP_assert( 0 );
+ return( ret );
+ }
+ /* Make sure no more than one packet can be produced */
+ if( 1000 * (SKP_int32)nSamplesIn > psEnc->sCmn.PacketSize_ms * psEnc->sCmn.API_fs_Hz ) {
+ ret = SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES;
+ SKP_assert( 0 );
+ return( ret );
+ }
}
- /* Make sure no more than one packet can be produced */
- if( 1000 * (SKP_int32)nSamplesIn > psEnc->sCmn.PacketSize_ms * psEnc->sCmn.API_fs_Hz ) {
- ret = SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES;
- SKP_assert( 0 );
- return( ret );
- }
-
/* Input buffering/resampling and encoding */
while( 1 ) {
nSamplesToBuffer = psEnc->sCmn.frame_length - psEnc->sCmn.inputBufIx;
@@ -295,7 +244,7 @@
/* Copy to buffer */
SKP_memcpy( &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], samplesIn, nSamplesFromInput * sizeof( SKP_int16 ) );
} else {
- nSamplesToBuffer = SKP_min( nSamplesToBuffer, 10 * input_10ms * psEnc->sCmn.fs_kHz );
+ nSamplesToBuffer = SKP_min( nSamplesToBuffer, 10 * nBlocksOf10ms * psEnc->sCmn.fs_kHz );
nSamplesFromInput = SKP_DIV32_16( nSamplesToBuffer * psEnc->sCmn.API_fs_Hz, psEnc->sCmn.fs_kHz * 1000 );
/* Resample and write to buffer */
ret += SKP_Silk_resampler( &psEnc->sCmn.resampler_state, &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], samplesIn, nSamplesFromInput );
@@ -323,9 +272,11 @@
}
}
- if( psEnc->sCmn.useDTX && psEnc->sCmn.inDTX ) {
- /* DTX */
- *nBytesOut = 0;
+ if( prefillFlag ) {
+ encControl->payloadSize_ms = tmp_payloadSize_ms;
+ encControl->complexity = tmp_complexity;
+ ret = process_enc_control_struct( psEnc, encControl );
+ psEnc->sCmn.prefillFlag = 0;
}
return ret;
--- a/src_common/SKP_Silk_encode_indices.c
+++ b/src_common/SKP_Silk_encode_indices.c
@@ -39,8 +39,13 @@
{
SKP_int i, k, condCoding, typeOffset;
SKP_int encode_absolute_lagIndex, delta_lagIndex;
- const SKP_Silk_NLSF_CB_struct *psNLSF_CB;
+ SKP_int16 ec_ix[ MAX_LPC_ORDER ];
+ SKP_uint8 pred_Q8[ MAX_LPC_ORDER ];
const SideInfoIndices *psIndices;
+#if SAVE_ALL_INTERNAL_DATA
+ SKP_int nBytes_lagIndex, nBytes_contourIndex, nBytes_LTP;
+ SKP_int nBytes_after, nBytes_before;
+#endif
if( FrameIndex > 0 && ( encode_LBRR == 0 || psEncC->LBRR_flags[ FrameIndex - 1 ] == 1 ) ) {
condCoding = 1;
@@ -54,11 +59,6 @@
psIndices = &psEncC->indices;
}
-#ifdef SAVE_ALL_INTERNAL_DATA
- SKP_int nBytes_lagIndex, nBytes_contourIndex, nBytes_LTP;
- SKP_int nBytes_after, nBytes_before;
-#endif
-
/*******************************************/
/* Encode signal type and quantizer offset */
/*******************************************/
@@ -107,15 +107,23 @@
#ifdef SAVE_ALL_INTERNAL_DATA
nBytes_before = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
#endif
- /* Range encoding of the NLSF path */
- psNLSF_CB = psEncC->psNLSF_CB[ 1 - ( psIndices->signalType >> 1 ) ];
- for( i = 0; i < psNLSF_CB->nStages; i++ ) {
- SKP_assert( 0 <= psIndices->NLSFIndices[ i ] && psIndices->NLSFIndices[ i ] < psNLSF_CB->CBStages[ i ].nVectors );
- ec_enc_icdf( psRangeEnc, psIndices->NLSFIndices[ i ], psNLSF_CB->StartPtr[ i ], 8 );
+ ec_enc_icdf( psRangeEnc, psIndices->NLSFIndices[ 0 ], &psEncC->psNLSF_CB->CB1_iCDF[ ( psIndices->signalType >> 1 ) * psEncC->psNLSF_CB->nVectors ], 8 );
+ SKP_Silk_NLSF_unpack( ec_ix, pred_Q8, psEncC->psNLSF_CB, psIndices->NLSFIndices[ 0 ] );
+ SKP_assert( psEncC->psNLSF_CB->order == psEncC->predictLPCOrder );
+ for( i = 0; i < psEncC->psNLSF_CB->order; i++ ) {
+ if( psIndices->NLSFIndices[ i+1 ] >= NLSF_QUANT_MAX_AMPLITUDE ) {
+ ec_enc_icdf( psRangeEnc, 2 * NLSF_QUANT_MAX_AMPLITUDE, &psEncC->psNLSF_CB->ec_iCDF[ ec_ix[ i ] ], 8 );
+ ec_enc_icdf( psRangeEnc, psIndices->NLSFIndices[ i+1 ] - NLSF_QUANT_MAX_AMPLITUDE, SKP_Silk_NLSF_EXT_iCDF, 8 );
+ } else if( psIndices->NLSFIndices[ i+1 ] <= -NLSF_QUANT_MAX_AMPLITUDE ) {
+ ec_enc_icdf( psRangeEnc, 0, &psEncC->psNLSF_CB->ec_iCDF[ ec_ix[ i ] ], 8 );
+ ec_enc_icdf( psRangeEnc, -psIndices->NLSFIndices[ i+1 ] - NLSF_QUANT_MAX_AMPLITUDE, SKP_Silk_NLSF_EXT_iCDF, 8 );
+ } else {
+ ec_enc_icdf( psRangeEnc, psIndices->NLSFIndices[ i+1 ] + NLSF_QUANT_MAX_AMPLITUDE, &psEncC->psNLSF_CB->ec_iCDF[ ec_ix[ i ] ], 8 );
+ }
}
+ /* Encode NLSF interpolation factor */
if( psEncC->nb_subfr == MAX_NB_SUBFR ) {
- /* Encode NLSF interpolation factor */
SKP_assert( psEncC->useInterpolatedNLSFs == 1 || psIndices->NLSFInterpCoef_Q2 == ( 1 << 2 ) );
SKP_assert( psIndices->NLSFInterpCoef_Q2 >= 0 && psIndices->NLSFInterpCoef_Q2 < 5 );
ec_enc_icdf( psRangeEnc, psIndices->NLSFInterpCoef_Q2, SKP_Silk_NLSF_interpolation_factor_iCDF, 8 );
@@ -122,7 +130,7 @@
}
#ifdef SAVE_ALL_INTERNAL_DATA
- DEBUG_STORE_DATA( lsf_interpol.dat, &psEncCtrlC->NLSFInterpCoef_Q2, sizeof(int) );
+ DEBUG_STORE_DATA( lsf_interpol.dat, &psIndices->NLSFInterpCoef_Q2, sizeof(int) );
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 ) );
--- a/src_common/SKP_Silk_interpolate.c
+++ b/src_common/SKP_Silk_interpolate.c
@@ -29,9 +29,9 @@
/* Interpolate two vectors */
void SKP_Silk_interpolate(
- SKP_int xi[ MAX_LPC_ORDER ], /* O interpolated vector */
- const SKP_int x0[ MAX_LPC_ORDER ], /* I first vector */
- const SKP_int x1[ MAX_LPC_ORDER ], /* I second vector */
+ SKP_int16 xi[ MAX_LPC_ORDER ], /* O interpolated vector */
+ const SKP_int16 x0[ MAX_LPC_ORDER ], /* I first vector */
+ const SKP_int16 x1[ MAX_LPC_ORDER ], /* I second vector */
const SKP_int ifact_Q2, /* I interp. factor, weight on 2nd vector */
const SKP_int d /* I number of parameters */
)
@@ -42,6 +42,6 @@
SKP_assert( ifact_Q2 <= 4 );
for( i = 0; i < d; i++ ) {
- xi[ i ] = ( SKP_int )( ( SKP_int32 )x0[ i ] + SKP_RSHIFT( SKP_MUL( ( SKP_int32 )x1[ i ] - ( SKP_int32 )x0[ i ], ifact_Q2 ), 2 ) );
+ xi[ i ] = ( SKP_int16 )SKP_ADD_RSHIFT( x0[ i ], SKP_SMULBB( x1[ i ] - x0[ i ], ifact_Q2 ), 2 );
}
}
--- a/src_common/SKP_Silk_main.h
+++ b/src_common/SKP_Silk_main.h
@@ -122,17 +122,17 @@
/* Convert NLSF parameters to stable AR prediction filter coefficients */
void SKP_Silk_NLSF2A_stable(
SKP_int16 pAR_Q12[ MAX_LPC_ORDER ], /* O Stabilized AR coefs [LPC_order] */
- const SKP_int pNLSF[ MAX_LPC_ORDER ], /* I NLSF vector [LPC_order] */
+ const SKP_int16 pNLSF[ MAX_LPC_ORDER ], /* I NLSF vector [LPC_order] */
const SKP_int LPC_order /* I LPC/LSF order */
);
/* Interpolate two vectors */
void SKP_Silk_interpolate(
- SKP_int xi[ MAX_LPC_ORDER ], /* O interpolated vector */
- const SKP_int x0[ MAX_LPC_ORDER ], /* I first vector */
- const SKP_int x1[ MAX_LPC_ORDER ], /* I second vector */
- const SKP_int ifact_Q2, /* I interp. factor, weight on 2nd vector */
- const SKP_int d /* I number of parameters */
+ SKP_int16 xi[ MAX_LPC_ORDER ], /* O interpolated vector */
+ const SKP_int16 x0[ MAX_LPC_ORDER ], /* I first vector */
+ const SKP_int16 x1[ MAX_LPC_ORDER ], /* I second vector */
+ const SKP_int ifact_Q2, /* I interp. factor, weight on 2nd vector */
+ const SKP_int d /* I number of parameters */
);
/* LTP tap quantizer */
@@ -232,7 +232,7 @@
/* Start by setting transition_frame_no = 1; */
void SKP_Silk_LP_variable_cutoff(
SKP_Silk_LP_state *psLP, /* I/O LP filter state */
- SKP_int16 *signal, /* I/O Low-pass filtered output signal */
+ SKP_int16 *signal, /* I/O Low-pass filtered output signal */
const SKP_int frame_length /* I Frame length */
);
#endif
@@ -246,53 +246,64 @@
/******************/
/* NLSF Quantizer */
/******************/
-/* Limit, stabilize, convert and quantize NLSFs. */
+/* Limit, stabilize, convert and quantize NLSFs */
void SKP_Silk_process_NLSFs(
SKP_Silk_encoder_state *psEncC, /* I/O Encoder state */
SKP_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ], /* O Prediction coefficients */
- SKP_int pNLSF_Q15[ MAX_LPC_ORDER ], /* I/O Normalized LSFs (quant out) (0 - (2^15-1)) */
- const SKP_int prev_NLSFq_Q15[ MAX_LPC_ORDER ] /* I Previous Normalized LSFs (0 - (2^15-1)) */
+ SKP_int16 pNLSF_Q15[ MAX_LPC_ORDER ], /* I/O Normalized LSFs (quant out) (0 - (2^15-1)) */
+ const SKP_int16 prev_NLSFq_Q15[ MAX_LPC_ORDER ] /* I Previous Normalized LSFs (0 - (2^15-1)) */
);
-/* NLSF vector encoder */
-void SKP_Silk_NLSF_MSVQ_encode(
- SKP_int8 *NLSFIndices, /* O Codebook path vector [ CB_STAGES ] */
- SKP_int *pNLSF_Q15, /* I/O Quantized NLSF vector [ LPC_ORDER ] */
+SKP_int32 SKP_Silk_NLSF_encode( /* O Returns RD value in Q25 */
+ SKP_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */
+ SKP_int16 *pNLSF_Q15, /* I/O Quantized NLSF vector [ LPC_ORDER ] */
const SKP_Silk_NLSF_CB_struct *psNLSF_CB, /* I Codebook object */
- const SKP_int *pNLSF_q_Q15_prev, /* I Prev. quantized NLSF vector [LPC_ORDER] */
- const SKP_int *pW_Q5, /* I NLSF weight vector [ LPC_ORDER ] */
- const SKP_int NLSF_mu_Q15, /* I Rate weight for the RD optimization */
- const SKP_int NLSF_mu_fluc_red_Q16, /* I Fluctuation reduction error weight */
- const SKP_int NLSF_MSVQ_Survivors, /* I Max survivors from each stage */
- const SKP_int LPC_order, /* I LPC order */
- const SKP_int deactivate_fluc_red /* I Deactivate fluctuation reduction */
+ const SKP_int16 *pW_Q5, /* I NLSF weight vector [ LPC_ORDER ] */
+ const SKP_int NLSF_mu_Q20, /* I Rate weight for the RD optimization */
+ const SKP_int nSurvivors, /* I Max survivors after first stage */
+ const SKP_int signalType /* I Signal type: 0/1/2 */
);
-/* Rate-Distortion calculations for multiple input data vectors */
-void SKP_Silk_NLSF_VQ_rate_distortion(
- SKP_int32 *pRD_Q19, /* O Rate-distortion values [psNLSF_CBS->nVectors*N] */
- const SKP_Silk_NLSF_CBS *psNLSF_CBS, /* I NLSF codebook stage struct */
- const SKP_int16 *in_Q15, /* I Input vectors to be quantized */
- const SKP_int *w_Q5, /* I Weight vector */
- const SKP_int32 *rate_acc_Q4, /* I Accumulated rates from previous stage */
- const SKP_int mu_Q15, /* I Weight between weighted error and rate */
- const SKP_int N, /* I Number of input vectors to be quantized */
- const SKP_int stage, /* I Stage number */
- const SKP_int LPC_order /* I LPC order */
+/* Compute quantization errors for an LPC_order element input vector for a VQ codebook */
+void SKP_Silk_NLSF_VQ(
+ SKP_int32 err_Q26[], /* O Quantization errors [K] */
+ const SKP_int16 in_Q15[], /* I Input vectors to be quantized [LPC_order] */
+ const SKP_uint8 pCB_Q8[], /* I Codebook vectors [K*LPC_order] */
+ const SKP_int K, /* I Number of codebook vectors */
+ const SKP_int LPC_order /* I Number of LPCs */
);
-/* Compute weighted quantization errors for an LPC_order element input vector, over one codebook stage */
-void SKP_Silk_NLSF_VQ_sum_error(
- SKP_int32 *err_Q19, /* O Weighted quantization errors [N*K] */
- const SKP_int16 *in_Q15, /* I Input vectors to be quantized [N*LPC_order] */
- const SKP_int *w_Q5, /* I Weighting vectors [N*LPC_order] */
- const SKP_int8 *pCB_Q9, /* I Codebook vectors [K*LPC_order] */
- const SKP_int N, /* I Number of input vectors */
- const SKP_int K, /* I Number of codebook vectors */
- const SKP_int stage, /* I Stage number */
- const SKP_int LPC_order /* I Number of LPCs */
+/* Delayed-decision quantizer for NLSF residuals */
+SKP_int32 SKP_Silk_NLSF_del_dec_quant( /* O Returns RD value in Q25 */
+ SKP_int8 indices[], /* O Quantization indices [ order ] */
+ const SKP_int16 x_Q10[], /* I Input [ order ] */
+ const SKP_int16 w_Q5[], /* I Weights [ order ] */
+ const SKP_uint8 pred_coef_Q8[], /* I Backward predictor coefs [ order ] */
+ const SKP_int16 ec_ix[], /* I Indices to entropy coding tables [ order ] */
+ const SKP_uint8 ec_rates_Q5[], /* I Rates [] */
+ const SKP_int quant_step_size_Q16, /* I Quantization step size */
+ const SKP_int16 inv_quant_step_size_Q6, /* I Inverse quantization step size */
+ const SKP_int32 mu_Q20, /* I R/D tradeoff */
+ const SKP_int16 order /* I Number of input values */
);
+/* Unpack predictor values and indices for entropy coding tables */
+void SKP_Silk_NLSF_unpack(
+ SKP_int16 ec_ix[], /* O Indices to entropy tales [ LPC_ORDER ] */
+ SKP_uint8 pred_Q8[], /* O LSF predictor [ LPC_ORDER ] */
+ const SKP_Silk_NLSF_CB_struct *psNLSF_CB, /* I Codebook object */
+ const SKP_int CB1_index /* I Index of vector in first LSF codebook */
+);
+
+/***********************/
+/* NLSF vector decoder */
+/***********************/
+void SKP_Silk_NLSF_decode(
+ SKP_int16 *pNLSF_Q15, /* O Quantized NLSF vector [ LPC_ORDER ] */
+ SKP_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */
+ const SKP_Silk_NLSF_CB_struct *psNLSF_CB /* I Codebook object */
+);
+
/****************************************************/
/* Decoder Functions */
/****************************************************/
@@ -326,7 +337,7 @@
SKP_int lostFlag /* I 0: no loss, 1 loss, 2 decode fec */
);
-/* Decode LBRR side info and excitation */
+/* Decode LBRR side info and excitation */
void SKP_Silk_LBRR_extract(
SKP_Silk_decoder_state *psDec, /* I/O State */
ec_dec *psRangeDec /* I/O Compressor data structure */
@@ -354,14 +365,6 @@
const SKP_int pulses[ MAX_FRAME_LENGTH ] /* I Pulse signal */
);
-/* NLSF vector decoder */
-void SKP_Silk_NLSF_MSVQ_decode(
- SKP_int *pNLSF_Q15, /* O Pointer to decoded output [LPC_ORDER x 1] */
- const SKP_Silk_NLSF_CB_struct *psNLSF_CB, /* I Pointer to NLSF codebook struct */
- const SKP_int8 *NLSFIndices, /* I Pointer to NLSF indices [nStages x 1] */
- const SKP_int LPC_order /* I LPC order */
-);
-
/* Decode quantization indices of excitation (Shell coding) */
void SKP_Silk_decode_pulses(
ec_dec *psRangeDec, /* I/O Compressor data structure */
@@ -380,7 +383,7 @@
SKP_Silk_decoder_state *psDec /* I/O Decoder state */
);
-/* Updates CNG estimate, and applies the CNG when packet was lost */
+/* Updates CNG estimate, and applies the CNG when packet was lost */
void SKP_Silk_CNG(
SKP_Silk_decoder_state *psDec, /* I/O Decoder state */
SKP_Silk_decoder_control *psDecCtrl, /* I/O Decoder control */
--- a/src_common/SKP_Silk_process_NLSFs.c
+++ b/src_common/SKP_Silk_process_NLSFs.c
@@ -27,21 +27,20 @@
#include "SKP_Silk_main.h"
-/* Limit, stabilize, convert and quantize NLSFs. */
+/* Limit, stabilize, convert and quantize NLSFs */
void SKP_Silk_process_NLSFs(
SKP_Silk_encoder_state *psEncC, /* I/O Encoder state */
SKP_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ], /* O Prediction coefficients */
- SKP_int pNLSF_Q15[ MAX_LPC_ORDER ], /* I/O Normalized LSFs (quant out) (0 - (2^15-1)) */
- const SKP_int prev_NLSFq_Q15[ MAX_LPC_ORDER ] /* I Previous Normalized LSFs (0 - (2^15-1)) */
+ SKP_int16 pNLSF_Q15[ MAX_LPC_ORDER ], /* I/O Normalized LSFs (quant out) (0 - (2^15-1)) */
+ const SKP_int16 prev_NLSFq_Q15[ MAX_LPC_ORDER ] /* I Previous Normalized LSFs (0 - (2^15-1)) */
)
{
SKP_int i, doInterpolate;
- SKP_int pNLSFW_Q5[ MAX_LPC_ORDER ];
- SKP_int NLSF_mu_Q15, NLSF_mu_fluc_red_Q16;
+ SKP_int16 pNLSFW_Q5[ MAX_LPC_ORDER ];
+ SKP_int NLSF_mu_Q20;
SKP_int32 i_sqr_Q15;
- SKP_int pNLSF0_temp_Q15[ MAX_LPC_ORDER ];
- SKP_int pNLSFW0_temp_Q5[ MAX_LPC_ORDER ];
- const SKP_Silk_NLSF_CB_struct *psNLSF_CB;
+ SKP_int16 pNLSF0_temp_Q15[ MAX_LPC_ORDER ];
+ SKP_int16 pNLSFW0_temp_Q5[ MAX_LPC_ORDER ];
SKP_assert( psEncC->speech_activity_Q8 >= 0 );
SKP_assert( psEncC->speech_activity_Q8 <= SKP_FIX_CONST( 1.0, 8 ) );
@@ -49,23 +48,11 @@
/***********************/
/* Calculate mu values */
/***********************/
- if( psEncC->indices.signalType == TYPE_VOICED ) {
- /* NLSF_mu = 0.002f - 0.001f * psEnc->speech_activity; */
- /* NLSF_mu_fluc_red = 0.1f - 0.05f * psEnc->speech_activity; */
- NLSF_mu_Q15 = SKP_SMLAWB( SKP_FIX_CONST( 0.002, 15 ), SKP_FIX_CONST( -0.001, 23 ), psEncC->speech_activity_Q8 );
- NLSF_mu_fluc_red_Q16 = SKP_SMLAWB( SKP_FIX_CONST( 0.1, 16 ), SKP_FIX_CONST( -0.05, 24 ), psEncC->speech_activity_Q8 );
- } else {
- /* NLSF_mu = 0.005f - 0.004f * psEnc->speech_activity; */
- /* NLSF_mu_fluc_red = 0.2f - 0.1f * psEnc->speech_activity - 0.1f * psEncCtrl->sparseness; */
- NLSF_mu_Q15 = SKP_SMLAWB( SKP_FIX_CONST( 0.005, 15 ), SKP_FIX_CONST( -0.004, 23 ), psEncC->speech_activity_Q8 );
- NLSF_mu_fluc_red_Q16 = SKP_SMLAWB( SKP_FIX_CONST( 0.15, 16 ), SKP_FIX_CONST( -0.1, 24 ), psEncC->speech_activity_Q8 );
- }
- SKP_assert( NLSF_mu_Q15 >= 0 );
- SKP_assert( NLSF_mu_Q15 <= SKP_FIX_CONST( 0.005, 15 ) );
- SKP_assert( NLSF_mu_fluc_red_Q16 >= 0 );
- SKP_assert( NLSF_mu_fluc_red_Q16 <= SKP_FIX_CONST( 0.15, 16 ) );
+ /* NLSF_mu = 0.003 - 0.0015 * psEnc->speech_activity; */
+ NLSF_mu_Q20 = SKP_SMLAWB( SKP_FIX_CONST( 0.003, 20 ), SKP_FIX_CONST( -0.0015, 28 ), psEncC->speech_activity_Q8 );
- NLSF_mu_Q15 = SKP_max( NLSF_mu_Q15, 1 );
+ SKP_assert( NLSF_mu_Q20 > 0 );
+ SKP_assert( NLSF_mu_Q20 <= SKP_FIX_CONST( 0.003, 20 ) );
/* Calculate NLSF weights */
SKP_Silk_NLSF_VQ_weights_laroia( pNLSFW_Q5, pNLSF_Q15, psEncC->predictLPCOrder );
@@ -89,14 +76,10 @@
}
}
- /* Set pointer to the NLSF codebook for the current signal type and LPC order */
- psNLSF_CB = psEncC->psNLSF_CB[ 1 - ( psEncC->indices.signalType >> 1 ) ];
-
- /* Quantize NLSF parameters given the trained NLSF codebooks */
- TIC(MSVQ_encode_FIX)
- SKP_Silk_NLSF_MSVQ_encode( psEncC->indices.NLSFIndices, pNLSF_Q15, psNLSF_CB, prev_NLSFq_Q15, pNLSFW_Q5, NLSF_mu_Q15,
- NLSF_mu_fluc_red_Q16, psEncC->NLSF_MSVQ_Survivors, psEncC->predictLPCOrder, psEncC->first_frame_after_reset );
- TOC(MSVQ_encode_FIX)
+ TIC(NLSF_encode)
+ SKP_Silk_NLSF_encode( psEncC->indices.NLSFIndices, pNLSF_Q15, psEncC->psNLSF_CB, pNLSFW_Q5,
+ NLSF_mu_Q20, psEncC->NLSF_MSVQ_Survivors, psEncC->indices.signalType );
+ TOC(NLSF_encode)
/* Convert quantized NLSFs back to LPC coefficients */
SKP_Silk_NLSF2A_stable( PredCoef_Q12[ 1 ], pNLSF_Q15, psEncC->predictLPCOrder );
--- a/src_common/SKP_Silk_setup.h
+++ b/src_common/SKP_Silk_setup.h
@@ -105,7 +105,7 @@
SKP_assert( psEncC->warping_Q16 <= 32767 );
SKP_assert( psEncC->la_shape <= LA_SHAPE_MAX );
SKP_assert( psEncC->shapeWinLength <= SHAPE_LPC_WIN_MAX );
- SKP_assert( psEncC->NLSF_MSVQ_Survivors <= MAX_NLSF_MSVQ_SURVIVORS );
+ SKP_assert( psEncC->NLSF_MSVQ_Survivors <= NLSF_VQ_MAX_SURVIVORS );
return( ret );
}
--- a/src_common/SKP_Silk_structs.h
+++ b/src_common/SKP_Silk_structs.h
@@ -28,6 +28,8 @@
#ifndef SKP_SILK_STRUCTS_H
#define SKP_SILK_STRUCTS_H
+#include "config.h"
+
#include "SKP_Silk_typedef.h"
#include "SKP_Silk_SigProc_FIX.h"
#include "SKP_Silk_define.h"
@@ -79,29 +81,25 @@
SKP_int mode; /* Operating mode, <0: switch down, >0: switch up; 0: do nothing */
} SKP_Silk_LP_state;
-/* Structure for one stage of MSVQ */
+/* Structure containing NLSF codebook */
typedef struct {
- const SKP_int32 nVectors;
- const SKP_int8 *CB_NLSF_Q8;
- const SKP_uint8 *Rates_Q4;
-} SKP_Silk_NLSF_CBS;
-
-/* Structure containing NLSF MSVQ codebook */
-typedef struct {
- const SKP_int32 nStages;
-
- /* Fields for (de)quantizing */
- const SKP_Silk_NLSF_CBS *CBStages;
- const SKP_int *NDeltaMin_Q15;
-
- /* Fields for range (de)coding */
- const SKP_uint8 * const *StartPtr;
+ const SKP_int16 nVectors;
+ const SKP_int16 order;
+ const SKP_int16 quantStepSize_Q16;
+ const SKP_int16 invQuantStepSize_Q6;
+ const SKP_uint8 *CB1_NLSF_Q8;
+ const SKP_uint8 *CB1_iCDF;
+ const SKP_uint8 *pred_Q8;
+ const SKP_uint8 *ec_sel;
+ const SKP_uint8 *ec_iCDF;
+ const SKP_uint8 *ec_Rates_Q5;
+ const SKP_int16 *deltaMin_Q15;
} SKP_Silk_NLSF_CB_struct;
typedef struct {
SKP_int8 GainsIndices[ MAX_NB_SUBFR ];
SKP_int8 LTPIndex[ MAX_NB_SUBFR ];
- SKP_int8 NLSFIndices[ NLSF_MSVQ_MAX_CB_STAGES ];
+ SKP_int8 NLSFIndices[ MAX_LPC_ORDER + 1 ];
SKP_int16 lagIndex;
SKP_int8 contourIndex;
SKP_int8 signalType;
@@ -116,15 +114,13 @@
/* Encoder state */
/********************************/
typedef struct {
-#if HIGH_PASS_INPUT
SKP_int32 In_HP_State[ 2 ]; /* High pass filter state */
SKP_int32 variable_HP_smth1_Q15; /* State of first smoother */
SKP_int32 variable_HP_smth2_Q15; /* State of second smoother */
-#endif
SKP_Silk_LP_state sLP; /* Low pass filter state */
SKP_Silk_VAD_state sVAD; /* Voice activity detector state */
SKP_Silk_nsq_state sNSQ; /* Noise Shape Quantizer State */
- SKP_int prev_NLSFq_Q15[ MAX_LPC_ORDER ];/* Previously quantized NLSF vector */
+ SKP_int16 prev_NLSFq_Q15[ MAX_LPC_ORDER ];/* Previously quantized NLSF vector */
SKP_int speech_activity_Q8; /* Speech activity */
SKP_int8 LBRRprevLastGainIndex;
SKP_int8 prevSignalType;
@@ -163,9 +159,10 @@
SKP_int warping_Q16; /* Warping parameter for warped noise shaping */
SKP_int useCBR; /* Flag to enable constant bitrate */
SKP_int prev_nBits; /* Use to track bits used by each frame in packet */
+ SKP_int prefillFlag; /* Flag to indicate that only buffers are prefilled, no coding */
const SKP_uint8 *pitch_lag_low_bits_iCDF; /* Pointer to iCDF table for low bits of pitch lag index */
const SKP_uint8 *pitch_contour_iCDF; /* Pointer to iCDF table for pitch contour index */
- const SKP_Silk_NLSF_CB_struct *psNLSF_CB[ 2 ]; /* Pointers to voiced/unvoiced NLSF codebooks */
+ const SKP_Silk_NLSF_CB_struct *psNLSF_CB; /* Pointer to NLSF codebook */
SKP_int input_quality_bands_Q15[ VAD_N_BANDS ];
SKP_int input_tilt_Q15;
@@ -223,7 +220,7 @@
/* Struct for CNG */
typedef struct {
SKP_int32 CNG_exc_buf_Q10[ MAX_FRAME_LENGTH ];
- SKP_int CNG_smth_NLSF_Q15[ MAX_LPC_ORDER ];
+ SKP_int16 CNG_smth_NLSF_Q15[ MAX_LPC_ORDER ];
SKP_int32 CNG_synth_state[ MAX_LPC_ORDER ];
SKP_int32 CNG_smth_Gain_Q16;
SKP_int32 rand_seed;
@@ -251,7 +248,7 @@
SKP_int subfr_length; /* Subframe length (samples) */
SKP_int ltp_mem_length; /* Length of LTP memory */
SKP_int LPC_order; /* LPC order */
- SKP_int prevNLSF_Q15[ MAX_LPC_ORDER ]; /* Used to interpolate LSFs */
+ SKP_int16 prevNLSF_Q15[ MAX_LPC_ORDER ]; /* Used to interpolate LSFs */
SKP_int first_frame_after_reset; /* Flag for deactivating NLSF interp. and fluc. reduction after resets */
const SKP_uint8 *pitch_lag_low_bits_iCDF; /* Pointer to iCDF table for low bits of pitch lag index */
const SKP_uint8 *pitch_contour_iCDF; /* Pointer to iCDF table for pitch contour index */
@@ -270,7 +267,7 @@
SKP_Silk_resampler_state_struct resampler_state;
- const SKP_Silk_NLSF_CB_struct *psNLSF_CB[ 2 ]; /* Pointers to voiced/unvoiced NLSF codebooks */
+ const SKP_Silk_NLSF_CB_struct *psNLSF_CB; /* Pointer to NLSF codebook */
/* Quantization indices */
SideInfoIndices indices;
--- a/src_common/SKP_Silk_tables.h
+++ b/src_common/SKP_Silk_tables.h
@@ -73,6 +73,8 @@
extern const SKP_uint8 SKP_Silk_uniform6_iCDF[ 6 ]; /* 6 */
extern const SKP_uint8 SKP_Silk_uniform8_iCDF[ 8 ]; /* 8 */
+extern const SKP_uint8 SKP_Silk_NLSF_EXT_iCDF[ 7 ]; /* 7 */
+
extern const SKP_uint8 SKP_Silk_LTP_per_index_iCDF[ 3 ]; /* 3 */
extern const SKP_uint8 * const SKP_Silk_LTP_gain_iCDF_ptrs[ NB_LTP_CBKS ]; /* 3 */
extern const SKP_uint8 * const SKP_Silk_LTP_gain_BITS_Q5_ptrs[ NB_LTP_CBKS ]; /* 3 */
@@ -90,9 +92,8 @@
extern const SKP_uint8 SKP_Silk_NLSF_interpolation_factor_iCDF[ 5 ]; /* 5 */
-/* NLSF codebooks */
-extern const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB0_16, SKP_Silk_NLSF_CB1_16;
-extern const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB0_10, SKP_Silk_NLSF_CB1_10;
+extern const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB_WB;
+extern const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB_NB_MB;
/* Piece-wise linear mapping from bitrate in kbps to coding quality in dB SNR */
extern const SKP_int32 TargetRate_table_NB[ TARGET_RATE_TAB_SZ ];
--- /dev/null
+++ b/src_common/SKP_Silk_tables_NLSF_CB_NB_MB.c
@@ -1,0 +1,155 @@
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved.
+Redistribution and use in source and binary forms, with or without
+modification, (subject to the limitations in the disclaimer below)
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific
+contributors, may be used to endorse or promote products derived from
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_structs.h"
+
+const SKP_uint8 SKP_Silk_NLSF_CB1_NB_MB_Q8[ 320 ] = {
+ 12, 35, 60, 83, 108, 132, 157, 180,
+ 206, 228, 15, 32, 55, 77, 101, 125,
+ 151, 175, 201, 225, 19, 42, 66, 89,
+ 114, 137, 162, 184, 209, 230, 12, 25,
+ 50, 72, 97, 120, 147, 172, 200, 223,
+ 26, 44, 69, 90, 114, 135, 159, 180,
+ 205, 225, 13, 22, 53, 80, 106, 130,
+ 156, 180, 205, 228, 15, 25, 44, 64,
+ 90, 115, 142, 168, 196, 222, 19, 24,
+ 62, 82, 100, 120, 145, 168, 190, 214,
+ 22, 31, 50, 79, 103, 120, 151, 170,
+ 203, 227, 21, 29, 45, 65, 106, 124,
+ 150, 171, 196, 224, 30, 49, 75, 97,
+ 121, 142, 165, 186, 209, 229, 19, 25,
+ 52, 70, 93, 116, 143, 166, 192, 219,
+ 26, 34, 62, 75, 97, 118, 145, 167,
+ 194, 217, 25, 33, 56, 70, 91, 113,
+ 143, 165, 196, 223, 21, 34, 51, 72,
+ 97, 117, 145, 171, 196, 222, 20, 29,
+ 50, 67, 90, 117, 144, 168, 197, 221,
+ 22, 31, 48, 66, 95, 117, 146, 168,
+ 196, 222, 24, 33, 51, 77, 116, 134,
+ 158, 180, 200, 224, 21, 28, 70, 87,
+ 106, 124, 149, 170, 194, 217, 26, 33,
+ 53, 64, 83, 117, 152, 173, 204, 225,
+ 27, 34, 65, 95, 108, 129, 155, 174,
+ 210, 225, 20, 26, 72, 99, 113, 131,
+ 154, 176, 200, 219, 34, 43, 61, 78,
+ 93, 114, 155, 177, 205, 229, 23, 29,
+ 54, 97, 124, 138, 163, 179, 209, 229,
+ 30, 38, 56, 89, 118, 129, 158, 178,
+ 200, 231, 21, 29, 49, 63, 85, 111,
+ 142, 163, 193, 222, 27, 48, 77, 103,
+ 133, 158, 179, 196, 215, 232, 29, 47,
+ 74, 99, 124, 151, 176, 198, 220, 237,
+ 33, 42, 61, 76, 93, 121, 155, 174,
+ 207, 225, 29, 53, 87, 112, 136, 154,
+ 170, 188, 208, 227, 24, 30, 52, 84,
+ 131, 150, 166, 186, 203, 229, 37, 48,
+ 64, 84, 104, 118, 156, 177, 201, 230
+};
+
+const SKP_uint8 SKP_Silk_NLSF_CB1_iCDF_NB_MB[ 64 ] = {
+ 212, 178, 148, 129, 108, 96, 85, 82,
+ 79, 77, 61, 59, 57, 56, 51, 49,
+ 48, 45, 42, 41, 40, 38, 36, 34,
+ 31, 30, 21, 12, 10, 3, 1, 0,
+ 255, 245, 244, 236, 233, 225, 217, 203,
+ 190, 176, 175, 161, 149, 136, 125, 114,
+ 102, 91, 81, 71, 60, 52, 43, 35,
+ 28, 20, 19, 18, 12, 11, 5, 0
+};
+
+const SKP_uint8 SKP_Silk_NLSF_CB2_SELECT_NB_MB[ 160 ] = {
+ 16, 0, 0, 0, 0, 99, 66, 36,
+ 36, 34, 36, 34, 34, 34, 34, 83,
+ 69, 36, 52, 34, 116, 102, 70, 68,
+ 68, 176, 102, 68, 68, 34, 65, 85,
+ 68, 84, 36, 116, 141, 152, 139, 170,
+ 132, 187, 184, 216, 137, 132, 249, 168,
+ 185, 139, 104, 102, 100, 68, 68, 178,
+ 218, 185, 185, 170, 244, 216, 187, 187,
+ 170, 244, 187, 187, 219, 138, 103, 155,
+ 184, 185, 137, 116, 183, 155, 152, 136,
+ 132, 217, 184, 184, 170, 164, 217, 171,
+ 155, 139, 244, 169, 184, 185, 170, 164,
+ 216, 223, 218, 138, 214, 143, 188, 218,
+ 168, 244, 141, 136, 155, 170, 168, 138,
+ 220, 219, 139, 164, 219, 202, 216, 137,
+ 168, 186, 246, 185, 139, 116, 185, 219,
+ 185, 138, 100, 100, 134, 100, 102, 34,
+ 68, 68, 100, 68, 168, 203, 221, 218,
+ 168, 167, 154, 136, 104, 70, 164, 246,
+ 171, 137, 139, 137, 155, 218, 219, 139
+};
+
+const SKP_uint8 SKP_Silk_NLSF_CB2_iCDF_NB_MB[ 72 ] = {
+ 255, 254, 253, 238, 14, 3, 2, 1,
+ 0, 255, 254, 252, 218, 35, 3, 2,
+ 1, 0, 255, 254, 250, 208, 59, 4,
+ 2, 1, 0, 255, 254, 246, 194, 71,
+ 10, 2, 1, 0, 255, 252, 236, 183,
+ 82, 8, 2, 1, 0, 255, 252, 235,
+ 180, 90, 17, 2, 1, 0, 255, 248,
+ 224, 171, 97, 30, 4, 1, 0, 255,
+ 254, 236, 173, 95, 37, 7, 1, 0
+};
+
+const SKP_uint8 SKP_Silk_NLSF_CB2_BITS_NB_MB_Q5[ 72 ] = {
+ 255, 255, 255, 131, 6, 145, 255, 255,
+ 255, 255, 255, 236, 93, 15, 96, 255,
+ 255, 255, 255, 255, 194, 83, 25, 71,
+ 221, 255, 255, 255, 255, 162, 73, 34,
+ 66, 162, 255, 255, 255, 210, 126, 73,
+ 43, 57, 173, 255, 255, 255, 201, 125,
+ 71, 48, 58, 130, 255, 255, 255, 166,
+ 110, 73, 57, 62, 104, 210, 255, 255,
+ 251, 123, 65, 55, 68, 100, 171, 255
+};
+
+const SKP_uint8 SKP_Silk_NLSF_PRED_NB_MB_Q8[ 18 ] = {
+ 179, 138, 140, 148, 151, 149, 153, 151,
+ 163, 116, 67, 82, 59, 92, 72, 100,
+ 89, 92
+};
+
+const SKP_int16 SKP_Silk_NLSF_DELTA_MIN_NB_MB_Q15[ 11 ] = {
+ 322, 3, 6, 3, 3, 3, 4, 3,
+ 3, 3, 461
+};
+
+const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB_NB_MB =
+{
+ 32,
+ 10,
+ SKP_FIX_CONST( 0.18, 16 ),
+ SKP_FIX_CONST( 1.0 / 0.18, 6 ),
+ SKP_Silk_NLSF_CB1_NB_MB_Q8,
+ SKP_Silk_NLSF_CB1_iCDF_NB_MB,
+ SKP_Silk_NLSF_PRED_NB_MB_Q8,
+ SKP_Silk_NLSF_CB2_SELECT_NB_MB,
+ SKP_Silk_NLSF_CB2_iCDF_NB_MB,
+ SKP_Silk_NLSF_CB2_BITS_NB_MB_Q5,
+ SKP_Silk_NLSF_DELTA_MIN_NB_MB_Q15,
+};
--- /dev/null
+++ b/src_common/SKP_Silk_tables_NLSF_CB_WB.c
@@ -1,0 +1,193 @@
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved.
+Redistribution and use in source and binary forms, with or without
+modification, (subject to the limitations in the disclaimer below)
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific
+contributors, may be used to endorse or promote products derived from
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#include "SKP_Silk_structs.h"
+
+const SKP_uint8 SKP_Silk_NLSF_CB1_WB_Q8[ 512 ] = {
+ 7, 23, 38, 54, 69, 85, 100, 116,
+ 131, 147, 162, 178, 193, 208, 223, 239,
+ 13, 25, 41, 55, 69, 83, 98, 112,
+ 127, 142, 157, 171, 187, 203, 220, 236,
+ 15, 21, 34, 51, 61, 78, 92, 106,
+ 126, 136, 152, 167, 185, 205, 225, 240,
+ 10, 21, 36, 50, 63, 79, 95, 110,
+ 126, 141, 157, 173, 189, 205, 221, 237,
+ 17, 20, 37, 51, 59, 78, 89, 107,
+ 123, 134, 150, 164, 184, 205, 224, 240,
+ 10, 15, 32, 51, 67, 81, 96, 112,
+ 129, 142, 158, 173, 189, 204, 220, 236,
+ 8, 21, 37, 51, 65, 79, 98, 113,
+ 126, 138, 155, 168, 179, 192, 209, 218,
+ 12, 15, 34, 55, 63, 78, 87, 108,
+ 118, 131, 148, 167, 185, 203, 219, 236,
+ 16, 19, 32, 36, 56, 79, 91, 108,
+ 118, 136, 154, 171, 186, 204, 220, 237,
+ 11, 28, 43, 58, 74, 89, 105, 120,
+ 135, 150, 165, 180, 196, 211, 226, 241,
+ 6, 16, 33, 46, 60, 75, 92, 107,
+ 123, 137, 156, 169, 185, 199, 214, 225,
+ 11, 19, 30, 44, 57, 74, 89, 105,
+ 121, 135, 152, 169, 186, 202, 218, 234,
+ 12, 19, 29, 46, 57, 71, 88, 100,
+ 120, 132, 148, 165, 182, 199, 216, 233,
+ 17, 23, 35, 46, 56, 77, 92, 106,
+ 123, 134, 152, 167, 185, 204, 222, 237,
+ 14, 17, 45, 53, 63, 75, 89, 107,
+ 115, 132, 151, 171, 188, 206, 221, 240,
+ 9, 16, 29, 40, 56, 71, 88, 103,
+ 119, 137, 154, 171, 189, 205, 222, 237,
+ 16, 19, 36, 48, 57, 76, 87, 105,
+ 118, 132, 150, 167, 185, 202, 218, 236,
+ 12, 17, 29, 54, 71, 81, 94, 104,
+ 126, 136, 149, 164, 182, 201, 221, 237,
+ 15, 28, 47, 62, 79, 97, 115, 129,
+ 142, 155, 168, 180, 194, 208, 223, 238,
+ 8, 14, 30, 45, 62, 78, 94, 111,
+ 127, 143, 159, 175, 192, 207, 223, 239,
+ 17, 30, 49, 62, 79, 92, 107, 119,
+ 132, 145, 160, 174, 190, 204, 220, 235,
+ 14, 19, 36, 45, 61, 76, 91, 108,
+ 121, 138, 154, 172, 189, 205, 222, 238,
+ 12, 18, 31, 45, 60, 76, 91, 107,
+ 123, 138, 154, 171, 187, 204, 221, 236,
+ 13, 17, 31, 43, 53, 70, 83, 103,
+ 114, 131, 149, 167, 185, 203, 220, 237,
+ 17, 22, 35, 42, 58, 78, 93, 110,
+ 125, 139, 155, 170, 188, 206, 224, 240,
+ 8, 15, 34, 50, 67, 83, 99, 115,
+ 131, 146, 162, 178, 193, 209, 224, 239,
+ 13, 16, 41, 66, 73, 86, 95, 111,
+ 128, 137, 150, 163, 183, 206, 225, 241,
+ 17, 25, 37, 52, 63, 75, 92, 102,
+ 119, 132, 144, 160, 175, 191, 212, 231,
+ 19, 31, 49, 65, 83, 100, 117, 133,
+ 147, 161, 174, 187, 200, 213, 227, 242,
+ 18, 31, 52, 68, 88, 103, 117, 126,
+ 138, 149, 163, 177, 192, 207, 223, 239,
+ 16, 29, 47, 61, 76, 90, 106, 119,
+ 133, 147, 161, 176, 193, 209, 224, 240,
+ 15, 21, 35, 50, 61, 73, 86, 97,
+ 110, 119, 129, 141, 175, 198, 218, 237
+};
+
+const SKP_uint8 SKP_Silk_NLSF_CB1_iCDF_WB[ 64 ] = {
+ 225, 204, 201, 184, 183, 175, 158, 154,
+ 153, 135, 119, 115, 113, 110, 109, 99,
+ 98, 95, 79, 68, 52, 50, 48, 45,
+ 43, 32, 31, 27, 18, 10, 3, 0,
+ 255, 251, 235, 230, 212, 201, 196, 182,
+ 167, 166, 163, 151, 138, 124, 110, 104,
+ 90, 78, 76, 70, 69, 57, 45, 34,
+ 24, 21, 11, 6, 5, 4, 3, 0
+};
+
+const SKP_uint8 SKP_Silk_NLSF_CB2_SELECT_WB[ 256 ] = {
+ 0, 0, 0, 0, 0, 0, 0, 1,
+ 100, 102, 102, 68, 68, 36, 34, 96,
+ 164, 107, 158, 185, 180, 185, 139, 102,
+ 64, 66, 36, 34, 34, 0, 1, 32,
+ 208, 139, 141, 191, 152, 185, 155, 104,
+ 96, 171, 104, 166, 102, 102, 102, 132,
+ 1, 0, 0, 0, 0, 16, 16, 0,
+ 80, 109, 78, 107, 185, 139, 103, 101,
+ 208, 212, 141, 139, 173, 153, 123, 103,
+ 36, 0, 0, 0, 0, 0, 0, 1,
+ 48, 0, 0, 0, 0, 0, 0, 32,
+ 68, 135, 123, 119, 119, 103, 69, 98,
+ 68, 103, 120, 118, 118, 102, 71, 98,
+ 134, 136, 157, 184, 182, 153, 139, 134,
+ 208, 168, 248, 75, 189, 143, 121, 107,
+ 32, 49, 34, 34, 34, 0, 17, 2,
+ 210, 235, 139, 123, 185, 137, 105, 134,
+ 98, 135, 104, 182, 100, 183, 171, 134,
+ 100, 70, 68, 70, 66, 66, 34, 131,
+ 64, 166, 102, 68, 36, 2, 1, 0,
+ 134, 166, 102, 68, 34, 34, 66, 132,
+ 212, 246, 158, 139, 107, 107, 87, 102,
+ 100, 219, 125, 122, 137, 118, 103, 132,
+ 114, 135, 137, 105, 171, 106, 50, 34,
+ 164, 214, 141, 143, 185, 151, 121, 103,
+ 192, 34, 0, 0, 0, 0, 0, 1,
+ 208, 109, 74, 187, 134, 249, 159, 137,
+ 102, 110, 154, 118, 87, 101, 119, 101,
+ 0, 2, 0, 36, 36, 66, 68, 35,
+ 96, 164, 102, 100, 36, 0, 2, 33,
+ 167, 138, 174, 102, 100, 84, 2, 2,
+ 100, 107, 120, 119, 36, 197, 24, 0
+};
+
+const SKP_uint8 SKP_Silk_NLSF_CB2_iCDF_WB[ 72 ] = {
+ 255, 254, 253, 244, 12, 3, 2, 1,
+ 0, 255, 254, 252, 224, 38, 3, 2,
+ 1, 0, 255, 254, 251, 209, 57, 4,
+ 2, 1, 0, 255, 254, 244, 195, 69,
+ 4, 2, 1, 0, 255, 251, 232, 184,
+ 84, 7, 2, 1, 0, 255, 254, 240,
+ 186, 86, 14, 2, 1, 0, 255, 254,
+ 239, 178, 91, 30, 5, 1, 0, 255,
+ 248, 227, 177, 100, 19, 2, 1, 0
+};
+
+const SKP_uint8 SKP_Silk_NLSF_CB2_BITS_WB_Q5[ 72 ] = {
+ 255, 255, 255, 156, 4, 154, 255, 255,
+ 255, 255, 255, 227, 102, 15, 92, 255,
+ 255, 255, 255, 255, 213, 83, 24, 72,
+ 236, 255, 255, 255, 255, 150, 76, 33,
+ 63, 214, 255, 255, 255, 190, 121, 77,
+ 43, 55, 185, 255, 255, 255, 245, 137,
+ 71, 43, 59, 139, 255, 255, 255, 255,
+ 131, 66, 50, 66, 107, 194, 255, 255,
+ 166, 116, 76, 55, 53, 125, 255, 255
+};
+
+const SKP_uint8 SKP_Silk_NLSF_PRED_WB_Q8[ 30 ] = {
+ 175, 148, 160, 176, 178, 173, 174, 164,
+ 177, 174, 196, 182, 198, 192, 182, 68,
+ 62, 66, 60, 72, 117, 85, 90, 118,
+ 136, 151, 142, 160, 142, 155
+};
+
+const SKP_int16 SKP_Silk_NLSF_DELTA_MIN_WB_Q15[ 17 ] = {
+ 121, 3, 42, 3, 3, 3, 5, 14,
+ 14, 10, 11, 3, 8, 9, 7, 3,
+ 347
+};
+
+const SKP_Silk_NLSF_CB_struct SKP_Silk_NLSF_CB_WB =
+{
+ 32,
+ 16,
+ SKP_FIX_CONST( 0.16, 16 ),
+ SKP_FIX_CONST( 1.0 / 0.16, 6 ),
+ SKP_Silk_NLSF_CB1_WB_Q8,
+ SKP_Silk_NLSF_CB1_iCDF_WB,
+ SKP_Silk_NLSF_PRED_WB_Q8,
+ SKP_Silk_NLSF_CB2_SELECT_WB,
+ SKP_Silk_NLSF_CB2_iCDF_WB,
+ SKP_Silk_NLSF_CB2_BITS_WB_Q5,
+ SKP_Silk_NLSF_DELTA_MIN_WB_Q15,
+};
--- a/src_common/SKP_Silk_tables_other.c
+++ b/src_common/SKP_Silk_tables_other.c
@@ -36,16 +36,16 @@
/* Piece-wise linear mapping from bitrate in kbps to coding quality in dB SNR */
const SKP_int32 TargetRate_table_NB[ TARGET_RATE_TAB_SZ ] = {
- 0, 8000, 9000, 11000, 13000, 17500, 25000, MAX_TARGET_RATE_BPS
+ 0, 8000, 9400, 11500, 13500, 17500, 25000, MAX_TARGET_RATE_BPS
};
const SKP_int32 TargetRate_table_MB[ TARGET_RATE_TAB_SZ ] = {
- 0, 10000, 12000, 14000, 17000, 23000, 33500, MAX_TARGET_RATE_BPS
+ 0, 9000, 11800, 14200, 17700, 23700, 34400, MAX_TARGET_RATE_BPS
};
const SKP_int32 TargetRate_table_WB[ TARGET_RATE_TAB_SZ ] = {
- 0, 11000, 14000, 17000, 21000, 27500, 41500, MAX_TARGET_RATE_BPS
+ 0, 10500, 14000, 17000, 21300, 28000, 41500, MAX_TARGET_RATE_BPS
};
const SKP_int16 SNR_table_Q1[ TARGET_RATE_TAB_SZ ] = {
- 19, 31, 35, 39, 44, 50, 60, 80
+ 19, 29, 35, 39, 44, 50, 60, 80
};
/* Decoder high-pass filter coefficients, -6 dB @ 50 Hz, 0.05 dB ripple */
@@ -96,6 +96,8 @@
const SKP_uint8 SKP_Silk_uniform4_iCDF[ 4 ] = { 192, 128, 64, 0 };
const SKP_uint8 SKP_Silk_uniform6_iCDF[ 6 ] = { 213, 171, 128, 85, 43, 0 };
const SKP_uint8 SKP_Silk_uniform8_iCDF[ 8 ] = { 224, 192, 160, 128, 96, 64, 32, 0 };
+
+const SKP_uint8 SKP_Silk_NLSF_EXT_iCDF[ 7 ] = { 100, 40, 16, 7, 3, 1, 0 };
#if SWITCH_TRANSITION_FILTERING
/* Elliptic/Cauer filters designed with 0.1 dB passband ripple,
--- a/src_common/SKP_Silk_tables_pulses_per_block.c
+++ b/src_common/SKP_Silk_tables_pulses_per_block.c
@@ -27,13 +27,12 @@
#include "SKP_Silk_tables.h"
-const SKP_uint8 SKP_Silk_max_pulses_table[4] = {
+const SKP_uint8 SKP_Silk_max_pulses_table[ 4 ] = {
8, 10, 12, 16
};
-const SKP_uint8 SKP_Silk_pulses_per_block_iCDF[10][18] =
+const SKP_uint8 SKP_Silk_pulses_per_block_iCDF[ 10 ][ 18 ] = {
{
-{
125, 51, 26, 18, 15, 12, 11, 10,
9, 8, 7, 6, 5, 4, 3, 2,
1, 0
@@ -85,9 +84,8 @@
}
};
-const SKP_uint8 SKP_Silk_pulses_per_block_BITS_Q5[9][18] =
+const SKP_uint8 SKP_Silk_pulses_per_block_BITS_Q5[ 9 ][ 18 ] = {
{
-{
31, 57, 107, 160, 205, 205, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255
@@ -134,7 +132,7 @@
}
};
-const SKP_uint8 SKP_Silk_rate_levels_iCDF[2][9] =
+const SKP_uint8 SKP_Silk_rate_levels_iCDF[ 2 ][ 9 ] =
{
{
241, 190, 178, 132, 87, 74, 41, 14,
@@ -146,7 +144,7 @@
}
};
-const SKP_uint8 SKP_Silk_rate_levels_BITS_Q5[2][9] =
+const SKP_uint8 SKP_Silk_rate_levels_BITS_Q5[ 2 ][ 9 ] =
{
{
131, 74, 141, 79, 80, 138, 95, 104,
@@ -158,7 +156,7 @@
}
};
-const SKP_uint8 SKP_Silk_shell_code_table0[44] = {
+const SKP_uint8 SKP_Silk_shell_code_table0[ 44 ] = {
128, 0, 214, 42, 0, 235, 128, 21,
0, 244, 184, 72, 11, 0, 248, 214,
128, 42, 7, 0, 248, 225, 170, 80,
@@ -167,7 +165,7 @@
35, 15, 5, 0
};
-const SKP_uint8 SKP_Silk_shell_code_table1[65] = {
+const SKP_uint8 SKP_Silk_shell_code_table1[ 65 ] = {
129, 0, 207, 50, 0, 236, 129, 20,
0, 245, 185, 72, 10, 0, 249, 213,
129, 42, 6, 0, 250, 226, 169, 87,
@@ -179,7 +177,7 @@
0
};
-const SKP_uint8 SKP_Silk_shell_code_table2[90] = {
+const SKP_uint8 SKP_Silk_shell_code_table2[ 90 ] = {
129, 0, 203, 54, 0, 234, 129, 23,
0, 245, 184, 73, 10, 0, 250, 215,
129, 41, 5, 0, 252, 232, 173, 86,
@@ -194,7 +192,7 @@
1, 0
};
-const SKP_uint8 SKP_Silk_shell_code_table3[152] = {
+const SKP_uint8 SKP_Silk_shell_code_table3[ 152 ] = {
130, 0, 200, 58, 0, 231, 130, 26,
0, 244, 184, 76, 12, 0, 249, 214,
130, 43, 6, 0, 252, 232, 173, 87,
@@ -216,13 +214,13 @@
76, 42, 18, 4, 3, 2, 1, 0
};
-const SKP_uint8 SKP_Silk_shell_code_table_offsets[17] = {
+const SKP_uint8 SKP_Silk_shell_code_table_offsets[ 17 ] = {
0, 0, 2, 5, 9, 14, 20, 27,
35, 44, 54, 65, 77, 90, 104, 119,
135
};
-const SKP_uint8 SKP_Silk_sign_iCDF[36] = {
+const SKP_uint8 SKP_Silk_sign_iCDF[ 36 ] = {
49, 67, 77, 82, 93, 99, 11, 18,
24, 31, 36, 45, 46, 66, 78, 87,
94, 104, 14, 21, 32, 42, 51, 66,
--- a/src_common/SKP_Silk_tuning_parameters.h
+++ b/src_common/SKP_Silk_tuning_parameters.h
@@ -50,10 +50,11 @@
/* LPC analysis defines: regularization and bandwidth expansion */
#define FIND_LPC_COND_FAC 2.5e-5f
#define FIND_LPC_CHIRP 0.99995f
+#define FIND_LPC_CHIRP_FIRST_FRAME 0.96f
/* LTP analysis defines */
#define FIND_LTP_COND_FAC 1e-5f
-#define LTP_DAMPING 0.001f
+#define LTP_DAMPING 0.01f
#define LTP_SMOOTHING 0.1f
/* LTP quantization settings */
@@ -148,12 +149,21 @@
#define SUBFR_SMTH_COEF 0.4f
/* parameters defining the R/D tradeoff in the residual quantizer */
-#define LAMBDA_OFFSET 1.2f
+#define LAMBDA_OFFSET 1.3f
#define LAMBDA_SPEECH_ACT -0.3f
#define LAMBDA_DELAYED_DECISIONS -0.05f
#define LAMBDA_INPUT_QUALITY -0.2f
#define LAMBDA_CODING_QUALITY -0.1f
#define LAMBDA_QUANT_OFFSET 1.5f
+
+/* Compensation in bitrate calculations for 10 ms modes */
+#define REDUCE_BITRATE_10_MS_BPS 2200
+
+/* Transition bitrates between modes */
+#define WB2MB_BITRATE_BPS 12600
+#define MB2WB_BITRATE_BPS 15600
+#define MB2NB_BITRATE_BPS 9600
+#define NB2MB_BITRATE_BPS 12600
#ifdef __cplusplus
}
--- a/src_common/src_common.vcxproj
+++ b/src_common/src_common.vcxproj
@@ -80,7 +80,6 @@
<ClInclude Include="SKP_Silk_setup.h" />
<ClInclude Include="SKP_Silk_structs.h" />
<ClInclude Include="SKP_Silk_tables.h" />
- <ClInclude Include="SKP_Silk_tables_NLSF_CB.h" />
<ClInclude Include="SKP_Silk_tuning_parameters.h" />
</ItemGroup>
<ItemGroup>
@@ -104,10 +103,11 @@
<ClCompile Include="SKP_Silk_LBRR_embed.c" />
<ClCompile Include="SKP_Silk_LP_variable_cutoff.c" />
<ClCompile Include="SKP_Silk_NLSF2A_stable.c" />
- <ClCompile Include="SKP_Silk_NLSF_MSVQ_decode.c" />
- <ClCompile Include="SKP_Silk_NLSF_MSVQ_encode.c" />
- <ClCompile Include="SKP_Silk_NLSF_VQ_rate_distortion.c" />
- <ClCompile Include="SKP_Silk_NLSF_VQ_sum_error.c" />
+ <ClCompile Include="SKP_Silk_NLSF_decode.c" />
+ <ClCompile Include="SKP_Silk_NLSF_del_dec_quant.c" />
+ <ClCompile Include="SKP_Silk_NLSF_encode.c" />
+ <ClCompile Include="SKP_Silk_NLSF_unpack.c" />
+ <ClCompile Include="SKP_Silk_NLSF_VQ.c" />
<ClCompile Include="SKP_Silk_NSQ.c" />
<ClCompile Include="SKP_Silk_NSQ_del_dec.c" />
<ClCompile Include="SKP_Silk_PLC.c" />
@@ -116,10 +116,8 @@
<ClCompile Include="SKP_Silk_shell_coder.c" />
<ClCompile Include="SKP_Silk_tables_gain.c" />
<ClCompile Include="SKP_Silk_tables_LTP.c" />
- <ClCompile Include="SKP_Silk_tables_NLSF_CB0_10.c" />
- <ClCompile Include="SKP_Silk_tables_NLSF_CB0_16.c" />
- <ClCompile Include="SKP_Silk_tables_NLSF_CB1_10.c" />
- <ClCompile Include="SKP_Silk_tables_NLSF_CB1_16.c" />
+ <ClCompile Include="SKP_Silk_tables_NLSF_CB_NB_MB.c" />
+ <ClCompile Include="SKP_Silk_tables_NLSF_CB_WB.c" />
<ClCompile Include="SKP_Silk_tables_other.c" />
<ClCompile Include="SKP_Silk_tables_pitch_lag.c" />
<ClCompile Include="SKP_Silk_tables_pulses_per_block.c" />
--- a/src_common/src_common.vcxproj.filters
+++ b/src_common/src_common.vcxproj.filters
@@ -36,9 +36,6 @@
<ClInclude Include="SKP_Silk_tuning_parameters.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="SKP_Silk_tables_NLSF_CB.h">
- <Filter>Header Files</Filter>
- </ClInclude>
<ClInclude Include="SKP_Silk_setup.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -86,9 +83,6 @@
<ClCompile Include="SKP_Silk_LP_variable_cutoff.c">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="SKP_Silk_NLSF_MSVQ_decode.c">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="SKP_Silk_NLSF2A_stable.c">
<Filter>Source Files</Filter>
</ClCompile>
@@ -110,18 +104,6 @@
<ClCompile Include="SKP_Silk_tables_LTP.c">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="SKP_Silk_tables_NLSF_CB0_10.c">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="SKP_Silk_tables_NLSF_CB0_16.c">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="SKP_Silk_tables_NLSF_CB1_10.c">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="SKP_Silk_tables_NLSF_CB1_16.c">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="SKP_Silk_tables_other.c">
<Filter>Source Files</Filter>
</ClCompile>
@@ -152,19 +134,31 @@
<ClCompile Include="SKP_Silk_LBRR_embed.c">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="SKP_Silk_NLSF_VQ_rate_distortion.c">
+ <ClCompile Include="SKP_Silk_process_NLSFs.c">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="SKP_Silk_process_NLSFs.c">
+ <ClCompile Include="SKP_Silk_HP_variable_cutoff.c">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="SKP_Silk_NLSF_VQ_sum_error.c">
+ <ClCompile Include="SKP_Silk_NLSF_encode.c">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="SKP_Silk_NLSF_MSVQ_encode.c">
+ <ClCompile Include="SKP_Silk_NLSF_decode.c">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="SKP_Silk_HP_variable_cutoff.c">
+ <ClCompile Include="SKP_Silk_tables_NLSF_CB_WB.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="SKP_Silk_NLSF_unpack.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="SKP_Silk_tables_NLSF_CB_NB_MB.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="SKP_Silk_NLSF_VQ.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="SKP_Silk_NLSF_del_dec_quant.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
--- a/test/Encoder.c
+++ b/test/Encoder.c
@@ -254,7 +254,7 @@
nBytes = MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES;
/* Silk Encoder */
- ret = SKP_Silk_SDK_Encode( psEnc, &encControl, in, (SKP_int16)counter, &range_enc_celt_state, &nBytes );
+ ret = SKP_Silk_SDK_Encode( psEnc, &encControl, in, (SKP_int16)counter, &range_enc_celt_state, &nBytes, 0 );
if( ret ) {
printf( "\nSKP_Silk_Encode returned %d", ret );
break;