media/libopus/silk/define.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /***********************************************************************
michael@0 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
michael@0 3 Redistribution and use in source and binary forms, with or without
michael@0 4 modification, are permitted provided that the following conditions
michael@0 5 are met:
michael@0 6 - Redistributions of source code must retain the above copyright notice,
michael@0 7 this list of conditions and the following disclaimer.
michael@0 8 - Redistributions in binary form must reproduce the above copyright
michael@0 9 notice, this list of conditions and the following disclaimer in the
michael@0 10 documentation and/or other materials provided with the distribution.
michael@0 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the
michael@0 12 names of specific contributors, may be used to endorse or promote
michael@0 13 products derived from this software without specific prior written
michael@0 14 permission.
michael@0 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
michael@0 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
michael@0 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
michael@0 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
michael@0 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
michael@0 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
michael@0 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
michael@0 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
michael@0 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
michael@0 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
michael@0 25 POSSIBILITY OF SUCH DAMAGE.
michael@0 26 ***********************************************************************/
michael@0 27
michael@0 28 #ifndef SILK_DEFINE_H
michael@0 29 #define SILK_DEFINE_H
michael@0 30
michael@0 31 #include "errors.h"
michael@0 32 #include "typedef.h"
michael@0 33
michael@0 34 #ifdef __cplusplus
michael@0 35 extern "C"
michael@0 36 {
michael@0 37 #endif
michael@0 38
michael@0 39 /* Max number of encoder channels (1/2) */
michael@0 40 #define ENCODER_NUM_CHANNELS 2
michael@0 41 /* Number of decoder channels (1/2) */
michael@0 42 #define DECODER_NUM_CHANNELS 2
michael@0 43
michael@0 44 #define MAX_FRAMES_PER_PACKET 3
michael@0 45
michael@0 46 /* Limits on bitrate */
michael@0 47 #define MIN_TARGET_RATE_BPS 5000
michael@0 48 #define MAX_TARGET_RATE_BPS 80000
michael@0 49 #define TARGET_RATE_TAB_SZ 8
michael@0 50
michael@0 51 /* LBRR thresholds */
michael@0 52 #define LBRR_NB_MIN_RATE_BPS 12000
michael@0 53 #define LBRR_MB_MIN_RATE_BPS 14000
michael@0 54 #define LBRR_WB_MIN_RATE_BPS 16000
michael@0 55
michael@0 56 /* DTX settings */
michael@0 57 #define NB_SPEECH_FRAMES_BEFORE_DTX 10 /* eq 200 ms */
michael@0 58 #define MAX_CONSECUTIVE_DTX 20 /* eq 400 ms */
michael@0 59
michael@0 60 /* Maximum sampling frequency */
michael@0 61 #define MAX_FS_KHZ 16
michael@0 62 #define MAX_API_FS_KHZ 48
michael@0 63
michael@0 64 /* Signal types */
michael@0 65 #define TYPE_NO_VOICE_ACTIVITY 0
michael@0 66 #define TYPE_UNVOICED 1
michael@0 67 #define TYPE_VOICED 2
michael@0 68
michael@0 69 /* Conditional coding types */
michael@0 70 #define CODE_INDEPENDENTLY 0
michael@0 71 #define CODE_INDEPENDENTLY_NO_LTP_SCALING 1
michael@0 72 #define CODE_CONDITIONALLY 2
michael@0 73
michael@0 74 /* Settings for stereo processing */
michael@0 75 #define STEREO_QUANT_TAB_SIZE 16
michael@0 76 #define STEREO_QUANT_SUB_STEPS 5
michael@0 77 #define STEREO_INTERP_LEN_MS 8 /* must be even */
michael@0 78 #define STEREO_RATIO_SMOOTH_COEF 0.01 /* smoothing coef for signal norms and stereo width */
michael@0 79
michael@0 80 /* Range of pitch lag estimates */
michael@0 81 #define PITCH_EST_MIN_LAG_MS 2 /* 2 ms -> 500 Hz */
michael@0 82 #define PITCH_EST_MAX_LAG_MS 18 /* 18 ms -> 56 Hz */
michael@0 83
michael@0 84 /* Maximum number of subframes */
michael@0 85 #define MAX_NB_SUBFR 4
michael@0 86
michael@0 87 /* Number of samples per frame */
michael@0 88 #define LTP_MEM_LENGTH_MS 20
michael@0 89 #define SUB_FRAME_LENGTH_MS 5
michael@0 90 #define MAX_SUB_FRAME_LENGTH ( SUB_FRAME_LENGTH_MS * MAX_FS_KHZ )
michael@0 91 #define MAX_FRAME_LENGTH_MS ( SUB_FRAME_LENGTH_MS * MAX_NB_SUBFR )
michael@0 92 #define MAX_FRAME_LENGTH ( MAX_FRAME_LENGTH_MS * MAX_FS_KHZ )
michael@0 93
michael@0 94 /* Milliseconds of lookahead for pitch analysis */
michael@0 95 #define LA_PITCH_MS 2
michael@0 96 #define LA_PITCH_MAX ( LA_PITCH_MS * MAX_FS_KHZ )
michael@0 97
michael@0 98 /* Order of LPC used in find pitch */
michael@0 99 #define MAX_FIND_PITCH_LPC_ORDER 16
michael@0 100
michael@0 101 /* Length of LPC window used in find pitch */
michael@0 102 #define FIND_PITCH_LPC_WIN_MS ( 20 + (LA_PITCH_MS << 1) )
michael@0 103 #define FIND_PITCH_LPC_WIN_MS_2_SF ( 10 + (LA_PITCH_MS << 1) )
michael@0 104 #define FIND_PITCH_LPC_WIN_MAX ( FIND_PITCH_LPC_WIN_MS * MAX_FS_KHZ )
michael@0 105
michael@0 106 /* Milliseconds of lookahead for noise shape analysis */
michael@0 107 #define LA_SHAPE_MS 5
michael@0 108 #define LA_SHAPE_MAX ( LA_SHAPE_MS * MAX_FS_KHZ )
michael@0 109
michael@0 110 /* Maximum length of LPC window used in noise shape analysis */
michael@0 111 #define SHAPE_LPC_WIN_MAX ( 15 * MAX_FS_KHZ )
michael@0 112
michael@0 113 /* dB level of lowest gain quantization level */
michael@0 114 #define MIN_QGAIN_DB 2
michael@0 115 /* dB level of highest gain quantization level */
michael@0 116 #define MAX_QGAIN_DB 88
michael@0 117 /* Number of gain quantization levels */
michael@0 118 #define N_LEVELS_QGAIN 64
michael@0 119 /* Max increase in gain quantization index */
michael@0 120 #define MAX_DELTA_GAIN_QUANT 36
michael@0 121 /* Max decrease in gain quantization index */
michael@0 122 #define MIN_DELTA_GAIN_QUANT -4
michael@0 123
michael@0 124 /* Quantization offsets (multiples of 4) */
michael@0 125 #define OFFSET_VL_Q10 32
michael@0 126 #define OFFSET_VH_Q10 100
michael@0 127 #define OFFSET_UVL_Q10 100
michael@0 128 #define OFFSET_UVH_Q10 240
michael@0 129
michael@0 130 #define QUANT_LEVEL_ADJUST_Q10 80
michael@0 131
michael@0 132 /* Maximum numbers of iterations used to stabilize an LPC vector */
michael@0 133 #define MAX_LPC_STABILIZE_ITERATIONS 16
michael@0 134 #define MAX_PREDICTION_POWER_GAIN 1e4f
michael@0 135 #define MAX_PREDICTION_POWER_GAIN_AFTER_RESET 1e2f
michael@0 136
michael@0 137 #define MAX_LPC_ORDER 16
michael@0 138 #define MIN_LPC_ORDER 10
michael@0 139
michael@0 140 /* Find Pred Coef defines */
michael@0 141 #define LTP_ORDER 5
michael@0 142
michael@0 143 /* LTP quantization settings */
michael@0 144 #define NB_LTP_CBKS 3
michael@0 145
michael@0 146 /* Flag to use harmonic noise shaping */
michael@0 147 #define USE_HARM_SHAPING 1
michael@0 148
michael@0 149 /* Max LPC order of noise shaping filters */
michael@0 150 #define MAX_SHAPE_LPC_ORDER 16
michael@0 151
michael@0 152 #define HARM_SHAPE_FIR_TAPS 3
michael@0 153
michael@0 154 /* Maximum number of delayed decision states */
michael@0 155 #define MAX_DEL_DEC_STATES 4
michael@0 156
michael@0 157 #define LTP_BUF_LENGTH 512
michael@0 158 #define LTP_MASK ( LTP_BUF_LENGTH - 1 )
michael@0 159
michael@0 160 #define DECISION_DELAY 32
michael@0 161 #define DECISION_DELAY_MASK ( DECISION_DELAY - 1 )
michael@0 162
michael@0 163 /* Number of subframes for excitation entropy coding */
michael@0 164 #define SHELL_CODEC_FRAME_LENGTH 16
michael@0 165 #define LOG2_SHELL_CODEC_FRAME_LENGTH 4
michael@0 166 #define MAX_NB_SHELL_BLOCKS ( MAX_FRAME_LENGTH / SHELL_CODEC_FRAME_LENGTH )
michael@0 167
michael@0 168 /* Number of rate levels, for entropy coding of excitation */
michael@0 169 #define N_RATE_LEVELS 10
michael@0 170
michael@0 171 /* Maximum sum of pulses per shell coding frame */
michael@0 172 #define MAX_PULSES 16
michael@0 173
michael@0 174 #define MAX_MATRIX_SIZE MAX_LPC_ORDER /* Max of LPC Order and LTP order */
michael@0 175
michael@0 176 #if( MAX_LPC_ORDER > DECISION_DELAY )
michael@0 177 # define NSQ_LPC_BUF_LENGTH MAX_LPC_ORDER
michael@0 178 #else
michael@0 179 # define NSQ_LPC_BUF_LENGTH DECISION_DELAY
michael@0 180 #endif
michael@0 181
michael@0 182 /***************************/
michael@0 183 /* Voice activity detector */
michael@0 184 /***************************/
michael@0 185 #define VAD_N_BANDS 4
michael@0 186
michael@0 187 #define VAD_INTERNAL_SUBFRAMES_LOG2 2
michael@0 188 #define VAD_INTERNAL_SUBFRAMES ( 1 << VAD_INTERNAL_SUBFRAMES_LOG2 )
michael@0 189
michael@0 190 #define VAD_NOISE_LEVEL_SMOOTH_COEF_Q16 1024 /* Must be < 4096 */
michael@0 191 #define VAD_NOISE_LEVELS_BIAS 50
michael@0 192
michael@0 193 /* Sigmoid settings */
michael@0 194 #define VAD_NEGATIVE_OFFSET_Q5 128 /* sigmoid is 0 at -128 */
michael@0 195 #define VAD_SNR_FACTOR_Q16 45000
michael@0 196
michael@0 197 /* smoothing for SNR measurement */
michael@0 198 #define VAD_SNR_SMOOTH_COEF_Q18 4096
michael@0 199
michael@0 200 /* Size of the piecewise linear cosine approximation table for the LSFs */
michael@0 201 #define LSF_COS_TAB_SZ_FIX 128
michael@0 202
michael@0 203 /******************/
michael@0 204 /* NLSF quantizer */
michael@0 205 /******************/
michael@0 206 #define NLSF_W_Q 2
michael@0 207 #define NLSF_VQ_MAX_VECTORS 32
michael@0 208 #define NLSF_VQ_MAX_SURVIVORS 32
michael@0 209 #define NLSF_QUANT_MAX_AMPLITUDE 4
michael@0 210 #define NLSF_QUANT_MAX_AMPLITUDE_EXT 10
michael@0 211 #define NLSF_QUANT_LEVEL_ADJ 0.1
michael@0 212 #define NLSF_QUANT_DEL_DEC_STATES_LOG2 2
michael@0 213 #define NLSF_QUANT_DEL_DEC_STATES ( 1 << NLSF_QUANT_DEL_DEC_STATES_LOG2 )
michael@0 214
michael@0 215 /* Transition filtering for mode switching */
michael@0 216 #define TRANSITION_TIME_MS 5120 /* 5120 = 64 * FRAME_LENGTH_MS * ( TRANSITION_INT_NUM - 1 ) = 64*(20*4)*/
michael@0 217 #define TRANSITION_NB 3 /* Hardcoded in tables */
michael@0 218 #define TRANSITION_NA 2 /* Hardcoded in tables */
michael@0 219 #define TRANSITION_INT_NUM 5 /* Hardcoded in tables */
michael@0 220 #define TRANSITION_FRAMES ( TRANSITION_TIME_MS / MAX_FRAME_LENGTH_MS )
michael@0 221 #define TRANSITION_INT_STEPS ( TRANSITION_FRAMES / ( TRANSITION_INT_NUM - 1 ) )
michael@0 222
michael@0 223 /* BWE factors to apply after packet loss */
michael@0 224 #define BWE_AFTER_LOSS_Q16 63570
michael@0 225
michael@0 226 /* Defines for CN generation */
michael@0 227 #define CNG_BUF_MASK_MAX 255 /* 2^floor(log2(MAX_FRAME_LENGTH))-1 */
michael@0 228 #define CNG_GAIN_SMTH_Q16 4634 /* 0.25^(1/4) */
michael@0 229 #define CNG_NLSF_SMTH_Q16 16348 /* 0.25 */
michael@0 230
michael@0 231 #ifdef __cplusplus
michael@0 232 }
michael@0 233 #endif
michael@0 234
michael@0 235 #endif

mercurial