2 |
- |
1 |
/*
|
|
|
2 |
* libmad - MPEG audio decoder library
|
|
|
3 |
* Copyright (C) 2000-2004 Underbit Technologies, Inc.
|
|
|
4 |
*
|
|
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
|
8 |
* (at your option) any later version.
|
|
|
9 |
*
|
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
13 |
* GNU General Public License for more details.
|
|
|
14 |
*
|
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
18 |
*
|
|
|
19 |
* If you would like to negotiate alternate licensing terms, you may do
|
|
|
20 |
* so by contacting: Underbit Technologies, Inc. <info@underbit.com>
|
|
|
21 |
*/
|
|
|
22 |
|
|
|
23 |
# ifdef __cplusplus
|
|
|
24 |
extern "C" {
|
|
|
25 |
# endif
|
|
|
26 |
|
|
|
27 |
# define FPM_INTEL
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
# define SIZEOF_INT 4
|
|
|
32 |
# define SIZEOF_LONG 4
|
|
|
33 |
# define SIZEOF_LONG_LONG 8
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
/* Id: version.h,v 1.26 2004/01/23 09:41:33 rob Exp */
|
|
|
37 |
|
|
|
38 |
# ifndef LIBMAD_VERSION_H
|
|
|
39 |
# define LIBMAD_VERSION_H
|
|
|
40 |
|
|
|
41 |
# define MAD_VERSION_MAJOR 0
|
|
|
42 |
# define MAD_VERSION_MINOR 15
|
|
|
43 |
# define MAD_VERSION_PATCH 1
|
|
|
44 |
# define MAD_VERSION_EXTRA " (beta)"
|
|
|
45 |
|
|
|
46 |
# define MAD_VERSION_STRINGIZE(str) #str
|
|
|
47 |
# define MAD_VERSION_STRING(num) MAD_VERSION_STRINGIZE(num)
|
|
|
48 |
|
|
|
49 |
# define MAD_VERSION MAD_VERSION_STRING(MAD_VERSION_MAJOR) "." \
|
|
|
50 |
MAD_VERSION_STRING(MAD_VERSION_MINOR) "." \
|
|
|
51 |
MAD_VERSION_STRING(MAD_VERSION_PATCH) \
|
|
|
52 |
MAD_VERSION_EXTRA
|
|
|
53 |
|
|
|
54 |
# define MAD_PUBLISHYEAR "2000-2004"
|
|
|
55 |
# define MAD_AUTHOR "Underbit Technologies, Inc."
|
|
|
56 |
# define MAD_EMAIL "info@underbit.com"
|
|
|
57 |
|
|
|
58 |
extern char const mad_version[];
|
|
|
59 |
extern char const mad_copyright[];
|
|
|
60 |
extern char const mad_author[];
|
|
|
61 |
extern char const mad_build[];
|
|
|
62 |
|
|
|
63 |
# endif
|
|
|
64 |
|
|
|
65 |
/* Id: fixed.h,v 1.38 2004/02/17 02:02:03 rob Exp */
|
|
|
66 |
|
|
|
67 |
# ifndef LIBMAD_FIXED_H
|
|
|
68 |
# define LIBMAD_FIXED_H
|
|
|
69 |
|
|
|
70 |
# if SIZEOF_INT >= 4
|
|
|
71 |
typedef signed int mad_fixed_t;
|
|
|
72 |
|
|
|
73 |
typedef signed int mad_fixed64hi_t;
|
|
|
74 |
typedef unsigned int mad_fixed64lo_t;
|
|
|
75 |
# else
|
|
|
76 |
typedef signed long mad_fixed_t;
|
|
|
77 |
|
|
|
78 |
typedef signed long mad_fixed64hi_t;
|
|
|
79 |
typedef unsigned long mad_fixed64lo_t;
|
|
|
80 |
# endif
|
|
|
81 |
|
|
|
82 |
# if defined(_MSC_VER)
|
|
|
83 |
# define mad_fixed64_t signed __int64
|
|
|
84 |
# elif 1 || defined(__GNUC__)
|
|
|
85 |
# define mad_fixed64_t signed long long
|
|
|
86 |
# endif
|
|
|
87 |
|
|
|
88 |
# if defined(FPM_FLOAT)
|
|
|
89 |
typedef double mad_sample_t;
|
|
|
90 |
# else
|
|
|
91 |
typedef mad_fixed_t mad_sample_t;
|
|
|
92 |
# endif
|
|
|
93 |
|
|
|
94 |
/*
|
|
|
95 |
* Fixed-point format: 0xABBBBBBB
|
|
|
96 |
* A == whole part (sign + 3 bits)
|
|
|
97 |
* B == fractional part (28 bits)
|
|
|
98 |
*
|
|
|
99 |
* Values are signed two's complement, so the effective range is:
|
|
|
100 |
* 0x80000000 to 0x7fffffff
|
|
|
101 |
* -8.0 to +7.9999999962747097015380859375
|
|
|
102 |
*
|
|
|
103 |
* The smallest representable value is:
|
|
|
104 |
* 0x00000001 == 0.0000000037252902984619140625 (i.e. about 3.725e-9)
|
|
|
105 |
*
|
|
|
106 |
* 28 bits of fractional accuracy represent about
|
|
|
107 |
* 8.6 digits of decimal accuracy.
|
|
|
108 |
*
|
|
|
109 |
* Fixed-point numbers can be added or subtracted as normal
|
|
|
110 |
* integers, but multiplication requires shifting the 64-bit result
|
|
|
111 |
* from 56 fractional bits back to 28 (and rounding.)
|
|
|
112 |
*
|
|
|
113 |
* Changing the definition of MAD_F_FRACBITS is only partially
|
|
|
114 |
* supported, and must be done with care.
|
|
|
115 |
*/
|
|
|
116 |
|
|
|
117 |
# define MAD_F_FRACBITS 28
|
|
|
118 |
|
|
|
119 |
# define MAD_F(x) ((mad_fixed_t) (x##L))
|
|
|
120 |
|
|
|
121 |
# define MAD_F_MIN ((mad_fixed_t) -0x80000000L)
|
|
|
122 |
# define MAD_F_MAX ((mad_fixed_t) +0x7fffffffL)
|
|
|
123 |
|
|
|
124 |
# define MAD_F_ONE MAD_F(0x10000000)
|
|
|
125 |
|
|
|
126 |
# define mad_f_tofixed(x) ((mad_fixed_t) \
|
|
|
127 |
((x) * (double) (1L << MAD_F_FRACBITS) + 0.5))
|
|
|
128 |
# define mad_f_todouble(x) ((double) \
|
|
|
129 |
((x) / (double) (1L << MAD_F_FRACBITS)))
|
|
|
130 |
|
|
|
131 |
# define mad_f_intpart(x) ((x) >> MAD_F_FRACBITS)
|
|
|
132 |
# define mad_f_fracpart(x) ((x) & ((1L << MAD_F_FRACBITS) - 1))
|
|
|
133 |
/* (x should be positive) */
|
|
|
134 |
|
|
|
135 |
# define mad_f_fromint(x) ((x) << MAD_F_FRACBITS)
|
|
|
136 |
|
|
|
137 |
# define mad_f_add(x, y) ((x) + (y))
|
|
|
138 |
# define mad_f_sub(x, y) ((x) - (y))
|
|
|
139 |
|
|
|
140 |
# if defined(FPM_FLOAT)
|
|
|
141 |
# error "FPM_FLOAT not yet supported"
|
|
|
142 |
|
|
|
143 |
# undef MAD_F
|
|
|
144 |
# define MAD_F(x) mad_f_todouble(x)
|
|
|
145 |
|
|
|
146 |
# define mad_f_mul(x, y) ((x) * (y))
|
|
|
147 |
# define mad_f_scale64
|
|
|
148 |
|
|
|
149 |
# undef ASO_ZEROCHECK
|
|
|
150 |
|
|
|
151 |
# elif defined(FPM_64BIT)
|
|
|
152 |
|
|
|
153 |
/*
|
|
|
154 |
* This version should be the most accurate if 64-bit types are supported by
|
|
|
155 |
* the compiler, although it may not be the most efficient.
|
|
|
156 |
*/
|
|
|
157 |
# if defined(OPT_ACCURACY)
|
|
|
158 |
# define mad_f_mul(x, y) \
|
|
|
159 |
((mad_fixed_t) \
|
|
|
160 |
((((mad_fixed64_t) (x) * (y)) + \
|
|
|
161 |
(1L << (MAD_F_SCALEBITS - 1))) >> MAD_F_SCALEBITS))
|
|
|
162 |
# else
|
|
|
163 |
# define mad_f_mul(x, y) \
|
|
|
164 |
((mad_fixed_t) (((mad_fixed64_t) (x) * (y)) >> MAD_F_SCALEBITS))
|
|
|
165 |
# endif
|
|
|
166 |
|
|
|
167 |
# define MAD_F_SCALEBITS MAD_F_FRACBITS
|
|
|
168 |
|
|
|
169 |
/* --- Intel --------------------------------------------------------------- */
|
|
|
170 |
|
|
|
171 |
# elif defined(FPM_INTEL)
|
|
|
172 |
|
|
|
173 |
# if defined(_MSC_VER)
|
|
|
174 |
# pragma warning(push)
|
|
|
175 |
# pragma warning(disable: 4035) /* no return value */
|
|
|
176 |
static __forceinline
|
|
|
177 |
mad_fixed_t mad_f_mul_inline(mad_fixed_t x, mad_fixed_t y)
|
|
|
178 |
{
|
|
|
179 |
enum {
|
|
|
180 |
fracbits = MAD_F_FRACBITS
|
|
|
181 |
};
|
|
|
182 |
|
|
|
183 |
__asm {
|
|
|
184 |
mov eax, x
|
|
|
185 |
imul y
|
|
|
186 |
shrd eax, edx, fracbits
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
/* implicit return of eax */
|
|
|
190 |
}
|
|
|
191 |
# pragma warning(pop)
|
|
|
192 |
|
|
|
193 |
# define mad_f_mul mad_f_mul_inline
|
|
|
194 |
# define mad_f_scale64
|
|
|
195 |
# else
|
|
|
196 |
/*
|
|
|
197 |
* This Intel version is fast and accurate; the disposition of the least
|
|
|
198 |
* significant bit depends on OPT_ACCURACY via mad_f_scale64().
|
|
|
199 |
*/
|
|
|
200 |
# define MAD_F_MLX(hi, lo, x, y) \
|
|
|
201 |
asm ("imull %3" \
|
|
|
202 |
: "=a" (lo), "=d" (hi) \
|
|
|
203 |
: "%a" (x), "rm" (y) \
|
|
|
204 |
: "cc")
|
|
|
205 |
|
|
|
206 |
# if defined(OPT_ACCURACY)
|
|
|
207 |
/*
|
|
|
208 |
* This gives best accuracy but is not very fast.
|
|
|
209 |
*/
|
|
|
210 |
# define MAD_F_MLA(hi, lo, x, y) \
|
|
|
211 |
({ mad_fixed64hi_t __hi; \
|
|
|
212 |
mad_fixed64lo_t __lo; \
|
|
|
213 |
MAD_F_MLX(__hi, __lo, (x), (y)); \
|
|
|
214 |
asm ("addl %2,%0\n\t" \
|
|
|
215 |
"adcl %3,%1" \
|
|
|
216 |
: "=rm" (lo), "=rm" (hi) \
|
|
|
217 |
: "r" (__lo), "r" (__hi), "0" (lo), "1" (hi) \
|
|
|
218 |
: "cc"); \
|
|
|
219 |
})
|
|
|
220 |
# endif /* OPT_ACCURACY */
|
|
|
221 |
|
|
|
222 |
# if defined(OPT_ACCURACY)
|
|
|
223 |
/*
|
|
|
224 |
* Surprisingly, this is faster than SHRD followed by ADC.
|
|
|
225 |
*/
|
|
|
226 |
# define mad_f_scale64(hi, lo) \
|
|
|
227 |
({ mad_fixed64hi_t __hi_; \
|
|
|
228 |
mad_fixed64lo_t __lo_; \
|
|
|
229 |
mad_fixed_t __result; \
|
|
|
230 |
asm ("addl %4,%2\n\t" \
|
|
|
231 |
"adcl %5,%3" \
|
|
|
232 |
: "=rm" (__lo_), "=rm" (__hi_) \
|
|
|
233 |
: "0" (lo), "1" (hi), \
|
|
|
234 |
"ir" (1L << (MAD_F_SCALEBITS - 1)), "ir" (0) \
|
|
|
235 |
: "cc"); \
|
|
|
236 |
asm ("shrdl %3,%2,%1" \
|
|
|
237 |
: "=rm" (__result) \
|
|
|
238 |
: "0" (__lo_), "r" (__hi_), "I" (MAD_F_SCALEBITS) \
|
|
|
239 |
: "cc"); \
|
|
|
240 |
__result; \
|
|
|
241 |
})
|
|
|
242 |
# elif defined(OPT_INTEL)
|
|
|
243 |
/*
|
|
|
244 |
* Alternate Intel scaling that may or may not perform better.
|
|
|
245 |
*/
|
|
|
246 |
# define mad_f_scale64(hi, lo) \
|
|
|
247 |
({ mad_fixed_t __result; \
|
|
|
248 |
asm ("shrl %3,%1\n\t" \
|
|
|
249 |
"shll %4,%2\n\t" \
|
|
|
250 |
"orl %2,%1" \
|
|
|
251 |
: "=rm" (__result) \
|
|
|
252 |
: "0" (lo), "r" (hi), \
|
|
|
253 |
"I" (MAD_F_SCALEBITS), "I" (32 - MAD_F_SCALEBITS) \
|
|
|
254 |
: "cc"); \
|
|
|
255 |
__result; \
|
|
|
256 |
})
|
|
|
257 |
# else
|
|
|
258 |
# define mad_f_scale64(hi, lo) \
|
|
|
259 |
({ mad_fixed_t __result; \
|
|
|
260 |
asm ("shrdl %3,%2,%1" \
|
|
|
261 |
: "=rm" (__result) \
|
|
|
262 |
: "0" (lo), "r" (hi), "I" (MAD_F_SCALEBITS) \
|
|
|
263 |
: "cc"); \
|
|
|
264 |
__result; \
|
|
|
265 |
})
|
|
|
266 |
# endif /* OPT_ACCURACY */
|
|
|
267 |
|
|
|
268 |
# define MAD_F_SCALEBITS MAD_F_FRACBITS
|
|
|
269 |
# endif
|
|
|
270 |
|
|
|
271 |
/* --- ARM ----------------------------------------------------------------- */
|
|
|
272 |
|
|
|
273 |
# elif defined(FPM_ARM)
|
|
|
274 |
|
|
|
275 |
/*
|
|
|
276 |
* This ARM V4 version is as accurate as FPM_64BIT but much faster. The
|
|
|
277 |
* least significant bit is properly rounded at no CPU cycle cost!
|
|
|
278 |
*/
|
|
|
279 |
# if 1
|
|
|
280 |
/*
|
|
|
281 |
* This is faster than the default implementation via MAD_F_MLX() and
|
|
|
282 |
* mad_f_scale64().
|
|
|
283 |
*/
|
|
|
284 |
# define mad_f_mul(x, y) \
|
|
|
285 |
({ mad_fixed64hi_t __hi; \
|
|
|
286 |
mad_fixed64lo_t __lo; \
|
|
|
287 |
mad_fixed_t __result; \
|
|
|
288 |
asm ("smull %0, %1, %3, %4\n\t" \
|
|
|
289 |
"movs %0, %0, lsr %5\n\t" \
|
|
|
290 |
"adc %2, %0, %1, lsl %6" \
|
|
|
291 |
: "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
|
|
|
292 |
: "%r" (x), "r" (y), \
|
|
|
293 |
"M" (MAD_F_SCALEBITS), "M" (32 - MAD_F_SCALEBITS) \
|
|
|
294 |
: "cc"); \
|
|
|
295 |
__result; \
|
|
|
296 |
})
|
|
|
297 |
# endif
|
|
|
298 |
|
|
|
299 |
# define MAD_F_MLX(hi, lo, x, y) \
|
|
|
300 |
asm ("smull %0, %1, %2, %3" \
|
|
|
301 |
: "=&r" (lo), "=&r" (hi) \
|
|
|
302 |
: "%r" (x), "r" (y))
|
|
|
303 |
|
|
|
304 |
# define MAD_F_MLA(hi, lo, x, y) \
|
|
|
305 |
asm ("smlal %0, %1, %2, %3" \
|
|
|
306 |
: "+r" (lo), "+r" (hi) \
|
|
|
307 |
: "%r" (x), "r" (y))
|
|
|
308 |
|
|
|
309 |
# define MAD_F_MLN(hi, lo) \
|
|
|
310 |
asm ("rsbs %0, %2, #0\n\t" \
|
|
|
311 |
"rsc %1, %3, #0" \
|
|
|
312 |
: "=r" (lo), "=r" (hi) \
|
|
|
313 |
: "0" (lo), "1" (hi) \
|
|
|
314 |
: "cc")
|
|
|
315 |
|
|
|
316 |
# define mad_f_scale64(hi, lo) \
|
|
|
317 |
({ mad_fixed_t __result; \
|
|
|
318 |
asm ("movs %0, %1, lsr %3\n\t" \
|
|
|
319 |
"adc %0, %0, %2, lsl %4" \
|
|
|
320 |
: "=&r" (__result) \
|
|
|
321 |
: "r" (lo), "r" (hi), \
|
|
|
322 |
"M" (MAD_F_SCALEBITS), "M" (32 - MAD_F_SCALEBITS) \
|
|
|
323 |
: "cc"); \
|
|
|
324 |
__result; \
|
|
|
325 |
})
|
|
|
326 |
|
|
|
327 |
# define MAD_F_SCALEBITS MAD_F_FRACBITS
|
|
|
328 |
|
|
|
329 |
/* --- MIPS ---------------------------------------------------------------- */
|
|
|
330 |
|
|
|
331 |
# elif defined(FPM_MIPS)
|
|
|
332 |
|
|
|
333 |
/*
|
|
|
334 |
* This MIPS version is fast and accurate; the disposition of the least
|
|
|
335 |
* significant bit depends on OPT_ACCURACY via mad_f_scale64().
|
|
|
336 |
*/
|
|
|
337 |
# define MAD_F_MLX(hi, lo, x, y) \
|
|
|
338 |
asm ("mult %2,%3" \
|
|
|
339 |
: "=l" (lo), "=h" (hi) \
|
|
|
340 |
: "%r" (x), "r" (y))
|
|
|
341 |
|
|
|
342 |
# if defined(HAVE_MADD_ASM)
|
|
|
343 |
# define MAD_F_MLA(hi, lo, x, y) \
|
|
|
344 |
asm ("madd %2,%3" \
|
|
|
345 |
: "+l" (lo), "+h" (hi) \
|
|
|
346 |
: "%r" (x), "r" (y))
|
|
|
347 |
# elif defined(HAVE_MADD16_ASM)
|
|
|
348 |
/*
|
|
|
349 |
* This loses significant accuracy due to the 16-bit integer limit in the
|
|
|
350 |
* multiply/accumulate instruction.
|
|
|
351 |
*/
|
|
|
352 |
# define MAD_F_ML0(hi, lo, x, y) \
|
|
|
353 |
asm ("mult %2,%3" \
|
|
|
354 |
: "=l" (lo), "=h" (hi) \
|
|
|
355 |
: "%r" ((x) >> 12), "r" ((y) >> 16))
|
|
|
356 |
# define MAD_F_MLA(hi, lo, x, y) \
|
|
|
357 |
asm ("madd16 %2,%3" \
|
|
|
358 |
: "+l" (lo), "+h" (hi) \
|
|
|
359 |
: "%r" ((x) >> 12), "r" ((y) >> 16))
|
|
|
360 |
# define MAD_F_MLZ(hi, lo) ((mad_fixed_t) (lo))
|
|
|
361 |
# endif
|
|
|
362 |
|
|
|
363 |
# if defined(OPT_SPEED)
|
|
|
364 |
# define mad_f_scale64(hi, lo) \
|
|
|
365 |
((mad_fixed_t) ((hi) << (32 - MAD_F_SCALEBITS)))
|
|
|
366 |
# define MAD_F_SCALEBITS MAD_F_FRACBITS
|
|
|
367 |
# endif
|
|
|
368 |
|
|
|
369 |
/* --- SPARC --------------------------------------------------------------- */
|
|
|
370 |
|
|
|
371 |
# elif defined(FPM_SPARC)
|
|
|
372 |
|
|
|
373 |
/*
|
|
|
374 |
* This SPARC V8 version is fast and accurate; the disposition of the least
|
|
|
375 |
* significant bit depends on OPT_ACCURACY via mad_f_scale64().
|
|
|
376 |
*/
|
|
|
377 |
# define MAD_F_MLX(hi, lo, x, y) \
|
|
|
378 |
asm ("smul %2, %3, %0\n\t" \
|
|
|
379 |
"rd %%y, %1" \
|
|
|
380 |
: "=r" (lo), "=r" (hi) \
|
|
|
381 |
: "%r" (x), "rI" (y))
|
|
|
382 |
|
|
|
383 |
/* --- PowerPC ------------------------------------------------------------- */
|
|
|
384 |
|
|
|
385 |
# elif defined(FPM_PPC)
|
|
|
386 |
|
|
|
387 |
/*
|
|
|
388 |
* This PowerPC version is fast and accurate; the disposition of the least
|
|
|
389 |
* significant bit depends on OPT_ACCURACY via mad_f_scale64().
|
|
|
390 |
*/
|
|
|
391 |
# define MAD_F_MLX(hi, lo, x, y) \
|
|
|
392 |
do { \
|
|
|
393 |
asm ("mullw %0,%1,%2" \
|
|
|
394 |
: "=r" (lo) \
|
|
|
395 |
: "%r" (x), "r" (y)); \
|
|
|
396 |
asm ("mulhw %0,%1,%2" \
|
|
|
397 |
: "=r" (hi) \
|
|
|
398 |
: "%r" (x), "r" (y)); \
|
|
|
399 |
} \
|
|
|
400 |
while (0)
|
|
|
401 |
|
|
|
402 |
# if defined(OPT_ACCURACY)
|
|
|
403 |
/*
|
|
|
404 |
* This gives best accuracy but is not very fast.
|
|
|
405 |
*/
|
|
|
406 |
# define MAD_F_MLA(hi, lo, x, y) \
|
|
|
407 |
({ mad_fixed64hi_t __hi; \
|
|
|
408 |
mad_fixed64lo_t __lo; \
|
|
|
409 |
MAD_F_MLX(__hi, __lo, (x), (y)); \
|
|
|
410 |
asm ("addc %0,%2,%3\n\t" \
|
|
|
411 |
"adde %1,%4,%5" \
|
|
|
412 |
: "=r" (lo), "=r" (hi) \
|
|
|
413 |
: "%r" (lo), "r" (__lo), \
|
|
|
414 |
"%r" (hi), "r" (__hi) \
|
|
|
415 |
: "xer"); \
|
|
|
416 |
})
|
|
|
417 |
# endif
|
|
|
418 |
|
|
|
419 |
# if defined(OPT_ACCURACY)
|
|
|
420 |
/*
|
|
|
421 |
* This is slower than the truncating version below it.
|
|
|
422 |
*/
|
|
|
423 |
# define mad_f_scale64(hi, lo) \
|
|
|
424 |
({ mad_fixed_t __result, __round; \
|
|
|
425 |
asm ("rotrwi %0,%1,%2" \
|
|
|
426 |
: "=r" (__result) \
|
|
|
427 |
: "r" (lo), "i" (MAD_F_SCALEBITS)); \
|
|
|
428 |
asm ("extrwi %0,%1,1,0" \
|
|
|
429 |
: "=r" (__round) \
|
|
|
430 |
: "r" (__result)); \
|
|
|
431 |
asm ("insrwi %0,%1,%2,0" \
|
|
|
432 |
: "+r" (__result) \
|
|
|
433 |
: "r" (hi), "i" (MAD_F_SCALEBITS)); \
|
|
|
434 |
asm ("add %0,%1,%2" \
|
|
|
435 |
: "=r" (__result) \
|
|
|
436 |
: "%r" (__result), "r" (__round)); \
|
|
|
437 |
__result; \
|
|
|
438 |
})
|
|
|
439 |
# else
|
|
|
440 |
# define mad_f_scale64(hi, lo) \
|
|
|
441 |
({ mad_fixed_t __result; \
|
|
|
442 |
asm ("rotrwi %0,%1,%2" \
|
|
|
443 |
: "=r" (__result) \
|
|
|
444 |
: "r" (lo), "i" (MAD_F_SCALEBITS)); \
|
|
|
445 |
asm ("insrwi %0,%1,%2,0" \
|
|
|
446 |
: "+r" (__result) \
|
|
|
447 |
: "r" (hi), "i" (MAD_F_SCALEBITS)); \
|
|
|
448 |
__result; \
|
|
|
449 |
})
|
|
|
450 |
# endif
|
|
|
451 |
|
|
|
452 |
# define MAD_F_SCALEBITS MAD_F_FRACBITS
|
|
|
453 |
|
|
|
454 |
/* --- Default ------------------------------------------------------------- */
|
|
|
455 |
|
|
|
456 |
# elif defined(FPM_DEFAULT)
|
|
|
457 |
|
|
|
458 |
/*
|
|
|
459 |
* This version is the most portable but it loses significant accuracy.
|
|
|
460 |
* Furthermore, accuracy is biased against the second argument, so care
|
|
|
461 |
* should be taken when ordering operands.
|
|
|
462 |
*
|
|
|
463 |
* The scale factors are constant as this is not used with SSO.
|
|
|
464 |
*
|
|
|
465 |
* Pre-rounding is required to stay within the limits of compliance.
|
|
|
466 |
*/
|
|
|
467 |
# if defined(OPT_SPEED)
|
|
|
468 |
# define mad_f_mul(x, y) (((x) >> 12) * ((y) >> 16))
|
|
|
469 |
# else
|
|
|
470 |
# define mad_f_mul(x, y) ((((x) + (1L << 11)) >> 12) * \
|
|
|
471 |
(((y) + (1L << 15)) >> 16))
|
|
|
472 |
# endif
|
|
|
473 |
|
|
|
474 |
/* ------------------------------------------------------------------------- */
|
|
|
475 |
|
|
|
476 |
# else
|
|
|
477 |
# error "no FPM selected"
|
|
|
478 |
# endif
|
|
|
479 |
|
|
|
480 |
/* default implementations */
|
|
|
481 |
|
|
|
482 |
# if !defined(mad_f_mul)
|
|
|
483 |
# define mad_f_mul(x, y) \
|
|
|
484 |
({ register mad_fixed64hi_t __hi; \
|
|
|
485 |
register mad_fixed64lo_t __lo; \
|
|
|
486 |
MAD_F_MLX(__hi, __lo, (x), (y)); \
|
|
|
487 |
mad_f_scale64(__hi, __lo); \
|
|
|
488 |
})
|
|
|
489 |
# endif
|
|
|
490 |
|
|
|
491 |
# if !defined(MAD_F_MLA)
|
|
|
492 |
# define MAD_F_ML0(hi, lo, x, y) ((lo) = mad_f_mul((x), (y)))
|
|
|
493 |
# define MAD_F_MLA(hi, lo, x, y) ((lo) += mad_f_mul((x), (y)))
|
|
|
494 |
# define MAD_F_MLN(hi, lo) ((lo) = -(lo))
|
|
|
495 |
# define MAD_F_MLZ(hi, lo) ((void) (hi), (mad_fixed_t) (lo))
|
|
|
496 |
# endif
|
|
|
497 |
|
|
|
498 |
# if !defined(MAD_F_ML0)
|
|
|
499 |
# define MAD_F_ML0(hi, lo, x, y) MAD_F_MLX((hi), (lo), (x), (y))
|
|
|
500 |
# endif
|
|
|
501 |
|
|
|
502 |
# if !defined(MAD_F_MLN)
|
|
|
503 |
# define MAD_F_MLN(hi, lo) ((hi) = ((lo) = -(lo)) ? ~(hi) : -(hi))
|
|
|
504 |
# endif
|
|
|
505 |
|
|
|
506 |
# if !defined(MAD_F_MLZ)
|
|
|
507 |
# define MAD_F_MLZ(hi, lo) mad_f_scale64((hi), (lo))
|
|
|
508 |
# endif
|
|
|
509 |
|
|
|
510 |
# if !defined(mad_f_scale64)
|
|
|
511 |
# if defined(OPT_ACCURACY)
|
|
|
512 |
# define mad_f_scale64(hi, lo) \
|
|
|
513 |
((((mad_fixed_t) \
|
|
|
514 |
(((hi) << (32 - (MAD_F_SCALEBITS - 1))) | \
|
|
|
515 |
((lo) >> (MAD_F_SCALEBITS - 1)))) + 1) >> 1)
|
|
|
516 |
# else
|
|
|
517 |
# define mad_f_scale64(hi, lo) \
|
|
|
518 |
((mad_fixed_t) \
|
|
|
519 |
(((hi) << (32 - MAD_F_SCALEBITS)) | \
|
|
|
520 |
((lo) >> MAD_F_SCALEBITS)))
|
|
|
521 |
# endif
|
|
|
522 |
# define MAD_F_SCALEBITS MAD_F_FRACBITS
|
|
|
523 |
# endif
|
|
|
524 |
|
|
|
525 |
/* C routines */
|
|
|
526 |
|
|
|
527 |
mad_fixed_t mad_f_abs(mad_fixed_t);
|
|
|
528 |
mad_fixed_t mad_f_div(mad_fixed_t, mad_fixed_t);
|
|
|
529 |
|
|
|
530 |
# endif
|
|
|
531 |
|
|
|
532 |
/* Id: bit.h,v 1.12 2004/01/23 09:41:32 rob Exp */
|
|
|
533 |
|
|
|
534 |
# ifndef LIBMAD_BIT_H
|
|
|
535 |
# define LIBMAD_BIT_H
|
|
|
536 |
|
|
|
537 |
struct mad_bitptr {
|
|
|
538 |
unsigned char const *byte;
|
|
|
539 |
unsigned short cache;
|
|
|
540 |
unsigned short left;
|
|
|
541 |
};
|
|
|
542 |
|
|
|
543 |
void mad_bit_init(struct mad_bitptr *, unsigned char const *);
|
|
|
544 |
|
|
|
545 |
# define mad_bit_finish(bitptr) /* nothing */
|
|
|
546 |
|
|
|
547 |
unsigned int mad_bit_length(struct mad_bitptr const *,
|
|
|
548 |
struct mad_bitptr const *);
|
|
|
549 |
|
|
|
550 |
# define mad_bit_bitsleft(bitptr) ((bitptr)->left)
|
|
|
551 |
unsigned char const *mad_bit_nextbyte(struct mad_bitptr const *);
|
|
|
552 |
|
|
|
553 |
void mad_bit_skip(struct mad_bitptr *, unsigned int);
|
|
|
554 |
unsigned long mad_bit_read(struct mad_bitptr *, unsigned int);
|
|
|
555 |
void mad_bit_write(struct mad_bitptr *, unsigned int, unsigned long);
|
|
|
556 |
|
|
|
557 |
unsigned short mad_bit_crc(struct mad_bitptr, unsigned int, unsigned short);
|
|
|
558 |
|
|
|
559 |
# endif
|
|
|
560 |
|
|
|
561 |
/* Id: timer.h,v 1.16 2004/01/23 09:41:33 rob Exp */
|
|
|
562 |
|
|
|
563 |
# ifndef LIBMAD_TIMER_H
|
|
|
564 |
# define LIBMAD_TIMER_H
|
|
|
565 |
|
|
|
566 |
typedef struct {
|
|
|
567 |
signed long seconds; /* whole seconds */
|
|
|
568 |
unsigned long fraction; /* 1/MAD_TIMER_RESOLUTION seconds */
|
|
|
569 |
} mad_timer_t;
|
|
|
570 |
|
|
|
571 |
extern mad_timer_t const mad_timer_zero;
|
|
|
572 |
|
|
|
573 |
# define MAD_TIMER_RESOLUTION 352800000UL
|
|
|
574 |
|
|
|
575 |
enum mad_units {
|
|
|
576 |
MAD_UNITS_HOURS = -2,
|
|
|
577 |
MAD_UNITS_MINUTES = -1,
|
|
|
578 |
MAD_UNITS_SECONDS = 0,
|
|
|
579 |
|
|
|
580 |
/* metric units */
|
|
|
581 |
|
|
|
582 |
MAD_UNITS_DECISECONDS = 10,
|
|
|
583 |
MAD_UNITS_CENTISECONDS = 100,
|
|
|
584 |
MAD_UNITS_MILLISECONDS = 1000,
|
|
|
585 |
|
|
|
586 |
/* audio sample units */
|
|
|
587 |
|
|
|
588 |
MAD_UNITS_8000_HZ = 8000,
|
|
|
589 |
MAD_UNITS_11025_HZ = 11025,
|
|
|
590 |
MAD_UNITS_12000_HZ = 12000,
|
|
|
591 |
|
|
|
592 |
MAD_UNITS_16000_HZ = 16000,
|
|
|
593 |
MAD_UNITS_22050_HZ = 22050,
|
|
|
594 |
MAD_UNITS_24000_HZ = 24000,
|
|
|
595 |
|
|
|
596 |
MAD_UNITS_32000_HZ = 32000,
|
|
|
597 |
MAD_UNITS_44100_HZ = 44100,
|
|
|
598 |
MAD_UNITS_48000_HZ = 48000,
|
|
|
599 |
|
|
|
600 |
/* video frame/field units */
|
|
|
601 |
|
|
|
602 |
MAD_UNITS_24_FPS = 24,
|
|
|
603 |
MAD_UNITS_25_FPS = 25,
|
|
|
604 |
MAD_UNITS_30_FPS = 30,
|
|
|
605 |
MAD_UNITS_48_FPS = 48,
|
|
|
606 |
MAD_UNITS_50_FPS = 50,
|
|
|
607 |
MAD_UNITS_60_FPS = 60,
|
|
|
608 |
|
|
|
609 |
/* CD audio frames */
|
|
|
610 |
|
|
|
611 |
MAD_UNITS_75_FPS = 75,
|
|
|
612 |
|
|
|
613 |
/* video drop-frame units */
|
|
|
614 |
|
|
|
615 |
MAD_UNITS_23_976_FPS = -24,
|
|
|
616 |
MAD_UNITS_24_975_FPS = -25,
|
|
|
617 |
MAD_UNITS_29_97_FPS = -30,
|
|
|
618 |
MAD_UNITS_47_952_FPS = -48,
|
|
|
619 |
MAD_UNITS_49_95_FPS = -50,
|
|
|
620 |
MAD_UNITS_59_94_FPS = -60
|
|
|
621 |
};
|
|
|
622 |
|
|
|
623 |
# define mad_timer_reset(timer) ((void) (*(timer) = mad_timer_zero))
|
|
|
624 |
|
|
|
625 |
int mad_timer_compare(mad_timer_t, mad_timer_t);
|
|
|
626 |
|
|
|
627 |
# define mad_timer_sign(timer) mad_timer_compare((timer), mad_timer_zero)
|
|
|
628 |
|
|
|
629 |
void mad_timer_negate(mad_timer_t *);
|
|
|
630 |
mad_timer_t mad_timer_abs(mad_timer_t);
|
|
|
631 |
|
|
|
632 |
void mad_timer_set(mad_timer_t *, unsigned long, unsigned long, unsigned long);
|
|
|
633 |
void mad_timer_add(mad_timer_t *, mad_timer_t);
|
|
|
634 |
void mad_timer_multiply(mad_timer_t *, signed long);
|
|
|
635 |
|
|
|
636 |
signed long mad_timer_count(mad_timer_t, enum mad_units);
|
|
|
637 |
unsigned long mad_timer_fraction(mad_timer_t, unsigned long);
|
|
|
638 |
void mad_timer_string(mad_timer_t, char *, char const *,
|
|
|
639 |
enum mad_units, enum mad_units, unsigned long);
|
|
|
640 |
|
|
|
641 |
# endif
|
|
|
642 |
|
|
|
643 |
/* Id: stream.h,v 1.20 2004/02/05 09:02:39 rob Exp */
|
|
|
644 |
|
|
|
645 |
# ifndef LIBMAD_STREAM_H
|
|
|
646 |
# define LIBMAD_STREAM_H
|
|
|
647 |
|
|
|
648 |
|
|
|
649 |
# define MAD_BUFFER_GUARD 8
|
|
|
650 |
# define MAD_BUFFER_MDLEN (511 + 2048 + MAD_BUFFER_GUARD)
|
|
|
651 |
|
|
|
652 |
enum mad_error {
|
|
|
653 |
MAD_ERROR_NONE = 0x0000, /* no error */
|
|
|
654 |
|
|
|
655 |
MAD_ERROR_BUFLEN = 0x0001, /* input buffer too small (or EOF) */
|
|
|
656 |
MAD_ERROR_BUFPTR = 0x0002, /* invalid (null) buffer pointer */
|
|
|
657 |
|
|
|
658 |
MAD_ERROR_NOMEM = 0x0031, /* not enough memory */
|
|
|
659 |
|
|
|
660 |
MAD_ERROR_LOSTSYNC = 0x0101, /* lost synchronization */
|
|
|
661 |
MAD_ERROR_BADLAYER = 0x0102, /* reserved header layer value */
|
|
|
662 |
MAD_ERROR_BADBITRATE = 0x0103, /* forbidden bitrate value */
|
|
|
663 |
MAD_ERROR_BADSAMPLERATE = 0x0104, /* reserved sample frequency value */
|
|
|
664 |
MAD_ERROR_BADEMPHASIS = 0x0105, /* reserved emphasis value */
|
|
|
665 |
|
|
|
666 |
MAD_ERROR_BADCRC = 0x0201, /* CRC check failed */
|
|
|
667 |
MAD_ERROR_BADBITALLOC = 0x0211, /* forbidden bit allocation value */
|
|
|
668 |
MAD_ERROR_BADSCALEFACTOR = 0x0221, /* bad scalefactor index */
|
|
|
669 |
MAD_ERROR_BADMODE = 0x0222, /* bad bitrate/mode combination */
|
|
|
670 |
MAD_ERROR_BADFRAMELEN = 0x0231, /* bad frame length */
|
|
|
671 |
MAD_ERROR_BADBIGVALUES = 0x0232, /* bad big_values count */
|
|
|
672 |
MAD_ERROR_BADBLOCKTYPE = 0x0233, /* reserved block_type */
|
|
|
673 |
MAD_ERROR_BADSCFSI = 0x0234, /* bad scalefactor selection info */
|
|
|
674 |
MAD_ERROR_BADDATAPTR = 0x0235, /* bad main_data_begin pointer */
|
|
|
675 |
MAD_ERROR_BADPART3LEN = 0x0236, /* bad audio data length */
|
|
|
676 |
MAD_ERROR_BADHUFFTABLE = 0x0237, /* bad Huffman table select */
|
|
|
677 |
MAD_ERROR_BADHUFFDATA = 0x0238, /* Huffman data overrun */
|
|
|
678 |
MAD_ERROR_BADSTEREO = 0x0239 /* incompatible block_type for JS */
|
|
|
679 |
};
|
|
|
680 |
|
|
|
681 |
# define MAD_RECOVERABLE(error) ((error) & 0xff00)
|
|
|
682 |
|
|
|
683 |
struct mad_stream {
|
|
|
684 |
unsigned char const *buffer; /* input bitstream buffer */
|
|
|
685 |
unsigned char const *bufend; /* end of buffer */
|
|
|
686 |
unsigned long skiplen; /* bytes to skip before next frame */
|
|
|
687 |
|
|
|
688 |
int sync; /* stream sync found */
|
|
|
689 |
unsigned long freerate; /* free bitrate (fixed) */
|
|
|
690 |
|
|
|
691 |
unsigned char const *this_frame; /* start of current frame */
|
|
|
692 |
unsigned char const *next_frame; /* start of next frame */
|
|
|
693 |
struct mad_bitptr ptr; /* current processing bit pointer */
|
|
|
694 |
|
|
|
695 |
struct mad_bitptr anc_ptr; /* ancillary bits pointer */
|
|
|
696 |
unsigned int anc_bitlen; /* number of ancillary bits */
|
|
|
697 |
|
|
|
698 |
unsigned char (*main_data)[MAD_BUFFER_MDLEN];
|
|
|
699 |
/* Layer III main_data() */
|
|
|
700 |
unsigned int md_len; /* bytes in main_data */
|
|
|
701 |
|
|
|
702 |
int options; /* decoding options (see below) */
|
|
|
703 |
enum mad_error error; /* error code (see above) */
|
|
|
704 |
};
|
|
|
705 |
|
|
|
706 |
enum {
|
|
|
707 |
MAD_OPTION_IGNORECRC = 0x0001, /* ignore CRC errors */
|
|
|
708 |
MAD_OPTION_HALFSAMPLERATE = 0x0002 /* generate PCM at 1/2 sample rate */
|
|
|
709 |
# if 0 /* not yet implemented */
|
|
|
710 |
MAD_OPTION_LEFTCHANNEL = 0x0010, /* decode left channel only */
|
|
|
711 |
MAD_OPTION_RIGHTCHANNEL = 0x0020, /* decode right channel only */
|
|
|
712 |
MAD_OPTION_SINGLECHANNEL = 0x0030 /* combine channels */
|
|
|
713 |
# endif
|
|
|
714 |
};
|
|
|
715 |
|
|
|
716 |
void mad_stream_init(struct mad_stream *);
|
|
|
717 |
void mad_stream_finish(struct mad_stream *);
|
|
|
718 |
|
|
|
719 |
# define mad_stream_options(stream, opts) \
|
|
|
720 |
((void) ((stream)->options = (opts)))
|
|
|
721 |
|
|
|
722 |
void mad_stream_buffer(struct mad_stream *,
|
|
|
723 |
unsigned char const *, unsigned long);
|
|
|
724 |
void mad_stream_skip(struct mad_stream *, unsigned long);
|
|
|
725 |
|
|
|
726 |
int mad_stream_sync(struct mad_stream *);
|
|
|
727 |
|
|
|
728 |
char const *mad_stream_errorstr(struct mad_stream const *);
|
|
|
729 |
|
|
|
730 |
# endif
|
|
|
731 |
|
|
|
732 |
/* Id: frame.h,v 1.20 2004/01/23 09:41:32 rob Exp */
|
|
|
733 |
|
|
|
734 |
# ifndef LIBMAD_FRAME_H
|
|
|
735 |
# define LIBMAD_FRAME_H
|
|
|
736 |
|
|
|
737 |
|
|
|
738 |
enum mad_layer {
|
|
|
739 |
MAD_LAYER_I = 1, /* Layer I */
|
|
|
740 |
MAD_LAYER_II = 2, /* Layer II */
|
|
|
741 |
MAD_LAYER_III = 3 /* Layer III */
|
|
|
742 |
};
|
|
|
743 |
|
|
|
744 |
enum mad_mode {
|
|
|
745 |
MAD_MODE_SINGLE_CHANNEL = 0, /* single channel */
|
|
|
746 |
MAD_MODE_DUAL_CHANNEL = 1, /* dual channel */
|
|
|
747 |
MAD_MODE_JOINT_STEREO = 2, /* joint (MS/intensity) stereo */
|
|
|
748 |
MAD_MODE_STEREO = 3 /* normal LR stereo */
|
|
|
749 |
};
|
|
|
750 |
|
|
|
751 |
enum mad_emphasis {
|
|
|
752 |
MAD_EMPHASIS_NONE = 0, /* no emphasis */
|
|
|
753 |
MAD_EMPHASIS_50_15_US = 1, /* 50/15 microseconds emphasis */
|
|
|
754 |
MAD_EMPHASIS_CCITT_J_17 = 3, /* CCITT J.17 emphasis */
|
|
|
755 |
MAD_EMPHASIS_RESERVED = 2 /* unknown emphasis */
|
|
|
756 |
};
|
|
|
757 |
|
|
|
758 |
struct mad_header {
|
|
|
759 |
enum mad_layer layer; /* audio layer (1, 2, or 3) */
|
|
|
760 |
enum mad_mode mode; /* channel mode (see above) */
|
|
|
761 |
int mode_extension; /* additional mode info */
|
|
|
762 |
enum mad_emphasis emphasis; /* de-emphasis to use (see above) */
|
|
|
763 |
|
|
|
764 |
unsigned long bitrate; /* stream bitrate (bps) */
|
|
|
765 |
unsigned int samplerate; /* sampling frequency (Hz) */
|
|
|
766 |
|
|
|
767 |
unsigned short crc_check; /* frame CRC accumulator */
|
|
|
768 |
unsigned short crc_target; /* final target CRC checksum */
|
|
|
769 |
|
|
|
770 |
int flags; /* flags (see below) */
|
|
|
771 |
int private_bits; /* private bits (see below) */
|
|
|
772 |
|
|
|
773 |
mad_timer_t duration; /* audio playing time of frame */
|
|
|
774 |
};
|
|
|
775 |
|
|
|
776 |
struct mad_frame {
|
|
|
777 |
struct mad_header header; /* MPEG audio header */
|
|
|
778 |
|
|
|
779 |
int options; /* decoding options (from stream) */
|
|
|
780 |
|
|
|
781 |
mad_fixed_t sbsample[2][36][32]; /* synthesis subband filter samples */
|
|
|
782 |
mad_fixed_t (*overlap)[2][32][18]; /* Layer III block overlap data */
|
|
|
783 |
};
|
|
|
784 |
|
|
|
785 |
# define MAD_NCHANNELS(header) ((header)->mode ? 2 : 1)
|
|
|
786 |
# define MAD_NSBSAMPLES(header) \
|
|
|
787 |
((header)->layer == MAD_LAYER_I ? 12 : \
|
|
|
788 |
(((header)->layer == MAD_LAYER_III && \
|
|
|
789 |
((header)->flags & MAD_FLAG_LSF_EXT)) ? 18 : 36))
|
|
|
790 |
|
|
|
791 |
enum {
|
|
|
792 |
MAD_FLAG_NPRIVATE_III = 0x0007, /* number of Layer III private bits */
|
|
|
793 |
MAD_FLAG_INCOMPLETE = 0x0008, /* header but not data is decoded */
|
|
|
794 |
|
|
|
795 |
MAD_FLAG_PROTECTION = 0x0010, /* frame has CRC protection */
|
|
|
796 |
MAD_FLAG_COPYRIGHT = 0x0020, /* frame is copyright */
|
|
|
797 |
MAD_FLAG_ORIGINAL = 0x0040, /* frame is original (else copy) */
|
|
|
798 |
MAD_FLAG_PADDING = 0x0080, /* frame has additional slot */
|
|
|
799 |
|
|
|
800 |
MAD_FLAG_I_STEREO = 0x0100, /* uses intensity joint stereo */
|
|
|
801 |
MAD_FLAG_MS_STEREO = 0x0200, /* uses middle/side joint stereo */
|
|
|
802 |
MAD_FLAG_FREEFORMAT = 0x0400, /* uses free format bitrate */
|
|
|
803 |
|
|
|
804 |
MAD_FLAG_LSF_EXT = 0x1000, /* lower sampling freq. extension */
|
|
|
805 |
MAD_FLAG_MC_EXT = 0x2000, /* multichannel audio extension */
|
|
|
806 |
MAD_FLAG_MPEG_2_5_EXT = 0x4000 /* MPEG 2.5 (unofficial) extension */
|
|
|
807 |
};
|
|
|
808 |
|
|
|
809 |
enum {
|
|
|
810 |
MAD_PRIVATE_HEADER = 0x0100, /* header private bit */
|
|
|
811 |
MAD_PRIVATE_III = 0x001f /* Layer III private bits (up to 5) */
|
|
|
812 |
};
|
|
|
813 |
|
|
|
814 |
void mad_header_init(struct mad_header *);
|
|
|
815 |
|
|
|
816 |
# define mad_header_finish(header) /* nothing */
|
|
|
817 |
|
|
|
818 |
int mad_header_decode(struct mad_header *, struct mad_stream *);
|
|
|
819 |
|
|
|
820 |
void mad_frame_init(struct mad_frame *);
|
|
|
821 |
void mad_frame_finish(struct mad_frame *);
|
|
|
822 |
|
|
|
823 |
int mad_frame_decode(struct mad_frame *, struct mad_stream *);
|
|
|
824 |
|
|
|
825 |
void mad_frame_mute(struct mad_frame *);
|
|
|
826 |
|
|
|
827 |
# endif
|
|
|
828 |
|
|
|
829 |
/* Id: synth.h,v 1.15 2004/01/23 09:41:33 rob Exp */
|
|
|
830 |
|
|
|
831 |
# ifndef LIBMAD_SYNTH_H
|
|
|
832 |
# define LIBMAD_SYNTH_H
|
|
|
833 |
|
|
|
834 |
|
|
|
835 |
struct mad_pcm {
|
|
|
836 |
unsigned int samplerate; /* sampling frequency (Hz) */
|
|
|
837 |
unsigned short channels; /* number of channels */
|
|
|
838 |
unsigned short length; /* number of samples per channel */
|
|
|
839 |
mad_fixed_t samples[2][1152]; /* PCM output samples [ch][sample] */
|
|
|
840 |
};
|
|
|
841 |
|
|
|
842 |
struct mad_synth {
|
|
|
843 |
mad_fixed_t filter[2][2][2][16][8]; /* polyphase filterbank outputs */
|
|
|
844 |
/* [ch][eo][peo][s][v] */
|
|
|
845 |
|
|
|
846 |
unsigned int phase; /* current processing phase */
|
|
|
847 |
|
|
|
848 |
struct mad_pcm pcm; /* PCM output */
|
|
|
849 |
};
|
|
|
850 |
|
|
|
851 |
/* single channel PCM selector */
|
|
|
852 |
enum {
|
|
|
853 |
MAD_PCM_CHANNEL_SINGLE = 0
|
|
|
854 |
};
|
|
|
855 |
|
|
|
856 |
/* dual channel PCM selector */
|
|
|
857 |
enum {
|
|
|
858 |
MAD_PCM_CHANNEL_DUAL_1 = 0,
|
|
|
859 |
MAD_PCM_CHANNEL_DUAL_2 = 1
|
|
|
860 |
};
|
|
|
861 |
|
|
|
862 |
/* stereo PCM selector */
|
|
|
863 |
enum {
|
|
|
864 |
MAD_PCM_CHANNEL_STEREO_LEFT = 0,
|
|
|
865 |
MAD_PCM_CHANNEL_STEREO_RIGHT = 1
|
|
|
866 |
};
|
|
|
867 |
|
|
|
868 |
void mad_synth_init(struct mad_synth *);
|
|
|
869 |
|
|
|
870 |
# define mad_synth_finish(synth) /* nothing */
|
|
|
871 |
|
|
|
872 |
void mad_synth_mute(struct mad_synth *);
|
|
|
873 |
|
|
|
874 |
void mad_synth_frame(struct mad_synth *, struct mad_frame const *);
|
|
|
875 |
|
|
|
876 |
# endif
|
|
|
877 |
|
|
|
878 |
/* Id: decoder.h,v 1.17 2004/01/23 09:41:32 rob Exp */
|
|
|
879 |
|
|
|
880 |
# ifndef LIBMAD_DECODER_H
|
|
|
881 |
# define LIBMAD_DECODER_H
|
|
|
882 |
|
|
|
883 |
|
|
|
884 |
enum mad_decoder_mode {
|
|
|
885 |
MAD_DECODER_MODE_SYNC = 0,
|
|
|
886 |
MAD_DECODER_MODE_ASYNC
|
|
|
887 |
};
|
|
|
888 |
|
|
|
889 |
enum mad_flow {
|
|
|
890 |
MAD_FLOW_CONTINUE = 0x0000, /* continue normally */
|
|
|
891 |
MAD_FLOW_STOP = 0x0010, /* stop decoding normally */
|
|
|
892 |
MAD_FLOW_BREAK = 0x0011, /* stop decoding and signal an error */
|
|
|
893 |
MAD_FLOW_IGNORE = 0x0020 /* ignore the current frame */
|
|
|
894 |
};
|
|
|
895 |
|
|
|
896 |
struct mad_decoder {
|
|
|
897 |
enum mad_decoder_mode mode;
|
|
|
898 |
|
|
|
899 |
int options;
|
|
|
900 |
|
|
|
901 |
struct {
|
|
|
902 |
long pid;
|
|
|
903 |
int in;
|
|
|
904 |
int out;
|
|
|
905 |
} async;
|
|
|
906 |
|
|
|
907 |
struct {
|
|
|
908 |
struct mad_stream stream;
|
|
|
909 |
struct mad_frame frame;
|
|
|
910 |
struct mad_synth synth;
|
|
|
911 |
} *sync;
|
|
|
912 |
|
|
|
913 |
void *cb_data;
|
|
|
914 |
|
|
|
915 |
enum mad_flow (*input_func)(void *, struct mad_stream *);
|
|
|
916 |
enum mad_flow (*header_func)(void *, struct mad_header const *);
|
|
|
917 |
enum mad_flow (*filter_func)(void *,
|
|
|
918 |
struct mad_stream const *, struct mad_frame *);
|
|
|
919 |
enum mad_flow (*output_func)(void *,
|
|
|
920 |
struct mad_header const *, struct mad_pcm *);
|
|
|
921 |
enum mad_flow (*error_func)(void *, struct mad_stream *, struct mad_frame *);
|
|
|
922 |
enum mad_flow (*message_func)(void *, void *, unsigned int *);
|
|
|
923 |
};
|
|
|
924 |
|
|
|
925 |
void mad_decoder_init(struct mad_decoder *, void *,
|
|
|
926 |
enum mad_flow (*)(void *, struct mad_stream *),
|
|
|
927 |
enum mad_flow (*)(void *, struct mad_header const *),
|
|
|
928 |
enum mad_flow (*)(void *,
|
|
|
929 |
struct mad_stream const *,
|
|
|
930 |
struct mad_frame *),
|
|
|
931 |
enum mad_flow (*)(void *,
|
|
|
932 |
struct mad_header const *,
|
|
|
933 |
struct mad_pcm *),
|
|
|
934 |
enum mad_flow (*)(void *,
|
|
|
935 |
struct mad_stream *,
|
|
|
936 |
struct mad_frame *),
|
|
|
937 |
enum mad_flow (*)(void *, void *, unsigned int *));
|
|
|
938 |
int mad_decoder_finish(struct mad_decoder *);
|
|
|
939 |
|
|
|
940 |
# define mad_decoder_options(decoder, opts) \
|
|
|
941 |
((void) ((decoder)->options = (opts)))
|
|
|
942 |
|
|
|
943 |
int mad_decoder_run(struct mad_decoder *, enum mad_decoder_mode);
|
|
|
944 |
int mad_decoder_message(struct mad_decoder *, void *, unsigned int *);
|
|
|
945 |
|
|
|
946 |
# endif
|
|
|
947 |
|
|
|
948 |
# ifdef __cplusplus
|
|
|
949 |
}
|
|
|
950 |
# endif
|