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