FS-3486 --resolve update silk

This commit is contained in:
Brian West 2011-08-25 17:24:46 -05:00
parent b426ec0bfa
commit fdf74f449f
148 changed files with 2723 additions and 7653 deletions

View File

@ -15,34 +15,32 @@ test/SignalCompare.vcproj
lib_LTLIBRARIES = libSKP_SILK_SDK.la
libSKP_SILK_SDK_la_SOURCES = src/SKP_Silk_A2NLSF.c \
src/SKP_Silk_allpass_int.c \
src/SKP_Silk_ana_filt_bank_1.c \
src/SKP_Silk_apply_sine_window.c \
src/SKP_Silk_apply_sine_window_new.c \
src/SKP_Silk_array_maxabs.c \
src/SKP_Silk_autocorr.c \
src/SKP_Silk_biquad_alt.c \
src/SKP_Silk_biquad.c \
src/SKP_Silk_biquad_alt.c \
src/SKP_Silk_burg_modified.c \
src/SKP_Silk_bwexpander_32.c \
src/SKP_Silk_bwexpander.c \
src/SKP_Silk_bwexpander_32.c \
src/SKP_Silk_CNG.c \
src/SKP_Silk_code_signs.c \
src/SKP_Silk_control_audio_bandwidth.c \
src/SKP_Silk_control_codec_FIX.c \
src/SKP_Silk_corrMatrix_FIX.c \
src/SKP_Silk_create_init_destroy.c \
src/SKP_Silk_dec_API.c \
src/SKP_Silk_decode_core.c \
src/SKP_Silk_decode_frame.c \
src/SKP_Silk_decode_indices_v4.c \
src/SKP_Silk_decode_parameters.c \
src/SKP_Silk_decode_parameters_v4.c \
src/SKP_Silk_decode_pitch.c \
src/SKP_Silk_decode_pulses.c \
src/SKP_Silk_decoder_set_fs.c \
src/SKP_Silk_detect_SWB_input.c \
src/SKP_Silk_enc_API.c \
src/SKP_Silk_encode_frame_FIX.c \
src/SKP_Silk_encode_parameters.c \
src/SKP_Silk_encode_parameters_v4.c \
src/SKP_Silk_encode_pulses.c \
src/SKP_Silk_find_LPC_FIX.c \
src/SKP_Silk_find_LTP_FIX.c \
@ -56,78 +54,75 @@ src/SKP_Silk_interpolate.c \
src/SKP_Silk_k2a.c \
src/SKP_Silk_k2a_Q16.c \
src/SKP_Silk_LBRR_reset.c \
src/SKP_Silk_lin2log.c \
src/SKP_Silk_log2lin.c \
src/SKP_Silk_lowpass_int.c \
src/SKP_Silk_lowpass_short.c \
src/SKP_Silk_LPC_inv_pred_gain.c \
src/SKP_Silk_LPC_stabilize.c \
src/SKP_Silk_LPC_synthesis_filter.c \
src/SKP_Silk_LPC_synthesis_order16.c \
src/SKP_Silk_LP_variable_cutoff.c \
src/SKP_Silk_LSF_cos_table.c \
src/SKP_Silk_LTP_analysis_filter_FIX.c \
src/SKP_Silk_LTP_scale_ctrl_FIX.c \
src/SKP_Silk_lin2log.c \
src/SKP_Silk_log2lin.c \
src/SKP_Silk_MA.c \
src/SKP_Silk_NLSF2A.c \
src/SKP_Silk_NLSF2A_stable.c \
src/SKP_Silk_NLSF_MSVQ_decode.c \
src/SKP_Silk_NLSF_MSVQ_encode_FIX.c \
src/SKP_Silk_NLSF_stabilize.c \
src/SKP_Silk_NLSF_VQ_rate_distortion_FIX.c \
src/SKP_Silk_NLSF_VQ_sum_error_FIX.c \
src/SKP_Silk_NLSF_VQ_weights_laroia.c \
src/SKP_Silk_noise_shape_analysis_FIX.c \
src/SKP_Silk_NLSF_stabilize.c \
src/SKP_Silk_NSQ.c \
src/SKP_Silk_NSQ_del_dec.c \
src/SKP_Silk_noise_shape_analysis_FIX.c \
src/SKP_Silk_PLC.c \
src/SKP_Silk_pitch_analysis_core.c \
src/SKP_Silk_pitch_est_tables.c \
src/SKP_Silk_PLC.c \
src/SKP_Silk_prefilter_FIX.c \
src/SKP_Silk_process_gains_FIX.c \
src/SKP_Silk_process_NLSFs_FIX.c \
src/SKP_Silk_pulses_to_bytes.c \
src/SKP_Silk_process_gains_FIX.c \
src/SKP_Silk_quant_LTP_gains_FIX.c \
src/SKP_Silk_range_coder.c \
src/SKP_Silk_regularize_correlations_FIX.c \
src/SKP_Silk_resample_1_2.c \
src/SKP_Silk_resample_1_2_coarse.c \
src/SKP_Silk_resample_1_2_coarsest.c \
src/SKP_Silk_resample_1_3.c \
src/SKP_Silk_resample_2_1_coarse.c \
src/SKP_Silk_resample_2_3.c \
src/SKP_Silk_resample_2_3_coarse.c \
src/SKP_Silk_resample_2_3_coarsest.c \
src/SKP_Silk_resample_2_3_rom.c \
src/SKP_Silk_resample_3_1.c \
src/SKP_Silk_resample_3_2.c \
src/SKP_Silk_resample_3_2_rom.c \
src/SKP_Silk_resample_3_4.c \
src/SKP_Silk_resample_4_3.c \
src/SKP_Silk_resampler.c \
src/SKP_Silk_resampler_down2.c \
src/SKP_Silk_resampler_down2_3.c \
src/SKP_Silk_resampler_down3.c \
src/SKP_Silk_resampler_private_AR2.c \
src/SKP_Silk_resampler_private_ARMA4.c \
src/SKP_Silk_resampler_private_IIR_FIR.c \
src/SKP_Silk_resampler_private_copy.c \
src/SKP_Silk_resampler_private_down4.c \
src/SKP_Silk_resampler_private_down_FIR.c \
src/SKP_Silk_resampler_private_up2_HQ.c \
src/SKP_Silk_resampler_private_up4.c \
src/SKP_Silk_resampler_rom.c \
src/SKP_Silk_resampler_up2.c \
src/SKP_Silk_residual_energy16_FIX.c \
src/SKP_Silk_residual_energy_FIX.c \
src/SKP_Silk_scale_copy_vector16.c \
src/SKP_Silk_scale_vector.c \
src/SKP_Silk_schur64.c \
src/SKP_Silk_schur.c \
src/SKP_Silk_schur64.c \
src/SKP_Silk_shell_coder.c \
src/SKP_Silk_sigm_Q15.c \
src/SKP_Silk_solve_LS_FIX.c \
src/SKP_Silk_sort.c \
src/SKP_Silk_sum_sqr_shift.c \
src/SKP_Silk_tables_gain.c \
src/SKP_Silk_tables_LTP.c \
src/SKP_Silk_tables_NLSF_CB0_10.c \
src/SKP_Silk_tables_NLSF_CB0_16.c \
src/SKP_Silk_tables_NLSF_CB1_10.c \
src/SKP_Silk_tables_NLSF_CB1_16.c \
src/SKP_Silk_tables_gain.c \
src/SKP_Silk_tables_other.c \
src/SKP_Silk_tables_pitch_lag.c \
src/SKP_Silk_tables_pulses_per_block.c \
src/SKP_Silk_tables_sign.c \
src/SKP_Silk_tables_type_offset.c \
src/SKP_Silk_VAD.c \
src/SKP_Silk_VQ_nearest_neighbor_FIX.c
src/SKP_Silk_VQ_nearest_neighbor_FIX.c \
src/SKP_Silk_warped_autocorrelation_FIX.c
libSKP_SILK_SDK_la_CFLAGS = $(AM_CFLAGS)
@ -135,24 +130,26 @@ libSKP_SILK_SDK_la_LDFLAGS = $(LIBS)
library_includedir = $(prefix)/include/silk
library_include_HEADERS = src/SKP_Silk_common_pitch_est_defines.h \
src/SKP_Silk_define_FIX.h \
src/SKP_Silk_define.h \
src/SKP_Silk_Inlines.h \
src/SKP_Silk_macros.h \
src/SKP_Silk_main_FIX.h \
src/SKP_Silk_main.h \
src/SKP_Silk_perceptual_parameters_FIX.h \
src/SKP_Silk_main_FIX.h \
src/SKP_Silk_pitch_est_defines.h \
src/SKP_Silk_PLC.h \
src/SKP_Silk_resample_rom.h \
src/SKP_Silk_resampler_private.h \
src/SKP_Silk_resampler_rom.h \
src/SKP_Silk_resampler_structs.h \
src/SKP_Silk_SigProc_FIX.h \
src/SKP_Silk_structs_FIX.h \
src/SKP_Silk_setup_complexity.h \
src/SKP_Silk_structs.h \
src/SKP_Silk_structs_FIX.h \
src/SKP_Silk_tables.h \
src/SKP_Silk_tables_NLSF_CB0_10.h \
src/SKP_Silk_tables_NLSF_CB0_16.h \
src/SKP_Silk_tables_NLSF_CB1_10.h \
src/SKP_Silk_tables_NLSF_CB1_16.h \
src/SKP_Silk_tuning_parameters.h \
interface/SKP_Silk_control.h \
interface/SKP_Silk_errors.h \
interface/SKP_Silk_SDK_API.h \

View File

@ -2,8 +2,8 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.59])
AC_INIT(libSKP_SILK_SDK, 1.0.2, brian@freeswitch.org, libSKP_SILK_SDK)
AM_INIT_AUTOMAKE(libSKP_SILK_SDK,1.0.2)
AC_INIT(libSKP_SILK_SDK, 1.0.8, brian@freeswitch.org, libSKP_SILK_SDK)
AM_INIT_AUTOMAKE(libSKP_SILK_SDK,1.0.8)
# Checks for programs.
AC_PROG_CC

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -39,7 +39,7 @@ extern "C"
#define SILK_MAX_FRAMES_PER_PACKET 5
/* Struct for TOC (Table Of Contents) */
/* Struct for TOC (Table of Contents) */
typedef struct {
SKP_int framesInPacket; /* Number of 20 ms frames in packet */
SKP_int fs_kHz; /* Sampling frequency in packet */
@ -85,7 +85,7 @@ SKP_int SKP_Silk_SDK_Encode(
const SKP_int16 *samplesIn, /* I: Speech sample input vector */
SKP_int nSamplesIn, /* I: Number of samples in input vector */
SKP_uint8 *outData, /* O: Encoded output vector */
SKP_int16 *nBytesOut /* I/O: Number of Bytes in outData (input: Max Bytes) */
SKP_int16 *nBytesOut /* I/O: Number of bytes in outData (input: Max bytes) */
);
/****************************************/
@ -114,7 +114,7 @@ SKP_int SKP_Silk_SDK_Decode(
SKP_SILK_SDK_DecControlStruct* decControl, /* I/O: Control Structure */
SKP_int lostFlag, /* I: 0: no loss, 1 loss */
const SKP_uint8 *inData, /* I: Encoded input vector */
const SKP_int nBytesIn, /* I: Number of input Bytes */
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) */
);
@ -123,22 +123,20 @@ SKP_int SKP_Silk_SDK_Decode(
/* Find Low Bit Rate Redundancy (LBRR) information in a packet */
/***************************************************************/
void SKP_Silk_SDK_search_for_LBRR(
void *decState, /* I: Decoder state, to select bitstream version only */
const SKP_uint8 *inData, /* I: Encoded input vector */
const SKP_int16 nBytesIn, /* I: Number of input Bytes */
const SKP_int 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 */
);
/************************************/
/* Get type of content for a packet */
/************************************/
/**************************************/
/* Get table of contents for a packet */
/**************************************/
void SKP_Silk_SDK_get_TOC(
void *decState, /* I: Decoder state, to select bitstream version only */
const SKP_uint8 *inData, /* I: Encoded input vector */
const SKP_int16 nBytesIn, /* I: Number of input bytes */
SKP_Silk_TOC_struct *Silk_TOC /* O: Type of content */
const SKP_int nBytesIn, /* I: Number of input bytes */
SKP_Silk_TOC_struct *Silk_TOC /* O: Table of contents */
);
/**************************/

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -39,8 +39,11 @@ extern "C"
/* Structure for controlling encoder operation */
/***********************************************/
typedef struct {
/* I: Sampling rate in Hertz; 8000/12000/16000/24000 */
SKP_int32 sampleRate;
/* I: Input signal sampling rate in Hertz; 8000/12000/16000/24000 */
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;
@ -48,7 +51,7 @@ typedef struct {
/* I: Bitrate during active speech in bits/second; internally limited */
SKP_int32 bitRate;
/* I: Uplink Packet loss in pct (0...100) */
/* I: Uplink packet loss in percent (0-100) */
SKP_int packetLossPercentage;
/* I: Complexity mode; 0 is lowest; 1 is medium and 2 is highest complexity */
@ -57,7 +60,7 @@ typedef struct {
/* I: Flag to enable in-band Forward Error Correction (FEC); 0/1 */
SKP_int useInBandFEC;
/* I: Flag to enable Discontinous Transmission; 0/1 */
/* I: Flag to enable discontinuous transmission (DTX); 0/1 */
SKP_int useDTX;
} SKP_SILK_SDK_EncControlStruct;
@ -65,8 +68,8 @@ typedef struct {
/* Structure for controlling decoder operation and reading decoder status */
/**************************************************************************/
typedef struct {
/* I: Sampling rate in Hertz; 8000/12000/16000/24000 */
SKP_int32 sampleRate;
/* I: Output signal sampling rate in Hertz; 8000/12000/16000/24000 */
SKP_int32 API_sampleRate;
/* O: Number of samples per frame */
SKP_int frameSize;

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -36,48 +36,45 @@ extern "C"
/******************/
/* Error messages */
/******************/
#define SKP_SILK_NO_ERROR 0
#define SKP_SILK_NO_ERROR 0
/**************************/
/* Encoder error messages */
/**************************/
/* 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
/* 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
/* Sampling frequency not 8000, 12000, 16000
or 24000 Hertz */
#define SKP_SILK_ENC_FS_NOT_SUPPORTED -2
/* Sampling frequency not 8000, 12000, 16000 or 24000 Hertz */
#define SKP_SILK_ENC_FS_NOT_SUPPORTED -2
/* 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 -3
/* Allocated payload buffer too short */
#define SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT -4
#define SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT -4
/* Loss rate not between 0 and 100 percent */
#define SKP_SILK_ENC_WRONG_LOSS_RATE -5
#define SKP_SILK_ENC_INVALID_LOSS_RATE -5
/* Complexity setting not valid, use 0, 1 or 2 */
#define SKP_SILK_ENC_WRONG_COMPLEXITY_SETTING -6
#define SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING -6
/* Inband FEC setting not valid, use 0 or 1 */
#define SKP_SILK_ENC_WRONG_INBAND_FEC_SETTING -7
#define SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING -7
/* DTX setting not valid, use 0 or 1 */
#define SKP_SILK_ENC_WRONG_DTX_SETTING -8
#define SKP_SILK_ENC_INVALID_DTX_SETTING -8
/* Internal encoder error */
#define SKP_SILK_ENC_INTERNAL_ERROR -9
#define SKP_SILK_ENC_INTERNAL_ERROR -9
/**************************/
/* Decoder error messages */
/**************************/
/* Output sampling frequency lower than internal
decoded sampling frequency */
#define SKP_SILK_DEC_WRONG_SAMPLING_FREQUENCY -10
/* Output sampling frequency lower than internal decoded sampling frequency */
#define SKP_SILK_DEC_INVALID_SAMPLING_FREQUENCY -10
/* Payload size exceeded the maximum allowed 1024 bytes */
#define SKP_SILK_DEC_PAYLOAD_TOO_LARGE -11
@ -85,7 +82,6 @@ extern "C"
/* Payload has bit errors */
#define SKP_SILK_DEC_PAYLOAD_ERROR -12
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:

View File

@ -1,14 +1,14 @@
************************************************************************
Fixed Point SILK SDK 1.0.2 beta source code package
Fixed Point SILK SDK 1.0.8 beta source code package
Copyright 2010 (c), Skype Limited
https://developer.skype.com/silk/
************************************************************************
Date: 09/03/2010 (Format: DD/MM/YYYY)
Date: 15/06/2011 (Format: DD/MM/YYYY)
I. Description
This package contains files for compiling and testing the fixed
This package contains files for compilation and evaluation of the fixed
point SILK SDK library. The following is included in this package:
o Source code for the fixed point SILK SDK library
@ -51,22 +51,38 @@ III. How to use the Makefile
make clean all
6. How to use the comparison tool:
6. How to build for big endian CPU's
Make clean all ADDED_DEFINES+=_SYSTEM_IS_BIG_ENDIAN
To be able to use the test vectors with big endian CPU's the test programs
need to be compiled in a different way. Note that the 16 bit input and output
from the test programs will have the upper and lower bytes swapped with this setting.
7. How to use the comparison tool:
See 'How to use the test vectors.txt' in the test_vectors folder.
IV. History
Version 1.0.8 - Improved noise shaping, various other improvements, and various bugfixes. Added a MIPS version
Version 1.0.7 - Updated with bugfixes for LBRR and pitch estimator. SignalCompare updated
Version 1.0.6 - Updated with bugfixes for ARM builds
Version 1.0.5 - Updated with bugfixes for ARM builds
Version 1.0.4 - Updated with various bugfixes and improvements, including some API changes
Added support for big endian platforms
Added resampler support for additional API sample rates
Version 1.0.3 - Updated with various bugfixes and improvements
Version 1.0.2 - Updated with various bugfixes and improvements
Version 1.0.1 - First beta source code release
V. Compatibility
This package has been tested under the following platforms:
This package has been tested on the following platforms:
Windows XP Home and Professional
Windows Vista, 32-bit version
Mac OS X Version 10.5.8
Mac OSX intel
Mac OSX ppc
Ubuntu Linux 9.10, 64-bit version
VI. Known Issues

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -33,10 +33,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SKP_Silk_SigProc_FIX.h"
/* Number of binary divisions, when not in low complexity mode */
#define BIN_DIV_STEPS_A2NLSF_FIX 2 /* must be no higher than 16 - log2( LSF_COS_TAB_SZ_FIX ) */
/* Number of binary divisions */
#define BIN_DIV_STEPS_A2NLSF_FIX 3 /* must be no higher than 16 - log2( LSF_COS_TAB_SZ_FIX ) */
#define QPoly 16
#define MAX_ITERATIONS_A2NLSF_FIX 50
#define MAX_ITERATIONS_A2NLSF_FIX 30
/* Flag for using 2x as many cosine sampling points, reduces the risk of missing a root */
#define OVERSAMPLE_COSINE_TABLE 0
@ -57,12 +57,11 @@ SKP_INLINE void SKP_Silk_A2NLSF_trans_poly(
p[ k - 2 ] -= SKP_LSHIFT( p[ k ], 1 );
}
}
/* Helper function for A2NLSF(..) */
/* Polynomial evaluation */
SKP_INLINE SKP_int32 SKP_Silk_A2NLSF_eval_poly( /* return the polynomial evaluation, in QPoly */
SKP_int32 *p, /* I Polynomial, QPoly */
const SKP_int32 x, /* I Evaluation point, Q12 */
const SKP_int32 x, /* I Evaluation point, Q12 */
const SKP_int dd /* I Order */
)
{
@ -79,9 +78,9 @@ SKP_INLINE SKP_int32 SKP_Silk_A2NLSF_eval_poly( /* return the polynomial eval
SKP_INLINE void SKP_Silk_A2NLSF_init(
const SKP_int32 *a_Q16,
SKP_int32 *P,
SKP_int32 *Q,
const SKP_int dd
SKP_int32 *P,
SKP_int32 *Q,
const SKP_int dd
)
{
SKP_int k;
@ -127,8 +126,8 @@ void SKP_Silk_A2NLSF(
SKP_int32 xlo, xhi, xmid;
SKP_int32 ylo, yhi, ymid;
SKP_int32 nom, den;
SKP_int32 P[ SigProc_MAX_ORDER_LPC / 2 + 1 ];
SKP_int32 Q[ SigProc_MAX_ORDER_LPC / 2 + 1 ];
SKP_int32 P[ SKP_Silk_MAX_ORDER_LPC / 2 + 1 ];
SKP_int32 Q[ SKP_Silk_MAX_ORDER_LPC / 2 + 1 ];
SKP_int32 *PQ[ 2 ];
SKP_int32 *p;
@ -258,7 +257,7 @@ void SKP_Silk_A2NLSF(
}
/* Error: Apply progressively more bandwidth expansion and run again */
SKP_Silk_bwexpander_32( a_Q16, d, 65536 - SKP_SMULBB( 66, i ) ); // 66_Q16 = 0.001
SKP_Silk_bwexpander_32( a_Q16, d, 65536 - SKP_SMULBB( 10 + i, i ) ); // 10_Q16 = 0.00015
SKP_Silk_A2NLSF_init( a_Q16, P, Q, dd );
p = P; /* Pointer to polynomial */
@ -269,9 +268,9 @@ void SKP_Silk_A2NLSF(
NLSF[ 0 ] = 0;
p = Q; /* Pointer to polynomial */
ylo = SKP_Silk_A2NLSF_eval_poly( p, xlo, dd );
root_ix = 1; /* Index of current root */
root_ix = 1; /* Index of current root */
} else {
root_ix = 0; /* Index of current root */
root_ix = 0; /* Index of current root */
}
k = 1; /* Reset loop counter */
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -25,7 +25,7 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
#include "SKP_Silk_main_FIX.h"
#include "SKP_Silk_main.h"
/* Generates excitation for CNG LPC synthesis */
SKP_INLINE void SKP_Silk_CNG_exc(

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -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( 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( 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 );
/********************************/

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -57,20 +57,15 @@ SKP_INLINE void SKP_Silk_CLZ_FRAC(SKP_int32 in, /* I: input */
SKP_int32 *lz, /* O: number of leading zeros */
SKP_int32 *frac_Q7) /* O: the 7 bits right after the leading one */
{
SKP_int32 leadingZeros;
SKP_int32 lzeros = SKP_Silk_CLZ32(in);
leadingZeros = SKP_Silk_CLZ32(in);
*lz = leadingZeros;
if( leadingZeros < 24 ) {
*frac_Q7 = SKP_RSHIFT(in, 24 - leadingZeros) & 0x7F;
} else {
*frac_Q7 = SKP_LSHIFT(in, leadingZeros - 24) & 0x7F;
}
* lz = lzeros;
* frac_Q7 = SKP_ROR32(in, 24 - lzeros) & 0x7f;
}
/* Approximation of square root */
/* Accuracy: < +/- 10% for output values > 15 */
/* < +/- 2.5% for output values > 120 */
/* Accuracy: < +/- 10% for output values > 15 */
/* < +/- 2.5% for output values > 120 */
SKP_INLINE SKP_int32 SKP_Silk_SQRT_APPROX(SKP_int32 x)
{
SKP_int32 y, lz, frac_Q7;
@ -125,9 +120,9 @@ SKP_INLINE SKP_int32 SKP_Silk_norm32(SKP_int32 a) {
/* Divide two int32 values and return result as int32 in a given Q-domain */
SKP_INLINE SKP_int32 SKP_DIV32_varQ( /* O returns a good approximation of "(a32 << Qres) / b32" */
const SKP_int32 a32, /* I numerator (Q0) */
const SKP_int32 b32, /* I denominator (Q0) */
const SKP_int Qres /* I Q-domain of result (>= 0) */
const SKP_int32 a32, /* I numerator (Q0) */
const SKP_int32 b32, /* I denominator (Q0) */
const SKP_int Qres /* I Q-domain of result (>= 0) */
)
{
SKP_int a_headrm, b_headrm, lshift;
@ -170,14 +165,15 @@ SKP_INLINE SKP_int32 SKP_DIV32_varQ( /* O returns a good approximation of
/* Invert int32 value and return result as int32 in a given Q-domain */
SKP_INLINE SKP_int32 SKP_INVERSE32_varQ( /* O returns a good approximation of "(1 << Qres) / b32" */
const SKP_int32 b32, /* I denominator (Q0) */
const SKP_int Qres /* I Q-domain of result (> 0) */
const SKP_int32 b32, /* I denominator (Q0) */
const SKP_int Qres /* I Q-domain of result (> 0) */
)
{
SKP_int b_headrm, lshift;
SKP_int32 b32_inv, b32_nrm, err_Q32, result;
SKP_assert( b32 != 0 );
SKP_assert( b32 != SKP_int32_MIN ); /* SKP_int32_MIN is not handled by SKP_abs */
SKP_assert( Qres > 0 );
/* Compute number of bits head room and normalize input */
@ -277,4 +273,4 @@ SKP_INLINE SKP_int32 SKP_Silk_COS_APPROX_Q24( /* O returns approximate
}
#endif
#endif //_SKP_SILK_FIX_INLINES_H_
#endif /*_SKP_SILK_FIX_INLINES_H_*/

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -31,30 +31,27 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* Compute inverse of LPC prediction gain, and *
* test if LPC coefficients are stable (all poles within unit circle) *
* *
* Copyright 2008 (c), Skype Limited *
* Copyright 2008 (c), Skype Limited *
* */
#include "SKP_Silk_SigProc_FIX.h"
#define QA 16
#define A_LIMIT 65520
#define A_LIMIT SKP_FIX_CONST( 0.99975, QA )
/* Compute inverse of LPC prediction gain, and */
/* test if LPC coefficients are stable (all poles within unit circle) */
SKP_int SKP_Silk_LPC_inverse_pred_gain( /* O: Returns 1 if unstable, otherwise 0 */
static SKP_int LPC_inverse_pred_gain_QA( /* O: Returns 1 if unstable, otherwise 0 */
SKP_int32 *invGain_Q30, /* O: Inverse prediction gain, Q30 energy domain */
const SKP_int16 *A_Q12, /* I: Prediction coefficients, Q12 [order] */
SKP_int32 A_QA[ 2 ][ SKP_Silk_MAX_ORDER_LPC ],
/* I: Prediction coefficients */
const SKP_int order /* I: Prediction order */
)
{
SKP_int k, n, headrm;
SKP_int32 rc_Q31, rc_mult1_Q30, rc_mult2_Q16;
SKP_int32 Atmp_QA[ 2 ][ SigProc_MAX_ORDER_LPC ], tmp_QA;
SKP_int32 rc_Q31, rc_mult1_Q30, rc_mult2_Q16, tmp_QA;
SKP_int32 *Aold_QA, *Anew_QA;
Anew_QA = Atmp_QA[ order & 1 ];
/* Increase Q domain of the AR coefficients */
for( k = 0; k < order; k++ ) {
Anew_QA[ k ] = SKP_LSHIFT( (SKP_int32)A_Q12[ k ], QA - 12 );
}
Anew_QA = A_QA[ order & 1 ];
*invGain_Q30 = ( 1 << 30 );
for( k = order - 1; k > 0; k-- ) {
@ -82,7 +79,7 @@ SKP_int SKP_Silk_LPC_inverse_pred_gain( /* O: Returns 1 if unstable, oth
/* Swap pointers */
Aold_QA = Anew_QA;
Anew_QA = Atmp_QA[ k & 1 ];
Anew_QA = A_QA[ k & 1 ];
/* Update AR coefficient */
headrm = SKP_Silk_CLZ32( rc_mult2_Q16 ) - 1;
@ -112,78 +109,45 @@ SKP_int SKP_Silk_LPC_inverse_pred_gain( /* O: Returns 1 if unstable, oth
return 0;
}
/* For input in Q13 domain */
SKP_int SKP_Silk_LPC_inverse_pred_gain_Q13( /* O: Returns 1 if unstable, otherwise 0 */
/* For input in Q12 domain */
SKP_int SKP_Silk_LPC_inverse_pred_gain( /* O: Returns 1 if unstable, otherwise 0 */
SKP_int32 *invGain_Q30, /* O: Inverse prediction gain, Q30 energy domain */
const SKP_int16 *A_Q13, /* I: Prediction coefficients, Q13 [order] */
const SKP_int16 *A_Q12, /* I: Prediction coefficients, Q12 [order] */
const SKP_int order /* I: Prediction order */
)
{
SKP_int k, n, headrm;
SKP_int32 rc_Q31, rc_mult1_Q30, rc_mult2_Q16;
SKP_int32 Atmp_QA[ 2 ][ SigProc_MAX_ORDER_LPC ], tmp_QA;
SKP_int32 *Aold_QA, *Anew_QA;
SKP_int k;
SKP_int32 Atmp_QA[ 2 ][ SKP_Silk_MAX_ORDER_LPC ];
SKP_int32 *Anew_QA;
Anew_QA = Atmp_QA[ order & 1 ];
/* Increase Q domain of the AR coefficients */
for( k = 0; k < order; k++ ) {
Anew_QA[ k ] = SKP_LSHIFT( (SKP_int32)A_Q13[ k ], QA - 13 );
Anew_QA[ k ] = SKP_LSHIFT( (SKP_int32)A_Q12[ k ], QA - 12 );
}
*invGain_Q30 = ( 1 << 30 );
for( k = order - 1; k > 0; k-- ) {
/* Check for stability */
if( ( Anew_QA[ k ] > A_LIMIT ) || ( Anew_QA[ k ] < -A_LIMIT ) ) {
return 1;
}
/* Set RC equal to negated AR coef */
rc_Q31 = -SKP_LSHIFT( Anew_QA[ k ], 31 - QA );
/* rc_mult1_Q30 range: [ 1 : 2^30-1 ] */
rc_mult1_Q30 = ( SKP_int32_MAX >> 1 ) - SKP_SMMUL( rc_Q31, rc_Q31 );
SKP_assert( rc_mult1_Q30 > ( 1 << 15 ) ); /* reduce A_LIMIT if fails */
SKP_assert( rc_mult1_Q30 < ( 1 << 30 ) );
/* rc_mult2_Q16 range: [ 2^16 : SKP_int32_MAX ] */
rc_mult2_Q16 = SKP_INVERSE32_varQ( rc_mult1_Q30, 46 ); /* 16 = 46 - 30 */
/* Update inverse gain */
/* invGain_Q30 range: [ 0 : 2^30 ] */
*invGain_Q30 = SKP_LSHIFT( SKP_SMMUL( *invGain_Q30, rc_mult1_Q30 ), 2 );
SKP_assert( *invGain_Q30 >= 0 );
SKP_assert( *invGain_Q30 <= 1<<30 );
/* Swap pointers */
Aold_QA = Anew_QA;
Anew_QA = Atmp_QA[ k & 1 ];
/* Update AR coefficient */
headrm = SKP_Silk_CLZ32( rc_mult2_Q16 ) - 1;
rc_mult2_Q16 = SKP_LSHIFT( rc_mult2_Q16, headrm ); /* Q: 16 + headrm */
for( n = 0; n < k; n++ ) {
tmp_QA = Aold_QA[ n ] - SKP_LSHIFT( SKP_SMMUL( Aold_QA[ k - n - 1 ], rc_Q31 ), 1 );
Anew_QA[ n ] = SKP_LSHIFT( SKP_SMMUL( tmp_QA, rc_mult2_Q16 ), 16 - headrm );
}
}
/* Check for stability */
if( ( Anew_QA[ 0 ] > A_LIMIT ) || ( Anew_QA[ 0 ] < -A_LIMIT ) ) {
return 1;
}
/* Set RC equal to negated AR coef */
rc_Q31 = -SKP_LSHIFT( Anew_QA[ 0 ], 31 - QA );
/* Range: [ 1 : 2^30 ] */
rc_mult1_Q30 = ( SKP_int32_MAX >> 1 ) - SKP_SMMUL( rc_Q31, rc_Q31 );
/* Update inverse gain */
/* Range: [ 0 : 2^30 ] */
*invGain_Q30 = SKP_LSHIFT( SKP_SMMUL( *invGain_Q30, rc_mult1_Q30 ), 2 );
SKP_assert( *invGain_Q30 >= 0 );
SKP_assert( *invGain_Q30 <= 1<<30 );
return 0;
return LPC_inverse_pred_gain_QA( invGain_Q30, Atmp_QA, order );
}
/* For input in Q24 domain */
SKP_int SKP_Silk_LPC_inverse_pred_gain_Q24( /* O: Returns 1 if unstable, otherwise 0 */
SKP_int32 *invGain_Q30, /* O: Inverse prediction gain, Q30 energy domain */
const SKP_int32 *A_Q24, /* I: Prediction coefficients, Q24 [order] */
const SKP_int order /* I: Prediction order */
)
{
SKP_int k;
SKP_int32 Atmp_QA[ 2 ][ SKP_Silk_MAX_ORDER_LPC ];
SKP_int32 *Anew_QA;
Anew_QA = Atmp_QA[ order & 1 ];
/* Increase Q domain of the AR coefficients */
for( k = 0; k < order; k++ ) {
Anew_QA[ k ] = SKP_RSHIFT_ROUND( A_Q24[ k ], 24 - QA );
}
return LPC_inverse_pred_gain_QA( invGain_Q30, Atmp_QA, order );
}

View File

@ -1,132 +0,0 @@
/***********************************************************************
Copyright (c) 2006-2010, 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_typedef.h"
#include "SKP_Silk_SigProc_FIX.h"
#define LPC_STABILIZE_LPC_MAX_ABS_VALUE_Q16 ( ( (SKP_int32)SKP_int16_MAX ) << 4 )
/* LPC stabilizer, for a single input data vector */
void SKP_Silk_LPC_stabilize(
SKP_int16 *a_Q12, /* O stabilized LPC vector [L] */
SKP_int32 *a_Q16, /* I LPC vector [L] */
const SKP_int32 bwe_Q16, /* I Bandwidth expansion factor */
const SKP_int L /* I Number of LPC parameters in the input vector */
)
{
SKP_int32 maxabs, absval, sc_Q16;
SKP_int i, idx = 0;
SKP_int32 invGain_Q30;
SKP_Silk_bwexpander_32( a_Q16, L, bwe_Q16 );
/***************************/
/* Limit range of the LPCs */
/***************************/
/* Limit the maximum absolute value of the prediction coefficients */
while( SKP_TRUE ) {
/* Find maximum absolute value and its index */
maxabs = SKP_int32_MIN;
for( i = 0; i < L; i++ ) {
absval = SKP_abs( a_Q16[ i ] );
if( absval > maxabs ) {
maxabs = absval;
idx = i;
}
}
if( maxabs >= LPC_STABILIZE_LPC_MAX_ABS_VALUE_Q16 ) {
/* Reduce magnitude of prediction coefficients */
sc_Q16 = SKP_DIV32( SKP_int32_MAX, SKP_RSHIFT( maxabs, 4 ) );
sc_Q16 = 65536 - sc_Q16;
sc_Q16 = SKP_DIV32( sc_Q16, idx + 1 );
sc_Q16 = 65536 - sc_Q16;
sc_Q16 = SKP_LSHIFT( SKP_SMULWB( sc_Q16, 32604 ), 1 ); // 0.995 in Q16
SKP_Silk_bwexpander_32( a_Q16, L, sc_Q16 );
} else {
break;
}
}
/* Convert to 16 bit Q12 */
for( i = 0; i < L; i++ ) {
a_Q12[ i ] = (SKP_int16)SKP_RSHIFT_ROUND( a_Q16[ i ], 4 );
}
/**********************/
/* Ensure stable LPCs */
/**********************/
while( SKP_Silk_LPC_inverse_pred_gain( &invGain_Q30, a_Q12, L ) == 1 ) {
SKP_Silk_bwexpander( a_Q12, L, 65339 ); // 0.997 in Q16
}
}
void SKP_Silk_LPC_fit(
SKP_int16 *a_QQ, /* O Stabilized LPC vector, Q(24-rshift) [L] */
SKP_int32 *a_Q24, /* I LPC vector [L] */
const SKP_int QQ, /* I Q domain of output LPC vector */
const SKP_int L /* I Number of LPC parameters in the input vector */
)
{
SKP_int i, rshift, idx = 0;
SKP_int32 maxabs, absval, sc_Q16;
rshift = 24 - QQ;
/***************************/
/* Limit range of the LPCs */
/***************************/
/* Limit the maximum absolute value of the prediction coefficients */
while( SKP_TRUE ) {
/* Find maximum absolute value and its index */
maxabs = SKP_int32_MIN;
for( i = 0; i < L; i++ ) {
absval = SKP_abs( a_Q24[ i ] );
if( absval > maxabs ) {
maxabs = absval;
idx = i;
}
}
maxabs = SKP_RSHIFT( maxabs, rshift );
if( maxabs >= SKP_int16_MAX ) {
/* Reduce magnitude of prediction coefficients */
sc_Q16 = 65470 - SKP_DIV32( SKP_MUL( 65470 >> 2, maxabs - SKP_int16_MAX ),
SKP_RSHIFT32( SKP_MUL( maxabs, idx + 1), 2 ) );
SKP_Silk_bwexpander_32( a_Q24, L, sc_Q16 );
} else {
break;
}
}
/* Convert to 16 bit Q(24-rshift) */
SKP_assert( rshift > 0 );
SKP_assert( rshift < 31 );
for( i = 0; i < L; i++ ) {
a_QQ[ i ] = (SKP_int16)SKP_RSHIFT_ROUND( a_Q24[ i ], rshift );
}
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -45,54 +45,40 @@ void SKP_Silk_LPC_synthesis_filter(
)
{
SKP_int k, j, idx, Order_half = SKP_RSHIFT( Order, 1 );
SKP_int32 SA, SB, Atmp, A_align_Q12[SigProc_MAX_ORDER_LPC >> 1], out32_Q10, out32;
SKP_int32 SA, SB, out32_Q10, out32;
/* Order must be even */
SKP_assert( 2*Order_half == Order );
/* combine two A_Q12 values and ensure 32-bit alignment */
for( k = 0; k < Order_half; k++ ) {
idx = SKP_SMULBB( 2, k );
A_align_Q12[k] = (((SKP_int32)A_Q12[idx]) & 0x0000ffff) | SKP_LSHIFT( (SKP_int32)A_Q12[idx+1], 16 );
}
SKP_assert( 2 * Order_half == Order );
/* S[] values are in Q14 */
for( k = 0; k < len; k++ ) {
SA = S[Order-1];
SA = S[ Order - 1 ];
out32_Q10 = 0;
for( j=0;j<(Order_half-1); j++ ) {
for( j = 0; j < ( Order_half - 1 ); j++ ) {
idx = SKP_SMULBB( 2, j ) + 1;
/* multiply-add two prediction coefficients for each loop */
/* NOTE: the code below loads two int16 values in an int32, and multiplies each using the */
/* SMLAWB and SMLAWT instructions. On a big-endian CPU the two int16 variables would be */
/* loaded in reverse order and the code will give the wrong result. In that case swapping */
/* the SMLAWB and SMLAWT instructions should solve the problem. */
Atmp = A_align_Q12[j];
SB = S[Order - 1 - idx];
S[Order - 1 - idx] = SA;
out32_Q10 = SKP_SMLAWB( out32_Q10, SA, Atmp );
out32_Q10 = SKP_SMLAWT( out32_Q10, SB, Atmp );
SA = S[Order - 2 - idx];
S[Order - 2 - idx] = SB;
SB = S[ Order - 1 - idx ];
S[ Order - 1 - idx ] = SA;
out32_Q10 = SKP_SMLAWB( out32_Q10, SA, A_Q12[ ( j << 1 ) ] );
out32_Q10 = SKP_SMLAWB( out32_Q10, SB, A_Q12[ ( j << 1 ) + 1 ] );
SA = S[ Order - 2 - idx ];
S[ Order - 2 - idx ] = SB;
}
/* unrolled loop: epilog */
Atmp = A_align_Q12[Order_half-1];
SB = S[0];
S[0] = SA;
out32_Q10 = SKP_SMLAWB( out32_Q10, SA, Atmp );
out32_Q10 = SKP_SMLAWT( out32_Q10, SB, Atmp );
SB = S[ 0 ];
S[ 0 ] = SA;
out32_Q10 = SKP_SMLAWB( out32_Q10, SA, A_Q12[ Order - 2 ] );
out32_Q10 = SKP_SMLAWB( out32_Q10, SB, A_Q12[ Order - 1 ] );
/* apply gain to excitation signal and add to prediction */
out32_Q10 = SKP_ADD_SAT32( out32_Q10, SKP_SMULWB( Gain_Q26, in[k] ) );
out32_Q10 = SKP_ADD_SAT32( out32_Q10, SKP_SMULWB( Gain_Q26, in[ k ] ) );
/* scale to Q0 */
out32 = SKP_RSHIFT_ROUND( out32_Q10, 10 );
/* saturate output */
out[k] = (SKP_int16)SKP_SAT16( out32 );
out[ k ] = ( SKP_int16 )SKP_SAT16( out32 );
/* move result into delay line */
S[Order - 1] = SKP_LSHIFT_SAT32( out32_Q10, 4 );
S[ Order - 1 ] = SKP_LSHIFT_SAT32( out32_Q10, 4 );
}
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -43,98 +43,79 @@ void SKP_Silk_LPC_synthesis_order16(const SKP_int16 *in, /* I: excita
)
{
SKP_int k;
SKP_int32 SA, SB, Atmp, A_align_Q12[8], out32_Q10, out32;
/* combine two A_Q12 values and ensure 32-bit alignment */
for( k = 0; k < 8; k++ ) {
A_align_Q12[k] = (((SKP_int32)A_Q12[ 2*k ]) & 0x0000ffff) | SKP_LSHIFT( (SKP_int32)A_Q12[ 2*k + 1 ], 16 );
}
/* S[] values are in Q14 */
/* NOTE: the code below loads two int16 values in an int32, and multiplies each using the */
/* SMLAWB and SMLAWT instructions. On a big-endian CPU the two int16 variables would be */
/* loaded in reverse order and the code will give the wrong result. In that case swapping */
/* the SMLAWB and SMLAWT instructions should solve the problem. */
SKP_int32 SA, SB, out32_Q10, out32;
for( k = 0; k < len; k++ ) {
/* unrolled loop: prolog */
/* multiply-add two prediction coefficients per iteration */
SA = S[15];
Atmp = A_align_Q12[0];
SB = S[14];
S[14] = SA;
out32_Q10 = SKP_SMULWB( SA, Atmp );
out32_Q10 = SKP_SMLAWT_ovflw( out32_Q10, SB, Atmp );
SA = S[13];
S[13] = SB;
SA = S[ 15 ];
SB = S[ 14 ];
S[ 14 ] = SA;
out32_Q10 = SKP_SMULWB( SA, A_Q12[ 0 ] );
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 1 ] );
SA = S[ 13 ];
S[ 13 ] = SB;
/* unrolled loop: main loop */
Atmp = A_align_Q12[1];
SB = S[12];
S[12] = SA;
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, Atmp );
out32_Q10 = SKP_SMLAWT_ovflw( out32_Q10, SB, Atmp );
SA = S[11];
S[11] = SB;
SB = S[ 12 ];
S[ 12 ] = SA;
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 2 ] );
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 3 ] );
SA = S[ 11 ];
S[ 11 ] = SB;
Atmp = A_align_Q12[2];
SB = S[10];
S[10] = SA;
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, Atmp );
out32_Q10 = SKP_SMLAWT_ovflw( out32_Q10, SB, Atmp );
SA = S[9];
S[9] = SB;
SB = S[ 10 ];
S[ 10 ] = SA;
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 4 ] );
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 5 ] );
SA = S[ 9 ];
S[ 9 ] = SB;
Atmp = A_align_Q12[3];
SB = S[8];
S[8] = SA;
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, Atmp );
out32_Q10 = SKP_SMLAWT_ovflw( out32_Q10, SB, Atmp );
SA = S[7];
S[7] = SB;
SB = S[ 8 ];
S[ 8 ] = SA;
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 6 ] );
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 7 ] );
SA = S[ 7 ];
S[ 7 ] = SB;
Atmp = A_align_Q12[4];
SB = S[6];
S[6] = SA;
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, Atmp );
out32_Q10 = SKP_SMLAWT_ovflw( out32_Q10, SB, Atmp );
SA = S[5];
S[5] = SB;
SB = S[ 6 ];
S[ 6 ] = SA;
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 8 ] );
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 9 ] );
SA = S[ 5 ];
S[ 5 ] = SB;
Atmp = A_align_Q12[5];
SB = S[4];
S[4] = SA;
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, Atmp );
out32_Q10 = SKP_SMLAWT_ovflw( out32_Q10, SB, Atmp );
SA = S[3];
S[3] = SB;
SB = S[ 4 ];
S[ 4 ] = SA;
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 10 ] );
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 11 ] );
SA = S[ 3 ];
S[ 3 ] = SB;
Atmp = A_align_Q12[6];
SB = S[2];
S[2] = SA;
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, Atmp );
out32_Q10 = SKP_SMLAWT_ovflw( out32_Q10, SB, Atmp );
SA = S[1];
S[1] = SB;
SB = S[ 2 ];
S[ 2 ] = SA;
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 12 ] );
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 13 ] );
SA = S[ 1 ];
S[ 1 ] = SB;
/* unrolled loop: epilog */
Atmp = A_align_Q12[7];
SB = S[0];
S[0] = SA;
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, Atmp );
out32_Q10 = SKP_SMLAWT_ovflw( out32_Q10, SB, Atmp );
SB = S[ 0 ];
S[ 0 ] = SA;
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SA, A_Q12[ 14 ] );
out32_Q10 = SKP_SMLAWB_ovflw( out32_Q10, SB, A_Q12[ 15 ] );
/* unrolled loop: end */
/* apply gain to excitation signal and add to prediction */
out32_Q10 = SKP_ADD_SAT32( out32_Q10, SKP_SMULWB( Gain_Q26, in[k] ) );
out32_Q10 = SKP_ADD_SAT32( out32_Q10, SKP_SMULWB( Gain_Q26, in[ k ] ) );
/* scale to Q0 */
out32 = SKP_RSHIFT_ROUND( out32_Q10, 10 );
/* saturate output */
out[k] = (SKP_int16)SKP_SAT16( out32 );
out[ k ] = ( SKP_int16 )SKP_SAT16( out32 );
/* move result into delay line */
S[15] = SKP_LSHIFT_SAT32( out32_Q10, 4 );
S[ 15 ] = SKP_LSHIFT_SAT32( out32_Q10, 4 );
}
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -119,8 +119,8 @@ void SKP_Silk_LP_variable_cutoff(
const SKP_int frame_length /* I Frame length */
)
{
SKP_int32 B_Q28[ TRANSITION_NB ], A_Q28[ TRANSITION_NA ];
SKP_int fac_Q16 = 0, ind = 0;
SKP_int32 B_Q28[ TRANSITION_NB ], A_Q28[ TRANSITION_NA ], fac_Q16 = 0;
SKP_int ind = 0;
SKP_assert( psLP->transition_frame_no >= 0 );
SKP_assert( ( ( ( psLP->transition_frame_no <= TRANSITION_FRAMES_DOWN ) && ( psLP->mode == 0 ) ) ||
@ -148,11 +148,13 @@ void SKP_Silk_LP_variable_cutoff(
/* Increment transition frame number for next frame */
psLP->transition_frame_no++;
} else if( psLP->transition_frame_no == TRANSITION_FRAMES_DOWN ) {
} else {
SKP_assert( psLP->transition_frame_no == TRANSITION_FRAMES_DOWN );
/* End of transition phase */
SKP_Silk_LP_interpolate_filter_taps( B_Q28, A_Q28, TRANSITION_INT_NUM - 1, 0 );
}
} else if( psLP->mode == 1 ) {
} else {
SKP_assert( psLP->mode == 1 );
if( psLP->transition_frame_no < TRANSITION_FRAMES_UP ) {
/* Calculate index and interpolation factor for interpolation */
#if( TRANSITION_INT_STEPS_UP == 64 )
@ -172,7 +174,8 @@ void SKP_Silk_LP_variable_cutoff(
/* Increment transition frame number for next frame */
psLP->transition_frame_no++;
} else if( psLP->transition_frame_no == TRANSITION_FRAMES_UP ) {
} else {
SKP_assert( psLP->transition_frame_no == TRANSITION_FRAMES_UP );
/* End of transition phase */
SKP_Silk_LP_interpolate_filter_taps( B_Q28, A_Q28, 0, 0 );
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -32,8 +32,7 @@ void SKP_Silk_LTP_analysis_filter_FIX(
const SKP_int16 *x, /* I: Pointer to input signal with at least max( pitchL ) preceeding samples */
const SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],/* I: LTP_ORDER LTP coefficients for each NB_SUBFR subframe */
const SKP_int pitchL[ NB_SUBFR ], /* I: Pitch lag, one for each subframe */
const SKP_int32 invGains_Qxx[ NB_SUBFR ], /* I: Inverse quantization gains, one for each subframe */
const SKP_int Qxx, /* I: Inverse quantization gains Q domain */
const SKP_int32 invGains_Q16[ NB_SUBFR ], /* I: Inverse quantization gains, one for each subframe */
const SKP_int subfr_length, /* I: Length of each subframe */
const SKP_int pre_length /* I: Length of the preceeding samples starting at &x[0] for each subframe */
)
@ -61,18 +60,14 @@ void SKP_Silk_LTP_analysis_filter_FIX(
LTP_est = SKP_SMULBB( x_lag_ptr[ LTP_ORDER / 2 ], Btmp_Q14[ 0 ] );
for( j = 1; j < LTP_ORDER; j++ ) {
LTP_est = SKP_SMLABB_ovflw( LTP_est, x_lag_ptr[ LTP_ORDER / 2 - j ], Btmp_Q14[ j ] );
}
}
LTP_est = SKP_RSHIFT_ROUND( LTP_est, 14 ); // round and -> Q0
/* Subtract long-term prediction */
LTP_res_ptr[ i ] = ( SKP_int16 )SKP_SAT16( ( SKP_int32 )x_ptr[ i ] - LTP_est );
/* Scale residual */
if( Qxx == 16 ) {
LTP_res_ptr[ i ] = SKP_SMULWB( invGains_Qxx[ k ], LTP_res_ptr[ i ] );
} else {
LTP_res_ptr[ i ] = ( SKP_int16 )SKP_CHECK_FIT16( SKP_RSHIFT64( SKP_SMULL( invGains_Qxx[ k ], LTP_res_ptr[ i ] ), Qxx ) );
}
LTP_res_ptr[ i ] = SKP_SMULWB( invGains_Q16[ k ], LTP_res_ptr[ i ] );
x_lag_ptr++;
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -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;

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -35,33 +35,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* */
#include "SKP_Silk_SigProc_FIX.h"
/* Variable order MA filter */
void SKP_Silk_MA(
const SKP_int16 *in, /* I: input signal */
const SKP_int16 *B, /* I: MA coefficients, Q13 [order+1] */
SKP_int32 *S, /* I/O: state vector [order] */
SKP_int16 *out, /* O: output signal */
const SKP_int32 len, /* I: signal length */
const SKP_int32 order /* I: filter order */
)
{
SKP_int k, d, in16;
SKP_int32 out32;
for( k = 0; k < len; k++ ) {
in16 = in[ k ];
out32 = SKP_SMLABB( S[ 0 ], in16, B[ 0 ] );
out32 = SKP_RSHIFT_ROUND( out32, 13 );
for( d = 1; d < order; d++ ) {
S[ d - 1 ] = SKP_SMLABB( S[ d ], in16, B[ d ] );
}
S[ order - 1 ] = SKP_SMULBB( in16, B[ order ] );
/* Limit */
out[ k ] = (SKP_int16)SKP_SAT16( out32 );
}
}
/* Variable order MA prediction error filter */
void SKP_Silk_MA_Prediction(
const SKP_int16 *in, /* I: Input signal */
@ -74,105 +47,23 @@ void SKP_Silk_MA_Prediction(
{
SKP_int k, d, in16;
SKP_int32 out32;
SKP_int32 B32;
if( ( order & 1 ) == 0 && (SKP_int32)( (SKP_int_ptr_size)B & 3 ) == 0 ) {
/* Even order and 4-byte aligned coefficient array */
/* NOTE: the code below loads two int16 values in an int32, and multiplies each using the */
/* SMLABB and SMLABT instructions. On a big-endian CPU the two int16 variables would be */
/* loaded in reverse order and the code will give the wrong result. In that case swapping */
/* the SMLABB and SMLABT instructions should solve the problem. */
for( k = 0; k < len; k++ ) {
in16 = in[ k ];
out32 = SKP_LSHIFT( in16, 12 ) - S[ 0 ];
out32 = SKP_RSHIFT_ROUND( out32, 12 );
for( d = 0; d < order - 2; d += 2 ) {
B32 = *( (SKP_int32*)&B[ d ] ); /* read two coefficients at once */
S[ d ] = SKP_SMLABB_ovflw( S[ d + 1 ], in16, B32 );
S[ d + 1 ] = SKP_SMLABT_ovflw( S[ d + 2 ], in16, B32 );
}
B32 = *( (SKP_int32*)&B[ d ] ); /* read two coefficients at once */
S[ order - 2 ] = SKP_SMLABB_ovflw( S[ order - 1 ], in16, B32 );
S[ order - 1 ] = SKP_SMULBT( in16, B32 );
/* Limit */
out[ k ] = (SKP_int16)SKP_SAT16( out32 );
}
} else {
/* Odd order or not 4-byte aligned coefficient array */
for( k = 0; k < len; k++ ) {
in16 = in[ k ];
out32 = SKP_LSHIFT( in16, 12 ) - S[ 0 ];
out32 = SKP_RSHIFT_ROUND( out32, 12 );
for( d = 0; d < order - 1; d++ ) {
S[ d ] = SKP_SMLABB_ovflw( S[ d + 1 ], in16, B[ d ] );
}
S[ order - 1 ] = SKP_SMULBB( in16, B[ order - 1 ] );
/* Limit */
out[ k ] = (SKP_int16)SKP_SAT16( out32 );
}
}
}
void SKP_Silk_MA_Prediction_Q13(
const SKP_int16 *in, /* I: input signal */
const SKP_int16 *B, /* I: MA prediction coefficients, Q13 [order] */
SKP_int32 *S, /* I/O: state vector [order] */
SKP_int16 *out, /* O: output signal */
SKP_int32 len, /* I: signal length */
SKP_int32 order /* I: filter order */
)
{
SKP_int k, d, in16;
SKP_int32 out32, B32;
if( ( order & 1 ) == 0 && (SKP_int32)( (SKP_int_ptr_size)B & 3 ) == 0 ) {
/* Even order and 4-byte aligned coefficient array */
for( k = 0; k < len; k++ ) {
in16 = in[ k ];
out32 = SKP_LSHIFT( in16, 12 ) - S[ 0 ];
out32 = SKP_RSHIFT_ROUND( out32, 12 );
/* NOTE: the code below loads two int16 values in an int32, and multiplies each using the */
/* SMLABB and SMLABT instructions. On a big-endian CPU the two int16 variables would be */
/* loaded in reverse order and the code will give the wrong result. In that case swapping */
/* the SMLABB and SMLABT instructions should solve the problem. */
for( k = 0; k < len; k++ ) {
in16 = in[ k ];
out32 = SKP_LSHIFT( in16, 13 ) - S[ 0 ];
out32 = SKP_RSHIFT_ROUND( out32, 13 );
for( d = 0; d < order - 2; d += 2 ) {
B32 = *( (SKP_int32*)&B[ d ] ); /* read two coefficients at once */
S[ d ] = SKP_SMLABB( S[ d + 1 ], in16, B32 );
S[ d + 1 ] = SKP_SMLABT( S[ d + 2 ], in16, B32 );
}
B32 = *( (SKP_int32*)&B[ d ] ); /* read two coefficients at once */
S[ order - 2 ] = SKP_SMLABB( S[ order - 1 ], in16, B32 );
S[ order - 1 ] = SKP_SMULBT( in16, B32 );
/* Limit */
out[ k ] = (SKP_int16)SKP_SAT16( out32 );
for( d = 0; d < order - 1; d++ ) {
S[ d ] = SKP_SMLABB_ovflw( S[ d + 1 ], in16, B[ d ] );
}
} else {
/* Odd order or not 4-byte aligned coefficient array */
for( k = 0; k < len; k++ ) {
in16 = in[ k ];
out32 = SKP_LSHIFT( in16, 13 ) - S[ 0 ];
out32 = SKP_RSHIFT_ROUND( out32, 13 );
for( d = 0; d < order - 1; d++ ) {
S[ d ] = SKP_SMLABB( S[ d + 1 ], in16, B[ d ] );
}
S[ order - 1 ] = SKP_SMULBB( in16, B[ order - 1 ] );
S[ order - 1 ] = SKP_SMULBB( in16, B[ order - 1 ] );
/* Limit */
out[ k ] = (SKP_int16)SKP_SAT16( out32 );
}
/* Limit */
out[ k ] = (SKP_int16)SKP_SAT16( out32 );
}
}
/* Variable order MA prediction error filter. */
/* Inverse filter of SKP_Silk_LPC_synthesis_filter */
void SKP_Silk_LPC_analysis_filter(
const SKP_int16 *in, /* I: Input signal */
const SKP_int16 *B, /* I: MA prediction coefficients, Q12 [order] */
@ -183,17 +74,11 @@ void SKP_Silk_LPC_analysis_filter(
)
{
SKP_int k, j, idx, Order_half = SKP_RSHIFT( Order, 1 );
SKP_int32 Btmp, B_align_Q12[ SigProc_MAX_ORDER_LPC >> 1 ], out32_Q12, out32;
SKP_int32 out32_Q12, out32;
SKP_int16 SA, SB;
/* Order must be even */
SKP_assert( 2 * Order_half == Order );
/* Combine two A_Q12 values and ensure 32-bit alignment */
for( k = 0; k < Order_half; k++ ) {
idx = SKP_SMULBB( 2, k );
B_align_Q12[ k ] = ( ( (SKP_int32)B[ idx ] ) & 0x0000ffff ) | SKP_LSHIFT( (SKP_int32)B[ idx + 1 ], 16 );
}
/* S[] values are in Q0 */
for( k = 0; k < len; k++ ) {
SA = S[ 0 ];
@ -201,21 +86,19 @@ void SKP_Silk_LPC_analysis_filter(
for( j = 0; j < ( Order_half - 1 ); j++ ) {
idx = SKP_SMULBB( 2, j ) + 1;
/* Multiply-add two prediction coefficients for each loop */
Btmp = B_align_Q12[ j ];
SB = S[ idx ];
S[ idx ] = SA;
out32_Q12 = SKP_SMLABB( out32_Q12, SA, Btmp );
out32_Q12 = SKP_SMLABT( out32_Q12, SB, Btmp );
out32_Q12 = SKP_SMLABB( out32_Q12, SA, B[ idx - 1 ] );
out32_Q12 = SKP_SMLABB( out32_Q12, SB, B[ idx ] );
SA = S[ idx + 1 ];
S[ idx + 1 ] = SB;
}
/* Unrolled loop: epilog */
Btmp = B_align_Q12[ Order_half - 1 ];
SB = S[ Order - 1 ];
S[ Order - 1 ] = SA;
out32_Q12 = SKP_SMLABB( out32_Q12, SA, Btmp );
out32_Q12 = SKP_SMLABT( out32_Q12, SB, Btmp );
out32_Q12 = SKP_SMLABB( out32_Q12, SA, B[ Order - 2 ] );
out32_Q12 = SKP_SMLABB( out32_Q12, SB, B[ Order - 1 ] );
/* Subtract prediction */
out32_Q12 = SKP_SUB_SAT32( SKP_LSHIFT( (SKP_int32)in[ k ], 12 ), out32_Q12 );
@ -224,7 +107,7 @@ void SKP_Silk_LPC_analysis_filter(
out32 = SKP_RSHIFT_ROUND( out32_Q12, 12 );
/* Saturate output */
out[ k ] = (SKP_int16)SKP_SAT16( out32 );
out[ k ] = ( SKP_int16 )SKP_SAT16( out32 );
/* Move input line */
S[ 0 ] = in[ k ];

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -63,13 +63,13 @@ void SKP_Silk_NLSF2A(
)
{
SKP_int k, i, dd;
SKP_int32 cos_LSF_Q20[SigProc_MAX_ORDER_LPC];
SKP_int32 P[SigProc_MAX_ORDER_LPC/2+1], Q[SigProc_MAX_ORDER_LPC/2+1];
SKP_int32 cos_LSF_Q20[SKP_Silk_MAX_ORDER_LPC];
SKP_int32 P[SKP_Silk_MAX_ORDER_LPC/2+1], Q[SKP_Silk_MAX_ORDER_LPC/2+1];
SKP_int32 Ptmp, Qtmp;
SKP_int32 f_int;
SKP_int32 f_frac;
SKP_int32 cos_val, delta;
SKP_int32 a_int32[SigProc_MAX_ORDER_LPC];
SKP_int32 a_int32[SKP_Silk_MAX_ORDER_LPC];
SKP_int32 maxabs, absval, idx=0, sc_Q16;
SKP_assert(LSF_COS_TAB_SZ_FIX == 128);
@ -127,6 +127,7 @@ void SKP_Silk_NLSF2A(
if( maxabs > SKP_int16_MAX ) {
/* Reduce magnitude of prediction coefficients */
maxabs = SKP_min( maxabs, 98369 ); // ( SKP_int32_MAX / ( 65470 >> 2 ) ) + SKP_int16_MAX = 98369
sc_Q16 = 65470 - SKP_DIV32( SKP_MUL( 65470 >> 2, maxabs - SKP_int16_MAX ),
SKP_RSHIFT32( SKP_MUL( maxabs, idx + 1), 2 ) );
SKP_Silk_bwexpander_32( a_int32, d, sc_Q16 );

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -42,7 +42,7 @@ void SKP_Silk_NLSF2A_stable(
/* Ensure stable LPCs */
for( i = 0; i < MAX_LPC_STABILIZE_ITERATIONS; i++ ) {
if( SKP_Silk_LPC_inverse_pred_gain( &invGain_Q30, pAR_Q12, LPC_order ) == 1 ) {
SKP_Silk_bwexpander( pAR_Q12, LPC_order, 65536 - SKP_SMULBB( 66, i ) ); /* 66_Q16 = 0.001 */
SKP_Silk_bwexpander( pAR_Q12, LPC_order, 65536 - SKP_SMULBB( 10 + i, i ) ); /* 10_Q16 = 0.00015 */
} else {
break;
}
@ -50,6 +50,7 @@ void SKP_Silk_NLSF2A_stable(
/* Reached the last iteration */
if( i == MAX_LPC_STABILIZE_ITERATIONS ) {
SKP_assert( 0 );
for( i = 0; i < LPC_order; i++ ) {
pAR_Q12[ i ] = 0;
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -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
@ -75,14 +74,15 @@ void SKP_Silk_NLSF_MSVQ_encode_FIX(
const SKP_int16 *pCB_element;
const SKP_Silk_NLSF_CBS *pCurrentCBStage;
#ifdef USE_UNQUANTIZED_LSFS
SKP_int NLSF_orig[ MAX_LPC_ORDER ];
SKP_memcpy( NLSF_orig, pNLSF_Q15, LPC_order * sizeof( SKP_int ) );
#endif
SKP_assert( NLSF_MSVQ_Survivors <= MAX_NLSF_MSVQ_SURVIVORS );
SKP_assert( ( LOW_COMPLEXITY_ONLY == 0 ) || ( NLSF_MSVQ_Survivors <= MAX_NLSF_MSVQ_SURVIVORS_LC_MODE ) );
/* Copy the input vector */
SKP_memcpy( pNLSF_in_Q15, pNLSF_Q15, LPC_order * sizeof( SKP_int ) );
/****************************************************/
/* Tree search for the multi-stage vector quantizer */
/****************************************************/
@ -98,6 +98,9 @@ void SKP_Silk_NLSF_MSVQ_encode_FIX(
/* 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++ ) {
@ -124,9 +127,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--;
}
}
@ -228,4 +232,8 @@ void SKP_Silk_NLSF_MSVQ_encode_FIX(
/* Decode and stabilize the best survivor */
SKP_Silk_NLSF_MSVQ_decode( pNLSF_Q15, psNLSF_CB, NLSFIndices, LPC_order );
#ifdef USE_UNQUANTIZED_LSFS
SKP_memcpy( pNLSF_Q15, NLSF_orig, LPC_order * sizeof( SKP_int ) );
#endif
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -27,6 +27,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SKP_Silk_main_FIX.h"
/* 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] */
@ -77,3 +78,4 @@ void SKP_Silk_NLSF_VQ_sum_error_FIX(
}
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -34,6 +34,7 @@ Signal Processing, pp. 641-644, 1991.
*/
#define Q_OUT 6
#define MIN_NDELTA 3
/* Laroia low complexity NLSF weights */
void SKP_Silk_NLSF_VQ_weights_laroia(
@ -50,28 +51,28 @@ void SKP_Silk_NLSF_VQ_weights_laroia(
SKP_assert( ( D & 1 ) == 0 );
/* First value */
tmp1_int = SKP_max_int( pNLSF_Q15[ 0 ], 1 );
tmp1_int = SKP_max_int( pNLSF_Q15[ 0 ], MIN_NDELTA );
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_max_int( pNLSF_Q15[ 1 ] - pNLSF_Q15[ 0 ], MIN_NDELTA );
tmp2_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp2_int );
pNLSFW_Q6[ 0 ] = (SKP_int)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX );
SKP_assert( pNLSFW_Q6[ 0 ] > 0 );
/* Main loop */
for( k = 1; k < D - 1; k += 2 ) {
tmp1_int = SKP_max_int( pNLSF_Q15[ k + 1 ] - pNLSF_Q15[ k ], 1 );
tmp1_int = SKP_max_int( pNLSF_Q15[ k + 1 ] - pNLSF_Q15[ k ], MIN_NDELTA );
tmp1_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp1_int );
pNLSFW_Q6[ k ] = (SKP_int)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX );
SKP_assert( pNLSFW_Q6[ k ] > 0 );
tmp2_int = SKP_max_int( pNLSF_Q15[ k + 2 ] - pNLSF_Q15[ k + 1 ], 1 );
tmp2_int = SKP_max_int( pNLSF_Q15[ k + 2 ] - pNLSF_Q15[ k + 1 ], MIN_NDELTA );
tmp2_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp2_int );
pNLSFW_Q6[ k + 1 ] = (SKP_int)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX );
SKP_assert( pNLSFW_Q6[ k + 1 ] > 0 );
}
/* Last value */
tmp1_int = SKP_max_int( ( 1 << 15 ) - pNLSF_Q15[ D - 1 ], 1 );
tmp1_int = SKP_max_int( ( 1 << 15 ) - pNLSF_Q15[ D - 1 ], MIN_NDELTA );
tmp1_int = SKP_DIV32_16( 1 << ( 15 + Q_OUT ), tmp1_int );
pNLSFW_Q6[ D - 1 ] = (SKP_int)SKP_min_int( tmp1_int + tmp2_int, SKP_int16_MAX );
SKP_assert( pNLSFW_Q6[ D - 1 ] > 0 );

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -106,7 +106,7 @@ void SKP_Silk_NLSF_stabilize(
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( SKP_RSHIFT_ROUND( (SKP_int32)NLSF_Q15[I-1] + (SKP_int32)NLSF_Q15[I], 1 ),
center_freq_Q15 = 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];
@ -137,18 +137,3 @@ void SKP_Silk_NLSF_stabilize(
}
}
/* 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 );
}
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -31,8 +31,8 @@ SKP_INLINE void SKP_Silk_nsq_scale_states(
SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */
const SKP_int16 x[], /* I input in Q0 */
SKP_int32 x_sc_Q10[], /* O input scaled with 1/Gain */
SKP_int length, /* I length of input */
SKP_int16 sLTP[], /* I re-whitened LTP state in Q0 */
SKP_int subfr_length, /* I length of input */
const SKP_int16 sLTP[], /* I re-whitened LTP state in Q0 */
SKP_int32 sLTP_Q16[], /* O LTP state matching scaled input */
SKP_int subfr, /* I subframe number */
const SKP_int LTP_scale_Q14, /* I */
@ -44,7 +44,7 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer(
SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */
SKP_int sigtype, /* I Signal type */
const SKP_int32 x_sc_Q10[], /* I */
SKP_int q[], /* O */
SKP_int8 q[], /* O */
SKP_int16 xq[], /* O */
SKP_int32 sLTP_Q16[], /* I/O LTP state */
const SKP_int16 a_Q12[], /* I Short term prediction coefs */
@ -67,11 +67,11 @@ void SKP_Silk_NSQ(
SKP_Silk_encoder_control *psEncCtrlC, /* I Encoder Control */
SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */
const SKP_int16 x[], /* I prefiltered input signal */
SKP_int q[], /* O quantized qulse signal */
SKP_int8 q[], /* O quantized qulse signal */
const SKP_int LSFInterpFactor_Q2, /* I LSF interpolation factor in Q2 */
const SKP_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefficients */
const SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ], /* I Long term prediction coefficients */
const SKP_int16 AR2_Q13[ NB_SUBFR * SHAPE_LPC_ORDER_MAX ], /* I */
const SKP_int16 AR2_Q13[ NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I */
const SKP_int HarmShapeGain_Q14[ NB_SUBFR ], /* I */
const SKP_int Tilt_Q14[ NB_SUBFR ], /* I Spectral tilt */
const SKP_int32 LF_shp_Q14[ NB_SUBFR ], /* I */
@ -113,25 +113,26 @@ void SKP_Silk_NSQ(
for( k = 0; k < NB_SUBFR; k++ ) {
A_Q12 = &PredCoef_Q12[ (( k >> 1 ) | ( 1 - LSF_interpolation_flag )) * MAX_LPC_ORDER ];
B_Q14 = &LTPCoef_Q14[ k * LTP_ORDER ];
AR_shp_Q13 = &AR2_Q13[ k * SHAPE_LPC_ORDER_MAX ];
AR_shp_Q13 = &AR2_Q13[ k * MAX_SHAPE_LPC_ORDER ];
/* Noise shape parameters */
SKP_assert( HarmShapeGain_Q14[ k ] >= 0 );
HarmShapeFIRPacked_Q14 = SKP_RSHIFT( HarmShapeGain_Q14[ k ], 2 );
HarmShapeFIRPacked_Q14 = SKP_RSHIFT( HarmShapeGain_Q14[ k ], 2 );
HarmShapeFIRPacked_Q14 |= SKP_LSHIFT( ( SKP_int32 )SKP_RSHIFT( HarmShapeGain_Q14[ k ], 1 ), 16 );
NSQ->rewhite_flag = 0;
if( psEncCtrlC->sigtype == SIG_TYPE_VOICED ) {
/* Voiced */
lag = psEncCtrlC->pitchL[ k ];
NSQ->rewhite_flag = 0;
/* Re-whitening */
if( ( k & ( 3 - SKP_LSHIFT( LSF_interpolation_flag, 1 ) ) ) == 0 ) {
/* Rewhiten with new A coefs */
start_idx = psEncC->frame_length - lag - psEncC->predictLPCOrder - LTP_ORDER / 2;
start_idx = SKP_LIMIT( start_idx, 0, psEncC->frame_length - psEncC->predictLPCOrder ); /* Limit */
SKP_assert( start_idx >= 0 );
SKP_assert( start_idx <= psEncC->frame_length - psEncC->predictLPCOrder );
SKP_memset( FiltState, 0, psEncC->predictLPCOrder * sizeof( SKP_int32 ) );
SKP_Silk_MA_Prediction( &NSQ->xq[ start_idx + k * ( psEncC->frame_length >> 2 ) ],
A_Q12, FiltState, sLTP + start_idx, psEncC->frame_length - start_idx, psEncC->predictLPCOrder );
@ -154,14 +155,17 @@ void SKP_Silk_NSQ(
pxq += psEncC->subfr_length;
}
/* Save scalars for this layer */
NSQ->sLF_AR_shp_Q12 = NSQ->sLF_AR_shp_Q12;
NSQ->prev_inv_gain_Q16 = NSQ->prev_inv_gain_Q16;
NSQ->lagPrev = psEncCtrlC->pitchL[ NB_SUBFR - 1 ];
/* Update lagPrev for next frame */
NSQ->lagPrev = psEncCtrlC->pitchL[ NB_SUBFR - 1 ];
/* Save quantized speech and noise shaping signals */
SKP_memcpy( NSQ->xq, &NSQ->xq[ psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int16 ) );
SKP_memcpy( NSQ->sLTP_shp_Q10, &NSQ->sLTP_shp_Q10[ psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int32 ) );
#ifdef USE_UNQUANTIZED_LSFS
DEBUG_STORE_DATA( xq_unq_lsfs.pcm, NSQ->xq, psEncC->frame_length * sizeof( SKP_int16 ) );
#endif
}
/***********************************/
@ -171,7 +175,7 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer(
SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */
SKP_int sigtype, /* I Signal type */
const SKP_int32 x_sc_Q10[], /* I */
SKP_int q[], /* O */
SKP_int8 q[], /* O */
SKP_int16 xq[], /* O */
SKP_int32 sLTP_Q16[], /* I/O LTP state */
const SKP_int16 a_Q12[], /* I Short term prediction coefs */
@ -193,29 +197,22 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer(
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 Atmp, dither;
SKP_int32 exc_Q10, LPC_exc_Q10, xq_Q10;
SKP_int32 tmp, sLF_AR_shp_Q10;
SKP_int32 *psLPC_Q14;
SKP_int32 *shp_lag_ptr, *pred_lag_ptr;
SKP_int32 a_Q12_tmp[ MAX_LPC_ORDER / 2 ], AR_shp_Q13_tmp[ MAX_LPC_ORDER / 2 ];
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;
shp_lag_ptr = &NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - lag + HARM_SHAPE_FIR_TAPS / 2 ];
pred_lag_ptr = &sLTP_Q16[ NSQ->sLTP_buf_idx - lag + LTP_ORDER / 2 ];
/* Setup short term AR state */
psLPC_Q14 = &NSQ->sLPC_Q14[ MAX_LPC_ORDER - 1 ];
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);
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);
/* Preload LPC coeficients to array on stack. Gives small performance gain */
SKP_memcpy( a_Q12_tmp, a_Q12, predictLPCOrder * sizeof( SKP_int16 ) );
SKP_memcpy( AR_shp_Q13_tmp, AR_shp_Q13, shapingLPCOrder * sizeof( SKP_int16 ) );
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 );
@ -225,35 +222,23 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer(
/* Short-term prediction */
SKP_assert( ( predictLPCOrder & 1 ) == 0 ); /* check that order is even */
SKP_assert( ( (SKP_int64)a_Q12 & 3 ) == 0 ); /* check that array starts at 4-byte aligned address */
/* check that array starts at 4-byte aligned address */
SKP_assert( ( ( SKP_int64 )( ( SKP_int8* )a_Q12 - ( SKP_int8* )0 ) & 3 ) == 0 );
SKP_assert( predictLPCOrder >= 10 ); /* check that unrolling works */
/* NOTE: the code below loads two int16 values in an int32, and multiplies each using the */
/* SMLAWB and SMLAWT instructions. On a big-endian CPU the two int16 variables would be */
/* loaded in reverse order and the code will give the wrong result. In that case swapping */
/* the SMLAWB and SMLAWT instructions should solve the problem. */
/* Partially unrolled */
Atmp = a_Q12_tmp[ 0 ]; /* read two coefficients at once */
LPC_pred_Q10 = SKP_SMULWB( psLPC_Q14[ 0 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -1 ], Atmp );
Atmp = a_Q12_tmp[ 1 ];
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -2 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -3 ], Atmp );
Atmp = a_Q12_tmp[ 2 ];
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -4 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -5 ], Atmp );
Atmp = a_Q12_tmp[ 3 ];
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -6 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -7 ], Atmp );
Atmp = a_Q12_tmp[ 4 ];
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -8 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -9 ], Atmp );
for( j = 10; j < predictLPCOrder; j += 2 ) {
Atmp = a_Q12_tmp[ j >> 1 ]; /* read two coefficients at once */
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -j ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -j - 1 ], Atmp );
LPC_pred_Q10 = SKP_SMULWB( psLPC_Q14[ 0 ], a_Q12[ 0 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -1 ], a_Q12[ 1 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -2 ], a_Q12[ 2 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -3 ], a_Q12[ 3 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -4 ], a_Q12[ 4 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -5 ], a_Q12[ 5 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -6 ], a_Q12[ 6 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -7 ], a_Q12[ 7 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -8 ], a_Q12[ 8 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -9 ], a_Q12[ 9 ] );
for( j = 10; j < predictLPCOrder; j ++ ) {
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -j ], a_Q12[ j ] );
}
/* Long-term prediction */
if( sigtype == SIG_TYPE_VOICED ) {
/* Unrolled loop */
@ -268,83 +253,73 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer(
}
/* Noise shape feedback */
SKP_assert( ( shapingLPCOrder & 1 ) == 0 ); /* check that order is even */
SKP_assert( ( (SKP_int64)AR_shp_Q13 & 3 ) == 0 ); /* check that array starts at 4-byte aligned address */
SKP_assert( shapingLPCOrder >= 12 ); /* check that unrolling works */
/* Partially unrolled */
Atmp = AR_shp_Q13_tmp[ 0 ]; /* read two coefficients at once */
n_AR_Q10 = SKP_SMULWB( psLPC_Q14[ 0 ], Atmp );
n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -1 ], Atmp );
Atmp = AR_shp_Q13_tmp[ 1 ];
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -2 ], Atmp );
n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -3 ], Atmp );
Atmp = AR_shp_Q13_tmp[ 2 ];
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -4 ], Atmp );
n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -5 ], Atmp );
Atmp = AR_shp_Q13_tmp[ 3 ];
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -6 ], Atmp );
n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -7 ], Atmp );
Atmp = AR_shp_Q13_tmp[ 4 ];
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -8 ], Atmp );
n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -9 ], Atmp );
Atmp = AR_shp_Q13_tmp[ 5 ];
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -10 ], Atmp );
n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -11 ], Atmp );
for( j = 12; j < shapingLPCOrder; j += 2 ) {
Atmp = AR_shp_Q13_tmp[ j >> 1 ]; /* read two coefficients at once */
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -j ], Atmp );
n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -j - 1 ], Atmp );
SKP_assert( ( shapingLPCOrder & 1 ) == 0 ); /* check that order is even */
tmp2 = psLPC_Q14[ 0 ];
tmp1 = NSQ->sAR2_Q14[ 0 ];
NSQ->sAR2_Q14[ 0 ] = tmp2;
n_AR_Q10 = SKP_SMULWB( tmp2, AR_shp_Q13[ 0 ] );
for( j = 2; j < shapingLPCOrder; j += 2 ) {
tmp2 = NSQ->sAR2_Q14[ j - 1 ];
NSQ->sAR2_Q14[ j - 1 ] = tmp1;
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp1, AR_shp_Q13[ j - 1 ] );
tmp1 = NSQ->sAR2_Q14[ j + 0 ];
NSQ->sAR2_Q14[ j + 0 ] = tmp2;
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp2, AR_shp_Q13[ j ] );
}
NSQ->sAR2_Q14[ shapingLPCOrder - 1 ] = tmp1;
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp1, AR_shp_Q13[ shapingLPCOrder - 1 ] );
n_AR_Q10 = SKP_RSHIFT( n_AR_Q10, 1 ); /* Q11 -> Q10 */
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, NSQ->sLF_AR_shp_Q12, Tilt_Q14 );
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, NSQ->sLF_AR_shp_Q12, Tilt_Q14 );
n_LF_Q10 = SKP_LSHIFT( SKP_SMULWB( NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - 1 ], LF_shp_Q14 ), 2 );
n_LF_Q10 = SKP_SMLAWT( n_LF_Q10, NSQ->sLF_AR_shp_Q12, LF_shp_Q14 );
n_LF_Q10 = SKP_LSHIFT( SKP_SMULWB( NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - 1 ], LF_shp_Q14 ), 2 );
n_LF_Q10 = SKP_SMLAWT( n_LF_Q10, NSQ->sLF_AR_shp_Q12, LF_shp_Q14 );
SKP_assert( lag > 0 || sigtype == SIG_TYPE_UNVOICED);
SKP_assert( lag > 0 || sigtype == SIG_TYPE_UNVOICED );
/* Long-term shaping */
if( lag > 0 ) {
/* Symmetric, packed FIR coefficients */
n_LTP_Q14 = SKP_SMULWB( SKP_ADD32( shp_lag_ptr[ 0 ], shp_lag_ptr[ -2 ] ), HarmShapeFIRPacked_Q14 );
n_LTP_Q14 = SKP_SMLAWT( n_LTP_Q14, shp_lag_ptr[ -1 ], HarmShapeFIRPacked_Q14 );
shp_lag_ptr++;
n_LTP_Q14 = SKP_LSHIFT( n_LTP_Q14, 6 );
shp_lag_ptr++;
} else {
n_LTP_Q14 = 0;
}
/* Input minus prediction plus noise feedback */
//r = x[ i ] - LTP_pred - LPC_pred + n_AR + n_Tilt + n_LF + n_LTP;
tmp = SKP_SUB32( LTP_pred_Q14, n_LTP_Q14 ); /* Add Q14 stuff */
tmp = SKP_RSHIFT_ROUND( tmp, 4 ); /* round to Q10 */
tmp = SKP_ADD32( tmp, LPC_pred_Q10 ); /* add Q10 stuff */
tmp = SKP_SUB32( tmp, n_AR_Q10 ); /* subtract Q10 stuff */
tmp = SKP_SUB32( tmp, n_LF_Q10 ); /* subtract Q10 stuff */
r_Q10 = SKP_SUB32( x_sc_Q10[ i ], tmp );
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( 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( r_Q10, -64 << 10, 64 << 10 );
r_Q10 = SKP_LIMIT_32( r_Q10, -64 << 10, 64 << 10 );
/* Quantize */
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 if( r_Q10 < thr2_Q10 ) {
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 );
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 {
q_Q0 = 0;
q_Q10 = 0;
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 );
}
}
q[ i ] = q_Q0;
q[ i ] = ( SKP_int8 )q_Q0; /* No saturation needed because max is 64 */
/* Excitation */
exc_Q10 = SKP_ADD32( q_Q10, offset_Q10 );
@ -365,23 +340,24 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer(
NSQ->sLF_AR_shp_Q12 = SKP_LSHIFT( sLF_AR_shp_Q10, 2 );
NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx ] = SKP_SUB32( sLF_AR_shp_Q10, n_LF_Q10 );
sLTP_Q16[NSQ->sLTP_buf_idx] = SKP_LSHIFT( LPC_exc_Q10, 6 );
sLTP_Q16[ NSQ->sLTP_buf_idx ] = SKP_LSHIFT( LPC_exc_Q10, 6 );
NSQ->sLTP_shp_buf_idx++;
NSQ->sLTP_buf_idx++;
/* Make dither dependent on quantized signal */
NSQ->rand_seed += q[ i ];
}
/* Update LPC synth buffer */
SKP_memcpy( NSQ->sLPC_Q14, &NSQ->sLPC_Q14[ length ], MAX_LPC_ORDER * sizeof( SKP_int32 ) );
SKP_memcpy( NSQ->sLPC_Q14, &NSQ->sLPC_Q14[ length ], NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );
}
SKP_INLINE void SKP_Silk_nsq_scale_states(
SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */
const SKP_int16 x[], /* I input in Q0 */
SKP_int32 x_sc_Q10[], /* O input scaled with 1/Gain */
SKP_int length, /* I length of input */
SKP_int16 sLTP[], /* I re-whitened LTP state in Q0 */
SKP_int subfr_length, /* I length of input */
const SKP_int16 sLTP[], /* I re-whitened LTP state in Q0 */
SKP_int32 sLTP_Q16[], /* O LTP state matching scaled input */
SKP_int subfr, /* I subframe number */
const SKP_int LTP_scale_Q14, /* I */
@ -389,14 +365,14 @@ SKP_INLINE void SKP_Silk_nsq_scale_states(
const SKP_int pitchL[ NB_SUBFR ] /* I */
)
{
SKP_int i, scale_length, lag;
SKP_int i, lag;
SKP_int32 inv_gain_Q16, gain_adj_Q16, inv_gain_Q32;
inv_gain_Q16 = SKP_DIV32( SKP_int32_MAX, SKP_RSHIFT( Gains_Q16[ subfr ], 1) );
inv_gain_Q16 = SKP_INVERSE32_varQ( SKP_max( Gains_Q16[ subfr ], 1 ), 32 );
inv_gain_Q16 = SKP_min( inv_gain_Q16, SKP_int16_MAX );
lag = pitchL[ subfr ];
/* After rewhitening the LTP state is un-scaled */
/* After rewhitening the LTP state is un-scaled, so scale with inv_gain_Q16 */
if( NSQ->rewhite_flag ) {
inv_gain_Q32 = SKP_LSHIFT( inv_gain_Q16, 16 );
if( subfr == 0 ) {
@ -404,39 +380,40 @@ SKP_INLINE void SKP_Silk_nsq_scale_states(
inv_gain_Q32 = SKP_LSHIFT( SKP_SMULWB( inv_gain_Q32, LTP_scale_Q14 ), 2 );
}
for( i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx; i++ ) {
SKP_assert( i < MAX_FRAME_LENGTH );
sLTP_Q16[ i ] = SKP_SMULWB( inv_gain_Q32, sLTP[ i ] );
}
}
/* Prepare for Worst case. Next frame starts with max lag voiced */
scale_length = length * NB_SUBFR; /* approx max lag */
scale_length = scale_length - SKP_SMULBB( NB_SUBFR - (subfr + 1), length ); /* subtract samples that will be too old in next frame */
scale_length = SKP_max_int( scale_length, lag + LTP_ORDER ); /* make sure to scale whole pitch period if voiced */
/* Adjust for changing gain */
if( inv_gain_Q16 != NSQ->prev_inv_gain_Q16 ) {
gain_adj_Q16 = SKP_DIV32_varQ( inv_gain_Q16, NSQ->prev_inv_gain_Q16, 16 );
gain_adj_Q16 = SKP_DIV32_varQ( inv_gain_Q16, NSQ->prev_inv_gain_Q16, 16 );
for( i = NSQ->sLTP_shp_buf_idx - scale_length; i < NSQ->sLTP_shp_buf_idx; i++ ) {
/* Scale long-term shaping state */
for( i = NSQ->sLTP_shp_buf_idx - subfr_length * NB_SUBFR; i < NSQ->sLTP_shp_buf_idx; i++ ) {
NSQ->sLTP_shp_Q10[ i ] = SKP_SMULWW( gain_adj_Q16, NSQ->sLTP_shp_Q10[ i ] );
}
/* Scale LTP predict state */
/* Scale long-term prediction state */
if( NSQ->rewhite_flag == 0 ) {
for( i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx; i++ ) {
sLTP_Q16[ i ] = SKP_SMULWW( gain_adj_Q16, sLTP_Q16[ i ] );
}
}
NSQ->sLF_AR_shp_Q12 = SKP_SMULWW( gain_adj_Q16, NSQ->sLF_AR_shp_Q12 );
/* scale short term state */
for( i = 0; i < MAX_LPC_ORDER; i++ ) {
/* Scale short-term prediction and shaping states */
for( i = 0; i < NSQ_LPC_BUF_LENGTH; i++ ) {
NSQ->sLPC_Q14[ i ] = SKP_SMULWW( gain_adj_Q16, NSQ->sLPC_Q14[ i ] );
}
for( i = 0; i < MAX_SHAPE_LPC_ORDER; i++ ) {
NSQ->sAR2_Q14[ i ] = SKP_SMULWW( gain_adj_Q16, NSQ->sAR2_Q14[ i ] );
}
}
/* Scale input */
for( i = 0; i < length; i++ ) {
for( i = 0; i < subfr_length; i++ ) {
x_sc_Q10[ i ] = SKP_RSHIFT( SKP_SMULBB( x[ i ], ( SKP_int16 )inv_gain_Q16 ), 6 );
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -28,12 +28,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SKP_Silk_main.h"
typedef struct {
SKP_int RandState[ DECISION_DELAY ];
SKP_int32 RandState[ DECISION_DELAY ];
SKP_int32 Q_Q10[ DECISION_DELAY ];
SKP_int32 Xq_Q10[ DECISION_DELAY ];
SKP_int32 Pred_Q16[ DECISION_DELAY ];
SKP_int32 Shape_Q10[ DECISION_DELAY ];
SKP_int32 Gain_Q16[ DECISION_DELAY ];
SKP_int32 sAR2_Q14[ MAX_SHAPE_LPC_ORDER ];
SKP_int32 sLPC_Q14[ MAX_FRAME_LENGTH / NB_SUBFR + NSQ_LPC_BUF_LENGTH ];
SKP_int32 LF_AR_Q12;
SKP_int32 Seed;
@ -61,8 +62,8 @@ SKP_INLINE void SKP_Silk_nsq_del_dec_scale_states(
NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */
const SKP_int16 x[], /* I Input in Q0 */
SKP_int32 x_sc_Q10[], /* O Input scaled with 1/Gain in Q10 */
SKP_int length, /* I Length of input */
SKP_int16 sLTP[], /* I Re-whitened LTP state in Q0 */
SKP_int subfr_length, /* I Length of input */
const SKP_int16 sLTP[], /* I Re-whitened LTP state in Q0 */
SKP_int32 sLTP_Q16[], /* O LTP state matching scaled input */
SKP_int subfr, /* I Subframe number */
SKP_int nStatesDelayedDecision, /* I Number of del dec states */
@ -80,7 +81,7 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec(
NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */
SKP_int sigtype, /* I Signal type */
const SKP_int32 x_Q10[], /* I */
SKP_int q[], /* O */
SKP_int8 q[], /* O */
SKP_int16 xq[], /* O */
SKP_int32 sLTP_Q16[], /* I/O LTP filter state */
const SKP_int16 a_Q12[], /* I Short term prediction coefs */
@ -96,7 +97,8 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec(
SKP_int length, /* I Input length */
SKP_int subfr, /* I Subframe number */
SKP_int shapingLPCOrder, /* I Shaping LPC filter order */
SKP_int predictLPCOrder, /* I Prediction LPC filter order */
SKP_int predictLPCOrder, /* I Prediction filter order */
SKP_int warping_Q16, /* I */
SKP_int nStatesDelayedDecision, /* I Number of states in decision tree */
SKP_int *smpl_buf_idx, /* I Index to newest samples in buffers */
SKP_int decisionDelay /* I */
@ -107,11 +109,11 @@ void SKP_Silk_NSQ_del_dec(
SKP_Silk_encoder_control *psEncCtrlC, /* I Encoder Control */
SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */
const SKP_int16 x[], /* I Prefiltered input signal */
SKP_int q[], /* O Quantized pulse signal */
SKP_int8 q[], /* O Quantized pulse signal */
const SKP_int LSFInterpFactor_Q2, /* I LSF interpolation factor in Q2 */
const SKP_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Prediction coefs */
const SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ], /* I LT prediction coefs */
const SKP_int16 AR2_Q13[ NB_SUBFR * SHAPE_LPC_ORDER_MAX ], /* I */
const SKP_int16 AR2_Q13[ NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I */
const SKP_int HarmShapeGain_Q14[ NB_SUBFR ], /* I */
const SKP_int Tilt_Q14[ NB_SUBFR ], /* I Spectral tilt */
const SKP_int32 LF_shp_Q14[ NB_SUBFR ], /* I */
@ -130,7 +132,7 @@ void SKP_Silk_NSQ_del_dec(
SKP_int offset_Q10;
SKP_int32 FiltState[ MAX_LPC_ORDER ], RDmin_Q10;
SKP_int32 x_sc_Q10[ MAX_FRAME_LENGTH / NB_SUBFR ];
NSQ_del_dec_struct psDelDec[ DEL_DEC_STATES_MAX ];
NSQ_del_dec_struct psDelDec[ MAX_DEL_DEC_STATES ];
NSQ_del_dec_struct *psDD;
subfr_length = psEncC->frame_length / NB_SUBFR;
@ -150,17 +152,23 @@ void SKP_Silk_NSQ_del_dec(
psDD->LF_AR_Q12 = NSQ->sLF_AR_shp_Q12;
psDD->Shape_Q10[ 0 ] = NSQ->sLTP_shp_Q10[ psEncC->frame_length - 1 ];
SKP_memcpy( psDD->sLPC_Q14, NSQ->sLPC_Q14, NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );
SKP_memcpy( psDD->sAR2_Q14, NSQ->sAR2_Q14, sizeof( NSQ->sAR2_Q14 ) );
}
offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psEncCtrlC->sigtype ][ psEncCtrlC->QuantOffsetType ];
smpl_buf_idx = 0; /* index of oldest samples */
decisionDelay = SKP_min_int( DECISION_DELAY, subfr_length );
/* For voiced frames limit the decision delay to lower than the pitch lag */
if( psEncCtrlC->sigtype == SIG_TYPE_VOICED ) {
for( k = 0; k < NB_SUBFR; k++ ) {
decisionDelay = SKP_min_int( decisionDelay, psEncCtrlC->pitchL[ k ] - LTP_ORDER / 2 - 1 );
}
} else {
if( lag > 0 ) {
decisionDelay = SKP_min_int( decisionDelay, lag - LTP_ORDER / 2 - 1 );
}
}
if( LSFInterpFactor_Q2 == ( 1 << 2 ) ) {
@ -177,7 +185,12 @@ void SKP_Silk_NSQ_del_dec(
for( k = 0; k < NB_SUBFR; k++ ) {
A_Q12 = &PredCoef_Q12[ ( ( k >> 1 ) | ( 1 - LSF_interpolation_flag ) ) * MAX_LPC_ORDER ];
B_Q14 = &LTPCoef_Q14[ k * LTP_ORDER ];
AR_shp_Q13 = &AR2_Q13[ k * SHAPE_LPC_ORDER_MAX ];
AR_shp_Q13 = &AR2_Q13[ k * MAX_SHAPE_LPC_ORDER ];
/* Noise shape parameters */
SKP_assert( HarmShapeGain_Q14[ k ] >= 0 );
HarmShapeFIRPacked_Q14 = SKP_RSHIFT( HarmShapeGain_Q14[ k ], 2 );
HarmShapeFIRPacked_Q14 |= SKP_LSHIFT( ( SKP_int32 )SKP_RSHIFT( HarmShapeGain_Q14[ k ], 1 ), 16 );
NSQ->rewhite_flag = 0;
if( psEncCtrlC->sigtype == SIG_TYPE_VOICED ) {
@ -209,7 +222,7 @@ void SKP_Silk_NSQ_del_dec(
last_smple_idx = smpl_buf_idx + decisionDelay;
for( i = 0; i < decisionDelay; i++ ) {
last_smple_idx = ( last_smple_idx - 1 ) & DECISION_DELAY_MASK;
q[ i - decisionDelay ] = ( SKP_int )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 );
q[ i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT( 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 ],
psDD->Gain_Q16[ last_smple_idx ] ), 10 ) );
@ -221,8 +234,9 @@ void SKP_Silk_NSQ_del_dec(
/* Rewhiten with new A coefs */
start_idx = psEncC->frame_length - lag - psEncC->predictLPCOrder - LTP_ORDER / 2;
start_idx = SKP_LIMIT( start_idx, 0, psEncC->frame_length - psEncC->predictLPCOrder );
SKP_assert( start_idx >= 0 );
SKP_assert( start_idx <= psEncC->frame_length - psEncC->predictLPCOrder );
SKP_memset( FiltState, 0, psEncC->predictLPCOrder * sizeof( SKP_int32 ) );
SKP_Silk_MA_Prediction( &NSQ->xq[ start_idx + k * psEncC->subfr_length ],
A_Q12, FiltState, sLTP + start_idx, psEncC->frame_length - start_idx, psEncC->predictLPCOrder );
@ -232,11 +246,6 @@ void SKP_Silk_NSQ_del_dec(
}
}
/* Noise shape parameters */
SKP_assert( HarmShapeGain_Q14[ k ] >= 0 );
HarmShapeFIRPacked_Q14 = SKP_RSHIFT( HarmShapeGain_Q14[ k ], 2 );
HarmShapeFIRPacked_Q14 |= SKP_LSHIFT( ( SKP_int32 )SKP_RSHIFT( HarmShapeGain_Q14[ k ], 1 ), 16 );
SKP_Silk_nsq_del_dec_scale_states( NSQ, psDelDec, x, x_sc_Q10,
subfr_length, sLTP, sLTP_Q16, k, psEncC->nStatesDelayedDecision, smpl_buf_idx,
LTP_scale_Q14, Gains_Q16, psEncCtrlC->pitchL );
@ -244,8 +253,7 @@ void SKP_Silk_NSQ_del_dec(
SKP_Silk_noise_shape_quantizer_del_dec( NSQ, psDelDec, psEncCtrlC->sigtype, x_sc_Q10, q, pxq, sLTP_Q16,
A_Q12, B_Q14, AR_shp_Q13, lag, HarmShapeFIRPacked_Q14, Tilt_Q14[ k ], LF_shp_Q14[ k ], Gains_Q16[ k ],
Lambda_Q10, offset_Q10, psEncC->subfr_length, subfr++, psEncC->shapingLPCOrder, psEncC->predictLPCOrder,
psEncC->nStatesDelayedDecision, &smpl_buf_idx, decisionDelay
);
psEncC->warping_Q16, psEncC->nStatesDelayedDecision, &smpl_buf_idx, decisionDelay );
x += psEncC->subfr_length;
q += psEncC->subfr_length;
@ -268,24 +276,27 @@ void SKP_Silk_NSQ_del_dec(
last_smple_idx = smpl_buf_idx + decisionDelay;
for( i = 0; i < decisionDelay; i++ ) {
last_smple_idx = ( last_smple_idx - 1 ) & DECISION_DELAY_MASK;
q[ i - decisionDelay ] = ( SKP_int )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 );
q[ i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT( 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 ], psDD->Gain_Q16[ last_smple_idx ] ), 10 ) );
NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay + i ] = psDD->Shape_Q10[ last_smple_idx ];
sLTP_Q16[ NSQ->sLTP_buf_idx - decisionDelay + i ] = psDD->Pred_Q16[ last_smple_idx ];
}
SKP_memcpy( NSQ->sLPC_Q14, &psDD->sLPC_Q14[ psEncC->subfr_length ], NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );
SKP_memcpy( NSQ->sAR2_Q14, psDD->sAR2_Q14, sizeof( psDD->sAR2_Q14 ) );
/* Update states */
NSQ->sLF_AR_shp_Q12 = psDD->LF_AR_Q12;
NSQ->prev_inv_gain_Q16 = NSQ->prev_inv_gain_Q16;
NSQ->lagPrev = psEncCtrlC->pitchL[ NB_SUBFR - 1 ];
NSQ->sLF_AR_shp_Q12 = psDD->LF_AR_Q12;
NSQ->lagPrev = psEncCtrlC->pitchL[ NB_SUBFR - 1 ];
/* Save quantized speech and noise shaping signals */
SKP_memcpy( NSQ->xq, &NSQ->xq[ psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int16 ) );
SKP_memcpy( NSQ->sLTP_shp_Q10, &NSQ->sLTP_shp_Q10[ psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int32 ) );
#ifdef USE_UNQUANTIZED_LSFS
DEBUG_STORE_DATA( xq_unq_lsfs.pcm, NSQ->xq, psEncC->frame_length * sizeof( SKP_int16 ) );
#endif
}
/******************************************/
@ -296,7 +307,7 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec(
NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */
SKP_int sigtype, /* I Signal type */
const SKP_int32 x_Q10[], /* I */
SKP_int q[], /* O */
SKP_int8 q[], /* O */
SKP_int16 xq[], /* O */
SKP_int32 sLTP_Q16[], /* I/O LTP filter state */
const SKP_int16 a_Q12[], /* I Short term prediction coefs */
@ -312,7 +323,8 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec(
SKP_int length, /* I Input length */
SKP_int subfr, /* I Subframe number */
SKP_int shapingLPCOrder, /* I Shaping LPC filter order */
SKP_int predictLPCOrder, /* I Prediction LPC filter order */
SKP_int predictLPCOrder, /* I Prediction filter order */
SKP_int warping_Q16, /* I */
SKP_int nStatesDelayedDecision, /* I Number of states in decision tree */
SKP_int *smpl_buf_idx, /* I Index to newest samples in buffers */
SKP_int decisionDelay /* I */
@ -321,25 +333,16 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec(
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;
SKP_int32 n_LF_Q10;
SKP_int32 r_Q10, rr_Q20, rd1_Q10, rd2_Q10, RDmin_Q10, RDmax_Q10;
SKP_int32 q1_Q10, q2_Q10;
SKP_int32 Atmp, dither;
SKP_int32 exc_Q10, LPC_exc_Q10, xq_Q10;
SKP_int32 tmp, sLF_AR_shp_Q10;
SKP_int32 *pred_lag_ptr, *shp_lag_ptr;
SKP_int32 *psLPC_Q14;
SKP_int32 a_Q12_tmp[ MAX_LPC_ORDER / 2 ], AR_shp_Q13_tmp[ MAX_LPC_ORDER / 2 ];
NSQ_sample_struct psSampleState[ DEL_DEC_STATES_MAX ][ 2 ];
SKP_int32 n_LF_Q10, r_Q10, rr_Q20, 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;
NSQ_sample_struct psSampleState[ MAX_DEL_DEC_STATES ][ 2 ];
NSQ_del_dec_struct *psDD;
NSQ_sample_struct *psSS;
shp_lag_ptr = &NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - lag + HARM_SHAPE_FIR_TAPS / 2 ];
pred_lag_ptr = &sLTP_Q16[ NSQ->sLTP_buf_idx - lag + LTP_ORDER / 2 ];
/* Preload LPC coeficients to array on stack. Gives small performance gain */
SKP_memcpy( a_Q12_tmp, a_Q12, predictLPCOrder * sizeof( SKP_int16 ) );
SKP_memcpy( AR_shp_Q13_tmp, AR_shp_Q13, shapingLPCOrder * sizeof( SKP_int16 ) );
for( i = 0; i < length; i++ ) {
/* Perform common calculations used in all states */
@ -384,85 +387,65 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec(
/* Pointer used in short term prediction and shaping */
psLPC_Q14 = &psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - 1 + i ];
/* Short-term prediction */
SKP_assert( ( predictLPCOrder & 1 ) == 0 ); /* check that order is even */
SKP_assert( ( (SKP_int64)a_Q12 & 3 ) == 0 ); /* check that array starts at 4-byte aligned address */
SKP_assert( predictLPCOrder >= 10 ); /* check that unrolling works */
SKP_assert( ( predictLPCOrder & 1 ) == 0 ); /* check that order is even */
SKP_assert( ( ( ( int )( ( char* )( a_Q12 ) - ( ( char* ) 0 ) ) ) & 3 ) == 0 ); /* check that array starts at 4-byte aligned address */
/* Partially unrolled */
Atmp = a_Q12_tmp[ 0 ]; /* read two coefficients at once */
LPC_pred_Q10 = SKP_SMULWB( psLPC_Q14[ 0 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -1 ], Atmp );
Atmp = a_Q12_tmp[ 1 ];
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -2 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -3 ], Atmp );
Atmp = a_Q12_tmp[ 2 ];
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -4 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -5 ], Atmp );
Atmp = a_Q12_tmp[ 3 ];
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -6 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -7 ], Atmp );
Atmp = a_Q12_tmp[ 4 ];
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -8 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -9 ], Atmp );
for( j = 10; j < predictLPCOrder; j += 2 ) {
Atmp = a_Q12_tmp[ j >> 1 ]; /* read two coefficients at once */
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -j ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -j - 1 ], Atmp );
LPC_pred_Q10 = SKP_SMULWB( psLPC_Q14[ 0 ], a_Q12[ 0 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -1 ], a_Q12[ 1 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -2 ], a_Q12[ 2 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -3 ], a_Q12[ 3 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -4 ], a_Q12[ 4 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -5 ], a_Q12[ 5 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -6 ], a_Q12[ 6 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -7 ], a_Q12[ 7 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -8 ], a_Q12[ 8 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -9 ], a_Q12[ 9 ] );
for( j = 10; j < predictLPCOrder; j ++ ) {
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -j ], a_Q12[ j ] );
}
/* Noise shape feedback */
SKP_assert( ( shapingLPCOrder & 1 ) == 0 ); /* check that order is even */
SKP_assert( ( (SKP_int64)AR_shp_Q13 & 3 ) == 0 ); /* check that array starts at 4-byte aligned address */
SKP_assert( shapingLPCOrder >= 12 ); /* check that unrolling works */
/* NOTE: the code below loads two int16 values in an int32, and multiplies each using the */
/* SMLAWB and SMLAWT instructions. On a big-endian CPU the two int16 variables would be */
/* loaded in reverse order and the code will give the wrong result. In that case swapping */
/* the SMLAWB and SMLAWT instructions should solve the problem. */
/* Partially unrolled */
Atmp = AR_shp_Q13_tmp[ 0 ]; /* read two coefficients at once */
n_AR_Q10 = SKP_SMULWB( psLPC_Q14[ 0 ], Atmp );
n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -1 ], Atmp );
Atmp = AR_shp_Q13_tmp[ 1 ];
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -2 ], Atmp );
n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -3 ], Atmp );
Atmp = AR_shp_Q13_tmp[ 2 ];
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -4 ], Atmp );
n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -5 ], Atmp );
Atmp = AR_shp_Q13_tmp[ 3 ];
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -6 ], Atmp );
n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -7 ], Atmp );
Atmp = AR_shp_Q13_tmp[ 4 ];
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -8 ], Atmp );
n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -9 ], Atmp );
Atmp = AR_shp_Q13_tmp[ 5 ];
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -10 ], Atmp );
n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -11 ], Atmp );
for( j = 12; j < shapingLPCOrder; j += 2 ) {
Atmp = AR_shp_Q13_tmp[ j >> 1 ]; /* read two coefficients at once */
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -j ], Atmp );
n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -j - 1 ], Atmp );
SKP_assert( ( shapingLPCOrder & 1 ) == 0 ); /* check that order is even */
/* Output of lowpass section */
tmp2 = SKP_SMLAWB( psLPC_Q14[ 0 ], psDD->sAR2_Q14[ 0 ], warping_Q16 );
/* Output of allpass section */
tmp1 = SKP_SMLAWB( psDD->sAR2_Q14[ 0 ], psDD->sAR2_Q14[ 1 ] - tmp2, warping_Q16 );
psDD->sAR2_Q14[ 0 ] = tmp2;
n_AR_Q10 = SKP_SMULWB( tmp2, AR_shp_Q13[ 0 ] );
/* Loop over allpass sections */
for( j = 2; j < shapingLPCOrder; j += 2 ) {
/* Output of allpass section */
tmp2 = SKP_SMLAWB( psDD->sAR2_Q14[ j - 1 ], psDD->sAR2_Q14[ j + 0 ] - tmp1, warping_Q16 );
psDD->sAR2_Q14[ j - 1 ] = tmp1;
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp1, AR_shp_Q13[ j - 1 ] );
/* Output of allpass section */
tmp1 = SKP_SMLAWB( psDD->sAR2_Q14[ j + 0 ], psDD->sAR2_Q14[ j + 1 ] - tmp2, warping_Q16 );
psDD->sAR2_Q14[ j + 0 ] = tmp2;
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp2, AR_shp_Q13[ j ] );
}
psDD->sAR2_Q14[ shapingLPCOrder - 1 ] = tmp1;
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, tmp1, AR_shp_Q13[ shapingLPCOrder - 1 ] );
n_AR_Q10 = SKP_RSHIFT( n_AR_Q10, 1 ); /* Q11 -> Q10 */
n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psDD->LF_AR_Q12, Tilt_Q14 );
n_LF_Q10 = SKP_LSHIFT( SKP_SMULWB( psDD->Shape_Q10[ *smpl_buf_idx ], LF_shp_Q14 ), 2 );
n_LF_Q10 = SKP_SMLAWT( n_LF_Q10, psDD->LF_AR_Q12, LF_shp_Q14 );
n_LF_Q10 = SKP_LSHIFT( SKP_SMULWB( psDD->Shape_Q10[ *smpl_buf_idx ], LF_shp_Q14 ), 2 );
n_LF_Q10 = SKP_SMLAWT( n_LF_Q10, psDD->LF_AR_Q12, LF_shp_Q14 );
/* Input minus prediction plus noise feedback */
/* r = x[ i ] - LTP_pred - LPC_pred + n_AR + n_Tilt + n_LF + n_LTP */
tmp = SKP_SUB32( LTP_pred_Q14, n_LTP_Q14 ); /* Add Q14 stuff */
tmp = SKP_RSHIFT_ROUND( tmp, 4 ); /* round to Q10 */
tmp = SKP_ADD32( tmp, LPC_pred_Q10 ); /* add Q10 stuff */
tmp = SKP_SUB32( tmp, n_AR_Q10 ); /* subtract Q10 stuff */
tmp = SKP_SUB32( tmp, n_LF_Q10 ); /* subtract Q10 stuff */
r_Q10 = SKP_SUB32( x_Q10[ i ], tmp ); /* residual error Q10 */
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( tmp1, n_LF_Q10 ); /* subtract Q10 stuff */
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( r_Q10, -64 << 10, 64 << 10 );
r_Q10 = SKP_LIMIT_32( r_Q10, -64 << 10, 64 << 10 );
/* Find two quantization level candidates and measure their rate-distortion */
if( r_Q10 < -1536 ) {
@ -585,7 +568,7 @@ SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec(
/* Write samples from winner to output and long-term filter states */
psDD = &psDelDec[ Winner_ind ];
if( subfr > 0 || i >= decisionDelay ) {
q[ i - decisionDelay ] = ( SKP_int )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 );
q[ i - decisionDelay ] = ( SKP_int8 )SKP_RSHIFT( 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 ], psDD->Gain_Q16[ last_smple_idx ] ), 10 ) );
NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay ] = psDD->Shape_Q10[ last_smple_idx ];
@ -622,8 +605,8 @@ SKP_INLINE void SKP_Silk_nsq_del_dec_scale_states(
NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */
const SKP_int16 x[], /* I Input in Q0 */
SKP_int32 x_sc_Q10[], /* O Input scaled with 1/Gain in Q10 */
SKP_int length, /* I Length of input */
SKP_int16 sLTP[], /* I Re-whitened LTP state in Q0 */
SKP_int subfr_length, /* I Length of input */
const SKP_int16 sLTP[], /* I Re-whitened LTP state in Q0 */
SKP_int32 sLTP_Q16[], /* O LTP state matching scaled input */
SKP_int subfr, /* I Subframe number */
SKP_int nStatesDelayedDecision, /* I Number of del dec states */
@ -633,14 +616,15 @@ SKP_INLINE void SKP_Silk_nsq_del_dec_scale_states(
const SKP_int pitchL[ NB_SUBFR ] /* I Pitch lag */
)
{
SKP_int i, k, scale_length, lag;
SKP_int i, k, lag;
SKP_int32 inv_gain_Q16, gain_adj_Q16, inv_gain_Q32;
NSQ_del_dec_struct *psDD;
inv_gain_Q16 = SKP_DIV32( SKP_int32_MAX, SKP_RSHIFT( Gains_Q16[ subfr ], 1 ) );
inv_gain_Q16 = SKP_INVERSE32_varQ( SKP_max( Gains_Q16[ subfr ], 1 ), 32 );
inv_gain_Q16 = SKP_min( inv_gain_Q16, SKP_int16_MAX );
lag = pitchL[ subfr ];
/* After rewhitening the LTP state is un-scaled. So scale with inv_gain_Q16 */
/* After rewhitening the LTP state is un-scaled, so scale with inv_gain_Q16 */
if( NSQ->rewhite_flag ) {
inv_gain_Q32 = SKP_LSHIFT( inv_gain_Q16, 16 );
if( subfr == 0 ) {
@ -657,43 +641,40 @@ SKP_INLINE void SKP_Silk_nsq_del_dec_scale_states(
if( inv_gain_Q16 != NSQ->prev_inv_gain_Q16 ) {
gain_adj_Q16 = SKP_DIV32_varQ( inv_gain_Q16, NSQ->prev_inv_gain_Q16, 16 );
/* Scale long-term shaping state */
for( i = NSQ->sLTP_shp_buf_idx - subfr_length * NB_SUBFR; i < NSQ->sLTP_shp_buf_idx; i++ ) {
NSQ->sLTP_shp_Q10[ i ] = SKP_SMULWW( gain_adj_Q16, NSQ->sLTP_shp_Q10[ i ] );
}
/* Scale long-term prediction state */
if( NSQ->rewhite_flag == 0 ) {
for( i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx; i++ ) {
sLTP_Q16[ i ] = SKP_SMULWW( gain_adj_Q16, sLTP_Q16[ i ] );
}
}
for( k = 0; k < nStatesDelayedDecision; k++ ) {
psDD = &psDelDec[ k ];
/* Scale scalar states */
psDD->LF_AR_Q12 = SKP_SMULWW( gain_adj_Q16, psDD->LF_AR_Q12 );
/* scale short term state */
/* Scale short-term prediction and shaping states */
for( i = 0; i < NSQ_LPC_BUF_LENGTH; i++ ) {
psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - i - 1 ] = SKP_SMULWW( gain_adj_Q16, psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - i - 1 ] );
psDD->sLPC_Q14[ i ] = SKP_SMULWW( gain_adj_Q16, psDD->sLPC_Q14[ i ] );
}
for( i = 0; i < MAX_SHAPE_LPC_ORDER; i++ ) {
psDD->sAR2_Q14[ i ] = SKP_SMULWW( gain_adj_Q16, psDD->sAR2_Q14[ i ] );
}
for( i = 0; i < DECISION_DELAY; i++ ) {
psDD->Pred_Q16[ i ] = SKP_SMULWW( gain_adj_Q16, psDD->Pred_Q16[ i ] );
psDD->Shape_Q10[ i ] = SKP_SMULWW( gain_adj_Q16, psDD->Shape_Q10[ i ] );
}
}
/* Scale long term shaping state */
/* Calculate length to be scaled, Worst case: Next frame is voiced with max lag */
scale_length = length * NB_SUBFR; /* aprox max lag */
scale_length = scale_length - SKP_SMULBB( NB_SUBFR - ( subfr + 1 ), length ); /* subtract samples that will be too old in next frame */
scale_length = SKP_max_int( scale_length, lag + LTP_ORDER ); /* make sure to scale whole pitch period if voiced */
for( i = NSQ->sLTP_shp_buf_idx - scale_length; i < NSQ->sLTP_shp_buf_idx; i++ ) {
NSQ->sLTP_shp_Q10[ i ] = SKP_SMULWW( gain_adj_Q16, NSQ->sLTP_shp_Q10[ i ] );
}
/* Scale LTP predict state */
if( NSQ->rewhite_flag == 0 ) {
for( i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx; i++ ) {
sLTP_Q16[ i ] = SKP_SMULWW( gain_adj_Q16, sLTP_Q16[ i ] );
}
}
}
/* Scale input */
for( i = 0; i < length; i++ ) {
for( i = 0; i < subfr_length; i++ ) {
x_sc_Q10[ i ] = SKP_RSHIFT( SKP_SMULBB( x[ i ], ( SKP_int16 )inv_gain_Q16 ), 6 );
}
@ -708,12 +689,12 @@ SKP_INLINE void SKP_Silk_copy_del_dec_state(
SKP_int LPC_state_idx /* I Index to LPC buffer */
)
{
SKP_memcpy( DD_dst->RandState, DD_src->RandState, DECISION_DELAY * sizeof( SKP_int ) );
SKP_memcpy( DD_dst->Q_Q10, DD_src->Q_Q10, DECISION_DELAY * sizeof( SKP_int32 ) );
SKP_memcpy( DD_dst->Pred_Q16, DD_src->Pred_Q16, DECISION_DELAY * sizeof( SKP_int32 ) );
SKP_memcpy( DD_dst->Shape_Q10, DD_src->Shape_Q10, DECISION_DELAY * sizeof( SKP_int32 ) );
SKP_memcpy( DD_dst->Xq_Q10, DD_src->Xq_Q10, DECISION_DELAY * sizeof( SKP_int32 ) );
SKP_memcpy( DD_dst->RandState, DD_src->RandState, sizeof( DD_src->RandState ) );
SKP_memcpy( DD_dst->Q_Q10, DD_src->Q_Q10, sizeof( DD_src->Q_Q10 ) );
SKP_memcpy( DD_dst->Pred_Q16, DD_src->Pred_Q16, sizeof( DD_src->Pred_Q16 ) );
SKP_memcpy( DD_dst->Shape_Q10, DD_src->Shape_Q10, sizeof( DD_src->Shape_Q10 ) );
SKP_memcpy( DD_dst->Xq_Q10, DD_src->Xq_Q10, sizeof( DD_src->Xq_Q10 ) );
SKP_memcpy( DD_dst->sAR2_Q14, DD_src->sAR2_Q14, sizeof( DD_src->sAR2_Q14 ) );
SKP_memcpy( &DD_dst->sLPC_Q14[ LPC_state_idx ], &DD_src->sLPC_Q14[ LPC_state_idx ], NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );
DD_dst->LF_AR_Q12 = DD_src->LF_AR_Q12;
DD_dst->Seed = DD_src->Seed;

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -59,6 +59,8 @@ void SKP_Silk_PLC(
/* Generate Signal */
/****************************/
SKP_Silk_PLC_conceal( psDec, psDecCtrl, signal, length );
psDec->lossCnt++;
} else {
/****************************/
/* Update state */
@ -150,13 +152,16 @@ void SKP_Silk_PLC_conceal(
{
SKP_int i, j, k;
SKP_int16 *B_Q14, exc_buf[ MAX_FRAME_LENGTH ], *exc_buf_ptr;
SKP_int16 rand_scale_Q14, A_Q12_tmp[ MAX_LPC_ORDER ];
SKP_int16 rand_scale_Q14;
union {
SKP_int16 as_int16[ MAX_LPC_ORDER ];
SKP_int32 as_int32[ MAX_LPC_ORDER / 2 ];
} A_Q12_tmp;
SKP_int32 rand_seed, harm_Gain_Q15, rand_Gain_Q15;
SKP_int lag, idx, shift1, shift2;
SKP_int32 energy1, energy2, *rand_ptr, *pred_lag_ptr, Atmp;
SKP_int lag, idx, sLTP_buf_idx, shift1, shift2;
SKP_int32 energy1, energy2, *rand_ptr, *pred_lag_ptr;
SKP_int32 sig_Q10[ MAX_FRAME_LENGTH ], *sig_Q10_ptr, LPC_exc_Q10, LPC_pred_Q10, LTP_pred_Q14;
SKP_Silk_PLC_struct *psPLC;
psPLC = &psDec->sPLC;
/* Update LTP buffer */
@ -179,7 +184,7 @@ void SKP_Silk_PLC_conceal(
SKP_Silk_sum_sqr_shift( &energy1, &shift1, exc_buf, psDec->subfr_length );
SKP_Silk_sum_sqr_shift( &energy2, &shift2, &exc_buf[ psDec->subfr_length ], psDec->subfr_length );
if( SKP_RSHIFT( energy1, shift2 ) < SKP_RSHIFT( energy1, shift2 ) ) {
if( SKP_RSHIFT( energy1, shift2 ) < SKP_RSHIFT( energy2, shift1 ) ) {
/* First sub-frame has lowest energy */
rand_ptr = &psDec->exc_Q10[ SKP_max_int( 0, 3 * psDec->subfr_length - RAND_BUF_SIZE ) ];
} else {
@ -226,9 +231,9 @@ void SKP_Silk_PLC_conceal(
}
}
rand_seed = psPLC->rand_seed;
lag = SKP_RSHIFT_ROUND( psPLC->pitchL_Q8, 8 );
psDec->sLTP_buf_idx = psDec->frame_length;
rand_seed = psPLC->rand_seed;
lag = SKP_RSHIFT_ROUND( psPLC->pitchL_Q8, 8 );
sLTP_buf_idx = psDec->frame_length;
/***************************/
/* LTP synthesis filtering */
@ -236,7 +241,7 @@ void SKP_Silk_PLC_conceal(
sig_Q10_ptr = sig_Q10;
for( k = 0; k < NB_SUBFR; k++ ) {
/* Setup pointer */
pred_lag_ptr = &psDec->sLTP_Q16[ psDec->sLTP_buf_idx - lag + LTP_ORDER / 2 ];
pred_lag_ptr = &psDec->sLTP_Q16[ sLTP_buf_idx - lag + LTP_ORDER / 2 ];
for( i = 0; i < psDec->subfr_length; i++ ) {
rand_seed = SKP_RAND( rand_seed );
idx = SKP_RSHIFT( rand_seed, 25 ) & RAND_BUF_MASK;
@ -254,8 +259,8 @@ void SKP_Silk_PLC_conceal(
LPC_exc_Q10 = SKP_ADD32( LPC_exc_Q10, SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 ) ); /* Harmonic part */
/* Update states */
psDec->sLTP_Q16[ psDec->sLTP_buf_idx ] = SKP_LSHIFT( LPC_exc_Q10, 6 );
psDec->sLTP_buf_idx++;
psDec->sLTP_Q16[ sLTP_buf_idx ] = SKP_LSHIFT( LPC_exc_Q10, 6 );
sLTP_buf_idx++;
/* Save LPC residual */
sig_Q10_ptr[ i ] = LPC_exc_Q10;
@ -279,32 +284,25 @@ void SKP_Silk_PLC_conceal(
/***************************/
sig_Q10_ptr = sig_Q10;
/* Preload LPC coeficients to array on stack. Gives small performance gain */
SKP_memcpy( A_Q12_tmp, psPLC->prevLPC_Q12, psDec->LPC_order * sizeof( SKP_int16 ) );
SKP_memcpy( A_Q12_tmp.as_int16, psPLC->prevLPC_Q12, psDec->LPC_order * sizeof( SKP_int16 ) );
SKP_assert( psDec->LPC_order >= 10 ); /* check that unrolling works */
for( k = 0; k < NB_SUBFR; k++ ) {
for( i = 0; i < psDec->subfr_length; i++ ){
/* unrolled */
Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 0 ] ); /* read two coefficients at once */
LPC_pred_Q10 = SKP_SMULWB( psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 1 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 2 ], Atmp );
Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 2 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 3 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 4 ], Atmp );
Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 4 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 5 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 6 ], Atmp );
Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 6 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 7 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 8 ], Atmp );
Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 8 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 9 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 10 ], Atmp );
for( j = 10 ; j < psDec->LPC_order ; j+=2 ) {
Atmp = *( ( SKP_int32* )&A_Q12_tmp[ j ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 1 - j ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 2 - j ], Atmp );
}
/* partly unrolled */
LPC_pred_Q10 = SKP_SMULWB( psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 1 ], A_Q12_tmp.as_int16[ 0 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 2 ], A_Q12_tmp.as_int16[ 1 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 3 ], A_Q12_tmp.as_int16[ 2 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 4 ], A_Q12_tmp.as_int16[ 3 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 5 ], A_Q12_tmp.as_int16[ 4 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 6 ], A_Q12_tmp.as_int16[ 5 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 7 ], A_Q12_tmp.as_int16[ 6 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 8 ], A_Q12_tmp.as_int16[ 7 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 9 ], A_Q12_tmp.as_int16[ 8 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 10 ], A_Q12_tmp.as_int16[ 9 ] );
for( j = 10; j < psDec->LPC_order; j++ ) {
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - j - 1 ], A_Q12_tmp.as_int16[ j ] );
}
/* Add prediction to LPC residual */
sig_Q10_ptr[ i ] = SKP_ADD32( sig_Q10_ptr[ i ], LPC_pred_Q10 );
@ -387,3 +385,4 @@ void SKP_Silk_PLC_glue_frames(
}
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -28,7 +28,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef SKP_SILK_PLC_FIX_H
#define SKP_SILK_PLC_FIX_H
#include "SKP_Silk_main_FIX.h"
#include "SKP_Silk_main.h"
#define BWE_COEF_Q16 64880 /* 0.99 in Q16 */
#define V_PITCH_GAIN_START_MIN_Q14 11469 /* 0.7 in Q14 */
@ -38,7 +38,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define USE_SINGLE_TAP 1
#define RAND_BUF_SIZE 128
#define RAND_BUF_MASK (RAND_BUF_SIZE - 1)
#define LOG2_INV_LPC_GAIN_HIGH_THRES 4 /* 2^4 = 12 dB LPC gain */
#define LOG2_INV_LPC_GAIN_HIGH_THRES 3 /* 2^3 = 8 dB LPC gain */
#define LOG2_INV_LPC_GAIN_LOW_THRES 8 /* 2^8 = 24 dB LPC gain */
#define PITCH_DRIFT_FAC_Q16 655 /* 0.01 in Q16 */

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -33,173 +33,87 @@ extern "C"
{
#endif
#define SigProc_MAX_ORDER_LPC 16 /* max order of the LPC analysis in schur() and k2a() */
#define SigProc_MAX_CORRELATION_LENGTH 640 /* max input length to the correlation */
#define SKP_Silk_MAX_ORDER_LPC 16 /* max order of the LPC analysis in schur() and k2a() */
#define SKP_Silk_MAX_CORRELATION_LENGTH 640 /* max input length to the correlation */
#include "SKP_Silk_typedef.h"
#include <string.h>
#include <stdlib.h> /* for abs() */
#include "SKP_Silk_macros.h"
#include "SKP_Silk_resample_rom.h"
#include "SKP_Silk_resampler_structs.h"
# include "SKP_Silk_macros.h"
/********************************************************************/
/* SIGNAL PROCESSING FUNCTIONS */
/********************************************************************/
/* downsample by a factor 2 */
void SKP_Silk_resample_1_2(
const SKP_int16 *in, /* I: 16 kHz signal [2*len] */
SKP_int32 *S, /* I/O: State vector [6] */
SKP_int16 *out, /* O: 8 kHz signal [len] */
SKP_int32 *scratch, /* I: Scratch memory [4*len] */
const SKP_int32 len /* I: Number of OUTPUT samples */
/*!
* Initialize/reset the resampler state for a given pair of input/output sampling rates
*/
SKP_int SKP_Silk_resampler_init(
SKP_Silk_resampler_state_struct *S, /* I/O: Resampler state */
SKP_int32 Fs_Hz_in, /* I: Input sampling rate (Hz) */
SKP_int32 Fs_Hz_out /* I: Output sampling rate (Hz) */
);
/*!
* downsample by a factor 2, coarser (good for resampling audio)
*/
void SKP_Silk_resample_1_2_coarse(
const SKP_int16 *in, /* I: 16 kHz signal [2*len] */
SKP_int32 *S, /* I/O: state vector [4] */
SKP_int16 *out, /* O: 8 kHz signal [len] */
SKP_int32 *scratch, /* I: scratch memory [3*len] */
const SKP_int32 len /* I: number of OUTPUT samples */
);
/*!
* downsample by a factor 2, coarsest (good for signals that are already oversampled, or for analysis purposes)
/*!
* Clear the states of all resampling filters, without resetting sampling rate ratio
*/
void SKP_Silk_resample_1_2_coarsest(
const SKP_int16 *in, /* I: 16 kHz signal [2*len] */
SKP_int32 *S, /* I/O: State vector [2] */
SKP_int16 *out, /* O: 8 kHz signal [len] */
SKP_int32 *scratch, /* I: Scratch memory [3*len] */
const SKP_int32 len /* I: Number of OUTPUT samples */
);
/*!
* upsample by a factor 2, coarser (good for resampling audio)
*/
void SKP_Silk_resample_2_1_coarse(
const SKP_int16 *in, /* I: 8 kHz signal [len] */
SKP_int32 *S, /* I/O: State vector [4] */
SKP_int16 *out, /* O: 16 kHz signal [2*len] */
SKP_int32 *scratch, /* I: Scratch memory [3*len] */
const SKP_int32 len /* I: Number of INPUT samples */
SKP_int SKP_Silk_resampler_clear(
SKP_Silk_resampler_state_struct *S /* I/O: Resampler state */
);
/*!
* Resamples by a factor 1/3
* Resampler: convert from one sampling rate to another
*/
void SKP_Silk_resample_1_3(
SKP_int16 *out, /* O: Fs_low signal [inLen/3] */
SKP_int32 *S, /* I/O: State vector [7] */
const SKP_int16 *in, /* I: Fs_high signal [inLen] */
const SKP_int32 inLen /* I: Input length, must be a multiple of 3 */
SKP_int SKP_Silk_resampler(
SKP_Silk_resampler_state_struct *S, /* I/O: Resampler state */
SKP_int16 out[], /* O: Output signal */
const SKP_int16 in[], /* I: Input signal */
SKP_int32 inLen /* I: Number of input samples */
);
/*!
* Resamples by a factor 3/1
Upsample 2x, low quality
*/
void SKP_Silk_resample_3_1(
SKP_int16 *out, /* O: Fs_high signal [inLen*3] */
SKP_int32 *S, /* I/O: State vector [7] */
const SKP_int16 *in, /* I: Fs_low signal [inLen] */
const SKP_int32 inLen /* I: Input length */
void SKP_Silk_resampler_up2(
SKP_int32 *S, /* I/O: State vector [ 2 ] */
SKP_int16 *out, /* O: Output signal [ 2 * len ] */
const SKP_int16 *in, /* I: Input signal [ len ] */
SKP_int32 len /* I: Number of input samples */
);
/*!
* Resamples by a factor 2/3
*/
void SKP_Silk_resample_2_3(
SKP_int16 *out, /* O: Fs_low signal [inLen * 2/3] */
SKP_int32 *S, /* I/O: State vector [7+4] */
const SKP_int16 *in, /* I: Fs_high signal [inLen] */
const SKP_int inLen /* I: Input length, must be a multiple of 3 */
);
* Downsample 2x, mediocre quality
*/
void SKP_Silk_resampler_down2(
SKP_int32 *S, /* I/O: State vector [ 2 ] */
SKP_int16 *out, /* O: Output signal [ len ] */
const SKP_int16 *in, /* I: Input signal [ floor(len/2) ] */
SKP_int32 inLen /* I: Number of input samples */
);
/*!
* Resamples by a factor 3/2
*/
void SKP_Silk_resample_3_2(
SKP_int16 *out, /* O: Fs_high signal [inLen*3/2] */
SKP_int32 *S, /* I/O: State vector [7+4] */
const SKP_int16 *in, /* I: Fs_low signal [inLen] */
SKP_int inLen /* I: Input length, must be a multiple of 2 */
* Downsample by a factor 2/3, low quality
*/
void SKP_Silk_resampler_down2_3(
SKP_int32 *S, /* I/O: State vector [ 6 ] */
SKP_int16 *out, /* O: Output signal [ floor(2*inLen/3) ] */
const SKP_int16 *in, /* I: Input signal [ inLen ] */
SKP_int32 inLen /* I: Number of input samples */
);
/*!
* Resamples by a factor 4/3
*/
void SKP_Silk_resample_4_3(
SKP_int16 *out, /* O: Fs_low signal [inLen * 4/3] */
SKP_int32 *S, /* I/O: State vector [7+4+4] */
const SKP_int16 *in, /* I: Fs_high signal [inLen] */
const SKP_int inLen /* I: input length, must be a multiple of 3 */
);
/*!
* Resamples by a factor 3/4
*/
void SKP_Silk_resample_3_4(
SKP_int16 *out, /* O: Fs_high signal [inLen*3/4] */
SKP_int32 *S, /* I/O: State vector [7+2+6] */
const SKP_int16 *in, /* I: Fs_low signal [inLen] */
SKP_int inLen /* I: Input length, must be a multiple of 4 */
);
/*!
* resample with a factor 2/3 coarse
*/
void SKP_Silk_resample_2_3_coarse(
SKP_int16 *out, /* O: Output signal */
SKP_int16 *S, /* I/O: Resampler state [ SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ] */
const SKP_int16 *in, /* I: Input signal */
const SKP_int frameLenIn, /* I: Number of input samples */
SKP_int16 *scratch /* I: Scratch memory [ frameLenIn + SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ] */
);
/*!
* resample with a factor 2/3 coarsest
*/
void SKP_Silk_resample_2_3_coarsest(
SKP_int16 *out, /* O: Output signal */
SKP_int16 *S, /* I/O: Resampler state [ SigProc_Resample_2_3_coarsest_NUM_FIR_COEFS - 1 ] */
const SKP_int16 *in, /* I: Input signal */
const SKP_int frameLenIn, /* I: Number of input samples */
SKP_int16 *scratch /* I: Scratch memory [ frameLenIn + SigProc_Resample_2_3_coarsest_NUM_FIR_COEFS - 1 ] */
);
/*!
* 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 */
* Downsample by a factor 3, low quality
*/
void SKP_Silk_resampler_down3(
SKP_int32 *S, /* I/O: State vector [ 8 ] */
SKP_int16 *out, /* O: Output signal [ floor(inLen/3) ] */
const SKP_int16 *in, /* I: Input signal [ inLen ] */
SKP_int32 inLen /* I: Number of input samples */
);
/*!
@ -240,15 +154,6 @@ void SKP_Silk_MA_Prediction(
const SKP_int32 order /* I: Filter order */
);
void SKP_Silk_MA_Prediction_Q13(
const SKP_int16 *in, /* I: input signal */
const SKP_int16 *B, /* I: MA prediction coefficients, Q13 [order] */
SKP_int32 *S, /* I/O: state vector [order] */
SKP_int16 *out, /* O: output signal */
SKP_int32 len, /* I: signal length */
SKP_int32 order /* I: filter order */
);
/*!
* 16th order AR filter for LPC synthesis, coefficients are in Q12
*/
@ -305,10 +210,10 @@ SKP_int SKP_Silk_LPC_inverse_pred_gain( /* O: Returns 1 if unstable, otherwise
const SKP_int order /* I: Prediction order */
);
SKP_int SKP_Silk_LPC_inverse_pred_gain_Q13( /* O: returns 1 if unstable, otherwise 0 */
SKP_int32 *invGain_Q30, /* O: Inverse prediction gain, Q30 energy domain */
const SKP_int16 *A_Q13, /* I: Prediction coefficients, Q13 [order] */
const SKP_int order /* I: Prediction order */
SKP_int SKP_Silk_LPC_inverse_pred_gain_Q24( /* O: Returns 1 if unstable, otherwise 0 */
SKP_int32 *invGain_Q30, /* O: Inverse prediction gain, Q30 energy domain */
const SKP_int32 *A_Q24, /* I: Prediction coefficients, Q24 [order] */
const SKP_int order /* I: Prediction order */
);
/* split signal in two decimated bands using first-order allpass filters */
@ -353,12 +258,12 @@ void SKP_Silk_sum_sqr_shift(
/* Calculates the reflection coefficients from the correlation sequence */
/* Faster than schur64(), but much less accurate. */
/* Uses SMLAWB(), requiring armv5E and higher. */
void SKP_Silk_schur(
SKP_int16 *rc_Q15, /* O: reflection coefficients [order] Q15 */
const SKP_int32 *c, /* I: correlations [order+1] */
const SKP_int32 order /* I: prediction order */
);
/* uses SMLAWB(), requiring armv5E and higher. */
SKP_int32 SKP_Silk_schur( /* O: Returns residual energy */
SKP_int16 *rc_Q15, /* O: reflection coefficients [order] Q15 */
const SKP_int32 *c, /* I: correlations [order+1] */
const SKP_int32 order /* I: prediction order */
);;
/* Calculates the reflection coefficients from the correlation sequence */
/* Slower than schur(), but more accurate. */
@ -385,30 +290,30 @@ void SKP_Silk_k2a_Q16(
/* Apply sine window to signal vector. */
/* Window types: */
/* 0 -> sine window from 0 to pi */
/* 1 -> sine window from 0 to pi/2 */
/* 2 -> sine window from pi/2 to pi */
/* every other sample of window is linearly interpolated, for speed */
void SKP_Silk_apply_sine_window(
SKP_int16 px_win[], /* O Pointer to windowed signal */
const SKP_int16 px[], /* I Pointer to input signal */
const SKP_int win_type, /* I Selects a window type */
const SKP_int length /* I Window length, multiple of 4 */
/* Every other sample is linearly interpolated, for speed. */
/* Window length must be between 16 and 120 (incl) and a multiple of 4. */
void SKP_Silk_apply_sine_window_new(
SKP_int16 px_win[], /* O Pointer to windowed signal */
const SKP_int16 px[], /* I Pointer to input signal */
const SKP_int win_type, /* I Selects a window type */
const SKP_int length /* I Window length, multiple of 4 */
);
/* Compute autocorrelation */
void SKP_Silk_autocorr(
SKP_int32 *results, /* O Result (length correlationCount) */
SKP_int32 *scale, /* O Scaling of the correlation vector */
SKP_int *scale, /* O Scaling of the correlation vector */
const SKP_int16 *inputData, /* I Input data to correlate */
const SKP_int inputDataSize, /* I Length of input */
const SKP_int correlationCount /* I Number of correlation taps to compute */
);
/* Pitch estimator */
#define SigProc_PITCH_EST_MIN_COMPLEX 0
#define SigProc_PITCH_EST_MID_COMPLEX 1
#define SigProc_PITCH_EST_MAX_COMPLEX 2
#define SKP_Silk_PITCH_EST_MIN_COMPLEX 0
#define SKP_Silk_PITCH_EST_MID_COMPLEX 1
#define SKP_Silk_PITCH_EST_MAX_COMPLEX 2
void SKP_Silk_decode_pitch(
SKP_int lagIndex, /* I */
@ -417,17 +322,18 @@ void SKP_Silk_decode_pitch(
SKP_int Fs_kHz /* I sampling frequency (kHz) */
);
SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unvoiced */
const SKP_int16 *signal, /* I Signal of length PITCH_EST_FRAME_LENGTH_MS*Fs_kHz */
SKP_int *pitch_out, /* O 4 pitch lag values */
SKP_int *lagIndex, /* O Lag Index */
SKP_int *contourIndex, /* O Pitch contour Index */
SKP_int *LTPCorr_Q15, /* I/O Normalized correlation; input: value from previous frame */
SKP_int prevLag, /* I Last lag of previous frame; set to zero is unvoiced */
const SKP_int32 search_thres1_Q16, /* I First stage threshold for lag candidates 0 - 1 */
const SKP_int search_thres2_Q15, /* I Final threshold for lag candidates 0 - 1 */
const SKP_int Fs_kHz, /* I Sample frequency (kHz) */
const SKP_int complexity /* I Complexity setting, 0-2, where 2 is highest */
SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unvoiced */
const SKP_int16 *signal, /* I Signal of length PITCH_EST_FRAME_LENGTH_MS*Fs_kHz */
SKP_int *pitch_out, /* O 4 pitch lag values */
SKP_int *lagIndex, /* O Lag Index */
SKP_int *contourIndex, /* O Pitch contour Index */
SKP_int *LTPCorr_Q15, /* I/O Normalized correlation; input: value from previous frame */
SKP_int prevLag, /* I Last lag of previous frame; set to zero is unvoiced */
const SKP_int32 search_thres1_Q16, /* I First stage threshold for lag candidates 0 - 1 */
const SKP_int search_thres2_Q15, /* I Final threshold for lag candidates 0 - 1 */
const SKP_int Fs_kHz, /* I Sample frequency (kHz) */
const SKP_int complexity, /* I Complexity setting, 0-2, where 2 is highest */
const SKP_int forLJC /* I 1 if this function is called from LJC code, 0 otherwise. */
);
/* parameter defining the size and accuracy of the piecewise linear */
@ -437,13 +343,6 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1
/* rom table with cosine values */
extern const SKP_int SKP_Silk_LSFCosTab_FIX_Q12[ LSF_COS_TAB_SZ_FIX + 1 ];
void SKP_Silk_LPC_fit(
SKP_int16 *a_QQ, /* O stabilized LPC vector, Q(24-rshift) [L] */
SKP_int32 *a_Q24, /* I LPC vector [L] */
const SKP_int QQ, /* I Q domain of output LPC vector */
const SKP_int L /* I Number of LPC parameters in the input vector */
);
/* 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(
@ -466,13 +365,6 @@ void SKP_Silk_insertion_sort_increasing(
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 */
@ -492,14 +384,6 @@ void SKP_Silk_NLSF_stabilize(
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_Q6, /* O: Pointer to input vector weights [D x 1] */
@ -519,13 +403,6 @@ void SKP_Silk_burg_modified(
const SKP_int D /* I order */
);
/* Multiply a vector by a constant */
void SKP_Silk_scale_vector16_Q14(
SKP_int16 *data1,
SKP_int gain_Q14, /* Gain in Q14 */
SKP_int dataSize
);
/* Copy and multiply a vector by a constant */
void SKP_Silk_scale_copy_vector16(
SKP_int16 *data_out,
@ -534,19 +411,6 @@ void SKP_Silk_scale_copy_vector16(
const SKP_int dataSize /* I: length */
);
void SKP_Silk_scale_vector32_16_Q14(
SKP_int32 *data1, /* I/O: Q0/Q0 */
SKP_int gain_Q14, /* I: Q14 */
SKP_int dataSize /* I: length */
);
/* Multiply a vector by a constant, does not saturate output data */
void SKP_Silk_scale_vector32_Q16(
SKP_int32 *data1, /* I/O: Q0/Q0 */
SKP_int32 gain_Q16, /* I: gain in Q16 ( SKP_int16_MIN <= gain_Q16 <= SKP_int16_MAX + 65536 ) */
const SKP_int dataSize /* I: length */
);
/* Some for the LTP related function requires Q26 to work.*/
void SKP_Silk_scale_vector32_Q26_lshift_18(
SKP_int32 *data1, /* I/O: Q0/Q18 */
@ -566,31 +430,32 @@ SKP_int32 SKP_Silk_inner_prod_aligned(
const SKP_int len /* I vector lengths */
);
SKP_int32 SKP_Silk_inner_prod16_aligned_sat(
const SKP_int16* const inVec1, /* I input vector 1 */
const SKP_int16* const inVec2, /* I input vector 2 */
const SKP_int len /* I vector lengths */
);
SKP_int64 SKP_Silk_inner_prod_aligned_64(
const SKP_int32 *inVec1, /* I input vector 1 */
const SKP_int32 *inVec2, /* I input vector 2 */
const SKP_int len /* I vector lengths */
);
SKP_int64 SKP_Silk_inner_prod16_aligned_64(
const SKP_int16 *inVec1, /* I input vector 1 */
const SKP_int16 *inVec1, /* I input vector 1 */
const SKP_int16 *inVec2, /* I input vector 2 */
const SKP_int len /* I vector lengths */
);
/********************************************************************/
/* MACROS */
/* MACROS */
/********************************************************************/
/* Define 4-byte aligned array of SKP_int16 */
#define SKP_array_of_int16_4_byte_aligned( arrayName, nElements ) \
SKP_int32 dummy_int32 ## arrayName; \
SKP_int16 arrayName[ (nElements) ]
/* Rotate a32 right by 'rot' bits. Negative rot values result in rotating
left. Output is 32bit int.
Note: contemporary compilers recognize the C expression below and
compile it into a 'ror' instruction if available. No need for inline ASM! */
SKP_INLINE SKP_int32 SKP_ROR32( SKP_int32 a32, SKP_int rot )
{
SKP_uint32 x = (SKP_uint32) a32;
SKP_uint32 r = (SKP_uint32) rot;
SKP_uint32 m = (SKP_uint32) -rot;
if(rot <= 0)
return (SKP_int32) ((x << m) | (x >> (32 - m)));
else
return (SKP_int32) ((x << (32 - r)) | (x >> r));
}
/* Allocate SKP_int16 alligned to 4-byte memory address */
#define SKP_DWORD_ALIGN
/* Useful Macros that can be adjusted to other platforms */
#define SKP_memcpy(a, b, c) memcpy((a), (b), (c)) /* Dest, Src, ByteCount */
@ -607,12 +472,6 @@ SKP_int64 SKP_Silk_inner_prod16_aligned_64(
// a32 + (b32 * c32) output have to be 32bit int
#define SKP_MLA(a32, b32, c32) SKP_ADD32((a32),((b32) * (c32)))
// a32 + (b32 * c32) output have to be 32bit uint
#define SKP_MLA_uint(a32, b32, c32) SKP_MLA(a32, b32, c32)
// ((a32 >> 16) * (b32 >> 16)) output have to be 32bit int
#define SKP_SMULTT(a32, b32) (((a32) >> 16) * ((b32) >> 16))
// a32 + ((a32 >> 16) * (b32 >> 16)) output have to be 32bit int
#define SKP_SMLATT(a32, b32, c32) SKP_ADD32((a32),((b32) >> 16) * ((c32) >> 16))
@ -626,70 +485,40 @@ SKP_int64 SKP_Silk_inner_prod16_aligned_64(
#ifndef SKP_SMLABB_ovflw
# define SKP_SMLABB_ovflw(a32, b32, c32) SKP_SMLABB(a32, b32, c32)
#endif
#define SKP_SMLABT_ovflw(a32, b32, c32) SKP_SMLABT(a32, b32, c32)
#define SKP_SMLATT_ovflw(a32, b32, c32) SKP_SMLATT(a32, b32, c32)
#define SKP_SMLAWB_ovflw(a32, b32, c32) SKP_SMLAWB(a32, b32, c32)
#define SKP_SMLAWT_ovflw(a32, b32, c32) SKP_SMLAWT(a32, b32, c32)
#define SKP_DIV64_32(a64, b32) ((a64)/(b32)) /* TODO: rewrite it as a set of SKP_DIV32.*/
#define SKP_DIV32_16(a32, b16) ((SKP_int32)((a32) / (b16)))
#define SKP_DIV32(a32, b32) ((SKP_int32)((a32) / (b32)))
// These macros enables checking for overflow in SKP_Silk_API_Debug.h
#define SKP_ADD16(a, b) ((a) + (b))
#define SKP_ADD32(a, b) ((a) + (b))
#define SKP_ADD64(a, b) ((a) + (b))
#define SKP_SUB16(a, b) ((a) - (b))
#define SKP_SUB32(a, b) ((a) - (b))
#define SKP_SUB64(a, b) ((a) - (b))
#define SKP_SAT8(a) ((a) > SKP_int8_MAX ? SKP_int8_MAX : \
((a) < SKP_int8_MIN ? SKP_int8_MIN : (a)))
#define SKP_SAT16(a) ((a) > SKP_int16_MAX ? SKP_int16_MAX : \
((a) < SKP_int16_MIN ? SKP_int16_MIN : (a)))
#define SKP_SAT32(a) ((a) > SKP_int32_MAX ? SKP_int32_MAX : \
((a) < SKP_int32_MIN ? SKP_int32_MIN : (a)))
#define SKP_CHECK_FIT8(a) (a)
#define SKP_CHECK_FIT16(a) (a)
#define SKP_CHECK_FIT32(a) (a)
#define SKP_ADD_SAT16(a, b) (SKP_int16)SKP_SAT16( SKP_ADD32( (SKP_int32)(a), (b) ) )
#define SKP_ADD_SAT64(a, b) ((((a) + (b)) & 0x8000000000000000LL) == 0 ? \
((((a) & (b)) & 0x8000000000000000LL) != 0 ? SKP_int64_MIN : (a)+(b)) : \
((((a) | (b)) & 0x8000000000000000LL) == 0 ? SKP_int64_MAX : (a)+(b)) )
#define SKP_SUB_SAT16(a, b) (SKP_int16)SKP_SAT16( SKP_SUB32( (SKP_int32)(a), (b) ) )
#define SKP_SUB_SAT64(a, b) ((((a)-(b)) & 0x8000000000000000LL) == 0 ? \
(( (a) & ((b)^0x8000000000000000LL) & 0x8000000000000000LL) ? SKP_int64_MIN : (a)-(b)) : \
((((a)^0x8000000000000000LL) & (b) & 0x8000000000000000LL) ? SKP_int64_MAX : (a)-(b)) )
/* Saturation for positive input values */
#define SKP_POS_SAT32(a) ((a) > SKP_int32_MAX ? SKP_int32_MAX : (a))
/* Add with saturation for positive input values */
#define SKP_ADD_POS_SAT8(a, b) ((((a)+(b)) & 0x80) ? SKP_int8_MAX : ((a)+(b)))
#define SKP_ADD_POS_SAT16(a, b) ((((a)+(b)) & 0x8000) ? SKP_int16_MAX : ((a)+(b)))
#define SKP_ADD_POS_SAT32(a, b) ((((a)+(b)) & 0x80000000) ? SKP_int32_MAX : ((a)+(b)))
#define SKP_ADD_POS_SAT64(a, b) ((((a)+(b)) & 0x8000000000000000LL) ? SKP_int64_MAX : ((a)+(b)))
#define SKP_LSHIFT8(a, shift) ((a)<<(shift)) // shift >= 0, shift < 8
#define SKP_LSHIFT16(a, shift) ((a)<<(shift)) // shift >= 0, shift < 16
#define SKP_LSHIFT32(a, shift) ((a)<<(shift)) // shift >= 0, shift < 32
#define SKP_LSHIFT64(a, shift) ((a)<<(shift)) // shift >= 0, shift < 64
#define SKP_LSHIFT(a, shift) SKP_LSHIFT32(a, shift) // shift >= 0, shift < 32
#define SKP_RSHIFT8(a, shift) ((a)>>(shift)) // shift >= 0, shift < 8
#define SKP_RSHIFT16(a, shift) ((a)>>(shift)) // shift >= 0, shift < 16
#define SKP_RSHIFT32(a, shift) ((a)>>(shift)) // shift >= 0, shift < 32
#define SKP_RSHIFT64(a, shift) ((a)>>(shift)) // shift >= 0, shift < 64
#define SKP_RSHIFT(a, shift) SKP_RSHIFT32(a, shift) // shift >= 0, shift < 32
/* saturates before shifting */
#define SKP_LSHIFT_SAT16(a, shift) (SKP_LSHIFT16( SKP_LIMIT( (a), SKP_RSHIFT16( SKP_int16_MIN, (shift) ), \
SKP_RSHIFT16( SKP_int16_MAX, (shift) ) ), (shift) ))
#define SKP_LSHIFT_SAT32(a, shift) (SKP_LSHIFT32( SKP_LIMIT( (a), SKP_RSHIFT32( SKP_int32_MIN, (shift) ), \
SKP_RSHIFT32( SKP_int32_MAX, (shift) ) ), (shift) ))
@ -699,7 +528,6 @@ SKP_int64 SKP_Silk_inner_prod16_aligned_64(
#define SKP_ADD_LSHIFT(a, b, shift) ((a) + SKP_LSHIFT((b), (shift))) // shift >= 0
#define SKP_ADD_LSHIFT32(a, b, shift) SKP_ADD32((a), SKP_LSHIFT32((b), (shift))) // shift >= 0
#define SKP_ADD_LSHIFT_uint(a, b, shift) ((a) + SKP_LSHIFT_uint((b), (shift))) // shift >= 0
#define SKP_ADD_RSHIFT(a, b, shift) ((a) + SKP_RSHIFT((b), (shift))) // shift >= 0
#define SKP_ADD_RSHIFT32(a, b, shift) SKP_ADD32((a), SKP_RSHIFT32((b), (shift))) // shift >= 0
#define SKP_ADD_RSHIFT_uint(a, b, shift) ((a) + SKP_RSHIFT_uint((b), (shift))) // shift >= 0
@ -712,32 +540,23 @@ SKP_int64 SKP_Silk_inner_prod16_aligned_64(
/* Number of rightshift required to fit the multiplication */
#define SKP_NSHIFT_MUL_32_32(a, b) ( -(31- (32-SKP_Silk_CLZ32(SKP_abs(a)) + (32-SKP_Silk_CLZ32(SKP_abs(b))))) )
#define SKP_NSHIFT_MUL_16_16(a, b) ( -(15- (16-SKP_Silk_CLZ16(SKP_abs(a)) + (16-SKP_Silk_CLZ16(SKP_abs(b))))) )
#define SKP_min(a, b) (((a) < (b)) ? (a) : (b))
#define SKP_max(a, b) (((a) > (b)) ? (a) : (b))
/* Macro to convert floating-point constants to fixed-point */
#define SKP_FIX_CONST( C, Q ) ((SKP_int32)((C) * (1 << (Q)) + 0.5))
#define SKP_FIX_CONST( C, Q ) ((SKP_int32)((C) * ((SKP_int64)1 << (Q)) + 0.5))
/* SKP_min() versions with typecast in the function call */
SKP_INLINE SKP_int SKP_min_int(SKP_int a, SKP_int b)
{
return (((a) < (b)) ? (a) : (b));
}
SKP_INLINE SKP_int16 SKP_min_16(SKP_int16 a, SKP_int16 b)
{
return (((a) < (b)) ? (a) : (b));
}
SKP_INLINE SKP_int32 SKP_min_32(SKP_int32 a, SKP_int32 b)
{
return (((a) < (b)) ? (a) : (b));
}
SKP_INLINE SKP_int64 SKP_min_64(SKP_int64 a, SKP_int64 b)
{
return (((a) < (b)) ? (a) : (b));
}
/* SKP_min() versions with typecast in the function call */
SKP_INLINE SKP_int SKP_max_int(SKP_int a, SKP_int b)
@ -752,24 +571,17 @@ SKP_INLINE SKP_int32 SKP_max_32(SKP_int32 a, SKP_int32 b)
{
return (((a) > (b)) ? (a) : (b));
}
SKP_INLINE SKP_int64 SKP_max_64(SKP_int64 a, SKP_int64 b)
{
return (((a) > (b)) ? (a) : (b));
}
#define SKP_LIMIT( a, limit1, limit2) ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \
: ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))))
#define SKP_LIMIT_int SKP_LIMIT
#define SKP_LIMIT_32 SKP_LIMIT
//#define SKP_non_neg(a) ((a) & ((-(a)) >> (8 * sizeof(a) - 1))) /* doesn't seem faster than SKP_max(0, a);
#define SKP_abs(a) (((a) > 0) ? (a) : -(a)) // Be careful, SKP_abs returns wrong when input equals to SKP_intXX_MIN
#define SKP_abs_int(a) (((a) ^ ((a) >> (8 * sizeof(a) - 1))) - ((a) >> (8 * sizeof(a) - 1)))
#define SKP_abs_int32(a) (((a) ^ ((a) >> 31)) - ((a) >> 31))
#define SKP_abs_int64(a) (((a) > 0) ? (a) : -(a))
#define SKP_sign(a) ((a) > 0 ? 1 : ( (a) < 0 ? -1 : 0 ))
#define SKP_sqrt(a) (sqrt(a))
/* PSEUDO-RANDOM GENERATOR */
/* Make sure to store the result as the seed for the next call (also in between */

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -141,7 +141,7 @@ SKP_int SKP_Silk_VAD_GetSA_Q8( /* O Retu
for( s = 0; s < VAD_INTERNAL_SUBFRAMES; s++ ) {
sumSquared = 0;
for( i = 0; i < dec_subframe_length; i++ ) {
/* The energy will be less than dec_subframe_length * ( SKP_int16_MIN / 8 )^2. */
/* The energy will be less than dec_subframe_length * ( SKP_int16_MIN / 8 ) ^ 2. */
/* Therefore we can accumulate with no risk of overflow (unless dec_subframe_length > 128) */
x_tmp = SKP_RSHIFT( X[ b ][ i + dec_subframe_offset ], 3 );
sumSquared = SKP_SMLABB( sumSquared, x_tmp, x_tmp );
@ -150,11 +150,11 @@ SKP_int SKP_Silk_VAD_GetSA_Q8( /* O Retu
SKP_assert( sumSquared >= 0 );
}
/* add/saturate summed energy of current subframe */
/* Add/saturate summed energy of current subframe */
if( s < VAD_INTERNAL_SUBFRAMES - 1 ) {
Xnrg[ b ] = SKP_ADD_POS_SAT32( Xnrg[ b ], sumSquared );
} else {
/* look-ahead subframe */
/* Look-ahead subframe */
Xnrg[ b ] = SKP_ADD_POS_SAT32( Xnrg[ b ], SKP_RSHIFT( sumSquared, 1 ) );
}
@ -201,7 +201,7 @@ SKP_int SKP_Silk_VAD_GetSA_Q8( /* O Retu
}
/* Mean-of-squares */
sumSquared = SKP_DIV32_16( sumSquared, VAD_N_BANDS ); /* Q14 */
sumSquared = SKP_DIV32_16( sumSquared, VAD_N_BANDS ); /* Q14 */
/* Root-mean-square approximation, scale to dBs, and write to output pointer */
*pSNR_dB_Q7 = ( SKP_int16 )( 3 * SKP_Silk_SQRT_APPROX( sumSquared ) ); /* Q7 */
@ -240,7 +240,7 @@ SKP_int SKP_Silk_VAD_GetSA_Q8( /* O Retu
/***********************************/
/* Energy Level and SNR estimation */
/***********************************/
/* smoothing coefficient */
/* Smoothing coefficient */
smooth_coef_Q16 = SKP_SMULWB( VAD_SNR_SMOOTH_COEF_Q18, SKP_SMULWB( SA_Q15, SA_Q15 ) );
for( b = 0; b < VAD_N_BANDS; b++ ) {
/* compute smoothed energy-to-noise ratio per band */

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -41,60 +41,57 @@ void SKP_Silk_VQ_WMat_EC_FIX(
{
SKP_int k;
const SKP_int16 *cb_row_Q14;
SKP_int32 sum1_Q14, sum2_Q16, diff_Q14_01, diff_Q14_23, diff_Q14_4;
SKP_int16 diff_Q14[ 5 ];
SKP_int32 sum1_Q14, sum2_Q16;
/* Loop over codebook */
*rate_dist_Q14 = SKP_int32_MAX;
cb_row_Q14 = cb_Q14;
for( k = 0; k < L; k++ ) {
/* Pack pairs of int16 values per int32 */
diff_Q14_01 = (SKP_uint16)( in_Q14[ 0 ] - cb_row_Q14[ 0 ] ) | SKP_LSHIFT( ( SKP_int32 )in_Q14[ 1 ] - cb_row_Q14[ 1 ], 16 );
diff_Q14_23 = (SKP_uint16)( in_Q14[ 2 ] - cb_row_Q14[ 2 ] ) | SKP_LSHIFT( ( SKP_int32 )in_Q14[ 3 ] - cb_row_Q14[ 3 ], 16 );
diff_Q14_4 = in_Q14[ 4 ] - cb_row_Q14[ 4 ];
diff_Q14[ 0 ] = in_Q14[ 0 ] - cb_row_Q14[ 0 ];
diff_Q14[ 1 ] = in_Q14[ 1 ] - cb_row_Q14[ 1 ];
diff_Q14[ 2 ] = in_Q14[ 2 ] - cb_row_Q14[ 2 ];
diff_Q14[ 3 ] = in_Q14[ 3 ] - cb_row_Q14[ 3 ];
diff_Q14[ 4 ] = in_Q14[ 4 ] - cb_row_Q14[ 4 ];
/* Weighted rate */
sum1_Q14 = SKP_SMULBB( mu_Q8, cl_Q6[ k ] );
SKP_assert( sum1_Q14 >= 0 );
/* Add weighted quantization error, assuming W_Q18 is symmetric */
/* NOTE: the code below loads two int16 values as one int32, and multiplies each using the */
/* SMLAWB and SMLAWT instructions. On a big-endian CPU the two int16 variables would be */
/* loaded in reverse order and the code will give the wrong result. In that case swapping */
/* the SMLAWB and SMLAWT instructions should solve the problem. */
/* first row of W_Q18 */
sum2_Q16 = SKP_SMULWT( W_Q18[ 1 ], diff_Q14_01 );
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 2 ], diff_Q14_23 );
sum2_Q16 = SKP_SMLAWT( sum2_Q16, W_Q18[ 3 ], diff_Q14_23 );
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 4 ], diff_Q14_4 );
sum2_Q16 = SKP_SMULWB( W_Q18[ 1 ], diff_Q14[ 1 ] );
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 2 ], diff_Q14[ 2 ] );
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 3 ], diff_Q14[ 3 ] );
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 4 ], diff_Q14[ 4 ] );
sum2_Q16 = SKP_LSHIFT( sum2_Q16, 1 );
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 0 ], diff_Q14_01 );
sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14_01 );
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 0 ], diff_Q14[ 0 ] );
sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14[ 0 ] );
/* second row of W_Q18 */
sum2_Q16 = SKP_SMULWB( W_Q18[ 7 ], diff_Q14_23 );
sum2_Q16 = SKP_SMLAWT( sum2_Q16, W_Q18[ 8 ], diff_Q14_23 );
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 9 ], diff_Q14_4 );
sum2_Q16 = SKP_SMULWB( W_Q18[ 7 ], diff_Q14[ 2 ] );
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 8 ], diff_Q14[ 3 ] );
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 9 ], diff_Q14[ 4 ] );
sum2_Q16 = SKP_LSHIFT( sum2_Q16, 1 );
sum2_Q16 = SKP_SMLAWT( sum2_Q16, W_Q18[ 6 ], diff_Q14_01 );
sum1_Q14 = SKP_SMLAWT( sum1_Q14, sum2_Q16, diff_Q14_01 );
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 6 ], diff_Q14[ 1 ] );
sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14[ 1 ] );
/* third row of W_Q18 */
sum2_Q16 = SKP_SMULWT( W_Q18[ 13 ], diff_Q14_23 );
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 14 ], diff_Q14_4 );
sum2_Q16 = SKP_SMULWB( W_Q18[ 13 ], diff_Q14[ 3 ] );
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 14 ], diff_Q14[ 4 ] );
sum2_Q16 = SKP_LSHIFT( sum2_Q16, 1 );
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 12 ], diff_Q14_23 );
sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14_23 );
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 12 ], diff_Q14[ 2 ] );
sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14[ 2 ] );
/* fourth row of W_Q18 */
sum2_Q16 = SKP_SMULWB( W_Q18[ 19 ], diff_Q14_4 );
sum2_Q16 = SKP_SMULWB( W_Q18[ 19 ], diff_Q14[ 4 ] );
sum2_Q16 = SKP_LSHIFT( sum2_Q16, 1 );
sum2_Q16 = SKP_SMLAWT( sum2_Q16, W_Q18[ 18 ], diff_Q14_23 );
sum1_Q14 = SKP_SMLAWT( sum1_Q14, sum2_Q16, diff_Q14_23 );
sum2_Q16 = SKP_SMLAWB( sum2_Q16, W_Q18[ 18 ], diff_Q14[ 3 ] );
sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14[ 3 ] );
/* last row of W_Q18 */
sum2_Q16 = SKP_SMULWB( W_Q18[ 24 ], diff_Q14_4 );
sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14_4 );
sum2_Q16 = SKP_SMULWB( W_Q18[ 24 ], diff_Q14[ 4 ] );
sum1_Q14 = SKP_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14[ 4 ] );
SKP_assert( sum1_Q14 >= 0 );

View File

@ -1,69 +0,0 @@
/***********************************************************************
Copyright (c) 2006-2010, 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.
***********************************************************************/
/* *
* SKP_Silk_allpass_int.c *
* *
* First-order allpass filter with *
* transfer function: *
* *
* A + Z^(-1) *
* H(z) = ------------ *
* 1 + A*Z^(-1) *
* *
* Implemented using minimum multiplier filter design. *
* *
* Reference: http://www.univ.trieste.it/~ramponi/teaching/ *
* DSP/materiale/Ch6(2).pdf *
* *
* Copyright 2007 (c), Skype Limited *
* Date: 070525 *
* */
#include "SKP_Silk_SigProc_FIX.h"
/* 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 */
)
{
SKP_int32 Y2, X2, S0;
SKP_int k;
S0 = S[ 0 ];
for( k = len - 1; k >= 0; k-- ) {
Y2 = *in - S0;
X2 = ( Y2 >> 15 ) * A + ( ( ( Y2 & 0x00007FFF ) * A ) >> 15 );
( *out++ ) = S0 + X2;
S0 = ( *in++ ) + X2;
}
S[ 0 ] = S0;
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -36,38 +36,45 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SKP_Silk_SigProc_FIX.h"
/* Coefficients for 2-band filter bank based on first-order allpass filters */
static SKP_int16 A_fb1_20[ 1 ] = { 5394 };
static SKP_int16 A_fb1_21[ 1 ] = { 20623 };
// old
static SKP_int16 A_fb1_20[ 1 ] = { 5394 << 1 };
static SKP_int16 A_fb1_21[ 1 ] = { 20623 << 1 }; /* wrap-around to negative number is intentional */
/* Split signal into two decimated bands using first-order allpass filters */
void SKP_Silk_ana_filt_bank_1(
const SKP_int16 *in, /* I: Input signal [N] */
const SKP_int16 *in, /* I: Input signal [N] */
SKP_int32 *S, /* I/O: State vector [2] */
SKP_int16 *outL, /* O: Low band [N/2] */
SKP_int16 *outH, /* O: High band [N/2] */
SKP_int32 *scratch, /* I: Scratch memory [3*N/2] */
SKP_int16 *outL, /* O: Low band [N/2] */
SKP_int16 *outH, /* O: High band [N/2] */
SKP_int32 *scratch, /* I: Scratch memory [3*N/2] */ // todo: remove - no longer used
const SKP_int32 N /* I: Number of input samples */
)
{
SKP_int k, N2 = SKP_RSHIFT( N, 1 );
SKP_int32 out_tmp;
SKP_int k, N2 = SKP_RSHIFT( N, 1 );
SKP_int32 in32, X, Y, out_1, out_2;
/* De-interleave three allpass inputs, and convert Q15 -> Q25 */
/* Internal variables and state are in Q10 format */
for( k = 0; k < N2; k++ ) {
scratch[ k + N ] = SKP_LSHIFT( (SKP_int32)in[ 2 * k ], 10 );
scratch[ k + N2 ] = SKP_LSHIFT( (SKP_int32)in[ 2 * k + 1 ], 10 );
/* Convert to Q10 */
in32 = SKP_LSHIFT( (SKP_int32)in[ 2 * k ], 10 );
/* All-pass section for even input sample */
Y = SKP_SUB32( in32, S[ 0 ] );
X = SKP_SMLAWB( Y, Y, A_fb1_21[ 0 ] );
out_1 = SKP_ADD32( S[ 0 ], X );
S[ 0 ] = SKP_ADD32( in32, X );
/* Convert to Q10 */
in32 = SKP_LSHIFT( (SKP_int32)in[ 2 * k + 1 ], 10 );
/* All-pass section for odd input sample */
Y = SKP_SUB32( in32, S[ 1 ] );
X = SKP_SMULWB( Y, A_fb1_20[ 0 ] );
out_2 = SKP_ADD32( S[ 1 ], X );
S[ 1 ] = SKP_ADD32( in32, X );
/* Add/subtract, convert back to int16 and store to output */
outL[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( SKP_ADD32( out_2, out_1 ), 11 ) );
outH[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( SKP_SUB32( out_2, out_1 ), 11 ) );
}
/* Allpass filters */
SKP_Silk_allpass_int( scratch + N2, S+0, A_fb1_20[ 0 ], scratch, N2 );
SKP_Silk_allpass_int( scratch + N, S+1, A_fb1_21[ 0 ], scratch + N2, N2 );
/* Add and subtract two allpass outputs to create bands */
for( k = 0; k < N2; k++ ) {
out_tmp = scratch[ k ] + scratch[ k + N2 ];
outL[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out_tmp, 11 ) );
out_tmp = scratch[ k ] - scratch[ k + N2 ];
outH[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( out_tmp, 11 ) );
}
}

View File

@ -1,92 +0,0 @@
/***********************************************************************
Copyright (c) 2006-2010, 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_SigProc_FIX.h"
/* Apply sine window to signal vector. */
/* Window types: */
/* 0 -> sine window from 0 to pi */
/* 1 -> sine window from 0 to pi/2 */
/* 2 -> sine window from pi/2 to pi */
/* every other sample of window is linearly interpolated, for speed */
void SKP_Silk_apply_sine_window(
SKP_int16 px_win[], /* O Pointer to windowed signal */
const SKP_int16 px[], /* I Pointer to input signal */
const SKP_int win_type, /* I Selects a window type */
const SKP_int length /* I Window length, multiple of 4 */
)
{
SKP_int k;
SKP_int32 px32, f_Q16, c_Q20, S0_Q16, S1_Q16;
/* Length must be multiple of 4 */
SKP_assert( ( length & 3 ) == 0 );
/* Input pointer must be 4-byte aligned */
SKP_assert( ( (SKP_int64)px & 3 ) == 0 );
if( win_type == 0 ) {
f_Q16 = SKP_DIV32_16( 411775, length + 1 ); // 411775 = 2 * 65536 * pi
} else {
f_Q16 = SKP_DIV32_16( 205887, length + 1 ); // 205887 = 65536 * pi
}
/* factor used for cosine approximation */
c_Q20 = -SKP_RSHIFT( SKP_MUL( f_Q16, f_Q16 ), 12 );
/* c_Q20 becomes too large if length is too small */
SKP_assert( c_Q20 >= -32768 );
/* initialize state */
if( win_type < 2 ) {
/* start from 0 */
S0_Q16 = 0;
/* approximation of sin(f) */
S1_Q16 = f_Q16;
} else {
/* start from 1 */
S0_Q16 = ( 1 << 16 );
/* approximation of cos(f) */
S1_Q16 = ( 1 << 16 ) + SKP_RSHIFT( c_Q20, 5 );
}
/* Uses the recursive equation: sin(n*f) = 2 * cos(f) * sin((n-1)*f) - sin((n-2)*f) */
/* 4 samples at a time */
for( k = 0; k < length; k += 4 ) {
px32 = *( (SKP_int32 *)&px[ k ] ); /* load two values at once */
px_win[ k ] = (SKP_int16)SKP_SMULWB( SKP_RSHIFT( S0_Q16 + S1_Q16, 1 ), px32 );
px_win[ k + 1 ] = (SKP_int16)SKP_SMULWT( S1_Q16, px32 );
S0_Q16 = SKP_RSHIFT( SKP_MUL( c_Q20, S1_Q16 ), 20 ) + SKP_LSHIFT( S1_Q16, 1 ) - S0_Q16 + 1;
S0_Q16 = SKP_min( S0_Q16, ( 1 << 16 ) );
px32 = *( (SKP_int32 *)&px[k + 2] ); /* load two values at once */
px_win[ k + 2 ] = (SKP_int16)SKP_SMULWB( SKP_RSHIFT( S0_Q16 + S1_Q16, 1 ), px32 );
px_win[ k + 3 ] = (SKP_int16)SKP_SMULWT( S0_Q16, px32 );
S1_Q16 = SKP_RSHIFT( SKP_MUL( c_Q20, S0_Q16 ), 20 ) + SKP_LSHIFT( S0_Q16, 1 ) - S1_Q16;
S1_Q16 = SKP_min( S1_Q16, ( 1 << 16 ) );
}
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -43,6 +43,7 @@ SKP_int16 SKP_Silk_int16_array_maxabs( /* O Maximum absolute value, max: 2
)
{
SKP_int32 max = 0, i, lvl = 0, ind;
if( len == 0 ) return 0;
ind = len - 1;
max = SKP_SMULBB( vec[ ind ], vec[ ind ] );
@ -55,10 +56,13 @@ SKP_int16 SKP_Silk_int16_array_maxabs( /* O Maximum absolute value, max: 2
}
/* Do not return 32768, as it will not fit in an int16 so may lead to problems later on */
lvl = SKP_abs( vec[ ind ] );
if( lvl > SKP_int16_MAX ) {
if( max >= 1073676289 ) { // (2^15-1)^2 = 1073676289
return( SKP_int16_MAX );
} else {
return( (SKP_int16)lvl );
if( vec[ ind ] < 0 ) {
return( -vec[ ind ] );
} else {
return( vec[ ind ] );
}
}
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -39,7 +39,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/* Compute autocorrelation */
void SKP_Silk_autocorr(
SKP_int32 *results, /* O Result (length correlationCount) */
SKP_int32 *scale, /* O Scaling of the correlation vector */
SKP_int *scale, /* O Scaling of the correlation vector */
const SKP_int16 *inputData, /* I Input data to correlate */
const SKP_int inputDataSize, /* I Length of input */
const SKP_int correlationCount /* I Number of correlation taps to compute */

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -42,7 +42,7 @@ void SKP_Silk_biquad(
const SKP_int16 *in, /* I: input signal */
const SKP_int16 *B, /* I: MA coefficients, Q13 [3] */
const SKP_int16 *A, /* I: AR coefficients, Q13 [2] */
SKP_int32 *S, /* I/O: state vector [2] */
SKP_int32 *S, /* I/O: state vector [2] */
SKP_int16 *out, /* O: output signal */
const SKP_int32 len /* I: signal length */
)

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -59,15 +59,15 @@ void SKP_Silk_biquad_alt(
inval = in[ k ];
out32_Q14 = SKP_LSHIFT( SKP_SMLAWB( S[ 0 ], B_Q28[ 0 ], inval ), 2 );
S[ 0 ] = S[1] + SKP_RSHIFT( SKP_SMULWB( out32_Q14, A0_L_Q28 ), 14 );
S[ 0 ] = S[1] + SKP_RSHIFT_ROUND( SKP_SMULWB( out32_Q14, A0_L_Q28 ), 14 );
S[ 0 ] = SKP_SMLAWB( S[ 0 ], out32_Q14, A0_U_Q28 );
S[ 0 ] = SKP_SMLAWB( S[ 0 ], B_Q28[ 1 ], inval);
S[ 1 ] = SKP_RSHIFT( SKP_SMULWB( out32_Q14, A1_L_Q28 ), 14 );
S[ 1 ] = SKP_RSHIFT_ROUND( SKP_SMULWB( out32_Q14, A1_L_Q28 ), 14 );
S[ 1 ] = SKP_SMLAWB( S[ 1 ], out32_Q14, A1_U_Q28 );
S[ 1 ] = SKP_SMLAWB( S[ 1 ], B_Q28[ 2 ], inval );
/* Scale back to Q0 and saturate */
out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT( out32_Q14, 14 ) + 2 );
out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT( out32_Q14 + (1<<14) - 1, 14 ) );
}
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -40,7 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define MAX_FRAME_SIZE 544 // subfr_length * nb_subfr = ( 0.005 * 24000 + 16 ) * 4 = 544
#define MAX_NB_SUBFR 4
#define QA 24
#define QA 25
#define N_BITS_HEAD_ROOM 2
#define MIN_RSHIFTS -16
#define MAX_RSHIFTS (32 - QA)
@ -61,12 +61,12 @@ void SKP_Silk_burg_modified(
SKP_int32 C0, num, nrg, rc_Q31, Atmp_QA, Atmp1, tmp1, tmp2, x1, x2;
const SKP_int16 *x_ptr;
SKP_int32 C_first_row[ SigProc_MAX_ORDER_LPC ];
SKP_int32 C_last_row[ SigProc_MAX_ORDER_LPC ];
SKP_int32 Af_QA[ SigProc_MAX_ORDER_LPC ];
SKP_int32 C_first_row[ SKP_Silk_MAX_ORDER_LPC ];
SKP_int32 C_last_row[ SKP_Silk_MAX_ORDER_LPC ];
SKP_int32 Af_QA[ SKP_Silk_MAX_ORDER_LPC ];
SKP_int32 CAf[ SigProc_MAX_ORDER_LPC + 1 ];
SKP_int32 CAb[ SigProc_MAX_ORDER_LPC + 1 ];
SKP_int32 CAf[ SKP_Silk_MAX_ORDER_LPC + 1 ];
SKP_int32 CAb[ SKP_Silk_MAX_ORDER_LPC + 1 ];
SKP_assert( subfr_length * nb_subfr <= MAX_FRAME_SIZE );
SKP_assert( nb_subfr <= MAX_NB_SUBFR );
@ -90,7 +90,7 @@ void SKP_Silk_burg_modified(
}
rshifts += rshifts_extra;
}
SKP_memset( C_first_row, 0, SigProc_MAX_ORDER_LPC * sizeof( SKP_int32 ) );
SKP_memset( C_first_row, 0, SKP_Silk_MAX_ORDER_LPC * sizeof( SKP_int32 ) );
if( rshifts > 0 ) {
for( s = 0; s < nb_subfr; s++ ) {
x_ptr = x + s * subfr_length;
@ -108,7 +108,7 @@ void SKP_Silk_burg_modified(
}
}
}
SKP_memcpy( C_last_row, C_first_row, SigProc_MAX_ORDER_LPC * sizeof( SKP_int32 ) );
SKP_memcpy( C_last_row, C_first_row, SKP_Silk_MAX_ORDER_LPC * sizeof( SKP_int32 ) );
/* Initialize */
CAb[ 0 ] = CAf[ 0 ] = C0 + SKP_SMMUL( WhiteNoiseFrac_Q32, C0 ) + 1; // Q(-rshifts)

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -36,7 +36,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/* Encodes signs of excitation */
void SKP_Silk_encode_signs(
SKP_Silk_range_coder_state *sRC, /* I/O Range coder state */
const SKP_int q[], /* I Pulse signal */
const SKP_int8 q[], /* I Pulse signal */
const SKP_int length, /* I Length of input */
const SKP_int sigtype, /* I Signal type */
const SKP_int QuantOffsetType, /* I Quantization offset type */
@ -45,10 +45,12 @@ void SKP_Silk_encode_signs(
{
SKP_int i;
SKP_int inData;
const SKP_uint16 *cdf;
SKP_uint16 cdf[ 3 ];
i = SKP_SMULBB( N_RATE_LEVELS - 1, SKP_LSHIFT( sigtype, 1 ) + QuantOffsetType ) + RateLevelIndex;
cdf = SKP_Silk_sign_CDF[ i ];
cdf[ 0 ] = 0;
cdf[ 1 ] = SKP_Silk_sign_CDF[ i ];
cdf[ 2 ] = 65535;
for( i = 0; i < length; i++ ) {
if( q[ i ] != 0 ) {
@ -70,10 +72,12 @@ void SKP_Silk_decode_signs(
{
SKP_int i;
SKP_int data;
const SKP_uint16 *cdf;
SKP_uint16 cdf[ 3 ];
i = SKP_SMULBB( N_RATE_LEVELS - 1, SKP_LSHIFT( sigtype, 1 ) + QuantOffsetType ) + RateLevelIndex;
cdf = SKP_Silk_sign_CDF[ i ];
cdf[ 0 ] = 0;
cdf[ 1 ] = SKP_Silk_sign_CDF[ i ];
cdf[ 2 ] = 65535;
for( i = 0; i < length; i++ ) {
if( q[ i ] > 0 ) {

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -68,9 +68,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
extern const SKP_int16 SKP_Silk_CB_lags_stage2[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE2_EXT];
extern const SKP_int16 SKP_Silk_CB_lags_stage3[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_STAGE3_MAX];
extern const SKP_int16 SKP_Silk_Lag_range_stage3[ SigProc_PITCH_EST_MAX_COMPLEX + 1 ] [ PITCH_EST_NB_SUBFR ][ 2 ];
extern const SKP_int16 SKP_Silk_cbk_sizes_stage3[ SigProc_PITCH_EST_MAX_COMPLEX + 1 ];
extern const SKP_int16 SKP_Silk_cbk_offsets_stage3[ SigProc_PITCH_EST_MAX_COMPLEX + 1 ];
extern const SKP_int16 SKP_Silk_Lag_range_stage3[ SKP_Silk_PITCH_EST_MAX_COMPLEX + 1 ] [ PITCH_EST_NB_SUBFR ][ 2 ];
extern const SKP_int16 SKP_Silk_cbk_sizes_stage3[ SKP_Silk_PITCH_EST_MAX_COMPLEX + 1 ];
extern const SKP_int16 SKP_Silk_cbk_offsets_stage3[ SKP_Silk_PITCH_EST_MAX_COMPLEX + 1 ];
#endif

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -26,534 +26,191 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
#include "SKP_Silk_main_FIX.h"
#include "SKP_Silk_setup_complexity.h"
/* Control encoder SNR */
SKP_INLINE SKP_int SKP_Silk_setup_resamplers_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk encoder state FIX */
SKP_int fs_kHz /* I Internal sampling rate (kHz) */
);
SKP_INLINE SKP_int SKP_Silk_setup_packetsize_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk encoder state FIX */
SKP_int PacketSize_ms /* I Packet length (ms) */
);
SKP_INLINE SKP_int SKP_Silk_setup_fs_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk encoder state FIX */
SKP_int fs_kHz /* I Internal sampling rate (kHz) */
);
SKP_INLINE SKP_int SKP_Silk_setup_rate_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk encoder state FIX */
SKP_int TargetRate_bps /* I Target max bitrate (if SNR_dB == 0) */
);
SKP_INLINE SKP_int SKP_Silk_setup_LBRR_FIX(
SKP_Silk_encoder_state_FIX *psEnc /* I/O Pointer to Silk encoder state FIX */
);
/* Control encoder */
SKP_int SKP_Silk_control_encoder_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk encoder state */
const SKP_int API_fs_kHz, /* I External (API) sampling rate (kHz) */
const SKP_int PacketSize_ms, /* I Packet length (ms) */
SKP_int32 TargetRate_bps, /* I Target max bitrate (bps) (used if SNR_dB == 0) */
const SKP_int PacketLoss_perc, /* I Packet loss rate (in percent) */
const SKP_int INBandFec_enabled, /* I Enable (1) / disable (0) inband FEC */
const SKP_int DTX_enabled, /* I Enable / disable DTX */
const SKP_int InputFramesize_ms, /* I Inputframe in ms */
const SKP_int Complexity /* I Complexity (0->low; 1->medium; 2->high) */
SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk encoder state */
const SKP_int PacketSize_ms, /* I Packet length (ms) */
const SKP_int32 TargetRate_bps, /* I Target max bitrate (bps) */
const SKP_int PacketLoss_perc, /* I Packet loss rate (in percent) */
const SKP_int DTX_enabled, /* I Enable / disable DTX */
const SKP_int Complexity /* I Complexity (0->low; 1->medium; 2->high) */
)
{
SKP_int32 LBRRRate_thres_bps;
SKP_int k, fs_kHz, ret = 0;
SKP_int32 frac_Q6;
const SKP_int32 *rateTable;
SKP_int fs_kHz, ret = 0;
/* State machine for the SWB/WB switching */
fs_kHz = psEnc->sCmn.fs_kHz;
/* Only switch during low speech activity, when no frames are sitting in the payload buffer */
if( API_fs_kHz == 8 || fs_kHz == 0 || API_fs_kHz < fs_kHz ) {
// Switching is not possible, encoder just initialized, or internal mode higher than external
fs_kHz = API_fs_kHz;
if( psEnc->sCmn.controlled_since_last_payload != 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_FIX( psEnc, psEnc->sCmn.fs_kHz );
}
return ret;
}
/* Beyond this point we know that there are no previously coded frames in the payload buffer */
/********************************************/
/* Determine internal sampling rate */
/********************************************/
fs_kHz = SKP_Silk_control_audio_bandwidth( &psEnc->sCmn, TargetRate_bps );
/********************************************/
/* Prepare resampler and buffered data */
/********************************************/
ret += SKP_Silk_setup_resamplers_FIX( psEnc, fs_kHz );
/********************************************/
/* Set packet size */
/********************************************/
ret += SKP_Silk_setup_packetsize_FIX( psEnc, PacketSize_ms );
/********************************************/
/* Set internal sampling frequency */
/********************************************/
ret += SKP_Silk_setup_fs_FIX( psEnc, fs_kHz );
/********************************************/
/* Set encoding complexity */
/********************************************/
ret += SKP_Silk_setup_complexity( &psEnc->sCmn, Complexity );
/********************************************/
/* Set bitrate/coding quality */
/********************************************/
ret += SKP_Silk_setup_rate_FIX( psEnc, TargetRate_bps );
/********************************************/
/* Set packet loss rate measured by farend */
/********************************************/
if( ( PacketLoss_perc < 0 ) || ( PacketLoss_perc > 100 ) ) {
ret = SKP_SILK_ENC_INVALID_LOSS_RATE;
}
psEnc->sCmn.PacketLoss_perc = PacketLoss_perc;
/********************************************/
/* Set LBRR usage */
/********************************************/
ret += SKP_Silk_setup_LBRR_FIX( psEnc );
/********************************************/
/* Set DTX mode */
/********************************************/
if( DTX_enabled < 0 || DTX_enabled > 1 ) {
ret = SKP_SILK_ENC_INVALID_DTX_SETTING;
}
psEnc->sCmn.useDTX = DTX_enabled;
psEnc->sCmn.controlled_since_last_payload = 1;
return ret;
}
/* Control low bitrate redundancy usage */
void SKP_Silk_LBRR_ctrl_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I Encoder state FIX */
SKP_Silk_encoder_control *psEncCtrlC /* I/O Encoder control */
)
{
SKP_int LBRR_usage;
if( psEnc->sCmn.LBRR_enabled ) {
/* Control LBRR */
/* Usage Control based on sensitivity and packet loss caracteristics */
/* For now only enable adding to next for active frames. Make more complex later */
LBRR_usage = SKP_SILK_NO_LBRR;
if( psEnc->speech_activity_Q8 > SKP_FIX_CONST( LBRR_SPEECH_ACTIVITY_THRES, 8 ) && psEnc->sCmn.PacketLoss_perc > LBRR_LOSS_THRES ) { // nb! maybe multiply loss prob and speech activity
LBRR_usage = SKP_SILK_ADD_LBRR_TO_PLUS1;
}
psEncCtrlC->LBRR_usage = LBRR_usage;
} else {
psEncCtrlC->LBRR_usage = SKP_SILK_NO_LBRR;
}
}
/* Resample all valid data in x_buf. Resampling the last part gets rid of a click, 5ms after switching */
/* this is because the same state is used when downsampling in API.c and is then up to date */
/* the click immidiatly after switching is most of the time still there */
SKP_INLINE SKP_int SKP_Silk_setup_resamplers_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk encoder state FIX */
SKP_int fs_kHz /* I Internal sampling rate (kHz) */
)
{
SKP_int ret = SKP_SILK_NO_ERROR;
if( psEnc->sCmn.fs_kHz != fs_kHz || psEnc->sCmn.prev_API_fs_Hz != psEnc->sCmn.API_fs_Hz ) {
if( psEnc->sCmn.fs_kHz == 0 ) {
/* Initialize the resampler for enc_API.c preparing resampling from API_fs_Hz to fs_kHz */
ret += SKP_Silk_resampler_init( &psEnc->sCmn.resampler_state, psEnc->sCmn.API_fs_Hz, fs_kHz * 1000 );
} else {
/* Allocate space for worst case temporary upsampling, 8 to 48 kHz, so a factor 6 */
SKP_int16 x_buf_API_fs_Hz[ ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * ( MAX_API_FS_KHZ / 8 ) ];
SKP_int32 nSamples_temp = SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + LA_SHAPE_MS * psEnc->sCmn.fs_kHz;
if( SKP_SMULBB( fs_kHz, 1000 ) < psEnc->sCmn.API_fs_Hz && psEnc->sCmn.fs_kHz != 0 ) {
/* Resample buffered data in x_buf to API_fs_Hz */
SKP_Silk_resampler_state_struct temp_resampler_state;
/* Initialize resampler for temporary resampling of x_buf data to API_fs_Hz */
ret += SKP_Silk_resampler_init( &temp_resampler_state, SKP_SMULBB( psEnc->sCmn.fs_kHz, 1000 ), psEnc->sCmn.API_fs_Hz );
/* Temporary resampling of x_buf data to API_fs_Hz */
ret += SKP_Silk_resampler( &temp_resampler_state, x_buf_API_fs_Hz, psEnc->x_buf, nSamples_temp );
/* Calculate number of samples that has been temporarily upsampled */
nSamples_temp = SKP_DIV32_16( nSamples_temp * psEnc->sCmn.API_fs_Hz, SKP_SMULBB( psEnc->sCmn.fs_kHz, 1000 ) );
/* Initialize the resampler for enc_API.c preparing resampling from API_fs_Hz to fs_kHz */
ret += SKP_Silk_resampler_init( &psEnc->sCmn.resampler_state, psEnc->sCmn.API_fs_Hz, SKP_SMULBB( fs_kHz, 1000 ) );
if( psEnc->sCmn.fs_kHz == 24 ) {
/* Accumulate the difference between the target rate and limit */
if( psEnc->sCmn.fs_kHz_changed == 0 ) {
psEnc->sCmn.bitrateDiff += SKP_MUL( InputFramesize_ms, TargetRate_bps - SWB2WB_BITRATE_BPS_INITIAL );
} else {
psEnc->sCmn.bitrateDiff += SKP_MUL( InputFramesize_ms, TargetRate_bps - SWB2WB_BITRATE_BPS );
}
psEnc->sCmn.bitrateDiff = SKP_min( psEnc->sCmn.bitrateDiff, 0 );
/* Check if we should switch from 24 to 16 kHz */
#if SWITCH_TRANSITION_FILTERING
if( ( psEnc->sCmn.sLP.transition_frame_no == 0 ) && /* Transition phase not active */
( psEnc->sCmn.bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD || psEnc->sCmn.sSWBdetect.WB_detected == 1 ) &&
( psEnc->speech_activity_Q8 < 128 && psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) {
psEnc->sCmn.sLP.transition_frame_no = 1; /* Begin transition phase */
psEnc->sCmn.sLP.mode = 0; /* Switch down */
/* Copy data */
SKP_memcpy( x_buf_API_fs_Hz, psEnc->x_buf, nSamples_temp * sizeof( SKP_int16 ) );
}
if( ( psEnc->sCmn.sLP.transition_frame_no >= TRANSITION_FRAMES_DOWN ) && ( psEnc->sCmn.sLP.mode == 0 ) && /* Transition phase complete, ready to switch */
#else
if( ( psEnc->sCmn.bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD || psEnc->sCmn.sSWBdetect.WB_detected == 1 ) &&
#endif
( psEnc->speech_activity_Q8 < 128 && psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) {
SKP_int16 x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ];
SKP_int16 x_bufout[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ];
psEnc->sCmn.bitrateDiff = 0;
fs_kHz = 16;
SKP_memcpy( x_buf, psEnc->x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) );
SKP_memset( psEnc->sCmn.resample24To16state, 0, sizeof( psEnc->sCmn.resample24To16state ) );
#if LOW_COMPLEXITY_ONLY
{
SKP_int16 scratch[ ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) + SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ];
SKP_Silk_resample_2_3_coarse( &x_bufout[ 0 ], psEnc->sCmn.resample24To16state, &x_buf[ 0 ], SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape, (SKP_int16*)scratch );
}
#else
SKP_Silk_resample_2_3( &x_bufout[ 0 ], psEnc->sCmn.resample24To16state, &x_buf[ 0 ], SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape );
#endif
/* set the first frame to zero, no performance difference was noticed though */
SKP_memset( x_bufout, 0, 320 * sizeof( SKP_int16 ) );
SKP_memcpy( psEnc->x_buf, x_bufout, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) );
#if SWITCH_TRANSITION_FILTERING
psEnc->sCmn.sLP.transition_frame_no = 0; /* Transition phase complete */
#endif
}
} else if( psEnc->sCmn.fs_kHz == 16 ) {
/* Check if we should switch from 16 to 24 kHz */
#if SWITCH_TRANSITION_FILTERING
if( ( psEnc->sCmn.sLP.transition_frame_no == 0 ) && /* No transition phase running, ready to switch */
#else
if(
#endif
( API_fs_kHz > psEnc->sCmn.fs_kHz && TargetRate_bps >= WB2SWB_BITRATE_BPS && psEnc->sCmn.sSWBdetect.WB_detected == 0 ) &&
( psEnc->speech_activity_Q8 < 128 && psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) {
SKP_int16 x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ];
SKP_int16 x_bufout[ 3 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) / 2 ];
SKP_int32 resample16To24state[ 11 ];
psEnc->sCmn.bitrateDiff = 0;
fs_kHz = 24;
SKP_memcpy( x_buf, psEnc->x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) );
SKP_memset( resample16To24state, 0, sizeof(resample16To24state) );
SKP_Silk_resample_3_2( &x_bufout[ 0 ], resample16To24state, &x_buf[ 0 ], SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape );
/* set the first frame to zero, no performance difference was noticed though */
SKP_memset( x_bufout, 0, 480 * sizeof( SKP_int16 ) );
SKP_memcpy( psEnc->x_buf, x_bufout, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) );
#if SWITCH_TRANSITION_FILTERING
psEnc->sCmn.sLP.mode = 1; /* Switch up */
#endif
} else {
/* accumulate the difference between the target rate and limit */
psEnc->sCmn.bitrateDiff += SKP_MUL( InputFramesize_ms, TargetRate_bps - WB2MB_BITRATE_BPS );
psEnc->sCmn.bitrateDiff = SKP_min( psEnc->sCmn.bitrateDiff, 0 );
/* Check if we should switch from 16 to 12 kHz */
#if SWITCH_TRANSITION_FILTERING
if( ( psEnc->sCmn.sLP.transition_frame_no == 0 ) && /* Transition phase not active */
( psEnc->sCmn.bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD ) &&
( psEnc->speech_activity_Q8 < 128 && psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) {
psEnc->sCmn.sLP.transition_frame_no = 1; /* Begin transition phase */
psEnc->sCmn.sLP.mode = 0; /* Switch down */
}
if( ( psEnc->sCmn.sLP.transition_frame_no >= TRANSITION_FRAMES_DOWN ) && ( psEnc->sCmn.sLP.mode == 0 ) && /* Transition phase complete, ready to switch */
#else
if( ( psEnc->sCmn.bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD ) &&
#endif
( psEnc->speech_activity_Q8 < 128 && psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) {
SKP_int16 x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ];
SKP_memcpy( x_buf, psEnc->x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) );
psEnc->sCmn.bitrateDiff = 0;
fs_kHz = 12;
if( API_fs_kHz == 24 ) {
/* Intermediate upsampling of x_bufFIX from 16 to 24 kHz */
SKP_int16 x_buf24[ 3 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) / 2 ];
SKP_int32 scratch[ 3 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) ];
SKP_int32 resample16To24state[ 11 ];
SKP_memset( resample16To24state, 0, sizeof( resample16To24state ) );
SKP_Silk_resample_3_2( &x_buf24[ 0 ], resample16To24state, &x_buf[ 0 ], SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape );
/* Update the state of the resampler used in API.c, from 24 to 12 kHz */
SKP_memset( psEnc->sCmn.resample24To12state, 0, sizeof( psEnc->sCmn.resample24To12state ) );
SKP_Silk_resample_1_2_coarse( &x_buf24[ 0 ], psEnc->sCmn.resample24To12state, &x_buf[ 0 ], scratch, SKP_RSHIFT( SKP_SMULBB( 3, SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape ), 2 ) );
/* set the first frame to zero, no performance difference was noticed though */
SKP_memset( x_buf, 0, 240 * sizeof( SKP_int16 ) );
SKP_memcpy( psEnc->x_buf, x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) );
} else if( API_fs_kHz == 16 ) {
SKP_int16 x_bufout[ 3 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) / 4 ];
SKP_memset( psEnc->sCmn.resample16To12state, 0, sizeof( psEnc->sCmn.resample16To12state ) );
SKP_Silk_resample_3_4( &x_bufout[ 0 ], psEnc->sCmn.resample16To12state, &x_buf[ 0 ], SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape );
/* set the first frame to zero, no performance difference was noticed though */
SKP_memset( x_bufout, 0, 240 * sizeof( SKP_int16 ) );
SKP_memcpy( psEnc->x_buf, x_bufout, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) );
}
#if SWITCH_TRANSITION_FILTERING
psEnc->sCmn.sLP.transition_frame_no = 0; /* Transition phase complete */
#endif
}
}
} else if( psEnc->sCmn.fs_kHz == 12 ) {
/* Check if we should switch from 12 to 16 kHz */
#if SWITCH_TRANSITION_FILTERING
if( ( psEnc->sCmn.sLP.transition_frame_no == 0 ) && /* No transition phase running, ready to switch */
#else
if(
#endif
( API_fs_kHz > psEnc->sCmn.fs_kHz && TargetRate_bps >= MB2WB_BITRATE_BPS ) &&
( psEnc->speech_activity_Q8 < 128 && psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) {
SKP_int16 x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ];
SKP_memcpy( x_buf, psEnc->x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) );
psEnc->sCmn.bitrateDiff = 0;
fs_kHz = 16;
/* Reset state of the resampler to be used */
if( API_fs_kHz == 24 ) {
SKP_int16 x_bufout[ 2 * 2 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) / 3 ];
/* Intermediate upsampling of x_bufFIX from 12 to 24 kHz */
SKP_int16 x_buf24[ 2 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) ];
SKP_int32 scratch[ 3 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) ];
SKP_int32 resample12To24state[6];
SKP_memset( resample12To24state, 0, sizeof( resample12To24state ) );
SKP_Silk_resample_2_1_coarse( &x_buf[ 0 ], resample12To24state, &x_buf24[ 0 ], scratch, SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape );
SKP_memset( psEnc->sCmn.resample24To16state, 0, sizeof( psEnc->sCmn.resample24To16state ) );
#if LOW_COMPLEXITY_ONLY
SKP_assert( sizeof( SKP_int16 ) * ( 2 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) + SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ) <= sizeof( scratch ) );
SKP_Silk_resample_2_3_coarse( &x_bufout[ 0 ], psEnc->sCmn.resample24To16state, &x_buf24[ 0 ], SKP_LSHIFT( SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape, 1 ), (SKP_int16*)scratch );
#else
SKP_Silk_resample_2_3( &x_bufout[ 0 ], psEnc->sCmn.resample24To16state, &x_buf24[ 0 ], SKP_LSHIFT( SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape, 1 ) );
#endif
/* set the first frame to zero, no performance difference was noticed though */
SKP_memset( x_bufout, 0, 320 * sizeof( SKP_int16 ) );
SKP_memcpy( psEnc->x_buf, x_bufout, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) );
}
#if SWITCH_TRANSITION_FILTERING
psEnc->sCmn.sLP.mode = 1; /* Switch up */
#endif
} else {
/* accumulate the difference between the target rate and limit */
psEnc->sCmn.bitrateDiff += SKP_MUL( InputFramesize_ms, TargetRate_bps - MB2NB_BITRATE_BPS );
psEnc->sCmn.bitrateDiff = SKP_min( psEnc->sCmn.bitrateDiff, 0 );
/* Check if we should switch from 12 to 8 kHz */
#if SWITCH_TRANSITION_FILTERING
if( ( psEnc->sCmn.sLP.transition_frame_no == 0 ) && /* Transition phase not active */
( psEnc->sCmn.bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD ) &&
( psEnc->speech_activity_Q8 < 128 && psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) {
psEnc->sCmn.sLP.transition_frame_no = 1; /* Begin transition phase */
psEnc->sCmn.sLP.mode = 0; /* Switch down */
}
if( ( psEnc->sCmn.sLP.transition_frame_no >= TRANSITION_FRAMES_DOWN ) && ( psEnc->sCmn.sLP.mode == 0 ) &&
#else
if( ( psEnc->sCmn.bitrateDiff <= -ACCUM_BITS_DIFF_THRESHOLD ) &&
#endif
( psEnc->speech_activity_Q8 < 128 && psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) {
SKP_int16 x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ];
SKP_memcpy( x_buf, psEnc->x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) );
psEnc->sCmn.bitrateDiff = 0;
fs_kHz = 8;
if( API_fs_kHz == 24 ) {
SKP_int32 scratch[ 3 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) ];
/* Intermediate upsampling of x_buf from 12 to 24 kHz */
SKP_int16 x_buf24[ 2 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) ];
SKP_int32 resample12To24state[ 6 ];
SKP_memset( resample12To24state, 0, sizeof( resample12To24state ) );
SKP_Silk_resample_2_1_coarse( &x_buf[ 0 ], resample12To24state, &x_buf24[ 0 ], scratch, SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape );
/* Update the state of the resampler used in API.c, from 24 to 8 kHz */
SKP_memset( psEnc->sCmn.resample24To8state, 0, sizeof( psEnc->sCmn.resample24To8state ) );
SKP_Silk_resample_1_3( &x_buf[ 0 ], psEnc->sCmn.resample24To8state, &x_buf24[ 0 ], SKP_LSHIFT( SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape, 1 ) );
/* set the first frame to zero, no performance difference was noticed though */
SKP_memset( x_buf, 0, 160 * sizeof( SKP_int16 ) );
SKP_memcpy( psEnc->x_buf, x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) );
} else if( API_fs_kHz == 16 ) {
/* Intermediate upsampling of x_bufFIX from 12 to 16 kHz */
SKP_int16 x_buf16[ 3 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) / 2 ];
SKP_int32 resample12To16state[11];
SKP_memset( resample12To16state, 0, sizeof( resample12To16state ) );
SKP_Silk_resample_3_2( &x_buf16[ 0 ], resample12To16state, &x_buf[ 0 ], SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape );
/* set the first frame to zero, no performance difference was noticed though */
SKP_memset( x_buf, 0, 160 * sizeof( SKP_int16 ) );
SKP_memcpy( psEnc->x_buf, x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) );
} else if( API_fs_kHz == 12 ) {
SKP_int16 x_bufout[ 2 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) / 3 ];
SKP_memset( psEnc->sCmn.resample12To8state, 0, sizeof( psEnc->sCmn.resample12To8state ) );
#if LOW_COMPLEXITY_ONLY
{
SKP_int16 scratch[ ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) + SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ];
SKP_Silk_resample_2_3_coarse( &x_bufout[ 0 ], psEnc->sCmn.resample12To8state, &x_buf[ 0 ],
SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape, scratch );
}
#else
SKP_Silk_resample_2_3( &x_bufout[ 0 ], psEnc->sCmn.resample12To8state, &x_buf[ 0 ], SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape );
#endif
/* set the first frame to zero, no performance difference was noticed though */
SKP_memset( x_bufout, 0, 160 * sizeof( SKP_int16 ) );
SKP_memcpy( psEnc->x_buf, x_bufout, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) );
}
#if SWITCH_TRANSITION_FILTERING
psEnc->sCmn.sLP.transition_frame_no = 0; /* Transition phase complete */
#endif
}
}
} else if( psEnc->sCmn.fs_kHz == 8 ) {
/* Check if we should switch from 8 to 12 kHz */
#if SWITCH_TRANSITION_FILTERING
if( ( psEnc->sCmn.sLP.transition_frame_no == 0 ) && /* No transition phase running, ready to switch */
#else
if(
#endif
( API_fs_kHz > psEnc->sCmn.fs_kHz && TargetRate_bps >= NB2MB_BITRATE_BPS ) &&
( psEnc->speech_activity_Q8 < 128 && psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) {
SKP_int16 x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ];
SKP_memcpy( x_buf, psEnc->x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) );
psEnc->sCmn.bitrateDiff = 0;
fs_kHz = 12;
/* Reset state of the resampler to be used */
if( API_fs_kHz == 24 ) {
SKP_int16 x_buf24[ 3 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) ];
SKP_int32 scratch[ 3 * 3 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) / 2 ];
SKP_int32 resample8To24state[ 7 ];
/* Intermediate upsampling of x_bufFIX from 8 to 24 kHz */
SKP_memset( resample8To24state, 0, sizeof( resample8To24state ) );
SKP_Silk_resample_3_1( &x_buf24[ 0 ], resample8To24state, &x_buf[ 0 ], SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape );
SKP_memset( psEnc->sCmn.resample24To12state, 0, sizeof( psEnc->sCmn.resample24To12state ) );
SKP_Silk_resample_1_2_coarse( &x_buf24[ 0 ], psEnc->sCmn.resample24To12state, &x_buf[ 0 ], scratch, SKP_RSHIFT( SKP_SMULBB( 3, SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape ), 1 ) );
/* set the first frame to zero, no performance difference was noticed though */
SKP_memset( x_buf, 0, 240 * sizeof( SKP_int16 ) );
SKP_memcpy( psEnc->x_buf, x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) );
} else if( API_fs_kHz == 16 ) {
SKP_int16 x_buf16[ 2 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) ];
SKP_int32 scratch[ 3 * ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) ];
SKP_int32 resample8To16state[ 6 ];
/* Intermediate upsampling of x_bufFIX from 8 to 16 kHz */
SKP_memset( resample8To16state, 0, sizeof( resample8To16state ) );
SKP_Silk_resample_2_1_coarse( &x_buf[ 0 ], resample8To16state, &x_buf16[ 0 ], scratch, SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape );
SKP_memset( psEnc->sCmn.resample16To12state, 0, sizeof( psEnc->sCmn.resample16To12state ) );
SKP_Silk_resample_3_4( &x_buf[ 0 ], psEnc->sCmn.resample16To12state, &x_buf16[ 0 ], SKP_LSHIFT( SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + psEnc->sCmn.la_shape, 1 ) );
/* set the first frame to zero, no performance difference was noticed though */
SKP_memset( x_buf, 0, 240 * sizeof( SKP_int16 ) );
SKP_memcpy( psEnc->x_buf, x_buf, ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * sizeof( SKP_int16 ) );
}
#if SWITCH_TRANSITION_FILTERING
psEnc->sCmn.sLP.mode = 1; /* Switch up */
#endif
}
} else {
// Internal sample frequency not supported!
SKP_assert( 0 );
}
}
#if SWITCH_TRANSITION_FILTERING
/* After switching up, stop transition filter during speech inactivity */
if( ( psEnc->sCmn.sLP.mode == 1 ) &&
( psEnc->sCmn.sLP.transition_frame_no >= TRANSITION_FRAMES_UP ) &&
( psEnc->speech_activity_Q8 < 128 ) &&
( psEnc->sCmn.nFramesInPayloadBuf == 0 ) ) {
psEnc->sCmn.sLP.transition_frame_no = 0;
/* Reset transition filter state */
SKP_memset( psEnc->sCmn.sLP.In_LP_State, 0, 2 * sizeof( SKP_int32 ) );
}
#endif
/* Set internal sampling frequency */
if( psEnc->sCmn.fs_kHz != fs_kHz ) {
/* reset part of the state */
SKP_memset( &psEnc->sShape, 0, sizeof( SKP_Silk_shape_state_FIX ) );
SKP_memset( &psEnc->sPrefilt, 0, sizeof( SKP_Silk_prefilter_state_FIX ) );
SKP_memset( &psEnc->sNSQ, 0, sizeof( SKP_Silk_nsq_state ) );
SKP_memset( &psEnc->sPred, 0, sizeof( SKP_Silk_predict_state_FIX ) );
SKP_memset( psEnc->sNSQ.xq, 0, ( 2 * MAX_FRAME_LENGTH ) * sizeof( SKP_int16 ) );
SKP_memset( psEnc->sNSQ_LBRR.xq, 0, ( 2 * MAX_FRAME_LENGTH ) * sizeof( SKP_int16 ) );
SKP_memset( psEnc->sCmn.LBRR_buffer, 0, MAX_LBRR_DELAY * sizeof( SKP_SILK_LBRR_struct ) );
#if SWITCH_TRANSITION_FILTERING
SKP_memset( psEnc->sCmn.sLP.In_LP_State, 0, 2 * sizeof( SKP_int32 ) );
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.nFramesInPayloadBuf = 0;
psEnc->sCmn.nBytesInPayloadBuf = 0;
psEnc->sCmn.oldest_LBRR_idx = 0;
psEnc->sCmn.TargetRate_bps = 0; /* ensures that psEnc->SNR_dB is recomputed */
SKP_memset( psEnc->sPred.prev_NLSFq_Q15, 0, MAX_LPC_ORDER * sizeof( SKP_int ) );
/* Initialize non-zero parameters */
psEnc->sCmn.prevLag = 100;
psEnc->sCmn.prev_sigtype = SIG_TYPE_UNVOICED;
psEnc->sCmn.first_frame_after_reset = 1;
psEnc->sPrefilt.lagPrev = 100;
psEnc->sShape.LastGainIndex = 1;
psEnc->sNSQ.lagPrev = 100;
psEnc->sNSQ.prev_inv_gain_Q16 = 65536;
psEnc->sNSQ_LBRR.prev_inv_gain_Q16 = 65536;
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;
} 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;
}
psEnc->sCmn.frame_length = SKP_SMULBB( FRAME_LENGTH_MS, fs_kHz );
psEnc->sCmn.subfr_length = SKP_DIV32_16( psEnc->sCmn.frame_length, NB_SUBFR );
psEnc->sCmn.la_pitch = SKP_SMULBB( LA_PITCH_MS, fs_kHz );
psEnc->sCmn.la_shape = SKP_SMULBB( LA_SHAPE_MS, fs_kHz );
psEnc->sPred.min_pitch_lag = SKP_SMULBB( 3, fs_kHz );
psEnc->sPred.max_pitch_lag = SKP_SMULBB( 18, fs_kHz );
psEnc->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz );
if( psEnc->sCmn.fs_kHz == 24 ) {
psEnc->mu_LTP_Q8 = MU_LTP_QUANT_SWB_Q8;
} else if( psEnc->sCmn.fs_kHz == 16 ) {
psEnc->mu_LTP_Q8 = MU_LTP_QUANT_WB_Q8;
} else if( psEnc->sCmn.fs_kHz == 12 ) {
psEnc->mu_LTP_Q8 = MU_LTP_QUANT_MB_Q8;
} else {
psEnc->mu_LTP_Q8 = MU_LTP_QUANT_NB_Q8;
}
psEnc->sCmn.fs_kHz_changed = 1;
/* Check that settings are valid */
SKP_assert( ( psEnc->sCmn.subfr_length * NB_SUBFR ) == psEnc->sCmn.frame_length );
}
/* Set encoding complexity */
if( Complexity == 0 || LOW_COMPLEXITY_ONLY ) {
/* Low complexity */
psEnc->sCmn.Complexity = 0;
psEnc->sCmn.pitchEstimationComplexity = PITCH_EST_COMPLEXITY_LC_MODE;
psEnc->pitchEstimationThreshold_Q16 = FIND_PITCH_CORRELATION_THRESHOLD_Q16_LC_MODE;
psEnc->sCmn.pitchEstimationLPCOrder = 8;
psEnc->sCmn.shapingLPCOrder = 12;
psEnc->sCmn.nStatesDelayedDecision = 1;
psEnc->NoiseShapingQuantizer = SKP_Silk_NSQ;
psEnc->sCmn.useInterpolatedNLSFs = 0;
psEnc->sCmn.LTPQuantLowComplexity = 1;
psEnc->sCmn.NLSF_MSVQ_Survivors = MAX_NLSF_MSVQ_SURVIVORS_LC_MODE;
} else if( Complexity == 1 ) {
/* Medium complexity */
psEnc->sCmn.Complexity = 1;
psEnc->sCmn.pitchEstimationComplexity = PITCH_EST_COMPLEXITY_MC_MODE;
psEnc->pitchEstimationThreshold_Q16 = FIND_PITCH_CORRELATION_THRESHOLD_Q16_MC_MODE;
psEnc->sCmn.pitchEstimationLPCOrder = 12;
psEnc->sCmn.shapingLPCOrder = 16;
psEnc->sCmn.nStatesDelayedDecision = 2;
psEnc->NoiseShapingQuantizer = SKP_Silk_NSQ_del_dec;
psEnc->sCmn.useInterpolatedNLSFs = 0;
psEnc->sCmn.LTPQuantLowComplexity = 0;
psEnc->sCmn.NLSF_MSVQ_Survivors = MAX_NLSF_MSVQ_SURVIVORS_MC_MODE;
} else if( Complexity == 2 ) {
/* High complexity */
psEnc->sCmn.Complexity = 2;
psEnc->sCmn.pitchEstimationComplexity = PITCH_EST_COMPLEXITY_HC_MODE;
psEnc->pitchEstimationThreshold_Q16 = FIND_PITCH_CORRELATION_THRESHOLD_Q16_HC_MODE;
psEnc->sCmn.pitchEstimationLPCOrder = 16;
psEnc->sCmn.shapingLPCOrder = 16;
psEnc->sCmn.nStatesDelayedDecision = 4;
psEnc->NoiseShapingQuantizer = SKP_Silk_NSQ_del_dec;
psEnc->sCmn.useInterpolatedNLSFs = 1;
psEnc->sCmn.LTPQuantLowComplexity = 0;
psEnc->sCmn.NLSF_MSVQ_Survivors = MAX_NLSF_MSVQ_SURVIVORS;
} else {
ret = SKP_SILK_ENC_WRONG_COMPLEXITY_SETTING;
}
/* Dont have higher Pitch estimation LPC order than predict LPC order */
psEnc->sCmn.pitchEstimationLPCOrder = SKP_min_int( psEnc->sCmn.pitchEstimationLPCOrder, psEnc->sCmn.predictLPCOrder );
SKP_assert( psEnc->sCmn.pitchEstimationLPCOrder <= FIND_PITCH_LPC_ORDER_MAX );
SKP_assert( psEnc->sCmn.shapingLPCOrder <= SHAPE_LPC_ORDER_MAX );
SKP_assert( psEnc->sCmn.nStatesDelayedDecision <= DEL_DEC_STATES_MAX );
/* Set bitrate/coding quality */
TargetRate_bps = SKP_min( TargetRate_bps, 100000 );
if( psEnc->sCmn.fs_kHz == 8 ) {
TargetRate_bps = SKP_max( TargetRate_bps, MIN_TARGET_RATE_NB_BPS );
} else if( psEnc->sCmn.fs_kHz == 12 ) {
TargetRate_bps = SKP_max( TargetRate_bps, MIN_TARGET_RATE_MB_BPS );
} else if( psEnc->sCmn.fs_kHz == 16 ) {
TargetRate_bps = SKP_max( TargetRate_bps, MIN_TARGET_RATE_WB_BPS );
} else {
TargetRate_bps = SKP_max( TargetRate_bps, MIN_TARGET_RATE_SWB_BPS );
}
if( TargetRate_bps != psEnc->sCmn.TargetRate_bps ) {
psEnc->sCmn.TargetRate_bps = TargetRate_bps;
/* if new TargetRate_bps, translate to SNR_dB value */
if( psEnc->sCmn.fs_kHz == 8 ) {
rateTable = TargetRate_table_NB;
} else if( psEnc->sCmn.fs_kHz == 12 ) {
rateTable = TargetRate_table_MB;
} else if( psEnc->sCmn.fs_kHz == 16 ) {
rateTable = TargetRate_table_WB;
} else {
rateTable = TargetRate_table_SWB;
}
for( k = 1; k < TARGET_RATE_TAB_SZ; k++ ) {
/* find bitrate interval in table and interpolate */
if( TargetRate_bps < rateTable[ k ] ) {
frac_Q6 = SKP_DIV32( SKP_LSHIFT( TargetRate_bps - rateTable[ k - 1 ], 6 ), rateTable[ k ] - rateTable[ k - 1 ] );
psEnc->SNR_dB_Q7 = SKP_LSHIFT( SNR_table_Q1[ k - 1 ], 6 ) + SKP_MUL( frac_Q6, SNR_table_Q1[ k ] - SNR_table_Q1[ k - 1 ] );
break;
if( 1000 * fs_kHz != psEnc->sCmn.API_fs_Hz ) {
/* Correct resampler state (unless resampling by a factor 1) by resampling buffered data from API_fs_Hz to fs_kHz */
ret += SKP_Silk_resampler( &psEnc->sCmn.resampler_state, psEnc->x_buf, x_buf_API_fs_Hz, nSamples_temp );
}
}
}
psEnc->sCmn.prev_API_fs_Hz = psEnc->sCmn.API_fs_Hz;
return(ret);
}
SKP_INLINE SKP_int SKP_Silk_setup_packetsize_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk encoder state FIX */
SKP_int PacketSize_ms /* I Packet length (ms) */
)
{
SKP_int ret = SKP_SILK_NO_ERROR;
/* Set packet size */
if( ( PacketSize_ms != 20 ) &&
( PacketSize_ms != 40 ) &&
@ -569,88 +226,178 @@ SKP_int SKP_Silk_control_encoder_FIX(
SKP_Silk_LBRR_reset( &psEnc->sCmn );
}
}
/* Set packet loss rate measured by farend */
if( ( PacketLoss_perc < 0 ) || ( PacketLoss_perc > 100 ) ) {
ret = SKP_SILK_ENC_WRONG_LOSS_RATE;
}
psEnc->sCmn.PacketLoss_perc = PacketLoss_perc;
#if USE_LBRR
if( INBandFec_enabled < 0 || INBandFec_enabled > 1 ) {
ret = SKP_SILK_ENC_WRONG_INBAND_FEC_SETTING;
}
/* Only change settings if first frame in packet */
if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) {
psEnc->sCmn.LBRR_enabled = INBandFec_enabled;
if( psEnc->sCmn.fs_kHz == 8 ) {
LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS - 9000;
} else if( psEnc->sCmn.fs_kHz == 12 ) {
LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS - 6000;;
} else if( psEnc->sCmn.fs_kHz == 16 ) {
LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS - 3000;
} else {
LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS;
}
if( psEnc->sCmn.TargetRate_bps >= LBRRRate_thres_bps ) {
/* Set gain increase / rate reduction for LBRR usage */
/* Coarse tuned with pesq for now. */
/* Linear regression coefs G = 8 - 0.5 * loss */
/* Meaning that at 16% loss main rate and redundant rate is the same, -> G = 0 */
psEnc->sCmn.LBRR_GainIncreases = SKP_max_int( 8 - SKP_RSHIFT( psEnc->sCmn.PacketLoss_perc, 1 ), 0 );
/* Set main stream rate compensation */
if( psEnc->sCmn.LBRR_enabled && psEnc->sCmn.PacketLoss_perc > LBRR_LOSS_THRES ) {
/* Tuned to give aprox same mean / weighted bitrate as no inband FEC */
psEnc->inBandFEC_SNR_comp_Q8 = ( 6 << 8 ) - SKP_LSHIFT( psEnc->sCmn.LBRR_GainIncreases, 7 );
} else {
psEnc->inBandFEC_SNR_comp_Q8 = 0;
psEnc->sCmn.LBRR_enabled = 0;
}
} else {
psEnc->inBandFEC_SNR_comp_Q8 = 0;
psEnc->sCmn.LBRR_enabled = 0;
}
}
#else
psEnc->sCmn.LBRR_enabled = 0;
#endif
/* Set DTX mode */
if( DTX_enabled < 0 || DTX_enabled > 1 ) {
ret = SKP_SILK_ENC_WRONG_DTX_SETTING;
}
psEnc->sCmn.useDTX = DTX_enabled;
return ret;
return(ret);
}
/* Control low bitrate redundancy usage */
void SKP_Silk_LBRR_ctrl_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O encoder state */
SKP_Silk_encoder_control_FIX *psEncCtrl /* I/O encoder control */
SKP_INLINE SKP_int SKP_Silk_setup_fs_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk encoder state FIX */
SKP_int fs_kHz /* I Internal sampling rate (kHz) */
)
{
SKP_int LBRR_usage;
SKP_int ret = SKP_SILK_NO_ERROR;
if( psEnc->sCmn.LBRR_enabled ) {
/* Control LBRR */
/* Usage Control based on sensitivity and packet loss caracteristics */
/* For now only enable adding to next for active frames. Make more complex later */
LBRR_usage = SKP_SILK_NO_LBRR;
if( psEnc->speech_activity_Q8 > LBRR_SPEECH_ACTIVITY_THRES_Q8 && psEnc->sCmn.PacketLoss_perc > LBRR_LOSS_THRES ) { // nb! maybe multiply loss prob and speech activity
//if( psEnc->PacketLoss_burst > BURST_THRES )
// psEncCtrl->LBRR_usage = SKP_SILK_ADD_LBRR_TO_PLUS2;
//} else {
LBRR_usage = SKP_SILK_ADD_LBRR_TO_PLUS1;//SKP_SILK_NO_LBRR
//}
/* Set internal sampling frequency */
if( psEnc->sCmn.fs_kHz != fs_kHz ) {
/* reset part of the state */
SKP_memset( &psEnc->sShape, 0, sizeof( SKP_Silk_shape_state_FIX ) );
SKP_memset( &psEnc->sPrefilt, 0, sizeof( SKP_Silk_prefilter_state_FIX ) );
SKP_memset( &psEnc->sNSQ, 0, sizeof( SKP_Silk_nsq_state ) );
SKP_memset( &psEnc->sPred, 0, sizeof( SKP_Silk_predict_state_FIX ) );
SKP_memset( psEnc->sNSQ.xq, 0, ( 2 * MAX_FRAME_LENGTH ) * sizeof( SKP_int16 ) );
SKP_memset( psEnc->sNSQ_LBRR.xq, 0, ( 2 * MAX_FRAME_LENGTH ) * sizeof( SKP_int16 ) );
SKP_memset( psEnc->sCmn.LBRR_buffer, 0, MAX_LBRR_DELAY * sizeof( SKP_SILK_LBRR_struct ) );
#if SWITCH_TRANSITION_FILTERING
SKP_memset( psEnc->sCmn.sLP.In_LP_State, 0, 2 * sizeof( SKP_int32 ) );
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;
}
psEncCtrl->sCmn.LBRR_usage = LBRR_usage;
} else {
psEncCtrl->sCmn.LBRR_usage = SKP_SILK_NO_LBRR;
#endif
psEnc->sCmn.inputBufIx = 0;
psEnc->sCmn.nFramesInPayloadBuf = 0;
psEnc->sCmn.nBytesInPayloadBuf = 0;
psEnc->sCmn.oldest_LBRR_idx = 0;
psEnc->sCmn.TargetRate_bps = 0; /* Ensures that psEnc->SNR_dB is recomputed */
SKP_memset( psEnc->sPred.prev_NLSFq_Q15, 0, MAX_LPC_ORDER * sizeof( SKP_int ) );
/* Initialize non-zero parameters */
psEnc->sCmn.prevLag = 100;
psEnc->sCmn.prev_sigtype = SIG_TYPE_UNVOICED;
psEnc->sCmn.first_frame_after_reset = 1;
psEnc->sPrefilt.lagPrev = 100;
psEnc->sShape.LastGainIndex = 1;
psEnc->sNSQ.lagPrev = 100;
psEnc->sNSQ.prev_inv_gain_Q16 = 65536;
psEnc->sNSQ_LBRR.prev_inv_gain_Q16 = 65536;
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;
} 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;
}
psEnc->sCmn.frame_length = SKP_SMULBB( FRAME_LENGTH_MS, fs_kHz );
psEnc->sCmn.subfr_length = SKP_DIV32_16( psEnc->sCmn.frame_length, NB_SUBFR );
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->sPred.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz );
if( psEnc->sCmn.fs_kHz == 24 ) {
psEnc->mu_LTP_Q8 = SKP_FIX_CONST( MU_LTP_QUANT_SWB, 8 );
psEnc->sCmn.bitrate_threshold_up = SKP_int32_MAX;
psEnc->sCmn.bitrate_threshold_down = SWB2WB_BITRATE_BPS;
} else if( psEnc->sCmn.fs_kHz == 16 ) {
psEnc->mu_LTP_Q8 = SKP_FIX_CONST( MU_LTP_QUANT_WB, 8 );
psEnc->sCmn.bitrate_threshold_up = WB2SWB_BITRATE_BPS;
psEnc->sCmn.bitrate_threshold_down = WB2MB_BITRATE_BPS;
} else if( psEnc->sCmn.fs_kHz == 12 ) {
psEnc->mu_LTP_Q8 = SKP_FIX_CONST( MU_LTP_QUANT_MB, 8 );
psEnc->sCmn.bitrate_threshold_up = MB2WB_BITRATE_BPS;
psEnc->sCmn.bitrate_threshold_down = MB2NB_BITRATE_BPS;
} else {
psEnc->mu_LTP_Q8 = SKP_FIX_CONST( MU_LTP_QUANT_NB, 8 );
psEnc->sCmn.bitrate_threshold_up = NB2MB_BITRATE_BPS;
psEnc->sCmn.bitrate_threshold_down = 0;
}
psEnc->sCmn.fs_kHz_changed = 1;
/* Check that settings are valid */
SKP_assert( ( psEnc->sCmn.subfr_length * NB_SUBFR ) == psEnc->sCmn.frame_length );
}
return( ret );
}
SKP_INLINE SKP_int SKP_Silk_setup_rate_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk encoder state FIX */
SKP_int TargetRate_bps /* I Target max bitrate (if SNR_dB == 0) */
)
{
SKP_int k, ret = SKP_SILK_NO_ERROR;
SKP_int32 frac_Q6;
const SKP_int32 *rateTable;
/* Set bitrate/coding quality */
if( TargetRate_bps != psEnc->sCmn.TargetRate_bps ) {
psEnc->sCmn.TargetRate_bps = TargetRate_bps;
/* If new TargetRate_bps, translate to SNR_dB value */
if( psEnc->sCmn.fs_kHz == 8 ) {
rateTable = TargetRate_table_NB;
} else if( psEnc->sCmn.fs_kHz == 12 ) {
rateTable = TargetRate_table_MB;
} else if( psEnc->sCmn.fs_kHz == 16 ) {
rateTable = TargetRate_table_WB;
} else {
rateTable = TargetRate_table_SWB;
}
for( k = 1; k < TARGET_RATE_TAB_SZ; k++ ) {
/* Find bitrate interval in table and interpolate */
if( TargetRate_bps < rateTable[ k ] ) {
frac_Q6 = SKP_DIV32( SKP_LSHIFT( TargetRate_bps - rateTable[ k - 1 ], 6 ),
rateTable[ k ] - rateTable[ k - 1 ] );
psEnc->SNR_dB_Q7 = SKP_LSHIFT( SNR_table_Q1[ k - 1 ], 6 ) + SKP_MUL( frac_Q6, SNR_table_Q1[ k ] - SNR_table_Q1[ k - 1 ] );
break;
}
}
}
return( ret );
}
SKP_INLINE SKP_int SKP_Silk_setup_LBRR_FIX(
SKP_Silk_encoder_state_FIX *psEnc /* I/O Pointer to Silk encoder state FIX */
)
{
SKP_int ret = SKP_SILK_NO_ERROR;
#if USE_LBRR
SKP_int32 LBRRRate_thres_bps;
if( psEnc->sCmn.useInBandFEC < 0 || psEnc->sCmn.useInBandFEC > 1 ) {
ret = SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING;
}
psEnc->sCmn.LBRR_enabled = psEnc->sCmn.useInBandFEC;
if( psEnc->sCmn.fs_kHz == 8 ) {
LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS - 9000;
} else if( psEnc->sCmn.fs_kHz == 12 ) {
LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS - 6000;;
} else if( psEnc->sCmn.fs_kHz == 16 ) {
LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS - 3000;
} else {
LBRRRate_thres_bps = INBAND_FEC_MIN_RATE_BPS;
}
if( psEnc->sCmn.TargetRate_bps >= LBRRRate_thres_bps ) {
/* Set gain increase / rate reduction for LBRR usage */
/* Coarsely tuned with PESQ for now. */
/* Linear regression coefs G = 8 - 0.5 * loss */
/* Meaning that at 16% loss main rate and redundant rate is the same, -> G = 0 */
psEnc->sCmn.LBRR_GainIncreases = SKP_max_int( 8 - SKP_RSHIFT( psEnc->sCmn.PacketLoss_perc, 1 ), 0 );
/* Set main stream rate compensation */
if( psEnc->sCmn.LBRR_enabled && psEnc->sCmn.PacketLoss_perc > LBRR_LOSS_THRES ) {
/* Tuned to give approx same mean / weighted bitrate as no inband FEC */
psEnc->inBandFEC_SNR_comp_Q8 = SKP_FIX_CONST( 6.0f, 8 ) - SKP_LSHIFT( psEnc->sCmn.LBRR_GainIncreases, 7 );
} else {
psEnc->inBandFEC_SNR_comp_Q8 = 0;
psEnc->sCmn.LBRR_enabled = 0;
}
} else {
psEnc->inBandFEC_SNR_comp_Q8 = 0;
psEnc->sCmn.LBRR_enabled = 0;
}
#else
if( INBandFEC_enabled != 0 ) {
ret = SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING;
}
psEnc->sCmn.LBRR_enabled = 0;
#endif
return ret;
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -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,9 @@ 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;

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -47,8 +47,6 @@ SKP_int SKP_Silk_init_decoder(
SKP_Silk_CNG_Reset( psDec );
SKP_Silk_PLC_Reset( psDec );
psDec->bitstream_v = USE_BIT_STREAM_V;
return(0);
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -26,7 +26,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
#include "SKP_Silk_SDK_API.h"
#include "SKP_Silk_main_FIX.h"
#include "SKP_Silk_main.h"
/*********************/
/* Decoder functions */
@ -69,9 +69,17 @@ SKP_int SKP_Silk_SDK_Decode(
{
SKP_int ret = 0, used_bytes, prev_fs_kHz;
SKP_Silk_decoder_state *psDec;
SKP_int16 samplesOutInternal[ MAX_API_FS_KHZ * FRAME_LENGTH_MS ];
SKP_int16 *pSamplesOutInternal;
psDec = (SKP_Silk_decoder_state *)decState;
/* We need this buffer to have room for an internal frame */
pSamplesOutInternal = samplesOut;
if( psDec->fs_kHz * 1000 > decControl->API_sampleRate ) {
pSamplesOutInternal = samplesOutInternal;
}
/**********************************/
/* Test if first frame in payload */
/**********************************/
@ -92,7 +100,7 @@ SKP_int SKP_Silk_SDK_Decode(
prev_fs_kHz = psDec->fs_kHz;
/* Call decoder for one frame */
ret += SKP_Silk_decode_frame( psDec, samplesOut, nSamplesOut, inData, nBytesIn,
ret += SKP_Silk_decode_frame( psDec, pSamplesOutInternal, nSamplesOut, inData, nBytesIn,
lostFlag, &used_bytes );
if( used_bytes ) { /* Only Call if not a packet loss */
@ -122,48 +130,38 @@ SKP_int SKP_Silk_SDK_Decode(
}
}
if( psDec->fs_kHz * 1000 > decControl->sampleRate ) {
ret = SKP_SILK_DEC_WRONG_SAMPLING_FREQUENCY;
if( MAX_API_FS_KHZ * 1000 < decControl->API_sampleRate ||
8000 > decControl->API_sampleRate ) {
ret = SKP_SILK_DEC_INVALID_SAMPLING_FREQUENCY;
return( ret );
}
/* Do any resampling if needed */
if( psDec->fs_kHz * 1000 != decControl->sampleRate ) {
SKP_int16 samplesOut_tmp[ 2 * MAX_FRAME_LENGTH ];
SKP_int32 scratch[ 3 * MAX_FRAME_LENGTH ];
/* Resample if needed */
if( psDec->fs_kHz * 1000 != decControl->API_sampleRate ) {
SKP_int16 samplesOut_tmp[ MAX_API_FS_KHZ * FRAME_LENGTH_MS ];
SKP_assert( psDec->fs_kHz <= MAX_API_FS_KHZ );
/* Copy to a tmpbuffer as the resampling writes to samplesOut */
memcpy( samplesOut_tmp, samplesOut, *nSamplesOut * sizeof( SKP_int16 ) );
/* Copy to a tmp buffer as the resampling writes to samplesOut */
SKP_memcpy( samplesOut_tmp, pSamplesOutInternal, *nSamplesOut * sizeof( SKP_int16 ) );
/* Clear resampler state when switching internal sampling frequency */
if( prev_fs_kHz != psDec->fs_kHz ) {
SKP_memset( psDec->resampleState, 0, sizeof( psDec->resampleState ) );
/* (Re-)initialize resampler state when switching internal sampling frequency */
if( prev_fs_kHz != psDec->fs_kHz || psDec->prev_API_sampleRate != decControl->API_sampleRate ) {
ret = SKP_Silk_resampler_init( &psDec->resampler_state, SKP_SMULBB( psDec->fs_kHz, 1000 ), decControl->API_sampleRate );
}
if( psDec->fs_kHz == 16 && decControl->sampleRate == 24000 ) {
/* Resample from 16 kHz to 24 kHz */
SKP_Silk_resample_3_2( samplesOut, psDec->resampleState, samplesOut_tmp, *nSamplesOut );
} else if( psDec->fs_kHz == 12 && decControl->sampleRate == 24000 ) {
/* Resample from 12 kHz to 24 kHz */
SKP_Silk_resample_2_1_coarse( samplesOut_tmp, psDec->resampleState, samplesOut, scratch, *nSamplesOut );
} else if( psDec->fs_kHz == 8 && decControl->sampleRate == 24000 ) {
/* Resample from 8 kHz to 24 kHz */
SKP_Silk_resample_3_1( samplesOut, psDec->resampleState, samplesOut_tmp, *nSamplesOut );
} else if( psDec->fs_kHz == 12 && decControl->sampleRate == 16000 ) {
/* Resample from 12 kHz to 16 kHz */
SKP_Silk_resample_4_3( samplesOut, psDec->resampleState, samplesOut_tmp, *nSamplesOut );
} else if( psDec->fs_kHz == 8 && decControl->sampleRate == 16000 ) {
/* Resample from 8 kHz to 16 kHz */
SKP_Silk_resample_2_1_coarse( samplesOut_tmp, psDec->resampleState, samplesOut, scratch, *nSamplesOut );
} else if( psDec->fs_kHz == 8 && decControl->sampleRate == 12000 ) {
/* Resample from 8 kHz to 12 kHz */
SKP_Silk_resample_3_2( samplesOut, psDec->resampleState, samplesOut_tmp, *nSamplesOut );
}
/* Resample the output to API_sampleRate */
ret += SKP_Silk_resampler( &psDec->resampler_state, samplesOut, samplesOut_tmp, *nSamplesOut );
*nSamplesOut = SKP_DIV32( ( SKP_int32 )*nSamplesOut * decControl->sampleRate, psDec->fs_kHz * 1000 );
/* Update the number of output samples */
*nSamplesOut = SKP_DIV32( ( SKP_int32 )*nSamplesOut * decControl->API_sampleRate, psDec->fs_kHz * 1000 );
} else if( prev_fs_kHz * 1000 > decControl->API_sampleRate ) {
SKP_memcpy( samplesOut, pSamplesOutInternal, *nSamplesOut * sizeof( SKP_int16 ) );
}
psDec->prev_API_sampleRate = decControl->API_sampleRate;
/* Copy all parameters that are needed out of internal structure to the control stucture */
decControl->frameSize = ( SKP_int )psDec->frame_length;
decControl->frameSize = (SKP_uint16)( decControl->API_sampleRate / 50 ) ;
decControl->framesPerPacket = ( SKP_int )psDec->nFramesInPacket;
decControl->inBandFECOffset = ( SKP_int )psDec->inband_FEC_offset;
decControl->moreInternalDecoderFrames = ( SKP_int )psDec->moreInternalDecoderFrames;
@ -173,20 +171,16 @@ SKP_int SKP_Silk_SDK_Decode(
/* Function to find LBRR information in a packet */
void SKP_Silk_SDK_search_for_LBRR(
void *decState, /* I: Decoder state, to select bitstream version only */
const SKP_uint8 *inData, /* I: Encoded input vector */
const SKP_int16 nBytesIn, /* I: Number of input Bytes */
const SKP_int 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_Silk_decoder_state *psDec;
SKP_Silk_decoder_state sDec; // Local decoder state to avoid interfering with running decoder */
SKP_Silk_decoder_control sDecCtrl;
SKP_int i, TempQ[ MAX_FRAME_LENGTH ];
psDec = ( SKP_Silk_decoder_state * )decState;
SKP_int TempQ[ MAX_FRAME_LENGTH ];
if( lost_offset < 1 || lost_offset > MAX_LBRR_DELAY ) {
/* No useful FEC in this packet */
@ -196,138 +190,80 @@ void SKP_Silk_SDK_search_for_LBRR(
sDec.nFramesDecoded = 0;
sDec.fs_kHz = 0; /* Force update parameters LPC_order etc */
sDec.lossCnt = 0; /* Avoid running bw expansion of the LPC parameters when searching for LBRR data */
SKP_memset( sDec.prevNLSF_Q15, 0, MAX_LPC_ORDER * sizeof( SKP_int ) );
SKP_Silk_range_dec_init( &sDec.sRC, inData, ( SKP_int32 )nBytesIn );
if( psDec->bitstream_v == BIT_STREAM_V4 ) { /* Silk_v4 payload */
/* Decode all parameter indices for the whole packet*/
SKP_Silk_decode_indices_v4( &sDec );
/* Is there usable LBRR in this packet */
*nLBRRBytes = 0;
while(1) {
SKP_Silk_decode_parameters( &sDec, &sDecCtrl, TempQ, 0 );
if( sDec.sRC.error ) {
/* Corrupt stream */
*nLBRRBytes = 0;
return;
};
if( ( sDec.FrameTermination - 1 ) & lost_offset && sDec.FrameTermination > 0 && sDec.nBytesLeft >= 0 ) {
/* The wanted FEC is present in the packet */
for( i = 0; i < sDec.nFramesInPacket; i++ ) {
SKP_Silk_decode_parameters_v4( &sDec, &sDecCtrl, TempQ, 0 );
if( sDec.nBytesLeft <= 0 || sDec.sRC.error ) {
/* Corrupt stream */
LBRRData = NULL;
*nLBRRBytes = 0;
break;
} else {
sDec.nFramesDecoded++;
}
}
if( LBRRData != NULL ) {
/* The wanted FEC is present in the packet */
*nLBRRBytes = sDec.nBytesLeft;
SKP_memcpy( LBRRData, &inData[ nBytesIn - sDec.nBytesLeft ], sDec.nBytesLeft * sizeof( SKP_uint8 ) );
}
*nLBRRBytes = sDec.nBytesLeft;
SKP_memcpy( LBRRData, &inData[ nBytesIn - sDec.nBytesLeft ], sDec.nBytesLeft * sizeof( SKP_uint8 ) );
break;
}
} else { /* Silk_v3 payload */
while(1) {
SKP_Silk_decode_parameters( &sDec, &sDecCtrl, TempQ, 0 );
if( sDec.sRC.error ) {
/* Corrupt stream */
*nLBRRBytes = 0;
return;
};
if( ( sDec.FrameTermination - 1 ) & lost_offset && sDec.FrameTermination > 0 && sDec.nBytesLeft >= 0 ) {
/* The wanted FEC is present in the packet */
*nLBRRBytes = sDec.nBytesLeft;
SKP_memcpy( LBRRData, &inData[ nBytesIn - sDec.nBytesLeft ], sDec.nBytesLeft * sizeof( SKP_uint8 ) );
break;
}
if( sDec.nBytesLeft > 0 && sDec.FrameTermination == SKP_SILK_MORE_FRAMES ) {
sDec.nFramesDecoded++;
} else {
LBRRData = NULL;
*nLBRRBytes = 0;
break;
}
if( sDec.nBytesLeft > 0 && sDec.FrameTermination == SKP_SILK_MORE_FRAMES ) {
sDec.nFramesDecoded++;
} else {
LBRRData = NULL;
*nLBRRBytes = 0;
break;
}
}
}
/* Getting type of content for a packet */
void SKP_Silk_SDK_get_TOC(
void *decState, /* I/O: Decoder state, to select bitstream version only */
const SKP_uint8 *inData, /* I: Encoded input vector */
const SKP_int16 nBytesIn, /* I: Number of input bytes */
const SKP_int nBytesIn, /* I: Number of input bytes */
SKP_Silk_TOC_struct *Silk_TOC /* O: Type of content */
)
{
SKP_Silk_decoder_state *psDec;
SKP_Silk_decoder_state sDec; // Local Decoder state to avoid interfering with running decoder */
SKP_Silk_decoder_control sDecCtrl;
SKP_int i, TempQ[ MAX_FRAME_LENGTH ];
psDec = (SKP_Silk_decoder_state *)decState;
SKP_int TempQ[ MAX_FRAME_LENGTH ];
sDec.nFramesDecoded = 0;
sDec.fs_kHz = 0; /* Force update parameters LPC_order etc */
SKP_Silk_range_dec_init( &sDec.sRC, inData, ( SKP_int32 )nBytesIn );
if( psDec->bitstream_v == BIT_STREAM_V4 ) { /* Silk_v4 payload */
/* Decode all parameter indices for the whole packet*/
SKP_Silk_decode_indices_v4( &sDec );
Silk_TOC->corrupt = 0;
while( 1 ) {
SKP_Silk_decode_parameters( &sDec, &sDecCtrl, TempQ, 0 );
if( sDec.nFramesInPacket > SILK_MAX_FRAMES_PER_PACKET || sDec.sRC.error ) {
/* Corrupt packet */
SKP_memset( Silk_TOC, 0, sizeof( SKP_Silk_TOC_struct ) );
Silk_TOC->vadFlags[ sDec.nFramesDecoded ] = sDec.vadFlag;
Silk_TOC->sigtypeFlags[ sDec.nFramesDecoded ] = sDecCtrl.sigtype;
if( sDec.sRC.error ) {
/* Corrupt stream */
Silk_TOC->corrupt = 1;
break;
};
if( sDec.nBytesLeft > 0 && sDec.FrameTermination == SKP_SILK_MORE_FRAMES ) {
sDec.nFramesDecoded++;
} else {
Silk_TOC->corrupt = 0;
Silk_TOC->framesInPacket = sDec.nFramesInPacket;
Silk_TOC->fs_kHz = sDec.fs_kHz;
if( sDec.FrameTermination == SKP_SILK_LAST_FRAME ) {
Silk_TOC->inbandLBRR = sDec.FrameTermination;
} else {
Silk_TOC->inbandLBRR = sDec.FrameTermination - 1;
}
/* Copy data */
for( i = 0; i < sDec.nFramesInPacket; i++ ) {
Silk_TOC->vadFlags[ i ] = sDec.vadFlagBuf[ i ];
Silk_TOC->sigtypeFlags[ i ] = sDec.sigtype[ i ];
}
break;
}
} else { /* Silk_v3 payload */
Silk_TOC->corrupt = 0;
while( 1 ) {
SKP_Silk_decode_parameters( &sDec, &sDecCtrl, TempQ, 0 );
Silk_TOC->vadFlags[ sDec.nFramesDecoded ] = sDec.vadFlag;
Silk_TOC->sigtypeFlags[ sDec.nFramesDecoded ] = sDecCtrl.sigtype;
if( sDec.sRC.error ) {
/* Corrupt stream */
Silk_TOC->corrupt = 1;
break;
};
if( sDec.nBytesLeft > 0 && sDec.FrameTermination == SKP_SILK_MORE_FRAMES ) {
sDec.nFramesDecoded++;
} else {
break;
}
}
if( Silk_TOC->corrupt || sDec.FrameTermination == SKP_SILK_MORE_FRAMES ||
sDec.nFramesInPacket > SILK_MAX_FRAMES_PER_PACKET ) {
/* Corrupt packet */
SKP_memset( Silk_TOC, 0, sizeof( SKP_Silk_TOC_struct ) );
Silk_TOC->corrupt = 1;
}
if( Silk_TOC->corrupt || sDec.FrameTermination == SKP_SILK_MORE_FRAMES ||
sDec.nFramesInPacket > SILK_MAX_FRAMES_PER_PACKET ) {
/* Corrupt packet */
SKP_memset( Silk_TOC, 0, sizeof( SKP_Silk_TOC_struct ) );
Silk_TOC->corrupt = 1;
} else {
Silk_TOC->framesInPacket = sDec.nFramesDecoded + 1;
Silk_TOC->fs_kHz = sDec.fs_kHz;
if( sDec.FrameTermination == SKP_SILK_LAST_FRAME ) {
Silk_TOC->inbandLBRR = sDec.FrameTermination;
} else {
Silk_TOC->framesInPacket = sDec.nFramesDecoded;
Silk_TOC->fs_kHz = sDec.fs_kHz;
if( sDec.FrameTermination == SKP_SILK_LAST_FRAME ) {
Silk_TOC->inbandLBRR = sDec.FrameTermination;
} else {
Silk_TOC->inbandLBRR = sDec.FrameTermination - 1;
}
Silk_TOC->inbandLBRR = sDec.FrameTermination - 1;
}
}
}
@ -338,6 +274,6 @@ void SKP_Silk_SDK_get_TOC(
/* Return a pointer to string specifying the version */
const char *SKP_Silk_SDK_get_version()
{
static const char version[] = "1.0.2";
static const char version[] = "1.0.8";
return version;
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -27,6 +27,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SKP_Silk_main.h"
void SKP_Silk_decode_short_term_prediction(
SKP_int32 *vec_Q10,
SKP_int32 *pres_Q10,
SKP_int32 *sLPC_Q14,
SKP_int16 *A_Q12_tmp,
SKP_int LPC_order,
SKP_int subfr_length
);
/**********************************************************/
/* Core decoder. Performs inverse NSQ operation LTP + LPC */
/**********************************************************/
@ -37,13 +48,14 @@ void SKP_Silk_decode_core(
const SKP_int q[ MAX_FRAME_LENGTH ] /* I Pulse signal */
)
{
SKP_int i, k, lag = 0, start_idx, NLSF_interpolation_flag, sigtype, LTP_scale_Q14;
SKP_int16 *A_Q12, *B_Q14, *pxq, A_Q12_tmp[ MAX_LPC_ORDER ];
SKP_int16 sLTP[ MAX_FRAME_LENGTH ];
SKP_int32 Gain_Q16, *pred_lag_ptr, *pexc_Q10, *pres_Q10, LTP_pred_Q14, LPC_pred_Q10;
SKP_int32 rand_seed, offset_Q10, dither;
SKP_int32 vec_Q10[ MAX_FRAME_LENGTH / NB_SUBFR ], Atmp;
SKP_int32 inv_gain_Q16, inv_gain_Q32, gain_adj_Q16, FiltState[ MAX_LPC_ORDER ];
SKP_int i, k, lag = 0, start_idx, sLTP_buf_idx, NLSF_interpolation_flag, sigtype, LTP_scale_Q14;
SKP_int16 *A_Q12, *B_Q14, *pxq, A_Q12_tmp[ MAX_LPC_ORDER ];
SKP_int16 sLTP[ MAX_FRAME_LENGTH ];
SKP_int32 LTP_pred_Q14, Gain_Q16, inv_gain_Q16, inv_gain_Q32, gain_adj_Q16, rand_seed, offset_Q10, dither;
SKP_int32 *pred_lag_ptr, *pexc_Q10, *pres_Q10;
SKP_int32 vec_Q10[ MAX_FRAME_LENGTH / NB_SUBFR ];
SKP_int32 FiltState[ MAX_LPC_ORDER ];
SKP_assert( psDec->prev_inv_gain_Q16 != 0 );
offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psDecCtrl->sigtype ][ psDecCtrl->QuantOffsetType ];
@ -72,7 +84,7 @@ void SKP_Silk_decode_core(
pexc_Q10 = psDec->exc_Q10;
pres_Q10 = psDec->res_Q10;
pxq = &psDec->outBuf[ psDec->frame_length ];
psDec->sLTP_buf_idx = psDec->frame_length;
sLTP_buf_idx = psDec->frame_length;
/* Loop over subframes */
for( k = 0; k < NB_SUBFR; k++ ) {
A_Q12 = psDecCtrl->PredCoef_Q12[ k >> 1 ];
@ -84,8 +96,8 @@ void SKP_Silk_decode_core(
LTP_scale_Q14 = psDecCtrl->LTP_scale_Q14;
sigtype = psDecCtrl->sigtype;
inv_gain_Q16 = SKP_DIV32( SKP_int32_MAX, SKP_RSHIFT( Gain_Q16, 1 ) );
inv_gain_Q16 = SKP_min( inv_gain_Q16, SKP_int16_MAX );
inv_gain_Q16 = SKP_INVERSE32_varQ( SKP_max( Gain_Q16, 1 ), 32 );
inv_gain_Q16 = SKP_min( inv_gain_Q16, SKP_int16_MAX );
/* Calculate Gain adjustment factor */
gain_adj_Q16 = ( SKP_int32 )1 << 16;
@ -104,6 +116,7 @@ void SKP_Silk_decode_core(
psDecCtrl->pitchL[ k ] = psDec->lagPrev;
LTP_scale_Q14 = ( SKP_int )1 << 14;
}
if( sigtype == SIG_TYPE_VOICED ) {
/* Voiced */
@ -112,8 +125,10 @@ void SKP_Silk_decode_core(
if( ( k & ( 3 - SKP_LSHIFT( NLSF_interpolation_flag, 1 ) ) ) == 0 ) {
/* Rewhiten with new A coefs */
start_idx = psDec->frame_length - lag - psDec->LPC_order - LTP_ORDER / 2;
start_idx = SKP_LIMIT( start_idx, 0, psDec->frame_length - psDec->LPC_order );
SKP_assert( start_idx >= 0 );
SKP_assert( start_idx <= psDec->frame_length - psDec->LPC_order );
SKP_memset( FiltState, 0, psDec->LPC_order * sizeof( SKP_int32 ) ); /* Not really necessary, but Valgrind and Coverity will complain otherwise */
SKP_Silk_MA_Prediction( &psDec->outBuf[ start_idx + k * ( psDec->frame_length >> 2 ) ],
A_Q12, FiltState, sLTP + start_idx, psDec->frame_length - start_idx, psDec->LPC_order );
@ -124,13 +139,13 @@ void SKP_Silk_decode_core(
inv_gain_Q32 = SKP_LSHIFT( SKP_SMULWB( inv_gain_Q32, psDecCtrl->LTP_scale_Q14 ), 2 );
}
for( i = 0; i < (lag + LTP_ORDER/2); i++ ) {
psDec->sLTP_Q16[ psDec->sLTP_buf_idx - i - 1 ] = SKP_SMULWB( inv_gain_Q32, sLTP[ psDec->frame_length - i - 1 ] );
psDec->sLTP_Q16[ sLTP_buf_idx - i - 1 ] = SKP_SMULWB( inv_gain_Q32, sLTP[ psDec->frame_length - i - 1 ] );
}
} else {
/* Update LTP state when Gain changes */
if( gain_adj_Q16 != ( SKP_int32 )1 << 16 ) {
for( i = 0; i < ( lag + LTP_ORDER / 2 ); i++ ) {
psDec->sLTP_Q16[ psDec->sLTP_buf_idx - i - 1 ] = SKP_SMULWW( gain_adj_Q16, psDec->sLTP_Q16[ psDec->sLTP_buf_idx - i - 1 ] );
psDec->sLTP_Q16[ sLTP_buf_idx - i - 1 ] = SKP_SMULWW( gain_adj_Q16, psDec->sLTP_Q16[ sLTP_buf_idx - i - 1 ] );
}
}
}
@ -145,11 +160,10 @@ void SKP_Silk_decode_core(
SKP_assert( inv_gain_Q16 != 0 );
psDec->prev_inv_gain_Q16 = inv_gain_Q16;
/* Long-term prediction */
if( sigtype == SIG_TYPE_VOICED ) {
/* Setup pointer */
pred_lag_ptr = &psDec->sLTP_Q16[ psDec->sLTP_buf_idx - lag + LTP_ORDER / 2 ];
pred_lag_ptr = &psDec->sLTP_Q16[ sLTP_buf_idx - lag + LTP_ORDER / 2 ];
for( i = 0; i < psDec->subfr_length; i++ ) {
/* Unrolled loop */
LTP_pred_Q14 = SKP_SMULWB( pred_lag_ptr[ 0 ], B_Q14[ 0 ] );
@ -163,80 +177,14 @@ void SKP_Silk_decode_core(
pres_Q10[ i ] = SKP_ADD32( pexc_Q10[ i ], SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 ) );
/* Update states */
psDec->sLTP_Q16[ psDec->sLTP_buf_idx ] = SKP_LSHIFT( pres_Q10[ i ], 6 );
psDec->sLTP_buf_idx++;
psDec->sLTP_Q16[ sLTP_buf_idx ] = SKP_LSHIFT( pres_Q10[ i ], 6 );
sLTP_buf_idx++;
}
} else {
SKP_memcpy( pres_Q10, pexc_Q10, psDec->subfr_length * sizeof( SKP_int32 ) );
}
/* Short term prediction */
/* NOTE: the code below loads two int16 values in an int32, and multiplies each using the */
/* SMLAWB and SMLAWT instructions. On a big-endian CPU the two int16 variables would be */
/* loaded in reverse order and the code will give the wrong result. In that case swapping */
/* the SMLAWB and SMLAWT instructions should solve the problem. */
if( psDec->LPC_order == 16 ) {
for( i = 0; i < psDec->subfr_length; i++ ) {
/* unrolled */
Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 0 ] ); /* read two coefficients at once */
LPC_pred_Q10 = SKP_SMULWB( psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 1 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 2 ], Atmp );
Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 2 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 3 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 4 ], Atmp );
Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 4 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 5 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 6 ], Atmp );
Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 6 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 7 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 8 ], Atmp );
Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 8 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 9 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 10 ], Atmp );
Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 10 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 11 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 12 ], Atmp );
Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 12 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 13 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 14 ], Atmp );
Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 14 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 15 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 16 ], Atmp );
/* Add prediction to LPC residual */
vec_Q10[ i ] = SKP_ADD32( pres_Q10[ i ], LPC_pred_Q10 );
/* Update states */
psDec->sLPC_Q14[ MAX_LPC_ORDER + i ] = SKP_LSHIFT( vec_Q10[ i ], 4 );
}
} else {
SKP_assert( psDec->LPC_order == 10 );
for( i = 0; i < psDec->subfr_length; i++ ) {
/* unrolled */
Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 0 ] ); /* read two coefficients at once */
LPC_pred_Q10 = SKP_SMULWB( psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 1 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 2 ], Atmp );
Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 2 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 3 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 4 ], Atmp );
Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 4 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 5 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 6 ], Atmp );
Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 6 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 7 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 8 ], Atmp );
Atmp = *( ( SKP_int32* )&A_Q12_tmp[ 8 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 9 ], Atmp );
LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psDec->sLPC_Q14[ MAX_LPC_ORDER + i - 10 ], Atmp );
/* Add prediction to LPC residual */
vec_Q10[ i ] = SKP_ADD32( pres_Q10[ i ], LPC_pred_Q10 );
/* Update states */
psDec->sLPC_Q14[ MAX_LPC_ORDER + i ] = SKP_LSHIFT( vec_Q10[ i ], 4 );
}
}
SKP_Silk_decode_short_term_prediction(vec_Q10, pres_Q10, psDec->sLPC_Q14,A_Q12_tmp,psDec->LPC_order,psDec->subfr_length);
/* Scale with Gain */
for( i = 0; i < psDec->subfr_length; i++ ) {
@ -254,3 +202,43 @@ void SKP_Silk_decode_core(
SKP_memcpy( xq, &psDec->outBuf[ psDec->frame_length ], psDec->frame_length * sizeof( SKP_int16 ) );
}
void SKP_Silk_decode_short_term_prediction(
SKP_int32 *vec_Q10,
SKP_int32 *pres_Q10,
SKP_int32 *sLPC_Q14,
SKP_int16 *A_Q12_tmp,
SKP_int LPC_order,
SKP_int subfr_length
)
{
SKP_int i;
SKP_int32 LPC_pred_Q10;
SKP_int j;
for( i = 0; i < subfr_length; i++ ) {
/* Partially unrolled */
LPC_pred_Q10 = SKP_SMULWB( sLPC_Q14[ MAX_LPC_ORDER + i - 1 ], A_Q12_tmp[ 0 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 2 ], A_Q12_tmp[ 1 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 3 ], A_Q12_tmp[ 2 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 4 ], A_Q12_tmp[ 3 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 5 ], A_Q12_tmp[ 4 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 6 ], A_Q12_tmp[ 5 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 7 ], A_Q12_tmp[ 6 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 8 ], A_Q12_tmp[ 7 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 9 ], A_Q12_tmp[ 8 ] );
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 10 ], A_Q12_tmp[ 9 ] );
for( j = 10; j < LPC_order; j ++ ) {
LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - j - 1 ], A_Q12_tmp[ j ] );
}
/* Add prediction to LPC residual */
vec_Q10[ i ] = SKP_ADD32( pres_Q10[ i ], LPC_pred_Q10 );
/* Update states */
sLPC_Q14[ MAX_LPC_ORDER + i ] = SKP_LSHIFT( vec_Q10[ i ], 4 );
}
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -66,30 +66,20 @@ SKP_int SKP_Silk_decode_frame(
if( psDec->nFramesDecoded == 0 ) {
/* Initialize range decoder state */
SKP_Silk_range_dec_init( &psDec->sRC, pCode, nBytes );
if( psDec->bitstream_v == BIT_STREAM_V4 ) {
SKP_Silk_decode_indices_v4( psDec );
}
}
/********************************************/
/* Decode parameters and pulse signal */
/********************************************/
if( psDec->bitstream_v == BIT_STREAM_V4 ) {
SKP_Silk_decode_parameters_v4( psDec, &sDecCtrl, Pulses, 1 );
} else {
SKP_Silk_decode_parameters( psDec, &sDecCtrl, Pulses, 1 );
}
SKP_Silk_decode_parameters( psDec, &sDecCtrl, Pulses, 1 );
if( psDec->sRC.error ) {
psDec->nBytesLeft = 0;
action = 1; /* PLC operation */
psDec->fs_kHz = fs_Khz_old; /* revert fs if changed in decode_parameters */
psDec->LPC_order = LPC_order_old; /* revert lpc_order if changed in decode_parameters */
psDec->frame_length = fs_Khz_old * FRAME_LENGTH_MS;
psDec->subfr_length = fs_Khz_old * FRAME_LENGTH_MS / NB_SUBFR;
/* revert fs if changed in decode_parameters */
SKP_Silk_decoder_set_fs( psDec, fs_Khz_old );
/* Avoid crashing */
*decBytes = psDec->sRC.bufferLength;
@ -124,13 +114,11 @@ SKP_int SKP_Silk_decode_frame(
}
}
/*************************************************************/
/* Generate Concealment Frame if packet is lost, or corrupt */
/* Generate Concealment frame if packet is lost, or corrupt */
/*************************************************************/
if( action == 1 ) {
/* Handle packet loss by extrapolation */
SKP_Silk_PLC( psDec, &sDecCtrl, pOut, L, action );
psDec->lossCnt++;
}
/*************************/
@ -163,5 +151,6 @@ SKP_int SKP_Silk_decode_frame(
/* Update some decoder state variables */
psDec->lagPrev = sDecCtrl.pitchL[ NB_SUBFR - 1 ];
return ret;
}

View File

@ -1,195 +0,0 @@
/***********************************************************************
Copyright (c) 2006-2010, 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"
/* Decode indices from payload */
void SKP_Silk_decode_indices_v4(
SKP_Silk_decoder_state *psDec /* I/O State */
)
{
SKP_int i, k, Ix, fs_kHz_dec, FrameIndex = 0, FrameTermination;
SKP_int sigtype, QuantOffsetType, seed_int, nBytesUsed;
SKP_int decode_absolute_lagIndex, delta_lagIndex, prev_lagIndex = 0;
const SKP_Silk_NLSF_CB_struct *psNLSF_CB = NULL;
SKP_Silk_range_coder_state *psRC = &psDec->sRC;
/************************/
/* Decode sampling rate */
/************************/
/* only done for first frame of packet */
if( psDec->nFramesDecoded == 0 ) {
SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_SamplingRates_CDF, SKP_Silk_SamplingRates_offset );
/* check that sampling rate is supported */
if( Ix < 0 || Ix > 3 ) {
psRC->error = RANGE_CODER_ILLEGAL_SAMPLING_RATE;
return;
}
fs_kHz_dec = SKP_Silk_SamplingRates_table[ Ix ];
SKP_Silk_decoder_set_fs( psDec, fs_kHz_dec );
FrameIndex = 0;
FrameTermination = SKP_SILK_MORE_FRAMES;
}
while( FrameTermination == SKP_SILK_MORE_FRAMES ) {
/*******************/
/* Decode VAD flag */
/*******************/
SKP_Silk_range_decoder( &psDec->vadFlagBuf[ FrameIndex ], psRC, SKP_Silk_vadflag_CDF, SKP_Silk_vadflag_offset );
/*******************************************/
/* Decode signal type and quantizer offset */
/*******************************************/
if( FrameIndex == 0 ) {
/* first frame in packet: independent coding */
SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_type_offset_CDF, SKP_Silk_type_offset_CDF_offset );
} else {
/* condidtional coding */
SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_type_offset_joint_CDF[ psDec->typeOffsetPrev ],
SKP_Silk_type_offset_CDF_offset );
}
sigtype = SKP_RSHIFT( Ix, 1 );
QuantOffsetType = Ix & 1;
psDec->typeOffsetPrev = Ix;
/****************/
/* Decode gains */
/****************/
/* first subframe */
if( FrameIndex == 0 ) {
/* first frame in packet: independent coding */
SKP_Silk_range_decoder( &psDec->GainsIndices[ FrameIndex ][ 0 ], psRC, SKP_Silk_gain_CDF[ sigtype ], SKP_Silk_gain_CDF_offset );
} else {
/* condidtional coding */
SKP_Silk_range_decoder( &psDec->GainsIndices[ FrameIndex ][ 0 ], psRC, SKP_Silk_delta_gain_CDF, SKP_Silk_delta_gain_CDF_offset );
}
/* remaining subframes */
for( i = 1; i < NB_SUBFR; i++ ) {
SKP_Silk_range_decoder( &psDec->GainsIndices[ FrameIndex ][ i ], psRC, SKP_Silk_delta_gain_CDF, SKP_Silk_delta_gain_CDF_offset );
}
/**********************/
/* Decode LSF Indices */
/**********************/
/* Set pointer to LSF VQ CB for the current signal type */
psNLSF_CB = psDec->psNLSF_CB[ sigtype ];
/* Arithmetically decode NLSF path */
SKP_Silk_range_decoder_multi( psDec->NLSFIndices[ FrameIndex ], psRC, psNLSF_CB->StartPtr, psNLSF_CB->MiddleIx, psNLSF_CB->nStages );
/***********************************/
/* Decode LSF interpolation factor */
/***********************************/
SKP_Silk_range_decoder( &psDec->NLSFInterpCoef_Q2[ FrameIndex ], psRC, SKP_Silk_NLSF_interpolation_factor_CDF,
SKP_Silk_NLSF_interpolation_factor_offset );
if( sigtype == SIG_TYPE_VOICED ) {
/*********************/
/* Decode pitch lags */
/*********************/
/* Get lag index */
decode_absolute_lagIndex = 1;
if( FrameIndex > 0 && psDec->sigtype[ FrameIndex - 1 ] == SIG_TYPE_VOICED ) {
/* Decode Delta index */
SKP_Silk_range_decoder( &delta_lagIndex,psRC, SKP_Silk_pitch_delta_CDF, SKP_Silk_pitch_delta_CDF_offset );
if( delta_lagIndex < ( MAX_DELTA_LAG << 1 ) + 1 ) {
delta_lagIndex = delta_lagIndex - MAX_DELTA_LAG;
psDec->lagIndex[ FrameIndex ] = prev_lagIndex + delta_lagIndex;
decode_absolute_lagIndex = 0;
}
}
if( decode_absolute_lagIndex ) {
/* Absolute decoding */
if( psDec->fs_kHz == 8 ) {
SKP_Silk_range_decoder( &psDec->lagIndex[ FrameIndex ], psRC, SKP_Silk_pitch_lag_NB_CDF, SKP_Silk_pitch_lag_NB_CDF_offset );
} else if( psDec->fs_kHz == 12 ) {
SKP_Silk_range_decoder( &psDec->lagIndex[ FrameIndex ], psRC, SKP_Silk_pitch_lag_MB_CDF, SKP_Silk_pitch_lag_MB_CDF_offset );
} else if( psDec->fs_kHz == 16 ) {
SKP_Silk_range_decoder( &psDec->lagIndex[ FrameIndex ], psRC, SKP_Silk_pitch_lag_WB_CDF, SKP_Silk_pitch_lag_WB_CDF_offset );
} else {
SKP_Silk_range_decoder( &psDec->lagIndex[ FrameIndex ], psRC, SKP_Silk_pitch_lag_SWB_CDF, SKP_Silk_pitch_lag_SWB_CDF_offset );
}
}
prev_lagIndex = psDec->lagIndex[ FrameIndex ];
/* Get countour index */
if( psDec->fs_kHz == 8 ) {
/* Less codevectors used in 8 khz mode */
SKP_Silk_range_decoder( &psDec->contourIndex[ FrameIndex ], psRC, SKP_Silk_pitch_contour_NB_CDF, SKP_Silk_pitch_contour_NB_CDF_offset );
} else {
/* Joint for 12, 16, and 24 khz */
SKP_Silk_range_decoder( &psDec->contourIndex[ FrameIndex ], psRC, SKP_Silk_pitch_contour_CDF, SKP_Silk_pitch_contour_CDF_offset );
}
/********************/
/* Decode LTP gains */
/********************/
/* Decode PERIndex value */
SKP_Silk_range_decoder( &psDec->PERIndex[ FrameIndex ], psRC, SKP_Silk_LTP_per_index_CDF, SKP_Silk_LTP_per_index_CDF_offset );
for( k = 0; k < NB_SUBFR; k++ ) {
SKP_Silk_range_decoder( &psDec->LTPIndex[ FrameIndex ][ k ], psRC, SKP_Silk_LTP_gain_CDF_ptrs[ psDec->PERIndex[ FrameIndex ] ],
SKP_Silk_LTP_gain_CDF_offsets[ psDec->PERIndex[ FrameIndex ] ] );
}
/**********************/
/* Decode LTP scaling */
/**********************/
SKP_Silk_range_decoder( &psDec->LTP_scaleIndex[ FrameIndex ], psRC, SKP_Silk_LTPscale_CDF, SKP_Silk_LTPscale_offset );
}
/***************/
/* Decode seed */
/***************/
SKP_Silk_range_decoder( &seed_int, psRC, SKP_Silk_Seed_CDF, SKP_Silk_Seed_offset );
psDec->Seed[ FrameIndex ] = ( SKP_int32 )seed_int;
/**************************************/
/* Decode Frame termination indicator */
/**************************************/
SKP_Silk_range_decoder( &FrameTermination, psRC, SKP_Silk_FrameTermination_v4_CDF, SKP_Silk_FrameTermination_v4_offset );
psDec->sigtype[ FrameIndex ] = sigtype;
psDec->QuantOffsetType[ FrameIndex ] = QuantOffsetType;
FrameIndex++;
}
/****************************************/
/* get number of bytes used so far */
/****************************************/
SKP_Silk_range_coder_get_length( psRC, &nBytesUsed );
psDec->nBytesLeft = psRC->bufferLength - nBytesUsed;
if( psDec->nBytesLeft < 0 ) {
psRC->error = RANGE_CODER_READ_BEYOND_BUFFER;
}
psDec->nFramesInPacket = FrameIndex;
psDec->FrameTermination = FrameTermination;
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -100,7 +100,7 @@ void SKP_Silk_decode_parameters(
/* Set pointer to NLSF VQ CB for the current signal type */
psNLSF_CB = psDec->psNLSF_CB[ psDecCtrl->sigtype ];
/* Arithmetically decode NLSF path */
/* Range decode NLSF path */
SKP_Silk_range_decoder_multi( NLSFIndices, psRC, psNLSF_CB->StartPtr, psNLSF_CB->MiddleIx, psNLSF_CB->nStages );
/* From the NLSF path, decode an NLSF vector */
@ -182,14 +182,14 @@ void SKP_Silk_decode_parameters(
SKP_Silk_LTP_per_index_CDF_offset );
/* Decode Codebook Index */
cbk_ptr_Q14 = SKP_Silk_LTP_vq_ptrs_Q14[ psDecCtrl->PERIndex ]; // set pointer to start of codebook
cbk_ptr_Q14 = SKP_Silk_LTP_vq_ptrs_Q14[ psDecCtrl->PERIndex ]; /* set pointer to start of codebook */
for( k = 0; k < NB_SUBFR; k++ ) {
SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_LTP_gain_CDF_ptrs[ psDecCtrl->PERIndex ],
SKP_Silk_LTP_gain_CDF_offsets[ psDecCtrl->PERIndex ] );
for( i = 0; i < LTP_ORDER; i++ ) {
psDecCtrl->LTPCoef_Q14[ SKP_SMULBB( k, LTP_ORDER ) + i ] = cbk_ptr_Q14[ SKP_SMULBB( Ix, LTP_ORDER ) + i ];
psDecCtrl->LTPCoef_Q14[ k * LTP_ORDER + i ] = cbk_ptr_Q14[ Ix * LTP_ORDER + i ];
}
}
@ -199,8 +199,9 @@ void SKP_Silk_decode_parameters(
SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_LTPscale_CDF, SKP_Silk_LTPscale_offset );
psDecCtrl->LTP_scale_Q14 = SKP_Silk_LTPScales_table_Q14[ Ix ];
} else {
SKP_memset( psDecCtrl->pitchL, 0, NB_SUBFR * sizeof( SKP_int ) );
SKP_memset( psDecCtrl->LTPCoef_Q14, 0, NB_SUBFR * LTP_ORDER * sizeof( SKP_int16 ) );
SKP_assert( psDecCtrl->sigtype == SIG_TYPE_UNVOICED );
SKP_memset( psDecCtrl->pitchL, 0, NB_SUBFR * sizeof( SKP_int ) );
SKP_memset( psDecCtrl->LTPCoef_Q14, 0, LTP_ORDER * NB_SUBFR * sizeof( SKP_int16 ) );
psDecCtrl->PERIndex = 0;
psDecCtrl->LTP_scale_Q14 = 0;
}

View File

@ -1,157 +0,0 @@
/***********************************************************************
Copyright (c) 2006-2010, 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"
/* Decode parameters from payload */
void SKP_Silk_decode_parameters_v4(
SKP_Silk_decoder_state *psDec, /* I/O State */
SKP_Silk_decoder_control *psDecCtrl, /* I/O Decoder control */
SKP_int q[ MAX_FRAME_LENGTH ], /* O Excitation signal */
const SKP_int fullDecoding /* I Flag to tell if only arithmetic decoding */
)
{
SKP_int i, k, Ix, nBytesUsed;
SKP_int pNLSF_Q15[ MAX_LPC_ORDER ], pNLSF0_Q15[ MAX_LPC_ORDER ];
const SKP_int16 *cbk_ptr_Q14;
const SKP_Silk_NLSF_CB_struct *psNLSF_CB = NULL;
SKP_Silk_range_coder_state *psRC = &psDec->sRC;
psDec->FrameTermination = SKP_SILK_MORE_FRAMES;
psDecCtrl->sigtype = psDec->sigtype[ psDec->nFramesDecoded ];
psDecCtrl->QuantOffsetType = psDec->QuantOffsetType[ psDec->nFramesDecoded ];
psDec->vadFlag = psDec->vadFlagBuf[ psDec->nFramesDecoded ];
psDecCtrl->NLSFInterpCoef_Q2 = psDec->NLSFInterpCoef_Q2[ psDec->nFramesDecoded ];
psDecCtrl->Seed = psDec->Seed[ psDec->nFramesDecoded ];
/* Dequant Gains */
SKP_Silk_gains_dequant( psDecCtrl->Gains_Q16, psDec->GainsIndices[ psDec->nFramesDecoded ], &psDec->LastGainIndex, psDec->nFramesDecoded );
/****************/
/* Decode NLSFs */
/****************/
/* Set pointer to NLSF VQ CB for the current signal type */
psNLSF_CB = psDec->psNLSF_CB[ psDecCtrl->sigtype ];
/* From the NLSF path, decode an NLSF vector */
SKP_Silk_NLSF_MSVQ_decode( pNLSF_Q15, psNLSF_CB, psDec->NLSFIndices[ psDec->nFramesDecoded ], psDec->LPC_order );
/* Convert NLSF parameters to AR prediction filter coefficients */
SKP_Silk_NLSF2A_stable( psDecCtrl->PredCoef_Q12[ 1 ], pNLSF_Q15, psDec->LPC_order );
/* If just reset, e.g., because internal Fs changed, do not allow interpolation */
/* improves the case of packet loss in the first frame after a switch */
if( psDec->first_frame_after_reset == 1 ) {
psDecCtrl->NLSFInterpCoef_Q2 = 4;
}
if( psDecCtrl->NLSFInterpCoef_Q2 < 4 ) {
/* Calculation of the interpolated NLSF0 vector from the interpolation factor, */
/* the previous NLSF1, and the current NLSF1 */
for( i = 0; i < psDec->LPC_order; i++ ) {
pNLSF0_Q15[ i ] = psDec->prevNLSF_Q15[ i ] + SKP_RSHIFT( SKP_MUL( psDecCtrl->NLSFInterpCoef_Q2,
( pNLSF_Q15[ i ] - psDec->prevNLSF_Q15[ i ] ) ), 2 );
}
/* Convert NLSF parameters to AR prediction filter coefficients */
SKP_Silk_NLSF2A_stable( psDecCtrl->PredCoef_Q12[ 0 ], pNLSF0_Q15, psDec->LPC_order );
} else {
/* Copy LPC coefficients for first half from second half */
SKP_memcpy( psDecCtrl->PredCoef_Q12[ 0 ], psDecCtrl->PredCoef_Q12[ 1 ],
psDec->LPC_order * sizeof( SKP_int16 ) );
}
SKP_memcpy( psDec->prevNLSF_Q15, pNLSF_Q15, psDec->LPC_order * sizeof( SKP_int ) );
/* After a packet loss do BWE of LPC coefs */
if( psDec->lossCnt ) {
SKP_Silk_bwexpander( psDecCtrl->PredCoef_Q12[ 0 ], psDec->LPC_order, BWE_AFTER_LOSS_Q16 );
SKP_Silk_bwexpander( psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order, BWE_AFTER_LOSS_Q16 );
}
if( psDecCtrl->sigtype == SIG_TYPE_VOICED ) {
/*********************/
/* Decode pitch lags */
/*********************/
/* Decode pitch values */
SKP_Silk_decode_pitch( psDec->lagIndex[ psDec->nFramesDecoded ],
psDec->contourIndex[ psDec->nFramesDecoded ], psDecCtrl->pitchL, psDec->fs_kHz );
/********************/
/* Decode LTP gains */
/********************/
psDecCtrl->PERIndex = psDec->PERIndex[ psDec->nFramesDecoded ];
/* Decode Codebook Index */
cbk_ptr_Q14 = SKP_Silk_LTP_vq_ptrs_Q14[ psDecCtrl->PERIndex ]; /* set pointer to start of codebook */
for( k = 0; k < NB_SUBFR; k++ ) {
Ix = psDec->LTPIndex[ psDec->nFramesDecoded ][ k ];
for( i = 0; i < LTP_ORDER; i++ ) {
psDecCtrl->LTPCoef_Q14[ SKP_SMULBB( k, LTP_ORDER ) + i ] = cbk_ptr_Q14[ SKP_SMULBB( Ix, LTP_ORDER ) + i ];
}
}
/**********************/
/* Decode LTP scaling */
/**********************/
Ix = psDec->LTP_scaleIndex[ psDec->nFramesDecoded ];
psDecCtrl->LTP_scale_Q14 = SKP_Silk_LTPScales_table_Q14[ Ix ];
} else {
SKP_memset( psDecCtrl->pitchL, 0, NB_SUBFR * sizeof( SKP_int ) );
SKP_memset( psDecCtrl->LTPCoef_Q14, 0, NB_SUBFR * LTP_ORDER * sizeof( SKP_int16 ) );
psDecCtrl->PERIndex = 0;
psDecCtrl->LTP_scale_Q14 = 0;
}
/*********************************************/
/* Decode quantization indices of excitation */
/*********************************************/
SKP_Silk_decode_pulses( psRC, psDecCtrl, q, psDec->frame_length );
/****************************************/
/* get number of bytes used so far */
/****************************************/
SKP_Silk_range_coder_get_length( psRC, &nBytesUsed );
psDec->nBytesLeft = psRC->bufferLength - nBytesUsed;
if( psDec->nBytesLeft < 0 ) {
psRC->error = RANGE_CODER_READ_BEYOND_BUFFER;
}
/****************************************/
/* check remaining bits in last byte */
/****************************************/
if( psDec->nBytesLeft == 0 ) {
SKP_Silk_range_coder_check_after_decoding( psRC );
}
if( psDec->nFramesInPacket == (psDec->nFramesDecoded + 1)) {
/* To indicate the packet has been fully decoded */
psDec->FrameTermination = SKP_SILK_LAST_FRAME;
}
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -47,11 +47,10 @@ void SKP_Silk_decoder_set_fs(
psDec->psNLSF_CB[ 1 ] = &SKP_Silk_NLSF_CB1_16;
}
/* 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, 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 ) );
psDec->sLTP_buf_idx = 0;
psDec->lagPrev = 100;
psDec->LastGainIndex = 1;
psDec->prev_sigtype = 0;

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -38,26 +38,18 @@ extern "C"
#define MAX_FRAMES_PER_PACKET 5
#define BIT_STREAM_V3 3
#define BIT_STREAM_V4 4
#define USE_BIT_STREAM_V BIT_STREAM_V3 // Should be moved to a API call
/* MAX DELTA LAG used for multiframe packets */
#define MAX_DELTA_LAG 10
/* Lower limit on bitrate for each mode */
#define MIN_TARGET_RATE_NB_BPS 5000
#define MIN_TARGET_RATE_MB_BPS 7000
#define MIN_TARGET_RATE_WB_BPS 8000
#define MIN_TARGET_RATE_SWB_BPS 20000
/* Limits on bitrate */
#define MIN_TARGET_RATE_BPS 5000
#define MAX_TARGET_RATE_BPS 100000
/* Transition bitrates between modes */
#define SWB2WB_BITRATE_BPS 30000
#define SWB2WB_BITRATE_BPS_INITIAL 25000
#define WB2SWB_BITRATE_BPS 35000
#define WB2MB_BITRATE_BPS 15000
#define MB2WB_BITRATE_BPS 20000
#define SWB2WB_BITRATE_BPS 25000
#define WB2SWB_BITRATE_BPS 30000
#define WB2MB_BITRATE_BPS 14000
#define MB2WB_BITRATE_BPS 18000
#define MB2NB_BITRATE_BPS 10000
#define NB2MB_BITRATE_BPS 14000
@ -80,7 +72,7 @@ extern "C"
#define LBRR_IDX_MASK 1
#define INBAND_FEC_MIN_RATE_BPS 18000 /* Dont use inband FEC below this total target rate */
#define LBRR_LOSS_THRES 2 /* Start adding LBRR at this loss rate (needs tuning) */
#define LBRR_LOSS_THRES 1 /* Start adding LBRR at this loss rate */
/* LBRR usage defines */
#define SKP_SILK_NO_LBRR 0 /* No LBRR information for this packet */
@ -101,28 +93,17 @@ extern "C"
#define WB_DETECT_ACTIVE_SPEECH_MS_THRES 15000 /* ms of active speech needed for WB detection */
/* Low complexity setting */
#ifdef EMBEDDED_OPT
# define LOW_COMPLEXITY_ONLY 1
#else
# define LOW_COMPLEXITY_ONLY 0
#endif
#define LOW_COMPLEXITY_ONLY 0
/* Activate bandwidth transition filtering for mode switching */
#ifdef EMBEDDED_OPT
# define SWITCH_TRANSITION_FILTERING 0
#else
#ifndef FORCE_FS_KHZ
# define SWITCH_TRANSITION_FILTERING 1
#else
# define SWITCH_TRANSITION_FILTERING 0
#endif
#endif
#define SWITCH_TRANSITION_FILTERING 1
/* Decoder Parameters */
#define DEC_HP_ORDER 2
/* Maximum sampling frequency, should be 16 for embedded */
/* Maximum sampling frequency, should be 16 for some embedded platforms */
#define MAX_FS_KHZ 24
#define MAX_API_FS_KHZ 48
/* Signal Types used by silk */
#define SIG_TYPE_VOICED 0
@ -132,29 +113,31 @@ extern "C"
#define NO_VOICE_ACTIVITY 0
#define VOICE_ACTIVITY 1
/* number of samples per frame */
#define FRAME_LENGTH_MS 20 /* 20 ms */
#define MAX_FRAME_LENGTH (FRAME_LENGTH_MS * MAX_FS_KHZ)
/* Number of samples per frame */
#define FRAME_LENGTH_MS 20
#define MAX_FRAME_LENGTH ( FRAME_LENGTH_MS * MAX_FS_KHZ )
/* number of lookahead samples for pitch analysis */
#define LA_PITCH_MS 3
#define LA_PITCH_MAX (LA_PITCH_MS * MAX_FS_KHZ)
/* number of lookahead samples for noise shape analysis */
#define LA_SHAPE_MS 5
#define LA_SHAPE_MAX (LA_SHAPE_MS * MAX_FS_KHZ)
/* Order of LPC used in find pitch */
#define FIND_PITCH_LPC_ORDER_MAX 16
/* Milliseconds of lookahead for pitch analysis */
#define LA_PITCH_MS 2
#define LA_PITCH_MAX ( LA_PITCH_MS * MAX_FS_KHZ )
/* Length of LPC window used in find pitch */
#define FIND_PITCH_LPC_WIN_MS (30 + (LA_PITCH_MS << 1))
#define FIND_PITCH_LPC_WIN_MAX (FIND_PITCH_LPC_WIN_MS * MAX_FS_KHZ)
#define FIND_PITCH_LPC_WIN_MS ( 20 + (LA_PITCH_MS << 1) )
#define FIND_PITCH_LPC_WIN_MAX ( FIND_PITCH_LPC_WIN_MS * MAX_FS_KHZ )
#define PITCH_EST_COMPLEXITY_HC_MODE SigProc_PITCH_EST_MAX_COMPLEX
#define PITCH_EST_COMPLEXITY_MC_MODE SigProc_PITCH_EST_MID_COMPLEX
#define PITCH_EST_COMPLEXITY_LC_MODE SigProc_PITCH_EST_MIN_COMPLEX
/* Order of LPC used in find pitch */
#define MAX_FIND_PITCH_LPC_ORDER 16
#define PITCH_EST_COMPLEXITY_HC_MODE SKP_Silk_PITCH_EST_MAX_COMPLEX
#define PITCH_EST_COMPLEXITY_MC_MODE SKP_Silk_PITCH_EST_MID_COMPLEX
#define PITCH_EST_COMPLEXITY_LC_MODE SKP_Silk_PITCH_EST_MIN_COMPLEX
/* Milliseconds of lookahead for noise shape analysis */
#define LA_SHAPE_MS 5
#define LA_SHAPE_MAX ( LA_SHAPE_MS * MAX_FS_KHZ )
/* Max length of LPC window used in noise shape analysis */
#define SHAPE_LPC_WIN_MAX ( 15 * MAX_FS_KHZ )
/* Max number of bytes in payload output buffer (may contain multiple frames) */
#define MAX_ARITHM_BYTES 1024
@ -204,18 +187,12 @@ extern "C"
#define USE_HARM_SHAPING 1
/* Max LPC order of noise shaping filters */
#define SHAPE_LPC_ORDER_MAX 16
#define MAX_SHAPE_LPC_ORDER 16
#define HARM_SHAPE_FIR_TAPS 3
/* Length of LPC window used in noise shape analysis */
#define SHAPE_LPC_WIN_MS 15
#define SHAPE_LPC_WIN_16_KHZ (SHAPE_LPC_WIN_MS * 16)
#define SHAPE_LPC_WIN_24_KHZ (SHAPE_LPC_WIN_MS * 24)
#define SHAPE_LPC_WIN_MAX (SHAPE_LPC_WIN_MS * MAX_FS_KHZ)
/* Maximum number of delayed decision states */
#define DEL_DEC_STATES_MAX 4
#define MAX_DEL_DEC_STATES 4
#define LTP_BUF_LENGTH 512
#define LTP_MASK (LTP_BUF_LENGTH - 1)
@ -249,12 +226,12 @@ extern "C"
/***************************/
/* Voice activity detector */
/***************************/
#define VAD_N_BANDS 4 /* 0-1, 1-2, 2-4, and 4-8 kHz */
#define VAD_N_BANDS 4
#define VAD_INTERNAL_SUBFRAMES_LOG2 2
#define VAD_INTERNAL_SUBFRAMES (1 << VAD_INTERNAL_SUBFRAMES_LOG2)
#define VAD_NOISE_LEVEL_SMOOTH_COEF_Q16 1024 /* Must be < 4096 */
#define VAD_NOISE_LEVEL_SMOOTH_COEF_Q16 1024 /* Must be < 4096 */
#define VAD_NOISE_LEVELS_BIAS 50
/* Sigmoid settings */
@ -267,15 +244,9 @@ extern "C"
/******************/
/* NLSF quantizer */
/******************/
#ifdef NLSF_TRAINING
# define NLSF_MSVQ_MAX_CB_STAGES 30
# define NLSF_MSVQ_MAX_VECTORS_IN_STAGE 256
# define NLSF_MSVQ_MAX_VECTORS_IN_STAGE_TWO_TO_END 128
#else
# define NLSF_MSVQ_MAX_CB_STAGES 10 /* Update manually when changing codebooks */
# define NLSF_MSVQ_MAX_VECTORS_IN_STAGE 128 /* Update manually when changing codebooks */
# define NLSF_MSVQ_MAX_VECTORS_IN_STAGE_TWO_TO_END 16 /* Update manually when changing codebooks */
#endif
#define NLSF_MSVQ_FLUCTUATION_REDUCTION 1
#define MAX_NLSF_MSVQ_SURVIVORS 16
@ -295,19 +266,19 @@ extern "C"
# 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 4
#define NLSF_MSVQ_SURV_MAX_REL_RD 0.1f /* Must be < 0.5 */
/* Transition filtering for mode switching */
#if SWITCH_TRANSITION_FILTERING
# define TRANSITION_TIME_UP_MS 5120 // 5120 = 64 * FRAME_LENGTH_MS * ( TRANSITION_INT_NUM - 1 ) = 64*(20*4)
# define TRANSITION_TIME_DOWN_MS 2560 // 2560 = 32 * FRAME_LENGTH_MS * ( TRANSITION_INT_NUM - 1 ) = 32*(20*4)
# define TRANSITION_NB 3 /* Hardcoded in tables */
# define TRANSITION_NA 2 /* Hardcoded in tables */
# define TRANSITION_INT_NUM 5 /* Hardcoded in tables */
# define TRANSITION_FRAMES_UP ( TRANSITION_TIME_UP_MS / FRAME_LENGTH_MS )
# define TRANSITION_FRAMES_DOWN ( TRANSITION_TIME_DOWN_MS / FRAME_LENGTH_MS )
# define TRANSITION_INT_STEPS_UP ( TRANSITION_FRAMES_UP / ( TRANSITION_INT_NUM - 1 ) )
# define TRANSITION_INT_STEPS_DOWN ( TRANSITION_FRAMES_DOWN / ( TRANSITION_INT_NUM - 1 ) )
# define TRANSITION_TIME_UP_MS 5120 // 5120 = 64 * FRAME_LENGTH_MS * ( TRANSITION_INT_NUM - 1 ) = 64*(20*4)
# define TRANSITION_TIME_DOWN_MS 2560 // 2560 = 32 * FRAME_LENGTH_MS * ( TRANSITION_INT_NUM - 1 ) = 32*(20*4)
# define TRANSITION_NB 3 /* Hardcoded in tables */
# define TRANSITION_NA 2 /* Hardcoded in tables */
# define TRANSITION_INT_NUM 5 /* Hardcoded in tables */
# define TRANSITION_FRAMES_UP ( TRANSITION_TIME_UP_MS / FRAME_LENGTH_MS )
# define TRANSITION_FRAMES_DOWN ( TRANSITION_TIME_DOWN_MS / FRAME_LENGTH_MS )
# define TRANSITION_INT_STEPS_UP ( TRANSITION_FRAMES_UP / ( TRANSITION_INT_NUM - 1 ) )
# define TRANSITION_INT_STEPS_DOWN ( TRANSITION_FRAMES_DOWN / ( TRANSITION_INT_NUM - 1 ) )
#endif
/* Row based */
@ -321,7 +292,12 @@ extern "C"
#define matrix_c_adr(Matrix_base_adr, row, column, M) (Matrix_base_adr + ((row)+(M)*(column)))
/* BWE factors to apply after packet loss */
#define BWE_AFTER_LOSS_Q16 63570
#define BWE_AFTER_LOSS_Q16 63570
/* Defines for CN generation */
#define CNG_BUF_MASK_MAX 255 /* 2^floor(log2(MAX_FRAME_LENGTH))-1 */
#define CNG_GAIN_SMTH_Q16 4634 /* 0.25^(1/4) */
#define CNG_NLSF_SMTH_Q16 16348 /* 0.25 */
#ifdef __cplusplus
}

View File

@ -1,97 +0,0 @@
/***********************************************************************
Copyright (c) 2006-2010, 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.
***********************************************************************/
#ifndef SKP_SILK_DEFINE_FIX_H
#define SKP_SILK_DEFINE_FIX_H
#ifdef __cplusplus
extern "C"
{
#endif
/* Head room for correlations */
#define LTP_CORRS_HEAD_ROOM 2
#define LPC_CORRS_HEAD_ROOM 10
#define WB_DETECT_ACTIVE_SPEECH_LEVEL_THRES_Q8 179 // 179.2_Q8 = 0.7f required speech activity for counting frame as active
/* DTX settings */
#define SPEECH_ACTIVITY_DTX_THRES_Q8 26 // 25.60_Q8 = 0.1f
#define LBRR_SPEECH_ACTIVITY_THRES_Q8 128
/* level of noise floor for whitening filter LPC analysis in pitch analysis */
#define FIND_PITCH_WHITE_NOISE_FRACTION_Q16 66
/* bandwdith expansion for whitening filter in pitch analysis */
#define FIND_PITCH_BANDWITH_EXPANSION_Q16 64881
/* Threshold used by pitch estimator for early escape */
#define FIND_PITCH_CORRELATION_THRESHOLD_Q16_HC_MODE 45875 // 0.7
#define FIND_PITCH_CORRELATION_THRESHOLD_Q16_MC_MODE 49152 // 0.75
#define FIND_PITCH_CORRELATION_THRESHOLD_Q16_LC_MODE 52429 // 0.8
/* Regualarization factor for correlation matrix. Equivalent to adding noise at -50 dB */
#define FIND_LTP_COND_FAC_Q31 21475
#define FIND_LPC_COND_FAC_Q32 257698 // 6e-5
/* Find Pred Coef defines */
#define INACTIVE_BWExp_Q16 64225 // 0.98
#define ACTIVE_BWExp_Q16 65470 // 0.999
#define LTP_DAMPING_Q16 66
#define LTP_SMOOTHING_Q26 6710886
/* LTP quantization settings */
#define MU_LTP_QUANT_NB_Q8 8
#define MU_LTP_QUANT_MB_Q8 6
#define MU_LTP_QUANT_WB_Q8 5
#define MU_LTP_QUANT_SWB_Q8 4
/***********************/
/* High pass filtering */
/***********************/
/* Smoothing parameters for low end of pitch frequency range estimation */
#define VARIABLE_HP_SMTH_COEF1_Q16 6554 // 0.1
#define VARIABLE_HP_SMTH_COEF2_Q16 983 // 0.015
/* Min and max values for low end of pitch frequency range estimation */
#define VARIABLE_HP_MIN_FREQ_Q0 80
#define VARIABLE_HP_MAX_FREQ_Q0 150
/* Max absolute difference between log2 of pitch frequency and smoother state, to enter the smoother */
#define VARIABLE_HP_MAX_DELTA_FREQ_Q7 51 // 0.4 in Q7
/* Defines for CN generation */
#define CNG_BUF_MASK_MAX 255 /* 2^floor(log2(MAX_FRAME_LENGTH)) */
#define CNG_GAIN_SMTH_Q16 4634 /* 0.25^(1/4) */
#define CNG_NLSF_SMTH_Q16 16348 /* 0.25 */
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -37,9 +37,9 @@ void SKP_Silk_detect_SWB_input(
SKP_int nSamplesIn /* (I) length of input */
)
{
SKP_int HP_8_kHz_len, i;
SKP_int HP_8_kHz_len, i, shift;
SKP_int16 in_HP_8_kHz[ MAX_FRAME_LENGTH ];
SKP_int32 energy_32, shift;
SKP_int32 energy_32;
/* High pass filter with cutoff at 8 khz */
HP_8_kHz_len = SKP_min_int( nSamplesIn, MAX_FRAME_LENGTH );

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -38,7 +38,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/* Encoder functions */
/****************************************/
SKP_int SKP_Silk_SDK_Get_Encoder_Size( SKP_int *encSizeBytes )
SKP_int SKP_Silk_SDK_Get_Encoder_Size( SKP_int32 *encSizeBytes )
{
SKP_int ret = 0;
@ -57,16 +57,18 @@ SKP_int SKP_Silk_SDK_QueryEncoder(
)
{
SKP_Silk_encoder_state_FIX *psEnc;
SKP_int ret = 0;
SKP_int ret = 0;
psEnc = ( SKP_Silk_encoder_state_FIX* )encState;
encStatus->sampleRate = ( unsigned short )SKP_SMULBB( psEnc->sCmn.fs_kHz, 1000 ); /* convert kHz -> Hz */
encStatus->packetSize = ( unsigned short )SKP_SMULBB( psEnc->sCmn.fs_kHz, psEnc->sCmn.PacketSize_ms ); /* convert samples -> ms */
encStatus->bitRate = ( unsigned short )psEnc->sCmn.TargetRate_bps;
encStatus->packetLossPercentage = psEnc->sCmn.PacketLoss_perc;
encStatus->complexity = psEnc->sCmn.Complexity;
encStatus->API_sampleRate = psEnc->sCmn.API_fs_Hz;
encStatus->maxInternalSampleRate = SKP_SMULBB( psEnc->sCmn.maxInternal_fs_kHz, 1000 );
encStatus->packetSize = ( SKP_int )SKP_DIV32_16( psEnc->sCmn.API_fs_Hz * psEnc->sCmn.PacketSize_ms, 1000 ); /* convert samples -> ms */
encStatus->bitRate = psEnc->sCmn.TargetRate_bps;
encStatus->packetLossPercentage = psEnc->sCmn.PacketLoss_perc;
encStatus->complexity = psEnc->sCmn.Complexity;
encStatus->useInBandFEC = psEnc->sCmn.useInBandFEC;
encStatus->useDTX = psEnc->sCmn.useDTX;
return ret;
}
@ -89,7 +91,7 @@ SKP_int SKP_Silk_SDK_InitEncoder(
SKP_assert( 0 );
}
/* Read Control structure */
/* Read control structure */
if( ret += SKP_Silk_SDK_QueryEncoder( encState, encStatus ) ) {
SKP_assert( 0 );
}
@ -110,131 +112,101 @@ SKP_int SKP_Silk_SDK_Encode(
SKP_int16 *nBytesOut /* I/O: Number of bytes in outData (input: Max bytes) */
)
{
SKP_int API_fs_kHz, PacketSize_ms, PacketLoss_perc, UseInBandFec, UseDTX, ret = 0;
SKP_int nSamplesToBuffer, Complexity, input_ms, nSamplesFromInput = 0;
SKP_int32 TargetRate_bps;
SKP_int max_internal_fs_kHz, PacketSize_ms, PacketLoss_perc, UseInBandFEC, UseDTX, ret = 0;
SKP_int nSamplesToBuffer, Complexity, input_10ms, nSamplesFromInput = 0;
SKP_int32 TargetRate_bps, API_fs_Hz;
SKP_int16 MaxBytesOut;
SKP_Silk_encoder_state_FIX *psEnc = ( SKP_Silk_encoder_state_FIX* )encState;
SKP_assert( encControl != NULL );
/* Check sampling frequency first, to avoid divide by zero later */
if( ( encControl->sampleRate != 8000 ) && ( encControl->sampleRate != 12000 ) &&
( encControl->sampleRate != 16000 ) && ( encControl->sampleRate != 24000 ) ) {
if( ( ( encControl->API_sampleRate != 8000 ) &&
( encControl->API_sampleRate != 12000 ) &&
( encControl->API_sampleRate != 16000 ) &&
( encControl->API_sampleRate != 24000 ) &&
( encControl->API_sampleRate != 32000 ) &&
( encControl->API_sampleRate != 44100 ) &&
( encControl->API_sampleRate != 48000 ) ) ||
( ( encControl->maxInternalSampleRate != 8000 ) &&
( encControl->maxInternalSampleRate != 12000 ) &&
( encControl->maxInternalSampleRate != 16000 ) &&
( encControl->maxInternalSampleRate != 24000 ) ) ) {
ret = SKP_SILK_ENC_FS_NOT_SUPPORTED;
SKP_assert( 0 );
return( ret );
}
/* Set Encoder parameters from Control structure */
API_fs_kHz = SKP_DIV32_16( ( SKP_int )encControl->sampleRate, 1000 ); /* convert Hz -> kHz */
PacketSize_ms = SKP_DIV32_16( ( SKP_int )encControl->packetSize, API_fs_kHz ); /* convert samples -> ms */
TargetRate_bps = ( SKP_int32 )encControl->bitRate;
PacketLoss_perc = ( SKP_int )encControl->packetLossPercentage;
UseInBandFec = ( SKP_int )encControl->useInBandFEC;
Complexity = ( SKP_int )encControl->complexity;
UseDTX = ( SKP_int )encControl->useDTX;
/* Set encoder parameters from control structure */
API_fs_Hz = encControl->API_sampleRate;
max_internal_fs_kHz = (SKP_int)( encControl->maxInternalSampleRate >> 10 ) + 1; /* convert Hz -> kHz */
PacketSize_ms = SKP_DIV32( 1000 * (SKP_int)encControl->packetSize, API_fs_Hz );
TargetRate_bps = encControl->bitRate;
PacketLoss_perc = encControl->packetLossPercentage;
UseInBandFEC = encControl->useInBandFEC;
Complexity = encControl->complexity;
UseDTX = encControl->useDTX;
/* Only accept input lengths that are multiplum of 10 ms */
input_ms = SKP_DIV32_16( nSamplesIn, API_fs_kHz );
if( ( input_ms % 10) != 0 || nSamplesIn < 0 ) {
/* Save values in state */
psEnc->sCmn.API_fs_Hz = API_fs_Hz;
psEnc->sCmn.maxInternal_fs_kHz = max_internal_fs_kHz;
psEnc->sCmn.useInBandFEC = UseInBandFEC;
/* Only accept input lengths that are a multiple of 10 ms */
input_10ms = SKP_DIV32( 100 * nSamplesIn, API_fs_Hz );
if( input_10ms * API_fs_Hz != 100 * nSamplesIn || nSamplesIn < 0 ) {
ret = SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES;
SKP_assert( 0 );
return( ret );
}
TargetRate_bps = SKP_LIMIT( TargetRate_bps, MIN_TARGET_RATE_BPS, MAX_TARGET_RATE_BPS );
if( ( ret = SKP_Silk_control_encoder_FIX( psEnc, PacketSize_ms, TargetRate_bps,
PacketLoss_perc, UseDTX, Complexity) ) != 0 ) {
SKP_assert( 0 );
return( ret );
}
/* Make sure no more than one packet can be produced */
if( nSamplesIn > SKP_SMULBB( psEnc->sCmn.PacketSize_ms, API_fs_kHz ) ) {
if( 1000 * (SKP_int32)nSamplesIn > psEnc->sCmn.PacketSize_ms * API_fs_Hz ) {
ret = SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES;
SKP_assert( 0 );
return( ret );
}
if( ( ret = SKP_Silk_control_encoder_FIX( psEnc, API_fs_kHz, PacketSize_ms, TargetRate_bps,
PacketLoss_perc, UseInBandFec, UseDTX, input_ms, Complexity ) ) != 0 ) {
SKP_assert( 0 );
return( ret );
}
#if MAX_FS_KHZ > 16
/* Detect energy above 8 kHz */
if( encControl->sampleRate == 24000 && psEnc->sCmn.sSWBdetect.SWB_detected == 0 && psEnc->sCmn.sSWBdetect.WB_detected == 0 ) {
if( SKP_min( API_fs_Hz, 1000 * max_internal_fs_kHz ) == 24000 &&
psEnc->sCmn.sSWBdetect.SWB_detected == 0 &&
psEnc->sCmn.sSWBdetect.WB_detected == 0 ) {
SKP_Silk_detect_SWB_input( &psEnc->sCmn.sSWBdetect, samplesIn, ( SKP_int )nSamplesIn );
}
#endif
/* Input buffering/resampling and encoding */
MaxBytesOut = 0; /* return 0 output bytes if no encoder called */
while( 1 ) {
/* Resample/buffer */
nSamplesToBuffer = psEnc->sCmn.frame_length - psEnc->sCmn.inputBufIx;
if( encControl->sampleRate == SKP_SMULBB( psEnc->sCmn.fs_kHz, 1000 ) ) {
/* Same sample frequency - copy the data */
if( API_fs_Hz == SKP_SMULBB( 1000, psEnc->sCmn.fs_kHz ) ) {
nSamplesToBuffer = SKP_min_int( nSamplesToBuffer, nSamplesIn );
nSamplesFromInput = nSamplesToBuffer;
SKP_memcpy( &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], samplesIn, SKP_SMULBB( nSamplesToBuffer, sizeof( SKP_int16 ) ) );
} else if( encControl->sampleRate == 24000 && psEnc->sCmn.fs_kHz == 16 ) {
/* Resample the data from 24 kHz to 16 kHz */
nSamplesToBuffer = SKP_min_int( nSamplesToBuffer, SKP_SMULWB( SKP_LSHIFT( nSamplesIn, 1 ), 21846 ) ); // 21846 = ceil(2/3)*2^15
nSamplesFromInput = SKP_RSHIFT( SKP_SMULBB( nSamplesToBuffer, 3 ), 1 );
#if LOW_COMPLEXITY_ONLY
{
SKP_int16 scratch[ MAX_FRAME_LENGTH + SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ];
SKP_assert( nSamplesFromInput <= MAX_FRAME_LENGTH );
SKP_Silk_resample_2_3_coarse( &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], psEnc->sCmn.resample24To16state,
samplesIn, nSamplesFromInput, scratch );
}
#else
SKP_Silk_resample_2_3( &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], psEnc->sCmn.resample24To16state,
samplesIn, nSamplesFromInput );
#endif
} else if( encControl->sampleRate == 24000 && psEnc->sCmn.fs_kHz == 12 ) {
SKP_int32 scratch[ 3 * MAX_FRAME_LENGTH ];
/* Resample the data from 24 kHz to 12 kHz */
nSamplesToBuffer = SKP_min_int( nSamplesToBuffer, SKP_RSHIFT( nSamplesIn, 1 ) );
nSamplesFromInput = SKP_LSHIFT16( nSamplesToBuffer, 1 );
SKP_Silk_resample_1_2_coarse( samplesIn, psEnc->sCmn.resample24To12state,
&psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], scratch, nSamplesToBuffer );
} else if( encControl->sampleRate == 24000 && psEnc->sCmn.fs_kHz == 8 ) {
/* Resample the data from 24 kHz to 8 kHz */
nSamplesToBuffer = SKP_min_int( nSamplesToBuffer, SKP_DIV32_16( nSamplesIn, 3 ) );
nSamplesFromInput = SKP_SMULBB( nSamplesToBuffer, 3 );
SKP_Silk_resample_1_3( &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], psEnc->sCmn.resample24To8state,
samplesIn, nSamplesFromInput);
} else if( encControl->sampleRate == 16000 && psEnc->sCmn.fs_kHz == 12 ) {
/* Resample the data from 16 kHz to 12 kHz */
nSamplesToBuffer = SKP_min_int( nSamplesToBuffer, SKP_RSHIFT( SKP_SMULBB( nSamplesIn, 3 ), 2 ) );
nSamplesFromInput = SKP_SMULWB( SKP_LSHIFT16( nSamplesToBuffer, 2 ), 21846 ); // 21846 = ceil((1/3)*2^16)
SKP_Silk_resample_3_4( &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], psEnc->sCmn.resample16To12state,
samplesIn, nSamplesFromInput );
} else if( encControl->sampleRate == 16000 && psEnc->sCmn.fs_kHz == 8 ) {
SKP_int32 scratch[ 3 * MAX_FRAME_LENGTH ];
/* Resample the data from 16 kHz to 8 kHz */
nSamplesToBuffer = SKP_min_int( nSamplesToBuffer, SKP_RSHIFT( nSamplesIn, 1 ) );
nSamplesFromInput = SKP_LSHIFT16( nSamplesToBuffer, 1 );
SKP_Silk_resample_1_2_coarse( samplesIn, psEnc->sCmn.resample16To8state,
&psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], scratch, nSamplesToBuffer );
} else if( encControl->sampleRate == 12000 && psEnc->sCmn.fs_kHz == 8 ) {
/* Resample the data from 12 kHz to 8 kHz */
nSamplesToBuffer = SKP_min_int( nSamplesToBuffer, SKP_SMULWB( SKP_LSHIFT( nSamplesIn, 1 ), 21846 ) );
nSamplesFromInput = SKP_RSHIFT( SKP_SMULBB( nSamplesToBuffer, 3 ), 1 );
#if LOW_COMPLEXITY_ONLY
{
SKP_int16 scratch[ MAX_FRAME_LENGTH + SigProc_Resample_2_3_coarse_NUM_FIR_COEFS - 1 ];
SKP_assert( nSamplesFromInput <= MAX_FRAME_LENGTH );
SKP_Silk_resample_2_3_coarse( &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], psEnc->sCmn.resample12To8state,
samplesIn, nSamplesFromInput, scratch );
}
#else
SKP_Silk_resample_2_3( &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], psEnc->sCmn.resample12To8state,
samplesIn, nSamplesFromInput );
#endif
}
samplesIn += nSamplesFromInput;
nSamplesIn -= nSamplesFromInput;
/* 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 );
nSamplesFromInput = SKP_DIV32_16( nSamplesToBuffer * 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 );
}
samplesIn += nSamplesFromInput;
nSamplesIn -= nSamplesFromInput;
psEnc->sCmn.inputBufIx += nSamplesToBuffer;
/* Silk encoder */
if( psEnc->sCmn.inputBufIx >= psEnc->sCmn.frame_length ) {
SKP_assert( psEnc->sCmn.inputBufIx == psEnc->sCmn.frame_length );
/* Enough data in input buffer, so encode */
if( MaxBytesOut == 0 ) {
/* No payload obtained so far */
@ -251,6 +223,11 @@ SKP_int SKP_Silk_SDK_Encode(
SKP_assert( *nBytesOut == 0 );
}
psEnc->sCmn.inputBufIx = 0;
psEnc->sCmn.controlled_since_last_payload = 0;
if( nSamplesIn == 0 ) {
break;
}
} else {
break;
}
@ -258,7 +235,7 @@ SKP_int SKP_Silk_SDK_Encode(
*nBytesOut = MaxBytesOut;
if( psEnc->sCmn.useDTX && psEnc->sCmn.inDTX ) {
/* Dtx simulation */
/* DTX simulation */
*nBytesOut = 0;
}
@ -266,3 +243,4 @@ SKP_int SKP_Silk_SDK_Encode(
return ret;
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -26,6 +26,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
#include "SKP_Silk_main_FIX.h"
#include "SKP_Silk_tuning_parameters.h"
/****************/
/* Encode frame */
/****************/
@ -38,22 +40,19 @@ SKP_int SKP_Silk_encode_frame_FIX(
)
{
SKP_Silk_encoder_control_FIX sEncCtrl;
SKP_int i, nBytes, ret = 0;
SKP_int nBytes, ret = 0;
SKP_int16 *x_frame, *res_pitch_frame;
SKP_int16 xfw[ MAX_FRAME_LENGTH ];
SKP_int16 pIn_HP[ MAX_FRAME_LENGTH ];
SKP_int16 res_pitch[ 2 * MAX_FRAME_LENGTH + LA_PITCH_MAX ];
SKP_int LBRR_idx, frame_terminator, SNR_dB_Q7;
const SKP_uint16 *FrameTermination_CDF;
/* Low bitrate redundancy parameters */
SKP_uint8 LBRRpayload[ MAX_ARITHM_BYTES ];
SKP_int16 nBytesLBRR;
//SKP_int32 Seed[ MAX_LAYERS ];
sEncCtrl.sCmn.Seed = psEnc->sCmn.frameCounter++ & 3;
/**************************************************************/
/* Setup Input Pointers, and insert frame in input buffer */
/*************************************************************/
@ -74,14 +73,14 @@ SKP_int SKP_Silk_encode_frame_FIX(
/* Variable high-pass filter */
SKP_Silk_HP_variable_cutoff_FIX( psEnc, &sEncCtrl, pIn_HP, pIn );
#else
SKP_memcpy( pIn_HP, pIn,psEnc->sCmn.frame_length * sizeof( SKP_int16 ) );
SKP_memcpy( pIn_HP, pIn, psEnc->sCmn.frame_length * sizeof( SKP_int16 ) );
#endif
#if SWITCH_TRANSITION_FILTERING
/* Ensure smooth bandwidth transitions */
SKP_Silk_LP_variable_cutoff( &psEnc->sCmn.sLP, x_frame + psEnc->sCmn.la_shape, pIn_HP, psEnc->sCmn.frame_length );
SKP_Silk_LP_variable_cutoff( &psEnc->sCmn.sLP, x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, pIn_HP, psEnc->sCmn.frame_length );
#else
SKP_memcpy( x_frame + psEnc->sCmn.la_shape, pIn_HP,psEnc->sCmn.frame_length * sizeof( SKP_int16 ) );
SKP_memcpy( x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, pIn_HP,psEnc->sCmn.frame_length * sizeof( SKP_int16 ) );
#endif
/*****************************************/
@ -92,14 +91,13 @@ SKP_int SKP_Silk_encode_frame_FIX(
/************************/
/* Noise shape analysis */
/************************/
SKP_Silk_noise_shape_analysis_FIX( psEnc, &sEncCtrl, res_pitch_frame, x_frame );
SKP_Silk_noise_shape_analysis_FIX( psEnc, &sEncCtrl, res_pitch_frame, x_frame );
/*****************************************/
/* Prefiltering for noise shaper */
/*****************************************/
SKP_Silk_prefilter_FIX( psEnc, &sEncCtrl, xfw, x_frame );
/***************************************************/
/* Find linear prediction coefficients (LPC + LTP) */
/***************************************************/
@ -109,10 +107,8 @@ SKP_int SKP_Silk_encode_frame_FIX(
/* Process gains */
/****************************************/
SKP_Silk_process_gains_FIX( psEnc, &sEncCtrl );
psEnc->sCmn.sigtype[ psEnc->sCmn.nFramesInPayloadBuf ] = sEncCtrl.sCmn.sigtype;
psEnc->sCmn.QuantOffsetType[ psEnc->sCmn.nFramesInPayloadBuf ] = sEncCtrl.sCmn.QuantOffsetType;
/****************************************/
/* Low Bitrate Redundant Encoding */
/****************************************/
@ -122,16 +118,24 @@ SKP_int SKP_Silk_encode_frame_FIX(
/*****************************************/
/* Noise shaping quantization */
/*****************************************/
psEnc->NoiseShapingQuantizer( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sNSQ, xfw,
&psEnc->sCmn.q[ psEnc->sCmn.nFramesInPayloadBuf *psEnc->sCmn.frame_length ], sEncCtrl.sCmn.NLSFInterpCoef_Q2,
sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEncCtrl.AR2_Q13, sEncCtrl.HarmShapeGain_Q14,
sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gains_Q16, sEncCtrl.Lambda_Q10,
sEncCtrl.LTP_scale_Q14 );
if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) {
SKP_Silk_NSQ_del_dec( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sNSQ, xfw,
psEnc->sCmn.q, sEncCtrl.sCmn.NLSFInterpCoef_Q2,
sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEncCtrl.AR2_Q13, sEncCtrl.HarmShapeGain_Q14,
sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gains_Q16, sEncCtrl.Lambda_Q10,
sEncCtrl.LTP_scale_Q14 );
} else {
SKP_Silk_NSQ( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sNSQ, xfw,
psEnc->sCmn.q, sEncCtrl.sCmn.NLSFInterpCoef_Q2,
sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEncCtrl.AR2_Q13, sEncCtrl.HarmShapeGain_Q14,
sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gains_Q16, sEncCtrl.Lambda_Q10,
sEncCtrl.LTP_scale_Q14 );
}
/**************************************************/
/* Convert speech activity into VAD and DTX flags */
/**************************************************/
if( psEnc->speech_activity_Q8 < SPEECH_ACTIVITY_DTX_THRES_Q8 ) {
if( psEnc->speech_activity_Q8 < SKP_FIX_CONST( SPEECH_ACTIVITY_DTX_THRES, 8 ) ) {
psEnc->sCmn.vadFlag = NO_VOICE_ACTIVITY;
psEnc->sCmn.noSpeechCounter++;
if( psEnc->sCmn.noSpeechCounter > NO_SPEECH_FRAMES_BEFORE_DTX ) {
@ -148,7 +152,7 @@ SKP_int SKP_Silk_encode_frame_FIX(
}
/****************************************/
/* Initialize arithmetic coder */
/* Initialize range coder */
/****************************************/
if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) {
SKP_Silk_range_enc_init( &psEnc->sCmn.sRC );
@ -158,35 +162,30 @@ SKP_int SKP_Silk_encode_frame_FIX(
/****************************************/
/* Encode Parameters */
/****************************************/
if( psEnc->sCmn.bitstream_v == BIT_STREAM_V4 ) {
SKP_Silk_encode_parameters_v4( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sCmn.sRC );
FrameTermination_CDF = SKP_Silk_FrameTermination_v4_CDF;
} else {
SKP_Silk_encode_parameters( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sCmn.sRC,
&psEnc->sCmn.q[ psEnc->sCmn.nFramesInPayloadBuf *psEnc->sCmn.frame_length ] );
FrameTermination_CDF = SKP_Silk_FrameTermination_CDF;
}
SKP_Silk_encode_parameters( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sCmn.sRC, psEnc->sCmn.q );
FrameTermination_CDF = SKP_Silk_FrameTermination_CDF;
/****************************************/
/* Update Buffers and State */
/****************************************/
/* Update Input buffer */
SKP_memmove( psEnc->x_buf, &psEnc->x_buf[ psEnc->sCmn.frame_length ], ( psEnc->sCmn.frame_length + psEnc->sCmn.la_shape ) * sizeof( SKP_int16 ) );
/* Update input buffer */
SKP_memmove( psEnc->x_buf, &psEnc->x_buf[ psEnc->sCmn.frame_length ],
( psEnc->sCmn.frame_length + LA_SHAPE_MS * psEnc->sCmn.fs_kHz ) * sizeof( SKP_int16 ) );
/* parameters needed for next frame */
/* Parameters needed for next frame */
psEnc->sCmn.prev_sigtype = sEncCtrl.sCmn.sigtype;
psEnc->sCmn.prevLag = sEncCtrl.sCmn.pitchL[ NB_SUBFR - 1];
psEnc->sCmn.first_frame_after_reset = 0;
if( psEnc->sCmn.sRC.error ) {
/* encoder returned error: clear payload buffer */
/* Encoder returned error: clear payload buffer */
psEnc->sCmn.nFramesInPayloadBuf = 0;
} else {
psEnc->sCmn.nFramesInPayloadBuf++;
}
/****************************************/
/* finalize payload and copy to output */
/* Finalize payload and copy to output */
/****************************************/
if( psEnc->sCmn.nFramesInPayloadBuf * FRAME_LENGTH_MS >= psEnc->sCmn.PacketSize_ms ) {
@ -201,20 +200,14 @@ SKP_int SKP_Silk_encode_frame_FIX(
frame_terminator = SKP_SILK_LBRR_VER2;
LBRR_idx = psEnc->sCmn.oldest_LBRR_idx;
}
/* Add the frame termination info to stream */
SKP_Silk_range_encoder( &psEnc->sCmn.sRC, frame_terminator, FrameTermination_CDF );
if( psEnc->sCmn.bitstream_v == BIT_STREAM_V4 ) {
/* Code excitation signal */
for( i = 0; i <psEnc->sCmn.nFramesInPayloadBuf; i++ ) {
SKP_Silk_encode_pulses( &psEnc->sCmn.sRC, psEnc->sCmn.sigtype[ i ],psEnc->sCmn.QuantOffsetType[ i ],
&psEnc->sCmn.q[ i * psEnc->sCmn.frame_length],psEnc->sCmn.frame_length );
}
}
/* payload length so far */
/* Payload length so far */
SKP_Silk_range_coder_get_length( &psEnc->sCmn.sRC, &nBytes );
/* check that there is enough space in external output buffer, and move data */
/* Check that there is enough space in external output buffer, and move data */
if( *pnBytesOut >= nBytes ) {
SKP_Silk_range_enc_wrap_up( &psEnc->sCmn.sRC );
SKP_memcpy( pCode, psEnc->sCmn.sRC.buffer, nBytes * sizeof( SKP_uint8 ) );
@ -227,42 +220,37 @@ SKP_int SKP_Silk_encode_frame_FIX(
psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes * sizeof( SKP_uint8 ) );
nBytes += psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes;
}
*pnBytesOut = nBytes;
/* Update FEC buffer */
SKP_memcpy( psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].payload, LBRRpayload,
nBytesLBRR * sizeof( SKP_uint8 ) );
psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].nBytes = nBytesLBRR;
/* This line tells describes how FEC should be used */
/* The line below describes how FEC should be used */
psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].usage = sEncCtrl.sCmn.LBRR_usage;
psEnc->sCmn.oldest_LBRR_idx = ( psEnc->sCmn.oldest_LBRR_idx + 1 ) & LBRR_IDX_MASK;
/* Reset number of frames in payload buffer */
psEnc->sCmn.nFramesInPayloadBuf = 0;
} else {
/* Not enough space: Payload will be discarded */
*pnBytesOut = 0;
nBytes = 0;
psEnc->sCmn.nFramesInPayloadBuf = 0;
ret = SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT;
}
/* Reset the number of frames in payload buffer */
psEnc->sCmn.nFramesInPayloadBuf = 0;
} else {
/* no payload for you this time */
/* No payload this time */
*pnBytesOut = 0;
/* Encode that more frames follows */
frame_terminator = SKP_SILK_MORE_FRAMES;
SKP_Silk_range_encoder( &psEnc->sCmn.sRC, frame_terminator, FrameTermination_CDF );
/* payload length so far */
/* Payload length so far */
SKP_Silk_range_coder_get_length( &psEnc->sCmn.sRC, &nBytes );
if( psEnc->sCmn.bitstream_v == BIT_STREAM_V4 ) {
/* Take into account the q signal that isnt in the bitstream yet */
nBytes += SKP_Silk_pulses_to_bytes( &psEnc->sCmn,
&psEnc->sCmn.q[ (psEnc->sCmn.nFramesInPayloadBuf - 1) * psEnc->sCmn.frame_length ] );
}
}
/* Check for arithmetic coder errors */
@ -270,16 +258,16 @@ SKP_int SKP_Silk_encode_frame_FIX(
ret = SKP_SILK_ENC_INTERNAL_ERROR;
}
/* simulate number of ms buffered in channel because of exceeding TargetRate */
/* Simulate number of ms buffered in channel because of exceeding TargetRate */
SKP_assert( ( 8 * 1000 * ( (SKP_int64)nBytes - (SKP_int64)psEnc->sCmn.nBytesInPayloadBuf ) ) ==
SKP_SAT32( 8 * 1000 * ( (SKP_int64)nBytes - (SKP_int64)psEnc->sCmn.nBytesInPayloadBuf ) ) );
SKP_assert( psEnc->sCmn.TargetRate_bps > 0 );
psEnc->BufferedInChannel_ms += SKP_DIV32( 8 * 1000 * ( nBytes -psEnc->sCmn.nBytesInPayloadBuf ),psEnc->sCmn.TargetRate_bps );
psEnc->BufferedInChannel_ms += SKP_DIV32( 8 * 1000 * ( nBytes - psEnc->sCmn.nBytesInPayloadBuf ), psEnc->sCmn.TargetRate_bps );
psEnc->BufferedInChannel_ms -= FRAME_LENGTH_MS;
psEnc->BufferedInChannel_ms = SKP_LIMIT( psEnc->BufferedInChannel_ms, 0, 100 );
psEnc->BufferedInChannel_ms = SKP_LIMIT_int( psEnc->BufferedInChannel_ms, 0, 100 );
psEnc->sCmn.nBytesInPayloadBuf = nBytes;
if( psEnc->speech_activity_Q8 > WB_DETECT_ACTIVE_SPEECH_LEVEL_THRES_Q8 ) {
if( psEnc->speech_activity_Q8 > SKP_FIX_CONST( WB_DETECT_ACTIVE_SPEECH_LEVEL_THRES, 8 ) ) {
psEnc->sCmn.sSWBdetect.ActiveSpeech_ms = SKP_ADD_POS_SAT32( psEnc->sCmn.sSWBdetect.ActiveSpeech_ms, FRAME_LENGTH_MS );
}
@ -296,19 +284,19 @@ void SKP_Silk_LBRR_encode_FIX(
SKP_int16 xfw[] /* I Input signal */
)
{
SKP_int i, TempGainsIndices[ NB_SUBFR ], frame_terminator;
SKP_int TempGainsIndices[ NB_SUBFR ], frame_terminator;
SKP_int nBytes, nFramesInPayloadBuf;
SKP_int32 TempGains_Q16[ NB_SUBFR ];
SKP_int typeOffset, LTP_scaleIndex, Rate_only_parameters = 0;
/*******************************************/
/* Control use of inband LBRR */
/*******************************************/
SKP_Silk_LBRR_ctrl_FIX( psEnc, psEncCtrl );
SKP_Silk_LBRR_ctrl_FIX( psEnc, &psEncCtrl->sCmn );
if( psEnc->sCmn.LBRR_enabled ) {
/* Save original Gains */
/* Save original gains */
SKP_memcpy( TempGainsIndices, psEncCtrl->sCmn.GainsIndices, NB_SUBFR * sizeof( SKP_int ) );
SKP_memcpy( TempGains_Q16, psEncCtrl->Gains_Q16, NB_SUBFR * sizeof( SKP_int32 ) );
SKP_memcpy( TempGains_Q16, psEncCtrl->Gains_Q16, NB_SUBFR * sizeof( SKP_int32 ) );
typeOffset = psEnc->sCmn.typeOffsetPrev; // Temp save as cannot be overwritten
LTP_scaleIndex = psEncCtrl->sCmn.LTP_scaleIndex;
@ -328,29 +316,35 @@ void SKP_Silk_LBRR_encode_FIX(
if( psEnc->sCmn.Complexity > 0 && psEnc->sCmn.TargetRate_bps > Rate_only_parameters ) {
if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) {
/* First frame in packet copy Everything */
/* First frame in packet; copy everything */
SKP_memcpy( &psEnc->sNSQ_LBRR, &psEnc->sNSQ, sizeof( SKP_Silk_nsq_state ) );
psEnc->sCmn.LBRRprevLastGainIndex = psEnc->sShape.LastGainIndex;
/* Increase Gains to get target LBRR rate */
psEncCtrl->sCmn.GainsIndices[ 0 ] = psEncCtrl->sCmn.GainsIndices[ 0 ] + psEnc->sCmn.LBRR_GainIncreases;
psEncCtrl->sCmn.GainsIndices[ 0 ] = SKP_LIMIT( psEncCtrl->sCmn.GainsIndices[ 0 ], 0, N_LEVELS_QGAIN - 1 );
psEncCtrl->sCmn.GainsIndices[ 0 ] = SKP_LIMIT_int( psEncCtrl->sCmn.GainsIndices[ 0 ], 0, N_LEVELS_QGAIN - 1 );
}
/* Decode to get Gains in sync with decoder */
/* Decode to get gains in sync with decoder */
/* Overwrite unquantized gains with quantized gains */
SKP_Silk_gains_dequant( psEncCtrl->Gains_Q16, psEncCtrl->sCmn.GainsIndices,
&psEnc->sCmn.LBRRprevLastGainIndex, psEnc->sCmn.nFramesInPayloadBuf );
/*****************************************/
/* Noise shaping quantization */
/*****************************************/
psEnc->NoiseShapingQuantizer( &psEnc->sCmn, &psEncCtrl->sCmn,
&psEnc->sNSQ_LBRR, xfw, &psEnc->sCmn.q_LBRR[ psEnc->sCmn.nFramesInPayloadBuf * psEnc->sCmn.frame_length ],
psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEncCtrl->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14,
psEncCtrl->AR2_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt_Q14, psEncCtrl->LF_shp_Q14,
psEncCtrl->Gains_Q16, psEncCtrl->Lambda_Q10, psEncCtrl->LTP_scale_Q14 );
if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) {
SKP_Silk_NSQ_del_dec( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sNSQ_LBRR, xfw, psEnc->sCmn.q_LBRR,
psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEncCtrl->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14,
psEncCtrl->AR2_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt_Q14, psEncCtrl->LF_shp_Q14,
psEncCtrl->Gains_Q16, psEncCtrl->Lambda_Q10, psEncCtrl->LTP_scale_Q14 );
} else {
SKP_Silk_NSQ( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sNSQ_LBRR, xfw, psEnc->sCmn.q_LBRR,
psEncCtrl->sCmn.NLSFInterpCoef_Q2, psEncCtrl->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14,
psEncCtrl->AR2_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt_Q14, psEncCtrl->LF_shp_Q14,
psEncCtrl->Gains_Q16, psEncCtrl->Lambda_Q10, psEncCtrl->LTP_scale_Q14 );
}
} else {
SKP_memset( &psEnc->sCmn.q_LBRR[ psEnc->sCmn.nFramesInPayloadBuf *psEnc->sCmn.frame_length ], 0,
psEnc->sCmn.frame_length * sizeof( SKP_int ) );
SKP_memset( psEnc->sCmn.q_LBRR, 0, psEnc->sCmn.frame_length * sizeof( SKP_int8 ) );
psEncCtrl->sCmn.LTP_scaleIndex = 0;
}
/****************************************/
@ -364,22 +358,18 @@ void SKP_Silk_LBRR_encode_FIX(
/****************************************/
/* Encode Parameters */
/****************************************/
if( psEnc->sCmn.bitstream_v == BIT_STREAM_V4 ) {
SKP_Silk_encode_parameters_v4( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sCmn.sRC_LBRR );
} else {
SKP_Silk_encode_parameters( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sCmn.sRC_LBRR,
&psEnc->sCmn.q_LBRR[ psEnc->sCmn.nFramesInPayloadBuf * psEnc->sCmn.frame_length] );
}
SKP_Silk_encode_parameters( &psEnc->sCmn, &psEncCtrl->sCmn,
&psEnc->sCmn.sRC_LBRR, psEnc->sCmn.q_LBRR );
if( psEnc->sCmn.sRC_LBRR.error ) {
/* encoder returned error: clear payload buffer */
/* Encoder returned error: clear payload buffer */
nFramesInPayloadBuf = 0;
} else {
nFramesInPayloadBuf = psEnc->sCmn.nFramesInPayloadBuf + 1;
}
/****************************************/
/* finalize payload and copy to output */
/* Finalize payload and copy to output */
/****************************************/
if( SKP_SMULBB( nFramesInPayloadBuf, FRAME_LENGTH_MS ) >= psEnc->sCmn.PacketSize_ms ) {
@ -388,32 +378,23 @@ void SKP_Silk_LBRR_encode_FIX(
/* Add the frame termination info to stream */
SKP_Silk_range_encoder( &psEnc->sCmn.sRC_LBRR, frame_terminator, SKP_Silk_FrameTermination_CDF );
if( psEnc->sCmn.bitstream_v == BIT_STREAM_V4 ) {
/*********************************************/
/* Encode quantization indices of excitation */
/*********************************************/
for( i = 0; i < nFramesInPayloadBuf; i++ ) {
SKP_Silk_encode_pulses( &psEnc->sCmn.sRC_LBRR, psEnc->sCmn.sigtype[ i ], psEnc->sCmn.QuantOffsetType[ i ],
&psEnc->sCmn.q_LBRR[ i * psEnc->sCmn.frame_length ], psEnc->sCmn.frame_length );
}
}
/* payload length so far */
/* Payload length so far */
SKP_Silk_range_coder_get_length( &psEnc->sCmn.sRC_LBRR, &nBytes );
/* check that there is enough space in external output buffer, and move data */
/* Check that there is enough space in external output buffer and move data */
if( *pnBytesOut >= nBytes ) {
SKP_Silk_range_enc_wrap_up( &psEnc->sCmn.sRC_LBRR );
SKP_memcpy( pCode, psEnc->sCmn.sRC_LBRR.buffer, nBytes * sizeof( SKP_uint8 ) );
*pnBytesOut = nBytes;
} else {
/* not enough space: payload will be discarded */
/* Not enough space: payload will be discarded */
*pnBytesOut = 0;
SKP_assert( 0 );
}
} else {
/* no payload for you this time */
/* No payload this time */
*pnBytesOut = 0;
/* Encode that more frames follows */
@ -423,7 +404,7 @@ void SKP_Silk_LBRR_encode_FIX(
/* Restore original Gains */
SKP_memcpy( psEncCtrl->sCmn.GainsIndices, TempGainsIndices, NB_SUBFR * sizeof( SKP_int ) );
SKP_memcpy( psEncCtrl->Gains_Q16, TempGains_Q16, NB_SUBFR * sizeof( SKP_int32 ) );
SKP_memcpy( psEncCtrl->Gains_Q16, TempGains_Q16, NB_SUBFR * sizeof( SKP_int32 ) );
/* Restore LTP scale index and typeoffset */
psEncCtrl->sCmn.LTP_scaleIndex = LTP_scaleIndex;

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -34,7 +34,7 @@ void SKP_Silk_encode_parameters(
SKP_Silk_encoder_state *psEncC, /* I/O Encoder state */
SKP_Silk_encoder_control *psEncCtrlC, /* I/O Encoder control */
SKP_Silk_range_coder_state *psRC, /* I/O Range encoder state */
const SKP_int *q /* I Quantization indices */
const SKP_int8 *q /* I Quantization indices */
)
{
SKP_int i, k, typeOffset;
@ -46,11 +46,6 @@ void SKP_Silk_encode_parameters(
/************************/
/* only done for first frame in packet */
if( psEncC->nFramesInPayloadBuf == 0 ) {
/* Initialize arithmetic coder */
SKP_Silk_range_enc_init( &psEncC->sRC );
psEncC->nBytesInPayloadBuf = 0;
/* get sampling rate index */
for( i = 0; i < 3; i++ ) {
if( SKP_Silk_SamplingRates_table[ i ] == psEncC->fs_kHz ) {

View File

@ -1,179 +0,0 @@
/***********************************************************************
Copyright (c) 2006-2010, 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"
/*******************************************/
/* Encode parameters to create the payload */
/*******************************************/
void SKP_Silk_encode_parameters_v4(
SKP_Silk_encoder_state *psEncC, /* I/O Encoder state */
SKP_Silk_encoder_control *psEncCtrlC, /* I/O Encoder control */
SKP_Silk_range_coder_state *psRC /* I/O Range encoder state */
)
{
SKP_int i, k, typeOffset;
SKP_int encode_absolute_lagIndex, delta_lagIndex;
const SKP_Silk_NLSF_CB_struct *psNLSF_CB;
/************************/
/* Encode sampling rate */
/************************/
/* only done for first frame in packet */
if( psEncC->nFramesInPayloadBuf == 0 ) {
/* Initialize arithmetic coder */
SKP_Silk_range_enc_init( &psEncC->sRC );
psEncC->nBytesInPayloadBuf = 0;
/* get sampling rate index */
for( i = 0; i < 3; i++ ) {
if( SKP_Silk_SamplingRates_table[ i ] == psEncC->fs_kHz ) {
break;
}
}
SKP_Silk_range_encoder( psRC, i, SKP_Silk_SamplingRates_CDF );
}
/*********************************************/
/* Encode VAD flag */
/*********************************************/
SKP_Silk_range_encoder( psRC, psEncC->vadFlag, SKP_Silk_vadflag_CDF );
/*******************************************/
/* Encode signal type and quantizer offset */
/*******************************************/
typeOffset = 2 * psEncCtrlC->sigtype + psEncCtrlC->QuantOffsetType;
if( psEncC->nFramesInPayloadBuf == 0 ) {
/* first frame in packet: independent coding */
SKP_Silk_range_encoder( psRC, typeOffset, SKP_Silk_type_offset_CDF );
} else {
/* condidtional coding */
SKP_Silk_range_encoder( psRC, typeOffset, SKP_Silk_type_offset_joint_CDF[ psEncC->typeOffsetPrev ] );
}
psEncC->typeOffsetPrev = typeOffset;
/****************/
/* Encode gains */
/****************/
/* first subframe */
if( psEncC->nFramesInPayloadBuf == 0 ) {
/* first frame in packet: independent coding */
SKP_Silk_range_encoder( psRC, psEncCtrlC->GainsIndices[ 0 ], SKP_Silk_gain_CDF[ psEncCtrlC->sigtype ] );
} else {
/* condidtional coding */
SKP_Silk_range_encoder( psRC, psEncCtrlC->GainsIndices[ 0 ], SKP_Silk_delta_gain_CDF );
}
/* remaining subframes */
for( i = 1; i < NB_SUBFR; i++ ) {
SKP_Silk_range_encoder( psRC, psEncCtrlC->GainsIndices[ i ], SKP_Silk_delta_gain_CDF );
}
/****************/
/* Encode NLSFs */
/****************/
/* Range encoding of the NLSF path */
psNLSF_CB = psEncC->psNLSF_CB[ psEncCtrlC->sigtype ];
SKP_Silk_range_encoder_multi( psRC, psEncCtrlC->NLSFIndices, psNLSF_CB->StartPtr, psNLSF_CB->nStages );
/* Encode NLSF interpolation factor */
SKP_assert( psEncC->useInterpolatedNLSFs == 1 || psEncCtrlC->NLSFInterpCoef_Q2 == ( 1 << 2 ) );
SKP_Silk_range_encoder( psRC, psEncCtrlC->NLSFInterpCoef_Q2, SKP_Silk_NLSF_interpolation_factor_CDF );
if( psEncCtrlC->sigtype == SIG_TYPE_VOICED ) {
/*********************/
/* Encode pitch lags */
/*********************/
/* lag index */
encode_absolute_lagIndex = 1;
if( psEncC->nFramesInPayloadBuf > 0 && psEncC->prev_sigtype == SIG_TYPE_VOICED ) {
/* Delta Encoding */
delta_lagIndex = psEncCtrlC->lagIndex - psEncC->prev_lagIndex;
if( delta_lagIndex > MAX_DELTA_LAG ) {
delta_lagIndex = ( MAX_DELTA_LAG << 1 ) + 1;
} else if ( delta_lagIndex < -MAX_DELTA_LAG ) {
delta_lagIndex = ( MAX_DELTA_LAG << 1 ) + 1;
} else {
delta_lagIndex = delta_lagIndex + MAX_DELTA_LAG;
encode_absolute_lagIndex = 0; /* Only use delta */
}
SKP_Silk_range_encoder( psRC, delta_lagIndex, SKP_Silk_pitch_delta_CDF );
}
if( encode_absolute_lagIndex ) {
/* Absolute encoding */
if( psEncC->fs_kHz == 8 ) {
SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_NB_CDF );
} else if( psEncC->fs_kHz == 12 ) {
SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_MB_CDF );
} else if( psEncC->fs_kHz == 16 ) {
SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_WB_CDF );
} else {
SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_SWB_CDF );
}
}
psEncC->prev_lagIndex = psEncCtrlC->lagIndex;
/* countour index */
if( psEncC->fs_kHz == 8 ) {
/* Less codevectors used in 8 khz mode */
SKP_Silk_range_encoder( psRC, psEncCtrlC->contourIndex, SKP_Silk_pitch_contour_NB_CDF );
} else {
/* Joint for 12, 16, 24 khz */
SKP_Silk_range_encoder( psRC, psEncCtrlC->contourIndex, SKP_Silk_pitch_contour_CDF );
}
/********************/
/* Encode LTP gains */
/********************/
/* PERIndex value */
SKP_Silk_range_encoder( psRC, psEncCtrlC->PERIndex, SKP_Silk_LTP_per_index_CDF );
/* Codebook Indices */
for( k = 0; k < NB_SUBFR; k++ ) {
SKP_Silk_range_encoder( psRC, psEncCtrlC->LTPIndex[ k ], SKP_Silk_LTP_gain_CDF_ptrs[ psEncCtrlC->PERIndex ] );
}
/**********************/
/* Encode LTP scaling */
/**********************/
SKP_Silk_range_encoder( psRC, psEncCtrlC->LTP_scaleIndex, SKP_Silk_LTPscale_CDF );
}
/***************/
/* Encode seed */
/***************/
SKP_Silk_range_encoder( psRC, psEncCtrlC->Seed, SKP_Silk_Seed_CDF );
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -56,7 +56,7 @@ void SKP_Silk_encode_pulses(
SKP_Silk_range_coder_state *psRC, /* I/O Range coder state */
const SKP_int sigtype, /* I Sigtype */
const SKP_int QuantOffsetType,/* I QuantOffsetType */
const SKP_int q[], /* I quantization indices */
const SKP_int8 q[], /* I quantization indices */
const SKP_int frame_length /* I Frame length */
)
{
@ -64,10 +64,10 @@ void SKP_Silk_encode_pulses(
SKP_int32 abs_q, minSumBits_Q6, sumBits_Q6;
SKP_int abs_pulses[ MAX_FRAME_LENGTH ];
SKP_int sum_pulses[ MAX_NB_SHELL_BLOCKS ];
SKP_int nRshifts[ MAX_NB_SHELL_BLOCKS ];
SKP_int nRshifts[ MAX_NB_SHELL_BLOCKS ];
SKP_int pulses_comb[ 8 ];
SKP_int *abs_pulses_ptr;
const SKP_int *pulses_ptr;
const SKP_int8 *pulses_ptr;
const SKP_uint16 *cdf_ptr;
const SKP_int16 *nBits_ptr;
@ -177,7 +177,7 @@ void SKP_Silk_encode_pulses(
pulses_ptr = &q[ i * SHELL_CODEC_FRAME_LENGTH ];
nLS = nRshifts[ i ] - 1;
for( k = 0; k < SHELL_CODEC_FRAME_LENGTH; k++ ) {
abs_q = SKP_abs( pulses_ptr[ k ] );
abs_q = (SKP_int8)SKP_abs( pulses_ptr[ k ] );
for( j = nLS; j > 0; j-- ) {
bit = SKP_RSHIFT( abs_q, j ) & 1;
SKP_Silk_range_encoder( psRC, bit, SKP_Silk_lsb_CDF );

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -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(
@ -40,7 +41,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;
@ -57,13 +57,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 ) {
/* Optimal solution for last 10 ms */
SKP_Silk_burg_modified( &res_tmp_nrg, &res_tmp_nrg_Q, a_tmp_Q16, x + ( NB_SUBFR >> 1 ) * subfr_length,
subfr_length, ( NB_SUBFR >> 1 ), FIND_LPC_COND_FAC_Q32, LPC_order );
subfr_length, ( 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 */

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -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 ],
@ -71,22 +75,27 @@ 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 = 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]) */
@ -99,12 +108,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;
@ -132,7 +141,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;
@ -204,8 +213,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;
@ -215,7 +224,7 @@ void SKP_Silk_find_LTP_FIX(
}
temp32 = SKP_DIV32( g_Q26, temp32 ); /* Q14->Q12 */
for( i = 0; i < LTP_ORDER; i++ ) {
b_Q14_ptr[ i ] = SKP_LIMIT( ( SKP_int32 )b_Q14_ptr[ i ] + SKP_SMULWB( SKP_LSHIFT_SAT32( temp32, 4 ), delta_b_Q14[ i ] ), -16000, 28000 );
b_Q14_ptr[ i ] = SKP_LIMIT_32( ( SKP_int32 )b_Q14_ptr[ i ] + SKP_SMULWB( SKP_LSHIFT_SAT32( temp32, 4 ), delta_b_Q14[ i ] ), -16000, 28000 );
}
b_Q14_ptr += LTP_ORDER;
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -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"
/* Find pitch lags */
void SKP_Silk_find_pitch_lags_FIX(
@ -36,19 +37,18 @@ void SKP_Silk_find_pitch_lags_FIX(
)
{
SKP_Silk_predict_state_FIX *psPredSt = &psEnc->sPred;
SKP_int buf_len, i;
SKP_int32 scale;
SKP_int32 thrhld_Q15;
SKP_int buf_len, i, scale;
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[ FIND_PITCH_LPC_ORDER_MAX + 1 ];
SKP_int16 rc_Q15[ FIND_PITCH_LPC_ORDER_MAX ];
SKP_int32 A_Q24[ FIND_PITCH_LPC_ORDER_MAX ];
SKP_int32 FiltState[ FIND_PITCH_LPC_ORDER_MAX ];
SKP_int16 A_Q12[ FIND_PITCH_LPC_ORDER_MAX ];
SKP_int32 auto_corr[ MAX_FIND_PITCH_LPC_ORDER + 1 ];
SKP_int16 rc_Q15[ MAX_FIND_PITCH_LPC_ORDER ];
SKP_int32 A_Q24[ MAX_FIND_PITCH_LPC_ORDER ];
SKP_int32 FiltState[ MAX_FIND_PITCH_LPC_ORDER ];
SKP_int16 A_Q12[ MAX_FIND_PITCH_LPC_ORDER ];
/******************************************/
/* Setup buffer lengths etc based of Fs. */
/* Setup buffer lengths etc based on Fs */
/******************************************/
buf_len = SKP_ADD_LSHIFT( psEnc->sCmn.la_pitch, psEnc->sCmn.frame_length, 1 );
@ -58,7 +58,7 @@ void SKP_Silk_find_pitch_lags_FIX(
x_buf = x - psEnc->sCmn.frame_length;
/*************************************/
/* Estimate LPC AR coeficients */
/* Estimate LPC AR coefficients */
/*************************************/
/* Calculate windowed signal */
@ -66,7 +66,7 @@ void SKP_Silk_find_pitch_lags_FIX(
/* First LA_LTP samples */
x_buf_ptr = x_buf + buf_len - psPredSt->pitch_LPC_win_length;
Wsig_ptr = Wsig;
SKP_Silk_apply_sine_window( Wsig_ptr, x_buf_ptr, 1, psEnc->sCmn.la_pitch );
SKP_Silk_apply_sine_window_new( Wsig_ptr, x_buf_ptr, 1, psEnc->sCmn.la_pitch );
/* Middle un - windowed samples */
Wsig_ptr += psEnc->sCmn.la_pitch;
@ -76,18 +76,21 @@ void SKP_Silk_find_pitch_lags_FIX(
/* 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 );
SKP_Silk_apply_sine_window( Wsig_ptr, x_buf_ptr, 2, psEnc->sCmn.la_pitch );
SKP_Silk_apply_sine_window_new( 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 );
/* 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,27 +99,27 @@ 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 */
/*****************************************/
SKP_memset( FiltState, 0, psEnc->sCmn.pitchEstimationLPCOrder * sizeof( SKP_int16 ) );
SKP_memset( FiltState, 0, psEnc->sCmn.pitchEstimationLPCOrder * sizeof( SKP_int32 ) ); /* Not really necessary, but Valgrind will complain otherwise */
SKP_Silk_MA_Prediction( x_buf, A_Q12, FiltState, res, buf_len, psEnc->sCmn.pitchEstimationLPCOrder );
SKP_memset( res, 0, psEnc->sCmn.pitchEstimationLPCOrder * sizeof( SKP_int16 ) );
/* Threshold for pitch estimator */
thrhld_Q15 = ( 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 );
thrhld_Q15 = SKP_SAT16( thrhld_Q15 );
/*****************************************/
/* Call Pitch estimator */
/* Call pitch estimator */
/*****************************************/
psEncCtrl->sCmn.sigtype = SKP_Silk_pitch_analysis_core( res, psEncCtrl->sCmn.pitchL, &psEncCtrl->sCmn.lagIndex,
&psEncCtrl->sCmn.contourIndex, &psEnc->LTPCorr_Q15, psEnc->sCmn.prevLag, psEnc->pitchEstimationThreshold_Q16,
( SKP_int16 )thrhld_Q15, psEnc->sCmn.fs_kHz, psEnc->sCmn.pitchEstimationComplexity );
&psEncCtrl->sCmn.contourIndex, &psEnc->LTPCorr_Q15, psEnc->sCmn.prevLag, psEnc->sCmn.pitchEstimationThreshold_Q16,
( SKP_int16 )thrhld_Q15, psEnc->sCmn.fs_kHz, psEnc->sCmn.pitchEstimationComplexity, SKP_FALSE );
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -28,9 +28,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SKP_Silk_main_FIX.h"
#define VARQ 1 // EXPERIMENTAL
#define Qx 0 // EXPERIMENTAL
void SKP_Silk_find_pred_coefs_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O encoder state */
SKP_Silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */
@ -39,15 +36,11 @@ void SKP_Silk_find_pred_coefs_FIX(
{
SKP_int i;
SKP_int32 WLTP[ NB_SUBFR * LTP_ORDER * LTP_ORDER ];
SKP_int32 invGains_Q16[ NB_SUBFR ], local_gains_Qx[ NB_SUBFR ], Wght_Q15[ NB_SUBFR ];
SKP_int32 invGains_Q16[ NB_SUBFR ], local_gains[ NB_SUBFR ], Wght_Q15[ NB_SUBFR ];
SKP_int NLSF_Q15[ MAX_LPC_ORDER ];
const SKP_int16 *x_ptr;
SKP_int16 *x_pre_ptr, LPC_in_pre[ NB_SUBFR * MAX_LPC_ORDER + MAX_FRAME_LENGTH ];
SKP_int32 tmp, min_gain_Q16;
#if !VARQ
SKP_int LZ;
#endif
SKP_int LTP_corrs_rshift[ NB_SUBFR ];
@ -56,20 +49,11 @@ void SKP_Silk_find_pred_coefs_FIX(
for( i = 0; i < NB_SUBFR; i++ ) {
min_gain_Q16 = SKP_min( min_gain_Q16, psEncCtrl->Gains_Q16[ i ] );
}
#if !VARQ
LZ = SKP_Silk_CLZ32( min_gain_Q16 ) - 1;
LZ = SKP_LIMIT( LZ, 0, 16 );
min_gain_Q16 = SKP_RSHIFT( min_gain_Q16, 2 ); /* Ensure that maximum invGains_Q16 is within range of a 16 bit int */
#endif
for( i = 0; i < NB_SUBFR; i++ ) {
/* Divide to Q16 */
SKP_assert( psEncCtrl->Gains_Q16[ i ] > 0 );
#if VARQ
/* Invert and normalize gains, and ensure that maximum invGains_Q16 is within range of a 16 bit int */
invGains_Q16[ i ] = SKP_DIV32_varQ( min_gain_Q16, psEncCtrl->Gains_Q16[ i ], 16 - 2 );
#else
invGains_Q16[ i ] = SKP_DIV32( SKP_LSHIFT( min_gain_Q16, LZ ), SKP_RSHIFT( psEncCtrl->Gains_Q16[ i ], 16 - LZ ) );
#endif
/* Ensure Wght_Q15 a minimum value 1 */
invGains_Q16[ i ] = SKP_max( invGains_Q16[ i ], 363 );
@ -80,7 +64,7 @@ void SKP_Silk_find_pred_coefs_FIX(
Wght_Q15[ i ] = SKP_RSHIFT( tmp, 1 );
/* Invert the inverted and normalized gains */
local_gains_Qx[ i ] = SKP_DIV32( ( 1 << ( 16 + Qx ) ), invGains_Q16[ i ] );
local_gains[ i ] = SKP_DIV32( ( 1 << 16 ), invGains_Q16[ i ] );
}
if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {
@ -104,7 +88,7 @@ void SKP_Silk_find_pred_coefs_FIX(
/* Create LTP residual */
SKP_Silk_LTP_analysis_filter_FIX( LPC_in_pre, psEnc->x_buf + psEnc->sCmn.frame_length - psEnc->sCmn.predictLPCOrder,
psEncCtrl->LTPCoef_Q14, psEncCtrl->sCmn.pitchL, invGains_Q16, 16, psEnc->sCmn.subfr_length, psEnc->sCmn.predictLPCOrder );
psEncCtrl->LTPCoef_Q14, psEncCtrl->sCmn.pitchL, invGains_Q16, psEnc->sCmn.subfr_length, psEnc->sCmn.predictLPCOrder );
} else {
/************/
@ -138,7 +122,7 @@ void SKP_Silk_find_pred_coefs_FIX(
TOC(PROCESS_LSFS)
/* Calculate residual energy using quantized LPC coefficients */
SKP_Silk_residual_energy_FIX( psEncCtrl->ResNrg, psEncCtrl->ResNrgQ, LPC_in_pre, psEncCtrl->PredCoef_Q12, local_gains_Qx, Qx,
SKP_Silk_residual_energy_FIX( psEncCtrl->ResNrg, psEncCtrl->ResNrgQ, LPC_in_pre, psEncCtrl->PredCoef_Q12, local_gains,
psEnc->sCmn.subfr_length, psEnc->sCmn.predictLPCOrder );
/* Copy to prediction struct for use in next frame for fluctuation reduction */

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -53,12 +53,12 @@ void SKP_Silk_gains_quant(
/* Compute delta indices and limit */
if( k == 0 && conditional == 0 ) {
/* Full index */
ind[ k ] = SKP_LIMIT( ind[ k ], 0, N_LEVELS_QGAIN - 1 );
ind[ k ] = SKP_LIMIT_int( ind[ k ], 0, N_LEVELS_QGAIN - 1 );
ind[ k ] = SKP_max_int( ind[ k ], *prev_ind + MIN_DELTA_GAIN_QUANT );
*prev_ind = ind[ k ];
} else {
/* Delta index */
ind[ k ] = SKP_LIMIT( ind[ k ] - *prev_ind, MIN_DELTA_GAIN_QUANT, MAX_DELTA_GAIN_QUANT );
ind[ k ] = SKP_LIMIT_int( ind[ k ] - *prev_ind, MIN_DELTA_GAIN_QUANT, MAX_DELTA_GAIN_QUANT );
/* Accumulate deltas */
*prev_ind += ind[ k ];
/* Shift to make non-negative */

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -31,16 +31,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/* Initialize Silk Encoder state */
/*********************************/
SKP_int SKP_Silk_init_encoder_FIX(
SKP_Silk_encoder_state_FIX *psEnc /* I/O Pointer to Silk encoder state */
)
{
SKP_Silk_encoder_state_FIX *psEnc /* I/O Pointer to Silk FIX encoder state */
) {
SKP_int ret = 0;
/* Clear the entire encoder state */
SKP_memset( psEnc, 0, sizeof( SKP_Silk_encoder_state_FIX ) );
/* Initialize to 24 kHz sampling, 20 ms packets, 25 kbps, 0% packet loss, and init non-zero values */
ret = SKP_Silk_control_encoder_FIX( psEnc, 24, 20, 25, 0, 0, 0, 10, 1 );
#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; */
@ -48,17 +44,13 @@ SKP_int SKP_Silk_init_encoder_FIX(
/* Used to deactivate e.g. LSF interpolation and fluctuation reduction */
psEnc->sCmn.first_frame_after_reset = 1;
psEnc->sCmn.fs_kHz_changed = 0;
psEnc->sCmn.LBRR_enabled = 0;
/* Initialize Silk VAD */
ret += SKP_Silk_VAD_Init( &psEnc->sCmn.sVAD );
/* Initialize NSQ */
psEnc->sNSQ.prev_inv_gain_Q16 = 65536; /* 1.0 in Q16 */
psEnc->sNSQ_LBRR.prev_inv_gain_Q16 = 65536; /* 1.0 in Q16 */
psEnc->sCmn.bitstream_v = USE_BIT_STREAM_V;
psEnc->sNSQ.prev_inv_gain_Q16 = 65536;
psEnc->sNSQ_LBRR.prev_inv_gain_Q16 = 65536;
return( ret );
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -28,8 +28,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/* *
* SKP_Silk_inner_prod_aligned.c *
* *
* *
* Copyright 2008 (c), Skype Limited *
* *
* Copyright 2008-2010 (c), Skype Limited *
* Date: 080601 *
* */
#include "SKP_Silk_SigProc_FIX.h"
@ -54,19 +54,6 @@ SKP_int32 SKP_Silk_inner_prod_aligned(
return sum;
}
SKP_int64 SKP_Silk_inner_prod_aligned_64(
const SKP_int32 *inVec1, /* I input vector 1 */
const SKP_int32 *inVec2, /* I input vector 2 */
const SKP_int len /* I vector lengths */
)
{
SKP_int i;
SKP_int64 sum = 0;
for( i = 0; i < len; i++ ) {
sum = SKP_SMLAL( sum, inVec1[ i ], inVec2[ i ] );
}
return sum;
}
SKP_int64 SKP_Silk_inner_prod16_aligned_64(
const SKP_int16 *inVec1, /* I input vector 1 */
const SKP_int16 *inVec2, /* I input vector 2 */
@ -80,17 +67,3 @@ SKP_int64 SKP_Silk_inner_prod16_aligned_64(
}
return sum;
}
SKP_int32 SKP_Silk_inner_prod16_aligned_sat(
const SKP_int16* const inVec1, /* I input vector 1 */
const SKP_int16* const inVec2, /* I input vector 2 */
const SKP_int len /* I vector lengths */
)
{
SKP_int i;
SKP_int32 sum = 0;
for( i = 0; i < len; i++ ) {
sum = SKP_ADD_SAT32( sum, SKP_SMULBB( inVec1[ i ], inVec2[ i ] ) );
}
return sum;
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -44,7 +44,7 @@ void SKP_Silk_k2a(
)
{
SKP_int k, n;
SKP_int32 Atmp[ SigProc_MAX_ORDER_LPC ];
SKP_int32 Atmp[ SKP_Silk_MAX_ORDER_LPC ];
for( k = 0; k < order; k++ ) {
for( n = 0; n < k; n++ ) {

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -44,7 +44,7 @@ void SKP_Silk_k2a_Q16(
)
{
SKP_int k, n;
SKP_int32 Atmp[ SigProc_MAX_ORDER_LPC ];
SKP_int32 Atmp[ SKP_Silk_MAX_ORDER_LPC ];
for( k = 0; k < order; k++ ) {
for( n = 0; n < k; n++ ) {

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:

View File

@ -1,61 +0,0 @@
/***********************************************************************
Copyright (c) 2006-2010, 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.
***********************************************************************/
/* *
* SKP_Silk_lowpass_int.c *
* *
* First order low-pass filter, with input as SKP_int32, running at *
* 48 kHz *
* *
* Copyright 2006 (c), Skype Limited *
* Date: 060221 *
* */
#include "SKP_Silk_SigProc_FIX.h"
/* 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 */
)
{
SKP_int k;
SKP_int32 in_tmp, out_tmp, state;
state = S[ 0 ];
for( k = len; k > 0; k-- ) {
in_tmp = *in++;
in_tmp -= SKP_RSHIFT( in_tmp, 2 ); /* multiply by 0.75 */
out_tmp = state + in_tmp; /* zero at nyquist */
state = in_tmp - SKP_RSHIFT( out_tmp, 1 ); /* pole */
*out++ = out_tmp;
}
S[ 0 ] = state;
}

View File

@ -1,61 +0,0 @@
/***********************************************************************
Copyright (c) 2006-2010, 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.
***********************************************************************/
/* *
* SKP_Silk_lowpass_short.c *
* *
* First order low-pass filter, with input as SKP_int16, running at *
* 48 kHz *
* *
* Copyright 2006 (c), Skype Limited *
* Date: 060221 *
* */
#include "SKP_Silk_SigProc_FIX.h"
/* 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 */
)
{
SKP_int k;
SKP_int32 in_tmp, out_tmp, state;
state = S[ 0 ];
for( k = 0; k < len; k++ ) {
in_tmp = SKP_MUL( 768, (SKP_int32)in[k] ); /* multiply by 0.75, going from Q15 to Q25 */
out_tmp = state + in_tmp; /* zero at nyquist */
state = in_tmp - SKP_RSHIFT( out_tmp, 1 ); /* pole */
out[ k ] = out_tmp;
}
S[ 0 ] = state;
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -31,91 +31,91 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This is an inline header file for general platform.
// (a32 * (SKP_int32)((SKP_int16)(b32))) >> 16 output have to be 32bit int
#define SKP_SMULWB(a32, b32) ((((a32) >> 16) * (SKP_int32)((SKP_int16)(b32))) + ((((a32) & 0x0000FFFF) * (SKP_int32)((SKP_int16)(b32))) >> 16))
#define SKP_SMULWB(a32, b32) ((((a32) >> 16) * (SKP_int32)((SKP_int16)(b32))) + ((((a32) & 0x0000FFFF) * (SKP_int32)((SKP_int16)(b32))) >> 16))
// a32 + (b32 * (SKP_int32)((SKP_int16)(c32))) >> 16 output have to be 32bit int
#define SKP_SMLAWB(a32, b32, c32) ((a32) + ((((b32) >> 16) * (SKP_int32)((SKP_int16)(c32))) + ((((b32) & 0x0000FFFF) * (SKP_int32)((SKP_int16)(c32))) >> 16)))
#define SKP_SMLAWB(a32, b32, c32) ((a32) + ((((b32) >> 16) * (SKP_int32)((SKP_int16)(c32))) + ((((b32) & 0x0000FFFF) * (SKP_int32)((SKP_int16)(c32))) >> 16)))
// (a32 * (b32 >> 16)) >> 16
#define SKP_SMULWT(a32, b32) (((a32) >> 16) * ((b32) >> 16) + ((((a32) & 0x0000FFFF) * ((b32) >> 16)) >> 16))
#define SKP_SMULWT(a32, b32) (((a32) >> 16) * ((b32) >> 16) + ((((a32) & 0x0000FFFF) * ((b32) >> 16)) >> 16))
// a32 + (b32 * (c32 >> 16)) >> 16
#define SKP_SMLAWT(a32, b32, c32) ((a32) + (((b32) >> 16) * ((c32) >> 16)) + ((((b32) & 0x0000FFFF) * ((c32) >> 16)) >> 16))
#define SKP_SMLAWT(a32, b32, c32) ((a32) + (((b32) >> 16) * ((c32) >> 16)) + ((((b32) & 0x0000FFFF) * ((c32) >> 16)) >> 16))
// (SKP_int32)((SKP_int16)(a3))) * (SKP_int32)((SKP_int16)(b32)) output have to be 32bit int
#define SKP_SMULBB(a32, b32) ((SKP_int32)((SKP_int16)(a32)) * (SKP_int32)((SKP_int16)(b32)))
#define SKP_SMULBB(a32, b32) ((SKP_int32)((SKP_int16)(a32)) * (SKP_int32)((SKP_int16)(b32)))
// a32 + (SKP_int32)((SKP_int16)(b32)) * (SKP_int32)((SKP_int16)(c32)) output have to be 32bit int
#define SKP_SMLABB(a32, b32, c32) ((a32) + ((SKP_int32)((SKP_int16)(b32))) * (SKP_int32)((SKP_int16)(c32)))
#define SKP_SMLABB(a32, b32, c32) ((a32) + ((SKP_int32)((SKP_int16)(b32))) * (SKP_int32)((SKP_int16)(c32)))
// (SKP_int32)((SKP_int16)(a32)) * (b32 >> 16)
#define SKP_SMULBT(a32, b32) ((SKP_int32)((SKP_int16)(a32)) * ((b32) >> 16))
#define SKP_SMULBT(a32, b32) ((SKP_int32)((SKP_int16)(a32)) * ((b32) >> 16))
// a32 + (SKP_int32)((SKP_int16)(b32)) * (c32 >> 16)
#define SKP_SMLABT(a32, b32, c32) ((a32) + ((SKP_int32)((SKP_int16)(b32))) * ((c32) >> 16))
#define SKP_SMLABT(a32, b32, c32) ((a32) + ((SKP_int32)((SKP_int16)(b32))) * ((c32) >> 16))
// a64 + (b32 * c32)
#define SKP_SMLAL(a64, b32, c32) (SKP_ADD64((a64), ((SKP_int64)(b32) * (SKP_int64)(c32))))
#define SKP_SMLAL(a64, b32, c32) (SKP_ADD64((a64), ((SKP_int64)(b32) * (SKP_int64)(c32))))
// (a32 * b32) >> 16
#define SKP_SMULWW(a32, b32) SKP_MLA(SKP_SMULWB((a32), (b32)), (a32), SKP_RSHIFT_ROUND((b32), 16))
#define SKP_SMULWW(a32, b32) SKP_MLA(SKP_SMULWB((a32), (b32)), (a32), SKP_RSHIFT_ROUND((b32), 16))
// a32 + ((b32 * c32) >> 16)
#define SKP_SMLAWW(a32, b32, c32) SKP_MLA(SKP_SMLAWB((a32), (b32), (c32)), (b32), SKP_RSHIFT_ROUND((c32), 16))
#define SKP_SMLAWW(a32, b32, c32) SKP_MLA(SKP_SMLAWB((a32), (b32), (c32)), (b32), SKP_RSHIFT_ROUND((c32), 16))
/* add/subtract with output saturated */
#define SKP_ADD_SAT32(a, b) ((((a) + (b)) & 0x80000000) == 0 ? \
((((a) & (b)) & 0x80000000) != 0 ? SKP_int32_MIN : (a)+(b)) : \
((((a) | (b)) & 0x80000000) == 0 ? SKP_int32_MAX : (a)+(b)) )
#define SKP_ADD_SAT32(a, b) ((((a) + (b)) & 0x80000000) == 0 ? \
((((a) & (b)) & 0x80000000) != 0 ? SKP_int32_MIN : (a)+(b)) : \
((((a) | (b)) & 0x80000000) == 0 ? SKP_int32_MAX : (a)+(b)) )
#define SKP_SUB_SAT32(a, b) ((((a)-(b)) & 0x80000000) == 0 ? \
(( (a) & ((b)^0x80000000) & 0x80000000) ? SKP_int32_MIN : (a)-(b)) : \
((((a)^0x80000000) & (b) & 0x80000000) ? SKP_int32_MAX : (a)-(b)) )
#define SKP_SUB_SAT32(a, b) ((((a)-(b)) & 0x80000000) == 0 ? \
(( (a) & ((b)^0x80000000) & 0x80000000) ? SKP_int32_MIN : (a)-(b)) : \
((((a)^0x80000000) & (b) & 0x80000000) ? SKP_int32_MAX : (a)-(b)) )
SKP_INLINE SKP_int32 SKP_Silk_CLZ16(SKP_int16 in16)
{
SKP_int32 out32 = 0;
if( in16 == 0 ) {
return 16;
}
/* test nibbles */
if( in16 & 0xFF00 ) {
if( in16 & 0xF000 ) {
in16 >>= 12;
} else {
out32 += 4;
in16 >>= 8;
}
} else {
if( in16 & 0xFFF0 ) {
out32 += 8;
in16 >>= 4;
} else {
out32 += 12;
}
}
/* test bits and return */
if( in16 & 0xC ) {
if( in16 & 0x8 )
return out32 + 0;
else
return out32 + 1;
} else {
if( in16 & 0xE )
return out32 + 2;
else
return out32 + 3;
}
SKP_int32 out32 = 0;
if( in16 == 0 ) {
return 16;
}
/* test nibbles */
if( in16 & 0xFF00 ) {
if( in16 & 0xF000 ) {
in16 >>= 12;
} else {
out32 += 4;
in16 >>= 8;
}
} else {
if( in16 & 0xFFF0 ) {
out32 += 8;
in16 >>= 4;
} else {
out32 += 12;
}
}
/* test bits and return */
if( in16 & 0xC ) {
if( in16 & 0x8 )
return out32 + 0;
else
return out32 + 1;
} else {
if( in16 & 0xE )
return out32 + 2;
else
return out32 + 3;
}
}
SKP_INLINE SKP_int32 SKP_Silk_CLZ32(SKP_int32 in32)
{
/* test highest 16 bits and convert to SKP_int16 */
if( in32 & 0xFFFF0000 ) {
return SKP_Silk_CLZ16((SKP_int16)(in32 >> 16));
} else {
return SKP_Silk_CLZ16((SKP_int16)in32) + 16;
}
/* test highest 16 bits and convert to SKP_int16 */
if( in32 & 0xFFFF0000 ) {
return SKP_Silk_CLZ16((SKP_int16)(in32 >> 16));
} else {
return SKP_Silk_CLZ16((SKP_int16)in32) + 16;
}
}
#endif //_SKP_SILK_API_C_H_

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -28,21 +28,22 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef SKP_SILK_MAIN_H
#define SKP_SILK_MAIN_H
#ifdef __cplusplus
extern "C"
{
#endif
#include "SKP_Silk_SigProc_FIX.h"
#include "SKP_Silk_define.h"
#include "SKP_Silk_structs.h"
#include "SKP_Silk_tables.h"
#include "SKP_Silk_PLC.h"
#ifdef __cplusplus
extern "C"
{
#endif
/* Encodes signs of excitation */
void SKP_Silk_encode_signs(
SKP_Silk_range_coder_state *psRC, /* I/O Range coder state */
const SKP_int q[], /* I pulse signal */
const SKP_int8 q[], /* I pulse signal */
const SKP_int length, /* I length of input */
const SKP_int sigtype, /* I Signal type */
const SKP_int QuantOffsetType, /* I Quantization offset type */
@ -59,6 +60,12 @@ void SKP_Silk_decode_signs(
const SKP_int RateLevelIndex /* I Rate Level Index */
);
/* Control internal sampling rate */
SKP_int SKP_Silk_control_audio_bandwidth(
SKP_Silk_encoder_state *psEncC, /* I/O Pointer to Silk encoder state */
const SKP_int32 TargetRate_bps /* I Target max bitrate (bps) */
);
/***************/
/* Shell coder */
/***************/
@ -68,7 +75,7 @@ void SKP_Silk_encode_pulses(
SKP_Silk_range_coder_state *psRC, /* I/O Range coder state */
const SKP_int sigtype, /* I Sigtype */
const SKP_int QuantOffsetType, /* I QuantOffsetType */
const SKP_int q[], /* I quantization indices */
const SKP_int8 q[], /* I quantization indices */
const SKP_int frame_length /* I Frame length */
);
@ -188,11 +195,11 @@ void SKP_Silk_NSQ(
SKP_Silk_encoder_control *psEncCtrlC, /* I Encoder Control */
SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */
const SKP_int16 x[], /* I prefiltered input signal */
SKP_int q[], /* O quantized qulse signal */
SKP_int8 q[], /* O quantized qulse signal */
const SKP_int LSFInterpFactor_Q2, /* I LSF interpolation factor in Q2 */
const SKP_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefficients */
const SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ], /* I Long term prediction coefficients */
const SKP_int16 AR2_Q13[ NB_SUBFR * SHAPE_LPC_ORDER_MAX ], /* I */
const SKP_int16 AR2_Q13[ NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I */
const SKP_int HarmShapeGain_Q14[ NB_SUBFR ], /* I */
const SKP_int Tilt_Q14[ NB_SUBFR ], /* I Spectral tilt */
const SKP_int32 LF_shp_Q14[ NB_SUBFR ], /* I */
@ -207,11 +214,11 @@ void SKP_Silk_NSQ_del_dec(
SKP_Silk_encoder_control *psEncCtrlC, /* I Encoder Control */
SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */
const SKP_int16 x[], /* I Prefiltered input signal */
SKP_int q[], /* O Quantized pulse signal */
SKP_int8 q[], /* O Quantized pulse signal */
const SKP_int LSFInterpFactor_Q2, /* I LSF interpolation factor in Q2 */
const SKP_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Prediction coefs */
const SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ], /* I LT prediction coefs */
const SKP_int16 AR2_Q13[ NB_SUBFR * SHAPE_LPC_ORDER_MAX ], /* I */
const SKP_int16 AR2_Q13[ NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I */
const SKP_int HarmShapeGain_Q14[ NB_SUBFR ], /* I */
const SKP_int Tilt_Q14[ NB_SUBFR ], /* I Spectral tilt */
const SKP_int32 LF_shp_Q14[ NB_SUBFR ], /* I */
@ -306,19 +313,6 @@ void SKP_Silk_decode_parameters(
const SKP_int fullDecoding /* I Flag to tell if only arithmetic decoding */
);
/* Decode indices from payload v4 Bitstream */
void SKP_Silk_decode_indices_v4(
SKP_Silk_decoder_state *psDec /* I/O State */
);
/* Decode parameters from payload v4 Bitstream */
void SKP_Silk_decode_parameters_v4(
SKP_Silk_decoder_state *psDec, /* I/O State */
SKP_Silk_decoder_control *psDecCtrl, /* I/O Decoder control */
SKP_int q[ MAX_FRAME_LENGTH ], /* O Excitation signal */
const SKP_int fullDecoding /* I Flag to tell if only arithmetic decoding */
);
/* Core decoder. Performs inverse NSQ operation LTP + LPC */
void SKP_Silk_decode_core(
SKP_Silk_decoder_state *psDec, /* I/O Decoder state */
@ -369,14 +363,7 @@ void SKP_Silk_encode_parameters(
SKP_Silk_encoder_state *psEncC, /* I/O Encoder state */
SKP_Silk_encoder_control *psEncCtrlC, /* I/O Encoder control */
SKP_Silk_range_coder_state *psRC, /* I/O Range coder state */
const SKP_int *q /* I Quantization indices */
);
/* Encoding of various parameters */
void SKP_Silk_encode_parameters_v4(
SKP_Silk_encoder_state *psEncC, /* I/O Encoder state */
SKP_Silk_encoder_control *psEncCtrlC, /* I/O Encoder control */
SKP_Silk_range_coder_state *psRC /* I/O Range encoder state */
const SKP_int8 *q /* I Quantization indices */
);
/* Extract lowest layer encoding */
@ -392,11 +379,6 @@ void SKP_Silk_LBRR_reset(
SKP_Silk_encoder_state *psEncC /* I/O Pointer to Silk encoder state */
);
/* Predict number of bytes used to encode q */
SKP_int SKP_Silk_pulses_to_bytes( /* O Return value, predicted number of bytes used to encode q */
SKP_Silk_encoder_state *psEncC, /* I/O Encoder State*/
SKP_int q[] /* I Pulse signal */
);
#ifdef __cplusplus
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -32,7 +32,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SKP_Silk_SigProc_FIX.h"
#include "SKP_Silk_structs_FIX.h"
#include "SKP_Silk_main.h"
#include "SKP_Silk_define_FIX.h"
#include "SKP_Silk_PLC.h"
#define TIC(TAG_NAME)
#define TOC(TAG_NAME)
@ -50,20 +49,17 @@ extern "C"
/* Initializes the Silk encoder state */
SKP_int SKP_Silk_init_encoder_FIX(
SKP_Silk_encoder_state_FIX *psEnc /* I/O Pointer to Silk FIX encoder state */
SKP_Silk_encoder_state_FIX *psEnc /* I/O Pointer to Silk FIX encoder state */
);
/* Control the Silk encoder */
SKP_int SKP_Silk_control_encoder_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */
const SKP_int API_fs_kHz, /* I External (API) sampling rate (kHz) */
const SKP_int PacketSize_ms, /* I Packet length (ms) */
SKP_int32 TargetRate_bps, /* I Target max bitrate (bps) (used if SNR_dB == 0) */
const SKP_int PacketLoss_perc, /* I Packet loss rate (in percent) */
const SKP_int INBandFec_enabled, /* I Enable (1) / disable (0) inband FEC */
const SKP_int DTX_enabled, /* I Enable / disable DTX */
const SKP_int InputFramesize_ms, /* I Inputframe in ms */
const SKP_int Complexity /* I Complexity (0->low; 1->medium; 2->high) */
SKP_Silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk encoder state */
const SKP_int PacketSize_ms, /* I Packet length (ms) */
const SKP_int32 TargetRate_bps, /* I Target max bitrate (bps) */
const SKP_int PacketLoss_perc, /* I Packet loss rate (in percent) */
const SKP_int DTX_enabled, /* I Enable / disable DTX */
const SKP_int Complexity /* I Complexity (0->low; 1->medium; 2->high) */
);
/* Encoder main function */
@ -106,10 +102,20 @@ void SKP_Silk_prefilter_FIX(
/* Compute noise shaping coefficients and initial gain values */
/**************************************************************/
void SKP_Silk_noise_shape_analysis_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O Encoder state */
SKP_Silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control */
SKP_Silk_encoder_state_FIX *psEnc, /* I/O Encoder state FIX */
SKP_Silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control FIX */
const SKP_int16 *pitch_res, /* I LPC residual from pitch analysis */
const SKP_int16 *x /* I Input signal [ 2 * frame_length + la_shape ]*/
const SKP_int16 *x /* I Input signal [ frame_length + la_shape ] */
);
/* Autocorrelations for a warped frequency axis */
void SKP_Silk_warped_autocorrelation_FIX(
SKP_int32 *corr, /* O Result [order + 1] */
SKP_int *scale, /* O Scaling of the correlation vector */
const SKP_int16 *input, /* I Input data to correlate */
const SKP_int16 warping_Q16, /* I Warping coefficient */
const SKP_int length, /* I Length of input */
const SKP_int order /* I Correlation order (even) */
);
/* Processing of gains */
@ -118,11 +124,10 @@ void SKP_Silk_process_gains_FIX(
SKP_Silk_encoder_control_FIX *psEncCtrl /* I/O Encoder control */
);
/* Control low bitrate redundancy usage */
void SKP_Silk_LBRR_ctrl_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O encoder state */
SKP_Silk_encoder_control_FIX *psEncCtrl /* I/O encoder control */
SKP_Silk_encoder_control *psEncCtrlC /* I/O encoder control */
);
/* Calculation of LTP state scaling */
@ -150,9 +155,9 @@ void SKP_Silk_find_pred_coefs_FIX(
);
void SKP_Silk_find_LPC_FIX(
SKP_int NLSF_Q15[], /* O LSFs */
SKP_int *interpIndex, /* O LSF interpolation index, only used for LSF interpolation */
const SKP_int prev_NLSFq_Q15[], /* I previous LSFs, only used for LSF interpolation */
SKP_int NLSF_Q15[], /* O NLSFs */
SKP_int *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 useInterpolatedLSFs, /* I Flag */
const SKP_int LPC_order, /* I LPC order */
const SKP_int16 x[], /* I Input signal */
@ -164,8 +169,7 @@ void SKP_Silk_LTP_analysis_filter_FIX(
const SKP_int16 *x, /* I: Pointer to input signal with at least max( pitchL ) preceeding samples */
const SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],/* I: LTP_ORDER LTP coefficients for each NB_SUBFR subframe */
const SKP_int pitchL[ NB_SUBFR ], /* I: Pitch lag, one for each subframe */
const SKP_int32 invGains_Qxx[ NB_SUBFR ], /* I: Inverse quantization gains, one for each subframe */
const SKP_int Qxx, /* I: Inverse quantization gains Q domain */
const SKP_int32 invGains_Q16[ NB_SUBFR ], /* I: Inverse quantization gains, one for each subframe */
const SKP_int subfr_length, /* I: Length of each subframe */
const SKP_int pre_length /* I: Length of the preceeding samples starting at &x[0] for each subframe */
);
@ -205,7 +209,7 @@ void SKP_Silk_process_NLSFs_FIX(
SKP_int *pNLSF_Q15 /* I/O Normalized LSFs (quant out) (0 - (2^15-1)) */
);
/* LSF vector encoder */
/* NLSF vector encoder */
void SKP_Silk_NLSF_MSVQ_encode_FIX(
SKP_int *NLSFIndices, /* O Codebook path vector [ CB_STAGES ] */
SKP_int *pNLSF_Q15, /* I/O Quantized NLSF vector [ LPC_ORDER ] */
@ -263,6 +267,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 */
);
@ -270,7 +275,7 @@ void SKP_Silk_corrMatrix_FIX(
/* Calculates correlation vector X'*t */
void SKP_Silk_corrVector_FIX(
const SKP_int16 *x, /* I x vector [L + order - 1] used to form data matrix X */
const SKP_int16 *t, /* I target vector [L] */
const SKP_int16 *t, /* I Target vector [L] */
const SKP_int L, /* I Length of vectors */
const SKP_int order, /* I Max lag for correlation */
SKP_int32 *Xt, /* O Pointer to X'*t correlation vector [order] */
@ -309,9 +314,8 @@ void SKP_Silk_residual_energy_FIX(
SKP_int32 nrgs[ NB_SUBFR ], /* O Residual energy per subframe */
SKP_int nrgsQ[ NB_SUBFR ], /* O Q value per subframe */
const SKP_int16 x[], /* I Input signal */
const SKP_int16 a_Q12[ 2 ][ MAX_LPC_ORDER ],/* I AR coefs for each frame half */
const SKP_int32 gains_Qx[ NB_SUBFR ], /* I Quantization gains in Qx */
const SKP_int Qx, /* I Quantization gains Q value */
SKP_int16 a_Q12[ 2 ][ MAX_LPC_ORDER ],/* I AR coefs for each frame half */
const SKP_int32 gains[ NB_SUBFR ], /* I Quantization gains */
const SKP_int subfr_length, /* I Subframe length */
const SKP_int LPC_order /* I LPC order */
);

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -26,8 +26,110 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
#include "SKP_Silk_main_FIX.h"
#include "SKP_Silk_perceptual_parameters_FIX.h"
#include "SKP_Silk_tuning_parameters.h"
/* Compute gain to make warped filter coefficients have a zero mean log frequency response on a */
/* non-warped frequency scale. (So that it can be implemented with a minimum-phase monic filter.) */
SKP_INLINE SKP_int32 warped_gain( // gain in Q16
const SKP_int32 *coefs_Q24,
SKP_int lambda_Q16,
SKP_int order
) {
SKP_int i;
SKP_int32 gain_Q24;
lambda_Q16 = -lambda_Q16;
gain_Q24 = coefs_Q24[ order - 1 ];
for( i = order - 2; i >= 0; i-- ) {
gain_Q24 = SKP_SMLAWB( coefs_Q24[ i ], gain_Q24, lambda_Q16 );
}
gain_Q24 = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 24 ), gain_Q24, -lambda_Q16 );
return SKP_INVERSE32_varQ( gain_Q24, 40 );
}
/* Convert warped filter coefficients to monic pseudo-warped coefficients and limit maximum */
/* amplitude of monic warped coefficients by using bandwidth expansion on the true coefficients */
SKP_INLINE void limit_warped_coefs(
SKP_int32 *coefs_syn_Q24,
SKP_int32 *coefs_ana_Q24,
SKP_int lambda_Q16,
SKP_int32 limit_Q24,
SKP_int order
) {
SKP_int i, iter, ind = 0;
SKP_int32 tmp, maxabs_Q24, chirp_Q16, gain_syn_Q16, gain_ana_Q16;
SKP_int32 nom_Q16, den_Q24;
/* Convert to monic coefficients */
lambda_Q16 = -lambda_Q16;
for( i = order - 1; i > 0; i-- ) {
coefs_syn_Q24[ i - 1 ] = SKP_SMLAWB( coefs_syn_Q24[ i - 1 ], coefs_syn_Q24[ i ], lambda_Q16 );
coefs_ana_Q24[ i - 1 ] = SKP_SMLAWB( coefs_ana_Q24[ i - 1 ], coefs_ana_Q24[ i ], lambda_Q16 );
}
lambda_Q16 = -lambda_Q16;
nom_Q16 = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 16 ), -lambda_Q16, lambda_Q16 );
den_Q24 = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 24 ), coefs_syn_Q24[ 0 ], lambda_Q16 );
gain_syn_Q16 = SKP_DIV32_varQ( nom_Q16, den_Q24, 24 );
den_Q24 = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 24 ), coefs_ana_Q24[ 0 ], lambda_Q16 );
gain_ana_Q16 = SKP_DIV32_varQ( nom_Q16, den_Q24, 24 );
for( i = 0; i < order; i++ ) {
coefs_syn_Q24[ i ] = SKP_SMULWW( gain_syn_Q16, coefs_syn_Q24[ i ] );
coefs_ana_Q24[ i ] = SKP_SMULWW( gain_ana_Q16, coefs_ana_Q24[ i ] );
}
for( iter = 0; iter < 10; iter++ ) {
/* Find maximum absolute value */
maxabs_Q24 = -1;
for( i = 0; i < order; i++ ) {
tmp = SKP_max( SKP_abs_int32( coefs_syn_Q24[ i ] ), SKP_abs_int32( coefs_ana_Q24[ i ] ) );
if( tmp > maxabs_Q24 ) {
maxabs_Q24 = tmp;
ind = i;
}
}
if( maxabs_Q24 <= limit_Q24 ) {
/* Coefficients are within range - done */
return;
}
/* Convert back to true warped coefficients */
for( i = 1; i < order; i++ ) {
coefs_syn_Q24[ i - 1 ] = SKP_SMLAWB( coefs_syn_Q24[ i - 1 ], coefs_syn_Q24[ i ], lambda_Q16 );
coefs_ana_Q24[ i - 1 ] = SKP_SMLAWB( coefs_ana_Q24[ i - 1 ], coefs_ana_Q24[ i ], lambda_Q16 );
}
gain_syn_Q16 = SKP_INVERSE32_varQ( gain_syn_Q16, 32 );
gain_ana_Q16 = SKP_INVERSE32_varQ( gain_ana_Q16, 32 );
for( i = 0; i < order; i++ ) {
coefs_syn_Q24[ i ] = SKP_SMULWW( gain_syn_Q16, coefs_syn_Q24[ i ] );
coefs_ana_Q24[ i ] = SKP_SMULWW( gain_ana_Q16, coefs_ana_Q24[ i ] );
}
/* Apply bandwidth expansion */
chirp_Q16 = SKP_FIX_CONST( 0.99, 16 ) - SKP_DIV32_varQ(
SKP_SMULWB( maxabs_Q24 - limit_Q24, SKP_SMLABB( SKP_FIX_CONST( 0.8, 10 ), SKP_FIX_CONST( 0.1, 10 ), iter ) ),
SKP_MUL( maxabs_Q24, ind + 1 ), 22 );
SKP_Silk_bwexpander_32( coefs_syn_Q24, order, chirp_Q16 );
SKP_Silk_bwexpander_32( coefs_ana_Q24, order, chirp_Q16 );
/* Convert to monic warped coefficients */
lambda_Q16 = -lambda_Q16;
for( i = order - 1; i > 0; i-- ) {
coefs_syn_Q24[ i - 1 ] = SKP_SMLAWB( coefs_syn_Q24[ i - 1 ], coefs_syn_Q24[ i ], lambda_Q16 );
coefs_ana_Q24[ i - 1 ] = SKP_SMLAWB( coefs_ana_Q24[ i - 1 ], coefs_ana_Q24[ i ], lambda_Q16 );
}
lambda_Q16 = -lambda_Q16;
nom_Q16 = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 16 ), -lambda_Q16, lambda_Q16 );
den_Q24 = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 24 ), coefs_syn_Q24[ 0 ], lambda_Q16 );
gain_syn_Q16 = SKP_DIV32_varQ( nom_Q16, den_Q24, 24 );
den_Q24 = SKP_SMLAWB( SKP_FIX_CONST( 1.0, 24 ), coefs_ana_Q24[ 0 ], lambda_Q16 );
gain_ana_Q16 = SKP_DIV32_varQ( nom_Q16, den_Q24, 24 );
for( i = 0; i < order; i++ ) {
coefs_syn_Q24[ i ] = SKP_SMULWW( gain_syn_Q16, coefs_syn_Q24[ i ] );
coefs_ana_Q24[ i ] = SKP_SMULWW( gain_ana_Q16, coefs_ana_Q24[ i ] );
}
}
SKP_assert( 0 );
}
/**************************************************************/
/* Compute noise shaping coefficients and initial gain values */
@ -36,33 +138,35 @@ void SKP_Silk_noise_shape_analysis_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O Encoder state FIX */
SKP_Silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control FIX */
const SKP_int16 *pitch_res, /* I LPC residual from pitch analysis */
const SKP_int16 *x /* I Input signal [ 2 * frame_length + la_shape ]*/
const SKP_int16 *x /* I Input signal [ frame_length + la_shape ] */
)
{
SKP_Silk_shape_state_FIX *psShapeSt = &psEnc->sShape;
SKP_int k, nSamples, lz, Qnrg, b_Q14, scale = 0, sz;
SKP_int k, i, nSamples, Qnrg, b_Q14, warping_Q16, scale = 0;
SKP_int32 SNR_adj_dB_Q7, HarmBoost_Q16, HarmShapeGain_Q16, Tilt_Q16, tmp32;
SKP_int32 nrg, pre_nrg_Q30, log_energy_Q7, log_energy_prev_Q7, energy_variation_Q7;
SKP_int32 delta_Q16, BWExp1_Q16, BWExp2_Q16, gain_mult_Q16, gain_add_Q16, strength_Q16, b_Q8;
SKP_int32 auto_corr[ SHAPE_LPC_ORDER_MAX + 1 ];
SKP_int32 refl_coef_Q16[ SHAPE_LPC_ORDER_MAX ];
SKP_int32 AR_Q24[ SHAPE_LPC_ORDER_MAX ];
SKP_int32 auto_corr[ MAX_SHAPE_LPC_ORDER + 1 ];
SKP_int32 refl_coef_Q16[ MAX_SHAPE_LPC_ORDER ];
SKP_int32 AR1_Q24[ MAX_SHAPE_LPC_ORDER ];
SKP_int32 AR2_Q24[ MAX_SHAPE_LPC_ORDER ];
SKP_int16 x_windowed[ SHAPE_LPC_WIN_MAX ];
const SKP_int16 *x_ptr, *pitch_res_ptr;
SKP_int32 sqrt_nrg[ NB_SUBFR ], Qnrg_vec[ NB_SUBFR ];
/* Point to start of first LPC analysis block */
x_ptr = x + psEnc->sCmn.la_shape - SKP_SMULBB( SHAPE_LPC_WIN_MS, psEnc->sCmn.fs_kHz ) + psEnc->sCmn.frame_length / NB_SUBFR;
x_ptr = x - psEnc->sCmn.la_shape;
/****************/
/* CONTROL SNR */
/****************/
/* Reduce SNR_dB values if recent bitstream has exceeded TargetRate */
psEncCtrl->current_SNR_dB_Q7 = psEnc->SNR_dB_Q7 - SKP_SMULWB( SKP_LSHIFT( ( SKP_int32 )psEnc->BufferedInChannel_ms, 7 ), 3277 );
psEncCtrl->current_SNR_dB_Q7 = psEnc->SNR_dB_Q7 - SKP_SMULWB( SKP_LSHIFT( ( SKP_int32 )psEnc->BufferedInChannel_ms, 7 ),
SKP_FIX_CONST( 0.05, 16 ) );
/* Reduce SNR_dB if inband FEC used */
if( psEnc->speech_activity_Q8 > LBRR_SPEECH_ACTIVITY_THRES_Q8 ) {
if( psEnc->speech_activity_Q8 > SKP_FIX_CONST( LBRR_SPEECH_ACTIVITY_THRES, 8 ) ) {
psEncCtrl->current_SNR_dB_Q7 -= SKP_RSHIFT( psEnc->inBandFEC_SNR_comp_Q8, 1 );
}
@ -72,24 +176,26 @@ void SKP_Silk_noise_shape_analysis_FIX(
/* 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 );
/* 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 - ( 18 << 7 ), 4 ) ), 1 );
psEncCtrl->coding_quality_Q14 = SKP_RSHIFT( SKP_Silk_sigm_Q15( SKP_RSHIFT_ROUND( psEncCtrl->current_SNR_dB_Q7 -
SKP_FIX_CONST( 18.0, 7 ), 4 ) ), 1 );
/* Reduce coding SNR during low speech activity */
b_Q8 = ( 1 << 8 ) - psEnc->speech_activity_Q8;
b_Q8 = SKP_FIX_CONST( 1.0, 8 ) - psEnc->speech_activity_Q8;
b_Q8 = SKP_SMULWB( SKP_LSHIFT( b_Q8, 8 ), b_Q8 );
SNR_adj_dB_Q7 = SKP_SMLAWB( psEncCtrl->current_SNR_dB_Q7,
SKP_SMULBB( -BG_SNR_DECR_dB_Q7 >> ( 4 + 1 ), b_Q8 ), // Q11
SKP_SMULWB( ( 1 << 14 ) + psEncCtrl->input_quality_Q14, psEncCtrl->coding_quality_Q14 ) ); // Q12
SKP_SMULBB( SKP_FIX_CONST( -BG_SNR_DECR_dB, 7 ) >> ( 4 + 1 ), b_Q8 ), // Q11
SKP_SMULWB( SKP_FIX_CONST( 1.0, 14 ) + psEncCtrl->input_quality_Q14, psEncCtrl->coding_quality_Q14 ) ); // Q12
if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {
/* Reduce gains for periodic signals */
SNR_adj_dB_Q7 = SKP_SMLAWB( SNR_adj_dB_Q7, HARM_SNR_INCR_dB_Q7 << 1, psEnc->LTPCorr_Q15 );
SNR_adj_dB_Q7 = SKP_SMLAWB( SNR_adj_dB_Q7, SKP_FIX_CONST( HARM_SNR_INCR_dB, 8 ), psEnc->LTPCorr_Q15 );
} else {
/* For unvoiced signals and low-quality input, adjust the quality slower than SNR_dB setting */
SNR_adj_dB_Q7 = SKP_SMLAWB( SNR_adj_dB_Q7,
SKP_SMLAWB( 6 << ( 7 + 2 ), -104856, psEncCtrl->current_SNR_dB_Q7 ), //-104856_Q18 = -0.4_Q0, Q9
( 1 << 14 ) - psEncCtrl->input_quality_Q14 ); // Q14
SKP_SMLAWB( SKP_FIX_CONST( 6.0, 9 ), -SKP_FIX_CONST( 0.4, 18 ), psEncCtrl->current_SNR_dB_Q7 ),
SKP_FIX_CONST( 1.0, 14 ) - psEncCtrl->input_quality_Q14 );
}
/*************************/
@ -118,74 +224,77 @@ void SKP_Silk_noise_shape_analysis_FIX(
pitch_res_ptr += nSamples;
}
psEncCtrl->sparseness_Q8 = SKP_RSHIFT( SKP_Silk_sigm_Q15( SKP_SMULWB( energy_variation_Q7 - ( 5 << 7 ), 6554 ) ), 7 ); // 6554_Q16 = 0.1_Q0
psEncCtrl->sparseness_Q8 = SKP_RSHIFT( SKP_Silk_sigm_Q15( SKP_SMULWB( energy_variation_Q7 -
SKP_FIX_CONST( 5.0, 7 ), SKP_FIX_CONST( 0.1, 16 ) ) ), 7 );
/* Set quantization offset depending on sparseness measure */
if( psEncCtrl->sparseness_Q8 > SPARSENESS_THRESHOLD_QNT_OFFSET_Q8 ) {
if( psEncCtrl->sparseness_Q8 > SKP_FIX_CONST( SPARSENESS_THRESHOLD_QNT_OFFSET, 8 ) ) {
psEncCtrl->sCmn.QuantOffsetType = 0;
} else {
psEncCtrl->sCmn.QuantOffsetType = 1;
}
/* Increase coding SNR for sparse signals */
SNR_adj_dB_Q7 = SKP_SMLAWB( SNR_adj_dB_Q7, SPARSE_SNR_INCR_dB_Q7 << 8, psEncCtrl->sparseness_Q8 - ( 1 << 7 ) );
SNR_adj_dB_Q7 = SKP_SMLAWB( SNR_adj_dB_Q7, SKP_FIX_CONST( SPARSE_SNR_INCR_dB, 15 ), psEncCtrl->sparseness_Q8 - SKP_FIX_CONST( 0.5, 8 ) );
}
/*******************************/
/* Control bandwidth expansion */
/*******************************/
delta_Q16 = SKP_SMULWB( ( 1 << 16 ) - SKP_SMULBB( 3, psEncCtrl->coding_quality_Q14 ), LOW_RATE_BANDWIDTH_EXPANSION_DELTA_Q16 );
BWExp1_Q16 = BANDWIDTH_EXPANSION_Q16 - delta_Q16;
BWExp2_Q16 = BANDWIDTH_EXPANSION_Q16 + delta_Q16;
if( psEnc->sCmn.fs_kHz == 24 ) {
/* Less bandwidth expansion for super wideband */
BWExp1_Q16 = ( 1 << 16 ) - SKP_SMULWB( SWB_BANDWIDTH_EXPANSION_REDUCTION_Q16, ( 1 << 16 ) - BWExp1_Q16 );
BWExp2_Q16 = ( 1 << 16 ) - SKP_SMULWB( SWB_BANDWIDTH_EXPANSION_REDUCTION_Q16, ( 1 << 16 ) - BWExp2_Q16 );
}
/* More BWE for signals with high prediction gain */
strength_Q16 = SKP_SMULWB( psEncCtrl->predGain_Q16, SKP_FIX_CONST( FIND_PITCH_WHITE_NOISE_FRACTION, 16 ) );
BWExp1_Q16 = BWExp2_Q16 = SKP_DIV32_varQ( SKP_FIX_CONST( BANDWIDTH_EXPANSION, 16 ),
SKP_SMLAWW( SKP_FIX_CONST( 1.0, 16 ), strength_Q16, strength_Q16 ), 16 );
delta_Q16 = SKP_SMULWB( SKP_FIX_CONST( 1.0, 16 ) - SKP_SMULBB( 3, psEncCtrl->coding_quality_Q14 ),
SKP_FIX_CONST( LOW_RATE_BANDWIDTH_EXPANSION_DELTA, 16 ) );
BWExp1_Q16 = SKP_SUB32( BWExp1_Q16, delta_Q16 );
BWExp2_Q16 = SKP_ADD32( BWExp2_Q16, delta_Q16 );
/* BWExp1 will be applied after BWExp2, so make it relative */
BWExp1_Q16 = SKP_DIV32_16( SKP_LSHIFT( BWExp1_Q16, 14 ), SKP_RSHIFT( BWExp2_Q16, 2 ) );
if( psEnc->sCmn.warping_Q16 > 0 ) {
/* Slightly more warping in analysis will move quantization noise up in frequency, where it's better masked */
warping_Q16 = SKP_SMLAWB( psEnc->sCmn.warping_Q16, psEncCtrl->coding_quality_Q14, SKP_FIX_CONST( 0.01, 18 ) );
} else {
warping_Q16 = 0;
}
/********************************************/
/* Compute noise shaping AR coefs and gains */
/********************************************/
sz = ( SKP_int )SKP_SMULBB( SHAPE_LPC_WIN_MS, psEnc->sCmn.fs_kHz );
for( k = 0; k < NB_SUBFR; k++ ) {
/* Apply window */
SKP_Silk_apply_sine_window( x_windowed, x_ptr, 0, SHAPE_LPC_WIN_MS * psEnc->sCmn.fs_kHz );
/* Apply window: sine slope followed by flat part followed by cosine slope */
SKP_int shift, slope_part, flat_part;
flat_part = psEnc->sCmn.fs_kHz * 5;
slope_part = SKP_RSHIFT( psEnc->sCmn.shapeWinLength - flat_part, 1 );
SKP_Silk_apply_sine_window_new( x_windowed, x_ptr, 1, slope_part );
shift = slope_part;
SKP_memcpy( x_windowed + shift, x_ptr + shift, flat_part * sizeof(SKP_int16) );
shift += flat_part;
SKP_Silk_apply_sine_window_new( x_windowed + shift, x_ptr + shift, 2, slope_part );
/* Update pointer: next LPC analysis block */
x_ptr += psEnc->sCmn.frame_length / NB_SUBFR;
x_ptr += psEnc->sCmn.subfr_length;
/* Calculate auto correlation */
SKP_Silk_autocorr( auto_corr, &scale, x_windowed, sz, psEnc->sCmn.shapingLPCOrder + 1 );
if( psEnc->sCmn.warping_Q16 > 0 ) {
/* Calculate warped auto correlation */
SKP_Silk_warped_autocorrelation_FIX( auto_corr, &scale, x_windowed, warping_Q16, psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder );
} else {
/* Calculate regular auto correlation */
SKP_Silk_autocorr( auto_corr, &scale, x_windowed, psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder + 1 );
}
/* Add white noise, as a fraction of energy */
auto_corr[0] = SKP_ADD32( auto_corr[0], SKP_max_32( SKP_SMULWB( SKP_RSHIFT( auto_corr[ 0 ], 4 ), SHAPE_WHITE_NOISE_FRACTION_Q20 ), 1 ) );
auto_corr[0] = SKP_ADD32( auto_corr[0], SKP_max_32( SKP_SMULWB( SKP_RSHIFT( auto_corr[ 0 ], 4 ),
SKP_FIX_CONST( SHAPE_WHITE_NOISE_FRACTION, 20 ) ), 1 ) );
/* Calculate the reflection coefficients using schur */
nrg = SKP_Silk_schur64( refl_coef_Q16, auto_corr, psEnc->sCmn.shapingLPCOrder );
SKP_assert( nrg >= 0 );
/* Convert reflection coefficients to prediction coefficients */
SKP_Silk_k2a_Q16( AR_Q24, refl_coef_Q16, psEnc->sCmn.shapingLPCOrder );
/* Bandwidth expansion for synthesis filter shaping */
SKP_Silk_bwexpander_32( AR_Q24, psEnc->sCmn.shapingLPCOrder, BWExp2_Q16 );
/* Make sure to fit in Q13 SKP_int16 */
SKP_Silk_LPC_fit( &psEncCtrl->AR2_Q13[ k * SHAPE_LPC_ORDER_MAX ], AR_Q24, 13, psEnc->sCmn.shapingLPCOrder );
/* Compute noise shaping filter coefficients */
SKP_memcpy(
&psEncCtrl->AR1_Q13[ k * SHAPE_LPC_ORDER_MAX ],
&psEncCtrl->AR2_Q13[ k * SHAPE_LPC_ORDER_MAX ],
psEnc->sCmn.shapingLPCOrder * sizeof( SKP_int16 ) );
/* Bandwidth expansion for analysis filter shaping */
SKP_assert( BWExp1_Q16 <= ( 1 << 16 ) ); // If ever breaking, use LPC_stabilize() in these cases to stay within range
SKP_Silk_bwexpander( &psEncCtrl->AR1_Q13[ k * SHAPE_LPC_ORDER_MAX ], psEnc->sCmn.shapingLPCOrder, BWExp1_Q16 );
/* Increase residual energy */
nrg = SKP_SMLAWB( nrg, SKP_RSHIFT( auto_corr[ 0 ], 8 ), SHAPE_MIN_ENERGY_RATIO_Q24 );
SKP_Silk_k2a_Q16( AR2_Q24, refl_coef_Q16, psEnc->sCmn.shapingLPCOrder );
Qnrg = -scale; // range: -12...30
SKP_assert( Qnrg >= -12 );
@ -204,30 +313,61 @@ void SKP_Silk_noise_shape_analysis_FIX(
Qnrg_vec[ k ] = Qnrg;
psEncCtrl->Gains_Q16[ k ] = SKP_LSHIFT_SAT32( tmp32, 16 - Qnrg );
/* Ratio of prediction gains, in energy domain */
SKP_Silk_LPC_inverse_pred_gain_Q13( &pre_nrg_Q30, &psEncCtrl->AR2_Q13[ k * SHAPE_LPC_ORDER_MAX ], psEnc->sCmn.shapingLPCOrder );
SKP_Silk_LPC_inverse_pred_gain_Q13( &nrg, &psEncCtrl->AR1_Q13[ k * SHAPE_LPC_ORDER_MAX ], psEnc->sCmn.shapingLPCOrder );
lz = SKP_min_32( SKP_Silk_CLZ32( pre_nrg_Q30 ) - 1, 19 );
pre_nrg_Q30 = SKP_DIV32( SKP_LSHIFT( pre_nrg_Q30, lz ), SKP_RSHIFT( nrg, 20 - lz ) + 1 ); // Q20
pre_nrg_Q30 = SKP_RSHIFT( SKP_LSHIFT_SAT32( pre_nrg_Q30, 9 ), 1 ); /* Q28 */
psEncCtrl->GainsPre_Q14[ k ] = ( SKP_int )SKP_Silk_SQRT_APPROX( pre_nrg_Q30 );
if( psEnc->sCmn.warping_Q16 > 0 ) {
/* Adjust gain for warping */
gain_mult_Q16 = warped_gain( AR2_Q24, warping_Q16, psEnc->sCmn.shapingLPCOrder );
SKP_assert( psEncCtrl->Gains_Q16[ k ] >= 0 );
psEncCtrl->Gains_Q16[ k ] = SKP_SMULWW( psEncCtrl->Gains_Q16[ k ], gain_mult_Q16 );
if( psEncCtrl->Gains_Q16[ k ] < 0 ) {
psEncCtrl->Gains_Q16[ k ] = SKP_int32_MAX;
}
}
/* Bandwidth expansion for synthesis filter shaping */
SKP_Silk_bwexpander_32( AR2_Q24, psEnc->sCmn.shapingLPCOrder, BWExp2_Q16 );
/* Compute noise shaping filter coefficients */
SKP_memcpy( AR1_Q24, AR2_Q24, psEnc->sCmn.shapingLPCOrder * sizeof( SKP_int32 ) );
/* Bandwidth expansion for analysis filter shaping */
SKP_assert( BWExp1_Q16 <= SKP_FIX_CONST( 1.0, 16 ) );
SKP_Silk_bwexpander_32( AR1_Q24, psEnc->sCmn.shapingLPCOrder, BWExp1_Q16 );
/* Ratio of prediction gains, in energy domain */
SKP_Silk_LPC_inverse_pred_gain_Q24( &pre_nrg_Q30, AR2_Q24, psEnc->sCmn.shapingLPCOrder );
SKP_Silk_LPC_inverse_pred_gain_Q24( &nrg, AR1_Q24, psEnc->sCmn.shapingLPCOrder );
//psEncCtrl->GainsPre[ k ] = 1.0f - 0.7f * ( 1.0f - pre_nrg / nrg ) = 0.3f + 0.7f * pre_nrg / nrg;
pre_nrg_Q30 = SKP_LSHIFT32( SKP_SMULWB( pre_nrg_Q30, SKP_FIX_CONST( 0.7, 15 ) ), 1 );
psEncCtrl->GainsPre_Q14[ k ] = ( SKP_int ) SKP_FIX_CONST( 0.3, 14 ) + SKP_DIV32_varQ( pre_nrg_Q30, nrg, 14 );
/* Convert to monic warped prediction coefficients and limit absolute values */
limit_warped_coefs( AR2_Q24, AR1_Q24, warping_Q16, SKP_FIX_CONST( 3.999, 24 ), psEnc->sCmn.shapingLPCOrder );
/* Convert from Q24 to Q13 and store in int16 */
for( i = 0; i < psEnc->sCmn.shapingLPCOrder; i++ ) {
psEncCtrl->AR1_Q13[ k * MAX_SHAPE_LPC_ORDER + i ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( AR1_Q24[ i ], 11 ) );
psEncCtrl->AR2_Q13[ k * MAX_SHAPE_LPC_ORDER + i ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( AR2_Q24[ i ], 11 ) );
}
}
/*****************/
/* Gain tweaking */
/*****************/
/* Increase gains during low speech activity and put lower limit on gains */
gain_mult_Q16 = SKP_Silk_log2lin( -SKP_SMLAWB( -16 << 7, SNR_adj_dB_Q7, 10486 ) ); // 10486_Q16 = 0.16_Q0
gain_add_Q16 = SKP_Silk_log2lin( SKP_SMLAWB( 16 << 7, NOISE_FLOOR_dB_Q7, 10486 ) ); // 10486_Q16 = 0.16_Q0
tmp32 = SKP_Silk_log2lin( SKP_SMLAWB( 16 << 7, RELATIVE_MIN_GAIN_dB_Q7, 10486 ) ); // 10486_Q16 = 0.16_Q0
gain_mult_Q16 = SKP_Silk_log2lin( -SKP_SMLAWB( -SKP_FIX_CONST( 16.0, 7 ), SNR_adj_dB_Q7, SKP_FIX_CONST( 0.16, 16 ) ) );
gain_add_Q16 = SKP_Silk_log2lin( SKP_SMLAWB( SKP_FIX_CONST( 16.0, 7 ), SKP_FIX_CONST( NOISE_FLOOR_dB, 7 ), SKP_FIX_CONST( 0.16, 16 ) ) );
tmp32 = SKP_Silk_log2lin( SKP_SMLAWB( SKP_FIX_CONST( 16.0, 7 ), SKP_FIX_CONST( RELATIVE_MIN_GAIN_dB, 7 ), SKP_FIX_CONST( 0.16, 16 ) ) );
tmp32 = SKP_SMULWW( psEnc->avgGain_Q16, tmp32 );
gain_add_Q16 = SKP_ADD_SAT32( gain_add_Q16, tmp32 );
SKP_assert( gain_mult_Q16 >= 0 );
for( k = 0; k < NB_SUBFR; k++ ) {
psEncCtrl->Gains_Q16[ k ] = SKP_SMULWW( psEncCtrl->Gains_Q16[ k ], gain_mult_Q16 );
SKP_assert( psEncCtrl->Gains_Q16[ k ] >= 0 );
if( psEncCtrl->Gains_Q16[ k ] < 0 ) {
psEncCtrl->Gains_Q16[ k ] = SKP_int32_MAX;
}
}
for( k = 0; k < NB_SUBFR; k++ ) {
@ -236,27 +376,28 @@ void SKP_Silk_noise_shape_analysis_FIX(
psEnc->avgGain_Q16,
SKP_SMULWB(
psEncCtrl->Gains_Q16[ k ] - psEnc->avgGain_Q16,
SKP_RSHIFT_ROUND( SKP_SMULBB( psEnc->speech_activity_Q8, GAIN_SMOOTHING_COEF_Q10 ), 2 )
SKP_RSHIFT_ROUND( SKP_SMULBB( psEnc->speech_activity_Q8, SKP_FIX_CONST( GAIN_SMOOTHING_COEF, 10 ) ), 2 )
) );
}
/************************************************/
/* Decrease level during fricatives (de-essing) */
/************************************************/
gain_mult_Q16 = ( 1 << 16 ) + SKP_RSHIFT_ROUND( SKP_MLA( INPUT_TILT_Q26, psEncCtrl->coding_quality_Q14, HIGH_RATE_INPUT_TILT_Q12 ), 10 );
gain_mult_Q16 = SKP_FIX_CONST( 1.0, 16 ) + SKP_RSHIFT_ROUND( SKP_MLA( SKP_FIX_CONST( INPUT_TILT, 26 ),
psEncCtrl->coding_quality_Q14, SKP_FIX_CONST( HIGH_RATE_INPUT_TILT, 12 ) ), 10 );
if( psEncCtrl->input_tilt_Q15 <= 0 && psEncCtrl->sCmn.sigtype == SIG_TYPE_UNVOICED ) {
if( psEnc->sCmn.fs_kHz == 24 ) {
SKP_int32 essStrength_Q15 = SKP_SMULWW( -psEncCtrl->input_tilt_Q15,
SKP_SMULBB( psEnc->speech_activity_Q8, ( 1 << 8 ) - psEncCtrl->sparseness_Q8 ) );
tmp32 = SKP_Silk_log2lin( ( 16 << 7 ) - SKP_SMULWB( essStrength_Q15,
SKP_SMULWB( DE_ESSER_COEF_SWB_dB_Q7, 20972 ) ) ); // 20972_Q17 = 0.16_Q0
SKP_SMULBB( psEnc->speech_activity_Q8, SKP_FIX_CONST( 1.0, 8 ) - psEncCtrl->sparseness_Q8 ) );
tmp32 = SKP_Silk_log2lin( SKP_FIX_CONST( 16.0, 7 ) - SKP_SMULWB( essStrength_Q15,
SKP_SMULWB( SKP_FIX_CONST( DE_ESSER_COEF_SWB_dB, 7 ), SKP_FIX_CONST( 0.16, 17 ) ) ) );
gain_mult_Q16 = SKP_SMULWW( gain_mult_Q16, tmp32 );
} else if( psEnc->sCmn.fs_kHz == 16 ) {
SKP_int32 essStrength_Q15 = SKP_SMULWW(-psEncCtrl->input_tilt_Q15,
SKP_SMULBB( psEnc->speech_activity_Q8, ( 1 << 8 ) - psEncCtrl->sparseness_Q8 ));
tmp32 = SKP_Silk_log2lin( ( 16 << 7 ) - SKP_SMULWB( essStrength_Q15,
SKP_SMULWB( DE_ESSER_COEF_WB_dB_Q7, 20972 ) ) ); // 20972_Q17 = 0.16_Q0
SKP_SMULBB( psEnc->speech_activity_Q8, SKP_FIX_CONST( 1.0, 8 ) - psEncCtrl->sparseness_Q8 ));
tmp32 = SKP_Silk_log2lin( SKP_FIX_CONST( 16.0, 7 ) - SKP_SMULWB( essStrength_Q15,
SKP_SMULWB( SKP_FIX_CONST( DE_ESSER_COEF_WB_dB, 7 ), SKP_FIX_CONST( 0.16, 17 ) ) ) );
gain_mult_Q16 = SKP_SMULWW( gain_mult_Q16, tmp32 );
} else {
SKP_assert( psEnc->sCmn.fs_kHz == 12 || psEnc->sCmn.fs_kHz == 8 );
@ -271,47 +412,50 @@ void SKP_Silk_noise_shape_analysis_FIX(
/* Control low-frequency shaping and noise tilt */
/************************************************/
/* Less low frequency shaping for noisy inputs */
strength_Q16 = SKP_MUL( LOW_FREQ_SHAPING_Q0, ( 1 << 16 ) + SKP_SMULBB( LOW_QUALITY_LOW_FREQ_SHAPING_DECR_Q1, psEncCtrl->input_quality_bands_Q15[ 0 ] - ( 1 << 15 ) ) );
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 ) ) );
if( psEncCtrl->sCmn.sigtype == SIG_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])*/
SKP_int fs_kHz_inv = SKP_DIV32_16( 3277, psEnc->sCmn.fs_kHz ); // 0.2_Q0 = 3277_Q14
SKP_int fs_kHz_inv = SKP_DIV32_16( SKP_FIX_CONST( 0.2, 14 ), psEnc->sCmn.fs_kHz );
for( k = 0; k < NB_SUBFR; k++ ) {
b_Q14 = fs_kHz_inv + SKP_DIV32_16( ( 3 << 14 ), psEncCtrl->sCmn.pitchL[ k ] );
b_Q14 = fs_kHz_inv + SKP_DIV32_16( SKP_FIX_CONST( 3.0, 14 ), psEncCtrl->sCmn.pitchL[ k ] );
/* Pack two coefficients in one int32 */
psEncCtrl->LF_shp_Q14[ k ] = SKP_LSHIFT( ( 1 << 14 ) - b_Q14 - SKP_SMULWB( strength_Q16, b_Q14 ), 16 );
psEncCtrl->LF_shp_Q14[ k ] |= (SKP_uint16)( b_Q14 - ( 1 << 14 ) );
psEncCtrl->LF_shp_Q14[ k ] = SKP_LSHIFT( SKP_FIX_CONST( 1.0, 14 ) - b_Q14 - SKP_SMULWB( strength_Q16, b_Q14 ), 16 );
psEncCtrl->LF_shp_Q14[ k ] |= (SKP_uint16)( b_Q14 - SKP_FIX_CONST( 1.0, 14 ) );
}
SKP_assert( HARM_HP_NOISE_COEF_Q24 < ( 1 << 23 ) ); // Guarantees that second argument to SMULWB() is within range of an SKP_int16
Tilt_Q16 = - HP_NOISE_COEF_Q16 -
SKP_SMULWB( ( 1 << 16 ) - HP_NOISE_COEF_Q16, SKP_SMULWB( HARM_HP_NOISE_COEF_Q24, psEnc->speech_activity_Q8 ) );
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 ) );
} else {
b_Q14 = SKP_DIV32_16( 21299, psEnc->sCmn.fs_kHz ); // 1.3_Q0 = 21299_Q14
/* Pack two coefficients in one int32 */
psEncCtrl->LF_shp_Q14[ 0 ] = SKP_LSHIFT( ( 1 << 14 ) - b_Q14 - SKP_SMULWB( strength_Q16, SKP_SMULWB( 39322, b_Q14 ) ), 16 ); // 0.6_Q0 = 39322_Q16
psEncCtrl->LF_shp_Q14[ 0 ] |= (SKP_uint16)( b_Q14 - ( 1 << 14 ) );
psEncCtrl->LF_shp_Q14[ 0 ] = SKP_LSHIFT( SKP_FIX_CONST( 1.0, 14 ) - b_Q14 -
SKP_SMULWB( strength_Q16, SKP_SMULWB( SKP_FIX_CONST( 0.6, 16 ), b_Q14 ) ), 16 );
psEncCtrl->LF_shp_Q14[ 0 ] |= (SKP_uint16)( b_Q14 - SKP_FIX_CONST( 1.0, 14 ) );
for( k = 1; k < NB_SUBFR; k++ ) {
psEncCtrl->LF_shp_Q14[ k ] = psEncCtrl->LF_shp_Q14[ k - 1 ];
psEncCtrl->LF_shp_Q14[ k ] = psEncCtrl->LF_shp_Q14[ 0 ];
}
Tilt_Q16 = -HP_NOISE_COEF_Q16;
Tilt_Q16 = -SKP_FIX_CONST( HP_NOISE_COEF, 16 );
}
/****************************/
/* HARMONIC SHAPING CONTROL */
/****************************/
/* Control boosting of harmonic frequencies */
HarmBoost_Q16 = SKP_SMULWB( SKP_SMULWB( ( 1 << 17 ) - SKP_LSHIFT( psEncCtrl->coding_quality_Q14, 3 ),
psEnc->LTPCorr_Q15 ), LOW_RATE_HARMONIC_BOOST_Q16 );
HarmBoost_Q16 = SKP_SMULWB( SKP_SMULWB( SKP_FIX_CONST( 1.0, 17 ) - SKP_LSHIFT( psEncCtrl->coding_quality_Q14, 3 ),
psEnc->LTPCorr_Q15 ), SKP_FIX_CONST( LOW_RATE_HARMONIC_BOOST, 16 ) );
/* More harmonic boost for noisy input signals */
HarmBoost_Q16 = SKP_SMLAWB( HarmBoost_Q16,
( 1 << 16 ) - SKP_LSHIFT( psEncCtrl->input_quality_Q14, 2 ), LOW_INPUT_QUALITY_HARMONIC_BOOST_Q16 );
SKP_FIX_CONST( 1.0, 16 ) - SKP_LSHIFT( psEncCtrl->input_quality_Q14, 2 ), SKP_FIX_CONST( LOW_INPUT_QUALITY_HARMONIC_BOOST, 16 ) );
if( USE_HARM_SHAPING && psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {
/* More harmonic noise shaping for high bitrates or noisy input */
HarmShapeGain_Q16 = SKP_SMLAWB( HARMONIC_SHAPING_Q16,
( 1 << 16 ) - SKP_SMULWB( ( 1 << 18 ) - SKP_LSHIFT( psEncCtrl->coding_quality_Q14, 4 ),
psEncCtrl->input_quality_Q14 ), HIGH_RATE_OR_LOW_QUALITY_HARMONIC_SHAPING_Q16 );
HarmShapeGain_Q16 = SKP_SMLAWB( SKP_FIX_CONST( HARMONIC_SHAPING, 16 ),
SKP_FIX_CONST( 1.0, 16 ) - SKP_SMULWB( SKP_FIX_CONST( 1.0, 18 ) - SKP_LSHIFT( psEncCtrl->coding_quality_Q14, 4 ),
psEncCtrl->input_quality_Q14 ), SKP_FIX_CONST( HIGH_RATE_OR_LOW_QUALITY_HARMONIC_SHAPING, 16 ) );
/* Less harmonic noise shaping for less periodic signals */
HarmShapeGain_Q16 = SKP_SMULWB( SKP_LSHIFT( HarmShapeGain_Q16, 1 ),
@ -325,11 +469,11 @@ void SKP_Silk_noise_shape_analysis_FIX(
/*************************/
for( k = 0; k < NB_SUBFR; k++ ) {
psShapeSt->HarmBoost_smth_Q16 =
SKP_SMLAWB( psShapeSt->HarmBoost_smth_Q16, HarmBoost_Q16 - psShapeSt->HarmBoost_smth_Q16, SUBFR_SMTH_COEF_Q16 );
SKP_SMLAWB( psShapeSt->HarmBoost_smth_Q16, HarmBoost_Q16 - psShapeSt->HarmBoost_smth_Q16, SKP_FIX_CONST( SUBFR_SMTH_COEF, 16 ) );
psShapeSt->HarmShapeGain_smth_Q16 =
SKP_SMLAWB( psShapeSt->HarmShapeGain_smth_Q16, HarmShapeGain_Q16 - psShapeSt->HarmShapeGain_smth_Q16, SUBFR_SMTH_COEF_Q16 );
SKP_SMLAWB( psShapeSt->HarmShapeGain_smth_Q16, HarmShapeGain_Q16 - psShapeSt->HarmShapeGain_smth_Q16, SKP_FIX_CONST( SUBFR_SMTH_COEF, 16 ) );
psShapeSt->Tilt_smth_Q16 =
SKP_SMLAWB( psShapeSt->Tilt_smth_Q16, Tilt_Q16 - psShapeSt->Tilt_smth_Q16, SUBFR_SMTH_COEF_Q16 );
SKP_SMLAWB( psShapeSt->Tilt_smth_Q16, Tilt_Q16 - psShapeSt->Tilt_smth_Q16, SKP_FIX_CONST( SUBFR_SMTH_COEF, 16 ) );
psEncCtrl->HarmBoost_Q14[ k ] = ( SKP_int )SKP_RSHIFT_ROUND( psShapeSt->HarmBoost_smth_Q16, 2 );
psEncCtrl->HarmShapeGain_Q14[ k ] = ( SKP_int )SKP_RSHIFT_ROUND( psShapeSt->HarmShapeGain_smth_Q16, 2 );

View File

@ -1,121 +0,0 @@
/***********************************************************************
Copyright (c) 2006-2010, 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.
***********************************************************************/
#ifndef SKP_SILK_PERCEPTUAL_PARAMETERS_FIX_H
#define SKP_SILK_PERCEPTUAL_PARAMETERS_FIX_H
#ifdef __cplusplus
extern "C"
{
#endif
/* reduction in coding SNR during low speech activity */
#define BG_SNR_DECR_dB_Q7 (3<<7)
/* factor for reducing quantization noise during voiced speech */
#define HARM_SNR_INCR_dB_Q7 (2<<7)
/* factor for reducing quantization noise for unvoiced sparse signals */
#define SPARSE_SNR_INCR_dB_Q7 (2<<7)
/* threshold for sparseness measure above which to use lower quantization offset during unvoiced */
#define SPARSENESS_THRESHOLD_QNT_OFFSET_Q8 (3<<6) // 0.75
/* noise shaping filter chirp factor */
#define BANDWIDTH_EXPANSION_Q16 61604 // 0.94
/* difference between chirp factors for analysis and synthesis noise shaping filters at low bitrates */
#define LOW_RATE_BANDWIDTH_EXPANSION_DELTA_Q16 655 //0.01f
/* factor to reduce all bandwidth expansion coefficients for super wideband, relative to wideband */
#define SWB_BANDWIDTH_EXPANSION_REDUCTION_Q16 (1<<16) // 1.0f;
/* gain reduction for fricatives */
#define DE_ESSER_COEF_SWB_dB_Q7 (2 << 7)
#define DE_ESSER_COEF_WB_dB_Q7 (1 << 7)
/* extra harmonic boosting (signal shaping) at low bitrates */
#define LOW_RATE_HARMONIC_BOOST_Q16 6554 // 0.1
/* extra harmonic boosting (signal shaping) for noisy input signals */
#define LOW_INPUT_QUALITY_HARMONIC_BOOST_Q16 6554 // 0.1
/* harmonic noise shaping */
#define HARMONIC_SHAPING_Q16 19661 // 0.3
/* extra harmonic noise shaping for high bitrates or noisy input */
#define HIGH_RATE_OR_LOW_QUALITY_HARMONIC_SHAPING_Q16 13107 // 0.2
/* parameter for shaping noise towards higher frequencies */
#define HP_NOISE_COEF_Q16 19661 // 0.3
/* parameter for shaping noise extra towards higher frequencies during voiced speech */
#define HARM_HP_NOISE_COEF_Q24 7549747 // 0.45
/* parameter for applying a high-pass tilt to the input signal */
#define INPUT_TILT_Q26 2684355 // 0.04
/* parameter for extra high-pass tilt to the input signal at high rates */
#define HIGH_RATE_INPUT_TILT_Q12 246 // 0.06
/* parameter for reducing noise at the very low frequencies */
#define LOW_FREQ_SHAPING_Q0 3
/* less reduction of noise at the very low frequencies for signals with low SNR at low frequencies */
#define LOW_QUALITY_LOW_FREQ_SHAPING_DECR_Q1 1 // 0.5_Q0
/* fraction added to first autocorrelation value */
#define SHAPE_WHITE_NOISE_FRACTION_Q20 50 // 50_Q20 = 4.7684e-5
/* fraction of first autocorrelation value added to residual energy value; limits prediction gain */
#define SHAPE_MIN_ENERGY_RATIO_Q24 256
/* noise floor to put a low limit on the quantization step size */
#define NOISE_FLOOR_dB_Q7 (4 << 7)
/* noise floor relative to active speech gain level */
#define RELATIVE_MIN_GAIN_dB_Q7 -6400 // -50_Q0 = -6400_Q7
/* subframe smoothing coefficient for determining active speech gain level (lower -> more smoothing) */
#define GAIN_SMOOTHING_COEF_Q10 1 // 1e-3_Q0 = 1.024_Q10
/* subframe smoothing coefficient for HarmBoost, HarmShapeGain, Tilt (lower -> more smoothing) */
#define SUBFR_SMTH_COEF_Q16 26214 // 0.4
#define NOISE_GAIN_VL_Q16 7864
#define NOISE_GAIN_VH_Q16 7864
#define NOISE_GAIN_UVL_Q16 6554
#define NOISE_GAIN_UVH_Q16 9830
#ifdef __cplusplus
}
#endif
#endif //SKP_SILK_PERCEPTUAL_PARAMETERS_FIX_H

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -30,7 +30,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************** */
#include "SKP_Silk_SigProc_FIX.h"
#include "SKP_Silk_pitch_est_defines.h"
#include "SKP_Silk_resample_rom.h"
#include "SKP_Silk_common_pitch_est_defines.h"
#define SCRATCH_SIZE 22
@ -59,31 +59,6 @@ SKP_int32 SKP_FIX_P_Ana_find_scaling(
const SKP_int sum_sqr_len
);
void SKP_Silk_decode_pitch(
SKP_int lagIndex, /* I */
SKP_int contourIndex, /* O */
SKP_int pitch_lags[], /* O 4 pitch values */
SKP_int Fs_kHz /* I sampling frequency (kHz) */
)
{
SKP_int lag, i, min_lag;
min_lag = SKP_SMULBB( PITCH_EST_MIN_LAG_MS, Fs_kHz );
/* Only for 24 / 16 kHz version for now */
lag = min_lag + lagIndex;
if( Fs_kHz == 8 ) {
/* Only a small codebook for 8 khz */
for( i = 0; i < PITCH_EST_NB_SUBFR; i++ ) {
pitch_lags[ i ] = lag + SKP_Silk_CB_lags_stage2[ i ][ contourIndex ];
}
} else {
for( i = 0; i < PITCH_EST_NB_SUBFR; i++ ) {
pitch_lags[ i ] = lag + SKP_Silk_CB_lags_stage3[ i ][ contourIndex ];
}
}
}
/*************************************************************/
/* FIXED POINT CORE PITCH ANALYSIS FUNCTION */
/*************************************************************/
@ -97,7 +72,8 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv
const SKP_int32 search_thres1_Q16, /* I First stage threshold for lag candidates 0 - 1 */
const SKP_int search_thres2_Q15, /* I Final threshold for lag candidates 0 - 1 */
const SKP_int Fs_kHz, /* I Sample frequency (kHz) */
const SKP_int complexity /* I Complexity setting, 0-2, where 2 is highest */
const SKP_int complexity, /* I Complexity setting, 0-2, where 2 is highest */
const SKP_int forLJC /* I 1 if this function is called from LJC code, 0 otherwise. */
)
{
SKP_int16 signal_8kHz[ PITCH_EST_MAX_FRAME_LENGTH_ST_2 ];
@ -131,8 +107,8 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv
SKP_assert( Fs_kHz == 8 || Fs_kHz == 12 || Fs_kHz == 16 || Fs_kHz == 24 );
/* Check for valid complexity setting */
SKP_assert( complexity >= SigProc_PITCH_EST_MIN_COMPLEX );
SKP_assert( complexity <= SigProc_PITCH_EST_MAX_COMPLEX );
SKP_assert( complexity >= SKP_Silk_PITCH_EST_MIN_COMPLEX );
SKP_assert( complexity <= SKP_Silk_PITCH_EST_MAX_COMPLEX );
SKP_assert( search_thres1_Q16 >= 0 && search_thres1_Q16 <= (1<<16) );
SKP_assert( search_thres2_Q15 >= 0 && search_thres2_Q15 <= (1<<15) );
@ -154,50 +130,24 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv
SKP_memset( C, 0, sizeof( SKP_int16 ) * PITCH_EST_NB_SUBFR * ( ( PITCH_EST_MAX_LAG >> 1 ) + 5) );
/* Resample from input sampled at Fs_kHz to 8 kHz */
if( Fs_kHz == 12 ) {
SKP_int16 R23[ SigProc_Resample_2_3_coarsest_NUM_FIR_COEFS - 1 ];
SKP_memset( R23, 0, ( SigProc_Resample_2_3_coarsest_NUM_FIR_COEFS - 1 ) * sizeof( SKP_int16 ) );
SKP_Silk_resample_2_3_coarsest( signal_8kHz, R23, signal,
PITCH_EST_FRAME_LENGTH_MS * 12, (SKP_int16*)scratch_mem );
} else if( Fs_kHz == 16 ) {
if( complexity == SigProc_PITCH_EST_MAX_COMPLEX ) {
SKP_assert( 4 <= PITCH_EST_MAX_DECIMATE_STATE_LENGTH );
SKP_memset( filt_state, 0, 4 * sizeof( SKP_int32 ) );
SKP_Silk_resample_1_2_coarse( signal, filt_state, signal_8kHz,
scratch_mem, frame_length_8kHz );
} else {
SKP_assert( 2 <= PITCH_EST_MAX_DECIMATE_STATE_LENGTH );
SKP_memset( filt_state, 0, 2 * sizeof( SKP_int32 ) );
SKP_Silk_resample_1_2_coarsest( signal, filt_state, signal_8kHz,
scratch_mem, frame_length_8kHz );
}
if( Fs_kHz == 16 ) {
SKP_memset( filt_state, 0, 2 * sizeof( SKP_int32 ) );
SKP_Silk_resampler_down2( filt_state, signal_8kHz, signal, frame_length );
} else if ( Fs_kHz == 12 ) {
SKP_int32 R23[ 6 ];
SKP_memset( R23, 0, 6 * sizeof( SKP_int32 ) );
SKP_Silk_resampler_down2_3( R23, signal_8kHz, signal, PITCH_EST_FRAME_LENGTH_MS * 12 );
} else if( Fs_kHz == 24 ) {
/* Resample to 24 -> 8 khz */
SKP_assert( 7 <= PITCH_EST_MAX_DECIMATE_STATE_LENGTH );
SKP_memset( filt_state, 0, 7 * sizeof( SKP_int32 ) );
SKP_Silk_resample_1_3( signal_8kHz, filt_state, signal, 24 * PITCH_EST_FRAME_LENGTH_MS );
SKP_int32 filt_state_fix[ 8 ];
SKP_memset( filt_state_fix, 0, 8 * sizeof(SKP_int32) );
SKP_Silk_resampler_down3( filt_state_fix, signal_8kHz, signal, 24 * PITCH_EST_FRAME_LENGTH_MS );
} else {
SKP_assert( Fs_kHz == 8 );
SKP_memcpy( signal_8kHz, signal, frame_length_8kHz * sizeof( SKP_int16 ) );
}
/* Decimate again to 4 kHz. Set mem to zero */
if( complexity == SigProc_PITCH_EST_MAX_COMPLEX ) {
SKP_assert( 4 <= PITCH_EST_MAX_DECIMATE_STATE_LENGTH );
SKP_memset( filt_state, 0, 4 * sizeof( SKP_int32 ) );
SKP_Silk_resample_1_2_coarse( signal_8kHz, filt_state,
signal_4kHz, scratch_mem, frame_length_4kHz );
} else {
SKP_assert( 2 <= PITCH_EST_MAX_DECIMATE_STATE_LENGTH );
SKP_memset( filt_state, 0, 2 * sizeof( SKP_int32 ) );
SKP_Silk_resample_1_2_coarsest( signal_8kHz, filt_state,
signal_4kHz, scratch_mem, frame_length_4kHz );
SKP_memcpy( signal_8kHz, signal, frame_length_8kHz * sizeof(SKP_int16) );
}
/* Decimate again to 4 kHz */
SKP_memset( filt_state, 0, 2 * sizeof( SKP_int32 ) );/* Set state to zero */
SKP_Silk_resampler_down2( filt_state, signal_4kHz, signal_8kHz, frame_length_8kHz );
/* Low-pass filter */
for( i = frame_length_4kHz - 1; i > 0; i-- ) {
@ -238,7 +188,7 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv
/* Calculate first vector products before loop */
cross_corr = SKP_Silk_inner_prod_aligned( target_ptr, basis_ptr, sf_length_8kHz );
normalizer = SKP_Silk_inner_prod_aligned( basis_ptr, basis_ptr, sf_length_8kHz );
normalizer = SKP_ADD_SAT32( normalizer, 1000 );
normalizer = SKP_ADD_SAT32( normalizer, SKP_SMULBB( sf_length_8kHz, 4000 ) );
temp32 = SKP_DIV32( cross_corr, SKP_Silk_SQRT_APPROX( normalizer ) + 1 );
C[ k ][ min_lag_4kHz ] = (SKP_int16)SKP_SAT16( temp32 ); /* Q0 */
@ -277,14 +227,14 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv
}
/* Sort */
length_d_srch = 5 + complexity;
SKP_assert( length_d_srch <= PITCH_EST_D_SRCH_LENGTH );
length_d_srch = 4 + 2 * complexity;
SKP_assert( 3 * length_d_srch <= PITCH_EST_D_SRCH_LENGTH );
SKP_Silk_insertion_sort_decreasing_int16( &C[ 0 ][ min_lag_4kHz ], d_srch, max_lag_4kHz - min_lag_4kHz + 1, length_d_srch );
/* Escape if correlation is very low already here */
target_ptr = &signal_4kHz[ SKP_RSHIFT( frame_length_4kHz, 1 ) ];
energy = SKP_Silk_inner_prod_aligned( target_ptr, target_ptr, SKP_RSHIFT( frame_length_4kHz, 1 ) );
energy = SKP_ADD_SAT32( energy, 1000 ); /* Q0 */
energy = SKP_ADD_POS_SAT32( energy, 1000 ); /* Q0 */
Cmax = (SKP_int)C[ 0 ][ min_lag_4kHz ]; /* Q-1 */
threshold = SKP_SMULBB( Cmax, Cmax ); /* Q-2 */
/* Compare in Q-2 domain */
@ -383,13 +333,13 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv
if( cross_corr > 0 ) {
energy = SKP_max( energy_target, energy_basis ); /* Find max to make sure first division < 1.0 */
lz = SKP_Silk_CLZ32( cross_corr );
lshift = SKP_LIMIT( lz - 1, 0, 15 );
lshift = SKP_LIMIT_32( lz - 1, 0, 15 );
temp32 = SKP_DIV32( SKP_LSHIFT( cross_corr, lshift ), SKP_RSHIFT( energy, 15 - lshift ) + 1 ); /* Q15 */
SKP_assert( temp32 == SKP_SAT16( temp32 ) );
temp32 = SKP_SMULWB( cross_corr, temp32 ); /* Q(-1), cc * ( cc / max(b, t) ) */
temp32 = SKP_ADD_SAT32( temp32, temp32 ); /* Q(0) */
lz = SKP_Silk_CLZ32( temp32 );
lshift = SKP_LIMIT( lz - 1, 0, 15 );
lshift = SKP_LIMIT_32( lz - 1, 0, 15 );
energy = SKP_min( energy_target, energy_basis );
C[ k ][ d ] = SKP_DIV32( SKP_LSHIFT( temp32, lshift ), SKP_RSHIFT( energy, 15 - lshift ) + 1 ); // Q15
} else {
@ -424,7 +374,7 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv
corr_thres_Q15 = SKP_RSHIFT( SKP_SMULBB( search_thres2_Q15, search_thres2_Q15 ), 13 );
/* If input is 8 khz use a larger codebook here because it is last stage */
if( Fs_kHz == 8 && complexity > SigProc_PITCH_EST_MIN_COMPLEX ) {
if( Fs_kHz == 8 && complexity > SKP_Silk_PITCH_EST_MIN_COMPLEX ) {
nb_cbks_stage2 = PITCH_EST_NB_CBKS_STAGE2_EXT;
} else {
nb_cbks_stage2 = PITCH_EST_NB_CBKS_STAGE2;
@ -451,10 +401,15 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv
/* Bias towards shorter lags */
lag_log2_Q7 = SKP_Silk_lin2log( (SKP_int32)d ); /* Q7 */
SKP_assert( lag_log2_Q7 == SKP_SAT16( lag_log2_Q7 ) );
SKP_assert( PITCH_EST_NB_SUBFR * PITCH_EST_SHORTLAG_BIAS_Q15 == SKP_SAT16( PITCH_EST_NB_SUBFR * PITCH_EST_SHORTLAG_BIAS_Q15 ) );
CCmax_new_b = CCmax_new - SKP_RSHIFT( SKP_SMULBB( PITCH_EST_NB_SUBFR * PITCH_EST_SHORTLAG_BIAS_Q15, lag_log2_Q7 ), 7 ); /* Q15 */
SKP_assert( lag_log2_Q7 == SKP_SAT16( lag_log2_Q7 ) );
SKP_assert( PITCH_EST_NB_SUBFR * PITCH_EST_SHORTLAG_BIAS_Q15 == SKP_SAT16( PITCH_EST_NB_SUBFR * PITCH_EST_SHORTLAG_BIAS_Q15 ) );
if (forLJC) {
CCmax_new_b = CCmax_new;
} else {
CCmax_new_b = CCmax_new - SKP_RSHIFT( SKP_SMULBB( PITCH_EST_NB_SUBFR * PITCH_EST_SHORTLAG_BIAS_Q15, lag_log2_Q7 ), 7 ); /* Q15 */
}
/* Bias towards previous lag */
SKP_assert( PITCH_EST_NB_SUBFR * PITCH_EST_PREVLAG_BIAS_Q15 == SKP_SAT16( PITCH_EST_NB_SUBFR * PITCH_EST_PREVLAG_BIAS_Q15 ) );
if( prevLag > 0 ) {
@ -466,7 +421,10 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv
CCmax_new_b -= prev_lag_bias_Q15; /* Q15 */
}
if( CCmax_new_b > CCmax_b && CCmax_new > corr_thres_Q15 ) {
if ( CCmax_new_b > CCmax_b && /* Find maximum biased correlation */
CCmax_new > corr_thres_Q15 && /* Correlation needs to be high enough to be voiced */
SKP_Silk_CB_lags_stage2[ 0 ][ CBimax_new ] <= min_lag_8kHz /* Lag must be in range */
) {
CCmax_b = CCmax_new_b;
CCmax = CCmax_new;
lag = d;
@ -515,7 +473,7 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv
lag = SKP_SMULBB( lag, 3 );
}
lag = SKP_LIMIT( lag, min_lag, max_lag );
lag = SKP_LIMIT_int( lag, min_lag, max_lag );
start_lag = SKP_max_int( lag - 2, min_lag );
end_lag = SKP_min_int( lag + 2, max_lag );
lag_new = lag; /* to avoid undefined lag */
@ -554,7 +512,7 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv
/* Divide cross_corr / energy and get result in Q15 */
lz = SKP_Silk_CLZ32( cross_corr );
/* Divide with result in Q13, cross_corr could be larger than energy */
lshift = SKP_LIMIT( lz - 1, 0, 13 );
lshift = SKP_LIMIT_32( lz - 1, 0, 13 );
CCmax_new = SKP_DIV32( SKP_LSHIFT( cross_corr, lshift ), SKP_RSHIFT( energy, 13 - lshift ) + 1 );
CCmax_new = SKP_SAT16( CCmax_new );
CCmax_new = SKP_SMULWB( cross_corr, CCmax_new );
@ -574,7 +532,9 @@ SKP_int SKP_Silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unv
CCmax_new = 0;
}
if( CCmax_new > CCmax ) {
if( CCmax_new > CCmax &&
( d + (SKP_int)SKP_Silk_CB_lags_stage3[ 0 ][ j ] ) <= max_lag
) {
CCmax = CCmax_new;
lag_new = d;
CBimax = j;
@ -621,8 +581,8 @@ void SKP_FIX_P_Ana_calc_corr_st3(
SKP_int cbk_offset, cbk_size, delta, idx;
SKP_int32 scratch_mem[ SCRATCH_SIZE ];
SKP_assert( complexity >= SigProc_PITCH_EST_MIN_COMPLEX );
SKP_assert( complexity <= SigProc_PITCH_EST_MAX_COMPLEX );
SKP_assert( complexity >= SKP_Silk_PITCH_EST_MIN_COMPLEX );
SKP_assert( complexity <= SKP_Silk_PITCH_EST_MAX_COMPLEX );
cbk_offset = SKP_Silk_cbk_offsets_stage3[ complexity ];
cbk_size = SKP_Silk_cbk_sizes_stage3[ complexity ];
@ -673,8 +633,8 @@ void SKP_FIX_P_Ana_calc_energy_st3(
SKP_int cbk_offset, cbk_size, delta, idx;
SKP_int32 scratch_mem[ SCRATCH_SIZE ];
SKP_assert( complexity >= SigProc_PITCH_EST_MIN_COMPLEX );
SKP_assert( complexity <= SigProc_PITCH_EST_MAX_COMPLEX );
SKP_assert( complexity >= SKP_Silk_PITCH_EST_MIN_COMPLEX );
SKP_assert( complexity <= SKP_Silk_PITCH_EST_MAX_COMPLEX );
cbk_offset = SKP_Silk_cbk_offsets_stage3[ complexity ];
cbk_size = SKP_Silk_cbk_sizes_stage3[ complexity ];

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -28,16 +28,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef SIGPROCFIX_PITCH_EST_DEFINES_H
#define SIGPROCFIX_PITCH_EST_DEFINES_H
#include "SKP_Silk_SigProc_FIX.h"
#include "SKP_Silk_common_pitch_est_defines.h"
/************************************************************/
/* Definitions For Fix pitch estimator */
/* Definitions For Fix pitch estimator */
/************************************************************/
#define PITCH_EST_SHORTLAG_BIAS_Q15 6554 /* 0.2f. for logarithmic weighting */
#define PITCH_EST_PREVLAG_BIAS_Q15 6554 /* Prev lag bias */
#define PITCH_EST_FLATCONTOUR_BIAS_Q20 52429 /* 0.05f */
#define PITCH_EST_SHORTLAG_BIAS_Q15 6554 /* 0.2f. for logarithmic weighting */
#define PITCH_EST_PREVLAG_BIAS_Q15 6554 /* Prev lag bias */
#define PITCH_EST_FLATCONTOUR_BIAS_Q20 52429 /* 0.05f */
#endif

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -26,7 +26,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
#include "SKP_Silk_typedef.h"
#include "SKP_Silk_pitch_est_defines.h"
#include "SKP_Silk_common_pitch_est_defines.h"
/********************************************************/
/* Auto Generated File from generate_pitch_est_tables.m */
@ -48,7 +48,7 @@ const SKP_int16 SKP_Silk_CB_lags_stage3[PITCH_EST_NB_SUBFR][PITCH_EST_NB_CBKS_ST
{ 9, 8, 6, 5, 6, 5, 4, 4, 3, 3, 2, 2, 2, 1, 0, 1, 1, 0, 0, 0,-1,-1,-1,-2,-2,-2,-3,-3,-4,-4,-5,-5,-6,-7}
};
const SKP_int16 SKP_Silk_Lag_range_stage3[ SigProc_PITCH_EST_MAX_COMPLEX + 1 ] [ PITCH_EST_NB_SUBFR ][ 2 ] =
const SKP_int16 SKP_Silk_Lag_range_stage3[ SKP_Silk_PITCH_EST_MAX_COMPLEX + 1 ] [ PITCH_EST_NB_SUBFR ][ 2 ] =
{
/* Lags to search for low number of stage3 cbks */
{
@ -73,14 +73,14 @@ const SKP_int16 SKP_Silk_Lag_range_stage3[ SigProc_PITCH_EST_MAX_COMPLEX + 1 ] [
}
};
const SKP_int16 SKP_Silk_cbk_sizes_stage3[SigProc_PITCH_EST_MAX_COMPLEX + 1] =
const SKP_int16 SKP_Silk_cbk_sizes_stage3[SKP_Silk_PITCH_EST_MAX_COMPLEX + 1] =
{
PITCH_EST_NB_CBKS_STAGE3_MIN,
PITCH_EST_NB_CBKS_STAGE3_MID,
PITCH_EST_NB_CBKS_STAGE3_MAX
};
const SKP_int16 SKP_Silk_cbk_offsets_stage3[SigProc_PITCH_EST_MAX_COMPLEX + 1] =
const SKP_int16 SKP_Silk_cbk_offsets_stage3[SKP_Silk_PITCH_EST_MAX_COMPLEX + 1] =
{
((PITCH_EST_NB_CBKS_STAGE3_MAX - PITCH_EST_NB_CBKS_STAGE3_MIN) >> 1),
((PITCH_EST_NB_CBKS_STAGE3_MAX - PITCH_EST_NB_CBKS_STAGE3_MID) >> 1),

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -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_perceptual_parameters_FIX.h"
#include "SKP_Silk_tuning_parameters.h"
/* SKP_Silk_prefilter. Prefilter for finding Quantizer input signal */
SKP_INLINE void SKP_Silk_prefilt_FIX(
@ -39,6 +39,46 @@ SKP_INLINE void SKP_Silk_prefilt_FIX(
SKP_int lag, /* I Lag for harmonic shaping */
SKP_int length /* I Length of signals */
);
void SKP_Silk_warped_LPC_analysis_filter_FIX(
SKP_int32 state[], /* I/O State [order + 1] */
SKP_int16 res[], /* O Residual signal [length] */
const SKP_int16 coef_Q13[], /* I Coefficients [order] */
const SKP_int16 input[], /* I Input signal [length] */
const SKP_int16 lambda_Q16, /* I Warping factor */
const SKP_int length, /* I Length of input signal */
const SKP_int order /* I Filter order (even) */
)
{
SKP_int n, i;
SKP_int32 acc_Q11, tmp1, tmp2;
/* Order must be even */
SKP_assert( ( order & 1 ) == 0 );
for( n = 0; n < length; n++ ) {
/* Output of lowpass section */
tmp2 = SKP_SMLAWB( state[ 0 ], state[ 1 ], lambda_Q16 );
state[ 0 ] = SKP_LSHIFT( input[ n ], 14 );
/* Output of allpass section */
tmp1 = SKP_SMLAWB( state[ 1 ], state[ 2 ] - tmp2, lambda_Q16 );
state[ 1 ] = tmp2;
acc_Q11 = SKP_SMULWB( tmp2, coef_Q13[ 0 ] );
/* Loop over allpass sections */
for( i = 2; i < order; i += 2 ) {
/* Output of allpass section */
tmp2 = SKP_SMLAWB( state[ i ], state[ i + 1 ] - tmp1, lambda_Q16 );
state[ i ] = tmp1;
acc_Q11 = SKP_SMLAWB( acc_Q11, tmp1, coef_Q13[ i - 1 ] );
/* Output of allpass section */
tmp1 = SKP_SMLAWB( state[ i + 1 ], state[ i + 2 ] - tmp2, lambda_Q16 );
state[ i + 1 ] = tmp2;
acc_Q11 = SKP_SMLAWB( acc_Q11, tmp2, coef_Q13[ i ] );
}
state[ order ] = tmp1;
acc_Q11 = SKP_SMLAWB( acc_Q11, tmp1, coef_Q13[ order - 1 ] );
res[ n ] = ( SKP_int16 )SKP_SAT16( ( SKP_int32 )input[ n ] - SKP_RSHIFT_ROUND( acc_Q11, 11 ) );
}
}
void SKP_Silk_prefilter_FIX(
SKP_Silk_encoder_state_FIX *psEnc, /* I/O Encoder state FIX */
@ -49,14 +89,15 @@ void SKP_Silk_prefilter_FIX(
{
SKP_Silk_prefilter_state_FIX *P = &psEnc->sPrefilt;
SKP_int j, k, lag;
SKP_int32 tmp_32, B_Q12;
SKP_int32 tmp_32;
const SKP_int16 *AR1_shp_Q13;
const SKP_int16 *px;
SKP_int16 *pxw, *pst_res;
SKP_int HarmShapeGain_Q12, Tilt_Q14, LF_shp_Q14;
SKP_int32 HarmShapeFIRPacked_Q12;
SKP_int32 x_filt_Q12[ MAX_FRAME_LENGTH / NB_SUBFR ], filterState[ MAX_LPC_ORDER ];
SKP_int16 st_res[ ( MAX_FRAME_LENGTH / NB_SUBFR ) + MAX_LPC_ORDER ];
SKP_int16 *pxw;
SKP_int HarmShapeGain_Q12, Tilt_Q14;
SKP_int32 HarmShapeFIRPacked_Q12, LF_shp_Q14;
SKP_int32 x_filt_Q12[ MAX_FRAME_LENGTH / NB_SUBFR ];
SKP_int16 st_res[ ( MAX_FRAME_LENGTH / NB_SUBFR ) + MAX_SHAPE_LPC_ORDER ];
SKP_int16 B_Q12[ 2 ];
/* Setup pointers */
px = x;
@ -71,36 +112,29 @@ void SKP_Silk_prefilter_FIX(
/* Noise shape parameters */
HarmShapeGain_Q12 = SKP_SMULWB( psEncCtrl->HarmShapeGain_Q14[ k ], 16384 - psEncCtrl->HarmBoost_Q14[ k ] );
SKP_assert( HarmShapeGain_Q12 >= 0 );
HarmShapeFIRPacked_Q12 = SKP_RSHIFT( HarmShapeGain_Q12, 2 );
HarmShapeFIRPacked_Q12 = SKP_RSHIFT( HarmShapeGain_Q12, 2 );
HarmShapeFIRPacked_Q12 |= SKP_LSHIFT( ( SKP_int32 )SKP_RSHIFT( HarmShapeGain_Q12, 1 ), 16 );
Tilt_Q14 = psEncCtrl->Tilt_Q14[ k ];
LF_shp_Q14 = psEncCtrl->LF_shp_Q14[ k ];
AR1_shp_Q13 = &psEncCtrl->AR1_Q13[ k * SHAPE_LPC_ORDER_MAX ];
AR1_shp_Q13 = &psEncCtrl->AR1_Q13[ k * MAX_SHAPE_LPC_ORDER ];
/* Short term FIR filtering*/
SKP_memset( filterState, 0, psEnc->sCmn.shapingLPCOrder * sizeof( SKP_int32 ) );
SKP_Silk_MA_Prediction_Q13( px - psEnc->sCmn.shapingLPCOrder, AR1_shp_Q13, filterState,
st_res, psEnc->sCmn.subfr_length + psEnc->sCmn.shapingLPCOrder, psEnc->sCmn.shapingLPCOrder );
pst_res = st_res + psEnc->sCmn.shapingLPCOrder; /* Point to first sample */
SKP_Silk_warped_LPC_analysis_filter_FIX( P->sAR_shp, st_res, AR1_shp_Q13, px,
psEnc->sCmn.warping_Q16, psEnc->sCmn.subfr_length, psEnc->sCmn.shapingLPCOrder );
/* reduce (mainly) low frequencies during harmonic emphasis */
B_Q12 = SKP_RSHIFT_ROUND( psEncCtrl->GainsPre_Q14[ k ], 2 );
tmp_32 = SKP_SMLABB( INPUT_TILT_Q26, psEncCtrl->HarmBoost_Q14[ k ], HarmShapeGain_Q12 ); /* Q26 */
tmp_32 = SKP_SMLABB( tmp_32, psEncCtrl->coding_quality_Q14, HIGH_RATE_INPUT_TILT_Q12 ); /* Q26 */
tmp_32 = SKP_SMULWB( tmp_32, -psEncCtrl->GainsPre_Q14[ k ] ); /* Q24 */
tmp_32 = SKP_RSHIFT_ROUND( tmp_32, 12 ); /* Q12 */
B_Q12 |= SKP_LSHIFT( SKP_SAT16( tmp_32 ), 16 );
B_Q12[ 0 ] = SKP_RSHIFT_ROUND( psEncCtrl->GainsPre_Q14[ k ], 2 );
tmp_32 = SKP_SMLABB( SKP_FIX_CONST( INPUT_TILT, 26 ), psEncCtrl->HarmBoost_Q14[ k ], HarmShapeGain_Q12 ); /* Q26 */
tmp_32 = SKP_SMLABB( tmp_32, psEncCtrl->coding_quality_Q14, SKP_FIX_CONST( HIGH_RATE_INPUT_TILT, 12 ) ); /* Q26 */
tmp_32 = SKP_SMULWB( tmp_32, -psEncCtrl->GainsPre_Q14[ k ] ); /* Q24 */
tmp_32 = SKP_RSHIFT_ROUND( tmp_32, 12 ); /* Q12 */
B_Q12[ 1 ]= SKP_SAT16( tmp_32 );
/* NOTE: the code below loads two int16 values in an int32, and multiplies each using the */
/* SMLABB and SMLABT instructions. On a big-endian CPU the two int16 variables would be */
/* loaded in reverse order and the code will give the wrong result. In that case swapping */
/* the SMLABB and SMLABT instructions should solve the problem. */
x_filt_Q12[ 0 ] = SKP_SMLABT( SKP_SMULBB( pst_res[ 0 ], B_Q12 ), P->sHarmHP, B_Q12 );
x_filt_Q12[ 0 ] = SKP_SMLABB( SKP_SMULBB( st_res[ 0 ], B_Q12[ 0 ] ), P->sHarmHP, B_Q12[ 1 ] );
for( j = 1; j < psEnc->sCmn.subfr_length; j++ ) {
x_filt_Q12[ j ] = SKP_SMLABT( SKP_SMULBB( pst_res[ j ], B_Q12 ), pst_res[ j - 1 ], B_Q12 );
x_filt_Q12[ j ] = SKP_SMLABB( SKP_SMULBB( st_res[ j ], B_Q12[ 0 ] ), st_res[ j - 1 ], B_Q12[ 1 ] );
}
P->sHarmHP = pst_res[ psEnc->sCmn.subfr_length - 1 ];
P->sHarmHP = st_res[ psEnc->sCmn.subfr_length - 1 ];
SKP_Silk_prefilt_FIX( P, x_filt_Q12, pxw, HarmShapeFIRPacked_Q12, Tilt_Q14,
LF_shp_Q14, lag, psEnc->sCmn.subfr_length );
@ -130,10 +164,10 @@ SKP_INLINE void SKP_Silk_prefilt_FIX(
SKP_int16 *LTP_shp_buf;
/* To speed up use temp variables instead of using the struct */
LTP_shp_buf = P->sLTP_shp1;
LTP_shp_buf_idx = P->sLTP_shp_buf_idx1;
sLF_AR_shp_Q12 = P->sLF_AR_shp1_Q12;
sLF_MA_shp_Q12 = P->sLF_MA_shp1_Q12;
LTP_shp_buf = P->sLTP_shp;
LTP_shp_buf_idx = P->sLTP_shp_buf_idx;
sLF_AR_shp_Q12 = P->sLF_AR_shp_Q12;
sLF_MA_shp_Q12 = P->sLF_MA_shp_Q12;
for( i = 0; i < length; i++ ) {
if( lag > 0 ) {
@ -147,20 +181,20 @@ SKP_INLINE void SKP_Silk_prefilt_FIX(
n_LTP_Q12 = 0;
}
n_LF_Q10 = SKP_SMLAWB( SKP_SMULWT( sLF_AR_shp_Q12, LF_shp_Q14 ), sLF_MA_shp_Q12, LF_shp_Q14 );
n_Tilt_Q10 = SKP_SMULWB( sLF_AR_shp_Q12, Tilt_Q14 );
n_LF_Q10 = SKP_SMLAWB( SKP_SMULWT( sLF_AR_shp_Q12, LF_shp_Q14 ), sLF_MA_shp_Q12, LF_shp_Q14 );
sLF_AR_shp_Q12 = SKP_SUB32( st_res_Q12[ i ], SKP_LSHIFT( n_Tilt_Q10, 2 ) );
sLF_MA_shp_Q12 = SKP_SUB32( sLF_AR_shp_Q12, SKP_LSHIFT( n_LF_Q10, 2 ) );
LTP_shp_buf_idx = ( LTP_shp_buf_idx - 1 ) & LTP_MASK;
LTP_shp_buf_idx = ( LTP_shp_buf_idx - 1 ) & LTP_MASK;
LTP_shp_buf[ LTP_shp_buf_idx ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( sLF_MA_shp_Q12, 12 ) );
xw[i] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND( SKP_SUB32( sLF_MA_shp_Q12, n_LTP_Q12 ), 12 ) );
}
/* Copy temp variable back to state */
P->sLF_AR_shp1_Q12 = sLF_AR_shp_Q12;
P->sLF_MA_shp1_Q12 = sLF_MA_shp_Q12;
P->sLTP_shp_buf_idx1 = LTP_shp_buf_idx;
P->sLF_AR_shp_Q12 = sLF_AR_shp_Q12;
P->sLF_MA_shp_Q12 = sLF_MA_shp_Q12;
P->sLTP_shp_buf_idx = LTP_shp_buf_idx;
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -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"
/* Processing of gains */
void SKP_Silk_process_gains_FIX(
@ -35,21 +36,20 @@ void SKP_Silk_process_gains_FIX(
{
SKP_Silk_shape_state_FIX *psShapeSt = &psEnc->sShape;
SKP_int k;
SKP_int32 s_Q16, InvMaxSqrVal_Q16, gain, gain_squared, ResNrg, ResNrgPart;
SKP_int32 s_Q16, InvMaxSqrVal_Q16, gain, gain_squared, ResNrg, ResNrgPart, quant_offset_Q10;
/* Gain reduction when LTP coding gain is high */
if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {
/*s = -0.5f * SKP_sigmoid( 0.25f * ( psEncCtrl->LTPredCodGain - 12.0f ) ); */
s_Q16 = -SKP_Silk_sigm_Q15( SKP_RSHIFT_ROUND( psEncCtrl->LTPredCodGain_Q7 - (12 << 7), 4 ) );
s_Q16 = -SKP_Silk_sigm_Q15( SKP_RSHIFT_ROUND( psEncCtrl->LTPredCodGain_Q7 - SKP_FIX_CONST( 12.0, 7 ), 4 ) );
for( k = 0; k < NB_SUBFR; k++ ) {
psEncCtrl->Gains_Q16[ k ] = SKP_SMLAWB( psEncCtrl->Gains_Q16[ k ], psEncCtrl->Gains_Q16[ k ], s_Q16 );
}
}
/* Limit the quantized signal */
/* 69 = 21.0f + 16/0.33 */
InvMaxSqrVal_Q16 = SKP_DIV32_16( SKP_Silk_log2lin(
SKP_SMULWB( (69 << 7) - psEncCtrl->current_SNR_dB_Q7, SKP_FIX_CONST( 0.33, 16 )) ), psEnc->sCmn.subfr_length );
SKP_SMULWB( SKP_FIX_CONST( 70.0, 7 ) - psEncCtrl->current_SNR_dB_Q7, SKP_FIX_CONST( 0.33, 16 ) ) ), psEnc->sCmn.subfr_length );
for( k = 0; k < NB_SUBFR; k++ ) {
/* Soft limit on ratio residual energy and squared gains */
@ -87,7 +87,7 @@ void SKP_Silk_process_gains_FIX(
&psShapeSt->LastGainIndex, psEnc->sCmn.nFramesInPayloadBuf );
/* Set quantizer offset for voiced signals. Larger offset when LTP coding gain is low or tilt is high (ie low-pass) */
if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {
if( psEncCtrl->LTPredCodGain_Q7 + SKP_RSHIFT( psEncCtrl->input_tilt_Q15, 8 ) > ( 1 << 7 ) ) {
if( psEncCtrl->LTPredCodGain_Q7 + SKP_RSHIFT( psEncCtrl->input_tilt_Q15, 8 ) > SKP_FIX_CONST( 1.0, 7 ) ) {
psEncCtrl->sCmn.QuantOffsetType = 0;
} else {
psEncCtrl->sCmn.QuantOffsetType = 1;
@ -95,20 +95,14 @@ void SKP_Silk_process_gains_FIX(
}
/* Quantizer boundary adjustment */
if( psEncCtrl->sCmn.sigtype == SIG_TYPE_VOICED ) {
psEncCtrl->Lambda_Q10 = SKP_FIX_CONST( 1.3, 10 )
- SKP_SMULWB( SKP_FIX_CONST( 0.5, 18 ), psEnc->speech_activity_Q8 )
- SKP_SMULWB( SKP_FIX_CONST( 0.3, 12 ), psEncCtrl->input_quality_Q14 )
+ SKP_SMULBB( SKP_FIX_CONST( 0.2, 10 ), psEncCtrl->sCmn.QuantOffsetType )
- SKP_SMULWB( SKP_FIX_CONST( 0.1, 12 ), psEncCtrl->coding_quality_Q14 );
} else {
psEncCtrl->Lambda_Q10 = SKP_FIX_CONST( 1.3, 10 )
- SKP_SMULWB( SKP_FIX_CONST( 0.5, 18 ), psEnc->speech_activity_Q8 )
- SKP_SMULWB( SKP_FIX_CONST( 0.4, 12 ), psEncCtrl->input_quality_Q14 )
+ SKP_SMULBB( SKP_FIX_CONST( 0.4, 10 ), psEncCtrl->sCmn.QuantOffsetType )
- SKP_SMULWB( SKP_FIX_CONST( 0.1, 12 ), psEncCtrl->coding_quality_Q14 );
}
SKP_assert( psEncCtrl->Lambda_Q10 >= 0 );
quant_offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psEncCtrl->sCmn.sigtype ][ psEncCtrl->sCmn.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_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 );
SKP_assert( psEncCtrl->Lambda_Q10 > 0 );
SKP_assert( psEncCtrl->Lambda_Q10 < SKP_FIX_CONST( 2, 10 ) );
}

View File

@ -1,77 +0,0 @@
/***********************************************************************
Copyright (c) 2006-2010, 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.
***********************************************************************/
/*
* File Name: SKP_Silk_pulses_to_bytes.c
*/
#include <stdlib.h>
#include "SKP_Silk_main.h"
/* nBytes = sum_over_shell_blocks( POLY_FIT_0 + POLY_FIT_1 * sum_abs_val + POLY_FIT_2 * sum_abs_val^2 ) */
#define POLY_FIT_0_Q15 12520
#define POLY_FIT_1_Q15 15862
#define POLY_FIT_2_Q20 -9222 // ToDo better training with
/* Predict number of bytes used to encode q */
SKP_int SKP_Silk_pulses_to_bytes( /* O Return value, predicted number of bytes used to encode q */
SKP_Silk_encoder_state *psEncC, /* I/O Encoder State */
SKP_int q[] /* I Pulse signal */
)
{
SKP_int i, j, iter, *q_ptr;
SKP_int32 sum_abs_val, nBytes, acc_nBytes;
/* Take the absolute value of the pulses */
iter = psEncC->frame_length / SHELL_CODEC_FRAME_LENGTH;
/* Calculate rate as a nonlinaer mapping of sum abs value of each Shell block */
q_ptr = q;
acc_nBytes = 0;
for( j = 0; j < iter; j++ ) {
sum_abs_val = 0;
for(i = 0; i < SHELL_CODEC_FRAME_LENGTH; i+=4){
sum_abs_val += SKP_abs( q_ptr[ i + 0 ] );
sum_abs_val += SKP_abs( q_ptr[ i + 1 ] );
sum_abs_val += SKP_abs( q_ptr[ i + 2 ] );
sum_abs_val += SKP_abs( q_ptr[ i + 3 ] );
}
/* Calculate nBytes used for thi sshell frame */
nBytes = SKP_SMULWB( SKP_SMULBB( sum_abs_val, sum_abs_val ), POLY_FIT_2_Q20 ); // Q4
nBytes = SKP_LSHIFT_SAT32( nBytes, 11 ); // Q15
nBytes += SKP_SMULBB( sum_abs_val, POLY_FIT_1_Q15 ); // Q15
nBytes += POLY_FIT_0_Q15; // Q15
acc_nBytes += nBytes;
q_ptr += SHELL_CODEC_FRAME_LENGTH; /* update pointer */
}
acc_nBytes = SKP_RSHIFT_ROUND( acc_nBytes, 15 ); // Q0
acc_nBytes = SKP_SAT16( acc_nBytes ); // just to be sure // Q0
return(( SKP_int )acc_nBytes);
}

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:
@ -292,7 +292,7 @@ SKP_int SKP_Silk_range_coder_get_length( /* O returns number o
{
SKP_int nBits;
/* Number of additional bits (1..9) required to be stored to stream */
/* Number of bits in stream */
nBits = SKP_LSHIFT( psRC->bufferIx, 3 ) + SKP_Silk_CLZ32( psRC->range_Q16 - 1 ) - 14;
*nBytes = SKP_RSHIFT( nBits + 7, 3 );

View File

@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
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:

View File

@ -1,77 +0,0 @@
/***********************************************************************
Copyright (c) 2006-2010, 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.
***********************************************************************/
/* *
* SKP_Silk_resample_1_2 *
* *
* Downsample by a factor 2 *
* *
* Copyright 2006 (c), Skype Limited *
* Date: 060221 *
* */
#include "SKP_Silk_SigProc_FIX.h"
/* Coefficients for 2-fold resampling */
static SKP_int16 A20_Resample_1_2[ 3 ] = { 1254, 10102, 22898 };
static SKP_int16 A21_Resample_1_2[ 3 ] = { 4810, 16371, 29374 };
/* Downsample by a factor 2 */
void SKP_Silk_resample_1_2(
const SKP_int16 *in, /* I: 16 kHz signal [2*len] */
SKP_int32 *S, /* I/O: State vector [6] */
SKP_int16 *out, /* O: 8 kHz signal [len] */
SKP_int32 *scratch, /* I: Scratch memory [4*len] */
const SKP_int32 len /* I: Number of OUTPUT samples*/
)
{
SKP_int32 k, idx;
/* De-interleave allpass inputs, and convert Q15 -> Q25 */
for( k = 0; k < len; k++ ) {
idx = SKP_LSHIFT( k, 1 );
scratch[ k ] = SKP_LSHIFT( (SKP_int32)in[ idx ], 10 );
scratch[ k + len ] = SKP_LSHIFT( (SKP_int32)in[ idx + 1 ], 10 );
}
idx = SKP_LSHIFT( len, 1 );
/* Allpass filters */
SKP_Silk_allpass_int( scratch, S, A21_Resample_1_2[ 0 ], scratch + idx, len );
SKP_Silk_allpass_int( scratch + idx, S + 1, A21_Resample_1_2[ 1 ], scratch + idx + len, len );
SKP_Silk_allpass_int( scratch + idx + len, S + 2, A21_Resample_1_2[ 2 ], scratch, len );
SKP_Silk_allpass_int( scratch + len, S + 3, A20_Resample_1_2[ 0 ], scratch + idx, len );
SKP_Silk_allpass_int( scratch + idx, S + 4, A20_Resample_1_2[ 1 ], scratch + idx + len, len );
SKP_Silk_allpass_int( scratch + idx + len, S + 5, A20_Resample_1_2[ 2 ], scratch + len, len );
/* Add two allpass outputs */
for( k = 0; k < len; k++ ) {
out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( scratch[ k ] + scratch[ k + len ], 11 ) );
}
}

View File

@ -1,74 +0,0 @@
/***********************************************************************
Copyright (c) 2006-2010, 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.
***********************************************************************/
/* *
* SKP_Silk_resample_1_2_coarse.c *
* *
* Downsample by a factor 2, coarser *
* *
* Copyright 2006 (c), Skype Limited *
* Date: 060221 *
* */
#include "SKP_Silk_SigProc_FIX.h"
/* downsample by a factor 2, coarser */
void SKP_Silk_resample_1_2_coarse(
const SKP_int16 *in, /* I: 16 kHz signal [2*len] */
SKP_int32 *S, /* I/O: State vector [4] */
SKP_int16 *out, /* O: 8 kHz signal [len] */
SKP_int32 *scratch, /* I: Scratch memory [3*len] */
const SKP_int32 len /* I: Number of OUTPUT samples*/
)
{
SKP_int32 k, idx;
/* Coefficients for coarser 2-fold resampling */
const SKP_int16 A20c[ 2 ] = { 2119, 16663 };
const SKP_int16 A21c[ 2 ] = { 8050, 26861 };
/* De-interleave allpass inputs, and convert Q15 -> Q25 */
for( k = 0; k < len; k++ ) {
idx = SKP_LSHIFT( k, 1 );
scratch[ k ] = SKP_LSHIFT( (SKP_int32)in[ idx ], 10 );
scratch[ k + len ] = SKP_LSHIFT( (SKP_int32)in[ idx + 1 ], 10 );
}
idx = SKP_LSHIFT( len, 1 );
/* Allpass filters */
SKP_Silk_allpass_int( scratch, S, A21c[ 0 ], scratch + idx, len );
SKP_Silk_allpass_int( scratch + idx, S + 1, A21c[ 1 ], scratch, len );
SKP_Silk_allpass_int( scratch + len, S + 2, A20c[ 0 ], scratch + idx, len );
SKP_Silk_allpass_int( scratch + idx, S + 3, A20c[ 1 ], scratch + len, len );
/* Add two allpass outputs */
for( k = 0; k < len; k++ ) {
out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( scratch[ k ] + scratch[ k + len ], 11 ) );
}
}

View File

@ -1,71 +0,0 @@
/***********************************************************************
Copyright (c) 2006-2010, 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.
***********************************************************************/
/* *
* SKP_Silk_resample_1_2_coarsest.c *
* *
* Downsample by a factor 2, coarsest *
* *
* Copyright 2006 (c), Skype Limited *
* Date: 060221 *
* */
#include "SKP_Silk_SigProc_FIX.h"
/* Coefficients for coarsest 2-fold resampling */
static SKP_int16 A20cst[ 1 ] = { 3786 };
static SKP_int16 A21cst[ 1 ] = { 17908 };
/* Downsample by a factor 2, coarsest */
void SKP_Silk_resample_1_2_coarsest(
const SKP_int16 *in, /* I: 16 kHz signal [2*len] */
SKP_int32 *S, /* I/O: State vector [2] */
SKP_int16 *out, /* O: 8 kHz signal [len] */
SKP_int32 *scratch, /* I: Scratch memory [3*len] */
const SKP_int32 len /* I: Number of OUTPUT samples*/
)
{
SKP_int32 k, idx;
/* De-interleave allpass inputs, and convert Q15 -> Q25 */
for( k = 0; k < len; k++ ) {
idx = SKP_LSHIFT( k, 1 );
scratch[ k ] = SKP_LSHIFT( (SKP_int32)in[ idx ], 10 );
scratch[ k + len ] = SKP_LSHIFT( (SKP_int32)in[ idx + 1 ], 10 );
}
idx = SKP_LSHIFT( len, 1 );
/* Allpass filters */
SKP_Silk_allpass_int( scratch, S, A21cst[ 0 ], scratch + idx, len );
SKP_Silk_allpass_int( scratch + len, S + 1, A20cst[ 0 ], scratch, len );
/* Add two allpass outputs */
for( k = 0; k < len; k++ ) {
out[ k ] = (SKP_int16)SKP_SAT16( SKP_RSHIFT_ROUND( scratch[ k ] + scratch[ k + idx ], 11 ) );
}
}

View File

@ -1,101 +0,0 @@
/***********************************************************************
Copyright (c) 2006-2010, 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.
***********************************************************************/
/* *
* SKP_Silk_resample_1_3.c *
* *
* Downsamples by a factor 3 *
* *
* Copyright 2008 (c), Skype Limited *
* Date: 081113 *
* */
#include "SKP_Silk_SigProc_FIX.h"
#define OUT_SUBFR_LEN 80
/* Downsamples by a factor 3 */
void SKP_Silk_resample_1_3(
SKP_int16 *out, /* O: Fs_low signal [inLen/3] */
SKP_int32 *S, /* I/O: State vector [7] */
const SKP_int16 *in, /* I: Fs_high signal [inLen] */
const SKP_int32 inLen /* I: Input length, must be a multiple of 3 */
)
{
SKP_int k, outLen, LSubFrameIn, LSubFrameOut;
SKP_int32 out_tmp, limit = 102258000; // (102258000 + 1560) * 21 * 2^(-16) = 32767.5
SKP_int32 scratch0[ 3 * OUT_SUBFR_LEN ];
SKP_int32 scratch10[ OUT_SUBFR_LEN ], scratch11[ OUT_SUBFR_LEN ], scratch12[ OUT_SUBFR_LEN ];
/* coefficients for 3-fold resampling */
const SKP_int16 A30[ 2 ] = { 1773, 17818 };
const SKP_int16 A31[ 2 ] = { 4942, 25677 };
const SKP_int16 A32[ 2 ] = { 11786, 29304 };
/* Check that input is multiple of 3 */
SKP_assert( inLen % 3 == 0 );
outLen = SKP_DIV32_16( inLen, 3 );
while( outLen > 0 ) {
LSubFrameOut = SKP_min_int( OUT_SUBFR_LEN, outLen );
LSubFrameIn = SKP_SMULBB( 3, LSubFrameOut );
/* Low-pass filter, Q15 -> Q25 */
SKP_Silk_lowpass_short( in, S, scratch0, LSubFrameIn );
/* De-interleave three allpass inputs */
for( k = 0; k < LSubFrameOut; k++ ) {
scratch10[ k ] = scratch0[ 3 * k ];
scratch11[ k ] = scratch0[ 3 * k + 1 ];
scratch12[ k ] = scratch0[ 3 * k + 2 ];
}
/* Allpass filters */
SKP_Silk_allpass_int( scratch10, S + 1, A32[ 0 ], scratch0, LSubFrameOut );
SKP_Silk_allpass_int( scratch0, S + 2, A32[ 1 ], scratch10, LSubFrameOut );
SKP_Silk_allpass_int( scratch11, S + 3, A31[ 0 ], scratch0, LSubFrameOut );
SKP_Silk_allpass_int( scratch0, S + 4, A31[ 1 ], scratch11, LSubFrameOut );
SKP_Silk_allpass_int( scratch12, S + 5, A30[ 0 ], scratch0, LSubFrameOut );
SKP_Silk_allpass_int( scratch0, S + 6, A30[ 1 ], scratch12, LSubFrameOut );
/* Add three allpass outputs */
for( k = 0; k < LSubFrameOut; k++ ) {
out_tmp = scratch10[ k ] + scratch11[ k ] + scratch12[ k ];
if( out_tmp - limit > 0 ) {
out[ k ] = SKP_int16_MAX;
} else if( out_tmp + limit < 0 ) {
out[ k ] = SKP_int16_MIN;
} else {
out[ k ] = (SKP_int16) SKP_SMULWB( out_tmp + 1560, 21 );
}
}
in += LSubFrameIn;
out += LSubFrameOut;
outLen -= LSubFrameOut;
}
}

Some files were not shown because too many files have changed in this diff Show More