3 * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
4 * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
5 * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
8 /*$Header: /cvsroot/sox/sox/libgsm/private.h,v 1.3 2008/03/21 13:34:21 robs Exp $*/
13 typedef short word
; /* 16 bit signed int */
14 typedef long longword
; /* 32 bit signed int */
16 typedef unsigned short uword
; /* unsigned word */
17 typedef unsigned long ulongword
; /* unsigned longword */
23 word z1
; /* preprocessing.c, Offset_com. */
24 longword L_z2
; /* Offset_com. */
25 int mp
; /* Preemphasis */
27 word u
[8]; /* short_term_aly_filter.c */
28 word LARpp
[2][8]; /* */
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 */
36 char verbose
; /* only used if !NDEBUG */
37 char fast
; /* only used if FAST */
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 */
45 #define MIN_WORD (-32767 - 1)
46 #define MAX_WORD 32767
48 #define MIN_LONGWORD (-2147483647 - 1)
49 #define MAX_LONGWORD 2147483647
51 #ifdef SASR /* flag: >> is a signed arithmetic shift right */
53 #define SASR(x, by) ((x) >> (by))
55 #define SASR(x, by) ((x) >= 0 ? (x) >> (by) : (~(-((x) + 1) >> (by))))
59 * Prototypes from add.c
61 extern word
gsm_mult (word a
, word b
);
62 extern longword
gsm_L_mult (word a
, word b
);
63 extern word
gsm_mult_r (word a
, word b
);
65 extern word
gsm_div (word num
, word denum
);
67 extern word
gsm_add ( word a
, word b
);
68 extern longword
gsm_L_add ( longword a
, longword b
);
70 extern word
gsm_sub (word a
, word b
);
71 extern longword
gsm_L_sub (longword a
, longword b
);
73 extern word
gsm_abs (word a
);
75 extern word
gsm_norm ( longword a
);
77 extern longword
gsm_L_asl (longword a
, int n
);
78 extern word
gsm_asl (word a
, int n
);
80 extern longword
gsm_L_asr (longword a
, int n
);
81 extern word
gsm_asr (word a
, int n
);
84 * Inlined functions from add.h
88 * #define GSM_MULT_R(a, b) (* word a, word b, !(a == b == MIN_WORD) *) \
89 * (0x0FFFF & SASR(((longword)(a) * (longword)(b) + 16384), 15))
91 #define GSM_MULT_R(a, b) /* word a, word b, !(a == b == MIN_WORD) */ \
92 (SASR( ((longword)(a) * (longword)(b) + 16384), 15 ))
94 # define GSM_MULT(a,b) /* word a, word b, !(a == b == MIN_WORD) */ \
95 (SASR( ((longword)(a) * (longword)(b)), 15 ))
97 # define GSM_L_MULT(a, b) /* word a, word b */ \
98 (((longword)(a) * (longword)(b)) << 1)
100 # define GSM_L_ADD(a, b) \
101 ( (a) < 0 ? ( (b) >= 0 ? (a) + (b) \
102 : (utmp = (ulongword)-((a) + 1) + (ulongword)-((b) + 1)) \
103 >= MAX_LONGWORD ? MIN_LONGWORD : -(longword)utmp-2 ) \
104 : ((b) <= 0 ? (a) + (b) \
105 : (utmp = (ulongword)(a) + (ulongword)(b)) >= MAX_LONGWORD \
106 ? MAX_LONGWORD : (longword)utmp))
109 * # define GSM_ADD(a, b) \
110 * ((ltmp = (longword)(a) + (longword)(b)) >= MAX_WORD \
111 * ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp)
113 /* Nonportable, but faster: */
115 #define GSM_ADD(a, b) \
116 ((ulongword)((ltmp = (longword)(a) + (longword)(b)) - MIN_WORD) > \
117 MAX_WORD - MIN_WORD ? (ltmp > 0 ? MAX_WORD : MIN_WORD) : ltmp)
119 # define GSM_SUB(a, b) \
120 ((ltmp = (longword)(a) - (longword)(b)) >= MAX_WORD \
121 ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp)
123 # define GSM_ABS(a) ((a) < 0 ? ((a) == MIN_WORD ? MAX_WORD : -(a)) : (a))
125 /* Use these if necessary:
127 # define GSM_MULT_R(a, b) gsm_mult_r(a, b)
128 # define GSM_MULT(a, b) gsm_mult(a, b)
129 # define GSM_L_MULT(a, b) gsm_L_mult(a, b)
131 # define GSM_L_ADD(a, b) gsm_L_add(a, b)
132 # define GSM_ADD(a, b) gsm_add(a, b)
133 # define GSM_SUB(a, b) gsm_sub(a, b)
135 # define GSM_ABS(a) gsm_abs(a)
140 * More prototypes from implementations..
142 extern void Gsm_Coder (
143 struct gsm_state
* S
,
144 word
* s
, /* [0..159] samples IN */
145 word
* LARc
, /* [0..7] LAR coefficients OUT */
146 word
* Nc
, /* [0..3] LTP lag OUT */
147 word
* bc
, /* [0..3] coded LTP gain OUT */
148 word
* Mc
, /* [0..3] RPE grid selection OUT */
149 word
* xmaxc
,/* [0..3] Coded maximum amplitude OUT */
150 word
* xMc
/* [13*4] normalized RPE samples OUT */);
152 extern void Gsm_Long_Term_Predictor ( /* 4x for 160 samples */
153 struct gsm_state
* S
,
154 word
* d
, /* [0..39] residual signal IN */
155 word
* dp
, /* [-120..-1] d' IN */
156 word
* e
, /* [0..40] OUT */
157 word
* dpp
, /* [0..40] OUT */
158 word
* Nc
, /* correlation lag OUT */
159 word
* bc
/* gain factor OUT */);
161 extern void Gsm_LPC_Analysis (
162 struct gsm_state
* S
,
163 word
* s
, /* 0..159 signals IN/OUT */
164 word
* LARc
); /* 0..7 LARc's OUT */
166 extern void Gsm_Preprocess (
167 struct gsm_state
* S
,
168 word
* s
, word
* so
);
170 extern void Gsm_Encoding (
171 struct gsm_state
* S
,
178 extern void Gsm_Short_Term_Analysis_Filter (
179 struct gsm_state
* S
,
180 word
* LARc
, /* coded log area ratio [0..7] IN */
181 word
* d
/* st res. signal [0..159] IN/OUT */);
183 extern void Gsm_Decoder (
184 struct gsm_state
* S
,
185 word
* LARcr
, /* [0..7] IN */
186 word
* Ncr
, /* [0..3] IN */
187 word
* bcr
, /* [0..3] IN */
188 word
* Mcr
, /* [0..3] IN */
189 word
* xmaxcr
, /* [0..3] IN */
190 word
* xMcr
, /* [0..13*4] IN */
191 word
* s
); /* [0..159] OUT */
193 extern void Gsm_Decoding (
194 struct gsm_state
* S
,
197 word
* xMcr
, /* [0..12] IN */
198 word
* erp
); /* [0..39] OUT */
200 extern void Gsm_Long_Term_Synthesis_Filtering (
204 word
* erp
, /* [0..39] IN */
205 word
* drp
); /* [-120..-1] IN, [0..40] OUT */
207 void Gsm_RPE_Decoding (
211 word
* xMcr
, /* [0..12], 3 bits IN */
212 word
* erp
); /* [0..39] OUT */
214 void Gsm_RPE_Encoding (
215 struct gsm_state
* S
,
216 word
* e
, /* -5..-1][0..39][40..44 IN/OUT */
217 word
* xmaxc
, /* OUT */
219 word
* xMc
); /* [0..12] OUT */
221 extern void Gsm_Short_Term_Synthesis_Filter (
222 struct gsm_state
* S
,
223 word
* LARcr
, /* log area ratios [0..7] IN */
224 word
* drp
, /* received d [0...39] IN */
225 word
* s
); /* signal s [0..159] OUT */
227 extern void Gsm_Update_of_reconstructed_short_time_residual_signal (
228 word
* dpp
, /* [0...39] IN */
229 word
* ep
, /* [0...39] IN */
230 word
* dp
); /* [-120...-1] IN/OUT */
233 * Tables from table.c
237 extern word gsm_A
[8], gsm_B
[8], gsm_MIC
[8], gsm_MAC
[8];
238 extern word gsm_INVA
[8];
239 extern word gsm_DLB
[4], gsm_QLB
[4];
240 extern word gsm_H
[11];
241 extern word gsm_NRFAC
[8];
242 extern word gsm_FAC
[8];
244 #endif /* GSM_TABLE_C */
251 # define gsm_debug_words(a, b, c, d) /* nil */
252 # define gsm_debug_longwords(a, b, c, d) /* nil */
253 # define gsm_debug_word(a, b) /* nil */
254 # define gsm_debug_longword(a, b) /* nil */
256 #else /* !NDEBUG => DEBUG */
258 extern void gsm_debug_words (char * name
, int, int, word
*);
259 extern void gsm_debug_longwords (char * name
, int, int, longword
*);
260 extern void gsm_debug_longword (char * name
, longword
);
261 extern void gsm_debug_word (char * name
, word
);
265 #endif /* PRIVATE_H */