blob: fea56942d15b1736e338cd04709d902ac4aee26a [file] [log] [blame]
Alexandre Lisiond204ea52013-10-15 10:16:25 -04001/*
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: /tmp_amd/presto/export/kbs/jutta/src/gsm/RCS/private.h,v 1.6 1996/07/02 10:15:26 jutta Exp $*/
8
9#ifndef PRIVATE_H
10#define PRIVATE_H
11
12typedef short word; /* 16 bit signed int */
13typedef long longword; /* 32 bit signed int */
14
15typedef unsigned short uword; /* unsigned word */
16typedef unsigned long ulongword; /* unsigned longword */
17
18struct 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 */
62extern word gsm_mult P((word a, word b));
63extern longword gsm_L_mult P((word a, word b));
64extern word gsm_mult_r P((word a, word b));
65
66extern word gsm_div P((word num, word denum));
67
68extern word gsm_add P(( word a, word b ));
69extern longword gsm_L_add P(( longword a, longword b ));
70
71extern word gsm_sub P((word a, word b));
72extern longword gsm_L_sub P((longword a, longword b));
73
74extern word gsm_abs P((word a));
75
76extern word gsm_norm P(( longword a ));
77
78extern longword gsm_L_asl P((longword a, int n));
79extern word gsm_asl P((word a, int n));
80
81extern longword gsm_L_asr P((longword a, int n));
82extern 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# define GSM_L_ADD(a, b) \
102 ( (a) < 0 ? ( (b) >= 0 ? (a) + (b) \
103 : (utmp = (ulongword)-((a) + 1) + (ulongword)-((b) + 1)) \
104 >= MAX_LONGWORD ? MIN_LONGWORD : -(longword)utmp-2 ) \
105 : ((b) <= 0 ? (a) + (b) \
106 : (utmp = (ulongword)(a) + (ulongword)(b)) >= MAX_LONGWORD \
107 ? MAX_LONGWORD : utmp))
108
109/*
110 * # define GSM_ADD(a, b) \
111 * ((ltmp = (longword)(a) + (longword)(b)) >= MAX_WORD \
112 * ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp)
113 */
114/* Nonportable, but faster: */
115
116#define GSM_ADD(a, b) \
117 ((ulongword)((ltmp = (longword)(a) + (longword)(b)) - MIN_WORD) > \
118 MAX_WORD - MIN_WORD ? (ltmp > 0 ? MAX_WORD : MIN_WORD) : ltmp)
119
120# define GSM_SUB(a, b) \
121 ((ltmp = (longword)(a) - (longword)(b)) >= MAX_WORD \
122 ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp)
123
124# define GSM_ABS(a) ((a) < 0 ? ((a) == MIN_WORD ? MAX_WORD : -(a)) : (a))
125
126/* Use these if necessary:
127
128# define GSM_MULT_R(a, b) gsm_mult_r(a, b)
129# define GSM_MULT(a, b) gsm_mult(a, b)
130# define GSM_L_MULT(a, b) gsm_L_mult(a, b)
131
132# define GSM_L_ADD(a, b) gsm_L_add(a, b)
133# define GSM_ADD(a, b) gsm_add(a, b)
134# define GSM_SUB(a, b) gsm_sub(a, b)
135
136# define GSM_ABS(a) gsm_abs(a)
137
138*/
139
140/*
141 * More prototypes from implementations..
142 */
143extern void Gsm_Coder P((
144 struct gsm_state * S,
145 word * s, /* [0..159] samples IN */
146 word * LARc, /* [0..7] LAR coefficients OUT */
147 word * Nc, /* [0..3] LTP lag OUT */
148 word * bc, /* [0..3] coded LTP gain OUT */
149 word * Mc, /* [0..3] RPE grid selection OUT */
150 word * xmaxc,/* [0..3] Coded maximum amplitude OUT */
151 word * xMc /* [13*4] normalized RPE samples OUT */));
152
153extern void Gsm_Long_Term_Predictor P(( /* 4x for 160 samples */
154 struct gsm_state * S,
155 word * d, /* [0..39] residual signal IN */
156 word * dp, /* [-120..-1] d' IN */
157 word * e, /* [0..40] OUT */
158 word * dpp, /* [0..40] OUT */
159 word * Nc, /* correlation lag OUT */
160 word * bc /* gain factor OUT */));
161
162extern void Gsm_LPC_Analysis P((
163 struct gsm_state * S,
164 word * s, /* 0..159 signals IN/OUT */
165 word * LARc)); /* 0..7 LARc's OUT */
166
167extern void Gsm_Preprocess P((
168 struct gsm_state * S,
169 word * s, word * so));
170
171extern void Gsm_Encoding P((
172 struct gsm_state * S,
173 word * e,
174 word * ep,
175 word * xmaxc,
176 word * Mc,
177 word * xMc));
178
179extern void Gsm_Short_Term_Analysis_Filter P((
180 struct gsm_state * S,
181 word * LARc, /* coded log area ratio [0..7] IN */
182 word * d /* st res. signal [0..159] IN/OUT */));
183
184extern void Gsm_Decoder P((
185 struct gsm_state * S,
186 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
194extern void Gsm_Decoding P((
195 struct gsm_state * S,
196 word xmaxcr,
197 word Mcr,
198 word * xMcr, /* [0..12] IN */
199 word * erp)); /* [0..39] OUT */
200
201extern void Gsm_Long_Term_Synthesis_Filtering P((
202 struct gsm_state* S,
203 word Ncr,
204 word bcr,
205 word * erp, /* [0..39] IN */
206 word * drp)); /* [-120..-1] IN, [0..40] OUT */
207
208void Gsm_RPE_Decoding P((
209 struct gsm_state *S,
210 word xmaxcr,
211 word Mcr,
212 word * xMcr, /* [0..12], 3 bits IN */
213 word * erp)); /* [0..39] OUT */
214
215void Gsm_RPE_Encoding P((
216 struct gsm_state * S,
217 word * e, /* -5..-1][0..39][40..44 IN/OUT */
218 word * xmaxc, /* OUT */
219 word * Mc, /* OUT */
220 word * xMc)); /* [0..12] OUT */
221
222extern void Gsm_Short_Term_Synthesis_Filter P((
223 struct gsm_state * S,
224 word * LARcr, /* log area ratios [0..7] IN */
225 word * drp, /* received d [0...39] IN */
226 word * s)); /* signal s [0..159] OUT */
227
228extern void Gsm_Update_of_reconstructed_short_time_residual_signal P((
229 word * dpp, /* [0...39] IN */
230 word * ep, /* [0...39] IN */
231 word * dp)); /* [-120...-1] IN/OUT */
232
233/*
234 * Tables from table.c
235 */
236#ifndef GSM_TABLE_C
237
238extern word gsm_A[8], gsm_B[8], gsm_MIC[8], gsm_MAC[8];
239extern word gsm_INVA[8];
240extern word gsm_DLB[4], gsm_QLB[4];
241extern word gsm_H[11];
242extern word gsm_NRFAC[8];
243extern word gsm_FAC[8];
244
245#endif /* GSM_TABLE_C */
246
247/*
248 * Debugging
249 */
250#ifdef NDEBUG
251
252# define gsm_debug_words(a, b, c, d) /* nil */
253# define gsm_debug_longwords(a, b, c, d) /* nil */
254# define gsm_debug_word(a, b) /* nil */
255# define gsm_debug_longword(a, b) /* nil */
256
257#else /* !NDEBUG => DEBUG */
258
259 extern void gsm_debug_words P((char * name, int, int, word *));
260 extern void gsm_debug_longwords P((char * name, int, int, longword *));
261 extern void gsm_debug_longword P((char * name, longword));
262 extern void gsm_debug_word P((char * name, word));
263
264#endif /* !NDEBUG */
265
266#include "unproto.h"
267
268#endif /* PRIVATE_H */