annotate win32-mingw/include/mad.h @ 5:e582a1ccd5fe

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