annotate osx/include/mad.h @ 83:ae30d91d2ffe

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