iLBC_define.h 6.1 KB

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