1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libopus/silk/fixed/main_FIX.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,257 @@ 1.4 +/*********************************************************************** 1.5 +Copyright (c) 2006-2011, Skype Limited. All rights reserved. 1.6 +Redistribution and use in source and binary forms, with or without 1.7 +modification, are permitted provided that the following conditions 1.8 +are met: 1.9 +- Redistributions of source code must retain the above copyright notice, 1.10 +this list of conditions and the following disclaimer. 1.11 +- Redistributions in binary form must reproduce the above copyright 1.12 +notice, this list of conditions and the following disclaimer in the 1.13 +documentation and/or other materials provided with the distribution. 1.14 +- Neither the name of Internet Society, IETF or IETF Trust, nor the 1.15 +names of specific contributors, may be used to endorse or promote 1.16 +products derived from this software without specific prior written 1.17 +permission. 1.18 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 1.19 +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.20 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1.21 +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 1.22 +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1.23 +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1.24 +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1.25 +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1.26 +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.27 +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1.28 +POSSIBILITY OF SUCH DAMAGE. 1.29 +***********************************************************************/ 1.30 + 1.31 +#ifndef SILK_MAIN_FIX_H 1.32 +#define SILK_MAIN_FIX_H 1.33 + 1.34 +#include "SigProc_FIX.h" 1.35 +#include "structs_FIX.h" 1.36 +#include "control.h" 1.37 +#include "main.h" 1.38 +#include "PLC.h" 1.39 +#include "debug.h" 1.40 +#include "entenc.h" 1.41 + 1.42 +#ifndef FORCE_CPP_BUILD 1.43 +#ifdef __cplusplus 1.44 +extern "C" 1.45 +{ 1.46 +#endif 1.47 +#endif 1.48 + 1.49 +#define silk_encoder_state_Fxx silk_encoder_state_FIX 1.50 +#define silk_encode_do_VAD_Fxx silk_encode_do_VAD_FIX 1.51 +#define silk_encode_frame_Fxx silk_encode_frame_FIX 1.52 + 1.53 +/*********************/ 1.54 +/* Encoder Functions */ 1.55 +/*********************/ 1.56 + 1.57 +/* High-pass filter with cutoff frequency adaptation based on pitch lag statistics */ 1.58 +void silk_HP_variable_cutoff( 1.59 + silk_encoder_state_Fxx state_Fxx[] /* I/O Encoder states */ 1.60 +); 1.61 + 1.62 +/* Encoder main function */ 1.63 +void silk_encode_do_VAD_FIX( 1.64 + silk_encoder_state_FIX *psEnc /* I/O Pointer to Silk FIX encoder state */ 1.65 +); 1.66 + 1.67 +/* Encoder main function */ 1.68 +opus_int silk_encode_frame_FIX( 1.69 + silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */ 1.70 + opus_int32 *pnBytesOut, /* O Pointer to number of payload bytes; */ 1.71 + ec_enc *psRangeEnc, /* I/O compressor data structure */ 1.72 + opus_int condCoding, /* I The type of conditional coding to use */ 1.73 + opus_int maxBits, /* I If > 0: maximum number of output bits */ 1.74 + opus_int useCBR /* I Flag to force constant-bitrate operation */ 1.75 +); 1.76 + 1.77 +/* Initializes the Silk encoder state */ 1.78 +opus_int silk_init_encoder( 1.79 + silk_encoder_state_Fxx *psEnc, /* I/O Pointer to Silk FIX encoder state */ 1.80 + int arch /* I Run-time architecture */ 1.81 +); 1.82 + 1.83 +/* Control the Silk encoder */ 1.84 +opus_int silk_control_encoder( 1.85 + silk_encoder_state_Fxx *psEnc, /* I/O Pointer to Silk encoder state */ 1.86 + silk_EncControlStruct *encControl, /* I Control structure */ 1.87 + const opus_int32 TargetRate_bps, /* I Target max bitrate (bps) */ 1.88 + const opus_int allow_bw_switch, /* I Flag to allow switching audio bandwidth */ 1.89 + const opus_int channelNb, /* I Channel number */ 1.90 + const opus_int force_fs_kHz 1.91 +); 1.92 + 1.93 +/****************/ 1.94 +/* Prefiltering */ 1.95 +/****************/ 1.96 +void silk_prefilter_FIX( 1.97 + silk_encoder_state_FIX *psEnc, /* I/O Encoder state */ 1.98 + const silk_encoder_control_FIX *psEncCtrl, /* I Encoder control */ 1.99 + opus_int32 xw_Q10[], /* O Weighted signal */ 1.100 + const opus_int16 x[] /* I Speech signal */ 1.101 +); 1.102 + 1.103 +/**************************/ 1.104 +/* Noise shaping analysis */ 1.105 +/**************************/ 1.106 +/* Compute noise shaping coefficients and initial gain values */ 1.107 +void silk_noise_shape_analysis_FIX( 1.108 + silk_encoder_state_FIX *psEnc, /* I/O Encoder state FIX */ 1.109 + silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control FIX */ 1.110 + const opus_int16 *pitch_res, /* I LPC residual from pitch analysis */ 1.111 + const opus_int16 *x, /* I Input signal [ frame_length + la_shape ] */ 1.112 + int arch /* I Run-time architecture */ 1.113 +); 1.114 + 1.115 +/* Autocorrelations for a warped frequency axis */ 1.116 +void silk_warped_autocorrelation_FIX( 1.117 + opus_int32 *corr, /* O Result [order + 1] */ 1.118 + opus_int *scale, /* O Scaling of the correlation vector */ 1.119 + const opus_int16 *input, /* I Input data to correlate */ 1.120 + const opus_int warping_Q16, /* I Warping coefficient */ 1.121 + const opus_int length, /* I Length of input */ 1.122 + const opus_int order /* I Correlation order (even) */ 1.123 +); 1.124 + 1.125 +/* Calculation of LTP state scaling */ 1.126 +void silk_LTP_scale_ctrl_FIX( 1.127 + silk_encoder_state_FIX *psEnc, /* I/O encoder state */ 1.128 + silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */ 1.129 + opus_int condCoding /* I The type of conditional coding to use */ 1.130 +); 1.131 + 1.132 +/**********************************************/ 1.133 +/* Prediction Analysis */ 1.134 +/**********************************************/ 1.135 +/* Find pitch lags */ 1.136 +void silk_find_pitch_lags_FIX( 1.137 + silk_encoder_state_FIX *psEnc, /* I/O encoder state */ 1.138 + silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */ 1.139 + opus_int16 res[], /* O residual */ 1.140 + const opus_int16 x[], /* I Speech signal */ 1.141 + int arch /* I Run-time architecture */ 1.142 +); 1.143 + 1.144 +/* Find LPC and LTP coefficients */ 1.145 +void silk_find_pred_coefs_FIX( 1.146 + silk_encoder_state_FIX *psEnc, /* I/O encoder state */ 1.147 + silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */ 1.148 + const opus_int16 res_pitch[], /* I Residual from pitch analysis */ 1.149 + const opus_int16 x[], /* I Speech signal */ 1.150 + opus_int condCoding /* I The type of conditional coding to use */ 1.151 +); 1.152 + 1.153 +/* LPC analysis */ 1.154 +void silk_find_LPC_FIX( 1.155 + silk_encoder_state *psEncC, /* I/O Encoder state */ 1.156 + opus_int16 NLSF_Q15[], /* O NLSFs */ 1.157 + const opus_int16 x[], /* I Input signal */ 1.158 + const opus_int32 minInvGain_Q30 /* I Inverse of max prediction gain */ 1.159 +); 1.160 + 1.161 +/* LTP analysis */ 1.162 +void silk_find_LTP_FIX( 1.163 + opus_int16 b_Q14[ MAX_NB_SUBFR * LTP_ORDER ], /* O LTP coefs */ 1.164 + opus_int32 WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Weight for LTP quantization */ 1.165 + opus_int *LTPredCodGain_Q7, /* O LTP coding gain */ 1.166 + const opus_int16 r_lpc[], /* I residual signal after LPC signal + state for first 10 ms */ 1.167 + const opus_int lag[ MAX_NB_SUBFR ], /* I LTP lags */ 1.168 + const opus_int32 Wght_Q15[ MAX_NB_SUBFR ], /* I weights */ 1.169 + const opus_int subfr_length, /* I subframe length */ 1.170 + const opus_int nb_subfr, /* I number of subframes */ 1.171 + const opus_int mem_offset, /* I number of samples in LTP memory */ 1.172 + opus_int corr_rshifts[ MAX_NB_SUBFR ] /* O right shifts applied to correlations */ 1.173 +); 1.174 + 1.175 +void silk_LTP_analysis_filter_FIX( 1.176 + opus_int16 *LTP_res, /* O LTP residual signal of length MAX_NB_SUBFR * ( pre_length + subfr_length ) */ 1.177 + const opus_int16 *x, /* I Pointer to input signal with at least max( pitchL ) preceding samples */ 1.178 + const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ],/* I LTP_ORDER LTP coefficients for each MAX_NB_SUBFR subframe */ 1.179 + const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lag, one for each subframe */ 1.180 + const opus_int32 invGains_Q16[ MAX_NB_SUBFR ], /* I Inverse quantization gains, one for each subframe */ 1.181 + const opus_int subfr_length, /* I Length of each subframe */ 1.182 + const opus_int nb_subfr, /* I Number of subframes */ 1.183 + const opus_int pre_length /* I Length of the preceding samples starting at &x[0] for each subframe */ 1.184 +); 1.185 + 1.186 +/* Calculates residual energies of input subframes where all subframes have LPC_order */ 1.187 +/* of preceding samples */ 1.188 +void silk_residual_energy_FIX( 1.189 + opus_int32 nrgs[ MAX_NB_SUBFR ], /* O Residual energy per subframe */ 1.190 + opus_int nrgsQ[ MAX_NB_SUBFR ], /* O Q value per subframe */ 1.191 + const opus_int16 x[], /* I Input signal */ 1.192 + opus_int16 a_Q12[ 2 ][ MAX_LPC_ORDER ], /* I AR coefs for each frame half */ 1.193 + const opus_int32 gains[ MAX_NB_SUBFR ], /* I Quantization gains */ 1.194 + const opus_int subfr_length, /* I Subframe length */ 1.195 + const opus_int nb_subfr, /* I Number of subframes */ 1.196 + const opus_int LPC_order /* I LPC order */ 1.197 +); 1.198 + 1.199 +/* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */ 1.200 +opus_int32 silk_residual_energy16_covar_FIX( 1.201 + const opus_int16 *c, /* I Prediction vector */ 1.202 + const opus_int32 *wXX, /* I Correlation matrix */ 1.203 + const opus_int32 *wXx, /* I Correlation vector */ 1.204 + opus_int32 wxx, /* I Signal energy */ 1.205 + opus_int D, /* I Dimension */ 1.206 + opus_int cQ /* I Q value for c vector 0 - 15 */ 1.207 +); 1.208 + 1.209 +/* Processing of gains */ 1.210 +void silk_process_gains_FIX( 1.211 + silk_encoder_state_FIX *psEnc, /* I/O Encoder state */ 1.212 + silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control */ 1.213 + opus_int condCoding /* I The type of conditional coding to use */ 1.214 +); 1.215 + 1.216 +/******************/ 1.217 +/* Linear Algebra */ 1.218 +/******************/ 1.219 +/* Calculates correlation matrix X'*X */ 1.220 +void silk_corrMatrix_FIX( 1.221 + const opus_int16 *x, /* I x vector [L + order - 1] used to form data matrix X */ 1.222 + const opus_int L, /* I Length of vectors */ 1.223 + const opus_int order, /* I Max lag for correlation */ 1.224 + const opus_int head_room, /* I Desired headroom */ 1.225 + opus_int32 *XX, /* O Pointer to X'*X correlation matrix [ order x order ] */ 1.226 + opus_int *rshifts /* I/O Right shifts of correlations */ 1.227 +); 1.228 + 1.229 +/* Calculates correlation vector X'*t */ 1.230 +void silk_corrVector_FIX( 1.231 + const opus_int16 *x, /* I x vector [L + order - 1] used to form data matrix X */ 1.232 + const opus_int16 *t, /* I Target vector [L] */ 1.233 + const opus_int L, /* I Length of vectors */ 1.234 + const opus_int order, /* I Max lag for correlation */ 1.235 + opus_int32 *Xt, /* O Pointer to X'*t correlation vector [order] */ 1.236 + const opus_int rshifts /* I Right shifts of correlations */ 1.237 +); 1.238 + 1.239 +/* Add noise to matrix diagonal */ 1.240 +void silk_regularize_correlations_FIX( 1.241 + opus_int32 *XX, /* I/O Correlation matrices */ 1.242 + opus_int32 *xx, /* I/O Correlation values */ 1.243 + opus_int32 noise, /* I Noise to add */ 1.244 + opus_int D /* I Dimension of XX */ 1.245 +); 1.246 + 1.247 +/* Solves Ax = b, assuming A is symmetric */ 1.248 +void silk_solve_LDL_FIX( 1.249 + opus_int32 *A, /* I Pointer to symetric square matrix A */ 1.250 + opus_int M, /* I Size of matrix */ 1.251 + const opus_int32 *b, /* I Pointer to b vector */ 1.252 + opus_int32 *x_Q16 /* O Pointer to x solution vector */ 1.253 +); 1.254 + 1.255 +#ifndef FORCE_CPP_BUILD 1.256 +#ifdef __cplusplus 1.257 +} 1.258 +#endif /* __cplusplus */ 1.259 +#endif /* FORCE_CPP_BUILD */ 1.260 +#endif /* SILK_MAIN_FIX_H */