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