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_FLP_H michael@0: #define SILK_MAIN_FLP_H michael@0: michael@0: #include "SigProc_FLP.h" michael@0: #include "SigProc_FIX.h" michael@0: #include "structs_FLP.h" michael@0: #include "main.h" michael@0: #include "define.h" michael@0: #include "debug.h" michael@0: #include "entenc.h" michael@0: michael@0: #ifdef __cplusplus michael@0: extern "C" michael@0: { michael@0: #endif michael@0: michael@0: #define silk_encoder_state_Fxx silk_encoder_state_FLP michael@0: #define silk_encode_do_VAD_Fxx silk_encode_do_VAD_FLP michael@0: #define silk_encode_frame_Fxx silk_encode_frame_FLP 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_FLP( michael@0: silk_encoder_state_FLP *psEnc /* I/O Encoder state FLP */ michael@0: ); michael@0: michael@0: /* Encoder main function */ michael@0: opus_int silk_encode_frame_FLP( michael@0: silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ michael@0: opus_int32 *pnBytesOut, /* O 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_FLP *psEnc, /* I/O Encoder state FLP */ michael@0: int arch /* I Run-tim architecture */ michael@0: ); michael@0: michael@0: /* Control the Silk encoder */ michael@0: opus_int silk_control_encoder( michael@0: silk_encoder_state_FLP *psEnc, /* I/O Pointer to Silk encoder state FLP */ 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_FLP( michael@0: silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ michael@0: const silk_encoder_control_FLP *psEncCtrl, /* I Encoder control FLP */ michael@0: silk_float xw[], /* O Weighted signal */ michael@0: const silk_float 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_FLP( michael@0: silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ michael@0: silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ michael@0: const silk_float *pitch_res, /* I LPC residual from pitch analysis */ michael@0: const silk_float *x /* I Input signal [frame_length + la_shape] */ michael@0: ); michael@0: michael@0: /* Autocorrelations for a warped frequency axis */ michael@0: void silk_warped_autocorrelation_FLP( michael@0: silk_float *corr, /* O Result [order + 1] */ michael@0: const silk_float *input, /* I Input data to correlate */ michael@0: const silk_float warping, /* 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_FLP( michael@0: silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ michael@0: silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ 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_FLP( michael@0: silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ michael@0: silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ michael@0: silk_float res[], /* O Residual */ michael@0: const silk_float 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_FLP( michael@0: silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ michael@0: silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ michael@0: const silk_float res_pitch[], /* I Residual from pitch analysis */ michael@0: const silk_float 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_FLP( michael@0: silk_encoder_state *psEncC, /* I/O Encoder state */ michael@0: opus_int16 NLSF_Q15[], /* O NLSFs */ michael@0: const silk_float x[], /* I Input signal */ michael@0: const silk_float minInvGain /* I Prediction gain from LTP (dB) */ michael@0: ); michael@0: michael@0: /* LTP analysis */ michael@0: void silk_find_LTP_FLP( michael@0: silk_float b[ MAX_NB_SUBFR * LTP_ORDER ], /* O LTP coefs */ michael@0: silk_float WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Weight for LTP quantization */ michael@0: silk_float *LTPredCodGain, /* O LTP coding gain */ michael@0: const silk_float r_lpc[], /* I LPC residual */ michael@0: const opus_int lag[ MAX_NB_SUBFR ], /* I LTP lags */ michael@0: const silk_float Wght[ 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: ); michael@0: michael@0: void silk_LTP_analysis_filter_FLP( michael@0: silk_float *LTP_res, /* O LTP res MAX_NB_SUBFR*(pre_lgth+subfr_lngth) */ michael@0: const silk_float *x, /* I Input signal, with preceding samples */ michael@0: const silk_float B[ LTP_ORDER * MAX_NB_SUBFR ], /* I LTP coefficients for each subframe */ michael@0: const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */ michael@0: const silk_float invGains[ MAX_NB_SUBFR ], /* I Inverse quantization gains */ 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 Preceding samples 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_FLP( michael@0: silk_float nrgs[ MAX_NB_SUBFR ], /* O Residual energy per subframe */ michael@0: const silk_float x[], /* I Input signal */ michael@0: silk_float a[ 2 ][ MAX_LPC_ORDER ], /* I AR coefs for each frame half */ michael@0: const silk_float gains[], /* 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: /* 16th order LPC analysis filter */ michael@0: void silk_LPC_analysis_filter_FLP( michael@0: silk_float r_LPC[], /* O LPC residual signal */ michael@0: const silk_float PredCoef[], /* I LPC coefficients */ michael@0: const silk_float s[], /* I Input signal */ michael@0: const opus_int length, /* I Length of input signal */ michael@0: const opus_int Order /* I LPC order */ michael@0: ); michael@0: michael@0: /* LTP tap quantizer */ michael@0: void silk_quant_LTP_gains_FLP( michael@0: silk_float B[ MAX_NB_SUBFR * LTP_ORDER ], /* I/O (Un-)quantized LTP gains */ michael@0: opus_int8 cbk_index[ MAX_NB_SUBFR ], /* O Codebook index */ michael@0: opus_int8 *periodicity_index, /* O Periodicity index */ michael@0: opus_int32 *sum_log_gain_Q7, /* I/O Cumulative max prediction gain */ michael@0: const silk_float W[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* I Error weights */ michael@0: const opus_int mu_Q10, /* I Mu value (R/D tradeoff) */ michael@0: const opus_int lowComplexity, /* I Flag for low complexity */ michael@0: const opus_int nb_subfr /* I number of subframes */ michael@0: ); michael@0: michael@0: /* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */ michael@0: silk_float silk_residual_energy_covar_FLP( /* O Weighted residual energy */ michael@0: const silk_float *c, /* I Filter coefficients */ michael@0: silk_float *wXX, /* I/O Weighted correlation matrix, reg. out */ michael@0: const silk_float *wXx, /* I Weighted correlation vector */ michael@0: const silk_float wxx, /* I Weighted correlation value */ michael@0: const opus_int D /* I Dimension */ michael@0: ); michael@0: michael@0: /* Processing of gains */ michael@0: void silk_process_gains_FLP( michael@0: silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ michael@0: silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ 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_FLP( michael@0: const silk_float *x, /* I x vector [ L+order-1 ] used to create X */ michael@0: const opus_int L, /* I Length of vectors */ michael@0: const opus_int Order, /* I Max lag for correlation */ michael@0: silk_float *XX /* O X'*X correlation matrix [order x order] */ michael@0: ); michael@0: michael@0: /* Calculates correlation vector X'*t */ michael@0: void silk_corrVector_FLP( michael@0: const silk_float *x, /* I x vector [L+order-1] used to create X */ michael@0: const silk_float *t, /* I Target vector [L] */ michael@0: const opus_int L, /* I Length of vecors */ michael@0: const opus_int Order, /* I Max lag for correlation */ michael@0: silk_float *Xt /* O X'*t correlation vector [order] */ michael@0: ); michael@0: michael@0: /* Add noise to matrix diagonal */ michael@0: void silk_regularize_correlations_FLP( michael@0: silk_float *XX, /* I/O Correlation matrices */ michael@0: silk_float *xx, /* I/O Correlation values */ michael@0: const silk_float noise, /* I Noise energy to add */ michael@0: const opus_int D /* I Dimension of XX */ michael@0: ); michael@0: michael@0: /* Function to solve linear equation Ax = b, where A is an MxM symmetric matrix */ michael@0: void silk_solve_LDL_FLP( michael@0: silk_float *A, /* I/O Symmetric square matrix, out: reg. */ michael@0: const opus_int M, /* I Size of matrix */ michael@0: const silk_float *b, /* I Pointer to b vector */ michael@0: silk_float *x /* O Pointer to x solution vector */ michael@0: ); michael@0: michael@0: /* Apply sine window to signal vector. */ michael@0: /* Window types: */ michael@0: /* 1 -> sine window from 0 to pi/2 */ michael@0: /* 2 -> sine window from pi/2 to pi */ michael@0: void silk_apply_sine_window_FLP( michael@0: silk_float px_win[], /* O Pointer to windowed signal */ michael@0: const silk_float px[], /* I Pointer to input signal */ michael@0: const opus_int win_type, /* I Selects a window type */ michael@0: const opus_int length /* I Window length, multiple of 4 */ michael@0: ); michael@0: michael@0: /* Wrapper functions. Call flp / fix code */ michael@0: michael@0: /* Convert AR filter coefficients to NLSF parameters */ michael@0: void silk_A2NLSF_FLP( michael@0: opus_int16 *NLSF_Q15, /* O NLSF vector [ LPC_order ] */ michael@0: const silk_float *pAR, /* I LPC coefficients [ LPC_order ] */ michael@0: const opus_int LPC_order /* I LPC order */ michael@0: ); michael@0: michael@0: /* Convert NLSF parameters to AR prediction filter coefficients */ michael@0: void silk_NLSF2A_FLP( michael@0: silk_float *pAR, /* O LPC coefficients [ LPC_order ] */ michael@0: const opus_int16 *NLSF_Q15, /* I NLSF vector [ LPC_order ] */ michael@0: const opus_int LPC_order /* I LPC order */ michael@0: ); michael@0: michael@0: /* Limit, stabilize, and quantize NLSFs */ michael@0: void silk_process_NLSFs_FLP( michael@0: silk_encoder_state *psEncC, /* I/O Encoder state */ michael@0: silk_float PredCoef[ 2 ][ MAX_LPC_ORDER ], /* O Prediction coefficients */ michael@0: opus_int16 NLSF_Q15[ MAX_LPC_ORDER ], /* I/O Normalized LSFs (quant out) (0 - (2^15-1)) */ michael@0: const opus_int16 prev_NLSF_Q15[ MAX_LPC_ORDER ] /* I Previous Normalized LSFs (0 - (2^15-1)) */ michael@0: ); michael@0: michael@0: /* Floating-point Silk NSQ wrapper */ michael@0: void silk_NSQ_wrapper_FLP( michael@0: silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ michael@0: silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ michael@0: SideInfoIndices *psIndices, /* I/O Quantization indices */ michael@0: silk_nsq_state *psNSQ, /* I/O Noise Shaping Quantzation state */ michael@0: opus_int8 pulses[], /* O Quantized pulse signal */ michael@0: const silk_float x[] /* I Prefiltered input signal */ michael@0: ); michael@0: michael@0: #ifdef __cplusplus michael@0: } michael@0: #endif michael@0: michael@0: #endif