iLBC_define.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /******************************************************************
  2. iLBC Speech Coder ANSI-C Source Code
  3. iLBC_define.h
  4. Copyright (C) The Internet Society (2004).
  5. All Rights Reserved.
  6. ******************************************************************/
  7. #include <string.h>
  8. #ifndef __iLBC_ILBCDEFINE_H
  9. #define __iLBC_ILBCDEFINE_H
  10. /* general codec settings */
  11. #define BLOCKL_20MS 160
  12. #define BLOCKL_30MS 240
  13. #define BLOCKL_MAX 240
  14. #define NSUB_20MS 4
  15. #define NSUB_30MS 6
  16. #define NSUB_MAX 6
  17. #define NASUB_20MS 2
  18. #define NASUB_30MS 4
  19. #define NASUB_MAX 4
  20. #define SUBL 40
  21. #define STATE_LEN 80
  22. #define STATE_SHORT_LEN_30MS 58
  23. #define STATE_SHORT_LEN_20MS 57
  24. /* LPC settings */
  25. #define LPC_FILTERORDER 10
  26. #define LPC_CHIRP_SYNTDENUM (float)0.9025
  27. #define LPC_CHIRP_WEIGHTDENUM (float)0.4222
  28. #define LPC_LOOKBACK 60
  29. #define LPC_N_20MS 1
  30. #define LPC_N_30MS 2
  31. #define LPC_N_MAX 2
  32. #define LPC_ASYMDIFF 20
  33. #define LPC_BW (float)60.0
  34. #define LPC_WN (float)1.0001
  35. #define LSF_NSPLIT 3
  36. #define LSF_NUMBER_OF_STEPS 4
  37. #define LPC_HALFORDER (LPC_FILTERORDER/2)
  38. /* cb settings */
  39. #define CB_NSTAGES 3
  40. #define CB_EXPAND 2
  41. #define CB_MEML 147
  42. #define CB_FILTERLEN 2*4
  43. #define CB_HALFFILTERLEN 4
  44. #define CB_RESRANGE 34
  45. #define CB_MAXGAIN (float)1.3
  46. /* enhancer */
  47. #define ENH_BLOCKL 80 /* block length */
  48. #define ENH_BLOCKL_HALF (ENH_BLOCKL/2)
  49. #define ENH_HL 3 /* 2*ENH_HL+1 is number blocks
  50. in said second sequence */
  51. #define ENH_SLOP 2 /* max difference estimated and
  52. correct pitch period */
  53. #define ENH_PLOCSL 20 /* pitch-estimates and pitch-
  54. locations buffer length */
  55. #define ENH_OVERHANG 2
  56. #define ENH_UPS0 4 /* upsampling rate */
  57. #define ENH_FL0 3 /* 2*FLO+1 is the length of
  58. each filter */
  59. #define ENH_VECTL (ENH_BLOCKL+2*ENH_FL0)
  60. #define ENH_CORRDIM (2*ENH_SLOP+1)
  61. #define ENH_NBLOCKS (BLOCKL_MAX/ENH_BLOCKL)
  62. #define ENH_NBLOCKS_EXTRA 5
  63. #define ENH_NBLOCKS_TOT 8 /* ENH_NBLOCKS +
  64. ENH_NBLOCKS_EXTRA */
  65. #define ENH_BUFL (ENH_NBLOCKS_TOT)*ENH_BLOCKL
  66. #define ENH_ALPHA0 (float)0.05
  67. /* Down sampling */
  68. #define FILTERORDER_DS 7
  69. #define DELAY_DS 3
  70. #define FACTOR_DS 2
  71. /* bit stream defs */
  72. #define NO_OF_BYTES_20MS 38
  73. #define NO_OF_BYTES_30MS 50
  74. #define NO_OF_WORDS_20MS 19
  75. #define NO_OF_WORDS_30MS 25
  76. #define STATE_BITS 3
  77. #define BYTE_LEN 8
  78. #define ULP_CLASSES 3
  79. /* help parameters */
  80. #define FLOAT_MAX (float)1.0e37
  81. #define EPS (float)2.220446049250313e-016
  82. #define PI (float)3.14159265358979323846
  83. #define MIN_SAMPLE -32768
  84. #define MAX_SAMPLE 32767
  85. #define TWO_PI (float)6.283185307
  86. #define PI2 (float)0.159154943
  87. /* type definition encoder instance */
  88. typedef struct iLBC_ULP_Inst_t_ {
  89. int lsf_bits[6][ULP_CLASSES+2];
  90. int start_bits[ULP_CLASSES+2];
  91. int startfirst_bits[ULP_CLASSES+2];
  92. int scale_bits[ULP_CLASSES+2];
  93. int state_bits[ULP_CLASSES+2];
  94. int extra_cb_index[CB_NSTAGES][ULP_CLASSES+2];
  95. int extra_cb_gain[CB_NSTAGES][ULP_CLASSES+2];
  96. int cb_index[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2];
  97. int cb_gain[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2];
  98. } iLBC_ULP_Inst_t;
  99. /* type definition encoder instance */
  100. typedef struct iLBC_Enc_Inst_t_ {
  101. /* flag for frame size mode */
  102. int mode;
  103. /* basic parameters for different frame sizes */
  104. int blockl;
  105. int nsub;
  106. int nasub;
  107. int no_of_bytes, no_of_words;
  108. int lpc_n;
  109. int state_short_len;
  110. const iLBC_ULP_Inst_t *ULP_inst;
  111. /* analysis filter state */
  112. float anaMem[LPC_FILTERORDER];
  113. /* old lsf parameters for interpolation */
  114. float lsfold[LPC_FILTERORDER];
  115. float lsfdeqold[LPC_FILTERORDER];
  116. /* signal buffer for LP analysis */
  117. float lpc_buffer[LPC_LOOKBACK + BLOCKL_MAX];
  118. /* state of input HP filter */
  119. float hpimem[4];
  120. } iLBC_Enc_Inst_t;
  121. /* type definition decoder instance */
  122. typedef struct iLBC_Dec_Inst_t_ {
  123. /* flag for frame size mode */
  124. int mode;
  125. /* basic parameters for different frame sizes */
  126. int blockl;
  127. int nsub;
  128. int nasub;
  129. int no_of_bytes, no_of_words;
  130. int lpc_n;
  131. int state_short_len;
  132. const iLBC_ULP_Inst_t *ULP_inst;
  133. /* synthesis filter state */
  134. float syntMem[LPC_FILTERORDER];
  135. /* old LSF for interpolation */
  136. float lsfdeqold[LPC_FILTERORDER];
  137. /* pitch lag estimated in enhancer and used in PLC */
  138. int last_lag;
  139. /* PLC state information */
  140. int prevLag, consPLICount, prevPLI, prev_enh_pl;
  141. float prevLpc[LPC_FILTERORDER+1];
  142. float prevResidual[NSUB_MAX*SUBL];
  143. float per;
  144. unsigned long seed;
  145. /* previous synthesis filter parameters */
  146. float old_syntdenum[(LPC_FILTERORDER + 1)*NSUB_MAX];
  147. /* state of output HP filter */
  148. float hpomem[4];
  149. /* enhancer state information */
  150. int use_enhancer;
  151. float enh_buf[ENH_BUFL];
  152. float enh_period[ENH_NBLOCKS_TOT];
  153. } iLBC_Dec_Inst_t;
  154. #endif