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