private.h 7.7 KB

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