annotate src/opus-1.3/silk/structs.h @ 168:ceec0dd9ec9c

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 07 Feb 2020 11:51:13 +0000
parents 4664ac0c1032
children
rev   line source
cannam@154 1 /***********************************************************************
cannam@154 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
cannam@154 3 Redistribution and use in source and binary forms, with or without
cannam@154 4 modification, are permitted provided that the following conditions
cannam@154 5 are met:
cannam@154 6 - Redistributions of source code must retain the above copyright notice,
cannam@154 7 this list of conditions and the following disclaimer.
cannam@154 8 - Redistributions in binary form must reproduce the above copyright
cannam@154 9 notice, this list of conditions and the following disclaimer in the
cannam@154 10 documentation and/or other materials provided with the distribution.
cannam@154 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the
cannam@154 12 names of specific contributors, may be used to endorse or promote
cannam@154 13 products derived from this software without specific prior written
cannam@154 14 permission.
cannam@154 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
cannam@154 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
cannam@154 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
cannam@154 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
cannam@154 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
cannam@154 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
cannam@154 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
cannam@154 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
cannam@154 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
cannam@154 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
cannam@154 25 POSSIBILITY OF SUCH DAMAGE.
cannam@154 26 ***********************************************************************/
cannam@154 27
cannam@154 28 #ifndef SILK_STRUCTS_H
cannam@154 29 #define SILK_STRUCTS_H
cannam@154 30
cannam@154 31 #include "typedef.h"
cannam@154 32 #include "SigProc_FIX.h"
cannam@154 33 #include "define.h"
cannam@154 34 #include "entenc.h"
cannam@154 35 #include "entdec.h"
cannam@154 36
cannam@154 37 #ifdef __cplusplus
cannam@154 38 extern "C"
cannam@154 39 {
cannam@154 40 #endif
cannam@154 41
cannam@154 42 /************************************/
cannam@154 43 /* Noise shaping quantization state */
cannam@154 44 /************************************/
cannam@154 45 typedef struct {
cannam@154 46 opus_int16 xq[ 2 * MAX_FRAME_LENGTH ]; /* Buffer for quantized output signal */
cannam@154 47 opus_int32 sLTP_shp_Q14[ 2 * MAX_FRAME_LENGTH ];
cannam@154 48 opus_int32 sLPC_Q14[ MAX_SUB_FRAME_LENGTH + NSQ_LPC_BUF_LENGTH ];
cannam@154 49 opus_int32 sAR2_Q14[ MAX_SHAPE_LPC_ORDER ];
cannam@154 50 opus_int32 sLF_AR_shp_Q14;
cannam@154 51 opus_int32 sDiff_shp_Q14;
cannam@154 52 opus_int lagPrev;
cannam@154 53 opus_int sLTP_buf_idx;
cannam@154 54 opus_int sLTP_shp_buf_idx;
cannam@154 55 opus_int32 rand_seed;
cannam@154 56 opus_int32 prev_gain_Q16;
cannam@154 57 opus_int rewhite_flag;
cannam@154 58 } silk_nsq_state;
cannam@154 59
cannam@154 60 /********************************/
cannam@154 61 /* VAD state */
cannam@154 62 /********************************/
cannam@154 63 typedef struct {
cannam@154 64 opus_int32 AnaState[ 2 ]; /* Analysis filterbank state: 0-8 kHz */
cannam@154 65 opus_int32 AnaState1[ 2 ]; /* Analysis filterbank state: 0-4 kHz */
cannam@154 66 opus_int32 AnaState2[ 2 ]; /* Analysis filterbank state: 0-2 kHz */
cannam@154 67 opus_int32 XnrgSubfr[ VAD_N_BANDS ]; /* Subframe energies */
cannam@154 68 opus_int32 NrgRatioSmth_Q8[ VAD_N_BANDS ]; /* Smoothed energy level in each band */
cannam@154 69 opus_int16 HPstate; /* State of differentiator in the lowest band */
cannam@154 70 opus_int32 NL[ VAD_N_BANDS ]; /* Noise energy level in each band */
cannam@154 71 opus_int32 inv_NL[ VAD_N_BANDS ]; /* Inverse noise energy level in each band */
cannam@154 72 opus_int32 NoiseLevelBias[ VAD_N_BANDS ]; /* Noise level estimator bias/offset */
cannam@154 73 opus_int32 counter; /* Frame counter used in the initial phase */
cannam@154 74 } silk_VAD_state;
cannam@154 75
cannam@154 76 /* Variable cut-off low-pass filter state */
cannam@154 77 typedef struct {
cannam@154 78 opus_int32 In_LP_State[ 2 ]; /* Low pass filter state */
cannam@154 79 opus_int32 transition_frame_no; /* Counter which is mapped to a cut-off frequency */
cannam@154 80 opus_int mode; /* Operating mode, <0: switch down, >0: switch up; 0: do nothing */
cannam@154 81 opus_int32 saved_fs_kHz; /* If non-zero, holds the last sampling rate before a bandwidth switching reset. */
cannam@154 82 } silk_LP_state;
cannam@154 83
cannam@154 84 /* Structure containing NLSF codebook */
cannam@154 85 typedef struct {
cannam@154 86 const opus_int16 nVectors;
cannam@154 87 const opus_int16 order;
cannam@154 88 const opus_int16 quantStepSize_Q16;
cannam@154 89 const opus_int16 invQuantStepSize_Q6;
cannam@154 90 const opus_uint8 *CB1_NLSF_Q8;
cannam@154 91 const opus_int16 *CB1_Wght_Q9;
cannam@154 92 const opus_uint8 *CB1_iCDF;
cannam@154 93 const opus_uint8 *pred_Q8;
cannam@154 94 const opus_uint8 *ec_sel;
cannam@154 95 const opus_uint8 *ec_iCDF;
cannam@154 96 const opus_uint8 *ec_Rates_Q5;
cannam@154 97 const opus_int16 *deltaMin_Q15;
cannam@154 98 } silk_NLSF_CB_struct;
cannam@154 99
cannam@154 100 typedef struct {
cannam@154 101 opus_int16 pred_prev_Q13[ 2 ];
cannam@154 102 opus_int16 sMid[ 2 ];
cannam@154 103 opus_int16 sSide[ 2 ];
cannam@154 104 opus_int32 mid_side_amp_Q0[ 4 ];
cannam@154 105 opus_int16 smth_width_Q14;
cannam@154 106 opus_int16 width_prev_Q14;
cannam@154 107 opus_int16 silent_side_len;
cannam@154 108 opus_int8 predIx[ MAX_FRAMES_PER_PACKET ][ 2 ][ 3 ];
cannam@154 109 opus_int8 mid_only_flags[ MAX_FRAMES_PER_PACKET ];
cannam@154 110 } stereo_enc_state;
cannam@154 111
cannam@154 112 typedef struct {
cannam@154 113 opus_int16 pred_prev_Q13[ 2 ];
cannam@154 114 opus_int16 sMid[ 2 ];
cannam@154 115 opus_int16 sSide[ 2 ];
cannam@154 116 } stereo_dec_state;
cannam@154 117
cannam@154 118 typedef struct {
cannam@154 119 opus_int8 GainsIndices[ MAX_NB_SUBFR ];
cannam@154 120 opus_int8 LTPIndex[ MAX_NB_SUBFR ];
cannam@154 121 opus_int8 NLSFIndices[ MAX_LPC_ORDER + 1 ];
cannam@154 122 opus_int16 lagIndex;
cannam@154 123 opus_int8 contourIndex;
cannam@154 124 opus_int8 signalType;
cannam@154 125 opus_int8 quantOffsetType;
cannam@154 126 opus_int8 NLSFInterpCoef_Q2;
cannam@154 127 opus_int8 PERIndex;
cannam@154 128 opus_int8 LTP_scaleIndex;
cannam@154 129 opus_int8 Seed;
cannam@154 130 } SideInfoIndices;
cannam@154 131
cannam@154 132 /********************************/
cannam@154 133 /* Encoder state */
cannam@154 134 /********************************/
cannam@154 135 typedef struct {
cannam@154 136 opus_int32 In_HP_State[ 2 ]; /* High pass filter state */
cannam@154 137 opus_int32 variable_HP_smth1_Q15; /* State of first smoother */
cannam@154 138 opus_int32 variable_HP_smth2_Q15; /* State of second smoother */
cannam@154 139 silk_LP_state sLP; /* Low pass filter state */
cannam@154 140 silk_VAD_state sVAD; /* Voice activity detector state */
cannam@154 141 silk_nsq_state sNSQ; /* Noise Shape Quantizer State */
cannam@154 142 opus_int16 prev_NLSFq_Q15[ MAX_LPC_ORDER ]; /* Previously quantized NLSF vector */
cannam@154 143 opus_int speech_activity_Q8; /* Speech activity */
cannam@154 144 opus_int allow_bandwidth_switch; /* Flag indicating that switching of internal bandwidth is allowed */
cannam@154 145 opus_int8 LBRRprevLastGainIndex;
cannam@154 146 opus_int8 prevSignalType;
cannam@154 147 opus_int prevLag;
cannam@154 148 opus_int pitch_LPC_win_length;
cannam@154 149 opus_int max_pitch_lag; /* Highest possible pitch lag (samples) */
cannam@154 150 opus_int32 API_fs_Hz; /* API sampling frequency (Hz) */
cannam@154 151 opus_int32 prev_API_fs_Hz; /* Previous API sampling frequency (Hz) */
cannam@154 152 opus_int maxInternal_fs_Hz; /* Maximum internal sampling frequency (Hz) */
cannam@154 153 opus_int minInternal_fs_Hz; /* Minimum internal sampling frequency (Hz) */
cannam@154 154 opus_int desiredInternal_fs_Hz; /* Soft request for internal sampling frequency (Hz) */
cannam@154 155 opus_int fs_kHz; /* Internal sampling frequency (kHz) */
cannam@154 156 opus_int nb_subfr; /* Number of 5 ms subframes in a frame */
cannam@154 157 opus_int frame_length; /* Frame length (samples) */
cannam@154 158 opus_int subfr_length; /* Subframe length (samples) */
cannam@154 159 opus_int ltp_mem_length; /* Length of LTP memory */
cannam@154 160 opus_int la_pitch; /* Look-ahead for pitch analysis (samples) */
cannam@154 161 opus_int la_shape; /* Look-ahead for noise shape analysis (samples) */
cannam@154 162 opus_int shapeWinLength; /* Window length for noise shape analysis (samples) */
cannam@154 163 opus_int32 TargetRate_bps; /* Target bitrate (bps) */
cannam@154 164 opus_int PacketSize_ms; /* Number of milliseconds to put in each packet */
cannam@154 165 opus_int PacketLoss_perc; /* Packet loss rate measured by farend */
cannam@154 166 opus_int32 frameCounter;
cannam@154 167 opus_int Complexity; /* Complexity setting */
cannam@154 168 opus_int nStatesDelayedDecision; /* Number of states in delayed decision quantization */
cannam@154 169 opus_int useInterpolatedNLSFs; /* Flag for using NLSF interpolation */
cannam@154 170 opus_int shapingLPCOrder; /* Filter order for noise shaping filters */
cannam@154 171 opus_int predictLPCOrder; /* Filter order for prediction filters */
cannam@154 172 opus_int pitchEstimationComplexity; /* Complexity level for pitch estimator */
cannam@154 173 opus_int pitchEstimationLPCOrder; /* Whitening filter order for pitch estimator */
cannam@154 174 opus_int32 pitchEstimationThreshold_Q16; /* Threshold for pitch estimator */
cannam@154 175 opus_int32 sum_log_gain_Q7; /* Cumulative max prediction gain */
cannam@154 176 opus_int NLSF_MSVQ_Survivors; /* Number of survivors in NLSF MSVQ */
cannam@154 177 opus_int first_frame_after_reset; /* Flag for deactivating NLSF interpolation, pitch prediction */
cannam@154 178 opus_int controlled_since_last_payload; /* Flag for ensuring codec_control only runs once per packet */
cannam@154 179 opus_int warping_Q16; /* Warping parameter for warped noise shaping */
cannam@154 180 opus_int useCBR; /* Flag to enable constant bitrate */
cannam@154 181 opus_int prefillFlag; /* Flag to indicate that only buffers are prefilled, no coding */
cannam@154 182 const opus_uint8 *pitch_lag_low_bits_iCDF; /* Pointer to iCDF table for low bits of pitch lag index */
cannam@154 183 const opus_uint8 *pitch_contour_iCDF; /* Pointer to iCDF table for pitch contour index */
cannam@154 184 const silk_NLSF_CB_struct *psNLSF_CB; /* Pointer to NLSF codebook */
cannam@154 185 opus_int input_quality_bands_Q15[ VAD_N_BANDS ];
cannam@154 186 opus_int input_tilt_Q15;
cannam@154 187 opus_int SNR_dB_Q7; /* Quality setting */
cannam@154 188
cannam@154 189 opus_int8 VAD_flags[ MAX_FRAMES_PER_PACKET ];
cannam@154 190 opus_int8 LBRR_flag;
cannam@154 191 opus_int LBRR_flags[ MAX_FRAMES_PER_PACKET ];
cannam@154 192
cannam@154 193 SideInfoIndices indices;
cannam@154 194 opus_int8 pulses[ MAX_FRAME_LENGTH ];
cannam@154 195
cannam@154 196 int arch;
cannam@154 197
cannam@154 198 /* Input/output buffering */
cannam@154 199 opus_int16 inputBuf[ MAX_FRAME_LENGTH + 2 ]; /* Buffer containing input signal */
cannam@154 200 opus_int inputBufIx;
cannam@154 201 opus_int nFramesPerPacket;
cannam@154 202 opus_int nFramesEncoded; /* Number of frames analyzed in current packet */
cannam@154 203
cannam@154 204 opus_int nChannelsAPI;
cannam@154 205 opus_int nChannelsInternal;
cannam@154 206 opus_int channelNb;
cannam@154 207
cannam@154 208 /* Parameters For LTP scaling Control */
cannam@154 209 opus_int frames_since_onset;
cannam@154 210
cannam@154 211 /* Specifically for entropy coding */
cannam@154 212 opus_int ec_prevSignalType;
cannam@154 213 opus_int16 ec_prevLagIndex;
cannam@154 214
cannam@154 215 silk_resampler_state_struct resampler_state;
cannam@154 216
cannam@154 217 /* DTX */
cannam@154 218 opus_int useDTX; /* Flag to enable DTX */
cannam@154 219 opus_int inDTX; /* Flag to signal DTX period */
cannam@154 220 opus_int noSpeechCounter; /* Counts concecutive nonactive frames, used by DTX */
cannam@154 221
cannam@154 222 /* Inband Low Bitrate Redundancy (LBRR) data */
cannam@154 223 opus_int useInBandFEC; /* Saves the API setting for query */
cannam@154 224 opus_int LBRR_enabled; /* Depends on useInBandFRC, bitrate and packet loss rate */
cannam@154 225 opus_int LBRR_GainIncreases; /* Gains increment for coding LBRR frames */
cannam@154 226 SideInfoIndices indices_LBRR[ MAX_FRAMES_PER_PACKET ];
cannam@154 227 opus_int8 pulses_LBRR[ MAX_FRAMES_PER_PACKET ][ MAX_FRAME_LENGTH ];
cannam@154 228 } silk_encoder_state;
cannam@154 229
cannam@154 230
cannam@154 231 /* Struct for Packet Loss Concealment */
cannam@154 232 typedef struct {
cannam@154 233 opus_int32 pitchL_Q8; /* Pitch lag to use for voiced concealment */
cannam@154 234 opus_int16 LTPCoef_Q14[ LTP_ORDER ]; /* LTP coeficients to use for voiced concealment */
cannam@154 235 opus_int16 prevLPC_Q12[ MAX_LPC_ORDER ];
cannam@154 236 opus_int last_frame_lost; /* Was previous frame lost */
cannam@154 237 opus_int32 rand_seed; /* Seed for unvoiced signal generation */
cannam@154 238 opus_int16 randScale_Q14; /* Scaling of unvoiced random signal */
cannam@154 239 opus_int32 conc_energy;
cannam@154 240 opus_int conc_energy_shift;
cannam@154 241 opus_int16 prevLTP_scale_Q14;
cannam@154 242 opus_int32 prevGain_Q16[ 2 ];
cannam@154 243 opus_int fs_kHz;
cannam@154 244 opus_int nb_subfr;
cannam@154 245 opus_int subfr_length;
cannam@154 246 } silk_PLC_struct;
cannam@154 247
cannam@154 248 /* Struct for CNG */
cannam@154 249 typedef struct {
cannam@154 250 opus_int32 CNG_exc_buf_Q14[ MAX_FRAME_LENGTH ];
cannam@154 251 opus_int16 CNG_smth_NLSF_Q15[ MAX_LPC_ORDER ];
cannam@154 252 opus_int32 CNG_synth_state[ MAX_LPC_ORDER ];
cannam@154 253 opus_int32 CNG_smth_Gain_Q16;
cannam@154 254 opus_int32 rand_seed;
cannam@154 255 opus_int fs_kHz;
cannam@154 256 } silk_CNG_struct;
cannam@154 257
cannam@154 258 /********************************/
cannam@154 259 /* Decoder state */
cannam@154 260 /********************************/
cannam@154 261 typedef struct {
cannam@154 262 opus_int32 prev_gain_Q16;
cannam@154 263 opus_int32 exc_Q14[ MAX_FRAME_LENGTH ];
cannam@154 264 opus_int32 sLPC_Q14_buf[ MAX_LPC_ORDER ];
cannam@154 265 opus_int16 outBuf[ MAX_FRAME_LENGTH + 2 * MAX_SUB_FRAME_LENGTH ]; /* Buffer for output signal */
cannam@154 266 opus_int lagPrev; /* Previous Lag */
cannam@154 267 opus_int8 LastGainIndex; /* Previous gain index */
cannam@154 268 opus_int fs_kHz; /* Sampling frequency in kHz */
cannam@154 269 opus_int32 fs_API_hz; /* API sample frequency (Hz) */
cannam@154 270 opus_int nb_subfr; /* Number of 5 ms subframes in a frame */
cannam@154 271 opus_int frame_length; /* Frame length (samples) */
cannam@154 272 opus_int subfr_length; /* Subframe length (samples) */
cannam@154 273 opus_int ltp_mem_length; /* Length of LTP memory */
cannam@154 274 opus_int LPC_order; /* LPC order */
cannam@154 275 opus_int16 prevNLSF_Q15[ MAX_LPC_ORDER ]; /* Used to interpolate LSFs */
cannam@154 276 opus_int first_frame_after_reset; /* Flag for deactivating NLSF interpolation */
cannam@154 277 const opus_uint8 *pitch_lag_low_bits_iCDF; /* Pointer to iCDF table for low bits of pitch lag index */
cannam@154 278 const opus_uint8 *pitch_contour_iCDF; /* Pointer to iCDF table for pitch contour index */
cannam@154 279
cannam@154 280 /* For buffering payload in case of more frames per packet */
cannam@154 281 opus_int nFramesDecoded;
cannam@154 282 opus_int nFramesPerPacket;
cannam@154 283
cannam@154 284 /* Specifically for entropy coding */
cannam@154 285 opus_int ec_prevSignalType;
cannam@154 286 opus_int16 ec_prevLagIndex;
cannam@154 287
cannam@154 288 opus_int VAD_flags[ MAX_FRAMES_PER_PACKET ];
cannam@154 289 opus_int LBRR_flag;
cannam@154 290 opus_int LBRR_flags[ MAX_FRAMES_PER_PACKET ];
cannam@154 291
cannam@154 292 silk_resampler_state_struct resampler_state;
cannam@154 293
cannam@154 294 const silk_NLSF_CB_struct *psNLSF_CB; /* Pointer to NLSF codebook */
cannam@154 295
cannam@154 296 /* Quantization indices */
cannam@154 297 SideInfoIndices indices;
cannam@154 298
cannam@154 299 /* CNG state */
cannam@154 300 silk_CNG_struct sCNG;
cannam@154 301
cannam@154 302 /* Stuff used for PLC */
cannam@154 303 opus_int lossCnt;
cannam@154 304 opus_int prevSignalType;
cannam@154 305 int arch;
cannam@154 306
cannam@154 307 silk_PLC_struct sPLC;
cannam@154 308
cannam@154 309 } silk_decoder_state;
cannam@154 310
cannam@154 311 /************************/
cannam@154 312 /* Decoder control */
cannam@154 313 /************************/
cannam@154 314 typedef struct {
cannam@154 315 /* Prediction and coding parameters */
cannam@154 316 opus_int pitchL[ MAX_NB_SUBFR ];
cannam@154 317 opus_int32 Gains_Q16[ MAX_NB_SUBFR ];
cannam@154 318 /* Holds interpolated and final coefficients, 4-byte aligned */
cannam@154 319 silk_DWORD_ALIGN opus_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ];
cannam@154 320 opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ];
cannam@154 321 opus_int LTP_scale_Q14;
cannam@154 322 } silk_decoder_control;
cannam@154 323
cannam@154 324
cannam@154 325 #ifdef __cplusplus
cannam@154 326 }
cannam@154 327 #endif
cannam@154 328
cannam@154 329 #endif