dtx.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. ITU-T G.729A Annex B ANSI-C Source Code
  3. Version 1.3 Last modified: August 1997
  4. Copyright (c) 1996, France Telecom, Rockwell International,
  5. Universite de Sherbrooke.
  6. All rights reserved.
  7. */
  8. /*--------------------------------------------------------------------------*
  9. * Prototypes for DTX/CNG *
  10. *--------------------------------------------------------------------------*/
  11. /* Encoder DTX/CNG functions */
  12. void Init_Cod_cng(void);
  13. void Cod_cng(
  14. Word16 *exc, /* (i/o) : excitation array */
  15. Word16 pastVad, /* (i) : previous VAD decision */
  16. Word16 *lsp_old_q, /* (i/o) : previous quantized lsp */
  17. Word16 *Aq, /* (o) : set of interpolated LPC coefficients */
  18. Word16 *ana, /* (o) : coded SID parameters */
  19. Word16 freq_prev[MA_NP][M],
  20. /* (i/o) : previous LPS for quantization */
  21. Word16 *seed /* (i/o) : random generator seed */
  22. );
  23. void Update_cng(
  24. Word16 *r_h, /* (i) : MSB of frame autocorrelation */
  25. Word16 exp_r, /* (i) : scaling factor associated */
  26. Word16 Vad /* (i) : current Vad decision */
  27. );
  28. /* SID gain Quantization */
  29. void Qua_Sidgain(
  30. Word16 *ener, /* (i) array of energies */
  31. Word16 *sh_ener, /* (i) corresponding scaling factors */
  32. Word16 nb_ener, /* (i) number of energies or */
  33. Word16 *enerq, /* (o) decoded energies in dB */
  34. Word16 *idx /* (o) SID gain quantization index */
  35. );
  36. /* CNG excitation generation */
  37. void Calc_exc_rand(
  38. Word16 cur_gain, /* (i) : target sample gain */
  39. Word16 *exc, /* (i/o) : excitation array */
  40. Word16 *seed, /* (i) : current Vad decision */
  41. Flag flag_cod /* (i) : encoder/decoder flag */
  42. );
  43. /* SID LSP Quantization */
  44. void Get_freq_prev(Word16 x[MA_NP][M]);
  45. void Update_freq_prev(Word16 x[MA_NP][M]);
  46. void Get_decfreq_prev(Word16 x[MA_NP][M]);
  47. void Update_decfreq_prev(Word16 x[MA_NP][M]);
  48. /* Decoder CNG generation */
  49. void Init_Dec_cng(void);
  50. void Dec_cng(
  51. Word16 past_ftyp, /* (i) : past frame type */
  52. Word16 sid_sav, /* (i) : energy to recover SID gain */
  53. Word16 sh_sid_sav, /* (i) : corresponding scaling factor */
  54. Word16 *parm, /* (i) : coded SID parameters */
  55. Word16 *exc, /* (i/o) : excitation array */
  56. Word16 *lsp_old, /* (i/o) : previous lsp */
  57. Word16 *A_t, /* (o) : set of interpolated LPC coefficients */
  58. Word16 *seed, /* (i/o) : random generator seed */
  59. Word16 freq_prev[MA_NP][M]
  60. /* (i/o) : previous LPS for quantization */
  61. );
  62. Word16 read_frame(FILE *f_serial, Word16 *parm);
  63. /*--------------------------------------------------------------------------*
  64. * Constants for DTX/CNG *
  65. *--------------------------------------------------------------------------*/
  66. /* DTX constants */
  67. #define FLAG_COD (Flag)1
  68. #define FLAG_DEC (Flag)0
  69. #define INIT_SEED 11111
  70. #define FR_SID_MIN 3
  71. #define NB_SUMACF 3
  72. #define NB_CURACF 2
  73. #define NB_GAIN 2
  74. #define FRAC_THRESH1 4855
  75. #define FRAC_THRESH2 3161
  76. #define A_GAIN0 28672
  77. #define SIZ_SUMACF (NB_SUMACF * MP1)
  78. #define SIZ_ACF (NB_CURACF * MP1)
  79. #define A_GAIN1 4096 /* 32768L - A_GAIN0 */
  80. #define RATE_8000 80 /* Full rate (8000 bit/s) */
  81. #define RATE_SID 15 /* SID */
  82. #define RATE_0 0 /* 0 bit/s rate */
  83. /* CNG excitation generation constant */
  84. /* alpha = 0.5 */
  85. #define FRAC1 19043 /* (sqrt(40)xalpha/2 - 1) * 32768 */
  86. #define K0 24576 /* (1 - alpha ** 2) in Q15 */
  87. #define G_MAX 5000