comparison intercom/gsm/private.h @ 2:13be24d74cd2

import intercom-0.4.1
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Fri, 25 Jun 2010 09:57:52 +0200
parents
children
comparison
equal deleted inserted replaced
1:9cadc470e3da 2:13be24d74cd2
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: /home/kbs/jutta/src/gsm/gsm-1.0/inc/RCS/private.h,v 1.2 1993/01/29 18:25:27 jutta Exp $*/
8
9 /*
10 ************************** WARNING ******************************
11 Several pseudo-functions GSM_... provide faster operation than
12 their equivalent true function, but may generate non-compatible
13 results. It is known that the implementation of GSM_ADD_2 is
14 not working correctly on 16-bit machines/compilers (besides
15 an error-free compilation!). In the safer case, compilation
16 should be carried out using SLOWER_BUT_SAFER defined.
17 Another test is using add_test.c, explained elsewhere.
18 -- <simao@cpqd.ansp.br> [08.Apr.94] ---
19 *****************************************************************
20 */
21
22 #ifndef PRIVATE_H
23 #define PRIVATE_H
24
25 typedef short word; /* 16 bit signed int */
26 typedef long longword; /* 32 bit signed int */
27
28 typedef unsigned short uword; /* unsigned word */
29 typedef unsigned long ulongword; /* unsigned longword */
30
31 struct gsm_state {
32
33 word dp0[280];
34
35 word z1; /* preprocessing.c, Offset_com. */
36 longword L_z2; /* Offset_com. */
37 int mp; /* Preemphasis */
38
39 word u[8]; /* short_term_aly_filter.c */
40 word LARpp[2][8]; /* */
41 word j; /* */
42
43 word nrp; /* 40 *//* long_term.c, synthesis */
44 word v[9]; /* short_term.c, synthesis */
45 word msr; /* decoder.c, Postprocessing */
46
47 char verbose; /* only used if !NDEBUG */
48 char fast; /* only used if FAST */
49
50 };
51
52
53 #define MIN_WORD (-32768)
54 #define MAX_WORD ( 32767)
55
56 #define MIN_LONGWORD ((-2147483647)-1)
57 #define MAX_LONGWORD ( 2147483647)
58
59 #ifdef SASR /* >> is a signed arithmetic shift right */
60 #undef SASR
61 #define SASR(x, by) ((x) >> (by))
62 #endif /* SASR */
63
64
65 #include "proto.h"
66
67 /*
68 * Prototypes from add.c
69 */
70 extern word gsm_mult P((word a, word b));
71 extern longword gsm_L_mult P((word a, word b));
72 extern word gsm_mult_r P((word a, word b));
73
74 extern word gsm_div P((word num, word denum));
75
76 extern word gsm_add P((word a, word b));
77 extern longword gsm_L_add P((longword a, longword b));
78
79 extern word gsm_sub P((word a, word b));
80 extern longword gsm_L_sub P((longword a, longword b));
81
82 extern word gsm_abs P((word a));
83
84 extern word gsm_norm P((longword a));
85
86 extern longword gsm_L_asl P((longword a, int n));
87 extern word gsm_asl P((word a, int n));
88
89 extern longword gsm_L_asr P((longword a, int n));
90 extern word gsm_asr P((word a, int n));
91
92 /*
93 * Inlined functions from add.h
94 */
95 #ifndef SLOWER_BUT_SAFER
96 /*
97 * #define GSM_MULT_R(a, b) (* word a, word b, !(a == b == MIN_WORD) *) \
98 * (0x0FFFF & SASR(((longword)(a) * (longword)(b) + 16384), 15))
99 */
100 #define GSM_MULT_R(a, b) /* word a, word b, !(a == b == MIN_WORD) */ \
101 (SASR( ((longword)(a) * (longword)(b) + 16384), 15 ))
102
103 # define GSM_MULT(a,b) /* word a, word b, !(a == b == MIN_WORD) */ \
104 (SASR( ((longword)(a) * (longword)(b)), 15 ))
105
106 # define GSM_L_MULT(a, b) /* word a, word b */ \
107 (((longword)(a) * (longword)(b)) << 1)
108
109 # define GSM_L_ADD(a, b) \
110 ( (a) < 0 ? ( (b) >= 0 ? (a) + (b) \
111 : (utmp = (ulongword)-((a) + 1) + (ulongword)-((b) + 1)) \
112 >= (ulongword)MAX_LONGWORD ? MIN_LONGWORD : -(longword)utmp-2 ) \
113 : ((b) <= 0 ? (a) + (b) \
114 : (utmp = (ulongword)(a) + (ulongword)(b)) >= (ulongword)MAX_LONGWORD \
115 ? (ulongword)MAX_LONGWORD : utmp))
116
117
118 /* Slower but portable */
119 #define GSM_ADD_1(a, b) \
120 ((ltmp = (longword)(a) + (longword)(b)) >= MAX_WORD \
121 ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp)
122
123 /* Nonportable, but faster: */
124 #define GSM_ADD_2(a, b) \
125 ((unsigned)((ltmp = (longword)(a) + (longword)(b)) - MIN_WORD) > \
126 MAX_WORD - MIN_WORD ? (ltmp > 0 ? MAX_WORD : MIN_WORD) : ltmp)
127
128 /* Now you choose: fast or portable? */
129 /* #define GSM_ADD GSM_ADD_1 -> Slow & portable */
130 /* #define GSM_ADD GSM_ADD_2 -> Fast & non-portable */
131 #define GSM_ADD GSM_ADD_1
132
133 # define GSM_SUB(a, b) \
134 ((ltmp = (longword)(a) - (longword)(b)) >= MAX_WORD \
135 ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp)
136
137 # define GSM_ABS(a) ((a) < 0 ? ((a) == MIN_WORD ? MAX_WORD : -(a)) : (a))
138
139 #else
140
141 /* Use these if necessary: */
142
143 # define GSM_MULT_R(a, b) gsm_mult_r(a, b)
144 # define GSM_MULT(a, b) gsm_mult(a, b)
145 # define GSM_L_MULT(a, b) gsm_L_mult(a, b)
146
147 # define GSM_L_ADD(a, b) gsm_L_add(a, b)
148 # define GSM_ADD(a, b) gsm_add(a, b)
149 # define GSM_SUB(a, b) gsm_sub(a, b)
150
151 # define GSM_ABS(a) gsm_abs(a)
152
153 #endif /* SLOWER_BUT_SAFER */
154
155 /*
156 * More prototypes from implementations..
157 */
158 extern void Gsm_Coder P((struct gsm_state * S, word * s, /* [0..159] samples IN */
159 word * LARc, /* [0..7] LAR coefficients OUT */
160 word * Nc, /* [0..3] LTP lag OUT */
161 word * bc, /* [0..3] coded LTP gain OUT */
162 word * Mc, /* [0..3] RPE grid selection OUT */
163 word * xmaxc, /* [0..3] Coded maximum amplitude OUT */
164 word * xMc /* [13*4] normalized RPE samples OUT */ ));
165
166 extern void Gsm_Long_Term_Predictor P(( /* 4x for 160 samples */
167 struct gsm_state * S, word * d, /* [0..39] residual signal IN */
168 word * dp, /* [-120..-1] d' IN */
169 word * e, /* [0..40] OUT */
170 word * dpp, /* [0..40] OUT */
171 word * Nc, /* correlation lag OUT */
172 word * bc /* gain factor OUT */ ));
173
174 extern void Gsm_LPC_Analysis P((struct gsm_state * S, word * s, /* 0..159 signals IN/OUT */
175 word * LARc)); /* 0..7 LARc's OUT */
176
177 extern void Gsm_Preprocess P((struct gsm_state * S,
178 word * s, word * so));
179
180 extern void Gsm_Encoding P((struct gsm_state * S,
181 word * e, word * ep, word * xmaxc, word * Mc, word * xMc));
182
183 extern void Gsm_Short_Term_Analysis_Filter P((struct gsm_state * S, word * LARc, /* coded log area ratio [0..7] IN */
184 word * d /* st res. signal [0..159] IN/OUT */ ));
185
186 extern void Gsm_Decoder P((struct gsm_state * S, word * LARcr, /* [0..7] IN */
187 word * Ncr, /* [0..3] IN */
188 word * bcr, /* [0..3] IN */
189 word * Mcr, /* [0..3] IN */
190 word * xmaxcr, /* [0..3] IN */
191 word * xMcr, /* [0..13*4] IN */
192 word * s)); /* [0..159] OUT */
193
194 extern void Gsm_Decoding P((struct gsm_state * S, word xmaxcr, word Mcr, word * xMcr, /* [0..12] IN */
195 word * erp)); /* [0..39] OUT */
196
197 extern void Gsm_Long_Term_Synthesis_Filtering P((struct gsm_state * S, word Ncr, word bcr, word * erp, /* [0..39] IN */
198 word * drp)); /* [-120..-1] IN, [0..40] OUT */
199
200 extern void Gsm_Short_Term_Synthesis_Filter P((struct gsm_state * S, word * LARcr, /* log area ratios [0..7] IN */
201 word * drp, /* received d [0...39] IN */
202 word * s)); /* signal s [0..159] OUT */
203
204 extern void Gsm_Update_of_reconstructed_short_time_residual_signal P((word * dpp, /* [0...39] IN */
205 word * ep, /* [0...39] IN */
206 word * dp)); /* [-120...-1] IN/OUT */
207
208 /*
209 * Tables from table.c
210 */
211 #ifndef GSM_TABLE_C
212
213 extern word gsm_A[8], gsm_B[8], gsm_MIC[8], gsm_MAC[8];
214 extern word gsm_INVA[8];
215 extern word gsm_DLB[4], gsm_QLB[4];
216 extern word gsm_H[11];
217 extern word gsm_NRFAC[8];
218 extern word gsm_FAC[8];
219
220 #endif /* GSM_TABLE_C */
221
222 /*
223 * Debugging
224 */
225 #ifdef NDEBUG
226
227 # define gsm_debug_words(a, b, c, d) /* nil */
228 # define gsm_debug_longwords(a, b, c, d) /* nil */
229 # define gsm_debug_word(a, b) /* nil */
230 # define gsm_debug_longword(a, b) /* nil */
231
232 #else /* !NDEBUG => DEBUG */
233
234 extern void gsm_debug_words P((char *name, int, int, word *));
235 extern void gsm_debug_longwords P((char *name, int, int, longword *));
236 extern void gsm_debug_longword P((char *name, longword));
237 extern void gsm_debug_word P((char *name, word));
238
239 #endif /* !NDEBUG */
240
241 #include "unproto.h"
242
243 #endif /* PRIVATE_H */

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.