vad2.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. ********************************************************************************
  3. *
  4. * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
  5. * R99 Version 3.3.0
  6. * REL-4 Version 4.1.0
  7. *
  8. ********************************************************************************
  9. *
  10. * File : vad2.h
  11. * Purpose : Voice Activity Detection (VAD) for AMR (option 2)
  12. *
  13. ********************************************************************************
  14. */
  15. #ifndef vad2_h
  16. #define vad2_h "$Id $"
  17. #include "typedef.h"
  18. /***** Defines ****/
  19. #define YES 1
  20. #define NO 0
  21. #define ON 1
  22. #define OFF 0
  23. #define TRUE 1
  24. #define FALSE 0
  25. #define FRM_LEN 80
  26. #define DELAY 24
  27. #define FFT_LEN 128
  28. #define NUM_CHAN 16
  29. #define LO_CHAN 0
  30. #define HI_CHAN 15
  31. #define UPDATE_THLD 35
  32. #define HYSTER_CNT_THLD 6
  33. #define UPDATE_CNT_THLD 50
  34. #define SHIFT_STATE_0 0 /* channel energy scaled as 22,9 */
  35. #define SHIFT_STATE_1 1 /* channel energy scaled as 27,4 */
  36. #define NOISE_FLOOR_CHAN_0 512 /* 1.0 scaled as 22,9 */
  37. #define MIN_CHAN_ENRG_0 32 /* 0.0625 scaled as 22,9 */
  38. #define MIN_NOISE_ENRG_0 32 /* 0.0625 scaled as 22,9 */
  39. #define INE_NOISE_0 8192 /* 16.0 scaled as 22,9 */
  40. #define FRACTIONAL_BITS_0 9 /* used as input to fn10Log10() */
  41. #define NOISE_FLOOR_CHAN_1 16 /* 1.0 scaled as 27,4 */
  42. #define MIN_CHAN_ENRG_1 1 /* 0.0625 scaled as 27,4 */
  43. #define MIN_NOISE_ENRG_1 1 /* 0.0625 scaled as 27,4 */
  44. #define INE_NOISE_1 256 /* 16.0 scaled as 27,4 */
  45. #define FRACTIONAL_BITS_1 4 /* used as input to fn10Log10() */
  46. #define STATE_1_TO_0_SHIFT_R (FRACTIONAL_BITS_1-FRACTIONAL_BITS_0) /* state correction factor */
  47. #define STATE_0_TO_1_SHIFT_R (FRACTIONAL_BITS_0-FRACTIONAL_BITS_1) /* state correction factor */
  48. #define HIGH_ALPHA 29491 /* 0.9 scaled as 0,15 */
  49. #define LOW_ALPHA 22938 /* 0.7 scaled as 0,15 */
  50. #define ALPHA_RANGE (HIGH_ALPHA - LOW_ALPHA)
  51. #define DEV_THLD 7168 /* 28.0 scaled as 7,8 */
  52. #define PRE_EMP_FAC (-26214) /* -0.8 scaled as 0,15 */
  53. #define CEE_SM_FAC 18022 /* 0.55 scaled as 0,15 */
  54. #define ONE_MINUS_CEE_SM_FAC 14746 /* 0.45 scaled as 0,15 */
  55. #define CNE_SM_FAC 3277 /* 0.1 scaled as 0,15 */
  56. #define ONE_MINUS_CNE_SM_FAC 29491 /* 0.9 scaled as 0,15 */
  57. #define FFT_HEADROOM 2
  58. typedef struct
  59. {
  60. Word16 pre_emp_mem;
  61. Word16 update_cnt;
  62. Word16 hyster_cnt;
  63. Word16 last_update_cnt;
  64. Word16 ch_enrg_long_db[NUM_CHAN]; /* scaled as 7,8 */
  65. Word32 Lframe_cnt;
  66. Word32 Lch_enrg[NUM_CHAN]; /* scaled as 22,9 or 27,4 */
  67. Word32 Lch_noise[NUM_CHAN]; /* scaled as 22,9 */
  68. Word16 last_normb_shift; /* last block norm shift count */
  69. Word16 tsnr; /* total signal-to-noise ratio in dB (scaled as 7,8) */
  70. Word16 hangover;
  71. Word16 burstcount;
  72. Word16 fupdate_flag; /* forced update flag from previous frame */
  73. Word16 negSNRvar; /* Negative SNR variance (scaled as 7,8) */
  74. Word16 negSNRbias; /* sensitivity bias from negative SNR variance (scaled as 15,0) */
  75. Word16 shift_state; /* use 22,9 or 27,4 scaling for ch_enrg[] */
  76. Word32 L_R0;
  77. Word32 L_Rmax;
  78. Flag LTP_flag; /* Use to indicate the the LTP gain is > LTP_THRESH */
  79. } vadState2;
  80. /**** Prototypes ****/
  81. Word16 vad2 (Word16 *farray_ptr, vadState2 *st);
  82. int vad2_init (vadState2 **st);
  83. int vad2_reset (vadState2 *st);
  84. void vad2_exit (vadState2 **state);
  85. void r_fft_ex (Word16 *farray_ptr);
  86. void LTP_flag_update (vadState2 *st, Word16 mode);
  87. #endif