private.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
  3. * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
  4. * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
  5. */
  6. /*$Header: /tmp_amd/presto/export/kbs/jutta/src/gsm/RCS/private.h,v 1.6 1996/07/02 10:15:26 jutta Exp $*/
  7. #ifndef PRIVATE_H
  8. #define PRIVATE_H
  9. typedef short word; /* 16 bit signed int */
  10. typedef long longword; /* 32 bit signed int */
  11. typedef unsigned short uword; /* unsigned word */
  12. typedef unsigned long ulongword; /* unsigned longword */
  13. struct gsm_state {
  14. word dp0[ 280 ];
  15. word e[ 50 ]; /* code.c */
  16. word z1; /* preprocessing.c, Offset_com. */
  17. longword L_z2; /* Offset_com. */
  18. int mp; /* Preemphasis */
  19. word u[8]; /* short_term_aly_filter.c */
  20. word LARpp[2][8]; /* */
  21. word j; /* */
  22. word ltp_cut; /* long_term.c, LTP crosscorr. */
  23. word nrp; /* 40 */ /* long_term.c, synthesis */
  24. word v[9]; /* short_term.c, synthesis */
  25. word msr; /* decoder.c, Postprocessing */
  26. char verbose; /* only used if !NDEBUG */
  27. char fast; /* only used if FAST */
  28. char wav_fmt; /* only used if WAV49 defined */
  29. unsigned char frame_index; /* odd/even chaining */
  30. unsigned char frame_chain; /* half-byte to carry forward */
  31. };
  32. #define MIN_WORD (-32767 - 1)
  33. #define MAX_WORD 32767
  34. #define MIN_LONGWORD (-2147483647 - 1)
  35. #define MAX_LONGWORD 2147483647
  36. #ifdef SASR /* flag: >> is a signed arithmetic shift right */
  37. #undef SASR
  38. #define SASR(x, by) ((x) >> (by))
  39. #else
  40. #define SASR(x, by) ((x) >= 0 ? (x) >> (by) : (~(-((x) + 1) >> (by))))
  41. #endif /* SASR */
  42. #include "proto.h"
  43. /*
  44. * Prototypes from add.c
  45. */
  46. extern word gsm_mult P((word a, word b));
  47. extern longword gsm_L_mult P((word a, word b));
  48. extern word gsm_mult_r P((word a, word b));
  49. extern word gsm_div P((word num, word denum));
  50. extern word gsm_add P(( word a, word b ));
  51. extern longword gsm_L_add P(( longword a, longword b ));
  52. extern word gsm_sub P((word a, word b));
  53. extern longword gsm_L_sub P((longword a, longword b));
  54. extern word gsm_abs P((word a));
  55. extern word gsm_norm P(( longword a ));
  56. extern longword gsm_L_asl P((longword a, int n));
  57. extern word gsm_asl P((word a, int n));
  58. extern longword gsm_L_asr P((longword a, int n));
  59. extern word gsm_asr P((word a, int n));
  60. /*
  61. * Inlined functions from add.h
  62. */
  63. /*
  64. * #define GSM_MULT_R(a, b) (* word a, word b, !(a == b == MIN_WORD) *) \
  65. * (0x0FFFF & SASR(((longword)(a) * (longword)(b) + 16384), 15))
  66. */
  67. #define GSM_MULT_R(a, b) /* word a, word b, !(a == b == MIN_WORD) */ \
  68. (SASR( ((longword)(a) * (longword)(b) + 16384), 15 ))
  69. # define GSM_MULT(a,b) /* word a, word b, !(a == b == MIN_WORD) */ \
  70. (SASR( ((longword)(a) * (longword)(b)), 15 ))
  71. # define GSM_L_MULT(a, b) /* word a, word b */ \
  72. (((longword)(a) * (longword)(b)) << 1)
  73. # define GSM_L_ADD(a, b) \
  74. ( (a) < 0 ? ( (b) >= 0 ? (a) + (b) \
  75. : (utmp = (ulongword)-((a) + 1) + (ulongword)-((b) + 1)) \
  76. >= MAX_LONGWORD ? MIN_LONGWORD : -(longword)utmp-2 ) \
  77. : ((b) <= 0 ? (a) + (b) \
  78. : (utmp = (ulongword)(a) + (ulongword)(b)) >= MAX_LONGWORD \
  79. ? MAX_LONGWORD : utmp))
  80. /*
  81. * # define GSM_ADD(a, b) \
  82. * ((ltmp = (longword)(a) + (longword)(b)) >= MAX_WORD \
  83. * ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp)
  84. */
  85. /* Nonportable, but faster: */
  86. #define GSM_ADD(a, b) \
  87. ((ulongword)((ltmp = (longword)(a) + (longword)(b)) - MIN_WORD) > \
  88. MAX_WORD - MIN_WORD ? (ltmp > 0 ? MAX_WORD : MIN_WORD) : ltmp)
  89. # define GSM_SUB(a, b) \
  90. ((ltmp = (longword)(a) - (longword)(b)) >= MAX_WORD \
  91. ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp)
  92. # define GSM_ABS(a) ((a) < 0 ? ((a) == MIN_WORD ? MAX_WORD : -(a)) : (a))
  93. /* Use these if necessary:
  94. # define GSM_MULT_R(a, b) gsm_mult_r(a, b)
  95. # define GSM_MULT(a, b) gsm_mult(a, b)
  96. # define GSM_L_MULT(a, b) gsm_L_mult(a, b)
  97. # define GSM_L_ADD(a, b) gsm_L_add(a, b)
  98. # define GSM_ADD(a, b) gsm_add(a, b)
  99. # define GSM_SUB(a, b) gsm_sub(a, b)
  100. # define GSM_ABS(a) gsm_abs(a)
  101. */
  102. /*
  103. * More prototypes from implementations..
  104. */
  105. extern void Gsm_Coder P((
  106. struct gsm_state * S,
  107. word * s, /* [0..159] samples IN */
  108. word * LARc, /* [0..7] LAR coefficients OUT */
  109. word * Nc, /* [0..3] LTP lag OUT */
  110. word * bc, /* [0..3] coded LTP gain OUT */
  111. word * Mc, /* [0..3] RPE grid selection OUT */
  112. word * xmaxc,/* [0..3] Coded maximum amplitude OUT */
  113. word * xMc /* [13*4] normalized RPE samples OUT */));
  114. extern void Gsm_Long_Term_Predictor P(( /* 4x for 160 samples */
  115. struct gsm_state * S,
  116. word * d, /* [0..39] residual signal IN */
  117. word * dp, /* [-120..-1] d' IN */
  118. word * e, /* [0..40] OUT */
  119. word * dpp, /* [0..40] OUT */
  120. word * Nc, /* correlation lag OUT */
  121. word * bc /* gain factor OUT */));
  122. extern void Gsm_LPC_Analysis P((
  123. struct gsm_state * S,
  124. word * s, /* 0..159 signals IN/OUT */
  125. word * LARc)); /* 0..7 LARc's OUT */
  126. extern void Gsm_Preprocess P((
  127. struct gsm_state * S,
  128. word * s, word * so));
  129. extern void Gsm_Encoding P((
  130. struct gsm_state * S,
  131. word * e,
  132. word * ep,
  133. word * xmaxc,
  134. word * Mc,
  135. word * xMc));
  136. extern void Gsm_Short_Term_Analysis_Filter P((
  137. struct gsm_state * S,
  138. word * LARc, /* coded log area ratio [0..7] IN */
  139. word * d /* st res. signal [0..159] IN/OUT */));
  140. extern void Gsm_Decoder P((
  141. struct gsm_state * S,
  142. word * LARcr, /* [0..7] IN */
  143. word * Ncr, /* [0..3] IN */
  144. word * bcr, /* [0..3] IN */
  145. word * Mcr, /* [0..3] IN */
  146. word * xmaxcr, /* [0..3] IN */
  147. word * xMcr, /* [0..13*4] IN */
  148. word * s)); /* [0..159] OUT */
  149. extern void Gsm_Decoding P((
  150. struct gsm_state * S,
  151. word xmaxcr,
  152. word Mcr,
  153. word * xMcr, /* [0..12] IN */
  154. word * erp)); /* [0..39] OUT */
  155. extern void Gsm_Long_Term_Synthesis_Filtering P((
  156. struct gsm_state* S,
  157. word Ncr,
  158. word bcr,
  159. word * erp, /* [0..39] IN */
  160. word * drp)); /* [-120..-1] IN, [0..40] OUT */
  161. void Gsm_RPE_Decoding P((
  162. struct gsm_state *S,
  163. word xmaxcr,
  164. word Mcr,
  165. word * xMcr, /* [0..12], 3 bits IN */
  166. word * erp)); /* [0..39] OUT */
  167. void Gsm_RPE_Encoding P((
  168. struct gsm_state * S,
  169. word * e, /* -5..-1][0..39][40..44 IN/OUT */
  170. word * xmaxc, /* OUT */
  171. word * Mc, /* OUT */
  172. word * xMc)); /* [0..12] OUT */
  173. extern void Gsm_Short_Term_Synthesis_Filter P((
  174. struct gsm_state * S,
  175. word * LARcr, /* log area ratios [0..7] IN */
  176. word * drp, /* received d [0...39] IN */
  177. word * s)); /* signal s [0..159] OUT */
  178. extern void Gsm_Update_of_reconstructed_short_time_residual_signal P((
  179. word * dpp, /* [0...39] IN */
  180. word * ep, /* [0...39] IN */
  181. word * dp)); /* [-120...-1] IN/OUT */
  182. /*
  183. * Tables from table.c
  184. */
  185. #ifndef GSM_TABLE_C
  186. extern word gsm_A[8], gsm_B[8], gsm_MIC[8], gsm_MAC[8];
  187. extern word gsm_INVA[8];
  188. extern word gsm_DLB[4], gsm_QLB[4];
  189. extern word gsm_H[11];
  190. extern word gsm_NRFAC[8];
  191. extern word gsm_FAC[8];
  192. #endif /* GSM_TABLE_C */
  193. /*
  194. * Debugging
  195. */
  196. #ifdef NDEBUG
  197. # define gsm_debug_words(a, b, c, d) /* nil */
  198. # define gsm_debug_longwords(a, b, c, d) /* nil */
  199. # define gsm_debug_word(a, b) /* nil */
  200. # define gsm_debug_longword(a, b) /* nil */
  201. #else /* !NDEBUG => DEBUG */
  202. extern void gsm_debug_words P((char * name, int, int, word *));
  203. extern void gsm_debug_longwords P((char * name, int, int, longword *));
  204. extern void gsm_debug_longword P((char * name, longword));
  205. extern void gsm_debug_word P((char * name, word));
  206. #endif /* !NDEBUG */
  207. #include "unproto.h"
  208. #endif /* PRIVATE_H */