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

SILK update

parent 6c98e344
......@@ -29,7 +29,7 @@ src_common/SKP_Silk_decode_indices.c \
src_common/SKP_Silk_decode_parameters.c \
src_common/SKP_Silk_decode_pulses.c \
src_common/SKP_Silk_decoder_set_fs.c \
src_common/SKP_Silk_dec_SDK_API.c \
src_common/SKP_Silk_dec_API.c \
src_common/SKP_Silk_detect_SWB_input.c \
src_common/SKP_Silk_enc_API.c \
src_common/SKP_Silk_encode_parameters.c \
......@@ -58,6 +58,7 @@ src_common/SKP_Silk_tables_pulses_per_block.c \
src_common/SKP_Silk_tables_sign.c \
src_common/SKP_Silk_tables_type_offset.c \
src_common/SKP_Silk_VAD.c \
src_common/SKP_Silk_control_audio_bandwidth.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 \
......
......@@ -83,11 +83,11 @@ SKP_int SKP_Silk_SDK_QueryEncoder( /* O: Returns error co
/**************************/
SKP_int SKP_Silk_SDK_Encode( /* O: Returns error code */
void *encState, /* I/O: State */
const SKP_SILK_SDK_EncControlStruct *encControl, /* I: Control status */
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_int16 *nBytesOut /* I/O: Number of bytes in payload (input: Max bytes) */
SKP_int32 *nBytesOut /* I/O: Number of bytes in payload (input: Max bytes) */
);
/****************************************/
......@@ -118,7 +118,7 @@ SKP_int SKP_Silk_SDK_Decode( /* O: Returns error co
ec_dec *psRangeDec, /* I/O Compressor data structure */
const SKP_int nBytesIn, /* I: Number of input bytes */
SKP_int16 *samplesOut, /* O: Decoded output speech vector */
SKP_int16 *nSamplesOut /* I/O: Number of samples (vector/decoded) */
SKP_int32 *nSamplesOut /* I/O: Number of samples (vector/decoded) */
);
/***************************************************************/
......@@ -129,7 +129,7 @@ void SKP_Silk_SDK_search_for_LBRR(
const SKP_int16 nBytesIn, /* I: Number of input bytes */
SKP_int lost_offset, /* I: Offset from lost packet */
SKP_uint8 *LBRRData, /* O: LBRR payload */
SKP_int16 *nLBRRBytes /* O: Number of LBRR Bytes */
SKP_int32 *nLBRRBytes /* O: Number of LBRR Bytes */
);
/**************************************/
......
......@@ -39,14 +39,17 @@ extern "C"
/* Structure for controlling encoder operation */
/***********************************************/
typedef struct {
/* I: Input signal sampling rate in Hertz; 8000/12000/16000/24000 */
/* I: Input signal sampling rate in Hertz; 8000/12000/16000/24000/32000/44100/48000 */
SKP_int32 API_sampleRate;
/* I: Maximum internal sampling rate in Hertz; 8000/12000/16000/24000 */
SKP_int32 maxInternalSampleRate;
/* I: Number of samples per packet; must be equivalent of 20, 40, 60, 80 or 100 ms */
SKP_int packetSize;
/* I: Minimum internal sampling rate in Hertz; 8000/12000/16000/24000 */
SKP_int32 minInternalSampleRate;
/* I: Number of samples per packet in milliseconds; 10/20/40/60 */
SKP_int payloadSize_ms;
/* I: Bitrate during active speech in bits/second; internally limited */
SKP_int32 bitRate;
......@@ -62,20 +65,32 @@ typedef struct {
/* I: Flag to enable discontinuous transmission (DTX); 0/1 */
SKP_int useDTX;
/* I: Flag to use constant bitrate */
SKP_int useCBR;
/* O: Internal sampling rate used, in Hertz; 8000/12000/16000/24000 */
SKP_int32 internalSampleRate;
} SKP_SILK_SDK_EncControlStruct;
/**************************************************************************/
/* Structure for controlling decoder operation and reading decoder status */
/**************************************************************************/
typedef struct {
/* I: Output signal sampling rate in Hertz; 8000/12000/16000/24000 */
/* I: Output signal sampling rate in Hertz; 8000/12000/16000/24000/32000/44100/48000 */
SKP_int32 API_sampleRate;
/* I: Number of samples per packet in milliseconds; 10/20/40/60 */
SKP_int payloadSize_ms;
/* I: Internal sampling rate used, in Hertz; 8000/12000/16000/24000 */
SKP_int32 internalSampleRate;
/* O: Number of samples per frame */
SKP_int frameSize;
/* O: Frames per packet 1, 2, 3, 4, 5 */
SKP_int framesPerPacket;
/* O: Frames per payload 1, 2, 3 */
SKP_int framesPerPayload;
/* O: Flag to indicate that the decoder has remaining payloads internally */
SKP_int moreInternalDecoderFrames;
......
......@@ -43,44 +43,50 @@ extern "C"
/**************************/
/* Input length is not a multiplum of 10 ms, or length is longer than the packet length */
#define SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES -1
#define SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES -101
/* Sampling frequency not 8000, 12000, 16000 or 24000 Hertz */
#define SKP_SILK_ENC_FS_NOT_SUPPORTED -2
#define SKP_SILK_ENC_FS_NOT_SUPPORTED -102
/* Packet size not 20, 40, 60, 80 or 100 ms */
#define SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED -3
#define SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED -103
/* Allocated payload buffer too short */
#define SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT -4
#define SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT -104
/* Loss rate not between 0 and 100 percent */
#define SKP_SILK_ENC_INVALID_LOSS_RATE -5
#define SKP_SILK_ENC_INVALID_LOSS_RATE -105
/* Complexity setting not valid, use 0, 1 or 2 */
#define SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING -6
#define SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING -106
/* Inband FEC setting not valid, use 0 or 1 */
#define SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING -7
#define SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING -107
/* DTX setting not valid, use 0 or 1 */
#define SKP_SILK_ENC_INVALID_DTX_SETTING -8
#define SKP_SILK_ENC_INVALID_DTX_SETTING -108
/* CBR setting not valid, use 0 or 1 */
#define SKP_SILK_ENC_INVALID_CBR_SETTING -109
/* Internal encoder error */
#define SKP_SILK_ENC_INTERNAL_ERROR -9
#define SKP_SILK_ENC_INTERNAL_ERROR -110
/**************************/
/* Decoder error messages */
/**************************/
/* Output sampling frequency lower than internal decoded sampling frequency */
#define SKP_SILK_DEC_INVALID_SAMPLING_FREQUENCY -10
#define SKP_SILK_DEC_INVALID_SAMPLING_FREQUENCY -200
/* Payload size exceeded the maximum allowed 1024 bytes */
#define SKP_SILK_DEC_PAYLOAD_TOO_LARGE -11
#define SKP_SILK_DEC_PAYLOAD_TOO_LARGE -201
/* Payload has bit errors */
#define SKP_SILK_DEC_PAYLOAD_ERROR -202
/* Payload has bit errors */
#define SKP_SILK_DEC_PAYLOAD_ERROR -12
#define SKP_SILK_DEC_INVALID_FRAME_SIZE -203
#ifdef __cplusplus
}
......
......@@ -26,6 +26,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
#include "SKP_Silk_main_FIX.h"
#include "SKP_Silk_tuning_parameters.h"
#if HIGH_PASS_INPUT
......@@ -57,7 +58,7 @@ void SKP_Silk_HP_variable_cutoff_FIX(
quality_Q15 = psEncCtrl->input_quality_bands_Q15[ 0 ];
pitch_freq_log_Q7 = SKP_SUB32( pitch_freq_log_Q7, SKP_SMULWB( SKP_SMULWB( SKP_LSHIFT( quality_Q15, 2 ), quality_Q15 ),
pitch_freq_log_Q7 - SKP_LOG2_VARIABLE_HP_MIN_FREQ_Q7 ) );
pitch_freq_log_Q7 = SKP_ADD32( pitch_freq_log_Q7, SKP_RSHIFT( 19661 - quality_Q15, 9 ) ); // 19661_Q15 = 0.6_Q0
pitch_freq_log_Q7 = SKP_ADD32( pitch_freq_log_Q7, SKP_RSHIFT( SKP_FIX_CONST( 0.6, 15 ) - quality_Q15, 9 ) );
//delta_freq = pitch_freq_log - psEnc->variable_HP_smth1;
delta_freq_Q7 = pitch_freq_log_Q7 - SKP_RSHIFT( psEnc->variable_HP_smth1_Q15, 8 );
......@@ -67,21 +68,22 @@ void SKP_Silk_HP_variable_cutoff_FIX(
}
/* limit delta, to reduce impact of outliers */
delta_freq_Q7 = SKP_LIMIT_32( delta_freq_Q7, -VARIABLE_HP_MAX_DELTA_FREQ_Q7, VARIABLE_HP_MAX_DELTA_FREQ_Q7 );
delta_freq_Q7 = SKP_LIMIT_32( delta_freq_Q7, -SKP_FIX_CONST( VARIABLE_HP_MAX_DELTA_FREQ, 7 ), SKP_FIX_CONST( VARIABLE_HP_MAX_DELTA_FREQ, 7 ) );
/* update smoother */
psEnc->variable_HP_smth1_Q15 = SKP_SMLAWB( psEnc->variable_HP_smth1_Q15,
SKP_MUL( SKP_LSHIFT( psEnc->speech_activity_Q8, 1 ), delta_freq_Q7 ), VARIABLE_HP_SMTH_COEF1_Q16 );
SKP_MUL( SKP_LSHIFT( psEnc->speech_activity_Q8, 1 ), delta_freq_Q7 ), SKP_FIX_CONST( VARIABLE_HP_SMTH_COEF1, 16 ) );
}
/* second smoother */
psEnc->variable_HP_smth2_Q15 = SKP_SMLAWB( psEnc->variable_HP_smth2_Q15,
psEnc->variable_HP_smth1_Q15 - psEnc->variable_HP_smth2_Q15, VARIABLE_HP_SMTH_COEF2_Q16 );
psEnc->variable_HP_smth1_Q15 - psEnc->variable_HP_smth2_Q15, SKP_FIX_CONST( VARIABLE_HP_SMTH_COEF2, 16 ) );
/* convert from log scale to Hertz */
psEncCtrl->pitch_freq_low_Hz = SKP_Silk_log2lin( SKP_RSHIFT( psEnc->variable_HP_smth2_Q15, 8 ) ); //pow( 2.0, psEnc->variable_HP_smth2 );
psEncCtrl->pitch_freq_low_Hz = SKP_Silk_log2lin( SKP_RSHIFT( psEnc->variable_HP_smth2_Q15, 8 ) );
/* limit frequency range */
psEncCtrl->pitch_freq_low_Hz = SKP_LIMIT_32( psEncCtrl->pitch_freq_low_Hz, VARIABLE_HP_MIN_FREQ_Q0, VARIABLE_HP_MAX_FREQ_Q0 );
psEncCtrl->pitch_freq_low_Hz = SKP_LIMIT_32( psEncCtrl->pitch_freq_low_Hz,
SKP_FIX_CONST( VARIABLE_HP_MIN_FREQ, 0 ), SKP_FIX_CONST( VARIABLE_HP_MAX_FREQ, 0 ) );
/********************************/
/* Compute Filter Coefficients */
......@@ -94,7 +96,7 @@ void SKP_Silk_HP_variable_cutoff_FIX(
SKP_assert( Fc_Q19 >= 3704 );
SKP_assert( Fc_Q19 <= 27787 );
r_Q28 = ( 1 << 28 ) - SKP_MUL( 471, Fc_Q19 ); // 471_Q9 = 0.92_Q0, range: 255347779 to 266690872, 27-28 bits
r_Q28 = SKP_FIX_CONST( 1.0, 28 ) - SKP_MUL( SKP_FIX_CONST( 0.92, 9 ), Fc_Q19 );
SKP_assert( r_Q28 >= 255347779 );
SKP_assert( r_Q28 <= 266690872 );
......@@ -106,7 +108,7 @@ void SKP_Silk_HP_variable_cutoff_FIX(
// -r * ( 2 - Fc * Fc );
r_Q22 = SKP_RSHIFT( r_Q28, 6 );
A_Q28[ 0 ] = SKP_SMULWW( r_Q22, SKP_SMULWW( Fc_Q19, Fc_Q19 ) - ( 2 << 22 ) );
A_Q28[ 0 ] = SKP_SMULWW( r_Q22, SKP_SMULWW( Fc_Q19, Fc_Q19 ) - SKP_FIX_CONST( 2.0, 22 ) );
A_Q28[ 1 ] = SKP_SMULWW( r_Q22, r_Q22 );
/********************************/
......
......@@ -52,7 +52,7 @@ void SKP_Silk_LTP_scale_ctrl_FIX(
/* combine input and filtered input */
g_out_Q5 = SKP_RSHIFT_ROUND( SKP_RSHIFT( psEncCtrl->LTPredCodGain_Q7, 1 ) + SKP_RSHIFT( psEnc->HPLTPredCodGain_Q7, 1 ), 3 );
g_limit_Q15 = SKP_Silk_sigm_Q15( g_out_Q5 - ( 3 << 5 ) ); /* mulitplid with 0.5 */
g_limit_Q15 = SKP_Silk_sigm_Q15( g_out_Q5 - ( 3 << 5 ) );
/* Default is minimum scaling */
psEncCtrl->sCmn.LTP_scaleIndex = 0;
......
......@@ -43,9 +43,8 @@ void SKP_Silk_NLSF_MSVQ_encode_FIX(
const SKP_int deactivate_fluc_red /* I Deactivate fluctuation reduction */
)
{
SKP_int i, s, k, cur_survivors = 0, prev_survivors, input_index, cb_index, bestIndex;
SKP_int i, s, k, cur_survivors = 0, prev_survivors, min_survivors, input_index, cb_index, bestIndex;
SKP_int32 rateDistThreshold_Q18;
SKP_int pNLSF_in_Q15[ MAX_LPC_ORDER ];
#if( NLSF_MSVQ_FLUCTUATION_REDUCTION == 1 )
SKP_int32 se_Q15, wsse_Q20, bestRateDist_Q20;
#endif
......@@ -72,7 +71,7 @@ void SKP_Silk_NLSF_MSVQ_encode_FIX(
const SKP_int *pConstInt;
SKP_int *pInt;
const SKP_int16 *pCB_element;
const SKP_int8 *pCB_element;
const SKP_Silk_NLSF_CBS *pCurrentCBStage;
SKP_assert( NLSF_MSVQ_Survivors <= MAX_NLSF_MSVQ_SURVIVORS );
......@@ -85,25 +84,24 @@ void SKP_Silk_NLSF_MSVQ_encode_FIX(
DEBUG_STORE_DATA( NLSF_mu.dat, &NLSF_mu_Q15, sizeof( SKP_int32 ) );
#endif
/* Copy the input vector */
SKP_memcpy( pNLSF_in_Q15, pNLSF_Q15, LPC_order * sizeof( SKP_int ) );
/****************************************************/
/* Tree search for the multi-stage vector quantizer */
/****************************************************/
/* Clear accumulated rates */
SKP_memset( pRate_Q5, 0, NLSF_MSVQ_Survivors * sizeof( SKP_int32 ) );
/* Copy NLSFs into residual signal vector */
/* Subtract 1/2 from NLSF input vector to create initial residual */
for( i = 0; i < LPC_order; i++ ) {
pRes_Q15[ i ] = pNLSF_Q15[ i ];
pRes_Q15[ i ] = pNLSF_Q15[ i ] - SKP_FIX_CONST( 0.5f, 15 );
}
/* Set first stage values */
prev_survivors = 1;
/* Minimum number of survivors */
min_survivors = NLSF_MSVQ_Survivors / 2;
/* Loop over all stages */
for( s = 0; s < psNLSF_CB->nStages; s++ ) {
......@@ -130,9 +128,10 @@ void SKP_Silk_NLSF_MSVQ_encode_FIX(
prev_survivors * pCurrentCBStage->nVectors, cur_survivors );
/* Discard survivors with rate-distortion values too far above the best one */
if( pRateDist_Q18[ 0 ] < SKP_int32_MAX / NLSF_MSVQ_SURV_MAX_REL_RD ) {
rateDistThreshold_Q18 = SKP_MUL( NLSF_MSVQ_SURV_MAX_REL_RD, pRateDist_Q18[ 0 ] );
while( pRateDist_Q18[ cur_survivors - 1 ] > rateDistThreshold_Q18 && cur_survivors > 1 ) {
if( pRateDist_Q18[ 0 ] < SKP_int32_MAX / MAX_NLSF_MSVQ_SURVIVORS ) {
rateDistThreshold_Q18 = SKP_SMLAWB( pRateDist_Q18[ 0 ],
SKP_MUL( NLSF_MSVQ_Survivors, pRateDist_Q18[ 0 ] ), SKP_FIX_CONST( NLSF_MSVQ_SURV_MAX_REL_RD, 16 ) );
while( pRateDist_Q18[ cur_survivors - 1 ] > rateDistThreshold_Q18 && cur_survivors > min_survivors ) {
cur_survivors--;
}
}
......@@ -155,14 +154,14 @@ void SKP_Silk_NLSF_MSVQ_encode_FIX(
/* Subtract new contribution from the previous residual vector for each of 'cur_survivors' */
pConstInt = &pRes_Q15[ SKP_SMULBB( input_index, LPC_order ) ];
pCB_element = &pCurrentCBStage->CB_NLSF_Q15[ SKP_SMULBB( cb_index, LPC_order ) ];
pCB_element = &pCurrentCBStage->CB_NLSF_Q8[ SKP_SMULBB( cb_index, LPC_order ) ];
pInt = &pRes_new_Q15[ SKP_SMULBB( k, LPC_order ) ];
for( i = 0; i < LPC_order; i++ ) {
pInt[ i ] = pConstInt[ i ] - ( SKP_int )pCB_element[ i ];
pInt[ i ] = pConstInt[ i ] - SKP_LSHIFT16( ( SKP_int )pCB_element[ i ], 7 );
}
/* Update accumulated rate for stage 1 to the current */
pRate_new_Q5[ k ] = pRate_Q5[ input_index ] + pCurrentCBStage->Rates_Q5[ cb_index ];
pRate_new_Q5[ k ] = pRate_Q5[ input_index ] + SKP_LSHIFT32( ( SKP_int32 )pCurrentCBStage->Rates_Q4[ cb_index ], 1 );
/* Copy paths from previous matrix, starting with the best path */
pConstInt = &pPath[ SKP_SMULBB( input_index, psNLSF_CB->nStages ) ];
......
......@@ -43,7 +43,7 @@ void SKP_Silk_NLSF_VQ_rate_distortion_FIX(
SKP_int32 *pRD_vec_Q20;
/* Compute weighted quantization errors for all input vectors over one codebook stage */
SKP_Silk_NLSF_VQ_sum_error_FIX( pRD_Q20, in_Q15, w_Q6, psNLSF_CBS->CB_NLSF_Q15,
SKP_Silk_NLSF_VQ_sum_error_FIX( pRD_Q20, in_Q15, w_Q6, psNLSF_CBS->CB_NLSF_Q8,
N, psNLSF_CBS->nVectors, LPC_order );
/* Loop over input vectors */
......@@ -51,9 +51,9 @@ void SKP_Silk_NLSF_VQ_rate_distortion_FIX(
for( n = 0; n < N; n++ ) {
/* Add rate cost to error for each codebook vector */
for( i = 0; i < psNLSF_CBS->nVectors; i++ ) {
SKP_assert( rate_acc_Q5[ n ] + psNLSF_CBS->Rates_Q5[ i ] >= 0 );
SKP_assert( rate_acc_Q5[ n ] + psNLSF_CBS->Rates_Q5[ i ] <= SKP_int16_MAX );
pRD_vec_Q20[ i ] = SKP_SMLABB( pRD_vec_Q20[ i ], rate_acc_Q5[ n ] + psNLSF_CBS->Rates_Q5[ i ], mu_Q15 );
SKP_assert( rate_acc_Q5[ n ] + SKP_LSHIFT32( ( SKP_int32 )psNLSF_CBS->Rates_Q4[ i ], 1 ) >= 0 );
SKP_assert( rate_acc_Q5[ n ] + SKP_LSHIFT32( ( SKP_int32 )psNLSF_CBS->Rates_Q4[ i ], 1 ) <= SKP_int16_MAX );
pRD_vec_Q20[ i ] = SKP_SMLABB( pRD_vec_Q20[ i ], rate_acc_Q5[ n ] + SKP_LSHIFT32( ( SKP_int32 )psNLSF_CBS->Rates_Q4[ i ], 1 ), mu_Q15 );
SKP_assert( pRD_vec_Q20[ i ] >= 0 );
}
pRD_vec_Q20 += psNLSF_CBS->nVectors;
......
......@@ -32,16 +32,16 @@ void SKP_Silk_NLSF_VQ_sum_error_FIX(
SKP_int32 *err_Q20, /* O Weighted quantization errors [N*K] */
const SKP_int *in_Q15, /* I Input vectors to be quantized [N*LPC_order] */
const SKP_int *w_Q6, /* I Weighting vectors [N*LPC_order] */
const SKP_int16 *pCB_Q15, /* I Codebook vectors [K*LPC_order] */
const SKP_int8 *pCB_Q8, /* 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 */
)
{
SKP_int i, n, m;
SKP_int32 diff_Q15, sum_error, Wtmp_Q6;
SKP_int32 Wcpy_Q6[ MAX_LPC_ORDER / 2 ];
const SKP_int16 *cb_vec_Q15;
SKP_int i, n, m;
SKP_int32 diff_Q15, sum_error, Wtmp_Q6;
SKP_int32 Wcpy_Q6[ MAX_LPC_ORDER / 2 ];
const SKP_int8 *cb_vec_Q8;
SKP_assert( LPC_order <= 16 );
SKP_assert( ( LPC_order & 1 ) == 0 );
......@@ -54,7 +54,7 @@ void SKP_Silk_NLSF_VQ_sum_error_FIX(
/* Loop over input vectors */
for( n = 0; n < N; n++ ) {
/* Loop over codebook */
cb_vec_Q15 = pCB_Q15;
cb_vec_Q8 = pCB_Q8;
for( i = 0; i < K; i++ ) {
sum_error = 0;
for( m = 0; m < LPC_order; m += 2 ) {
......@@ -62,11 +62,11 @@ void SKP_Silk_NLSF_VQ_sum_error_FIX(
Wtmp_Q6 = Wcpy_Q6[ SKP_RSHIFT( m, 1 ) ];
/* Compute weighted squared quantization error for index m */
diff_Q15 = in_Q15[ m ] - *cb_vec_Q15++; // range: [ -32767 : 32767 ]
diff_Q15 = in_Q15[ m ] - SKP_LSHIFT16( ( SKP_int )( *cb_vec_Q8++ ), 7 ); // range: [ -32767 : 32767 ]
sum_error = SKP_SMLAWB( sum_error, SKP_SMULBB( diff_Q15, diff_Q15 ), Wtmp_Q6 );
/* Compute weighted squared quantization error for index m + 1 */
diff_Q15 = in_Q15[m + 1] - *cb_vec_Q15++; // range: [ -32767 : 32767 ]
diff_Q15 = in_Q15[m + 1] - SKP_LSHIFT16( ( SKP_int )( *cb_vec_Q8++ ), 7 ); // range: [ -32767 : 32767 ]
sum_error = SKP_SMLAWT( sum_error, SKP_SMULBB( diff_Q15, diff_Q15 ), Wtmp_Q6 );
}
SKP_assert( sum_error >= 0 );
......
This diff is collapsed.
......@@ -72,6 +72,7 @@ void SKP_Silk_corrMatrix_FIX(
const SKP_int16 *x, /* I x vector [L + order - 1] used to form data matrix X */
const SKP_int L, /* I Length of vectors */
const SKP_int order, /* I Max lag for correlation */
const SKP_int head_room, /* I Desired headroom */
SKP_int32 *XX, /* O Pointer to X'*X correlation matrix [ order x order ]*/
SKP_int *rshifts /* I/O Right shifts of correlations */
)
......@@ -82,9 +83,8 @@ void SKP_Silk_corrMatrix_FIX(
/* Calculate energy to find shift used to fit in 32 bits */
SKP_Silk_sum_sqr_shift( &energy, &rshifts_local, x, L + order - 1 );
/* Add shifts to get the wanted head room */
head_room_rshifts = SKP_max( LTP_CORRS_HEAD_ROOM - SKP_Silk_CLZ32( energy ), 0 );
/* Add shifts to get the desired head room */
head_room_rshifts = SKP_max( head_room - SKP_Silk_CLZ32( energy ), 0 );
energy = SKP_RSHIFT32( energy, head_room_rshifts );
rshifts_local += head_room_rshifts;
......
This diff is collapsed.
......@@ -26,6 +26,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
#include "SKP_Silk_main_FIX.h"
#include "SKP_Silk_tuning_parameters.h"
/* Finds LPC vector from correlations, and converts to NLSF */
void SKP_Silk_find_LPC_FIX(
......@@ -41,7 +42,6 @@ void SKP_Silk_find_LPC_FIX(
{
SKP_int k;
SKP_int32 a_Q16[ MAX_LPC_ORDER ];
SKP_int isInterpLower, shift;
SKP_int16 S[ MAX_LPC_ORDER ];
SKP_int32 res_nrg0, res_nrg1;
......@@ -58,13 +58,17 @@ void SKP_Silk_find_LPC_FIX(
*interpIndex = 4;
/* Burg AR analysis for the full frame */
SKP_Silk_burg_modified( &res_nrg, &res_nrg_Q, a_Q16, x, subfr_length, nb_subfr, FIND_LPC_COND_FAC_Q32, LPC_order );
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( useInterpolatedNLSFs == 1 && 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,
subfr_length, ( MAX_NB_SUBFR >> 1 ), FIND_LPC_COND_FAC_Q32, LPC_order );
subfr_length, ( MAX_NB_SUBFR >> 1 ), SKP_FIX_CONST( FIND_LPC_COND_FAC, 32 ), LPC_order );
SKP_Silk_bwexpander_32( a_tmp_Q16, LPC_order, SKP_FIX_CONST( FIND_LPC_CHIRP, 16 ) );
/* 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 */
......
......@@ -26,6 +26,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
#include "SKP_Silk_main_FIX.h"
#include "SKP_Silk_tuning_parameters.h"
/* Head room for correlations */
#define LTP_CORRS_HEAD_ROOM 2
void SKP_Silk_fit_LTP(
SKP_int32 LTP_coefs_Q16[ LTP_ORDER ],
......@@ -68,22 +72,24 @@ void SKP_Silk_find_LTP_FIX(
lag_ptr = r_ptr - ( lag[ k ] + LTP_ORDER / 2 );
SKP_Silk_sum_sqr_shift( &rr[ k ], &rr_shifts, r_ptr, subfr_length ); /* rr[ k ] in Q( -rr_shifts ) */
/* Assure headroom */
LZs = SKP_Silk_CLZ32( rr[k] );
if( LZs < LTP_CORRS_HEAD_ROOM ) {
rr[ k ] = SKP_RSHIFT_ROUND( rr[ k ], LTP_CORRS_HEAD_ROOM - LZs );
rr_shifts += (LTP_CORRS_HEAD_ROOM - LZs);
rr_shifts += ( LTP_CORRS_HEAD_ROOM - LZs );
}
corr_rshifts[ k ] = rr_shifts;
SKP_Silk_corrMatrix_FIX( lag_ptr, subfr_length, LTP_ORDER, WLTP_ptr, &corr_rshifts[ k ] ); /* WLTP_fix_ptr in Q( -corr_rshifts[ k ] ) */
/* The correlation vector always have lower max abs value than rr and/or RR so head room is assured */
SKP_Silk_corrVector_FIX( lag_ptr, r_ptr, subfr_length, LTP_ORDER, Rr, corr_rshifts[ k ] ); /* Rr_fix_ptr in Q( -corr_rshifts[ k ] ) */
SKP_Silk_corrMatrix_FIX( lag_ptr, subfr_length, LTP_ORDER, LTP_CORRS_HEAD_ROOM, WLTP_ptr, &corr_rshifts[ k ] ); /* WLTP_fix_ptr in Q( -corr_rshifts[ k ] ) */
/* The correlation vector always has lower max abs value than rr and/or RR so head room is assured */
SKP_Silk_corrVector_FIX( lag_ptr, r_ptr, subfr_length, LTP_ORDER, Rr, corr_rshifts[ k ] ); /* Rr_fix_ptr in Q( -corr_rshifts[ k ] ) */
if( corr_rshifts[ k ] > rr_shifts ) {
rr[ k ] = SKP_RSHIFT( rr[ k ], corr_rshifts[ k ] - rr_shifts ); /* rr[ k ] in Q( -corr_rshifts[ k ] ) */
}
SKP_assert( rr[ k ] >= 0 );
regu = SKP_SMULWB( rr[ k ] + 1, LTP_DAMPING_Q16 );
regu = SKP_SMULWB( rr[ k ] + 1, SKP_FIX_CONST( LTP_DAMPING, 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]) */
......@@ -96,12 +102,12 @@ void SKP_Silk_find_LTP_FIX(
/* temp = Wght[ k ] / ( nrg[ k ] * Wght[ k ] + 0.01f * subfr_length ); */
extra_shifts = SKP_min_int( corr_rshifts[ k ], LTP_CORRS_HEAD_ROOM );
denom32 = SKP_LSHIFT_SAT32( SKP_SMULWB( nrg[ k ], Wght_Q15[ k ] ), 1 + extra_shifts ) + /* Q( -corr_rshifts[ k ] + extra_shifts ) */
SKP_RSHIFT( SKP_SMULWB( subfr_length, 655 ), corr_rshifts[ k ] - extra_shifts ); /* Q( -corr_rshifts[ k ] + extra_shifts ) */
denom32 = SKP_LSHIFT_SAT32( SKP_SMULWB( nrg[ k ], Wght_Q15[ k ] ), 1 + extra_shifts ) + /* Q( -corr_rshifts[ k ] + extra_shifts ) */
SKP_RSHIFT( SKP_SMULWB( subfr_length, 655 ), corr_rshifts[ k ] - extra_shifts ); /* Q( -corr_rshifts[ k ] + extra_shifts ) */
denom32 = SKP_max( denom32, 1 );
SKP_assert( ((SKP_int64)Wght_Q15[ k ] << 16 ) < SKP_int32_MAX ); /* Wght always < 0.5 in Q0 */
temp32 = SKP_DIV32( SKP_LSHIFT( ( SKP_int32 )Wght_Q15[ k ], 16 ), denom32 ); /* Q( 15 + 16 + corr_rshifts[k] - extra_shifts ) */
temp32 = SKP_RSHIFT( temp32, 31 + corr_rshifts[ k ] - extra_shifts - 26 ); /* Q26 */
SKP_assert( ((SKP_int64)Wght_Q15[ k ] << 16 ) < SKP_int32_MAX ); /* Wght always < 0.5 in Q0 */
temp32 = SKP_DIV32( SKP_LSHIFT( ( SKP_int32 )Wght_Q15[ k ], 16 ), denom32 ); /* Q( 15 + 16 + corr_rshifts[k] - extra_shifts ) */
temp32 = SKP_RSHIFT( temp32, 31 + corr_rshifts[ k ] - extra_shifts - 26 ); /* Q26 */
/* Limit temp such that the below scaling never wraps around */
WLTP_max = 0;
......@@ -129,7 +135,7 @@ void SKP_Silk_find_LTP_FIX(
maxRshifts = SKP_max_int( corr_rshifts[ k ], maxRshifts );
}
/* compute LTP coding gain */
/* Compute LTP coding gain */
if( LTPredCodGain_Q7 != NULL ) {
LPC_LTP_res_nrg = 0;
LPC_res_nrg = 0;
......@@ -201,8 +207,8 @@ void SKP_Silk_find_LTP_FIX(
g_Q26 = SKP_MUL(
SKP_DIV32(
LTP_SMOOTHING_Q26,
SKP_RSHIFT( LTP_SMOOTHING_Q26, 10 ) + temp32 ), /* Q10 */
SKP_FIX_CONST( LTP_SMOOTHING, 26 ),
SKP_RSHIFT( SKP_FIX_CONST( LTP_SMOOTHING, 26 ), 10 ) + temp32 ), /* Q10 */
SKP_LSHIFT_SAT32( SKP_SUB_SAT32( ( SKP_int32 )m_Q12, SKP_RSHIFT( d_Q14[ k ], 2 ) ), 4 ) ); /* Q16 */
temp32 = 0;
......
......@@ -26,7 +26,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
#include "SKP_Silk_main_FIX.h"
#include "SKP_Silk_common_pitch_est_defines.h"
#include "SKP_Silk_tuning_parameters.h"
/* Find pitch lags */
void SKP_Silk_find_pitch_lags_FIX(
......@@ -38,7 +38,7 @@ void SKP_Silk_find_pitch_lags_FIX(
{
SKP_Silk_predict_state_FIX *psPredSt = &psEnc->sPred;
SKP_int buf_len, i, scale;
SKP_int32 thrhld_Q15;
SKP_int32 thrhld_Q15, res_nrg;
const SKP_int16 *x_buf, *x_buf_ptr;
SKP_int16 Wsig[ FIND_PITCH_LPC_WIN_MAX ], *Wsig_ptr;
SKP_int32 auto_corr[ MAX_FIND_PITCH_LPC_ORDER + 1 ];
......@@ -81,13 +81,16 @@ void SKP_Silk_find_pitch_lags_FIX(
/* Calculate autocorrelation sequence */
SKP_Silk_autocorr( auto_corr, &scale, Wsig, psPredSt->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 ], FIND_PITCH_WHITE_NOISE_FRACTION_Q16 );
/* 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 ) );
/* calculate the reflection coefficients using schur */
SKP_Silk_schur( rc_Q15, auto_corr, psEnc->sCmn.pitchEstimationLPCOrder );
/* Calculate the reflection coefficients using schur */
res_nrg = SKP_Silk_schur( rc_Q15, auto_corr, psEnc->sCmn.pitchEstimationLPCOrder );
/* convert reflection coefficients to prediction coefficients */
/* Prediction gain */
psEncCtrl->predGain_Q16 = SKP_DIV32_varQ( auto_corr[ 0 ], SKP_max_int( res_nrg, 1 ), 16 );
/* Convert reflection coefficients to prediction coefficients */
SKP_Silk_k2a( A_Q24, rc_Q15, psEnc->sCmn.pitchEstimationLPCOrder );
/* Convert From 32 bit Q24 to 16 bit Q12 coefs */
......@@ -96,7 +99,7 @@ void SKP_Silk_find_pitch_lags_FIX(
}
/* Do BWE */
SKP_Silk_bwexpander( A_Q12, psEnc->sCmn.pitchEstimationLPCOrder, FIND_PITCH_BANDWITH_EXPANSION_Q16 );
SKP_Silk_bwexpander( A_Q12, psEnc->sCmn.pitchEstimationLPCOrder, SKP_FIX_CONST( FIND_PITCH_BANDWITH_EXPANSION, 16 ) );
/*****************************************/
/* LPC analysis filtering */
......@@ -106,11 +109,11 @@ void SKP_Silk_find_pitch_lags_FIX(
SKP_memset( res, 0, psEnc->sCmn.pitchEstimationLPCOrder * sizeof( SKP_int16 ) );
/* Threshold for pitch estimator */
thrhld_Q15 = ( 1 << 14 ); // 0.5f in Q15
thrhld_Q15 = SKP_SMLABB( thrhld_Q15, -131, psEnc->sCmn.pitchEstimationLPCOrder );
thrhld_Q15 = SKP_SMLABB( thrhld_Q15, -13, ( SKP_int16 )SKP_Silk_SQRT_APPROX( SKP_LSHIFT( ( SKP_int32 )psEnc->speech_activity_Q8, 8 ) ) );
thrhld_Q15 = SKP_SMLABB( thrhld_Q15, 4587, psEnc->sCmn.prev_sigtype );
thrhld_Q15 = SKP_MLA( thrhld_Q15, -31, SKP_RSHIFT( psEncCtrl->input_tilt_Q15, 8 ) );
thrhld_Q15 = SKP_FIX_CONST( 0.45, 15 );
thrhld_Q15 = SKP_SMLABB( thrhld_Q15, SKP_FIX_CONST( -0.004, 15 ), psEnc->sCmn.pitchEstimationLPCOrder );
thrhld_Q15 = SKP_SMLABB( thrhld_Q15, SKP_FIX_CONST( -0.1, 7 ), psEnc->speech_activity_Q8 );
thrhld_Q15 = SKP_SMLABB( thrhld_Q15, SKP_FIX_CONST( 0.15, 15 ), psEnc->sCmn.prev_sigtype );
thrhld_Q15 = SKP_SMLAWB( thrhld_Q15, SKP_FIX_CONST( -0.1, 16 ), psEncCtrl->input_tilt_Q15 );