annotate win64-msvc/include/mad.h @ 74:2f2b27544483

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