tor-browser

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

define.h (10009B)


      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_DEFINE_H
     29 #define SILK_DEFINE_H
     30 
     31 #include "errors.h"
     32 #include "typedef.h"
     33 
     34 #ifdef __cplusplus
     35 extern "C"
     36 {
     37 #endif
     38 
     39 /* Max number of encoder channels (1/2) */
     40 #define ENCODER_NUM_CHANNELS                    2
     41 /* Number of decoder channels (1/2) */
     42 #define DECODER_NUM_CHANNELS                    2
     43 
     44 #define MAX_FRAMES_PER_PACKET                   3
     45 
     46 /* Limits on bitrate */
     47 #define MIN_TARGET_RATE_BPS                     5000
     48 #define MAX_TARGET_RATE_BPS                     80000
     49 
     50 /* LBRR thresholds */
     51 #define LBRR_NB_MIN_RATE_BPS                    12000
     52 #define LBRR_MB_MIN_RATE_BPS                    14000
     53 #define LBRR_WB_MIN_RATE_BPS                    16000
     54 
     55 /* DTX settings */
     56 #define NB_SPEECH_FRAMES_BEFORE_DTX             10      /* eq 200 ms */
     57 #define MAX_CONSECUTIVE_DTX                     20      /* eq 400 ms */
     58 #define DTX_ACTIVITY_THRESHOLD                  0.1f
     59 
     60 /* VAD decision */
     61 #define VAD_NO_DECISION                         -1
     62 #define VAD_NO_ACTIVITY                         0
     63 #define VAD_ACTIVITY                            1
     64 
     65 /* Maximum sampling frequency */
     66 #define MAX_FS_KHZ                              16
     67 #ifdef ENABLE_QEXT
     68 #define MAX_API_FS_KHZ                          96
     69 #else
     70 #define MAX_API_FS_KHZ                          48
     71 #endif
     72 
     73 /* Signal types */
     74 #define TYPE_NO_VOICE_ACTIVITY                  0
     75 #define TYPE_UNVOICED                           1
     76 #define TYPE_VOICED                             2
     77 
     78 /* Conditional coding types */
     79 #define CODE_INDEPENDENTLY                      0
     80 #define CODE_INDEPENDENTLY_NO_LTP_SCALING       1
     81 #define CODE_CONDITIONALLY                      2
     82 
     83 /* Settings for stereo processing */
     84 #define STEREO_QUANT_TAB_SIZE                   16
     85 #define STEREO_QUANT_SUB_STEPS                  5
     86 #define STEREO_INTERP_LEN_MS                    8       /* must be even */
     87 #define STEREO_RATIO_SMOOTH_COEF                0.01    /* smoothing coef for signal norms and stereo width */
     88 
     89 /* Range of pitch lag estimates */
     90 #define PITCH_EST_MIN_LAG_MS                    2       /* 2 ms -> 500 Hz */
     91 #define PITCH_EST_MAX_LAG_MS                    18      /* 18 ms -> 56 Hz */
     92 
     93 /* Maximum number of subframes */
     94 #define MAX_NB_SUBFR                            4
     95 
     96 /* Number of samples per frame */
     97 #define LTP_MEM_LENGTH_MS                       20
     98 #define SUB_FRAME_LENGTH_MS                     5
     99 #define MAX_SUB_FRAME_LENGTH                    ( SUB_FRAME_LENGTH_MS * MAX_FS_KHZ )
    100 #define MAX_FRAME_LENGTH_MS                     ( SUB_FRAME_LENGTH_MS * MAX_NB_SUBFR )
    101 #define MAX_FRAME_LENGTH                        ( MAX_FRAME_LENGTH_MS * MAX_FS_KHZ )
    102 
    103 /* Milliseconds of lookahead for pitch analysis */
    104 #define LA_PITCH_MS                             2
    105 #define LA_PITCH_MAX                            ( LA_PITCH_MS * MAX_FS_KHZ )
    106 
    107 /* Order of LPC used in find pitch */
    108 #define MAX_FIND_PITCH_LPC_ORDER                16
    109 
    110 /* Length of LPC window used in find pitch */
    111 #define FIND_PITCH_LPC_WIN_MS                   ( 20 + (LA_PITCH_MS << 1) )
    112 #define FIND_PITCH_LPC_WIN_MS_2_SF              ( 10 + (LA_PITCH_MS << 1) )
    113 #define FIND_PITCH_LPC_WIN_MAX                  ( FIND_PITCH_LPC_WIN_MS * MAX_FS_KHZ )
    114 
    115 /* Milliseconds of lookahead for noise shape analysis */
    116 #define LA_SHAPE_MS                             5
    117 #define LA_SHAPE_MAX                            ( LA_SHAPE_MS * MAX_FS_KHZ )
    118 
    119 /* Maximum length of LPC window used in noise shape analysis */
    120 #define SHAPE_LPC_WIN_MAX                       ( 15 * MAX_FS_KHZ )
    121 
    122 /* dB level of lowest gain quantization level */
    123 #define MIN_QGAIN_DB                            2
    124 /* dB level of highest gain quantization level */
    125 #define MAX_QGAIN_DB                            88
    126 /* Number of gain quantization levels */
    127 #define N_LEVELS_QGAIN                          64
    128 /* Max increase in gain quantization index */
    129 #define MAX_DELTA_GAIN_QUANT                    36
    130 /* Max decrease in gain quantization index */
    131 #define MIN_DELTA_GAIN_QUANT                    -4
    132 
    133 /* Quantization offsets (multiples of 4) */
    134 #define OFFSET_VL_Q10                           32
    135 #define OFFSET_VH_Q10                           100
    136 #define OFFSET_UVL_Q10                          100
    137 #define OFFSET_UVH_Q10                          240
    138 
    139 #define QUANT_LEVEL_ADJUST_Q10                  80
    140 
    141 /* Maximum numbers of iterations used to stabilize an LPC vector */
    142 #define MAX_LPC_STABILIZE_ITERATIONS            16
    143 #define MAX_PREDICTION_POWER_GAIN               1e4f
    144 #define MAX_PREDICTION_POWER_GAIN_AFTER_RESET   1e2f
    145 
    146 #define MAX_LPC_ORDER                           16
    147 #define MIN_LPC_ORDER                           10
    148 
    149 /* Find Pred Coef defines */
    150 #define LTP_ORDER                               5
    151 
    152 /* LTP quantization settings */
    153 #define NB_LTP_CBKS                             3
    154 
    155 /* Flag to use harmonic noise shaping */
    156 #define USE_HARM_SHAPING                        1
    157 
    158 /* Max LPC order of noise shaping filters */
    159 #define MAX_SHAPE_LPC_ORDER                     24
    160 
    161 #define HARM_SHAPE_FIR_TAPS                     3
    162 
    163 /* Maximum number of delayed decision states */
    164 #define MAX_DEL_DEC_STATES                      4
    165 
    166 #define LTP_BUF_LENGTH                          512
    167 #define LTP_MASK                                ( LTP_BUF_LENGTH - 1 )
    168 
    169 #define DECISION_DELAY                          40
    170 
    171 /* Number of subframes for excitation entropy coding */
    172 #define SHELL_CODEC_FRAME_LENGTH                16
    173 #define LOG2_SHELL_CODEC_FRAME_LENGTH           4
    174 #define MAX_NB_SHELL_BLOCKS                     ( MAX_FRAME_LENGTH / SHELL_CODEC_FRAME_LENGTH )
    175 
    176 /* Number of rate levels, for entropy coding of excitation */
    177 #define N_RATE_LEVELS                           10
    178 
    179 /* Maximum sum of pulses per shell coding frame */
    180 #define SILK_MAX_PULSES                         16
    181 
    182 #define MAX_MATRIX_SIZE                         MAX_LPC_ORDER /* Max of LPC Order and LTP order */
    183 
    184 # define NSQ_LPC_BUF_LENGTH                     MAX_LPC_ORDER
    185 
    186 /***************************/
    187 /* Voice activity detector */
    188 /***************************/
    189 #define VAD_N_BANDS                             4
    190 
    191 #define VAD_INTERNAL_SUBFRAMES_LOG2             2
    192 #define VAD_INTERNAL_SUBFRAMES                  ( 1 << VAD_INTERNAL_SUBFRAMES_LOG2 )
    193 
    194 #define VAD_NOISE_LEVEL_SMOOTH_COEF_Q16         1024    /* Must be <  4096 */
    195 #define VAD_NOISE_LEVELS_BIAS                   50
    196 
    197 /* Sigmoid settings */
    198 #define VAD_NEGATIVE_OFFSET_Q5                  128     /* sigmoid is 0 at -128 */
    199 #define VAD_SNR_FACTOR_Q16                      45000
    200 
    201 /* smoothing for SNR measurement */
    202 #define VAD_SNR_SMOOTH_COEF_Q18                 4096
    203 
    204 /* Size of the piecewise linear cosine approximation table for the LSFs */
    205 #define LSF_COS_TAB_SZ_FIX                      128
    206 
    207 /******************/
    208 /* NLSF quantizer */
    209 /******************/
    210 #define NLSF_W_Q                                2
    211 #define NLSF_VQ_MAX_VECTORS                     32
    212 #define NLSF_QUANT_MAX_AMPLITUDE                4
    213 #define NLSF_QUANT_MAX_AMPLITUDE_EXT            10
    214 #define NLSF_QUANT_LEVEL_ADJ                    0.1
    215 #define NLSF_QUANT_DEL_DEC_STATES_LOG2          2
    216 #define NLSF_QUANT_DEL_DEC_STATES               ( 1 << NLSF_QUANT_DEL_DEC_STATES_LOG2 )
    217 
    218 /* Transition filtering for mode switching */
    219 #define TRANSITION_TIME_MS                      5120    /* 5120 = 64 * FRAME_LENGTH_MS * ( TRANSITION_INT_NUM - 1 ) = 64*(20*4)*/
    220 #define TRANSITION_NB                           3       /* Hardcoded in tables */
    221 #define TRANSITION_NA                           2       /* Hardcoded in tables */
    222 #define TRANSITION_INT_NUM                      5       /* Hardcoded in tables */
    223 #define TRANSITION_FRAMES                       ( TRANSITION_TIME_MS / MAX_FRAME_LENGTH_MS )
    224 #define TRANSITION_INT_STEPS                    ( TRANSITION_FRAMES  / ( TRANSITION_INT_NUM - 1 ) )
    225 
    226 /* BWE factors to apply after packet loss */
    227 #define BWE_AFTER_LOSS_Q16                      63570
    228 
    229 /* Defines for CN generation */
    230 #define CNG_BUF_MASK_MAX                        255     /* 2^floor(log2(MAX_FRAME_LENGTH))-1    */
    231 #define CNG_GAIN_SMTH_Q16                       4634    /* 0.25^(1/4)                           */
    232 #define CNG_GAIN_SMTH_THRESHOLD_Q16             46396   /* -3 dB                                */
    233 #define CNG_NLSF_SMTH_Q16                       16348   /* 0.25                                 */
    234 
    235 #ifdef __cplusplus
    236 }
    237 #endif
    238 
    239 #endif