annotate src/opus-1.3/silk/structs.h @ 69:7aeed7906520

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