Skip to content

Latest commit

 

History

History
324 lines (287 loc) · 8.78 KB

mpg123lib_intern.h

File metadata and controls

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