2005-02-16 11:02:11 +00:00
|
|
|
/*
|
|
|
|
* a52_internal.h
|
|
|
|
* Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
|
|
|
|
* Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
|
|
|
|
*
|
|
|
|
* This file is part of a52dec, a free ATSC A-52 stream decoder.
|
|
|
|
* See http://liba52.sourceforge.net/ for updates.
|
|
|
|
*
|
|
|
|
* a52dec is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* a52dec is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct {
|
2010-02-22 19:44:05 +00:00
|
|
|
uint8_t bai; /* fine SNR offset, fast gain */
|
|
|
|
uint8_t deltbae; /* delta bit allocation exists */
|
|
|
|
int8_t deltba[50]; /* per-band delta bit allocation */
|
2005-02-16 11:02:11 +00:00
|
|
|
} ba_t;
|
|
|
|
|
|
|
|
typedef struct {
|
2010-02-22 19:44:05 +00:00
|
|
|
uint8_t exp[256]; /* decoded channel exponents */
|
|
|
|
int8_t bap[256]; /* derived channel bit allocation */
|
2005-02-16 11:02:11 +00:00
|
|
|
} expbap_t;
|
|
|
|
|
|
|
|
struct a52_state_s {
|
2010-02-22 19:44:05 +00:00
|
|
|
uint8_t fscod; /* sample rate */
|
|
|
|
uint8_t halfrate; /* halfrate factor */
|
|
|
|
uint8_t acmod; /* coded channels */
|
|
|
|
uint8_t lfeon; /* coded lfe channel */
|
|
|
|
level_t clev; /* centre channel mix level */
|
|
|
|
level_t slev; /* surround channels mix level */
|
|
|
|
|
|
|
|
int output; /* type of output */
|
|
|
|
level_t level; /* output level */
|
|
|
|
sample_t bias; /* output bias */
|
|
|
|
|
|
|
|
int dynrnge; /* apply dynamic range */
|
|
|
|
level_t dynrng; /* dynamic range */
|
|
|
|
void * dynrngdata; /* dynamic range callback funtion and data */
|
2005-02-16 11:02:11 +00:00
|
|
|
level_t (* dynrngcall) (level_t range, void * dynrngdata);
|
|
|
|
|
2010-02-22 19:44:05 +00:00
|
|
|
uint8_t chincpl; /* channel coupled */
|
|
|
|
uint8_t phsflginu; /* phase flags in use (stereo only) */
|
|
|
|
uint8_t cplstrtmant; /* coupling channel start mantissa */
|
|
|
|
uint8_t cplendmant; /* coupling channel end mantissa */
|
|
|
|
uint32_t cplbndstrc; /* coupling band structure */
|
|
|
|
level_t cplco[5][18]; /* coupling coordinates */
|
2005-02-16 11:02:11 +00:00
|
|
|
|
|
|
|
/* derived information */
|
2010-02-22 19:44:05 +00:00
|
|
|
uint8_t cplstrtbnd; /* coupling start band (for bit allocation) */
|
|
|
|
uint8_t ncplbnd; /* number of coupling bands */
|
2005-02-16 11:02:11 +00:00
|
|
|
|
2010-02-22 19:44:05 +00:00
|
|
|
uint8_t rematflg; /* stereo rematrixing */
|
2005-02-16 11:02:11 +00:00
|
|
|
|
2010-02-22 19:44:05 +00:00
|
|
|
uint8_t endmant[5]; /* channel end mantissa */
|
2005-02-16 11:02:11 +00:00
|
|
|
|
2010-02-22 19:44:05 +00:00
|
|
|
uint16_t bai; /* bit allocation information */
|
2005-02-16 11:02:11 +00:00
|
|
|
|
|
|
|
uint32_t * buffer_start;
|
2010-02-22 19:44:05 +00:00
|
|
|
uint16_t lfsr_state; /* dither state */
|
2005-02-16 11:02:11 +00:00
|
|
|
uint32_t bits_left;
|
|
|
|
uint32_t current_word;
|
|
|
|
|
2010-02-22 19:44:05 +00:00
|
|
|
uint8_t csnroffst; /* coarse SNR offset */
|
|
|
|
ba_t cplba; /* coupling bit allocation parameters */
|
|
|
|
ba_t ba[5]; /* channel bit allocation parameters */
|
|
|
|
ba_t lfeba; /* lfe bit allocation parameters */
|
2005-02-16 11:02:11 +00:00
|
|
|
|
2010-02-22 19:44:05 +00:00
|
|
|
uint8_t cplfleak; /* coupling fast leak init */
|
|
|
|
uint8_t cplsleak; /* coupling slow leak init */
|
2005-02-16 11:02:11 +00:00
|
|
|
|
|
|
|
expbap_t cpl_expbap;
|
|
|
|
expbap_t fbw_expbap[5];
|
|
|
|
expbap_t lfe_expbap;
|
|
|
|
|
|
|
|
sample_t * samples;
|
|
|
|
int downmixed;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define LEVEL_PLUS6DB 2.0
|
|
|
|
#define LEVEL_PLUS3DB 1.4142135623730951
|
|
|
|
#define LEVEL_3DB 0.7071067811865476
|
|
|
|
#define LEVEL_45DB 0.5946035575013605
|
|
|
|
#define LEVEL_6DB 0.5
|
|
|
|
|
|
|
|
#define EXP_REUSE (0)
|
|
|
|
#define EXP_D15 (1)
|
|
|
|
#define EXP_D25 (2)
|
|
|
|
#define EXP_D45 (3)
|
|
|
|
|
|
|
|
#define DELTA_BIT_REUSE (0)
|
|
|
|
#define DELTA_BIT_NEW (1)
|
|
|
|
#define DELTA_BIT_NONE (2)
|
|
|
|
#define DELTA_BIT_RESERVED (3)
|
|
|
|
|
|
|
|
void a52_bit_allocate (a52_state_t * state, ba_t * ba, int bndstart,
|
2010-02-22 19:44:05 +00:00
|
|
|
int start, int end, int fastleak, int slowleak,
|
|
|
|
expbap_t * expbap);
|
2005-02-16 11:02:11 +00:00
|
|
|
|
|
|
|
int a52_downmix_init (int input, int flags, level_t * level,
|
2010-02-22 19:44:05 +00:00
|
|
|
level_t clev, level_t slev);
|
2005-02-16 11:02:11 +00:00
|
|
|
int a52_downmix_coeff (level_t * coeff, int acmod, int output, level_t level,
|
2010-02-22 19:44:05 +00:00
|
|
|
level_t clev, level_t slev);
|
2010-02-17 00:49:53 +00:00
|
|
|
void a52_downmix (sample_t * samples, int acmod, int output,
|
2010-02-22 19:44:05 +00:00
|
|
|
level_t clev, level_t slev);
|
2005-02-16 11:02:11 +00:00
|
|
|
void a52_upmix (sample_t * samples, int acmod, int output);
|
|
|
|
|
|
|
|
void a52_imdct_init (uint32_t mm_accel);
|
2010-02-17 00:49:53 +00:00
|
|
|
void a52_imdct_256 (sample_t * data, sample_t * delay);
|
|
|
|
void a52_imdct_512 (sample_t * data, sample_t * delay);
|
2005-02-16 11:02:11 +00:00
|
|
|
|
|
|
|
#define ROUND(x) ((int)((x) + ((x) > 0 ? 0.5 : -0.5)))
|
|
|
|
|
|
|
|
#ifndef LIBA52_FIXED
|
|
|
|
|
|
|
|
typedef sample_t quantizer_t;
|
|
|
|
#define SAMPLE(x) (x)
|
|
|
|
#define LEVEL(x) (x)
|
|
|
|
#define MUL(a,b) ((a) * (b))
|
|
|
|
#define MUL_L(a,b) ((a) * (b))
|
|
|
|
#define MUL_C(a,b) ((a) * (b))
|
|
|
|
#define DIV(a,b) ((a) / (b))
|
|
|
|
#define BIAS(x) ((x) + bias)
|
|
|
|
|
|
|
|
#else /* LIBA52_FIXED */
|
|
|
|
|
|
|
|
typedef int16_t quantizer_t;
|
|
|
|
#define SAMPLE(x) (sample_t)((x) * (1 << 30))
|
|
|
|
#define LEVEL(x) (level_t)((x) * (1 << 26))
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#define MUL(a,b) ((int)(((int64_t)(a) * (b) + (1 << 29)) >> 30))
|
|
|
|
#define MUL_L(a,b) ((int)(((int64_t)(a) * (b) + (1 << 25)) >> 26))
|
2007-05-10 13:16:08 +00:00
|
|
|
#elif defined(CPU_COLDFIRE)
|
2005-06-11 14:45:48 +00:00
|
|
|
/* loses 1 bit of accuracy */
|
|
|
|
#define MUL(a, b) \
|
|
|
|
({ \
|
|
|
|
int32_t t; \
|
|
|
|
asm volatile ( \
|
|
|
|
"mac.l %[A], %[B], %%acc0\n\t" \
|
|
|
|
"movclr.l %%acc0, %[t]\n\t" \
|
|
|
|
"asl.l #1, %[t]" \
|
|
|
|
: [t] "=d" (t) \
|
|
|
|
: [A] "r" ((a)), [B] "r" ((b))); \
|
|
|
|
t; \
|
|
|
|
})
|
|
|
|
/* loses 5 bits of accuracy */
|
|
|
|
#define MUL_L(a, b) \
|
|
|
|
({ \
|
|
|
|
int32_t t; \
|
|
|
|
asm volatile ( \
|
|
|
|
"mac.l %[A], %[B], %%acc0\n\t" \
|
|
|
|
"movclr.l %%acc0, %[t]\n\t" \
|
|
|
|
"asl.l #5, %[t]" \
|
|
|
|
: [t] "=d" (t) \
|
|
|
|
: [A] "r" ((a)), [B] "r" ((b))); \
|
|
|
|
t; \
|
|
|
|
})
|
2008-09-23 00:51:22 +00:00
|
|
|
|
|
|
|
#elif defined(CPU_ARM)
|
|
|
|
#define MUL(x, y) \
|
|
|
|
({ int32_t __hi; \
|
|
|
|
uint32_t __lo; \
|
|
|
|
int32_t __result; \
|
|
|
|
asm ("smull %0, %1, %3, %4\n\t" \
|
|
|
|
"movs %2, %1, lsl #2" \
|
|
|
|
: "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
|
|
|
|
: "%r" (x), "r" (y) \
|
|
|
|
: "cc"); \
|
|
|
|
__result; \
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
#define MUL_L(x, y) \
|
|
|
|
({ int32_t __hi; \
|
|
|
|
uint32_t __lo; \
|
|
|
|
int32_t __result; \
|
|
|
|
asm ("smull %0, %1, %3, %4\n\t" \
|
|
|
|
"movs %0, %0, lsr %5\n\t" \
|
|
|
|
"adc %2, %0, %1, lsl %6" \
|
|
|
|
: "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
|
|
|
|
: "%r" (x), "r" (y), \
|
|
|
|
"M" (26), "M" (32 - 26) \
|
|
|
|
: "cc"); \
|
|
|
|
__result; \
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2005-02-16 11:02:11 +00:00
|
|
|
#elif 1
|
|
|
|
#define MUL(a,b) \
|
|
|
|
({ int32_t _ta=(a), _tb=(b), _tc; \
|
|
|
|
_tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)(((_tc >> 14))+ (((_ta >> 16)*(_tb >> 16)) << 2 )); })
|
|
|
|
#define MUL_L(a,b) \
|
|
|
|
({ int32_t _ta=(a), _tb=(b), _tc; \
|
|
|
|
_tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)((_tc >> 10) + (((_ta >> 16)*(_tb >> 16)) << 6)); })
|
|
|
|
#else
|
|
|
|
#define MUL(a,b) (((a) >> 15) * ((b) >> 15))
|
|
|
|
#define MUL_L(a,b) (((a) >> 13) * ((b) >> 13))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MUL_C(a,b) MUL_L (a, LEVEL (b))
|
|
|
|
#define DIV(a,b) ((((int64_t)LEVEL (a)) << 26) / (b))
|
2010-02-17 00:49:53 +00:00
|
|
|
#define BIAS(x) ((x))
|
2005-02-16 11:02:11 +00:00
|
|
|
|
|
|
|
#endif
|