cod_amr.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 : cod_amr.h
  11. * Purpose : Main encoder routine operating on a frame basis.
  12. *
  13. *****************************************************************************
  14. */
  15. #ifndef cod_amr_h
  16. #define cod_amr_h "$Id $"
  17. /*
  18. *****************************************************************************
  19. * INCLUDE FILES
  20. *****************************************************************************
  21. */
  22. #include "typedef.h"
  23. #include "cnst.h"
  24. #include "mode.h"
  25. #include "lpc.h"
  26. #include "lsp.h"
  27. #include "cl_ltp.h"
  28. #include "gain_q.h"
  29. #include "p_ol_wgh.h"
  30. #include "ton_stab.h"
  31. #include "vad.h"
  32. #include "dtx_enc.h"
  33. /*
  34. *****************************************************************************
  35. * DEFINITION OF DATA TYPES
  36. *****************************************************************************
  37. */
  38. /*-----------------------------------------------------------*
  39. * Coder constant parameters (defined in "cnst.h") *
  40. *-----------------------------------------------------------*
  41. * L_WINDOW : LPC analysis window size. *
  42. * L_NEXT : Samples of next frame needed for autocor. *
  43. * L_FRAME : Frame size. *
  44. * L_FRAME_BY2 : Half the frame size. *
  45. * L_SUBFR : Sub-frame size. *
  46. * M : LPC order. *
  47. * MP1 : LPC order+1 *
  48. * L_TOTAL7k4 : Total size of speech buffer. *
  49. * PIT_MIN7k4 : Minimum pitch lag. *
  50. * PIT_MAX : Maximum pitch lag. *
  51. * L_INTERPOL : Length of filter for interpolation *
  52. *-----------------------------------------------------------*/
  53. typedef struct {
  54. /* Speech vector */
  55. Word16 old_speech[L_TOTAL];
  56. Word16 *speech, *p_window, *p_window_12k2;
  57. Word16 *new_speech; /* Global variable */
  58. /* Weight speech vector */
  59. Word16 old_wsp[L_FRAME + PIT_MAX];
  60. Word16 *wsp;
  61. /* OL LTP states */
  62. Word16 old_lags[5];
  63. Word16 ol_gain_flg[2];
  64. /* Excitation vector */
  65. Word16 old_exc[L_FRAME + PIT_MAX + L_INTERPOL];
  66. Word16 *exc;
  67. /* Zero vector */
  68. Word16 ai_zero[L_SUBFR + MP1];
  69. Word16 *zero;
  70. /* Impulse response vector */
  71. Word16 *h1;
  72. Word16 hvec[L_SUBFR * 2];
  73. /* Substates */
  74. lpcState *lpcSt;
  75. lspState *lspSt;
  76. clLtpState *clLtpSt;
  77. gainQuantState *gainQuantSt;
  78. pitchOLWghtState *pitchOLWghtSt;
  79. tonStabState *tonStabSt;
  80. vadState *vadSt;
  81. Flag dtx;
  82. dtx_encState *dtx_encSt;
  83. /* Filter's memory */
  84. Word16 mem_syn[M], mem_w0[M], mem_w[M];
  85. Word16 mem_err[M + L_SUBFR], *error;
  86. Word16 sharp;
  87. } cod_amrState;
  88. /*
  89. ********************************************************************************
  90. * DECLARATION OF PROTOTYPES
  91. ********************************************************************************
  92. */
  93. /*
  94. **************************************************************************
  95. *
  96. * Function : cod_amr_init
  97. * Purpose : Allocates memory and initializes state variables
  98. * Description : Stores pointer to filter status struct in *st. This
  99. * pointer has to be passed to cod_amr in each call.
  100. * - initilize pointers to speech buffer
  101. * - initialize static pointers
  102. * - set static vectors to zero
  103. * Returns : 0 on success
  104. *
  105. **************************************************************************
  106. */
  107. int cod_amr_init (cod_amrState **st, Flag dtx);
  108. /*
  109. **************************************************************************
  110. *
  111. * Function : cod_amr_reset
  112. * Purpose : Resets state memory
  113. * Returns : 0 on success
  114. *
  115. **************************************************************************
  116. */
  117. int cod_amr_reset (cod_amrState *st);
  118. /*
  119. **************************************************************************
  120. *
  121. * Function : cod_amr_exit
  122. * Purpose : The memory used for state memory is freed
  123. * Description : Stores NULL in *st
  124. *
  125. **************************************************************************
  126. */
  127. void cod_amr_exit (cod_amrState **st);
  128. /***************************************************************************
  129. * FUNCTION: cod_amr_first
  130. *
  131. * PURPOSE: Copes with look-ahead.
  132. *
  133. * INPUTS:
  134. * No input argument are passed to this function. However, before
  135. * calling this function, 40 new speech data should be copied to the
  136. * vector new_speech[]. This is a global pointer which is declared in
  137. * this file (it points to the end of speech buffer minus 200).
  138. *
  139. ***************************************************************************/
  140. int cod_amr_first(cod_amrState *st, /* i/o : State struct */
  141. Word16 new_speech[] /* i : speech input (L_FRAME) */
  142. );
  143. /***************************************************************************
  144. * FUNCTION: cod_amr
  145. *
  146. * PURPOSE: Main encoder routine.
  147. *
  148. * DESCRIPTION: This function is called every 20 ms speech frame,
  149. * operating on the newly read 160 speech samples. It performs the
  150. * principle encoding functions to produce the set of encoded parameters
  151. * which include the LSP, adaptive codebook, and fixed codebook
  152. * quantization indices (addresses and gains).
  153. *
  154. * INPUTS:
  155. * No input argument are passed to this function. However, before
  156. * calling this function, 160 new speech data should be copied to the
  157. * vector new_speech[]. This is a global pointer which is declared in
  158. * this file (it points to the end of speech buffer minus 160).
  159. *
  160. * OUTPUTS:
  161. *
  162. * ana[]: vector of analysis parameters.
  163. * synth[]: Local synthesis speech (for debugging purposes)
  164. *
  165. ***************************************************************************/
  166. int cod_amr(cod_amrState *st, /* i/o : State struct */
  167. enum Mode mode, /* i : AMR mode */
  168. Word16 new_speech[], /* i : speech input (L_FRAME) */
  169. Word16 ana[], /* o : Analysis parameters */
  170. enum Mode *usedMode, /* o : used mode */
  171. Word16 synth[] /* o : Local synthesis */
  172. );
  173. #endif