Asterisk - The Open Source Telephony Project  18.5.0
codecs/gsm/inc/private.h
Go to the documentation of this file.
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 
7 /*$Header$*/
8 
9 #ifndef PRIVATE_H
10 #define PRIVATE_H
11 
12 typedef short word; /* 16 bit signed int */
13 typedef long longword; /* 32 bit signed int */
14 
15 typedef unsigned short uword; /* unsigned word */
16 typedef unsigned long ulongword; /* unsigned longword */
17 
18 struct gsm_state {
19 
20  word dp0[ 280 ];
21 
22  word z1; /* preprocessing.c, Offset_com. */
23  longword L_z2; /* Offset_com. */
24  int mp; /* Preemphasis */
25 
26  word u[8]; /* short_term_aly_filter.c */
27  word LARpp[2][8]; /* */
28  word j; /* */
29 
30  word ltp_cut; /* long_term.c, LTP crosscorr. */
31  word nrp; /* 40 */ /* long_term.c, synthesis */
32  word v[9]; /* short_term.c, synthesis */
33  word msr; /* decoder.c, Postprocessing */
34 
35  char verbose; /* only used if !NDEBUG */
36  char fast; /* only used if FAST */
37 
38  char wav_fmt; /* only used if WAV49 defined */
39  unsigned char frame_index; /* odd/even chaining */
40  unsigned char frame_chain; /* half-byte to carry forward */
41 };
42 
43 
44 #define MIN_WORD (-32767 - 1)
45 #define MAX_WORD 32767
46 
47 #define MIN_LONGWORD (-2147483647 - 1)
48 #define MAX_LONGWORD 2147483647
49 
50 #ifdef SASR /* flag: >> is a signed arithmetic shift right */
51 #undef SASR
52 #define SASR(x, by) ((x) >> (by))
53 #else
54 #define SASR(x, by) ((x) >= 0 ? (x) >> (by) : (~(-((x) + 1) >> (by))))
55 #endif /* SASR */
56 
57 #include "proto.h"
58 
59 /*
60  * Prototypes from add.c
61  */
62 extern word gsm_mult P((word a, word b));
63 extern longword gsm_L_mult P((word a, word b));
64 extern word gsm_mult_r P((word a, word b));
65 
66 extern word gsm_div P((word num, word denum));
67 
68 extern word gsm_add P(( word a, word b ));
69 extern longword gsm_L_add P(( longword a, longword b ));
70 
71 extern word gsm_sub P((word a, word b));
72 extern longword gsm_L_sub P((longword a, longword b));
73 
74 extern word gsm_abs P((word a));
75 
76 extern word gsm_norm P(( longword a ));
77 
78 extern longword gsm_L_asl P((longword a, int n));
79 extern word gsm_asl P((word a, int n));
80 
81 extern longword gsm_L_asr P((longword a, int n));
82 extern word gsm_asr P((word a, int n));
83 
84 /*
85  * Inlined functions from add.h
86  */
87 
88 /*
89  * #define GSM_MULT_R(a, b) (* word a, word b, !(a == b == MIN_WORD) *) \
90  * (0x0FFFF & SASR(((longword)(a) * (longword)(b) + 16384), 15))
91  */
92 #define GSM_MULT_R(a, b) /* word a, word b, !(a == b == MIN_WORD) */ \
93  (SASR( ((longword)(a) * (longword)(b) + 16384), 15 ))
94 
95 # define GSM_MULT(a,b) /* word a, word b, !(a == b == MIN_WORD) */ \
96  (SASR( ((longword)(a) * (longword)(b)), 15 ))
97 
98 # define GSM_L_MULT(a, b) /* word a, word b */ \
99  (((longword)(a) * (longword)(b)) << 1)
100 
101 #if defined(__GNUC__) && defined(__i386__)
102 
103 static __inline__ int GSM_L_ADD(int a, int b)
104 {
105  __asm__ __volatile__(
106 
107  "addl %2,%0; jno 0f; movl $0x7fffffff,%0; adcl $0,%0; 0:"
108  : "=&r" (a)
109  : "0" (a), "ir" (b)
110  : "cc"
111  );
112  return(a);
113 }
114 
115 static __inline__ short GSM_ADD(short a, short b)
116 {
117  __asm__ __volatile__(
118  "addw %2,%0; jno 0f; movw $0x7fff,%0; adcw $0,%0; 0:"
119  : "=&r" (a)
120  : "0" (a), "ir" (b)
121  : "cc"
122  );
123  return(a);
124 }
125 
126 static __inline__ short GSM_SUB(short a, short b)
127 {
128  __asm__ __volatile__(
129  "subw %2,%0; jno 0f; movw $0x7fff,%0; adcw $0,%0; 0:"
130  : "=&r" (a)
131  : "0" (a), "ir" (b)
132  : "cc"
133  );
134  return(a);
135 }
136 
137 #else
138 
139 #ifdef WIN32
140 #define inline __inline
141 #define __inline__ __inline
142 #endif
143 
144 # define GSM_L_ADD(a, b) \
145  ( (a) < 0 ? ( (b) >= 0 ? (a) + (b) \
146  : (utmp = (ulongword)-((a) + 1) + (ulongword)-((b) + 1)) \
147  >= MAX_LONGWORD ? MIN_LONGWORD : -(longword)utmp-2 ) \
148  : ((b) <= 0 ? (a) + (b) \
149  : (utmp = (ulongword)(a) + (ulongword)(b)) >= MAX_LONGWORD \
150  ? MAX_LONGWORD : utmp))
151 
152 static inline word GSM_ADD(longword a, longword b)
153 {
154  register longword ltmp;
155  ltmp = a + b;
156  return (word)((ulongword) (ltmp - MIN_WORD) > MAX_WORD - MIN_WORD ? (ltmp > 0 ? MAX_WORD : MIN_WORD) : ltmp);
157 };
158 
159 static inline word GSM_SUB(longword a, longword b)
160 {
161  register longword ltmp;
162  ltmp = a - b;
163  return (word)(ltmp >= MAX_WORD ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp);
164 };
165 
166 #endif
167 
168 # define GSM_ABS(a) ((a) < 0 ? ((a) == MIN_WORD ? MAX_WORD : -(a)) : (a))
169 
170 /* Use these if necessary:
171 
172 # define GSM_MULT_R(a, b) gsm_mult_r(a, b)
173 # define GSM_MULT(a, b) gsm_mult(a, b)
174 # define GSM_L_MULT(a, b) gsm_L_mult(a, b)
175 
176 # define GSM_L_ADD(a, b) gsm_L_add(a, b)
177 # define GSM_ADD(a, b) gsm_add(a, b)
178 # define GSM_SUB(a, b) gsm_sub(a, b)
179 
180 # define GSM_ABS(a) gsm_abs(a)
181 
182 */
183 
184 /*
185  * More prototypes from implementations..
186  */
187 extern void Gsm_Coder P((
188  struct gsm_state * S,
189  word * s, /* [0..159] samples IN */
190  word * LARc, /* [0..7] LAR coefficients OUT */
191  word * Nc, /* [0..3] LTP lag OUT */
192  word * bc, /* [0..3] coded LTP gain OUT */
193  word * Mc, /* [0..3] RPE grid selection OUT */
194  word * xmaxc,/* [0..3] Coded maximum amplitude OUT */
195  word * xMc /* [13*4] normalized RPE samples OUT */));
196 
197 extern void Gsm_Long_Term_Predictor P(( /* 4x for 160 samples */
198  struct gsm_state * S,
199  word * d, /* [0..39] residual signal IN */
200  word * dp, /* [-120..-1] d' IN */
201  word * e, /* [0..40] OUT */
202  word * dpp, /* [0..40] OUT */
203  word * Nc, /* correlation lag OUT */
204  word * bc /* gain factor OUT */));
205 
206 extern void Gsm_LPC_Analysis P((
207  struct gsm_state * S,
208  word * s, /* 0..159 signals IN/OUT */
209  word * LARc)); /* 0..7 LARc's OUT */
210 
211 extern void Gsm_Preprocess P((
212  struct gsm_state * S,
213  word * s, word * so));
214 
215 extern void Gsm_Encoding P((
216  struct gsm_state * S,
217  word * e,
218  word * ep,
219  word * xmaxc,
220  word * Mc,
221  word * xMc));
222 
223 extern void Gsm_Short_Term_Analysis_Filter P((
224  struct gsm_state * S,
225  word * LARc, /* coded log area ratio [0..7] IN */
226  word * d /* st res. signal [0..159] IN/OUT */));
227 
228 extern void Gsm_Decoder P((
229  struct gsm_state * S,
230  word * LARcr, /* [0..7] IN */
231  word * Ncr, /* [0..3] IN */
232  word * bcr, /* [0..3] IN */
233  word * Mcr, /* [0..3] IN */
234  word * xmaxcr, /* [0..3] IN */
235  word * xMcr, /* [0..13*4] IN */
236  word * s)); /* [0..159] OUT */
237 
238 extern void Gsm_Decoding P((
239  struct gsm_state * S,
240  word xmaxcr,
241  word Mcr,
242  word * xMcr, /* [0..12] IN */
243  word * erp)); /* [0..39] OUT */
244 
245 extern void Gsm_Long_Term_Synthesis_Filtering P((
246  struct gsm_state* S,
247  word Ncr,
248  word bcr,
249  word * erp, /* [0..39] IN */
250  word * drp)); /* [-120..-1] IN, [0..40] OUT */
251 
252 void Gsm_RPE_Decoding P((
253  struct gsm_state *S,
254  word xmaxcr,
255  word Mcr,
256  word * xMcr, /* [0..12], 3 bits IN */
257  word * erp)); /* [0..39] OUT */
258 
259 void Gsm_RPE_Encoding P((
260  struct gsm_state * S,
261  word * e, /* -5..-1][0..39][40..44 IN/OUT */
262  word * xmaxc, /* OUT */
263  word * Mc, /* OUT */
264  word * xMc)); /* [0..12] OUT */
265 
266 extern void Gsm_Short_Term_Synthesis_Filter P((
267  struct gsm_state * S,
268  word * LARcr, /* log area ratios [0..7] IN */
269  word * drp, /* received d [0...39] IN */
270  word * s)); /* signal s [0..159] OUT */
271 
272 extern void Gsm_Update_of_reconstructed_short_time_residual_signal P((
273  word * dpp, /* [0...39] IN */
274  word * ep, /* [0...39] IN */
275  word * dp)); /* [-120...-1] IN/OUT */
276 
277 /*
278  * Tables from table.c
279  */
280 #ifndef GSM_TABLE_C
281 
282 extern word gsm_A[8], gsm_B[8], gsm_MIC[8], gsm_MAC[8];
283 extern word gsm_INVA[8];
284 extern word gsm_DLB[4], gsm_QLB[4];
285 extern word gsm_H[11];
286 extern word gsm_NRFAC[8];
287 extern word gsm_FAC[8];
288 
289 #endif /* GSM_TABLE_C */
290 
291 /*
292  * Debugging
293  */
294 #ifdef NDEBUG
295 
296 # define gsm_debug_words(a, b, c, d) /* nil */
297 # define gsm_debug_longwords(a, b, c, d) /* nil */
298 # define gsm_debug_word(a, b) /* nil */
299 # define gsm_debug_longword(a, b) /* nil */
300 
301 #else /* !NDEBUG => DEBUG */
302 
303  extern void gsm_debug_words P((char * name, int, int, word *));
304  extern void gsm_debug_longwords P((char * name, int, int, longword *));
305  extern void gsm_debug_longword P((char * name, longword));
306  extern void gsm_debug_word P((char * name, word));
307 
308 #endif /* !NDEBUG */
309 
310 #include "unproto.h"
311 
312 #endif /* PRIVATE_H */
unsigned char frame_index
static word GSM_ADD(longword a, longword b)
word gsm_INVA[8]
Definition: table.c:33
#define bc
#define Mc
word gsm_QLB[4]
Definition: table.c:45
#define GSM_L_ADD(a, b)
static struct test_val d
word gsm_MIC[8]
Definition: table.c:27
#define S(e)
word gsm_MAC[8]
Definition: table.c:28
static word GSM_SUB(longword a, longword b)
word gsm_DLB[4]
Definition: table.c:39
word gsm_H[11]
Definition: table.c:51
#define MAX_WORD
word gsm_NRFAC[8]
Definition: table.c:57
unsigned short uword
word gsm_A[8]
Definition: table.c:25
static const char name[]
Definition: cdr_mysql.c:74
#define xmaxc
unsigned char frame_chain
#define Nc
word gsm_B[8]
Definition: table.c:26
word gsm_FAC[8]
Definition: table.c:63
static struct test_val b
#define MIN_WORD
#define LARc
long longword
word gsm_mult P((word a, word b))
unsigned long ulongword
short word
static struct test_val a