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

Squashed commit of the following:

commit 8501776e52242de200b48841b0a19a512f78085d
Author: Jean-Marc Valin <jean-marc.valin@octasic.com>
Date:   Thu Feb 17 16:35:02 2011 -0500

    Remove useless file

commit 8fdc775812f84df1bb75aa4366760c768b101d02
Author: Koen Vos <koen.vos@skype.net>
Date:   Thu Feb 17 16:22:05 2011 -0500

    SILK update (fixes a bandwidth control bug and adds encoder prefill)
parent c4d32b16
......@@ -3,7 +3,7 @@
NAME = libSKP_SILK_SDK
AM_CPPFLAGS = $(AM_CFLAGS)
INCLUDES = -I$(top_srcdir)/src_FLP -I$(top_srcdir)/src_SigProc_FIX -I$(top_srcdir)/src_SigProc_FLP -I$(top_srcdir)/src_common -I$(top_srcdir)/interface -I$(top_srcdir)/../celt/libcelt
INCLUDES = -I$(top_srcdir)/src_FLP -I$(top_srcdir)/src_FIX -I$(top_srcdir)/src_SigProc_FIX -I$(top_srcdir)/src_SigProc_FLP -I$(top_srcdir)/src_common -I$(top_srcdir)/interface -I$(top_srcdir)/../celt/libcelt
EXTRA_DIST = src_FIX/src_FIX.vcxproj \
src_FIX/src_FIX.vcxproj.filters \
src_FLP/src_FLP.vcxproj \
......@@ -59,6 +59,11 @@ src_common/SKP_Silk_VAD.c \
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_process_NLSFs.c \
src_FLP/SKP_Silk_apply_sine_window_FLP.c \
src_FLP/SKP_Silk_control_codec_FLP.c \
src_FLP/SKP_Silk_corrMatrix_FLP.c \
......@@ -67,19 +72,13 @@ src_FLP/SKP_Silk_find_LPC_FLP.c \
src_FLP/SKP_Silk_find_LTP_FLP.c \
src_FLP/SKP_Silk_find_pitch_lags_FLP.c \
src_FLP/SKP_Silk_find_pred_coefs_FLP.c \
src_FLP/SKP_Silk_HP_variable_cutoff_FLP.c \
src_FLP/SKP_Silk_init_encoder_FLP.c \
src_FLP/SKP_Silk_LPC_analysis_filter_FLP.c \
src_FLP/SKP_Silk_LTP_analysis_filter_FLP.c \
src_FLP/SKP_Silk_LTP_scale_ctrl_FLP.c \
src_FLP/SKP_Silk_NLSF_MSVQ_decode_FLP.c \
src_FLP/SKP_Silk_NLSF_MSVQ_encode_FLP.c \
src_FLP/SKP_Silk_NLSF_VQ_rate_distortion_FLP.c \
src_FLP/SKP_Silk_NLSF_VQ_sum_error_FLP.c \
src_FLP/SKP_Silk_noise_shape_analysis_FLP.c \
src_FLP/SKP_Silk_prefilter_FLP.c \
src_FLP/SKP_Silk_process_gains_FLP.c \
src_FLP/SKP_Silk_process_NLSFs_FLP.c \
src_FLP/SKP_Silk_regularize_correlations_FLP.c \
src_FLP/SKP_Silk_residual_energy_FLP.c \
src_FLP/SKP_Silk_solve_LS_FLP.c \
......@@ -144,7 +143,6 @@ src_SigProc_FLP/SKP_Silk_inner_product_FLP.c \
src_SigProc_FLP/SKP_Silk_k2a_FLP.c \
src_SigProc_FLP/SKP_Silk_levinsondurbin_FLP.c \
src_SigProc_FLP/SKP_Silk_LPC_inv_pred_gain_FLP.c \
src_SigProc_FLP/SKP_Silk_NLSF_VQ_weights_laroia_FLP.c \
src_SigProc_FLP/SKP_Silk_pitch_analysis_core_FLP.c \
src_SigProc_FLP/SKP_Silk_scale_copy_vector_FLP.c \
src_SigProc_FLP/SKP_Silk_scale_vector_FLP.c \
......
......@@ -75,6 +75,16 @@ 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 */
/**************************/
......
......@@ -28,7 +28,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SKP_Silk_main_FIX.h"
#include "SKP_Silk_setup.h"
/* ToDo: Move the functions belowto common to be able to use them in FLP control codec also */
SKP_INLINE SKP_int SKP_Silk_setup_resamplers(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O */
SKP_int fs_kHz /* I */
......@@ -180,7 +179,7 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
if( PacketSize_ms == 10 ) {
psEnc->sCmn.nFramesPerPacket = 1;
psEnc->sCmn.nb_subfr = MAX_NB_SUBFR >> 1;
psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz );
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;
} else {
......@@ -189,7 +188,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->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, 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;
} else {
......@@ -202,24 +201,14 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
/* Set internal sampling frequency */
if( psEnc->sCmn.fs_kHz != fs_kHz ) {
/* reset part of the state */
SKP_memset( &psEnc->sShape, 0, sizeof( SKP_Silk_shape_state_FIX ) );
SKP_memset( &psEnc->sPrefilt, 0, sizeof( SKP_Silk_prefilter_state_FIX ) );
SKP_memset( &psEnc->sCmn.sNSQ, 0, sizeof( SKP_Silk_nsq_state ) );
SKP_memset( &psEnc->sPred, 0, sizeof( SKP_Silk_predict_state_FIX ) );
SKP_memset( psEnc->sPred.prev_NLSFq_Q15, 0, sizeof( psEnc->sPred.prev_NLSFq_Q15 ) );
#if SWITCH_TRANSITION_FILTERING
SKP_memset( psEnc->sCmn.sLP.In_LP_State, 0, sizeof( psEnc->sCmn.sLP.In_LP_State ) );
if( psEnc->sCmn.sLP.mode == 1 ) {
/* Begin transition phase */
psEnc->sCmn.sLP.transition_frame_no = 1;
} else {
/* End transition phase */
psEnc->sCmn.sLP.transition_frame_no = 0;
}
#endif
psEnc->sCmn.inputBufIx = 0;
psEnc->sCmn.nFramesAnalyzed = 0;
psEnc->sCmn.TargetRate_bps = 0; /* Ensures that psEnc->SNR_dB is recomputed */
SKP_memset( &psEnc->sShape, 0, sizeof( SKP_Silk_shape_state_FIX ) );
SKP_memset( &psEnc->sPrefilt, 0, sizeof( SKP_Silk_prefilter_state_FIX ) );
SKP_memset( &psEnc->sCmn.sNSQ, 0, sizeof( SKP_Silk_nsq_state ) );
SKP_memset( psEnc->sCmn.prev_NLSFq_Q15, 0, sizeof( psEnc->sCmn.prev_NLSFq_Q15 ) );
SKP_memset( &psEnc->sCmn.sLP.In_LP_State, 0, sizeof( psEnc->sCmn.sLP.In_LP_State ) );
psEnc->sCmn.inputBufIx = 0;
psEnc->sCmn.nFramesAnalyzed = 0;
psEnc->sCmn.TargetRate_bps = 0; /* Ensures that psEnc->SNR_dB is recomputed */
/* Initialize non-zero parameters */
psEnc->sCmn.prevLag = 100;
......@@ -259,30 +248,23 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
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->sPred.min_pitch_lag = SKP_SMULBB( 3, fs_kHz );
psEnc->sPred.max_pitch_lag = SKP_SMULBB( 18, fs_kHz );
psEnc->sCmn.max_pitch_lag = SKP_SMULBB( 18, fs_kHz );
if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ){
psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz );
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->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz );
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 );
}
if( psEnc->sCmn.fs_kHz == 16 ) {
psEnc->sCmn.mu_LTP_Q9 = SKP_FIX_CONST( MU_LTP_QUANT_WB, 9 );
psEnc->sCmn.bitrate_threshold_up = SKP_int32_MAX;
psEnc->sCmn.bitrate_threshold_down = WB2MB_BITRATE_BPS;
psEnc->sCmn.pitch_lag_low_bits_iCDF = SKP_Silk_uniform8_iCDF;
} else if( psEnc->sCmn.fs_kHz == 12 ) {
psEnc->sCmn.mu_LTP_Q9 = SKP_FIX_CONST( MU_LTP_QUANT_MB, 9 );
psEnc->sCmn.bitrate_threshold_up = MB2WB_BITRATE_BPS;
psEnc->sCmn.bitrate_threshold_down = MB2NB_BITRATE_BPS;
psEnc->sCmn.pitch_lag_low_bits_iCDF = SKP_Silk_uniform6_iCDF;
} else if( psEnc->sCmn.fs_kHz == 8 ) {
psEnc->sCmn.mu_LTP_Q9 = SKP_FIX_CONST( MU_LTP_QUANT_NB, 9 );
psEnc->sCmn.bitrate_threshold_up = NB2MB_BITRATE_BPS;
psEnc->sCmn.bitrate_threshold_down = 0;
psEnc->sCmn.pitch_lag_low_bits_iCDF = SKP_Silk_uniform4_iCDF;
} else {
/* unsupported sampling rate */
......
......@@ -38,7 +38,7 @@ SKP_int SKP_Silk_encode_frame_FIX(
)
{
SKP_Silk_encoder_control_FIX sEncCtrl;
SKP_int i, nBits, SNR_dB_Q7, ret = 0;
SKP_int i, nBits, ret = 0;
SKP_uint8 flags;
SKP_int16 *x_frame, *res_pitch_frame;
SKP_int16 xfw[ MAX_FRAME_LENGTH ];
......@@ -77,15 +77,13 @@ TIC(ENCODE_FRAME)
/* Voice Activity Detection */
/****************************/
TIC(VAD)
ret = SKP_Silk_VAD_GetSA_Q8( &psEnc->sCmn.sVAD, &psEnc->speech_activity_Q8, &SNR_dB_Q7,
sEncCtrl.input_quality_bands_Q15, &sEncCtrl.input_tilt_Q15,
psEnc->sCmn.inputBuf, psEnc->sCmn.frame_length, psEnc->sCmn.fs_kHz );
ret = SKP_Silk_VAD_GetSA_Q8( &psEnc->sCmn, psEnc->sCmn.inputBuf );
TOC(VAD)
/**************************************************/
/* Convert speech activity into VAD and DTX flags */
/**************************************************/
if( psEnc->speech_activity_Q8 < SKP_FIX_CONST( SPEECH_ACTIVITY_DTX_THRES, 8 ) ) {
if( psEnc->sCmn.speech_activity_Q8 < SKP_FIX_CONST( SPEECH_ACTIVITY_DTX_THRES, 8 ) ) {
psEnc->sCmn.indices.signalType = TYPE_NO_VOICE_ACTIVITY;
psEnc->sCmn.noSpeechCounter++;
if( psEnc->sCmn.noSpeechCounter > NO_SPEECH_FRAMES_BEFORE_DTX ) {
......@@ -109,7 +107,7 @@ TOC(VAD)
TIC(HP_IN)
#if HIGH_PASS_INPUT
/* Variable high-pass filter */
SKP_Silk_HP_variable_cutoff_FIX( psEnc, &sEncCtrl, x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.inputBuf );
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
......@@ -257,13 +255,11 @@ TOC(ENCODE_FRAME)
}
DEBUG_STORE_DATA( PredCoef.dat, tmp, psEnc->sCmn.predictLPCOrder * sizeof( SKP_float ) );
tmp[ 0 ] = (SKP_float)sEncCtrl.pitch_freq_low_Hz;
DEBUG_STORE_DATA( pitch_freq_low_Hz.dat, tmp, sizeof( SKP_float ) );
tmp[ 0 ] = (SKP_float)sEncCtrl.LTPredCodGain_Q7 / 128.0f;
DEBUG_STORE_DATA( LTPredCodGain.dat, tmp, sizeof( SKP_float ) );
tmp[ 0 ] = (SKP_float)psEnc->LTPCorr_Q15 / 32768.0f;
DEBUG_STORE_DATA( LTPcorr.dat, tmp, sizeof( SKP_float ) );
tmp[ 0 ] = (SKP_float)sEncCtrl.input_tilt_Q15 / 32768.0f;
tmp[ 0 ] = (SKP_float)psEnc->sCmn.input_tilt_Q15 / 32768.0f;
DEBUG_STORE_DATA( tilt.dat, tmp, sizeof( SKP_float ) );
for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) {
tmp[ i ] = (SKP_float)sEncCtrl.Gains_Q16[ i ] / 65536.0f;
......@@ -277,7 +273,7 @@ TOC(ENCODE_FRAME)
tmp[ 0 ] = (SKP_float)psEnc->speech_activity_Q8 / 256.0f;
DEBUG_STORE_DATA( speech_activity.dat, tmp, sizeof( SKP_float ) );
for( i = 0; i < VAD_N_BANDS; i++ ) {
tmp[ i ] = (SKP_float)sEncCtrl.input_quality_bands_Q15[ i ] / 32768.0f;
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 ) );
......@@ -304,7 +300,7 @@ void SKP_Silk_LBRR_encode_FIX(
/*******************************************/
/* Control use of inband LBRR */
/*******************************************/
if( psEnc->sCmn.LBRR_enabled && psEnc->speech_activity_Q8 > SKP_FIX_CONST( LBRR_SPEECH_ACTIVITY_THRES, 8 ) ) {
if( psEnc->sCmn.LBRR_enabled && psEnc->sCmn.speech_activity_Q8 > SKP_FIX_CONST( LBRR_SPEECH_ACTIVITY_THRES, 8 ) ) {
psEnc->sCmn.LBRR_flags[ psEnc->sCmn.nFramesAnalyzed ] = 1;
/* Copy noise shaping quantizer state and quantization indices from regular encoding */
......
......@@ -36,7 +36,6 @@ void SKP_Silk_find_pitch_lags_FIX(
const SKP_int16 x[] /* I Speech signal */
)
{
SKP_Silk_predict_state_FIX *psPredSt = &psEnc->sPred;
SKP_int buf_len, i, scale;
SKP_int32 thrhld_Q15, res_nrg;
const SKP_int16 *x_buf, *x_buf_ptr;
......@@ -52,7 +51,7 @@ void SKP_Silk_find_pitch_lags_FIX(
buf_len = psEnc->sCmn.la_pitch + psEnc->sCmn.frame_length + psEnc->sCmn.ltp_mem_length;
/* Safty check */
SKP_assert( buf_len >= psPredSt->pitch_LPC_win_length );
SKP_assert( buf_len >= psEnc->sCmn.pitch_LPC_win_length );
x_buf = x - psEnc->sCmn.ltp_mem_length;
......@@ -63,22 +62,22 @@ void SKP_Silk_find_pitch_lags_FIX(
/* Calculate windowed signal */
/* First LA_LTP samples */
x_buf_ptr = x_buf + buf_len - psPredSt->pitch_LPC_win_length;
x_buf_ptr = x_buf + buf_len - psEnc->sCmn.pitch_LPC_win_length;
Wsig_ptr = Wsig;
SKP_Silk_apply_sine_window( Wsig_ptr, x_buf_ptr, 1, psEnc->sCmn.la_pitch );
/* Middle un - windowed samples */
Wsig_ptr += psEnc->sCmn.la_pitch;
x_buf_ptr += psEnc->sCmn.la_pitch;
SKP_memcpy( Wsig_ptr, x_buf_ptr, ( psPredSt->pitch_LPC_win_length - SKP_LSHIFT( psEnc->sCmn.la_pitch, 1 ) ) * sizeof( SKP_int16 ) );
SKP_memcpy( Wsig_ptr, x_buf_ptr, ( psEnc->sCmn.pitch_LPC_win_length - SKP_LSHIFT( psEnc->sCmn.la_pitch, 1 ) ) * sizeof( SKP_int16 ) );
/* Last LA_LTP samples */
Wsig_ptr += psPredSt->pitch_LPC_win_length - SKP_LSHIFT( psEnc->sCmn.la_pitch, 1 );
x_buf_ptr += psPredSt->pitch_LPC_win_length - SKP_LSHIFT( psEnc->sCmn.la_pitch, 1 );
Wsig_ptr += psEnc->sCmn.pitch_LPC_win_length - SKP_LSHIFT( psEnc->sCmn.la_pitch, 1 );
x_buf_ptr += psEnc->sCmn.pitch_LPC_win_length - SKP_LSHIFT( psEnc->sCmn.la_pitch, 1 );
SKP_Silk_apply_sine_window( Wsig_ptr, x_buf_ptr, 2, psEnc->sCmn.la_pitch );
/* Calculate autocorrelation sequence */
SKP_Silk_autocorr( auto_corr, &scale, Wsig, psPredSt->pitch_LPC_win_length, psEnc->sCmn.pitchEstimationLPCOrder + 1 );
SKP_Silk_autocorr( auto_corr, &scale, Wsig, psEnc->sCmn.pitch_LPC_win_length, psEnc->sCmn.pitchEstimationLPCOrder + 1 );
/* Add white noise, as fraction of energy */
auto_corr[ 0 ] = SKP_SMLAWB( auto_corr[ 0 ], auto_corr[ 0 ], SKP_FIX_CONST( FIND_PITCH_WHITE_NOISE_FRACTION, 16 ) ) + 1;
......@@ -105,13 +104,13 @@ void SKP_Silk_find_pitch_lags_FIX(
/*****************************************/
SKP_Silk_LPC_analysis_filter( res, x_buf, A_Q12, buf_len, psEnc->sCmn.pitchEstimationLPCOrder );
if( psEnc->sCmn.indices.signalType != TYPE_NO_VOICE_ACTIVITY ) {
if( psEnc->sCmn.indices.signalType != TYPE_NO_VOICE_ACTIVITY && psEnc->sCmn.first_frame_after_reset == 0 ) {
/* Threshold for pitch estimator */
thrhld_Q15 = SKP_FIX_CONST( 0.6, 15 );
thrhld_Q15 = SKP_SMLABB( thrhld_Q15, SKP_FIX_CONST( -0.004, 15 ), psEnc->sCmn.pitchEstimationLPCOrder );
thrhld_Q15 = SKP_SMLABB( thrhld_Q15, SKP_FIX_CONST( -0.1, 7 ), psEnc->speech_activity_Q8 );
thrhld_Q15 = SKP_SMLABB( thrhld_Q15, SKP_FIX_CONST( -0.1, 7 ), psEnc->sCmn.speech_activity_Q8 );
thrhld_Q15 = SKP_SMLABB( thrhld_Q15, SKP_FIX_CONST( -0.15, 15 ), SKP_RSHIFT( psEnc->sCmn.prevSignalType, 1 ) );
thrhld_Q15 = SKP_SMLAWB( thrhld_Q15, SKP_FIX_CONST( -0.1, 16 ), psEncCtrl->input_tilt_Q15 );
thrhld_Q15 = SKP_SMLAWB( thrhld_Q15, SKP_FIX_CONST( -0.1, 16 ), psEnc->sCmn.input_tilt_Q15 );
thrhld_Q15 = SKP_SAT16( thrhld_Q15 );
/*****************************************/
......
......@@ -108,14 +108,14 @@ 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->sPred.prev_NLSFq_Q15,
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,
LPC_in_pre, psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder, psEnc->sCmn.nb_subfr );
TOC(FIND_LPC)
/* Quantize LSFs */
TIC(PROCESS_LSFS)
SKP_Silk_process_NLSFs_FIX( psEnc, psEncCtrl, NLSF_Q15 );
SKP_Silk_process_NLSFs( &psEnc->sCmn, psEncCtrl->PredCoef_Q12, NLSF_Q15, psEnc->sCmn.prev_NLSFq_Q15 );
TOC(PROCESS_LSFS)
/* Calculate residual energy using quantized LPC coefficients */
......@@ -123,5 +123,5 @@ void SKP_Silk_find_pred_coefs_FIX(
psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.predictLPCOrder );
/* Copy to prediction struct for use in next frame for fluctuation reduction */
SKP_memcpy( psEnc->sPred.prev_NLSFq_Q15, NLSF_Q15, psEnc->sCmn.predictLPCOrder * sizeof( SKP_int ) );
SKP_memcpy( psEnc->sCmn.prev_NLSFq_Q15, NLSF_Q15, sizeof( psEnc->sCmn.prev_NLSFq_Q15 ) );
}
......@@ -38,11 +38,11 @@ SKP_int SKP_Silk_init_encoder_FIX(
SKP_memset( psEnc, 0, sizeof( SKP_Silk_encoder_state_FIX ) );
#if HIGH_PASS_INPUT
psEnc->variable_HP_smth1_Q15 = 200844; /* = SKP_Silk_log2(70)_Q0; */
psEnc->variable_HP_smth2_Q15 = 200844; /* = SKP_Silk_log2(70)_Q0; */
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 */
/* Used to deactivate LSF interpolation, fluctuation reduction, pitch prediction */
psEnc->sCmn.first_frame_after_reset = 1;
/* Initialize Silk VAD */
......
......@@ -46,14 +46,6 @@ extern "C"
/* Encoder Functions */
/*********************/
/* High-pass filter with cutoff frequency adaptation based on pitch lag statistics */
void SKP_Silk_HP_variable_cutoff_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O Encoder state */
SKP_Silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control */
SKP_int16 *out, /* O high-pass filtered output signal */
const SKP_int16 *in /* I input signal */
);
/* Encoder main function */
SKP_int SKP_Silk_encode_frame_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */
......@@ -188,53 +180,6 @@ void SKP_Silk_residual_energy_FIX(
const SKP_int LPC_order /* I LPC order */
);
/******************/
/* NLSF Quantizer */
/******************/
/* Limit, stabilize, convert and quantize NLSFs. */
void SKP_Silk_process_NLSFs_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O encoder state */
SKP_Silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */
SKP_int *pNLSF_Q15 /* I/O Normalized LSFs (quant out) (0 - (2^15-1)) */
);
/* NLSF vector encoder */
void SKP_Silk_NLSF_MSVQ_encode_FIX(
SKP_int8 *NLSFIndices, /* O Codebook path vector [ CB_STAGES ] */
SKP_int *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_Q6, /* 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 */
);
/* Rate-Distortion calculations for multiple input data vectors */
void SKP_Silk_NLSF_VQ_rate_distortion_FIX(
SKP_int32 *pRD_Q20, /* 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_Q6, /* I Weight vector */
const SKP_int32 *rate_acc_Q5, /* 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 LPC_order /* I LPC order */
);
/* Compute weighted quantization errors for an LPC_order element input vector, over one codebook stage */
void SKP_Silk_NLSF_VQ_sum_error_FIX(
SKP_int32 *err_Q20, /* O Weighted quantization errors [N*K] */
const SKP_int16 *in_Q15, /* I Input vectors to be quantized [N*LPC_order] */
const SKP_int *w_Q6, /* 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 LPC_order /* I Number of LPCs */
);
/* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */
SKP_int32 SKP_Silk_residual_energy16_covar_FIX(
const SKP_int16 *c, /* I Prediction vector */
......
......@@ -170,8 +170,8 @@ void SKP_Silk_noise_shape_analysis_FIX(
/* GAIN CONTROL */
/****************/
/* Input quality is the average of the quality in the lowest two VAD bands */
psEncCtrl->input_quality_Q14 = ( SKP_int )SKP_RSHIFT( ( SKP_int32 )psEncCtrl->input_quality_bands_Q15[ 0 ]
+ psEncCtrl->input_quality_bands_Q15[ 1 ], 2 );
psEncCtrl->input_quality_Q14 = ( SKP_int )SKP_RSHIFT( ( SKP_int32 )psEnc->sCmn.input_quality_bands_Q15[ 0 ]
+ psEnc->sCmn.input_quality_bands_Q15[ 1 ], 2 );
/* Coding quality level, between 0.0_Q0 and 1.0_Q0, but in Q14 */
psEncCtrl->coding_quality_Q14 = SKP_RSHIFT( SKP_Silk_sigm_Q15( SKP_RSHIFT_ROUND( psEncCtrl->current_SNR_dB_Q7 -
......@@ -180,7 +180,7 @@ void SKP_Silk_noise_shape_analysis_FIX(
/* Reduce coding SNR during low speech activity */
SNR_adj_dB_Q7 = psEncCtrl->current_SNR_dB_Q7;
if( psEnc->sCmn.useCBR == 0 ) {
b_Q8 = SKP_FIX_CONST( 1.0, 8 ) - psEnc->speech_activity_Q8;
b_Q8 = SKP_FIX_CONST( 1.0, 8 ) - psEnc->sCmn.speech_activity_Q8;
b_Q8 = SKP_SMULWB( SKP_LSHIFT( b_Q8, 8 ), b_Q8 );
SNR_adj_dB_Q7 = SKP_SMLAWB( SNR_adj_dB_Q7,
SKP_SMULBB( SKP_FIX_CONST( -BG_SNR_DECR_dB, 7 ) >> ( 4 + 1 ), b_Q8 ), // Q11
......@@ -370,15 +370,9 @@ void SKP_Silk_noise_shape_analysis_FIX(
/* Control low-frequency shaping and noise tilt */
/************************************************/
/* Less low frequency shaping for noisy inputs */
#if 1
strength_Q16 = SKP_MUL( SKP_FIX_CONST( LOW_FREQ_SHAPING, 0 ), SKP_FIX_CONST( 1.0, 16 ) +
SKP_SMULBB( SKP_FIX_CONST( LOW_QUALITY_LOW_FREQ_SHAPING_DECR, 1 ), psEncCtrl->input_quality_bands_Q15[ 0 ] - SKP_FIX_CONST( 1.0, 15 ) ) );
#else
// TODO: CHECK THAT BELOW WORKS FINE AND REPLACE
strength_Q16 = SKP_MUL( SKP_FIX_CONST( LOW_FREQ_SHAPING, 4 ), SKP_SMLAWB( SKP_FIX_CONST( 1.0, 12 ),
SKP_FIX_CONST( LOW_QUALITY_LOW_FREQ_SHAPING_DECR, 13 ), psEncCtrl->input_quality_bands_Q15[ 0 ] - SKP_FIX_CONST( 1.0, 15 ) ) );
#endif
strength_Q16 = SKP_RSHIFT( SKP_MUL( strength_Q16, psEnc->speech_activity_Q8 ), 8 );
SKP_FIX_CONST( LOW_QUALITY_LOW_FREQ_SHAPING_DECR, 13 ), psEnc->sCmn.input_quality_bands_Q15[ 0 ] - SKP_FIX_CONST( 1.0, 15 ) ) );
strength_Q16 = SKP_RSHIFT( SKP_MUL( strength_Q16, psEnc->sCmn.speech_activity_Q8 ), 8 );
if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) {
/* Reduce low frequencies quantization noise for periodic signals, depending on pitch lag */
/*f = 400; freqz([1, -0.98 + 2e-4 * f], [1, -0.97 + 7e-4 * f], 2^12, Fs); axis([0, 1000, -10, 1])*/
......@@ -392,7 +386,7 @@ void SKP_Silk_noise_shape_analysis_FIX(
SKP_assert( SKP_FIX_CONST( HARM_HP_NOISE_COEF, 24 ) < SKP_FIX_CONST( 0.5, 24 ) ); // Guarantees that second argument to SMULWB() is within range of an SKP_int16
Tilt_Q16 = - SKP_FIX_CONST( HP_NOISE_COEF, 16 ) -
SKP_SMULWB( SKP_FIX_CONST( 1.0, 16 ) - SKP_FIX_CONST( HP_NOISE_COEF, 16 ),
SKP_SMULWB( SKP_FIX_CONST( HARM_HP_NOISE_COEF, 24 ), psEnc->speech_activity_Q8 ) );
SKP_SMULWB( SKP_FIX_CONST( HARM_HP_NOISE_COEF, 24 ), psEnc->sCmn.speech_activity_Q8 ) );
} else {
b_Q14 = SKP_DIV32_16( 21299, psEnc->sCmn.fs_kHz ); // 1.3_Q0 = 21299_Q14
/* Pack two coefficients in one int32 */
......
......@@ -87,7 +87,7 @@ void SKP_Silk_process_gains_FIX(
&psShapeSt->LastGainIndex, psEnc->sCmn.nFramesAnalyzed, psEnc->sCmn.nb_subfr );
/* Set quantizer offset for voiced signals. Larger offset when LTP coding gain is low or tilt is high (ie low-pass) */
if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) {
if( psEncCtrl->LTPredCodGain_Q7 + SKP_RSHIFT( psEncCtrl->input_tilt_Q15, 8 ) > SKP_FIX_CONST( 1.0, 7 ) ) {
if( psEncCtrl->LTPredCodGain_Q7 + SKP_RSHIFT( psEnc->sCmn.input_tilt_Q15, 8 ) > SKP_FIX_CONST( 1.0, 7 ) ) {
psEnc->sCmn.indices.quantOffsetType = 0;
} else {
psEnc->sCmn.indices.quantOffsetType = 1;
......@@ -98,7 +98,7 @@ void SKP_Silk_process_gains_FIX(
quant_offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psEnc->sCmn.indices.signalType >> 1 ][ psEnc->sCmn.indices.quantOffsetType ];
psEncCtrl->Lambda_Q10 = SKP_FIX_CONST( LAMBDA_OFFSET, 10 )
+ SKP_SMULBB( SKP_FIX_CONST( LAMBDA_DELAYED_DECISIONS, 10 ), psEnc->sCmn.nStatesDelayedDecision )
+ SKP_SMULWB( SKP_FIX_CONST( LAMBDA_SPEECH_ACT, 18 ), psEnc->speech_activity_Q8 )
+ SKP_SMULWB( SKP_FIX_CONST( LAMBDA_SPEECH_ACT, 18 ), psEnc->sCmn.speech_activity_Q8 )
+ SKP_SMULWB( SKP_FIX_CONST( LAMBDA_INPUT_QUALITY, 12 ), psEncCtrl->input_quality_Q14 )
+ SKP_SMULWB( SKP_FIX_CONST( LAMBDA_CODING_QUALITY, 12 ), psEncCtrl->coding_quality_Q14 )
+ SKP_SMULWB( SKP_FIX_CONST( LAMBDA_QUANT_OFFSET, 16 ), quant_offset_Q10 );
......
......@@ -61,37 +61,19 @@ typedef struct {
SKP_int lagPrev;
} SKP_Silk_prefilter_state_FIX;
/*****************************/
/* Prediction analysis state */
/*****************************/
typedef struct {
SKP_int pitch_LPC_win_length;
SKP_int min_pitch_lag; /* Lowest possible pitch lag (samples) */
SKP_int max_pitch_lag; /* Highest possible pitch lag (samples) */
SKP_int prev_NLSFq_Q15[ MAX_LPC_ORDER ]; /* Previously quantized NLSF vector */
} SKP_Silk_predict_state_FIX;
/********************************/
/* Encoder state FIX */
/********************************/
typedef struct {
SKP_Silk_encoder_state sCmn; /* Common struct, shared with floating-point code */
#if HIGH_PASS_INPUT
SKP_int32 variable_HP_smth1_Q15; /* State of first smoother */
SKP_int32 variable_HP_smth2_Q15; /* State of second smoother */
#endif
SKP_Silk_shape_state_FIX sShape; /* Shape state */
SKP_Silk_prefilter_state_FIX sPrefilt; /* Prefilter State */
SKP_Silk_predict_state_FIX sPred; /* Prediction state */
/* Buffer for find pitch and noise shape analysis */
SKP_DWORD_ALIGN SKP_int16 x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ];
SKP_int LTPCorr_Q15; /* Normalized correlation from pitch lag estimator */
SKP_int32 SNR_dB_Q7; /* Quality setting */
SKP_int BufferedInChannel_ms; /* Simulated number of ms buffer because of exceeded TargetRate_bps */
SKP_int speech_activity_Q8; /* Speech activity in Q8 */
/* Parameters For LTP scaling Control */
SKP_int prevLTPredCodGain_Q7;
......@@ -124,15 +106,12 @@ typedef struct {
SKP_int Lambda_Q10;
SKP_int input_quality_Q14;
SKP_int coding_quality_Q14;
SKP_int32 pitch_freq_low_Hz;
SKP_int current_SNR_dB_Q7;
/* measures */
SKP_int sparseness_Q8;
SKP_int32 predGain_Q16;
SKP_int LTPredCodGain_Q7;
SKP_int input_quality_bands_Q15[ VAD_N_BANDS ];
SKP_int input_tilt_Q15;
SKP_int32 ResNrg[ MAX_NB_SUBFR ]; /* Residual energy per subframe */
SKP_int ResNrgQ[ MAX_NB_SUBFR ]; /* Q domain for the residual energy > 0 */
......
......@@ -85,17 +85,12 @@
<ClCompile Include="SKP_Silk_find_LTP_FIX.c" />
<ClCompile Include="SKP_Silk_find_pitch_lags_FIX.c" />
<ClCompile Include="SKP_Silk_find_pred_coefs_FIX.c" />
<ClCompile Include="SKP_Silk_HP_variable_cutoff_FIX.c" />
<ClCompile Include="SKP_Silk_init_encoder_FIX.c" />
<ClCompile Include="SKP_Silk_LTP_analysis_filter_FIX.c" />
<ClCompile Include="SKP_Silk_LTP_scale_ctrl_FIX.c" />
<ClCompile Include="SKP_Silk_NLSF_MSVQ_encode_FIX.c" />
<ClCompile Include="SKP_Silk_NLSF_VQ_rate_distortion_FIX.c" />
<ClCompile Include="SKP_Silk_NLSF_VQ_sum_error_FIX.c" />
<ClCompile Include="SKP_Silk_noise_shape_analysis_FIX.c" />
<ClCompile Include="SKP_Silk_prefilter_FIX.c" />
<ClCompile Include="SKP_Silk_process_gains_FIX.c" />
<ClCompile Include="SKP_Silk_process_NLSFs_FIX.c" />
<ClCompile Include="SKP_Silk_regularize_correlations_FIX.c" />
<ClCompile Include="SKP_Silk_residual_energy16_FIX.c" />
<ClCompile Include="SKP_Silk_residual_energy_FIX.c" />
......
......@@ -47,9 +47,6 @@
<ClCompile Include="SKP_Silk_find_pred_coefs_FIX.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SKP_Silk_HP_variable_cutoff_FIX.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SKP_Silk_init_encoder_FIX.c">
<Filter>Source Files</Filter>
</ClCompile>
......@@ -59,15 +56,6 @@
<ClCompile Include="SKP_Silk_LTP_scale_ctrl_FIX.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SKP_Silk_NLSF_MSVQ_encode_FIX.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SKP_Silk_NLSF_VQ_rate_distortion_FIX.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SKP_Silk_NLSF_VQ_sum_error_FIX.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SKP_Silk_noise_shape_analysis_FIX.c">
<Filter>Source Files</Filter>
</ClCompile>
......@@ -77,9 +65,6 @@
<ClCompile Include="SKP_Silk_process_gains_FIX.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SKP_Silk_process_NLSFs_FIX.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SKP_Silk_regularize_correlations_FIX.c">
<Filter>Source Files</Filter>
</ClCompile>
......
/***********************************************************************
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