add new sigc++2 directory
[ardour.git] / libs / libsndfile / src / GSM610 / gsm610_priv.h
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 #ifndef PRIVATE_H
8 #define PRIVATE_H
9
10 /* Added by Erik de Castro Lopo */
11 #define USE_FLOAT_MUL
12 #define FAST
13 #define WAV49
14
15 #ifdef __cplusplus
16 #error "This code is not designed to be compiled with a C++ compiler."
17 #endif
18 /* Added by Erik de Castro Lopo */
19
20
21
22 typedef short                           word;           /* 16 bit signed int    */
23 typedef int                                     longword;       /* 32 bit signed int    */
24
25 typedef unsigned short          uword;          /* unsigned word        */
26 typedef unsigned int            ulongword;      /* unsigned longword    */
27
28 struct gsm_state
29 {       word                    dp0[ 280 ] ;
30
31         word                    z1;                     /* preprocessing.c, Offset_com. */
32         longword                L_z2;           /*                  Offset_com. */
33         int                             mp;                     /*                  Preemphasis */
34
35         word                    u[8] ;                  /* short_term_aly_filter.c      */
36         word                    LARpp[2][8] ;   /*                              */
37         word                    j;                              /*                              */
38
39         word            ltp_cut;        /* long_term.c, LTP crosscorr.  */
40         word                    nrp;                    /* 40 */        /* long_term.c, synthesis       */
41         word                    v[9] ;                  /* short_term.c, synthesis      */
42         word                    msr;                    /* decoder.c,   Postprocessing  */
43
44         char                    verbose;                /* only used if !NDEBUG         */
45         char                    fast;                   /* only used if FAST            */
46
47         char                    wav_fmt;                /* only used if WAV49 defined   */
48         unsigned char   frame_index;    /*            odd/even chaining */
49         unsigned char   frame_chain;    /*   half-byte to carry forward */
50
51         /* Moved here from code.c where it was defined as static */
52         word e[50] ;
53 } ;
54
55 typedef struct gsm_state GSM_STATE ;
56
57 #define MIN_WORD        (-32767 - 1)
58 #define MAX_WORD          32767
59
60 #define MIN_LONGWORD    (-2147483647 - 1)
61 #define MAX_LONGWORD      2147483647
62
63 /* Signed arithmetic shift right. */
64 static inline word
65 SASR_W (word x, word by)
66 {       return (x >> by) ;
67 } /* SASR */
68
69 static inline longword
70 SASR_L (longword x, word by)
71 {       return (x >> by) ;
72 } /* SASR */
73
74 /*
75  *      Prototypes from add.c
76  */
77 word    gsm_mult                (word a, word b) ;
78 longword gsm_L_mult     (word a, word b) ;
79 word    gsm_mult_r              (word a, word b) ;
80
81 word    gsm_div                 (word num, word denum) ;
82
83 word    gsm_add                 (word a, word b ) ;
84 longword gsm_L_add      (longword a, longword b ) ;
85
86 word    gsm_sub                 (word a, word b) ;
87 longword gsm_L_sub      (longword a, longword b) ;
88
89 word    gsm_abs                 (word a) ;
90
91 word    gsm_norm                (longword a ) ;
92
93 longword gsm_L_asl      (longword a, int n) ;
94 word    gsm_asl                 (word a, int n) ;
95
96 longword gsm_L_asr      (longword a, int n) ;
97 word    gsm_asr                 (word a, int n) ;
98
99 /*
100  *  Inlined functions from add.h
101  */
102
103 static inline longword
104 GSM_MULT_R (word a, word b)
105 {       return (((longword) (a)) * ((longword) (b)) + 16384) >> 15 ;
106 } /* GSM_MULT_R */
107
108 static inline longword
109 GSM_MULT (word a, word b)
110 {       return (((longword) (a)) * ((longword) (b))) >> 15 ;
111 } /* GSM_MULT */
112
113 static inline longword
114 GSM_L_MULT (word a, word b)
115 {       return ((longword) (a)) * ((longword) (b)) << 1 ;
116 } /* GSM_L_MULT */
117
118 static inline longword
119 GSM_L_ADD (longword a, longword b)
120 {       ulongword utmp ;
121
122         if (a < 0 && b < 0)
123         {       utmp = (ulongword)-((a) + 1) + (ulongword)-((b) + 1) ;
124                 return (utmp >= (ulongword) MAX_LONGWORD) ? MIN_LONGWORD : -(longword)utmp-2 ;
125                 } ;
126
127         if (a > 0 && b > 0)
128         {       utmp = (ulongword) a + (ulongword) b ;
129                 return (utmp >= (ulongword) MAX_LONGWORD) ? MAX_LONGWORD : utmp ;
130                 } ;
131
132         return a + b ;
133 } /* GSM_L_ADD */
134
135 static inline longword
136 GSM_ADD (word a, word b)
137 {       longword ltmp ;
138
139         ltmp = ((longword) a) + ((longword) b) ;
140
141         if (ltmp >= MAX_WORD)
142                 return MAX_WORD ;
143         if (ltmp <= MIN_WORD)
144                 return MIN_WORD ;
145
146         return ltmp ;
147 } /* GSM_ADD */
148
149 static inline longword
150 GSM_SUB (word a, word b)
151 {       longword ltmp ;
152
153         ltmp = ((longword) a) - ((longword) b) ;
154
155         if (ltmp >= MAX_WORD)
156                 ltmp = MAX_WORD ;
157         else if (ltmp <= MIN_WORD)
158                 ltmp = MIN_WORD ;
159
160         return ltmp ;
161 } /* GSM_SUB */
162
163 static inline word
164 GSM_ABS (word a)
165 {
166         if (a > 0)
167                 return a ;
168         if (a == MIN_WORD)
169                 return MAX_WORD ;
170         return -a ;
171 } /* GSM_ADD */
172
173
174 /*
175  *  More prototypes from implementations..
176  */
177 void Gsm_Coder (
178                 struct gsm_state        * S,
179                 word    * s,    /* [0..159] samples             IN      */
180                 word    * LARc, /* [0..7] LAR coefficients      OUT     */
181                 word    * Nc,   /* [0..3] LTP lag               OUT     */
182                 word    * bc,   /* [0..3] coded LTP gain        OUT     */
183                 word    * Mc,   /* [0..3] RPE grid selection    OUT     */
184                 word    * xmaxc,/* [0..3] Coded maximum amplitude OUT   */
185                 word    * xMc) ;/* [13*4] normalized RPE samples OUT    */
186
187 void Gsm_Long_Term_Predictor (          /* 4x for 160 samples */
188                 struct gsm_state * S,
189                 word    * d,    /* [0..39]   residual signal    IN      */
190                 word    * dp,   /* [-120..-1] d'                IN      */
191                 word    * e,    /* [0..40]                      OUT     */
192                 word    * dpp,  /* [0..40]                      OUT     */
193                 word    * Nc,   /* correlation lag              OUT     */
194                 word    * bc) ; /* gain factor                  OUT     */
195
196 void Gsm_LPC_Analysis (
197                 struct gsm_state * S,
198                 word * s,               /* 0..159 signals       IN/OUT  */
199                 word * LARc) ;   /* 0..7   LARc's       OUT     */
200
201 void Gsm_Preprocess (
202                 struct gsm_state * S,
203                 word * s, word * so) ;
204
205 void Gsm_Encoding (
206                 struct gsm_state * S,
207                 word    * e,
208                 word    * ep,
209                 word    * xmaxc,
210                 word    * Mc,
211                 word    * xMc) ;
212
213 void Gsm_Short_Term_Analysis_Filter (
214                 struct gsm_state * S,
215                 word    * LARc, /* coded log area ratio [0..7]  IN      */
216                 word    * d) ;  /* st res. signal [0..159]      IN/OUT  */
217
218 void Gsm_Decoder (
219                 struct gsm_state * S,
220                 word    * LARcr,        /* [0..7]               IN      */
221                 word    * Ncr,          /* [0..3]               IN      */
222                 word    * bcr,          /* [0..3]               IN      */
223                 word    * Mcr,          /* [0..3]               IN      */
224                 word    * xmaxcr,       /* [0..3]               IN      */
225                 word    * xMcr,         /* [0..13*4]            IN      */
226                 word    * s) ;          /* [0..159]             OUT     */
227
228 void Gsm_Decoding (
229                 struct gsm_state * S,
230                 word    xmaxcr,
231                 word    Mcr,
232                 word    * xMcr,         /* [0..12]              IN      */
233                 word    * erp) ;        /* [0..39]              OUT     */
234
235 void Gsm_Long_Term_Synthesis_Filtering (
236                 struct gsm_state* S,
237                 word    Ncr,
238                 word    bcr,
239                 word    * erp,          /* [0..39]                IN    */
240                 word    * drp) ;        /* [-120..-1] IN, [0..40] OUT   */
241
242 void Gsm_RPE_Decoding (
243         /*-struct gsm_state *S,-*/
244                 word xmaxcr,
245                 word Mcr,
246                 word * xMcr,  /* [0..12], 3 bits             IN      */
247                 word * erp) ; /* [0..39]                     OUT     */
248
249 void Gsm_RPE_Encoding (
250                 /*-struct gsm_state * S,-*/
251                 word    * e,            /* -5..-1][0..39][40..44     IN/OUT  */
252                 word    * xmaxc,        /*                              OUT */
253                 word    * Mc,           /*                              OUT */
254                 word    * xMc) ;        /* [0..12]                      OUT */
255
256 void Gsm_Short_Term_Synthesis_Filter (
257                 struct gsm_state * S,
258                 word    * LARcr,        /* log area ratios [0..7]  IN   */
259                 word    * drp,          /* received d [0...39]     IN   */
260                 word    * s) ;          /* signal   s [0..159]    OUT   */
261
262 void Gsm_Update_of_reconstructed_short_time_residual_signal (
263                 word    * dpp,          /* [0...39]     IN      */
264                 word    * ep,           /* [0...39]     IN      */
265                 word    * dp) ;         /* [-120...-1]  IN/OUT  */
266
267 /*
268  *  Tables from table.c
269  */
270 #ifndef GSM_TABLE_C
271
272 extern word gsm_A [8], gsm_B [8], gsm_MIC [8], gsm_MAC [8] ;
273 extern word gsm_INVA [8] ;
274 extern word gsm_DLB [4], gsm_QLB [4] ;
275 extern word gsm_H [11] ;
276 extern word gsm_NRFAC [8] ;
277 extern word gsm_FAC [8] ;
278
279 #endif  /* GSM_TABLE_C */
280
281 /*
282  *  Debugging
283  */
284 #ifdef NDEBUG
285
286 #       define  gsm_debug_words(a, b, c, d)             /* nil */
287 #       define  gsm_debug_longwords(a, b, c, d)         /* nil */
288 #       define  gsm_debug_word(a, b)                    /* nil */
289 #       define  gsm_debug_longword(a, b)                /* nil */
290
291 #else   /* !NDEBUG => DEBUG */
292
293         void  gsm_debug_words     (char * name, int, int, word *) ;
294         void  gsm_debug_longwords (char * name, int, int, longword *) ;
295         void  gsm_debug_longword  (char * name, longword) ;
296         void  gsm_debug_word      (char * name, word) ;
297
298 #endif /* !NDEBUG */
299
300 #endif  /* PRIVATE_H */
301 /*
302 ** Do not edit or modify anything in this comment block.
303 ** The arch-tag line is a file identity tag for the GNU Arch
304 ** revision control system.
305 **
306 ** arch-tag: 8bc5fdf2-e8c8-4686-9bd7-a30b512bef0c
307 */
308