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

Squashed commit of the following:

commit 7721daf733c6986cb2c2511c81e6fc14fea1ec6a
Author: Jean-Marc Valin <jean-marc.valin@octasic.com>
Date:   Mon Feb 28 16:00:52 2011 -0500

    Makefile.am update

commit 47dcc4edad849f57240b0c364036a378b5d22a9a
Author: Koen Vos <koen.vos@skype.net>
Date:   Mon Feb 28 15:46:23 2011 -0500

    SILK update (prefill, new LSF quant)
parent 6df6db13
......@@ -42,17 +42,15 @@ src_common/SKP_Silk_interpolate.c \
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 \
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_control_audio_bandwidth.c \
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.c \
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_main.h \
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 \
......
......@@ -75,26 +75,19 @@ SKP_int SKP_Silk_SDK_QueryEncoder( /* O: Returns error co
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 */
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 */
);
/****************************************/
......@@ -115,6 +108,16 @@ SKP_int SKP_Silk_SDK_InitDecoder( /* O: Returns error co
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 */
);
/******************/
/* Decode a frame */
/******************/
......
......@@ -55,7 +55,7 @@ SKP_int SKP_Silk_control_encoder_FIX(
{
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 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
( 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 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
} 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 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
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 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
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 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
} 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 );
}
}
......
......@@ -46,7 +46,7 @@ SKP_int SKP_Silk_encode_frame_FIX(
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 @@ TOC(VAD)
/* 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 @@ TIC(NSQ)
}
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 @@ TOC(ENCODE_PULSES)
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 @@ TOC(ENCODE_FRAME)
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 */
......
......@@ -30,14 +30,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/* 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 @@ void SKP_Silk_find_LPC_FIX(
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 @@ void SKP_Silk_find_LPC_FIX(
/* 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 @@ void SKP_Silk_find_LPC_FIX(
/* 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 ) );
}
......@@ -89,7 +89,10 @@ void SKP_Silk_find_LTP_FIX(
}
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 @@ void SKP_Silk_find_LTP_FIX(
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;
......
......@@ -37,7 +37,7 @@ void SKP_Silk_find_pred_coefs_FIX(
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 @@ void SKP_Silk_find_pred_coefs_FIX(
/* 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)
......
......@@ -37,10 +37,8 @@ SKP_int SKP_Silk_init_encoder_FIX(
/* 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;
......
......@@ -132,14 +132,15 @@ void SKP_Silk_find_pred_coefs_FIX(
/* 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 */
......
......@@ -55,7 +55,7 @@ SKP_int SKP_Silk_control_encoder_FLP(
{
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 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
( 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 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
} 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 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
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 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
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 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
} 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 );
}
}
......
......@@ -47,7 +47,7 @@ SKP_int SKP_Silk_encode_frame_FLP(
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 @@ TOC(VAD)
/* 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 @@ TIC(NSQ)
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