1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libopus/silk/structs.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,327 @@ 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_STRUCTS_H 1.32 +#define SILK_STRUCTS_H 1.33 + 1.34 +#include "typedef.h" 1.35 +#include "SigProc_FIX.h" 1.36 +#include "define.h" 1.37 +#include "entenc.h" 1.38 +#include "entdec.h" 1.39 + 1.40 +#ifdef __cplusplus 1.41 +extern "C" 1.42 +{ 1.43 +#endif 1.44 + 1.45 +/************************************/ 1.46 +/* Noise shaping quantization state */ 1.47 +/************************************/ 1.48 +typedef struct { 1.49 + opus_int16 xq[ 2 * MAX_FRAME_LENGTH ]; /* Buffer for quantized output signal */ 1.50 + opus_int32 sLTP_shp_Q14[ 2 * MAX_FRAME_LENGTH ]; 1.51 + opus_int32 sLPC_Q14[ MAX_SUB_FRAME_LENGTH + NSQ_LPC_BUF_LENGTH ]; 1.52 + opus_int32 sAR2_Q14[ MAX_SHAPE_LPC_ORDER ]; 1.53 + opus_int32 sLF_AR_shp_Q14; 1.54 + opus_int lagPrev; 1.55 + opus_int sLTP_buf_idx; 1.56 + opus_int sLTP_shp_buf_idx; 1.57 + opus_int32 rand_seed; 1.58 + opus_int32 prev_gain_Q16; 1.59 + opus_int rewhite_flag; 1.60 +} silk_nsq_state; 1.61 + 1.62 +/********************************/ 1.63 +/* VAD state */ 1.64 +/********************************/ 1.65 +typedef struct { 1.66 + opus_int32 AnaState[ 2 ]; /* Analysis filterbank state: 0-8 kHz */ 1.67 + opus_int32 AnaState1[ 2 ]; /* Analysis filterbank state: 0-4 kHz */ 1.68 + opus_int32 AnaState2[ 2 ]; /* Analysis filterbank state: 0-2 kHz */ 1.69 + opus_int32 XnrgSubfr[ VAD_N_BANDS ]; /* Subframe energies */ 1.70 + opus_int32 NrgRatioSmth_Q8[ VAD_N_BANDS ]; /* Smoothed energy level in each band */ 1.71 + opus_int16 HPstate; /* State of differentiator in the lowest band */ 1.72 + opus_int32 NL[ VAD_N_BANDS ]; /* Noise energy level in each band */ 1.73 + opus_int32 inv_NL[ VAD_N_BANDS ]; /* Inverse noise energy level in each band */ 1.74 + opus_int32 NoiseLevelBias[ VAD_N_BANDS ]; /* Noise level estimator bias/offset */ 1.75 + opus_int32 counter; /* Frame counter used in the initial phase */ 1.76 +} silk_VAD_state; 1.77 + 1.78 +/* Variable cut-off low-pass filter state */ 1.79 +typedef struct { 1.80 + opus_int32 In_LP_State[ 2 ]; /* Low pass filter state */ 1.81 + opus_int32 transition_frame_no; /* Counter which is mapped to a cut-off frequency */ 1.82 + opus_int mode; /* Operating mode, <0: switch down, >0: switch up; 0: do nothing */ 1.83 +} silk_LP_state; 1.84 + 1.85 +/* Structure containing NLSF codebook */ 1.86 +typedef struct { 1.87 + const opus_int16 nVectors; 1.88 + const opus_int16 order; 1.89 + const opus_int16 quantStepSize_Q16; 1.90 + const opus_int16 invQuantStepSize_Q6; 1.91 + const opus_uint8 *CB1_NLSF_Q8; 1.92 + const opus_uint8 *CB1_iCDF; 1.93 + const opus_uint8 *pred_Q8; 1.94 + const opus_uint8 *ec_sel; 1.95 + const opus_uint8 *ec_iCDF; 1.96 + const opus_uint8 *ec_Rates_Q5; 1.97 + const opus_int16 *deltaMin_Q15; 1.98 +} silk_NLSF_CB_struct; 1.99 + 1.100 +typedef struct { 1.101 + opus_int16 pred_prev_Q13[ 2 ]; 1.102 + opus_int16 sMid[ 2 ]; 1.103 + opus_int16 sSide[ 2 ]; 1.104 + opus_int32 mid_side_amp_Q0[ 4 ]; 1.105 + opus_int16 smth_width_Q14; 1.106 + opus_int16 width_prev_Q14; 1.107 + opus_int16 silent_side_len; 1.108 + opus_int8 predIx[ MAX_FRAMES_PER_PACKET ][ 2 ][ 3 ]; 1.109 + opus_int8 mid_only_flags[ MAX_FRAMES_PER_PACKET ]; 1.110 +} stereo_enc_state; 1.111 + 1.112 +typedef struct { 1.113 + opus_int16 pred_prev_Q13[ 2 ]; 1.114 + opus_int16 sMid[ 2 ]; 1.115 + opus_int16 sSide[ 2 ]; 1.116 +} stereo_dec_state; 1.117 + 1.118 +typedef struct { 1.119 + opus_int8 GainsIndices[ MAX_NB_SUBFR ]; 1.120 + opus_int8 LTPIndex[ MAX_NB_SUBFR ]; 1.121 + opus_int8 NLSFIndices[ MAX_LPC_ORDER + 1 ]; 1.122 + opus_int16 lagIndex; 1.123 + opus_int8 contourIndex; 1.124 + opus_int8 signalType; 1.125 + opus_int8 quantOffsetType; 1.126 + opus_int8 NLSFInterpCoef_Q2; 1.127 + opus_int8 PERIndex; 1.128 + opus_int8 LTP_scaleIndex; 1.129 + opus_int8 Seed; 1.130 +} SideInfoIndices; 1.131 + 1.132 +/********************************/ 1.133 +/* Encoder state */ 1.134 +/********************************/ 1.135 +typedef struct { 1.136 + opus_int32 In_HP_State[ 2 ]; /* High pass filter state */ 1.137 + opus_int32 variable_HP_smth1_Q15; /* State of first smoother */ 1.138 + opus_int32 variable_HP_smth2_Q15; /* State of second smoother */ 1.139 + silk_LP_state sLP; /* Low pass filter state */ 1.140 + silk_VAD_state sVAD; /* Voice activity detector state */ 1.141 + silk_nsq_state sNSQ; /* Noise Shape Quantizer State */ 1.142 + opus_int16 prev_NLSFq_Q15[ MAX_LPC_ORDER ]; /* Previously quantized NLSF vector */ 1.143 + opus_int speech_activity_Q8; /* Speech activity */ 1.144 + opus_int allow_bandwidth_switch; /* Flag indicating that switching of internal bandwidth is allowed */ 1.145 + opus_int8 LBRRprevLastGainIndex; 1.146 + opus_int8 prevSignalType; 1.147 + opus_int prevLag; 1.148 + opus_int pitch_LPC_win_length; 1.149 + opus_int max_pitch_lag; /* Highest possible pitch lag (samples) */ 1.150 + opus_int32 API_fs_Hz; /* API sampling frequency (Hz) */ 1.151 + opus_int32 prev_API_fs_Hz; /* Previous API sampling frequency (Hz) */ 1.152 + opus_int maxInternal_fs_Hz; /* Maximum internal sampling frequency (Hz) */ 1.153 + opus_int minInternal_fs_Hz; /* Minimum internal sampling frequency (Hz) */ 1.154 + opus_int desiredInternal_fs_Hz; /* Soft request for internal sampling frequency (Hz) */ 1.155 + opus_int fs_kHz; /* Internal sampling frequency (kHz) */ 1.156 + opus_int nb_subfr; /* Number of 5 ms subframes in a frame */ 1.157 + opus_int frame_length; /* Frame length (samples) */ 1.158 + opus_int subfr_length; /* Subframe length (samples) */ 1.159 + opus_int ltp_mem_length; /* Length of LTP memory */ 1.160 + opus_int la_pitch; /* Look-ahead for pitch analysis (samples) */ 1.161 + opus_int la_shape; /* Look-ahead for noise shape analysis (samples) */ 1.162 + opus_int shapeWinLength; /* Window length for noise shape analysis (samples) */ 1.163 + opus_int32 TargetRate_bps; /* Target bitrate (bps) */ 1.164 + opus_int PacketSize_ms; /* Number of milliseconds to put in each packet */ 1.165 + opus_int PacketLoss_perc; /* Packet loss rate measured by farend */ 1.166 + opus_int32 frameCounter; 1.167 + opus_int Complexity; /* Complexity setting */ 1.168 + opus_int nStatesDelayedDecision; /* Number of states in delayed decision quantization */ 1.169 + opus_int useInterpolatedNLSFs; /* Flag for using NLSF interpolation */ 1.170 + opus_int shapingLPCOrder; /* Filter order for noise shaping filters */ 1.171 + opus_int predictLPCOrder; /* Filter order for prediction filters */ 1.172 + opus_int pitchEstimationComplexity; /* Complexity level for pitch estimator */ 1.173 + opus_int pitchEstimationLPCOrder; /* Whitening filter order for pitch estimator */ 1.174 + opus_int32 pitchEstimationThreshold_Q16; /* Threshold for pitch estimator */ 1.175 + opus_int LTPQuantLowComplexity; /* Flag for low complexity LTP quantization */ 1.176 + opus_int mu_LTP_Q9; /* Rate-distortion tradeoff in LTP quantization */ 1.177 + opus_int32 sum_log_gain_Q7; /* Cumulative max prediction gain */ 1.178 + opus_int NLSF_MSVQ_Survivors; /* Number of survivors in NLSF MSVQ */ 1.179 + opus_int first_frame_after_reset; /* Flag for deactivating NLSF interpolation, pitch prediction */ 1.180 + opus_int controlled_since_last_payload; /* Flag for ensuring codec_control only runs once per packet */ 1.181 + opus_int warping_Q16; /* Warping parameter for warped noise shaping */ 1.182 + opus_int useCBR; /* Flag to enable constant bitrate */ 1.183 + opus_int prefillFlag; /* Flag to indicate that only buffers are prefilled, no coding */ 1.184 + const opus_uint8 *pitch_lag_low_bits_iCDF; /* Pointer to iCDF table for low bits of pitch lag index */ 1.185 + const opus_uint8 *pitch_contour_iCDF; /* Pointer to iCDF table for pitch contour index */ 1.186 + const silk_NLSF_CB_struct *psNLSF_CB; /* Pointer to NLSF codebook */ 1.187 + opus_int input_quality_bands_Q15[ VAD_N_BANDS ]; 1.188 + opus_int input_tilt_Q15; 1.189 + opus_int SNR_dB_Q7; /* Quality setting */ 1.190 + 1.191 + opus_int8 VAD_flags[ MAX_FRAMES_PER_PACKET ]; 1.192 + opus_int8 LBRR_flag; 1.193 + opus_int LBRR_flags[ MAX_FRAMES_PER_PACKET ]; 1.194 + 1.195 + SideInfoIndices indices; 1.196 + opus_int8 pulses[ MAX_FRAME_LENGTH ]; 1.197 + 1.198 + int arch; 1.199 + 1.200 + /* Input/output buffering */ 1.201 + opus_int16 inputBuf[ MAX_FRAME_LENGTH + 2 ]; /* Buffer containing input signal */ 1.202 + opus_int inputBufIx; 1.203 + opus_int nFramesPerPacket; 1.204 + opus_int nFramesEncoded; /* Number of frames analyzed in current packet */ 1.205 + 1.206 + opus_int nChannelsAPI; 1.207 + opus_int nChannelsInternal; 1.208 + opus_int channelNb; 1.209 + 1.210 + /* Parameters For LTP scaling Control */ 1.211 + opus_int frames_since_onset; 1.212 + 1.213 + /* Specifically for entropy coding */ 1.214 + opus_int ec_prevSignalType; 1.215 + opus_int16 ec_prevLagIndex; 1.216 + 1.217 + silk_resampler_state_struct resampler_state; 1.218 + 1.219 + /* DTX */ 1.220 + opus_int useDTX; /* Flag to enable DTX */ 1.221 + opus_int inDTX; /* Flag to signal DTX period */ 1.222 + opus_int noSpeechCounter; /* Counts concecutive nonactive frames, used by DTX */ 1.223 + 1.224 + /* Inband Low Bitrate Redundancy (LBRR) data */ 1.225 + opus_int useInBandFEC; /* Saves the API setting for query */ 1.226 + opus_int LBRR_enabled; /* Depends on useInBandFRC, bitrate and packet loss rate */ 1.227 + opus_int LBRR_GainIncreases; /* Gains increment for coding LBRR frames */ 1.228 + SideInfoIndices indices_LBRR[ MAX_FRAMES_PER_PACKET ]; 1.229 + opus_int8 pulses_LBRR[ MAX_FRAMES_PER_PACKET ][ MAX_FRAME_LENGTH ]; 1.230 +} silk_encoder_state; 1.231 + 1.232 + 1.233 +/* Struct for Packet Loss Concealment */ 1.234 +typedef struct { 1.235 + opus_int32 pitchL_Q8; /* Pitch lag to use for voiced concealment */ 1.236 + opus_int16 LTPCoef_Q14[ LTP_ORDER ]; /* LTP coeficients to use for voiced concealment */ 1.237 + opus_int16 prevLPC_Q12[ MAX_LPC_ORDER ]; 1.238 + opus_int last_frame_lost; /* Was previous frame lost */ 1.239 + opus_int32 rand_seed; /* Seed for unvoiced signal generation */ 1.240 + opus_int16 randScale_Q14; /* Scaling of unvoiced random signal */ 1.241 + opus_int32 conc_energy; 1.242 + opus_int conc_energy_shift; 1.243 + opus_int16 prevLTP_scale_Q14; 1.244 + opus_int32 prevGain_Q16[ 2 ]; 1.245 + opus_int fs_kHz; 1.246 + opus_int nb_subfr; 1.247 + opus_int subfr_length; 1.248 +} silk_PLC_struct; 1.249 + 1.250 +/* Struct for CNG */ 1.251 +typedef struct { 1.252 + opus_int32 CNG_exc_buf_Q14[ MAX_FRAME_LENGTH ]; 1.253 + opus_int16 CNG_smth_NLSF_Q15[ MAX_LPC_ORDER ]; 1.254 + opus_int32 CNG_synth_state[ MAX_LPC_ORDER ]; 1.255 + opus_int32 CNG_smth_Gain_Q16; 1.256 + opus_int32 rand_seed; 1.257 + opus_int fs_kHz; 1.258 +} silk_CNG_struct; 1.259 + 1.260 +/********************************/ 1.261 +/* Decoder state */ 1.262 +/********************************/ 1.263 +typedef struct { 1.264 + opus_int32 prev_gain_Q16; 1.265 + opus_int32 exc_Q14[ MAX_FRAME_LENGTH ]; 1.266 + opus_int32 sLPC_Q14_buf[ MAX_LPC_ORDER ]; 1.267 + opus_int16 outBuf[ MAX_FRAME_LENGTH + 2 * MAX_SUB_FRAME_LENGTH ]; /* Buffer for output signal */ 1.268 + opus_int lagPrev; /* Previous Lag */ 1.269 + opus_int8 LastGainIndex; /* Previous gain index */ 1.270 + opus_int fs_kHz; /* Sampling frequency in kHz */ 1.271 + opus_int32 fs_API_hz; /* API sample frequency (Hz) */ 1.272 + opus_int nb_subfr; /* Number of 5 ms subframes in a frame */ 1.273 + opus_int frame_length; /* Frame length (samples) */ 1.274 + opus_int subfr_length; /* Subframe length (samples) */ 1.275 + opus_int ltp_mem_length; /* Length of LTP memory */ 1.276 + opus_int LPC_order; /* LPC order */ 1.277 + opus_int16 prevNLSF_Q15[ MAX_LPC_ORDER ]; /* Used to interpolate LSFs */ 1.278 + opus_int first_frame_after_reset; /* Flag for deactivating NLSF interpolation */ 1.279 + const opus_uint8 *pitch_lag_low_bits_iCDF; /* Pointer to iCDF table for low bits of pitch lag index */ 1.280 + const opus_uint8 *pitch_contour_iCDF; /* Pointer to iCDF table for pitch contour index */ 1.281 + 1.282 + /* For buffering payload in case of more frames per packet */ 1.283 + opus_int nFramesDecoded; 1.284 + opus_int nFramesPerPacket; 1.285 + 1.286 + /* Specifically for entropy coding */ 1.287 + opus_int ec_prevSignalType; 1.288 + opus_int16 ec_prevLagIndex; 1.289 + 1.290 + opus_int VAD_flags[ MAX_FRAMES_PER_PACKET ]; 1.291 + opus_int LBRR_flag; 1.292 + opus_int LBRR_flags[ MAX_FRAMES_PER_PACKET ]; 1.293 + 1.294 + silk_resampler_state_struct resampler_state; 1.295 + 1.296 + const silk_NLSF_CB_struct *psNLSF_CB; /* Pointer to NLSF codebook */ 1.297 + 1.298 + /* Quantization indices */ 1.299 + SideInfoIndices indices; 1.300 + 1.301 + /* CNG state */ 1.302 + silk_CNG_struct sCNG; 1.303 + 1.304 + /* Stuff used for PLC */ 1.305 + opus_int lossCnt; 1.306 + opus_int prevSignalType; 1.307 + 1.308 + silk_PLC_struct sPLC; 1.309 + 1.310 +} silk_decoder_state; 1.311 + 1.312 +/************************/ 1.313 +/* Decoder control */ 1.314 +/************************/ 1.315 +typedef struct { 1.316 + /* Prediction and coding parameters */ 1.317 + opus_int pitchL[ MAX_NB_SUBFR ]; 1.318 + opus_int32 Gains_Q16[ MAX_NB_SUBFR ]; 1.319 + /* Holds interpolated and final coefficients, 4-byte aligned */ 1.320 + silk_DWORD_ALIGN opus_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ]; 1.321 + opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ]; 1.322 + opus_int LTP_scale_Q14; 1.323 +} silk_decoder_control; 1.324 + 1.325 + 1.326 +#ifdef __cplusplus 1.327 +} 1.328 +#endif 1.329 + 1.330 +#endif