Sync winemp3.acm with Wine HEAD. This one uses libmpg123 which was added in Version...
[reactos.git] / reactos / include / reactos / libs / libmpg123 / mpg123lib_intern.h
1 /*
2 mpg123lib_intern: Common non-public stuff for libmpg123
3
4 copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.1
5 see COPYING and AUTHORS files in distribution or http://mpg123.org
6
7 derived from the old mpg123.h
8 */
9
10 #ifndef MPG123_H_INTERN
11 #define MPG123_H_INTERN
12
13 #define MPG123_RATES 9
14 #define MPG123_ENCODINGS 10
15
16 #include "config.h" /* Load this before _anything_ */
17
18 /* ABI conformance for other compilers.
19 mpg123 needs 16byte-aligned stack for SSE and friends.
20 gcc provides that, but others don't necessarily. */
21 #ifdef ABI_ALIGN_FUN
22 #ifndef attribute_align_arg
23 #if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__>1)
24 # define attribute_align_arg __attribute__((force_align_arg_pointer))
25 /* The gcc that can align the stack does not need the check... nor does it work with gcc 4.3+, anyway. */
26 #else
27
28 # define attribute_align_arg
29 /* Other compilers get code to catch misaligned stack.
30 Well, except Sun Studio, which accepts the aligned attribute but does not honor it. */
31 #if !defined(__SUNPRO_C)
32 # define NEED_ALIGNCHECK
33 #endif
34
35 #endif
36 #endif
37 #else
38 #define attribute_align_arg
39 /* We won't try the align check... */
40 #endif
41
42 /* export DLL symbols */
43 #if defined(WIN32) && defined(DYNAMIC_BUILD)
44 #define BUILD_MPG123_DLL
45 #endif
46 #include "compat.h"
47 #include "mpg123.h"
48
49 #define SKIP_JUNK 1
50
51 #ifndef M_PI
52 # define M_PI 3.14159265358979323846
53 #endif
54 #ifndef M_SQRT2
55 # define M_SQRT2 1.41421356237309504880
56 #endif
57
58 #ifdef SUNOS
59 #define memmove(dst,src,size) bcopy(src,dst,size)
60 #endif
61
62 /* some stuff has to go back to mpg123.h */
63 #ifdef REAL_IS_FLOAT
64 # define real float
65 # define REAL_SCANF "%f"
66 # define REAL_PRINTF "%f"
67 #elif defined(REAL_IS_LONG_DOUBLE)
68 # define real long double
69 # define REAL_SCANF "%Lf"
70 # define REAL_PRINTF "%Lf"
71 #elif defined(REAL_IS_FIXED)
72 /* Disable some output formats for fixed point decoder... */
73
74 # define real long
75
76 /*
77 for fixed-point decoders, use pre-calculated tables to avoid expensive floating-point maths
78 undef this macro for run-time calculation
79 */
80 #define PRECALC_TABLES
81
82 # define REAL_RADIX 24
83 # define REAL_FACTOR 16777216.0
84
85 static inline long double_to_long_rounded(double x, double scalefac)
86 {
87 x *= scalefac;
88 x += (x > 0) ? 0.5 : -0.5;
89 return (long)x;
90 }
91
92 static inline long scale_rounded(long x, int shift)
93 {
94 x += (x >> 31);
95 x >>= (shift - 1);
96 x += (x & 1);
97 return (x >> 1);
98 }
99
100 # ifdef __GNUC__
101 # if defined(OPT_I386)
102 /* for i386_nofpu decoder */
103 # define REAL_MUL_ASM(x, y, radix) \
104 ({ \
105 long _x=(x), _y=(y); \
106 __asm__ ( \
107 "imull %1 \n\t" \
108 "shrdl %2, %%edx, %0 \n\t" \
109 : "+&a" (_x) \
110 : "mr" (_y), "I" (radix) \
111 : "%edx", "cc" \
112 ); \
113 _x; \
114 })
115
116 # define REAL_MUL_SCALE_LAYER3_ASM(x, y, radix) \
117 ({ \
118 long _x=(x), _y=(y), _radix=(radix); \
119 __asm__ ( \
120 "imull %1 \n\t" \
121 "shrdl %%cl, %%edx, %0 \n\t" \
122 : "+&a" (_x) \
123 : "mr" (_y), "c" (_radix) \
124 : "%edx", "cc" \
125 ); \
126 _x; \
127 })
128 # elif defined(OPT_PPC)
129 /* for powerpc */
130 # define REAL_MUL_ASM(x, y, radix) \
131 ({ \
132 long _x=(x), _y=(y), _mull, _mulh; \
133 __asm__ ( \
134 "mullw %0, %2, %3 \n\t" \
135 "mulhw %1, %2, %3 \n\t" \
136 "srwi %0, %0, %4 \n\t" \
137 "rlwimi %0, %1, %5, 0, %6 \n\t" \
138 : "=&r" (_mull), "=&r" (_mulh) \
139 : "%r" (_x), "r" (_y), "i" (radix), "i" (32-(radix)), "i" ((radix)-1) \
140 ); \
141 _mull; \
142 })
143
144 # define REAL_MUL_SCALE_LAYER3_ASM(x, y, radix) \
145 ({ \
146 long _x=(x), _y=(y), _radix=(radix), _mull, _mulh, _radix2; \
147 __asm__ ( \
148 "mullw %0, %3, %4 \n\t" \
149 "mulhw %1, %3, %4 \n\t" \
150 "subfic %2, %5, 32 \n\t" \
151 "srw %0, %0, %5 \n\t" \
152 "slw %1, %1, %2 \n\t" \
153 "or %0, %0, %1 \n\t" \
154 : "=&r" (_mull), "=&r" (_mulh), "=&r" (_radix2) \
155 : "%r" (_x), "r" (_y), "r" (_radix) \
156 : "cc" \
157 ); \
158 _mull; \
159 })
160 # elif defined(OPT_ARM)
161 /* for arm */
162 # define REAL_MUL_ASM(x, y, radix) \
163 ({ \
164 long _x=(x), _y=(y), _mull, _mulh; \
165 __asm__ ( \
166 "smull %0, %1, %2, %3 \n\t" \
167 "mov %0, %0, lsr %4 \n\t" \
168 "orr %0, %0, %1, lsl %5 \n\t" \
169 : "=&r" (_mull), "=&r" (_mulh) \
170 : "%r" (_x), "r" (_y), "M" (radix), "M" (32-(radix)) \
171 ); \
172 _mull; \
173 })
174
175 # define REAL_MUL_SCALE_LAYER3_ASM(x, y, radix) \
176 ({ \
177 long _x=(x), _y=(y), _radix=(radix), _mull, _mulh, _radix2; \
178 __asm__ ( \
179 "smull %0, %1, %3, %4 \n\t" \
180 "mov %0, %0, lsr %5 \n\t" \
181 "rsb %2, %5, #32 \n\t" \
182 "orr %0, %0, %1, lsl %2 \n\t" \
183 : "=&r" (_mull), "=&r" (_mulh), "=&r" (_radix2) \
184 : "%r" (_x), "r" (_y), "r" (_radix) \
185 ); \
186 _mull; \
187 })
188 # endif
189 # endif
190
191 /* I just changed the (int) to (long) there... seemed right. */
192 # define DOUBLE_TO_REAL(x) (double_to_long_rounded(x, REAL_FACTOR))
193 # define DOUBLE_TO_REAL_15(x) (double_to_long_rounded(x, 32768.0))
194 # define DOUBLE_TO_REAL_POW43(x) (double_to_long_rounded(x, 8192.0))
195 # define DOUBLE_TO_REAL_SCALE_LAYER12(x) (double_to_long_rounded(x, 1073741824.0))
196 # define DOUBLE_TO_REAL_SCALE_LAYER3(x, y) (double_to_long_rounded(x, pow(2.0,gainpow2_scale[y])))
197 # define REAL_TO_DOUBLE(x) ((double)(x) / REAL_FACTOR)
198 # ifdef REAL_MUL_ASM
199 # define REAL_MUL(x, y) REAL_MUL_ASM(x, y, REAL_RADIX)
200 # define REAL_MUL_15(x, y) REAL_MUL_ASM(x, y, 15)
201 # define REAL_MUL_SCALE_LAYER12(x, y) REAL_MUL_ASM(x, y, 15 + 30 - REAL_RADIX)
202 # else
203 # define REAL_MUL(x, y) (((long long)(x) * (long long)(y)) >> REAL_RADIX)
204 # define REAL_MUL_15(x, y) (((long long)(x) * (long long)(y)) >> 15)
205 # define REAL_MUL_SCALE_LAYER12(x, y) (((long long)(x) * (long long)(y)) >> (15 + 30 - REAL_RADIX))
206 # endif
207 # ifdef REAL_MUL_SCALE_LAYER3_ASM
208 # define REAL_MUL_SCALE_LAYER3(x, y, z) REAL_MUL_SCALE_LAYER3_ASM(x, y, 13 + gainpow2_scale[z] - REAL_RADIX)
209 # else
210 # define REAL_MUL_SCALE_LAYER3(x, y, z) (((long long)(x) * (long long)(y)) >> (13 + gainpow2_scale[z] - REAL_RADIX))
211 # endif
212 # define REAL_SCALE_LAYER12(x) ((long)((x) >> (30 - REAL_RADIX)))
213 # define REAL_SCALE_LAYER3(x, y) ((long)((x) >> (gainpow2_scale[y] - REAL_RADIX)))
214 # ifdef ACCURATE_ROUNDING
215 # define REAL_MUL_SYNTH(x, y) REAL_MUL(x, y)
216 # define REAL_SCALE_DCT64(x) (x)
217 # define REAL_SCALE_WINDOW(x) (x)
218 # else
219 # define REAL_MUL_SYNTH(x, y) ((x) * (y))
220 # define REAL_SCALE_DCT64(x) ((x) >> 8)
221 # define REAL_SCALE_WINDOW(x) scale_rounded(x, 16)
222 # endif
223 # define REAL_SCANF "%ld"
224 # define REAL_PRINTF "%ld"
225
226 #else
227 # define real double
228 # define REAL_SCANF "%lf"
229 # define REAL_PRINTF "%f"
230 #endif
231
232 #ifndef REAL_IS_FIXED
233 # if (defined SIZEOF_INT32_T) && (SIZEOF_INT32_T != 4)
234 # error "Bad 32bit types!!!"
235 # endif
236 #endif
237
238 #ifndef DOUBLE_TO_REAL
239 # define DOUBLE_TO_REAL(x) (real)(x)
240 #endif
241 #ifndef DOUBLE_TO_REAL_15
242 # define DOUBLE_TO_REAL_15(x) (real)(x)
243 #endif
244 #ifndef DOUBLE_TO_REAL_POW43
245 # define DOUBLE_TO_REAL_POW43(x) (real)(x)
246 #endif
247 #ifndef DOUBLE_TO_REAL_SCALE_LAYER12
248 # define DOUBLE_TO_REAL_SCALE_LAYER12(x) (real)(x)
249 #endif
250 #ifndef DOUBLE_TO_REAL_SCALE_LAYER3
251 # define DOUBLE_TO_REAL_SCALE_LAYER3(x, y) (real)(x)
252 #endif
253 #ifndef REAL_TO_DOUBLE
254 # define REAL_TO_DOUBLE(x) (x)
255 #endif
256
257 #ifndef REAL_MUL
258 # define REAL_MUL(x, y) ((x) * (y))
259 #endif
260 #ifndef REAL_MUL_SYNTH
261 # define REAL_MUL_SYNTH(x, y) ((x) * (y))
262 #endif
263 #ifndef REAL_MUL_15
264 # define REAL_MUL_15(x, y) ((x) * (y))
265 #endif
266 #ifndef REAL_MUL_SCALE_LAYER12
267 # define REAL_MUL_SCALE_LAYER12(x, y) ((x) * (y))
268 #endif
269 #ifndef REAL_MUL_SCALE_LAYER3
270 # define REAL_MUL_SCALE_LAYER3(x, y, z) ((x) * (y))
271 #endif
272 #ifndef REAL_SCALE_LAYER12
273 # define REAL_SCALE_LAYER12(x) (x)
274 #endif
275 #ifndef REAL_SCALE_LAYER3
276 # define REAL_SCALE_LAYER3(x, y) (x)
277 #endif
278 #ifndef REAL_SCALE_DCT64
279 # define REAL_SCALE_DCT64(x) (x)
280 #endif
281
282 /* used to be: AUDIOBUFSIZE = n*64 with n=1,2,3 ...
283 now: factor on minimum frame buffer size (which takes upsampling into account) */
284 #define AUDIOBUFSIZE 2
285
286 #include "true.h"
287
288 #define MAX_NAME_SIZE 81
289 #define SBLIMIT 32
290 #define SCALE_BLOCK 12
291 #define SSLIMIT 18
292
293 /* Same as MPG_M_* */
294 #define MPG_MD_STEREO 0
295 #define MPG_MD_JOINT_STEREO 1
296 #define MPG_MD_DUAL_CHANNEL 2
297 #define MPG_MD_MONO 3
298
299 /* We support short or float output samples...
300 Short integer amplitude is scaled by this. */
301 #define SHORT_SCALE 32768
302 /* That scales a short-scaled value to a 32bit integer scaled one
303 value = 2**31/2**15 */
304 #define S32_RESCALE 65536
305
306 /* Pre Shift fo 16 to 8 bit converter table */
307 #define AUSHIFT (3)
308
309 #include "optimize.h"
310 #include "decode.h"
311 #include "parse.h"
312 #include "frame.h"
313
314 /* fr is a mpg123_handle* by convention here... */
315 #define NOQUIET (!(fr->p.flags & MPG123_QUIET))
316 #define VERBOSE (NOQUIET && fr->p.verbose)
317 #define VERBOSE2 (NOQUIET && fr->p.verbose > 1)
318 #define VERBOSE3 (NOQUIET && fr->p.verbose > 2)
319 #define VERBOSE4 (NOQUIET && fr->p.verbose > 3)
320 #define PVERB(mp, level) (!((mp)->flags & MPG123_QUIET) && (mp)->verbose >= (level))
321
322 int decode_update(mpg123_handle *mh);
323 /* residing in format.c */
324 off_t samples_to_bytes(mpg123_handle *fr , off_t s);
325 off_t bytes_to_samples(mpg123_handle *fr , off_t b);
326
327 /* If networking is enabled and we really mean internal networking, the timeout_read function is available. */
328 #if defined (NETWORK) && !defined (WANT_WIN32_SOCKETS)
329 /* Does not work with win32 */
330 #define TIMEOUT_READ
331 #endif
332
333 #endif