annotate osx/include/mad.h @ 169:223a55898ab9 tip default

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