tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

structs.h (21869B)


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