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