Debian Codegraph @

3rdparty/iaxclient/lib/gsm/inc/private.h

raw symbols SCIP
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 # define GSM_L_ADD(a, b) \
140 ( (a) < 0 ? ( (b) >= 0 ? (a) + (b) \
141 : (utmp = (ulongword)-((a) + 1) + (ulongword)-((b) + 1)) \
142 >= MAX_LONGWORD ? MIN_LONGWORD : -(longword)utmp-2 ) \
143 : ((b) <= 0 ? (a) + (b) \
144 : (utmp = (ulongword)(a) + (ulongword)(b)) >= MAX_LONGWORD \
145 ? MAX_LONGWORD : utmp))
146
147 /*
148 * # define GSM_ADD(a, b) \
149 * ((ltmp = (longword)(a) + (longword)(b)) >= MAX_WORD \
150 * ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp)
151 */
152 /* Nonportable, but faster: */
153
154 #define GSM_ADD(a, b) \
155 (short) ((ulongword)((ltmp = (longword)(a) + (longword)(b)) - MIN_WORD) > \
156 MAX_WORD - MIN_WORD ? (ltmp > 0 ? MAX_WORD : MIN_WORD) : ltmp)
157
158 # define GSM_SUB(a, b) \
159 ((ltmp = (longword)(a) - (longword)(b)) >= MAX_WORD \
160 ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp)
161
162 #endif
163
164 # define GSM_ABS(a) ((a) < 0 ? ((a) == MIN_WORD ? MAX_WORD : -(a)) : (a))
165
166 /* Use these if necessary:
167
168 # define GSM_MULT_R(a, b) gsm_mult_r(a, b)
169 # define GSM_MULT(a, b) gsm_mult(a, b)
170 # define GSM_L_MULT(a, b) gsm_L_mult(a, b)
171
172 # define GSM_L_ADD(a, b) gsm_L_add(a, b)
173 # define GSM_ADD(a, b) gsm_add(a, b)
174 # define GSM_SUB(a, b) gsm_sub(a, b)
175
176 # define GSM_ABS(a) gsm_abs(a)
177
178 */
179
180 /*
181 * More prototypes from implementations..
182 */
183 extern void Gsm_Coder P((
184 struct gsm_state * S,
185 word * s, /* [0..159] samples IN */
186 word * LARc, /* [0..7] LAR coefficients OUT */
187 word * Nc, /* [0..3] LTP lag OUT */
188 word * bc, /* [0..3] coded LTP gain OUT */
189 word * Mc, /* [0..3] RPE grid selection OUT */
190 word * xmaxc,/* [0..3] Coded maximum amplitude OUT */
191 word * xMc /* [13*4] normalized RPE samples OUT */));
192
193 extern void Gsm_Long_Term_Predictor P(( /* 4x for 160 samples */
194 struct gsm_state * S,
195 word * d, /* [0..39] residual signal IN */
196 word * dp, /* [-120..-1] d' IN */
197 word * e, /* [0..40] OUT */
198 word * dpp, /* [0..40] OUT */
199 word * Nc, /* correlation lag OUT */
200 word * bc /* gain factor OUT */));
201
202 extern void Gsm_LPC_Analysis P((
203 struct gsm_state * S,
204 word * s, /* 0..159 signals IN/OUT */
205 word * LARc)); /* 0..7 LARc's OUT */
206
207 extern void Gsm_Preprocess P((
208 struct gsm_state * S,
209 word * s, word * so));
210
211 extern void Gsm_Encoding P((
212 struct gsm_state * S,
213 word * e,
214 word * ep,
215 word * xmaxc,
216 word * Mc,
217 word * xMc));
218
219 extern void Gsm_Short_Term_Analysis_Filter P((
220 struct gsm_state * S,
221 word * LARc, /* coded log area ratio [0..7] IN */
222 word * d /* st res. signal [0..159] IN/OUT */));
223
224 extern void Gsm_Decoder P((
225 struct gsm_state * S,
226 word * LARcr, /* [0..7] IN */
227 word * Ncr, /* [0..3] IN */
228 word * bcr, /* [0..3] IN */
229 word * Mcr, /* [0..3] IN */
230 word * xmaxcr, /* [0..3] IN */
231 word * xMcr, /* [0..13*4] IN */
232 word * s)); /* [0..159] OUT */
233
234 extern void Gsm_Decoding P((
235 struct gsm_state * S,
236 word xmaxcr,
237 word Mcr,
238 word * xMcr, /* [0..12] IN */
239 word * erp)); /* [0..39] OUT */
240
241 extern void Gsm_Long_Term_Synthesis_Filtering P((
242 struct gsm_state* S,
243 word Ncr,
244 word bcr,
245 word * erp, /* [0..39] IN */
246 word * drp)); /* [-120..-1] IN, [0..40] OUT */
247
248 void Gsm_RPE_Decoding P((
249 struct gsm_state *S,
250 word xmaxcr,
251 word Mcr,
252 word * xMcr, /* [0..12], 3 bits IN */
253 word * erp)); /* [0..39] OUT */
254
255 void Gsm_RPE_Encoding P((
256 struct gsm_state * S,
257 word * e, /* -5..-1][0..39][40..44 IN/OUT */
258 word * xmaxc, /* OUT */
259 word * Mc, /* OUT */
260 word * xMc)); /* [0..12] OUT */
261
262 extern void Gsm_Short_Term_Synthesis_Filter P((
263 struct gsm_state * S,
264 word * LARcr, /* log area ratios [0..7] IN */
265 word * drp, /* received d [0...39] IN */
266 word * s)); /* signal s [0..159] OUT */
267
268 extern void Gsm_Update_of_reconstructed_short_time_residual_signal P((
269 word * dpp, /* [0...39] IN */
270 word * ep, /* [0...39] IN */
271 word * dp)); /* [-120...-1] IN/OUT */
272
273 /*
274 * Tables from table.c
275 */
276 #ifndef GSM_TABLE_C
277
278 extern word gsm_A[8], gsm_B[8], gsm_MIC[8], gsm_MAC[8];
279 extern word gsm_INVA[8];
280 extern word gsm_DLB[4], gsm_QLB[4];
281 extern word gsm_H[11];
282 extern word gsm_NRFAC[8];
283 extern word gsm_FAC[8];
284
285 #endif /* GSM_TABLE_C */
286
287 /*
288 * Debugging
289 */
290 #ifdef NDEBUG
291
292 # define gsm_debug_words(a, b, c, d) /* nil */
293 # define gsm_debug_longwords(a, b, c, d) /* nil */
294 # define gsm_debug_word(a, b) /* nil */
295 # define gsm_debug_longword(a, b) /* nil */
296
297 #else /* !NDEBUG => DEBUG */
298
299 extern void gsm_debug_words P((char * name, int, int, word *));
300 extern void gsm_debug_longwords P((char * name, int, int, longword *));
301 extern void gsm_debug_longword P((char * name, longword));
302 extern void gsm_debug_word P((char * name, word));
303
304 #endif /* !NDEBUG */
305
306 #include "unproto.h"
307
308 #endif /* PRIVATE_H */