defines.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. /******************************************************************
  11. iLBC Speech Coder ANSI-C Source Code
  12. define.h
  13. ******************************************************************/
  14. #ifndef MODULES_AUDIO_CODING_CODECS_ILBC_MAIN_SOURCE_DEFINES_H_
  15. #define MODULES_AUDIO_CODING_CODECS_ILBC_MAIN_SOURCE_DEFINES_H_
  16. #include <string.h>
  17. #include "common_audio/signal_processing/include/signal_processing_library.h"
  18. /* general codec settings */
  19. #define FS 8000
  20. #define BLOCKL_20MS 160
  21. #define BLOCKL_30MS 240
  22. #define BLOCKL_MAX 240
  23. #define NSUB_20MS 4
  24. #define NSUB_30MS 6
  25. #define NSUB_MAX 6
  26. #define NASUB_20MS 2
  27. #define NASUB_30MS 4
  28. #define NASUB_MAX 4
  29. #define SUBL 40
  30. #define STATE_LEN 80
  31. #define STATE_SHORT_LEN_30MS 58
  32. #define STATE_SHORT_LEN_20MS 57
  33. /* LPC settings */
  34. #define LPC_FILTERORDER 10
  35. #define LPC_LOOKBACK 60
  36. #define LPC_N_20MS 1
  37. #define LPC_N_30MS 2
  38. #define LPC_N_MAX 2
  39. #define LPC_ASYMDIFF 20
  40. #define LSF_NSPLIT 3
  41. #define LSF_NUMBER_OF_STEPS 4
  42. #define LPC_HALFORDER 5
  43. #define COS_GRID_POINTS 60
  44. /* cb settings */
  45. #define CB_NSTAGES 3
  46. #define CB_EXPAND 2
  47. #define CB_MEML 147
  48. #define CB_FILTERLEN (2 * 4)
  49. #define CB_HALFFILTERLEN 4
  50. #define CB_RESRANGE 34
  51. #define CB_MAXGAIN_FIXQ6 83 /* error = -0.24% */
  52. #define CB_MAXGAIN_FIXQ14 21299
  53. /* enhancer */
  54. #define ENH_BLOCKL 80 /* block length */
  55. #define ENH_BLOCKL_HALF (ENH_BLOCKL / 2)
  56. #define ENH_HL \
  57. 3 /* 2*ENH_HL+1 is number blocks \
  58. in said second \
  59. sequence */
  60. #define ENH_SLOP \
  61. 2 /* max difference estimated and \
  62. correct pitch period */
  63. #define ENH_PLOCSL \
  64. 8 /* pitch-estimates and \
  65. pitch-locations buffer \
  66. length */
  67. #define ENH_OVERHANG 2
  68. #define ENH_UPS0 4 /* upsampling rate */
  69. #define ENH_FL0 3 /* 2*FLO+1 is the length of each filter */
  70. #define ENH_FLO_MULT2_PLUS1 7
  71. #define ENH_VECTL (ENH_BLOCKL + 2 * ENH_FL0)
  72. #define ENH_CORRDIM (2 * ENH_SLOP + 1)
  73. #define ENH_NBLOCKS (BLOCKL / ENH_BLOCKL)
  74. #define ENH_NBLOCKS_EXTRA 5
  75. #define ENH_NBLOCKS_TOT 8 /* ENH_NBLOCKS+ENH_NBLOCKS_EXTRA */
  76. #define ENH_BUFL (ENH_NBLOCKS_TOT) * ENH_BLOCKL
  77. #define ENH_BUFL_FILTEROVERHEAD 3
  78. #define ENH_A0 819 /* Q14 */
  79. #define ENH_A0_MINUS_A0A0DIV4 848256041 /* Q34 */
  80. #define ENH_A0DIV2 26843546 /* Q30 */
  81. /* PLC */
  82. /* Down sampling */
  83. #define FILTERORDER_DS_PLUS1 7
  84. #define DELAY_DS 3
  85. #define FACTOR_DS 2
  86. /* bit stream defs */
  87. #define NO_OF_BYTES_20MS 38
  88. #define NO_OF_BYTES_30MS 50
  89. #define NO_OF_WORDS_20MS 19
  90. #define NO_OF_WORDS_30MS 25
  91. #define STATE_BITS 3
  92. #define BYTE_LEN 8
  93. #define ULP_CLASSES 3
  94. /* help parameters */
  95. #define TWO_PI_FIX 25736 /* Q12 */
  96. /* Constants for codebook search and creation */
  97. #define ST_MEM_L_TBL 85
  98. #define MEM_LF_TBL 147
  99. /* Struct for the bits */
  100. typedef struct iLBC_bits_t_ {
  101. int16_t lsf[LSF_NSPLIT * LPC_N_MAX];
  102. int16_t cb_index[CB_NSTAGES * (NASUB_MAX + 1)]; /* First CB_NSTAGES values
  103. contains extra CB index */
  104. int16_t gain_index[CB_NSTAGES * (NASUB_MAX + 1)]; /* First CB_NSTAGES values
  105. contains extra CB gain */
  106. size_t idxForMax;
  107. int16_t state_first;
  108. int16_t idxVec[STATE_SHORT_LEN_30MS];
  109. int16_t firstbits;
  110. size_t startIdx;
  111. } iLBC_bits;
  112. /* type definition encoder instance */
  113. typedef struct IlbcEncoder_ {
  114. /* flag for frame size mode */
  115. int16_t mode;
  116. /* basic parameters for different frame sizes */
  117. size_t blockl;
  118. size_t nsub;
  119. int16_t nasub;
  120. size_t no_of_bytes, no_of_words;
  121. int16_t lpc_n;
  122. size_t state_short_len;
  123. /* analysis filter state */
  124. int16_t anaMem[LPC_FILTERORDER];
  125. /* Fix-point old lsf parameters for interpolation */
  126. int16_t lsfold[LPC_FILTERORDER];
  127. int16_t lsfdeqold[LPC_FILTERORDER];
  128. /* signal buffer for LP analysis */
  129. int16_t lpc_buffer[LPC_LOOKBACK + BLOCKL_MAX];
  130. /* state of input HP filter */
  131. int16_t hpimemx[2];
  132. int16_t hpimemy[4];
  133. #ifdef SPLIT_10MS
  134. int16_t weightdenumbuf[66];
  135. int16_t past_samples[160];
  136. uint16_t bytes[25];
  137. int16_t section;
  138. int16_t Nfor_flag;
  139. int16_t Nback_flag;
  140. int16_t start_pos;
  141. size_t diff;
  142. #endif
  143. } IlbcEncoder;
  144. /* type definition decoder instance */
  145. typedef struct IlbcDecoder_ {
  146. /* flag for frame size mode */
  147. int16_t mode;
  148. /* basic parameters for different frame sizes */
  149. size_t blockl;
  150. size_t nsub;
  151. int16_t nasub;
  152. size_t no_of_bytes, no_of_words;
  153. int16_t lpc_n;
  154. size_t state_short_len;
  155. /* synthesis filter state */
  156. int16_t syntMem[LPC_FILTERORDER];
  157. /* old LSF for interpolation */
  158. int16_t lsfdeqold[LPC_FILTERORDER];
  159. /* pitch lag estimated in enhancer and used in PLC */
  160. size_t last_lag;
  161. /* PLC state information */
  162. int consPLICount, prev_enh_pl;
  163. int16_t perSquare;
  164. int16_t prevScale, prevPLI;
  165. size_t prevLag;
  166. int16_t prevLpc[LPC_FILTERORDER + 1];
  167. int16_t prevResidual[NSUB_MAX * SUBL];
  168. int16_t seed;
  169. /* previous synthesis filter parameters */
  170. int16_t old_syntdenum[(LPC_FILTERORDER + 1) * NSUB_MAX];
  171. /* state of output HP filter */
  172. int16_t hpimemx[2];
  173. int16_t hpimemy[4];
  174. /* enhancer state information */
  175. int use_enhancer;
  176. int16_t enh_buf[ENH_BUFL + ENH_BUFL_FILTEROVERHEAD];
  177. size_t enh_period[ENH_NBLOCKS_TOT];
  178. } IlbcDecoder;
  179. #endif