cannam@154: /*********************************************************************** cannam@154: Copyright (c) 2006-2011, Skype Limited. All rights reserved. cannam@154: Redistribution and use in source and binary forms, with or without cannam@154: modification, are permitted provided that the following conditions cannam@154: are met: cannam@154: - Redistributions of source code must retain the above copyright notice, cannam@154: this list of conditions and the following disclaimer. cannam@154: - Redistributions in binary form must reproduce the above copyright cannam@154: notice, this list of conditions and the following disclaimer in the cannam@154: documentation and/or other materials provided with the distribution. cannam@154: - Neither the name of Internet Society, IETF or IETF Trust, nor the cannam@154: names of specific contributors, may be used to endorse or promote cannam@154: products derived from this software without specific prior written cannam@154: permission. cannam@154: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" cannam@154: AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE cannam@154: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE cannam@154: ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE cannam@154: LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR cannam@154: CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF cannam@154: SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS cannam@154: INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN cannam@154: CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) cannam@154: ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE cannam@154: POSSIBILITY OF SUCH DAMAGE. cannam@154: ***********************************************************************/ cannam@154: cannam@154: #ifndef SILK_MAIN_FIX_H cannam@154: #define SILK_MAIN_FIX_H cannam@154: cannam@154: #include "SigProc_FIX.h" cannam@154: #include "structs_FIX.h" cannam@154: #include "control.h" cannam@154: #include "main.h" cannam@154: #include "PLC.h" cannam@154: #include "debug.h" cannam@154: #include "entenc.h" cannam@154: cannam@154: #if ((defined(OPUS_ARM_ASM) && defined(FIXED_POINT)) \ cannam@154: || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)) cannam@154: #include "fixed/arm/warped_autocorrelation_FIX_arm.h" cannam@154: #endif cannam@154: cannam@154: #ifndef FORCE_CPP_BUILD cannam@154: #ifdef __cplusplus cannam@154: extern "C" cannam@154: { cannam@154: #endif cannam@154: #endif cannam@154: cannam@154: #define silk_encoder_state_Fxx silk_encoder_state_FIX cannam@154: #define silk_encode_do_VAD_Fxx silk_encode_do_VAD_FIX cannam@154: #define silk_encode_frame_Fxx silk_encode_frame_FIX cannam@154: cannam@154: #define QC 10 cannam@154: #define QS 13 cannam@154: cannam@154: /*********************/ cannam@154: /* Encoder Functions */ cannam@154: /*********************/ cannam@154: cannam@154: /* High-pass filter with cutoff frequency adaptation based on pitch lag statistics */ cannam@154: void silk_HP_variable_cutoff( cannam@154: silk_encoder_state_Fxx state_Fxx[] /* I/O Encoder states */ cannam@154: ); cannam@154: cannam@154: /* Encoder main function */ cannam@154: void silk_encode_do_VAD_FIX( cannam@154: silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */ cannam@154: opus_int activity /* I Decision of Opus voice activity detector */ cannam@154: ); cannam@154: cannam@154: /* Encoder main function */ cannam@154: opus_int silk_encode_frame_FIX( cannam@154: silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */ cannam@154: opus_int32 *pnBytesOut, /* O Pointer to number of payload bytes; */ cannam@154: ec_enc *psRangeEnc, /* I/O compressor data structure */ cannam@154: opus_int condCoding, /* I The type of conditional coding to use */ cannam@154: opus_int maxBits, /* I If > 0: maximum number of output bits */ cannam@154: opus_int useCBR /* I Flag to force constant-bitrate operation */ cannam@154: ); cannam@154: cannam@154: /* Initializes the Silk encoder state */ cannam@154: opus_int silk_init_encoder( cannam@154: silk_encoder_state_Fxx *psEnc, /* I/O Pointer to Silk FIX encoder state */ cannam@154: int arch /* I Run-time architecture */ cannam@154: ); cannam@154: cannam@154: /* Control the Silk encoder */ cannam@154: opus_int silk_control_encoder( cannam@154: silk_encoder_state_Fxx *psEnc, /* I/O Pointer to Silk encoder state */ cannam@154: silk_EncControlStruct *encControl, /* I Control structure */ cannam@154: const opus_int allow_bw_switch, /* I Flag to allow switching audio bandwidth */ cannam@154: const opus_int channelNb, /* I Channel number */ cannam@154: const opus_int force_fs_kHz cannam@154: ); cannam@154: cannam@154: /**************************/ cannam@154: /* Noise shaping analysis */ cannam@154: /**************************/ cannam@154: /* Compute noise shaping coefficients and initial gain values */ cannam@154: void silk_noise_shape_analysis_FIX( cannam@154: silk_encoder_state_FIX *psEnc, /* I/O Encoder state FIX */ cannam@154: silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control FIX */ cannam@154: const opus_int16 *pitch_res, /* I LPC residual from pitch analysis */ cannam@154: const opus_int16 *x, /* I Input signal [ frame_length + la_shape ] */ cannam@154: int arch /* I Run-time architecture */ cannam@154: ); cannam@154: cannam@154: /* Autocorrelations for a warped frequency axis */ cannam@154: void silk_warped_autocorrelation_FIX_c( cannam@154: opus_int32 *corr, /* O Result [order + 1] */ cannam@154: opus_int *scale, /* O Scaling of the correlation vector */ cannam@154: const opus_int16 *input, /* I Input data to correlate */ cannam@154: const opus_int warping_Q16, /* I Warping coefficient */ cannam@154: const opus_int length, /* I Length of input */ cannam@154: const opus_int order /* I Correlation order (even) */ cannam@154: ); cannam@154: cannam@154: #if !defined(OVERRIDE_silk_warped_autocorrelation_FIX) cannam@154: #define silk_warped_autocorrelation_FIX(corr, scale, input, warping_Q16, length, order, arch) \ cannam@154: ((void)(arch), silk_warped_autocorrelation_FIX_c(corr, scale, input, warping_Q16, length, order)) cannam@154: #endif cannam@154: cannam@154: /* Calculation of LTP state scaling */ cannam@154: void silk_LTP_scale_ctrl_FIX( cannam@154: silk_encoder_state_FIX *psEnc, /* I/O encoder state */ cannam@154: silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */ cannam@154: opus_int condCoding /* I The type of conditional coding to use */ cannam@154: ); cannam@154: cannam@154: /**********************************************/ cannam@154: /* Prediction Analysis */ cannam@154: /**********************************************/ cannam@154: /* Find pitch lags */ cannam@154: void silk_find_pitch_lags_FIX( cannam@154: silk_encoder_state_FIX *psEnc, /* I/O encoder state */ cannam@154: silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */ cannam@154: opus_int16 res[], /* O residual */ cannam@154: const opus_int16 x[], /* I Speech signal */ cannam@154: int arch /* I Run-time architecture */ cannam@154: ); cannam@154: cannam@154: /* Find LPC and LTP coefficients */ cannam@154: void silk_find_pred_coefs_FIX( cannam@154: silk_encoder_state_FIX *psEnc, /* I/O encoder state */ cannam@154: silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */ cannam@154: const opus_int16 res_pitch[], /* I Residual from pitch analysis */ cannam@154: const opus_int16 x[], /* I Speech signal */ cannam@154: opus_int condCoding /* I The type of conditional coding to use */ cannam@154: ); cannam@154: cannam@154: /* LPC analysis */ cannam@154: void silk_find_LPC_FIX( cannam@154: silk_encoder_state *psEncC, /* I/O Encoder state */ cannam@154: opus_int16 NLSF_Q15[], /* O NLSFs */ cannam@154: const opus_int16 x[], /* I Input signal */ cannam@154: const opus_int32 minInvGain_Q30 /* I Inverse of max prediction gain */ cannam@154: ); cannam@154: cannam@154: /* LTP analysis */ cannam@154: void silk_find_LTP_FIX( cannam@154: opus_int32 XXLTP_Q17[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Correlation matrix */ cannam@154: opus_int32 xXLTP_Q17[ MAX_NB_SUBFR * LTP_ORDER ], /* O Correlation vector */ cannam@154: const opus_int16 r_lpc[], /* I Residual signal after LPC */ cannam@154: const opus_int lag[ MAX_NB_SUBFR ], /* I LTP lags */ cannam@154: const opus_int subfr_length, /* I Subframe length */ cannam@154: const opus_int nb_subfr, /* I Number of subframes */ cannam@154: int arch /* I Run-time architecture */ cannam@154: ); cannam@154: cannam@154: void silk_LTP_analysis_filter_FIX( cannam@154: opus_int16 *LTP_res, /* O LTP residual signal of length MAX_NB_SUBFR * ( pre_length + subfr_length ) */ cannam@154: const opus_int16 *x, /* I Pointer to input signal with at least max( pitchL ) preceding samples */ cannam@154: const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ],/* I LTP_ORDER LTP coefficients for each MAX_NB_SUBFR subframe */ cannam@154: const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lag, one for each subframe */ cannam@154: const opus_int32 invGains_Q16[ MAX_NB_SUBFR ], /* I Inverse quantization gains, one for each subframe */ cannam@154: const opus_int subfr_length, /* I Length of each subframe */ cannam@154: const opus_int nb_subfr, /* I Number of subframes */ cannam@154: const opus_int pre_length /* I Length of the preceding samples starting at &x[0] for each subframe */ cannam@154: ); cannam@154: cannam@154: /* Calculates residual energies of input subframes where all subframes have LPC_order */ cannam@154: /* of preceding samples */ cannam@154: void silk_residual_energy_FIX( cannam@154: opus_int32 nrgs[ MAX_NB_SUBFR ], /* O Residual energy per subframe */ cannam@154: opus_int nrgsQ[ MAX_NB_SUBFR ], /* O Q value per subframe */ cannam@154: const opus_int16 x[], /* I Input signal */ cannam@154: opus_int16 a_Q12[ 2 ][ MAX_LPC_ORDER ], /* I AR coefs for each frame half */ cannam@154: const opus_int32 gains[ MAX_NB_SUBFR ], /* I Quantization gains */ cannam@154: const opus_int subfr_length, /* I Subframe length */ cannam@154: const opus_int nb_subfr, /* I Number of subframes */ cannam@154: const opus_int LPC_order, /* I LPC order */ cannam@154: int arch /* I Run-time architecture */ cannam@154: ); cannam@154: cannam@154: /* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */ cannam@154: opus_int32 silk_residual_energy16_covar_FIX( cannam@154: const opus_int16 *c, /* I Prediction vector */ cannam@154: const opus_int32 *wXX, /* I Correlation matrix */ cannam@154: const opus_int32 *wXx, /* I Correlation vector */ cannam@154: opus_int32 wxx, /* I Signal energy */ cannam@154: opus_int D, /* I Dimension */ cannam@154: opus_int cQ /* I Q value for c vector 0 - 15 */ cannam@154: ); cannam@154: cannam@154: /* Processing of gains */ cannam@154: void silk_process_gains_FIX( cannam@154: silk_encoder_state_FIX *psEnc, /* I/O Encoder state */ cannam@154: silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control */ cannam@154: opus_int condCoding /* I The type of conditional coding to use */ cannam@154: ); cannam@154: cannam@154: /******************/ cannam@154: /* Linear Algebra */ cannam@154: /******************/ cannam@154: /* Calculates correlation matrix X'*X */ cannam@154: void silk_corrMatrix_FIX( cannam@154: const opus_int16 *x, /* I x vector [L + order - 1] used to form data matrix X */ cannam@154: const opus_int L, /* I Length of vectors */ cannam@154: const opus_int order, /* I Max lag for correlation */ cannam@154: opus_int32 *XX, /* O Pointer to X'*X correlation matrix [ order x order ] */ cannam@154: opus_int32 *nrg, /* O Energy of x vector */ cannam@154: opus_int *rshifts, /* O Right shifts of correlations */ cannam@154: int arch /* I Run-time architecture */ cannam@154: ); cannam@154: cannam@154: /* Calculates correlation vector X'*t */ cannam@154: void silk_corrVector_FIX( cannam@154: const opus_int16 *x, /* I x vector [L + order - 1] used to form data matrix X */ cannam@154: const opus_int16 *t, /* I Target vector [L] */ cannam@154: const opus_int L, /* I Length of vectors */ cannam@154: const opus_int order, /* I Max lag for correlation */ cannam@154: opus_int32 *Xt, /* O Pointer to X'*t correlation vector [order] */ cannam@154: const opus_int rshifts, /* I Right shifts of correlations */ cannam@154: int arch /* I Run-time architecture */ cannam@154: ); cannam@154: cannam@154: #ifndef FORCE_CPP_BUILD cannam@154: #ifdef __cplusplus cannam@154: } cannam@154: #endif /* __cplusplus */ cannam@154: #endif /* FORCE_CPP_BUILD */ cannam@154: #endif /* SILK_MAIN_FIX_H */