2 mpg123lib_intern: Common non-public stuff for libmpg123
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
7 derived from the old mpg123.h
10 #ifndef MPG123_H_INTERN
11 #define MPG123_H_INTERN
13 #define MPG123_RATES 9
14 #define MPG123_ENCODINGS 10
16 #include "config.h" /* Load this before _anything_ */
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. */
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. */
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
38 #define attribute_align_arg
39 /* We won't try the align check... */
42 /* export DLL symbols */
43 #if defined(WIN32) && defined(DYNAMIC_BUILD)
44 #define BUILD_MPG123_DLL
52 # define M_PI 3.14159265358979323846
55 # define M_SQRT2 1.41421356237309504880
59 #define memmove(dst,src,size) bcopy(src,dst,size)
62 /* some stuff has to go back to mpg123.h */
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... */
77 for fixed-point decoders, use pre-calculated tables to avoid expensive floating-point maths
78 undef this macro for run-time calculation
80 #define PRECALC_TABLES
82 # define REAL_RADIX 24
83 # define REAL_FACTOR 16777216.0
85 static inline long double_to_long_rounded(double x
, double scalefac
)
88 x
+= (x
> 0) ? 0.5 : -0.5;
92 static inline long scale_rounded(long x
, int shift
)
101 # if defined(OPT_I386)
102 /* for i386_nofpu decoder */
103 # define REAL_MUL_ASM(x, y, radix) \
105 long _x=(x), _y=(y); \
108 "shrdl %2, %%edx, %0 \n\t" \
110 : "mr" (_y), "I" (radix) \
116 # define REAL_MUL_SCALE_LAYER3_ASM(x, y, radix) \
118 long _x=(x), _y=(y), _radix=(radix); \
121 "shrdl %%cl, %%edx, %0 \n\t" \
123 : "mr" (_y), "c" (_radix) \
128 # elif defined(OPT_PPC)
130 # define REAL_MUL_ASM(x, y, radix) \
132 long _x=(x), _y=(y), _mull, _mulh; \
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) \
144 # define REAL_MUL_SCALE_LAYER3_ASM(x, y, radix) \
146 long _x=(x), _y=(y), _radix=(radix), _mull, _mulh, _radix2; \
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) \
160 # elif defined(OPT_ARM)
162 # define REAL_MUL_ASM(x, y, radix) \
164 long _x=(x), _y=(y), _mull, _mulh; \
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)) \
175 # define REAL_MUL_SCALE_LAYER3_ASM(x, y, radix) \
177 long _x=(x), _y=(y), _radix=(radix), _mull, _mulh, _radix2; \
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) \
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)
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)
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))
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)
210 # define REAL_MUL_SCALE_LAYER3(x, y, z) (((long long)(x) * (long long)(y)) >> (13 + gainpow2_scale[z] - REAL_RADIX))
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)
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)
223 # define REAL_SCANF "%ld"
224 # define REAL_PRINTF "%ld"
228 # define REAL_SCANF "%lf"
229 # define REAL_PRINTF "%f"
232 #ifndef REAL_IS_FIXED
233 # if (defined SIZEOF_INT32_T) && (SIZEOF_INT32_T != 4)
234 # error "Bad 32bit types!!!"
238 #ifndef DOUBLE_TO_REAL
239 # define DOUBLE_TO_REAL(x) (real)(x)
241 #ifndef DOUBLE_TO_REAL_15
242 # define DOUBLE_TO_REAL_15(x) (real)(x)
244 #ifndef DOUBLE_TO_REAL_POW43
245 # define DOUBLE_TO_REAL_POW43(x) (real)(x)
247 #ifndef DOUBLE_TO_REAL_SCALE_LAYER12
248 # define DOUBLE_TO_REAL_SCALE_LAYER12(x) (real)(x)
250 #ifndef DOUBLE_TO_REAL_SCALE_LAYER3
251 # define DOUBLE_TO_REAL_SCALE_LAYER3(x, y) (real)(x)
253 #ifndef REAL_TO_DOUBLE
254 # define REAL_TO_DOUBLE(x) (x)
258 # define REAL_MUL(x, y) ((x) * (y))
260 #ifndef REAL_MUL_SYNTH
261 # define REAL_MUL_SYNTH(x, y) ((x) * (y))
264 # define REAL_MUL_15(x, y) ((x) * (y))
266 #ifndef REAL_MUL_SCALE_LAYER12
267 # define REAL_MUL_SCALE_LAYER12(x, y) ((x) * (y))
269 #ifndef REAL_MUL_SCALE_LAYER3
270 # define REAL_MUL_SCALE_LAYER3(x, y, z) ((x) * (y))
272 #ifndef REAL_SCALE_LAYER12
273 # define REAL_SCALE_LAYER12(x) (x)
275 #ifndef REAL_SCALE_LAYER3
276 # define REAL_SCALE_LAYER3(x, y) (x)
278 #ifndef REAL_SCALE_DCT64
279 # define REAL_SCALE_DCT64(x) (x)
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
288 #define MAX_NAME_SIZE 81
290 #define SCALE_BLOCK 12
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
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
306 /* Pre Shift fo 16 to 8 bit converter table */
309 #include "optimize.h"
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))
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
);
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 */