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