define.h 9.7 KB

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