blob: 1286048e7e21fd213a358987ba449c230bcc73a6 [file] [log] [blame]
Gregory Maxwellae231142011-07-30 08:18:48 -04001/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
Jean-Marc Valinae00e602012-04-20 16:31:04 -04004modification, are permitted provided that the following conditions
5are met:
Gregory Maxwellae231142011-07-30 08:18:48 -04006- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
Ralph Gilesf2446c22013-09-16 14:40:04 -070011- Neither the name of Internet Society, IETF or IETF Trust, nor the
Jean-Marc Valinae00e602012-04-20 16:31:04 -040012names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
Timothy B. Terriberry80ad3832013-05-19 18:00:39 -070015THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Jean-Marc Valinae00e602012-04-20 16:31:04 -040016AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
Gregory Maxwellae231142011-07-30 08:18:48 -040026***********************************************************************/
27
28#ifndef SILK_DEFINE_H
29#define SILK_DEFINE_H
30
Jean-Marc Valin1c2f5632011-09-16 01:16:53 -070031#include "errors.h"
32#include "typedef.h"
Gregory Maxwellae231142011-07-30 08:18:48 -040033
Gregory Maxwellae231142011-07-30 08:18:48 -040034#ifdef __cplusplus
35extern "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 */
Felicia Lim36481342016-05-16 15:29:53 +020059#define DTX_ACTIVITY_THRESHOLD 0.1f
Gregory Maxwellae231142011-07-30 08:18:48 -040060
Koen Vosacc7a6c2011-10-28 19:44:26 -040061/* Maximum sampling frequency */
Gregory Maxwellae231142011-07-30 08:18:48 -040062#define MAX_FS_KHZ 16
63#define MAX_API_FS_KHZ 48
64
65/* Signal types */
66#define TYPE_NO_VOICE_ACTIVITY 0
67#define TYPE_UNVOICED 1
68#define TYPE_VOICED 2
69
Timothy B. Terriberry53cc1a02011-10-14 13:38:24 -070070/* Conditional coding types */
71#define CODE_INDEPENDENTLY 0
72#define CODE_INDEPENDENTLY_NO_LTP_SCALING 1
73#define CODE_CONDITIONALLY 2
74
Gregory Maxwellae231142011-07-30 08:18:48 -040075/* Settings for stereo processing */
76#define STEREO_QUANT_TAB_SIZE 16
77#define STEREO_QUANT_SUB_STEPS 5
Koen Vosacc7a6c2011-10-28 19:44:26 -040078#define STEREO_INTERP_LEN_MS 8 /* must be even */
79#define STEREO_RATIO_SMOOTH_COEF 0.01 /* smoothing coef for signal norms and stereo width */
Gregory Maxwellae231142011-07-30 08:18:48 -040080
81/* Range of pitch lag estimates */
Koen Vosacc7a6c2011-10-28 19:44:26 -040082#define PITCH_EST_MIN_LAG_MS 2 /* 2 ms -> 500 Hz */
83#define PITCH_EST_MAX_LAG_MS 18 /* 18 ms -> 56 Hz */
Gregory Maxwellae231142011-07-30 08:18:48 -040084
85/* Maximum number of subframes */
86#define MAX_NB_SUBFR 4
87
88/* Number of samples per frame */
89#define LTP_MEM_LENGTH_MS 20
90#define SUB_FRAME_LENGTH_MS 5
91#define MAX_SUB_FRAME_LENGTH ( SUB_FRAME_LENGTH_MS * MAX_FS_KHZ )
92#define MAX_FRAME_LENGTH_MS ( SUB_FRAME_LENGTH_MS * MAX_NB_SUBFR )
93#define MAX_FRAME_LENGTH ( MAX_FRAME_LENGTH_MS * MAX_FS_KHZ )
94
95/* Milliseconds of lookahead for pitch analysis */
96#define LA_PITCH_MS 2
97#define LA_PITCH_MAX ( LA_PITCH_MS * MAX_FS_KHZ )
98
99/* Order of LPC used in find pitch */
100#define MAX_FIND_PITCH_LPC_ORDER 16
101
102/* Length of LPC window used in find pitch */
103#define FIND_PITCH_LPC_WIN_MS ( 20 + (LA_PITCH_MS << 1) )
104#define FIND_PITCH_LPC_WIN_MS_2_SF ( 10 + (LA_PITCH_MS << 1) )
105#define FIND_PITCH_LPC_WIN_MAX ( FIND_PITCH_LPC_WIN_MS * MAX_FS_KHZ )
106
107/* Milliseconds of lookahead for noise shape analysis */
108#define LA_SHAPE_MS 5
109#define LA_SHAPE_MAX ( LA_SHAPE_MS * MAX_FS_KHZ )
110
111/* Maximum length of LPC window used in noise shape analysis */
112#define SHAPE_LPC_WIN_MAX ( 15 * MAX_FS_KHZ )
113
114/* dB level of lowest gain quantization level */
115#define MIN_QGAIN_DB 2
116/* dB level of highest gain quantization level */
117#define MAX_QGAIN_DB 88
118/* Number of gain quantization levels */
119#define N_LEVELS_QGAIN 64
120/* Max increase in gain quantization index */
121#define MAX_DELTA_GAIN_QUANT 36
122/* Max decrease in gain quantization index */
123#define MIN_DELTA_GAIN_QUANT -4
124
125/* Quantization offsets (multiples of 4) */
126#define OFFSET_VL_Q10 32
127#define OFFSET_VH_Q10 100
128#define OFFSET_UVL_Q10 100
129#define OFFSET_UVH_Q10 240
130
131#define QUANT_LEVEL_ADJUST_Q10 80
132
Koen Vosbbfc9c92011-12-13 14:50:12 -0500133/* Maximum numbers of iterations used to stabilize an LPC vector */
Koen Vos54518c82012-01-31 01:51:22 -0500134#define MAX_LPC_STABILIZE_ITERATIONS 16
Koen Vosbf75c8e2011-12-13 14:47:31 -0500135#define MAX_PREDICTION_POWER_GAIN 1e4f
136#define MAX_PREDICTION_POWER_GAIN_AFTER_RESET 1e2f
Gregory Maxwellae231142011-07-30 08:18:48 -0400137
138#define MAX_LPC_ORDER 16
139#define MIN_LPC_ORDER 10
140
141/* Find Pred Coef defines */
142#define LTP_ORDER 5
143
144/* LTP quantization settings */
145#define NB_LTP_CBKS 3
146
147/* Flag to use harmonic noise shaping */
148#define USE_HARM_SHAPING 1
149
150/* Max LPC order of noise shaping filters */
Koen Vos3e054b82016-06-01 16:10:57 +0800151#define MAX_SHAPE_LPC_ORDER 24
Gregory Maxwellae231142011-07-30 08:18:48 -0400152
153#define HARM_SHAPE_FIR_TAPS 3
154
155/* Maximum number of delayed decision states */
156#define MAX_DEL_DEC_STATES 4
157
158#define LTP_BUF_LENGTH 512
159#define LTP_MASK ( LTP_BUF_LENGTH - 1 )
160
Koen Vos2799c532016-06-01 21:49:11 +0800161#define DECISION_DELAY 40
Gregory Maxwellae231142011-07-30 08:18:48 -0400162
163/* Number of subframes for excitation entropy coding */
164#define SHELL_CODEC_FRAME_LENGTH 16
165#define LOG2_SHELL_CODEC_FRAME_LENGTH 4
166#define MAX_NB_SHELL_BLOCKS ( MAX_FRAME_LENGTH / SHELL_CODEC_FRAME_LENGTH )
167
168/* Number of rate levels, for entropy coding of excitation */
169#define N_RATE_LEVELS 10
170
171/* Maximum sum of pulses per shell coding frame */
Jean-Marc Valin68a0e042015-12-31 14:43:49 -0500172#define SILK_MAX_PULSES 16
Gregory Maxwellae231142011-07-30 08:18:48 -0400173
174#define MAX_MATRIX_SIZE MAX_LPC_ORDER /* Max of LPC Order and LTP order */
175
Gregory Maxwellae231142011-07-30 08:18:48 -0400176# define NSQ_LPC_BUF_LENGTH MAX_LPC_ORDER
Gregory Maxwellae231142011-07-30 08:18:48 -0400177
Gregory Maxwellae231142011-07-30 08:18:48 -0400178/***************************/
179/* Voice activity detector */
180/***************************/
181#define VAD_N_BANDS 4
182
183#define VAD_INTERNAL_SUBFRAMES_LOG2 2
Koen Vosa51ebd62011-12-14 11:39:29 -0500184#define VAD_INTERNAL_SUBFRAMES ( 1 << VAD_INTERNAL_SUBFRAMES_LOG2 )
Gregory Maxwellae231142011-07-30 08:18:48 -0400185
Koen Vosacc7a6c2011-10-28 19:44:26 -0400186#define VAD_NOISE_LEVEL_SMOOTH_COEF_Q16 1024 /* Must be < 4096 */
Gregory Maxwellae231142011-07-30 08:18:48 -0400187#define VAD_NOISE_LEVELS_BIAS 50
188
189/* Sigmoid settings */
Koen Vosacc7a6c2011-10-28 19:44:26 -0400190#define VAD_NEGATIVE_OFFSET_Q5 128 /* sigmoid is 0 at -128 */
Gregory Maxwellae231142011-07-30 08:18:48 -0400191#define VAD_SNR_FACTOR_Q16 45000
192
193/* smoothing for SNR measurement */
194#define VAD_SNR_SMOOTH_COEF_Q18 4096
195
196/* Size of the piecewise linear cosine approximation table for the LSFs */
197#define LSF_COS_TAB_SZ_FIX 128
198
199/******************/
200/* NLSF quantizer */
201/******************/
202#define NLSF_W_Q 2
203#define NLSF_VQ_MAX_VECTORS 32
Gregory Maxwellae231142011-07-30 08:18:48 -0400204#define NLSF_QUANT_MAX_AMPLITUDE 4
205#define NLSF_QUANT_MAX_AMPLITUDE_EXT 10
206#define NLSF_QUANT_LEVEL_ADJ 0.1
207#define NLSF_QUANT_DEL_DEC_STATES_LOG2 2
208#define NLSF_QUANT_DEL_DEC_STATES ( 1 << NLSF_QUANT_DEL_DEC_STATES_LOG2 )
209
210/* Transition filtering for mode switching */
Koen Vosacc7a6c2011-10-28 19:44:26 -0400211#define TRANSITION_TIME_MS 5120 /* 5120 = 64 * FRAME_LENGTH_MS * ( TRANSITION_INT_NUM - 1 ) = 64*(20*4)*/
212#define TRANSITION_NB 3 /* Hardcoded in tables */
213#define TRANSITION_NA 2 /* Hardcoded in tables */
214#define TRANSITION_INT_NUM 5 /* Hardcoded in tables */
Jean-Marc Valinb24e5742011-10-11 21:09:14 -0400215#define TRANSITION_FRAMES ( TRANSITION_TIME_MS / MAX_FRAME_LENGTH_MS )
216#define TRANSITION_INT_STEPS ( TRANSITION_FRAMES / ( TRANSITION_INT_NUM - 1 ) )
Gregory Maxwellae231142011-07-30 08:18:48 -0400217
218/* BWE factors to apply after packet loss */
219#define BWE_AFTER_LOSS_Q16 63570
220
221/* Defines for CN generation */
Koen Vosacc7a6c2011-10-28 19:44:26 -0400222#define CNG_BUF_MASK_MAX 255 /* 2^floor(log2(MAX_FRAME_LENGTH))-1 */
223#define CNG_GAIN_SMTH_Q16 4634 /* 0.25^(1/4) */
224#define CNG_NLSF_SMTH_Q16 16348 /* 0.25 */
Gregory Maxwellae231142011-07-30 08:18:48 -0400225
226#ifdef __cplusplus
227}
228#endif
229
230#endif