Subversion Repositories Kolibri OS

Rev

Rev 1905 | Details | Compare with Previous | Last modification | View Log | RSS feed

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