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