mirror of
https://gitee.com/openharmony/third_party_ffmpeg
synced 2024-11-24 03:39:45 +00:00
* sync with main liba52 sources
Originally committed as revision 1590 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
ca390e727d
commit
c947dec982
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* a52.h
|
||||
* Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
|
||||
* 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.
|
||||
@ -30,10 +30,15 @@
|
||||
#undef free
|
||||
#undef realloc
|
||||
|
||||
#ifndef LIBA52_DOUBLE
|
||||
typedef float sample_t;
|
||||
#else
|
||||
#if defined(LIBA52_FIXED)
|
||||
typedef int32_t sample_t;
|
||||
typedef int32_t level_t;
|
||||
#elif defined(LIBA52_DOUBLE)
|
||||
typedef double sample_t;
|
||||
typedef double level_t;
|
||||
#else
|
||||
typedef float sample_t;
|
||||
typedef float level_t;
|
||||
#endif
|
||||
|
||||
typedef struct a52_state_s a52_state_t;
|
||||
@ -59,9 +64,9 @@ sample_t * a52_samples (a52_state_t * state);
|
||||
int a52_syncinfo (uint8_t * buf, int * flags,
|
||||
int * sample_rate, int * bit_rate);
|
||||
int a52_frame (a52_state_t * state, uint8_t * buf, int * flags,
|
||||
sample_t * level, sample_t bias);
|
||||
level_t * level, sample_t bias);
|
||||
void a52_dynrng (a52_state_t * state,
|
||||
sample_t (* call) (sample_t, void *), void * data);
|
||||
level_t (* call) (level_t, void *), void * data);
|
||||
int a52_block (a52_state_t * state);
|
||||
void a52_free (a52_state_t * state);
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* a52_internal.h
|
||||
* Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
|
||||
* 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.
|
||||
@ -37,24 +37,24 @@ struct a52_state_s {
|
||||
uint8_t halfrate; /* halfrate factor */
|
||||
uint8_t acmod; /* coded channels */
|
||||
uint8_t lfeon; /* coded lfe channel */
|
||||
sample_t clev; /* centre channel mix level */
|
||||
sample_t slev; /* surround channels mix level */
|
||||
level_t clev; /* centre channel mix level */
|
||||
level_t slev; /* surround channels mix level */
|
||||
|
||||
int output; /* type of output */
|
||||
sample_t level; /* output level */
|
||||
level_t level; /* output level */
|
||||
sample_t bias; /* output bias */
|
||||
|
||||
int dynrnge; /* apply dynamic range */
|
||||
sample_t dynrng; /* dynamic range */
|
||||
level_t dynrng; /* dynamic range */
|
||||
void * dynrngdata; /* dynamic range callback funtion and data */
|
||||
sample_t (* dynrngcall) (sample_t range, void * dynrngdata);
|
||||
level_t (* dynrngcall) (level_t range, void * dynrngdata);
|
||||
|
||||
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 */
|
||||
sample_t cplco[5][18]; /* coupling coordinates */
|
||||
level_t cplco[5][18]; /* coupling coordinates */
|
||||
|
||||
/* derived information */
|
||||
uint8_t cplstrtbnd; /* coupling start band (for bit allocation) */
|
||||
@ -66,6 +66,11 @@ struct a52_state_s {
|
||||
|
||||
uint16_t bai; /* bit allocation information */
|
||||
|
||||
uint32_t * buffer_start;
|
||||
uint16_t lfsr_state; /* dither state */
|
||||
uint32_t bits_left;
|
||||
uint32_t current_word;
|
||||
|
||||
uint8_t csnroffst; /* coarse SNR offset */
|
||||
ba_t cplba; /* coupling bit allocation parameters */
|
||||
ba_t ba[5]; /* channel bit allocation parameters */
|
||||
@ -102,14 +107,54 @@ void a52_bit_allocate (a52_state_t * state, ba_t * ba, int bndstart,
|
||||
int start, int end, int fastleak, int slowleak,
|
||||
expbap_t * expbap);
|
||||
|
||||
int a52_downmix_init (int input, int flags, sample_t * level,
|
||||
sample_t clev, sample_t slev);
|
||||
int a52_downmix_coeff (sample_t * coeff, int acmod, int output, sample_t level,
|
||||
sample_t clev, sample_t slev);
|
||||
int a52_downmix_init (int input, int flags, level_t * level,
|
||||
level_t clev, level_t slev);
|
||||
int a52_downmix_coeff (level_t * coeff, int acmod, int output, level_t level,
|
||||
level_t clev, level_t slev);
|
||||
void a52_downmix (sample_t * samples, int acmod, int output, sample_t bias,
|
||||
sample_t clev, sample_t slev);
|
||||
level_t clev, level_t slev);
|
||||
void a52_upmix (sample_t * samples, int acmod, int output);
|
||||
|
||||
void a52_imdct_init (uint32_t mm_accel);
|
||||
void a52_imdct_256 (sample_t * data, sample_t * delay, sample_t bias);
|
||||
void a52_imdct_512 (sample_t * data, sample_t * delay, sample_t bias);
|
||||
|
||||
#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))
|
||||
#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))
|
||||
#define BIAS(x) (x)
|
||||
|
||||
#endif
|
||||
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* audio_out.h
|
||||
* Copyright (C) 2000-2002 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 ao_instance_s ao_instance_t;
|
||||
|
||||
struct ao_instance_s {
|
||||
int (* setup) (ao_instance_t * instance, int sample_rate, int * flags,
|
||||
sample_t * level, sample_t * bias);
|
||||
int (* play) (ao_instance_t * instance, int flags, sample_t * samples);
|
||||
void (* close) (ao_instance_t * instance);
|
||||
};
|
||||
|
||||
typedef ao_instance_t * ao_open_t (void);
|
||||
|
||||
typedef struct ao_driver_s {
|
||||
char * name;
|
||||
ao_open_t * open;
|
||||
} ao_driver_t;
|
||||
|
||||
/* return NULL terminated array of all drivers */
|
||||
ao_driver_t * ao_drivers (void);
|
||||
|
||||
static inline ao_instance_t * ao_open (ao_open_t * open)
|
||||
{
|
||||
return open ();
|
||||
}
|
||||
|
||||
static inline int ao_setup (ao_instance_t * instance, int sample_rate,
|
||||
int * flags, sample_t * level, sample_t * bias)
|
||||
{
|
||||
return instance->setup (instance, sample_rate, flags, level, bias);
|
||||
}
|
||||
|
||||
static inline int ao_play (ao_instance_t * instance, int flags,
|
||||
sample_t * samples)
|
||||
{
|
||||
return instance->play (instance, flags, samples);
|
||||
}
|
||||
|
||||
static inline void ao_close (ao_instance_t * instance)
|
||||
{
|
||||
if (instance->close)
|
||||
instance->close (instance);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* bit_allocate.c
|
||||
* Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
|
||||
* 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.
|
||||
@ -20,6 +20,11 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "a52.h"
|
||||
#include "a52_internal.h"
|
||||
|
||||
@ -226,7 +231,7 @@ void a52_bit_allocate (a52_state_t * state, ba_t * ba, int bndstart,
|
||||
int startband, endband;
|
||||
|
||||
startband = j;
|
||||
endband = ((bndtab-20)[i] < end) ? (bndtab-20)[i] : end;
|
||||
endband = (bndtab[i-20] < end) ? bndtab[i-20] : end;
|
||||
psd = 128 * exp[j++];
|
||||
while (j < endband) {
|
||||
int next, delta;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* bitstream.c
|
||||
* Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
|
||||
* 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.
|
||||
@ -21,34 +21,33 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "a52.h"
|
||||
#include "a52_internal.h"
|
||||
#include "bitstream.h"
|
||||
|
||||
#define BUFFER_SIZE 4096
|
||||
|
||||
static uint32_t * buffer_start;
|
||||
|
||||
uint32_t a52_bits_left;
|
||||
uint32_t a52_current_word;
|
||||
|
||||
void a52_bitstream_set_ptr (uint8_t * buf)
|
||||
void a52_bitstream_set_ptr (a52_state_t * state, uint8_t * buf)
|
||||
{
|
||||
int align;
|
||||
|
||||
align = (long)buf & 3;
|
||||
buffer_start = (uint32_t *) (buf - align);
|
||||
a52_bits_left = 0;
|
||||
bitstream_get (align * 8);
|
||||
state->buffer_start = (uint32_t *) (buf - align);
|
||||
state->bits_left = 0;
|
||||
state->current_word = 0;
|
||||
bitstream_get (state, align * 8);
|
||||
}
|
||||
|
||||
static inline void
|
||||
bitstream_fill_current()
|
||||
static inline void bitstream_fill_current (a52_state_t * state)
|
||||
{
|
||||
uint32_t tmp;
|
||||
|
||||
tmp = *(buffer_start++);
|
||||
a52_current_word = swab32 (tmp);
|
||||
tmp = *(state->buffer_start++);
|
||||
state->current_word = swab32 (tmp);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -60,40 +59,38 @@ bitstream_fill_current()
|
||||
* -ah
|
||||
*/
|
||||
|
||||
uint32_t
|
||||
a52_bitstream_get_bh(uint32_t num_bits)
|
||||
uint32_t a52_bitstream_get_bh (a52_state_t * state, uint32_t num_bits)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
num_bits -= a52_bits_left;
|
||||
result = ((a52_current_word << (32 - a52_bits_left)) >>
|
||||
(32 - a52_bits_left));
|
||||
num_bits -= state->bits_left;
|
||||
result = ((state->current_word << (32 - state->bits_left)) >>
|
||||
(32 - state->bits_left));
|
||||
|
||||
bitstream_fill_current();
|
||||
bitstream_fill_current (state);
|
||||
|
||||
if(num_bits != 0)
|
||||
result = (result << num_bits) | (a52_current_word >> (32 - num_bits));
|
||||
if (num_bits != 0)
|
||||
result = (result << num_bits) | (state->current_word >> (32 - num_bits));
|
||||
|
||||
a52_bits_left = 32 - num_bits;
|
||||
state->bits_left = 32 - num_bits;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t
|
||||
a52_bitstream_get_bh_2(uint32_t num_bits)
|
||||
int32_t a52_bitstream_get_bh_2 (a52_state_t * state, uint32_t num_bits)
|
||||
{
|
||||
int32_t result;
|
||||
|
||||
num_bits -= a52_bits_left;
|
||||
result = ((((int32_t)a52_current_word) << (32 - a52_bits_left)) >>
|
||||
(32 - a52_bits_left));
|
||||
num_bits -= state->bits_left;
|
||||
result = ((((int32_t)state->current_word) << (32 - state->bits_left)) >>
|
||||
(32 - state->bits_left));
|
||||
|
||||
bitstream_fill_current();
|
||||
bitstream_fill_current(state);
|
||||
|
||||
if(num_bits != 0)
|
||||
result = (result << num_bits) | (a52_current_word >> (32 - num_bits));
|
||||
if (num_bits != 0)
|
||||
result = (result << num_bits) | (state->current_word >> (32 - num_bits));
|
||||
|
||||
a52_bits_left = 32 - num_bits;
|
||||
state->bits_left = 32 - num_bits;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* bitstream.h
|
||||
* Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
|
||||
* 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.
|
||||
@ -46,37 +46,32 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
extern uint32_t a52_bits_left;
|
||||
extern uint32_t a52_current_word;
|
||||
void a52_bitstream_set_ptr (a52_state_t * state, uint8_t * buf);
|
||||
uint32_t a52_bitstream_get_bh (a52_state_t * state, uint32_t num_bits);
|
||||
int32_t a52_bitstream_get_bh_2 (a52_state_t * state, uint32_t num_bits);
|
||||
|
||||
void a52_bitstream_set_ptr (uint8_t * buf);
|
||||
uint32_t a52_bitstream_get_bh(uint32_t num_bits);
|
||||
int32_t a52_bitstream_get_bh_2(uint32_t num_bits);
|
||||
|
||||
static inline uint32_t
|
||||
bitstream_get(uint32_t num_bits)
|
||||
static inline uint32_t bitstream_get (a52_state_t * state, uint32_t num_bits)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
if(num_bits < a52_bits_left) {
|
||||
result = (a52_current_word << (32 - a52_bits_left)) >> (32 - num_bits);
|
||||
a52_bits_left -= num_bits;
|
||||
if (num_bits < state->bits_left) {
|
||||
result = (state->current_word << (32 - state->bits_left)) >> (32 - num_bits);
|
||||
state->bits_left -= num_bits;
|
||||
return result;
|
||||
}
|
||||
|
||||
return a52_bitstream_get_bh(num_bits);
|
||||
return a52_bitstream_get_bh (state, num_bits);
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
bitstream_get_2(uint32_t num_bits)
|
||||
static inline int32_t bitstream_get_2 (a52_state_t * state, uint32_t num_bits)
|
||||
{
|
||||
int32_t result;
|
||||
|
||||
if(num_bits < a52_bits_left) {
|
||||
result = (((int32_t)a52_current_word) << (32 - a52_bits_left)) >> (32 - num_bits);
|
||||
a52_bits_left -= num_bits;
|
||||
if (num_bits < state->bits_left) {
|
||||
result = (((int32_t)state->current_word) << (32 - state->bits_left)) >> (32 - num_bits);
|
||||
state->bits_left -= num_bits;
|
||||
return result;
|
||||
}
|
||||
|
||||
return a52_bitstream_get_bh_2(num_bits);
|
||||
return a52_bitstream_get_bh_2 (state, num_bits);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* downmix.c
|
||||
* Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
|
||||
* 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.
|
||||
@ -21,13 +21,18 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "a52.h"
|
||||
#include "a52_internal.h"
|
||||
|
||||
#define CONVERT(acmod,output) (((output) << 3) + (acmod))
|
||||
|
||||
int a52_downmix_init (int input, int flags, sample_t * level,
|
||||
sample_t clev, sample_t slev)
|
||||
int a52_downmix_init (int input, int flags, level_t * level,
|
||||
level_t clev, level_t slev)
|
||||
{
|
||||
static uint8_t table[11][8] = {
|
||||
{A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
|
||||
@ -61,94 +66,106 @@ int a52_downmix_init (int input, int flags, sample_t * level,
|
||||
|
||||
output = table[output][input & 7];
|
||||
|
||||
if ((output == A52_STEREO) &&
|
||||
((input == A52_DOLBY) || ((input == A52_3F) && (clev == LEVEL_3DB))))
|
||||
if (output == A52_STEREO &&
|
||||
(input == A52_DOLBY || (input == A52_3F && clev == LEVEL (LEVEL_3DB))))
|
||||
output = A52_DOLBY;
|
||||
|
||||
if (flags & A52_ADJUST_LEVEL)
|
||||
if (flags & A52_ADJUST_LEVEL) {
|
||||
level_t adjust;
|
||||
|
||||
switch (CONVERT (input & 7, output)) {
|
||||
|
||||
case CONVERT (A52_3F, A52_MONO):
|
||||
*level *= LEVEL_3DB / (1 + clev);
|
||||
adjust = DIV (LEVEL_3DB, LEVEL (1) + clev);
|
||||
break;
|
||||
|
||||
case CONVERT (A52_STEREO, A52_MONO):
|
||||
case CONVERT (A52_2F2R, A52_2F1R):
|
||||
case CONVERT (A52_3F2R, A52_3F1R):
|
||||
level_3db:
|
||||
*level *= LEVEL_3DB;
|
||||
adjust = LEVEL (LEVEL_3DB);
|
||||
break;
|
||||
|
||||
case CONVERT (A52_3F2R, A52_2F1R):
|
||||
if (clev < LEVEL_PLUS3DB - 1)
|
||||
if (clev < LEVEL (LEVEL_PLUS3DB - 1))
|
||||
goto level_3db;
|
||||
/* break thru */
|
||||
case CONVERT (A52_3F, A52_STEREO):
|
||||
case CONVERT (A52_3F1R, A52_2F1R):
|
||||
case CONVERT (A52_3F1R, A52_2F2R):
|
||||
case CONVERT (A52_3F2R, A52_2F2R):
|
||||
*level /= 1 + clev;
|
||||
adjust = DIV (1, LEVEL (1) + clev);
|
||||
break;
|
||||
|
||||
case CONVERT (A52_2F1R, A52_MONO):
|
||||
*level *= LEVEL_PLUS3DB / (2 + slev);
|
||||
adjust = DIV (LEVEL_PLUS3DB, LEVEL (2) + slev);
|
||||
break;
|
||||
|
||||
case CONVERT (A52_2F1R, A52_STEREO):
|
||||
case CONVERT (A52_3F1R, A52_3F):
|
||||
*level /= 1 + slev * LEVEL_3DB;
|
||||
adjust = DIV (1, LEVEL (1) + MUL_C (slev, LEVEL_3DB));
|
||||
break;
|
||||
|
||||
case CONVERT (A52_3F1R, A52_MONO):
|
||||
*level *= LEVEL_3DB / (1 + clev + 0.5 * slev);
|
||||
adjust = DIV (LEVEL_3DB, LEVEL (1) + clev + MUL_C (slev, 0.5));
|
||||
break;
|
||||
|
||||
case CONVERT (A52_3F1R, A52_STEREO):
|
||||
*level /= 1 + clev + slev * LEVEL_3DB;
|
||||
adjust = DIV (1, LEVEL (1) + clev + MUL_C (slev, LEVEL_3DB));
|
||||
break;
|
||||
|
||||
case CONVERT (A52_2F2R, A52_MONO):
|
||||
*level *= LEVEL_3DB / (1 + slev);
|
||||
adjust = DIV (LEVEL_3DB, LEVEL (1) + slev);
|
||||
break;
|
||||
|
||||
case CONVERT (A52_2F2R, A52_STEREO):
|
||||
case CONVERT (A52_3F2R, A52_3F):
|
||||
*level /= 1 + slev;
|
||||
adjust = DIV (1, LEVEL (1) + slev);
|
||||
break;
|
||||
|
||||
case CONVERT (A52_3F2R, A52_MONO):
|
||||
*level *= LEVEL_3DB / (1 + clev + slev);
|
||||
adjust = DIV (LEVEL_3DB, LEVEL (1) + clev + slev);
|
||||
break;
|
||||
|
||||
case CONVERT (A52_3F2R, A52_STEREO):
|
||||
*level /= 1 + clev + slev;
|
||||
adjust = DIV (1, LEVEL (1) + clev + slev);
|
||||
break;
|
||||
|
||||
case CONVERT (A52_MONO, A52_DOLBY):
|
||||
*level *= LEVEL_PLUS3DB;
|
||||
adjust = LEVEL (LEVEL_PLUS3DB);
|
||||
break;
|
||||
|
||||
case CONVERT (A52_3F, A52_DOLBY):
|
||||
case CONVERT (A52_2F1R, A52_DOLBY):
|
||||
*level *= 1 / (1 + LEVEL_3DB);
|
||||
adjust = LEVEL (1 / (1 + LEVEL_3DB));
|
||||
break;
|
||||
|
||||
case CONVERT (A52_3F1R, A52_DOLBY):
|
||||
case CONVERT (A52_2F2R, A52_DOLBY):
|
||||
*level *= 1 / (1 + 2 * LEVEL_3DB);
|
||||
adjust = LEVEL (1 / (1 + 2 * LEVEL_3DB));
|
||||
break;
|
||||
|
||||
case CONVERT (A52_3F2R, A52_DOLBY):
|
||||
*level *= 1 / (1 + 3 * LEVEL_3DB);
|
||||
adjust = LEVEL (1 / (1 + 3 * LEVEL_3DB));
|
||||
break;
|
||||
|
||||
default:
|
||||
return output;
|
||||
}
|
||||
|
||||
*level = MUL_L (*level, adjust);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
int a52_downmix_coeff (sample_t * coeff, int acmod, int output, sample_t level,
|
||||
sample_t clev, sample_t slev)
|
||||
int a52_downmix_coeff (level_t * coeff, int acmod, int output, level_t level,
|
||||
level_t clev, level_t slev)
|
||||
{
|
||||
level_t level_3db;
|
||||
|
||||
level_3db = MUL_C (level, LEVEL_3DB);
|
||||
|
||||
switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
|
||||
|
||||
case CONVERT (A52_CHANNEL, A52_CHANNEL):
|
||||
@ -164,120 +181,138 @@ int a52_downmix_coeff (sample_t * coeff, int acmod, int output, sample_t level,
|
||||
return 0;
|
||||
|
||||
case CONVERT (A52_CHANNEL, A52_MONO):
|
||||
coeff[0] = coeff[1] = level * LEVEL_6DB;
|
||||
coeff[0] = coeff[1] = MUL_C (level, LEVEL_6DB);
|
||||
return 3;
|
||||
|
||||
case CONVERT (A52_STEREO, A52_MONO):
|
||||
coeff[0] = coeff[1] = level * LEVEL_3DB;
|
||||
coeff[0] = coeff[1] = level_3db;
|
||||
return 3;
|
||||
|
||||
case CONVERT (A52_3F, A52_MONO):
|
||||
coeff[0] = coeff[2] = level * LEVEL_3DB;
|
||||
coeff[1] = level * clev * LEVEL_PLUS3DB;
|
||||
coeff[0] = coeff[2] = level_3db;
|
||||
coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
|
||||
return 7;
|
||||
|
||||
case CONVERT (A52_2F1R, A52_MONO):
|
||||
coeff[0] = coeff[1] = level * LEVEL_3DB;
|
||||
coeff[2] = level * slev * LEVEL_3DB;
|
||||
coeff[0] = coeff[1] = level_3db;
|
||||
coeff[2] = MUL_L (level_3db, slev);
|
||||
return 7;
|
||||
|
||||
case CONVERT (A52_2F2R, A52_MONO):
|
||||
coeff[0] = coeff[1] = level * LEVEL_3DB;
|
||||
coeff[2] = coeff[3] = level * slev * LEVEL_3DB;
|
||||
coeff[0] = coeff[1] = level_3db;
|
||||
coeff[2] = coeff[3] = MUL_L (level_3db, slev);
|
||||
return 15;
|
||||
|
||||
case CONVERT (A52_3F1R, A52_MONO):
|
||||
coeff[0] = coeff[2] = level * LEVEL_3DB;
|
||||
coeff[1] = level * clev * LEVEL_PLUS3DB;
|
||||
coeff[3] = level * slev * LEVEL_3DB;
|
||||
coeff[0] = coeff[2] = level_3db;
|
||||
coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
|
||||
coeff[3] = MUL_L (level_3db, slev);
|
||||
return 15;
|
||||
|
||||
case CONVERT (A52_3F2R, A52_MONO):
|
||||
coeff[0] = coeff[2] = level * LEVEL_3DB;
|
||||
coeff[1] = level * clev * LEVEL_PLUS3DB;
|
||||
coeff[3] = coeff[4] = level * slev * LEVEL_3DB;
|
||||
coeff[0] = coeff[2] = level_3db;
|
||||
coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
|
||||
coeff[3] = coeff[4] = MUL_L (level_3db, slev);
|
||||
return 31;
|
||||
|
||||
case CONVERT (A52_MONO, A52_DOLBY):
|
||||
coeff[0] = level * LEVEL_3DB;
|
||||
coeff[0] = level_3db;
|
||||
return 0;
|
||||
|
||||
case CONVERT (A52_3F, A52_DOLBY):
|
||||
clev = LEVEL_3DB;
|
||||
coeff[0] = coeff[2] = coeff[3] = coeff[4] = level;
|
||||
coeff[1] = level_3db;
|
||||
return 7;
|
||||
|
||||
case CONVERT (A52_3F, A52_STEREO):
|
||||
case CONVERT (A52_3F1R, A52_2F1R):
|
||||
case CONVERT (A52_3F2R, A52_2F2R):
|
||||
coeff[0] = coeff[2] = coeff[3] = coeff[4] = level;
|
||||
coeff[1] = level * clev;
|
||||
coeff[1] = MUL_L (level, clev);
|
||||
return 7;
|
||||
|
||||
case CONVERT (A52_2F1R, A52_DOLBY):
|
||||
slev = 1;
|
||||
coeff[0] = coeff[1] = level;
|
||||
coeff[2] = level_3db;
|
||||
return 7;
|
||||
|
||||
case CONVERT (A52_2F1R, A52_STEREO):
|
||||
coeff[0] = coeff[1] = level;
|
||||
coeff[2] = level * slev * LEVEL_3DB;
|
||||
coeff[2] = MUL_L (level_3db, slev);
|
||||
return 7;
|
||||
|
||||
case CONVERT (A52_3F1R, A52_DOLBY):
|
||||
clev = LEVEL_3DB;
|
||||
slev = 1;
|
||||
coeff[0] = coeff[2] = level;
|
||||
coeff[1] = coeff[3] = level_3db;
|
||||
return 15;
|
||||
|
||||
case CONVERT (A52_3F1R, A52_STEREO):
|
||||
coeff[0] = coeff[2] = level;
|
||||
coeff[1] = level * clev;
|
||||
coeff[3] = level * slev * LEVEL_3DB;
|
||||
coeff[1] = MUL_L (level, clev);
|
||||
coeff[3] = MUL_L (level_3db, slev);
|
||||
return 15;
|
||||
|
||||
case CONVERT (A52_2F2R, A52_DOLBY):
|
||||
slev = LEVEL_3DB;
|
||||
coeff[0] = coeff[1] = level;
|
||||
coeff[2] = coeff[3] = level_3db;
|
||||
return 15;
|
||||
|
||||
case CONVERT (A52_2F2R, A52_STEREO):
|
||||
coeff[0] = coeff[1] = level;
|
||||
coeff[2] = coeff[3] = level * slev;
|
||||
coeff[2] = coeff[3] = MUL_L (level, slev);
|
||||
return 15;
|
||||
|
||||
case CONVERT (A52_3F2R, A52_DOLBY):
|
||||
clev = LEVEL_3DB;
|
||||
coeff[0] = coeff[2] = level;
|
||||
coeff[1] = coeff[3] = coeff[4] = level_3db;
|
||||
return 31;
|
||||
|
||||
case CONVERT (A52_3F2R, A52_2F1R):
|
||||
slev = LEVEL_3DB;
|
||||
coeff[0] = coeff[2] = level;
|
||||
coeff[1] = MUL_L (level, clev);
|
||||
coeff[3] = coeff[4] = level_3db;
|
||||
return 31;
|
||||
|
||||
case CONVERT (A52_3F2R, A52_STEREO):
|
||||
coeff[0] = coeff[2] = level;
|
||||
coeff[1] = level * clev;
|
||||
coeff[3] = coeff[4] = level * slev;
|
||||
coeff[1] = MUL_L (level, clev);
|
||||
coeff[3] = coeff[4] = MUL_L (level, slev);
|
||||
return 31;
|
||||
|
||||
case CONVERT (A52_3F1R, A52_3F):
|
||||
coeff[0] = coeff[1] = coeff[2] = level;
|
||||
coeff[3] = level * slev * LEVEL_3DB;
|
||||
coeff[3] = MUL_L (level_3db, slev);
|
||||
return 13;
|
||||
|
||||
case CONVERT (A52_3F2R, A52_3F):
|
||||
coeff[0] = coeff[1] = coeff[2] = level;
|
||||
coeff[3] = coeff[4] = level * slev;
|
||||
coeff[3] = coeff[4] = MUL_L (level, slev);
|
||||
return 29;
|
||||
|
||||
case CONVERT (A52_2F2R, A52_2F1R):
|
||||
coeff[0] = coeff[1] = level;
|
||||
coeff[2] = coeff[3] = level * LEVEL_3DB;
|
||||
coeff[2] = coeff[3] = level_3db;
|
||||
return 12;
|
||||
|
||||
case CONVERT (A52_3F2R, A52_3F1R):
|
||||
coeff[0] = coeff[1] = coeff[2] = level;
|
||||
coeff[3] = coeff[4] = level * LEVEL_3DB;
|
||||
coeff[3] = coeff[4] = level_3db;
|
||||
return 24;
|
||||
|
||||
case CONVERT (A52_2F1R, A52_2F2R):
|
||||
coeff[0] = coeff[1] = level;
|
||||
coeff[2] = level * LEVEL_3DB;
|
||||
coeff[2] = level_3db;
|
||||
return 0;
|
||||
|
||||
case CONVERT (A52_3F1R, A52_2F2R):
|
||||
coeff[0] = coeff[2] = level;
|
||||
coeff[1] = level * clev;
|
||||
coeff[3] = level * LEVEL_3DB;
|
||||
coeff[1] = MUL_L (level, clev);
|
||||
coeff[3] = level_3db;
|
||||
return 7;
|
||||
|
||||
case CONVERT (A52_3F1R, A52_3F2R):
|
||||
coeff[0] = coeff[1] = coeff[2] = level;
|
||||
coeff[3] = level * LEVEL_3DB;
|
||||
coeff[3] = level_3db;
|
||||
return 0;
|
||||
|
||||
case CONVERT (A52_CHANNEL, A52_CHANNEL1):
|
||||
@ -299,7 +334,7 @@ static void mix2to1 (sample_t * dest, sample_t * src, sample_t bias)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
dest[i] += src[i] + bias;
|
||||
dest[i] += BIAS (src[i]);
|
||||
}
|
||||
|
||||
static void mix3to1 (sample_t * samples, sample_t bias)
|
||||
@ -307,7 +342,7 @@ static void mix3to1 (sample_t * samples, sample_t bias)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
samples[i] += samples[i + 256] + samples[i + 512] + bias;
|
||||
samples[i] += BIAS (samples[i + 256] + samples[i + 512]);
|
||||
}
|
||||
|
||||
static void mix4to1 (sample_t * samples, sample_t bias)
|
||||
@ -315,8 +350,8 @@ static void mix4to1 (sample_t * samples, sample_t bias)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
samples[i] += (samples[i + 256] + samples[i + 512] +
|
||||
samples[i + 768] + bias);
|
||||
samples[i] += BIAS (samples[i + 256] + samples[i + 512] +
|
||||
samples[i + 768]);
|
||||
}
|
||||
|
||||
static void mix5to1 (sample_t * samples, sample_t bias)
|
||||
@ -324,8 +359,8 @@ static void mix5to1 (sample_t * samples, sample_t bias)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
samples[i] += (samples[i + 256] + samples[i + 512] +
|
||||
samples[i + 768] + samples[i + 1024] + bias);
|
||||
samples[i] += BIAS (samples[i + 256] + samples[i + 512] +
|
||||
samples[i + 768] + samples[i + 1024]);
|
||||
}
|
||||
|
||||
static void mix3to2 (sample_t * samples, sample_t bias)
|
||||
@ -334,7 +369,7 @@ static void mix3to2 (sample_t * samples, sample_t bias)
|
||||
sample_t common;
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
common = samples[i + 256] + bias;
|
||||
common = BIAS (samples[i + 256]);
|
||||
samples[i] += common;
|
||||
samples[i + 256] = samples[i + 512] + common;
|
||||
}
|
||||
@ -346,7 +381,7 @@ static void mix21to2 (sample_t * left, sample_t * right, sample_t bias)
|
||||
sample_t common;
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
common = right[i + 256] + bias;
|
||||
common = BIAS (right[i + 256]);
|
||||
left[i] += common;
|
||||
right[i] += common;
|
||||
}
|
||||
@ -359,8 +394,8 @@ static void mix21toS (sample_t * samples, sample_t bias)
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
surround = samples[i + 512];
|
||||
samples[i] += bias - surround;
|
||||
samples[i + 256] += bias + surround;
|
||||
samples[i] += BIAS (-surround);
|
||||
samples[i + 256] += BIAS (surround);
|
||||
}
|
||||
}
|
||||
|
||||
@ -370,7 +405,7 @@ static void mix31to2 (sample_t * samples, sample_t bias)
|
||||
sample_t common;
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
common = samples[i + 256] + samples[i + 768] + bias;
|
||||
common = BIAS (samples[i + 256] + samples[i + 768]);
|
||||
samples[i] += common;
|
||||
samples[i + 256] = samples[i + 512] + common;
|
||||
}
|
||||
@ -382,7 +417,7 @@ static void mix31toS (sample_t * samples, sample_t bias)
|
||||
sample_t common, surround;
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
common = samples[i + 256] + bias;
|
||||
common = BIAS (samples[i + 256]);
|
||||
surround = samples[i + 768];
|
||||
samples[i] += common - surround;
|
||||
samples[i + 256] = samples[i + 512] + common + surround;
|
||||
@ -396,8 +431,8 @@ static void mix22toS (sample_t * samples, sample_t bias)
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
surround = samples[i + 512] + samples[i + 768];
|
||||
samples[i] += bias - surround;
|
||||
samples[i + 256] += bias + surround;
|
||||
samples[i] += BIAS (-surround);
|
||||
samples[i + 256] += BIAS (surround);
|
||||
}
|
||||
}
|
||||
|
||||
@ -407,7 +442,7 @@ static void mix32to2 (sample_t * samples, sample_t bias)
|
||||
sample_t common;
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
common = samples[i + 256] + bias;
|
||||
common = BIAS (samples[i + 256]);
|
||||
samples[i] += common + samples[i + 768];
|
||||
samples[i + 256] = common + samples[i + 512] + samples[i + 1024];
|
||||
}
|
||||
@ -419,7 +454,7 @@ static void mix32toS (sample_t * samples, sample_t bias)
|
||||
sample_t common, surround;
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
common = samples[i + 256] + bias;
|
||||
common = BIAS (samples[i + 256]);
|
||||
surround = samples[i + 768] + samples[i + 1024];
|
||||
samples[i] += common - surround;
|
||||
samples[i + 256] = samples[i + 512] + common + surround;
|
||||
@ -431,7 +466,7 @@ static void move2to1 (sample_t * src, sample_t * dest, sample_t bias)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
dest[i] = src[i] + src[i + 256] + bias;
|
||||
dest[i] = BIAS (src[i] + src[i + 256]);
|
||||
}
|
||||
|
||||
static void zero (sample_t * samples)
|
||||
@ -443,7 +478,7 @@ static void zero (sample_t * samples)
|
||||
}
|
||||
|
||||
void a52_downmix (sample_t * samples, int acmod, int output, sample_t bias,
|
||||
sample_t clev, sample_t slev)
|
||||
level_t clev, level_t slev)
|
||||
{
|
||||
switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
|
||||
|
||||
@ -578,7 +613,7 @@ void a52_downmix (sample_t * samples, int acmod, int output, sample_t bias,
|
||||
break;
|
||||
|
||||
case CONVERT (A52_3F1R, A52_3F2R):
|
||||
memcpy (samples + 1027, samples + 768, 256 * sizeof (sample_t));
|
||||
memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* imdct.c
|
||||
* Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
|
||||
* Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
|
||||
* Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
|
||||
*
|
||||
* The ifft algorithms in this file have been largely inspired by Dan
|
||||
@ -24,6 +24,18 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#ifdef LIBA52_DJBFFT
|
||||
#include <fftc4.h>
|
||||
#endif
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.1415926535897932384626433832795029
|
||||
#endif
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "a52.h"
|
||||
#include "a52_internal.h"
|
||||
#include "mm_accel.h"
|
||||
@ -33,8 +45,6 @@ typedef struct complex_s {
|
||||
sample_t imag;
|
||||
} complex_t;
|
||||
|
||||
static complex_t buf[128];
|
||||
|
||||
static uint8_t fftorder[] = {
|
||||
0,128, 64,192, 32,160,224, 96, 16,144, 80,208,240,112, 48,176,
|
||||
8,136, 72,200, 40,168,232,104,248,120, 56,184, 24,152,216, 88,
|
||||
@ -65,7 +75,7 @@ static void (* ifft64) (complex_t * buf);
|
||||
|
||||
static inline void ifft2 (complex_t * buf)
|
||||
{
|
||||
double r, i;
|
||||
sample_t r, i;
|
||||
|
||||
r = buf[0].real;
|
||||
i = buf[0].imag;
|
||||
@ -77,7 +87,7 @@ static inline void ifft2 (complex_t * buf)
|
||||
|
||||
static inline void ifft4 (complex_t * buf)
|
||||
{
|
||||
double tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
|
||||
sample_t tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
|
||||
|
||||
tmp1 = buf[0].real + buf[1].real;
|
||||
tmp2 = buf[3].real + buf[2].real;
|
||||
@ -98,25 +108,37 @@ static inline void ifft4 (complex_t * buf)
|
||||
buf[3].imag = tmp6 - tmp8;
|
||||
}
|
||||
|
||||
/* basic radix-2 ifft butterfly */
|
||||
|
||||
#define BUTTERFLY_0(t0,t1,W0,W1,d0,d1) do { \
|
||||
t0 = MUL (W1, d1) + MUL (W0, d0); \
|
||||
t1 = MUL (W0, d1) - MUL (W1, d0); \
|
||||
} while (0)
|
||||
|
||||
/* radix-2 ifft butterfly with bias */
|
||||
|
||||
#define BUTTERFLY_B(t0,t1,W0,W1,d0,d1) do { \
|
||||
t0 = BIAS (MUL (d1, W1) + MUL (d0, W0)); \
|
||||
t1 = BIAS (MUL (d1, W0) - MUL (d0, W1)); \
|
||||
} while (0)
|
||||
|
||||
/* the basic split-radix ifft butterfly */
|
||||
|
||||
#define BUTTERFLY(a0,a1,a2,a3,wr,wi) do { \
|
||||
tmp5 = a2.real * wr + a2.imag * wi; \
|
||||
tmp6 = a2.imag * wr - a2.real * wi; \
|
||||
tmp7 = a3.real * wr - a3.imag * wi; \
|
||||
tmp8 = a3.imag * wr + a3.real * wi; \
|
||||
tmp1 = tmp5 + tmp7; \
|
||||
tmp2 = tmp6 + tmp8; \
|
||||
tmp3 = tmp6 - tmp8; \
|
||||
tmp4 = tmp7 - tmp5; \
|
||||
a2.real = a0.real - tmp1; \
|
||||
a2.imag = a0.imag - tmp2; \
|
||||
a3.real = a1.real - tmp3; \
|
||||
a3.imag = a1.imag - tmp4; \
|
||||
a0.real += tmp1; \
|
||||
a0.imag += tmp2; \
|
||||
a1.real += tmp3; \
|
||||
a1.imag += tmp4; \
|
||||
#define BUTTERFLY(a0,a1,a2,a3,wr,wi) do { \
|
||||
BUTTERFLY_0 (tmp5, tmp6, wr, wi, a2.real, a2.imag); \
|
||||
BUTTERFLY_0 (tmp8, tmp7, wr, wi, a3.imag, a3.real); \
|
||||
tmp1 = tmp5 + tmp7; \
|
||||
tmp2 = tmp6 + tmp8; \
|
||||
tmp3 = tmp6 - tmp8; \
|
||||
tmp4 = tmp7 - tmp5; \
|
||||
a2.real = a0.real - tmp1; \
|
||||
a2.imag = a0.imag - tmp2; \
|
||||
a3.real = a1.real - tmp3; \
|
||||
a3.imag = a1.imag - tmp4; \
|
||||
a0.real += tmp1; \
|
||||
a0.imag += tmp2; \
|
||||
a1.real += tmp3; \
|
||||
a1.imag += tmp4; \
|
||||
} while (0)
|
||||
|
||||
/* split-radix ifft butterfly, specialized for wr=1 wi=0 */
|
||||
@ -139,10 +161,10 @@ static inline void ifft4 (complex_t * buf)
|
||||
/* split-radix ifft butterfly, specialized for wr=wi */
|
||||
|
||||
#define BUTTERFLY_HALF(a0,a1,a2,a3,w) do { \
|
||||
tmp5 = (a2.real + a2.imag) * w; \
|
||||
tmp6 = (a2.imag - a2.real) * w; \
|
||||
tmp7 = (a3.real - a3.imag) * w; \
|
||||
tmp8 = (a3.imag + a3.real) * w; \
|
||||
tmp5 = MUL (a2.real + a2.imag, w); \
|
||||
tmp6 = MUL (a2.imag - a2.real, w); \
|
||||
tmp7 = MUL (a3.real - a3.imag, w); \
|
||||
tmp8 = MUL (a3.imag + a3.real, w); \
|
||||
tmp1 = tmp5 + tmp7; \
|
||||
tmp2 = tmp6 + tmp8; \
|
||||
tmp3 = tmp6 - tmp8; \
|
||||
@ -159,7 +181,7 @@ static inline void ifft4 (complex_t * buf)
|
||||
|
||||
static inline void ifft8 (complex_t * buf)
|
||||
{
|
||||
double tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
|
||||
sample_t tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
|
||||
|
||||
ifft4 (buf);
|
||||
ifft2 (buf + 4);
|
||||
@ -173,7 +195,7 @@ static void ifft_pass (complex_t * buf, sample_t * weight, int n)
|
||||
complex_t * buf1;
|
||||
complex_t * buf2;
|
||||
complex_t * buf3;
|
||||
double tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
|
||||
sample_t tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
|
||||
int i;
|
||||
|
||||
buf++;
|
||||
@ -186,7 +208,8 @@ static void ifft_pass (complex_t * buf, sample_t * weight, int n)
|
||||
i = n - 1;
|
||||
|
||||
do {
|
||||
BUTTERFLY (buf[0], buf1[0], buf2[0], buf3[0], weight[n], weight[2*i]);
|
||||
BUTTERFLY (buf[0], buf1[0], buf2[0], buf3[0],
|
||||
weight[0], weight[2*i-n]);
|
||||
buf++;
|
||||
buf1++;
|
||||
buf2++;
|
||||
@ -200,7 +223,7 @@ static void ifft16 (complex_t * buf)
|
||||
ifft8 (buf);
|
||||
ifft4 (buf + 8);
|
||||
ifft4 (buf + 12);
|
||||
ifft_pass (buf, roots16 - 4, 4);
|
||||
ifft_pass (buf, roots16, 4);
|
||||
}
|
||||
|
||||
static void ifft32 (complex_t * buf)
|
||||
@ -208,7 +231,7 @@ static void ifft32 (complex_t * buf)
|
||||
ifft16 (buf);
|
||||
ifft8 (buf + 16);
|
||||
ifft8 (buf + 24);
|
||||
ifft_pass (buf, roots32 - 8, 8);
|
||||
ifft_pass (buf, roots32, 8);
|
||||
}
|
||||
|
||||
static void ifft64_c (complex_t * buf)
|
||||
@ -216,7 +239,7 @@ static void ifft64_c (complex_t * buf)
|
||||
ifft32 (buf);
|
||||
ifft16 (buf + 32);
|
||||
ifft16 (buf + 48);
|
||||
ifft_pass (buf, roots64 - 16, 16);
|
||||
ifft_pass (buf, roots64, 16);
|
||||
}
|
||||
|
||||
static void ifft128_c (complex_t * buf)
|
||||
@ -224,11 +247,11 @@ static void ifft128_c (complex_t * buf)
|
||||
ifft32 (buf);
|
||||
ifft16 (buf + 32);
|
||||
ifft16 (buf + 48);
|
||||
ifft_pass (buf, roots64 - 16, 16);
|
||||
ifft_pass (buf, roots64, 16);
|
||||
|
||||
ifft32 (buf + 64);
|
||||
ifft32 (buf + 96);
|
||||
ifft_pass (buf, roots128 - 32, 32);
|
||||
ifft_pass (buf, roots128, 32);
|
||||
}
|
||||
|
||||
void a52_imdct_512 (sample_t * data, sample_t * delay, sample_t bias)
|
||||
@ -236,14 +259,13 @@ void a52_imdct_512 (sample_t * data, sample_t * delay, sample_t bias)
|
||||
int i, k;
|
||||
sample_t t_r, t_i, a_r, a_i, b_r, b_i, w_1, w_2;
|
||||
const sample_t * window = a52_imdct_window;
|
||||
complex_t buf[128];
|
||||
|
||||
for (i = 0; i < 128; i++) {
|
||||
k = fftorder[i];
|
||||
t_r = pre1[i].real;
|
||||
t_i = pre1[i].imag;
|
||||
|
||||
buf[i].real = t_i * data[255-k] + t_r * data[k];
|
||||
buf[i].imag = t_r * data[255-k] - t_i * data[k];
|
||||
BUTTERFLY_0 (buf[i].real, buf[i].imag, t_r, t_i, data[k], data[255-k]);
|
||||
}
|
||||
|
||||
ifft128 (buf);
|
||||
@ -254,47 +276,35 @@ void a52_imdct_512 (sample_t * data, sample_t * delay, sample_t bias)
|
||||
/* y[n] = z[n] * (xcos1[n] + j * xsin1[n]) ; */
|
||||
t_r = post1[i].real;
|
||||
t_i = post1[i].imag;
|
||||
|
||||
a_r = t_r * buf[i].real + t_i * buf[i].imag;
|
||||
a_i = t_i * buf[i].real - t_r * buf[i].imag;
|
||||
b_r = t_i * buf[127-i].real + t_r * buf[127-i].imag;
|
||||
b_i = t_r * buf[127-i].real - t_i * buf[127-i].imag;
|
||||
BUTTERFLY_0 (a_r, a_i, t_i, t_r, buf[i].imag, buf[i].real);
|
||||
BUTTERFLY_0 (b_r, b_i, t_r, t_i, buf[127-i].imag, buf[127-i].real);
|
||||
|
||||
w_1 = window[2*i];
|
||||
w_2 = window[255-2*i];
|
||||
data[2*i] = delay[2*i] * w_2 - a_r * w_1 + bias;
|
||||
data[255-2*i] = delay[2*i] * w_1 + a_r * w_2 + bias;
|
||||
BUTTERFLY_B (data[255-2*i], data[2*i], w_2, w_1, a_r, delay[2*i]);
|
||||
delay[2*i] = a_i;
|
||||
|
||||
w_1 = window[2*i+1];
|
||||
w_2 = window[254-2*i];
|
||||
data[2*i+1] = delay[2*i+1] * w_2 + b_r * w_1 + bias;
|
||||
data[254-2*i] = delay[2*i+1] * w_1 - b_r * w_2 + bias;
|
||||
BUTTERFLY_B (data[2*i+1], data[254-2*i], w_1, w_2, b_r, delay[2*i+1]);
|
||||
delay[2*i+1] = b_i;
|
||||
}
|
||||
}
|
||||
|
||||
void a52_imdct_256(sample_t data[],sample_t delay[],sample_t bias)
|
||||
void a52_imdct_256 (sample_t * data, sample_t * delay, sample_t bias)
|
||||
{
|
||||
int i, k;
|
||||
sample_t t_r, t_i, a_r, a_i, b_r, b_i, c_r, c_i, d_r, d_i, w_1, w_2;
|
||||
complex_t * buf1, * buf2;
|
||||
const sample_t * window = a52_imdct_window;
|
||||
|
||||
buf1 = &buf[0];
|
||||
buf2 = &buf[64];
|
||||
complex_t buf1[64], buf2[64];
|
||||
|
||||
/* Pre IFFT complex multiply plus IFFT cmplx conjugate */
|
||||
for (i = 0; i < 64; i++) {
|
||||
k = fftorder[i];
|
||||
t_r = pre2[i].real;
|
||||
t_i = pre2[i].imag;
|
||||
|
||||
buf1[i].real = t_i * data[254-k] + t_r * data[k];
|
||||
buf1[i].imag = t_r * data[254-k] - t_i * data[k];
|
||||
|
||||
buf2[i].real = t_i * data[255-k] + t_r * data[k+1];
|
||||
buf2[i].imag = t_r * data[255-k] - t_i * data[k+1];
|
||||
BUTTERFLY_0 (buf1[i].real, buf1[i].imag, t_r, t_i, data[k], data[254-k]);
|
||||
BUTTERFLY_0 (buf2[i].real, buf2[i].imag, t_r, t_i, data[k+1], data[255-k]);
|
||||
}
|
||||
|
||||
ifft64 (buf1);
|
||||
@ -306,39 +316,29 @@ void a52_imdct_256(sample_t data[],sample_t delay[],sample_t bias)
|
||||
/* y1[n] = z1[n] * (xcos2[n] + j * xs in2[n]) ; */
|
||||
t_r = post2[i].real;
|
||||
t_i = post2[i].imag;
|
||||
|
||||
a_r = t_r * buf1[i].real + t_i * buf1[i].imag;
|
||||
a_i = t_i * buf1[i].real - t_r * buf1[i].imag;
|
||||
b_r = t_i * buf1[63-i].real + t_r * buf1[63-i].imag;
|
||||
b_i = t_r * buf1[63-i].real - t_i * buf1[63-i].imag;
|
||||
|
||||
c_r = t_r * buf2[i].real + t_i * buf2[i].imag;
|
||||
c_i = t_i * buf2[i].real - t_r * buf2[i].imag;
|
||||
d_r = t_i * buf2[63-i].real + t_r * buf2[63-i].imag;
|
||||
d_i = t_r * buf2[63-i].real - t_i * buf2[63-i].imag;
|
||||
BUTTERFLY_0 (a_r, a_i, t_i, t_r, buf1[i].imag, buf1[i].real);
|
||||
BUTTERFLY_0 (b_r, b_i, t_r, t_i, buf1[63-i].imag, buf1[63-i].real);
|
||||
BUTTERFLY_0 (c_r, c_i, t_i, t_r, buf2[i].imag, buf2[i].real);
|
||||
BUTTERFLY_0 (d_r, d_i, t_r, t_i, buf2[63-i].imag, buf2[63-i].real);
|
||||
|
||||
w_1 = window[2*i];
|
||||
w_2 = window[255-2*i];
|
||||
data[2*i] = delay[2*i] * w_2 - a_r * w_1 + bias;
|
||||
data[255-2*i] = delay[2*i] * w_1 + a_r * w_2 + bias;
|
||||
BUTTERFLY_B (data[255-2*i], data[2*i], w_2, w_1, a_r, delay[2*i]);
|
||||
delay[2*i] = c_i;
|
||||
|
||||
w_1 = window[128+2*i];
|
||||
w_2 = window[127-2*i];
|
||||
data[128+2*i] = delay[127-2*i] * w_2 + a_i * w_1 + bias;
|
||||
data[127-2*i] = delay[127-2*i] * w_1 - a_i * w_2 + bias;
|
||||
BUTTERFLY_B (data[128+2*i], data[127-2*i], w_1, w_2, a_i, delay[127-2*i]);
|
||||
delay[127-2*i] = c_r;
|
||||
|
||||
w_1 = window[2*i+1];
|
||||
w_2 = window[254-2*i];
|
||||
data[2*i+1] = delay[2*i+1] * w_2 - b_i * w_1 + bias;
|
||||
data[254-2*i] = delay[2*i+1] * w_1 + b_i * w_2 + bias;
|
||||
BUTTERFLY_B (data[254-2*i], data[2*i+1], w_2, w_1, b_i, delay[2*i+1]);
|
||||
delay[2*i+1] = d_r;
|
||||
|
||||
w_1 = window[129+2*i];
|
||||
w_2 = window[126-2*i];
|
||||
data[129+2*i] = delay[126-2*i] * w_2 + b_r * w_1 + bias;
|
||||
data[126-2*i] = delay[126-2*i] * w_1 - b_r * w_2 + bias;
|
||||
BUTTERFLY_B (data[129+2*i], data[126-2*i], w_1, w_2, b_r, delay[126-2*i]);
|
||||
delay[126-2*i] = d_i;
|
||||
}
|
||||
}
|
||||
@ -358,66 +358,65 @@ void a52_imdct_init (uint32_t mm_accel)
|
||||
{
|
||||
int i, k;
|
||||
double sum;
|
||||
double local_imdct_window[256];
|
||||
|
||||
/* compute imdct window - kaiser-bessel derived window, alpha = 5.0 */
|
||||
sum = 0;
|
||||
for (i = 0; i < 256; i++) {
|
||||
sum += besselI0 (i * (256 - i) * (5 * M_PI / 256) * (5 * M_PI / 256));
|
||||
a52_imdct_window[i] = sum;
|
||||
local_imdct_window[i] = sum;
|
||||
}
|
||||
sum++;
|
||||
for (i = 0; i < 256; i++)
|
||||
a52_imdct_window[i] = sqrt (a52_imdct_window[i] / sum);
|
||||
a52_imdct_window[i] = SAMPLE (sqrt (local_imdct_window[i] / sum));
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
roots16[i] = cos ((M_PI / 8) * (i + 1));
|
||||
roots16[i] = SAMPLE (cos ((M_PI / 8) * (i + 1)));
|
||||
|
||||
for (i = 0; i < 7; i++)
|
||||
roots32[i] = cos ((M_PI / 16) * (i + 1));
|
||||
roots32[i] = SAMPLE (cos ((M_PI / 16) * (i + 1)));
|
||||
|
||||
for (i = 0; i < 15; i++)
|
||||
roots64[i] = cos ((M_PI / 32) * (i + 1));
|
||||
roots64[i] = SAMPLE (cos ((M_PI / 32) * (i + 1)));
|
||||
|
||||
for (i = 0; i < 31; i++)
|
||||
roots128[i] = cos ((M_PI / 64) * (i + 1));
|
||||
roots128[i] = SAMPLE (cos ((M_PI / 64) * (i + 1)));
|
||||
|
||||
for (i = 0; i < 64; i++) {
|
||||
k = fftorder[i] / 2 + 64;
|
||||
pre1[i].real = cos ((M_PI / 256) * (k - 0.25));
|
||||
pre1[i].imag = sin ((M_PI / 256) * (k - 0.25));
|
||||
pre1[i].real = SAMPLE (cos ((M_PI / 256) * (k - 0.25)));
|
||||
pre1[i].imag = SAMPLE (sin ((M_PI / 256) * (k - 0.25)));
|
||||
}
|
||||
|
||||
for (i = 64; i < 128; i++) {
|
||||
k = fftorder[i] / 2 + 64;
|
||||
pre1[i].real = -cos ((M_PI / 256) * (k - 0.25));
|
||||
pre1[i].imag = -sin ((M_PI / 256) * (k - 0.25));
|
||||
pre1[i].real = SAMPLE (-cos ((M_PI / 256) * (k - 0.25)));
|
||||
pre1[i].imag = SAMPLE (-sin ((M_PI / 256) * (k - 0.25)));
|
||||
}
|
||||
|
||||
for (i = 0; i < 64; i++) {
|
||||
post1[i].real = cos ((M_PI / 256) * (i + 0.5));
|
||||
post1[i].imag = sin ((M_PI / 256) * (i + 0.5));
|
||||
post1[i].real = SAMPLE (cos ((M_PI / 256) * (i + 0.5)));
|
||||
post1[i].imag = SAMPLE (sin ((M_PI / 256) * (i + 0.5)));
|
||||
}
|
||||
|
||||
for (i = 0; i < 64; i++) {
|
||||
k = fftorder[i] / 4;
|
||||
pre2[i].real = cos ((M_PI / 128) * (k - 0.25));
|
||||
pre2[i].imag = sin ((M_PI / 128) * (k - 0.25));
|
||||
pre2[i].real = SAMPLE (cos ((M_PI / 128) * (k - 0.25)));
|
||||
pre2[i].imag = SAMPLE (sin ((M_PI / 128) * (k - 0.25)));
|
||||
}
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
post2[i].real = cos ((M_PI / 128) * (i + 0.5));
|
||||
post2[i].imag = sin ((M_PI / 128) * (i + 0.5));
|
||||
post2[i].real = SAMPLE (cos ((M_PI / 128) * (i + 0.5)));
|
||||
post2[i].imag = SAMPLE (sin ((M_PI / 128) * (i + 0.5)));
|
||||
}
|
||||
|
||||
#ifdef LIBA52_DJBFFT
|
||||
if (mm_accel & MM_ACCEL_DJBFFT) {
|
||||
fprintf (stderr, "Using djbfft for IMDCT transform\n");
|
||||
ifft128 = (void (*) (complex_t *)) fftc4_un128;
|
||||
ifft64 = (void (*) (complex_t *)) fftc4_un64;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
fprintf (stderr, "No accelerated IMDCT transform found\n");
|
||||
ifft128 = ifft128_c;
|
||||
ifft64 = ifft64_c;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* parse.c
|
||||
* Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
|
||||
* 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.
|
||||
@ -21,12 +21,18 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "a52.h"
|
||||
#include "a52_internal.h"
|
||||
#include "bitstream.h"
|
||||
#include "tables.h"
|
||||
|
||||
#ifdef HAVE_MEMALIGN
|
||||
#if defined(HAVE_MEMALIGN) && !defined(__cplusplus)
|
||||
/* some systems have memalign() but no declaration for it */
|
||||
void * memalign (size_t align, size_t size);
|
||||
#else
|
||||
@ -35,13 +41,13 @@ void * memalign (size_t align, size_t size);
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
sample_t q1[2];
|
||||
sample_t q2[2];
|
||||
sample_t q4;
|
||||
quantizer_t q1[2];
|
||||
quantizer_t q2[2];
|
||||
quantizer_t q4;
|
||||
int q1_ptr;
|
||||
int q2_ptr;
|
||||
int q4_ptr;
|
||||
} quantizer_t;
|
||||
} quantizer_set_t;
|
||||
|
||||
static uint8_t halfrate[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3};
|
||||
|
||||
@ -50,11 +56,11 @@ a52_state_t * a52_init (uint32_t mm_accel)
|
||||
a52_state_t * state;
|
||||
int i;
|
||||
|
||||
state = malloc (sizeof (a52_state_t));
|
||||
state = (a52_state_t *) malloc (sizeof (a52_state_t));
|
||||
if (state == NULL)
|
||||
return NULL;
|
||||
|
||||
state->samples = memalign (16, 256 * 12 * sizeof (sample_t));
|
||||
state->samples = (sample_t *) memalign (16, 256 * 12 * sizeof (sample_t));
|
||||
if (state->samples == NULL) {
|
||||
free (state);
|
||||
return NULL;
|
||||
@ -65,6 +71,8 @@ a52_state_t * a52_init (uint32_t mm_accel)
|
||||
|
||||
state->downmixed = 1;
|
||||
|
||||
state->lfsr_state = 1;
|
||||
|
||||
a52_imdct_init (mm_accel);
|
||||
|
||||
return state;
|
||||
@ -121,10 +129,12 @@ int a52_syncinfo (uint8_t * buf, int * flags,
|
||||
}
|
||||
|
||||
int a52_frame (a52_state_t * state, uint8_t * buf, int * flags,
|
||||
sample_t * level, sample_t bias)
|
||||
level_t * level, sample_t bias)
|
||||
{
|
||||
static sample_t clev[4] = {LEVEL_3DB, LEVEL_45DB, LEVEL_6DB, LEVEL_45DB};
|
||||
static sample_t slev[4] = {LEVEL_3DB, LEVEL_6DB, 0, LEVEL_6DB};
|
||||
static level_t clev[4] = { LEVEL (LEVEL_3DB), LEVEL (LEVEL_45DB),
|
||||
LEVEL (LEVEL_6DB), LEVEL (LEVEL_45DB) };
|
||||
static level_t slev[4] = { LEVEL (LEVEL_3DB), LEVEL (LEVEL_6DB),
|
||||
0, LEVEL (LEVEL_6DB) };
|
||||
int chaninfo;
|
||||
int acmod;
|
||||
|
||||
@ -132,19 +142,21 @@ int a52_frame (a52_state_t * state, uint8_t * buf, int * flags,
|
||||
state->halfrate = halfrate[buf[5] >> 3];
|
||||
state->acmod = acmod = buf[6] >> 5;
|
||||
|
||||
a52_bitstream_set_ptr (buf + 6);
|
||||
bitstream_get (3); /* skip acmod we already parsed */
|
||||
a52_bitstream_set_ptr (state, buf + 6);
|
||||
bitstream_get (state, 3); /* skip acmod we already parsed */
|
||||
|
||||
if ((acmod == 2) && (bitstream_get (2) == 2)) /* dsurmod */
|
||||
if ((acmod == 2) && (bitstream_get (state, 2) == 2)) /* dsurmod */
|
||||
acmod = A52_DOLBY;
|
||||
|
||||
state->clev = state->slev = 0;
|
||||
|
||||
if ((acmod & 1) && (acmod != 1))
|
||||
state->clev = clev[bitstream_get (2)]; /* cmixlev */
|
||||
state->clev = clev[bitstream_get (state, 2)]; /* cmixlev */
|
||||
|
||||
if (acmod & 4)
|
||||
state->slev = slev[bitstream_get (2)]; /* surmixlev */
|
||||
state->slev = slev[bitstream_get (state, 2)]; /* surmixlev */
|
||||
|
||||
state->lfeon = bitstream_get (1);
|
||||
state->lfeon = bitstream_get (state, 1);
|
||||
|
||||
state->output = a52_downmix_init (acmod, *flags, level,
|
||||
state->clev, state->slev);
|
||||
@ -154,7 +166,7 @@ int a52_frame (a52_state_t * state, uint8_t * buf, int * flags,
|
||||
state->output |= A52_LFE;
|
||||
*flags = state->output;
|
||||
/* the 2* compensates for differences in imdct */
|
||||
state->dynrng = state->level = 2 * *level;
|
||||
state->dynrng = state->level = MUL_C (*level, 2);
|
||||
state->bias = bias;
|
||||
state->dynrnge = 1;
|
||||
state->dynrngcall = NULL;
|
||||
@ -164,28 +176,28 @@ int a52_frame (a52_state_t * state, uint8_t * buf, int * flags,
|
||||
|
||||
chaninfo = !acmod;
|
||||
do {
|
||||
bitstream_get (5); /* dialnorm */
|
||||
if (bitstream_get (1)) /* compre */
|
||||
bitstream_get (8); /* compr */
|
||||
if (bitstream_get (1)) /* langcode */
|
||||
bitstream_get (8); /* langcod */
|
||||
if (bitstream_get (1)) /* audprodie */
|
||||
bitstream_get (7); /* mixlevel + roomtyp */
|
||||
bitstream_get (state, 5); /* dialnorm */
|
||||
if (bitstream_get (state, 1)) /* compre */
|
||||
bitstream_get (state, 8); /* compr */
|
||||
if (bitstream_get (state, 1)) /* langcode */
|
||||
bitstream_get (state, 8); /* langcod */
|
||||
if (bitstream_get (state, 1)) /* audprodie */
|
||||
bitstream_get (state, 7); /* mixlevel + roomtyp */
|
||||
} while (chaninfo--);
|
||||
|
||||
bitstream_get (2); /* copyrightb + origbs */
|
||||
bitstream_get (state, 2); /* copyrightb + origbs */
|
||||
|
||||
if (bitstream_get (1)) /* timecod1e */
|
||||
bitstream_get (14); /* timecod1 */
|
||||
if (bitstream_get (1)) /* timecod2e */
|
||||
bitstream_get (14); /* timecod2 */
|
||||
if (bitstream_get (state, 1)) /* timecod1e */
|
||||
bitstream_get (state, 14); /* timecod1 */
|
||||
if (bitstream_get (state, 1)) /* timecod2e */
|
||||
bitstream_get (state, 14); /* timecod2 */
|
||||
|
||||
if (bitstream_get (1)) { /* addbsie */
|
||||
if (bitstream_get (state, 1)) { /* addbsie */
|
||||
int addbsil;
|
||||
|
||||
addbsil = bitstream_get (6);
|
||||
addbsil = bitstream_get (state, 6);
|
||||
do {
|
||||
bitstream_get (8); /* addbsi */
|
||||
bitstream_get (state, 8); /* addbsi */
|
||||
} while (addbsil--);
|
||||
}
|
||||
|
||||
@ -193,7 +205,7 @@ int a52_frame (a52_state_t * state, uint8_t * buf, int * flags,
|
||||
}
|
||||
|
||||
void a52_dynrng (a52_state_t * state,
|
||||
sample_t (* call) (sample_t, void *), void * data)
|
||||
level_t (* call) (level_t, void *), void * data)
|
||||
{
|
||||
state->dynrnge = 0;
|
||||
if (call) {
|
||||
@ -203,13 +215,13 @@ void a52_dynrng (a52_state_t * state,
|
||||
}
|
||||
}
|
||||
|
||||
static int parse_exponents (int expstr, int ngrps, uint8_t exponent,
|
||||
uint8_t * dest)
|
||||
static int parse_exponents (a52_state_t * state, int expstr, int ngrps,
|
||||
uint8_t exponent, uint8_t * dest)
|
||||
{
|
||||
int exps;
|
||||
|
||||
while (ngrps--) {
|
||||
exps = bitstream_get (7);
|
||||
exps = bitstream_get (state, 7);
|
||||
|
||||
exponent += exp_1[exps];
|
||||
if (exponent > 24)
|
||||
@ -257,18 +269,18 @@ static int parse_exponents (int expstr, int ngrps, uint8_t exponent,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_deltba (int8_t * deltba)
|
||||
static int parse_deltba (a52_state_t * state, int8_t * deltba)
|
||||
{
|
||||
int deltnseg, deltlen, delta, j;
|
||||
|
||||
memset (deltba, 0, 50);
|
||||
|
||||
deltnseg = bitstream_get (3);
|
||||
deltnseg = bitstream_get (state, 3);
|
||||
j = 0;
|
||||
do {
|
||||
j += bitstream_get (5);
|
||||
deltlen = bitstream_get (4);
|
||||
delta = bitstream_get (3);
|
||||
j += bitstream_get (state, 5);
|
||||
deltlen = bitstream_get (state, 4);
|
||||
delta = bitstream_get (state, 3);
|
||||
delta -= (delta >= 4) ? 3 : 4;
|
||||
if (!deltlen)
|
||||
continue;
|
||||
@ -295,29 +307,46 @@ static inline int zero_snr_offsets (int nfchans, a52_state_t * state)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline int16_t dither_gen (void)
|
||||
static inline int16_t dither_gen (a52_state_t * state)
|
||||
{
|
||||
static uint16_t lfsr_state = 1;
|
||||
int16_t state;
|
||||
int16_t nstate;
|
||||
|
||||
state = dither_lut[lfsr_state >> 8] ^ (lfsr_state << 8);
|
||||
nstate = dither_lut[state->lfsr_state >> 8] ^ (state->lfsr_state << 8);
|
||||
|
||||
lfsr_state = (uint16_t) state;
|
||||
state->lfsr_state = (uint16_t) nstate;
|
||||
|
||||
return state;
|
||||
return (3 * nstate) >> 2;
|
||||
}
|
||||
|
||||
static void coeff_get (sample_t * coeff, expbap_t * expbap,
|
||||
quantizer_t * quantizer, sample_t level,
|
||||
int dither, int end)
|
||||
#ifndef LIBA52_FIXED
|
||||
#define COEFF(c,t,l,s,e) (c) = (t) * (s)[e]
|
||||
#else
|
||||
#define COEFF(c,_t,_l,s,e) do { \
|
||||
quantizer_t t = (_t); \
|
||||
level_t l = (_l); \
|
||||
int shift = e - 5; \
|
||||
sample_t tmp = t * (l >> 16) + ((t * (l & 0xffff)) >> 16); \
|
||||
if (shift >= 0) \
|
||||
(c) = tmp >> shift; \
|
||||
else \
|
||||
(c) = tmp << -shift; \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
static void coeff_get (a52_state_t * state, sample_t * coeff,
|
||||
expbap_t * expbap, quantizer_set_t * quant,
|
||||
level_t level, int dither, int end)
|
||||
{
|
||||
int i;
|
||||
uint8_t * exp;
|
||||
int8_t * bap;
|
||||
|
||||
#ifndef LIBA52_FIXED
|
||||
sample_t factor[25];
|
||||
|
||||
for (i = 0; i <= 24; i++)
|
||||
factor[i] = scale_factor[i] * level;
|
||||
#endif
|
||||
|
||||
exp = expbap->exp;
|
||||
bap = expbap->bap;
|
||||
@ -329,7 +358,7 @@ static void coeff_get (sample_t * coeff, expbap_t * expbap,
|
||||
switch (bapi) {
|
||||
case 0:
|
||||
if (dither) {
|
||||
coeff[i] = dither_gen() * LEVEL_3DB * factor[exp[i]];
|
||||
COEFF (coeff[i], dither_gen (state), level, factor, exp[i]);
|
||||
continue;
|
||||
} else {
|
||||
coeff[i] = 0;
|
||||
@ -337,76 +366,80 @@ static void coeff_get (sample_t * coeff, expbap_t * expbap,
|
||||
}
|
||||
|
||||
case -1:
|
||||
if (quantizer->q1_ptr >= 0) {
|
||||
coeff[i] = quantizer->q1[quantizer->q1_ptr--] * factor[exp[i]];
|
||||
if (quant->q1_ptr >= 0) {
|
||||
COEFF (coeff[i], quant->q1[quant->q1_ptr--], level,
|
||||
factor, exp[i]);
|
||||
continue;
|
||||
} else {
|
||||
int code;
|
||||
|
||||
code = bitstream_get (5);
|
||||
code = bitstream_get (state, 5);
|
||||
|
||||
quantizer->q1_ptr = 1;
|
||||
quantizer->q1[0] = q_1_2[code];
|
||||
quantizer->q1[1] = q_1_1[code];
|
||||
coeff[i] = q_1_0[code] * factor[exp[i]];
|
||||
quant->q1_ptr = 1;
|
||||
quant->q1[0] = q_1_2[code];
|
||||
quant->q1[1] = q_1_1[code];
|
||||
COEFF (coeff[i], q_1_0[code], level, factor, exp[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
case -2:
|
||||
if (quantizer->q2_ptr >= 0) {
|
||||
coeff[i] = quantizer->q2[quantizer->q2_ptr--] * factor[exp[i]];
|
||||
if (quant->q2_ptr >= 0) {
|
||||
COEFF (coeff[i], quant->q2[quant->q2_ptr--], level,
|
||||
factor, exp[i]);
|
||||
continue;
|
||||
} else {
|
||||
int code;
|
||||
|
||||
code = bitstream_get (7);
|
||||
code = bitstream_get (state, 7);
|
||||
|
||||
quantizer->q2_ptr = 1;
|
||||
quantizer->q2[0] = q_2_2[code];
|
||||
quantizer->q2[1] = q_2_1[code];
|
||||
coeff[i] = q_2_0[code] * factor[exp[i]];
|
||||
quant->q2_ptr = 1;
|
||||
quant->q2[0] = q_2_2[code];
|
||||
quant->q2[1] = q_2_1[code];
|
||||
COEFF (coeff[i], q_2_0[code], level, factor, exp[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
case 3:
|
||||
coeff[i] = q_3[bitstream_get (3)] * factor[exp[i]];
|
||||
COEFF (coeff[i], q_3[bitstream_get (state, 3)], level,
|
||||
factor, exp[i]);
|
||||
continue;
|
||||
|
||||
case -3:
|
||||
if (quantizer->q4_ptr == 0) {
|
||||
quantizer->q4_ptr = -1;
|
||||
coeff[i] = quantizer->q4 * factor[exp[i]];
|
||||
if (quant->q4_ptr == 0) {
|
||||
quant->q4_ptr = -1;
|
||||
COEFF (coeff[i], quant->q4, level, factor, exp[i]);
|
||||
continue;
|
||||
} else {
|
||||
int code;
|
||||
|
||||
code = bitstream_get (7);
|
||||
code = bitstream_get (state, 7);
|
||||
|
||||
quantizer->q4_ptr = 0;
|
||||
quantizer->q4 = q_4_1[code];
|
||||
coeff[i] = q_4_0[code] * factor[exp[i]];
|
||||
quant->q4_ptr = 0;
|
||||
quant->q4 = q_4_1[code];
|
||||
COEFF (coeff[i], q_4_0[code], level, factor, exp[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
case 4:
|
||||
coeff[i] = q_5[bitstream_get (4)] * factor[exp[i]];
|
||||
COEFF (coeff[i], q_5[bitstream_get (state, 4)], level,
|
||||
factor, exp[i]);
|
||||
continue;
|
||||
|
||||
default:
|
||||
coeff[i] = ((bitstream_get_2 (bapi) << (16 - bapi)) *
|
||||
factor[exp[i]]);
|
||||
COEFF (coeff[i], bitstream_get_2 (state, bapi) << (16 - bapi),
|
||||
level, factor, exp[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void coeff_get_coupling (a52_state_t * state, int nfchans,
|
||||
sample_t * coeff, sample_t (* samples)[256],
|
||||
quantizer_t * quantizer, uint8_t dithflag[5])
|
||||
level_t * coeff, sample_t (* samples)[256],
|
||||
quantizer_set_t * quant, uint8_t dithflag[5])
|
||||
{
|
||||
int cplbndstrc, bnd, i, i_end, ch;
|
||||
uint8_t * exp;
|
||||
int8_t * bap;
|
||||
sample_t cplco[5];
|
||||
level_t cplco[5];
|
||||
|
||||
exp = state->cpl_expbap.exp;
|
||||
bap = state->cpl_expbap.bap;
|
||||
@ -421,22 +454,26 @@ static void coeff_get_coupling (a52_state_t * state, int nfchans,
|
||||
}
|
||||
cplbndstrc >>= 1;
|
||||
for (ch = 0; ch < nfchans; ch++)
|
||||
cplco[ch] = state->cplco[ch][bnd] * coeff[ch];
|
||||
cplco[ch] = MUL_L (state->cplco[ch][bnd], coeff[ch]);
|
||||
bnd++;
|
||||
|
||||
while (i < i_end) {
|
||||
sample_t cplcoeff;
|
||||
quantizer_t cplcoeff;
|
||||
int bapi;
|
||||
|
||||
bapi = bap[i];
|
||||
switch (bapi) {
|
||||
case 0:
|
||||
cplcoeff = LEVEL_3DB * scale_factor[exp[i]];
|
||||
for (ch = 0; ch < nfchans; ch++)
|
||||
if ((state->chincpl >> ch) & 1) {
|
||||
if (dithflag[ch])
|
||||
samples[ch][i] = (cplcoeff * cplco[ch] *
|
||||
dither_gen ());
|
||||
#ifndef LIBA52_FIXED
|
||||
samples[ch][i] = (scale_factor[exp[i]] *
|
||||
cplco[ch] * dither_gen (state));
|
||||
#else
|
||||
COEFF (samples[ch][i], dither_gen (state),
|
||||
cplco[ch], scale_factor, exp[i]);
|
||||
#endif
|
||||
else
|
||||
samples[ch][i] = 0;
|
||||
}
|
||||
@ -444,69 +481,75 @@ static void coeff_get_coupling (a52_state_t * state, int nfchans,
|
||||
continue;
|
||||
|
||||
case -1:
|
||||
if (quantizer->q1_ptr >= 0) {
|
||||
cplcoeff = quantizer->q1[quantizer->q1_ptr--];
|
||||
if (quant->q1_ptr >= 0) {
|
||||
cplcoeff = quant->q1[quant->q1_ptr--];
|
||||
break;
|
||||
} else {
|
||||
int code;
|
||||
|
||||
code = bitstream_get (5);
|
||||
code = bitstream_get (state, 5);
|
||||
|
||||
quantizer->q1_ptr = 1;
|
||||
quantizer->q1[0] = q_1_2[code];
|
||||
quantizer->q1[1] = q_1_1[code];
|
||||
quant->q1_ptr = 1;
|
||||
quant->q1[0] = q_1_2[code];
|
||||
quant->q1[1] = q_1_1[code];
|
||||
cplcoeff = q_1_0[code];
|
||||
break;
|
||||
}
|
||||
|
||||
case -2:
|
||||
if (quantizer->q2_ptr >= 0) {
|
||||
cplcoeff = quantizer->q2[quantizer->q2_ptr--];
|
||||
if (quant->q2_ptr >= 0) {
|
||||
cplcoeff = quant->q2[quant->q2_ptr--];
|
||||
break;
|
||||
} else {
|
||||
int code;
|
||||
|
||||
code = bitstream_get (7);
|
||||
code = bitstream_get (state, 7);
|
||||
|
||||
quantizer->q2_ptr = 1;
|
||||
quantizer->q2[0] = q_2_2[code];
|
||||
quantizer->q2[1] = q_2_1[code];
|
||||
quant->q2_ptr = 1;
|
||||
quant->q2[0] = q_2_2[code];
|
||||
quant->q2[1] = q_2_1[code];
|
||||
cplcoeff = q_2_0[code];
|
||||
break;
|
||||
}
|
||||
|
||||
case 3:
|
||||
cplcoeff = q_3[bitstream_get (3)];
|
||||
cplcoeff = q_3[bitstream_get (state, 3)];
|
||||
break;
|
||||
|
||||
case -3:
|
||||
if (quantizer->q4_ptr == 0) {
|
||||
quantizer->q4_ptr = -1;
|
||||
cplcoeff = quantizer->q4;
|
||||
if (quant->q4_ptr == 0) {
|
||||
quant->q4_ptr = -1;
|
||||
cplcoeff = quant->q4;
|
||||
break;
|
||||
} else {
|
||||
int code;
|
||||
|
||||
code = bitstream_get (7);
|
||||
code = bitstream_get (state, 7);
|
||||
|
||||
quantizer->q4_ptr = 0;
|
||||
quantizer->q4 = q_4_1[code];
|
||||
quant->q4_ptr = 0;
|
||||
quant->q4 = q_4_1[code];
|
||||
cplcoeff = q_4_0[code];
|
||||
break;
|
||||
}
|
||||
|
||||
case 4:
|
||||
cplcoeff = q_5[bitstream_get (4)];
|
||||
cplcoeff = q_5[bitstream_get (state, 4)];
|
||||
break;
|
||||
|
||||
default:
|
||||
cplcoeff = bitstream_get_2 (bapi) << (16 - bapi);
|
||||
cplcoeff = bitstream_get_2 (state, bapi) << (16 - bapi);
|
||||
}
|
||||
|
||||
#ifndef LIBA52_FIXED
|
||||
cplcoeff *= scale_factor[exp[i]];
|
||||
#endif
|
||||
for (ch = 0; ch < nfchans; ch++)
|
||||
if ((state->chincpl >> ch) & 1)
|
||||
if ((state->chincpl >> ch) & 1)
|
||||
#ifndef LIBA52_FIXED
|
||||
samples[ch][i] = cplcoeff * cplco[ch];
|
||||
#else
|
||||
COEFF (samples[ch][i], cplcoeff, cplco[ch],
|
||||
scale_factor, exp[i]);
|
||||
#endif
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@ -519,40 +562,44 @@ int a52_block (a52_state_t * state)
|
||||
int i, nfchans, chaninfo;
|
||||
uint8_t cplexpstr, chexpstr[5], lfeexpstr, do_bit_alloc, done_cpl;
|
||||
uint8_t blksw[5], dithflag[5];
|
||||
sample_t coeff[5];
|
||||
level_t coeff[5];
|
||||
int chanbias;
|
||||
quantizer_t quantizer;
|
||||
quantizer_set_t quant;
|
||||
sample_t * samples;
|
||||
|
||||
nfchans = nfchans_tbl[state->acmod];
|
||||
|
||||
for (i = 0; i < nfchans; i++)
|
||||
blksw[i] = bitstream_get (1);
|
||||
blksw[i] = bitstream_get (state, 1);
|
||||
|
||||
for (i = 0; i < nfchans; i++)
|
||||
dithflag[i] = bitstream_get (1);
|
||||
dithflag[i] = bitstream_get (state, 1);
|
||||
|
||||
chaninfo = !state->acmod;
|
||||
do {
|
||||
if (bitstream_get (1)) { /* dynrnge */
|
||||
if (bitstream_get (state, 1)) { /* dynrnge */
|
||||
int dynrng;
|
||||
|
||||
dynrng = bitstream_get_2 (8);
|
||||
dynrng = bitstream_get_2 (state, 8);
|
||||
if (state->dynrnge) {
|
||||
sample_t range;
|
||||
level_t range;
|
||||
|
||||
#if !defined(LIBA52_FIXED)
|
||||
range = ((((dynrng & 0x1f) | 0x20) << 13) *
|
||||
scale_factor[3 - (dynrng >> 5)]);
|
||||
#else
|
||||
range = ((dynrng & 0x1f) | 0x20) << (21 + (dynrng >> 5));
|
||||
#endif
|
||||
if (state->dynrngcall)
|
||||
range = state->dynrngcall (range, state->dynrngdata);
|
||||
state->dynrng = state->level * range;
|
||||
state->dynrng = MUL_L (state->level, range);
|
||||
}
|
||||
}
|
||||
} while (chaninfo--);
|
||||
|
||||
if (bitstream_get (1)) { /* cplstre */
|
||||
if (bitstream_get (state, 1)) { /* cplstre */
|
||||
state->chincpl = 0;
|
||||
if (bitstream_get (1)) { /* cplinu */
|
||||
if (bitstream_get (state, 1)) { /* cplinu */
|
||||
static uint8_t bndtab[16] = {31, 35, 37, 39, 41, 42, 43, 44,
|
||||
45, 45, 46, 46, 47, 47, 48, 48};
|
||||
int cplbegf;
|
||||
@ -560,15 +607,15 @@ int a52_block (a52_state_t * state)
|
||||
int ncplsubnd;
|
||||
|
||||
for (i = 0; i < nfchans; i++)
|
||||
state->chincpl |= bitstream_get (1) << i;
|
||||
state->chincpl |= bitstream_get (state, 1) << i;
|
||||
switch (state->acmod) {
|
||||
case 0: case 1:
|
||||
return 1;
|
||||
case 2:
|
||||
state->phsflginu = bitstream_get (1);
|
||||
state->phsflginu = bitstream_get (state, 1);
|
||||
}
|
||||
cplbegf = bitstream_get (4);
|
||||
cplendf = bitstream_get (4);
|
||||
cplbegf = bitstream_get (state, 4);
|
||||
cplendf = bitstream_get (state, 4);
|
||||
|
||||
if (cplendf + 3 - cplbegf < 0)
|
||||
return 1;
|
||||
@ -579,7 +626,7 @@ int a52_block (a52_state_t * state)
|
||||
|
||||
state->cplbndstrc = 0;
|
||||
for (i = 0; i < ncplsubnd - 1; i++)
|
||||
if (bitstream_get (1)) {
|
||||
if (bitstream_get (state, 1)) {
|
||||
state->cplbndstrc |= 1 << i;
|
||||
state->ncplbnd--;
|
||||
}
|
||||
@ -592,47 +639,52 @@ int a52_block (a52_state_t * state)
|
||||
cplcoe = 0;
|
||||
for (i = 0; i < nfchans; i++)
|
||||
if ((state->chincpl) >> i & 1)
|
||||
if (bitstream_get (1)) { /* cplcoe */
|
||||
if (bitstream_get (state, 1)) { /* cplcoe */
|
||||
int mstrcplco, cplcoexp, cplcomant;
|
||||
|
||||
cplcoe = 1;
|
||||
mstrcplco = 3 * bitstream_get (2);
|
||||
mstrcplco = 3 * bitstream_get (state, 2);
|
||||
for (j = 0; j < state->ncplbnd; j++) {
|
||||
cplcoexp = bitstream_get (4);
|
||||
cplcomant = bitstream_get (4);
|
||||
cplcoexp = bitstream_get (state, 4);
|
||||
cplcomant = bitstream_get (state, 4);
|
||||
if (cplcoexp == 15)
|
||||
cplcomant <<= 14;
|
||||
else
|
||||
cplcomant = (cplcomant | 0x10) << 13;
|
||||
#ifndef LIBA52_FIXED
|
||||
state->cplco[i][j] =
|
||||
cplcomant * scale_factor[cplcoexp + mstrcplco];
|
||||
#else
|
||||
state->cplco[i][j] = (cplcomant << 11) >> (cplcoexp + mstrcplco);
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
if ((state->acmod == 2) && state->phsflginu && cplcoe)
|
||||
for (j = 0; j < state->ncplbnd; j++)
|
||||
if (bitstream_get (1)) /* phsflg */
|
||||
if (bitstream_get (state, 1)) /* phsflg */
|
||||
state->cplco[1][j] = -state->cplco[1][j];
|
||||
}
|
||||
|
||||
if ((state->acmod == 2) && (bitstream_get (1))) { /* rematstr */
|
||||
if ((state->acmod == 2) && (bitstream_get (state, 1))) { /* rematstr */
|
||||
int end;
|
||||
|
||||
state->rematflg = 0;
|
||||
end = (state->chincpl) ? state->cplstrtmant : 253; /* cplinu */
|
||||
i = 0;
|
||||
do
|
||||
state->rematflg |= bitstream_get (1) << i;
|
||||
state->rematflg |= bitstream_get (state, 1) << i;
|
||||
while (rematrix_band[i++] < end);
|
||||
}
|
||||
|
||||
cplexpstr = EXP_REUSE;
|
||||
lfeexpstr = EXP_REUSE;
|
||||
if (state->chincpl) /* cplinu */
|
||||
cplexpstr = bitstream_get (2);
|
||||
cplexpstr = bitstream_get (state, 2);
|
||||
for (i = 0; i < nfchans; i++)
|
||||
chexpstr[i] = bitstream_get (2);
|
||||
chexpstr[i] = bitstream_get (state, 2);
|
||||
if (state->lfeon)
|
||||
lfeexpstr = bitstream_get (1);
|
||||
lfeexpstr = bitstream_get (state, 1);
|
||||
|
||||
for (i = 0; i < nfchans; i++)
|
||||
if (chexpstr[i] != EXP_REUSE) {
|
||||
@ -641,7 +693,7 @@ int a52_block (a52_state_t * state)
|
||||
else {
|
||||
int chbwcod;
|
||||
|
||||
chbwcod = bitstream_get (6);
|
||||
chbwcod = bitstream_get (state, 6);
|
||||
if (chbwcod > 60)
|
||||
return 1;
|
||||
state->endmant[i] = chbwcod * 3 + 73;
|
||||
@ -656,8 +708,8 @@ int a52_block (a52_state_t * state)
|
||||
do_bit_alloc = 64;
|
||||
ncplgrps = ((state->cplendmant - state->cplstrtmant) /
|
||||
(3 << (cplexpstr - 1)));
|
||||
cplabsexp = bitstream_get (4) << 1;
|
||||
if (parse_exponents (cplexpstr, ncplgrps, cplabsexp,
|
||||
cplabsexp = bitstream_get (state, 4) << 1;
|
||||
if (parse_exponents (state, cplexpstr, ncplgrps, cplabsexp,
|
||||
state->cpl_expbap.exp + state->cplstrtmant))
|
||||
return 1;
|
||||
}
|
||||
@ -668,54 +720,54 @@ int a52_block (a52_state_t * state)
|
||||
do_bit_alloc |= 1 << i;
|
||||
grp_size = 3 << (chexpstr[i] - 1);
|
||||
nchgrps = (state->endmant[i] + grp_size - 4) / grp_size;
|
||||
state->fbw_expbap[i].exp[0] = bitstream_get (4);
|
||||
if (parse_exponents (chexpstr[i], nchgrps,
|
||||
state->fbw_expbap[i].exp[0] = bitstream_get (state, 4);
|
||||
if (parse_exponents (state, chexpstr[i], nchgrps,
|
||||
state->fbw_expbap[i].exp[0],
|
||||
state->fbw_expbap[i].exp + 1))
|
||||
return 1;
|
||||
bitstream_get (2); /* gainrng */
|
||||
bitstream_get (state, 2); /* gainrng */
|
||||
}
|
||||
if (lfeexpstr != EXP_REUSE) {
|
||||
do_bit_alloc |= 32;
|
||||
state->lfe_expbap.exp[0] = bitstream_get (4);
|
||||
if (parse_exponents (lfeexpstr, 2, state->lfe_expbap.exp[0],
|
||||
state->lfe_expbap.exp[0] = bitstream_get (state, 4);
|
||||
if (parse_exponents (state, lfeexpstr, 2, state->lfe_expbap.exp[0],
|
||||
state->lfe_expbap.exp + 1))
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (bitstream_get (1)) { /* baie */
|
||||
do_bit_alloc = -1;
|
||||
state->bai = bitstream_get (11);
|
||||
if (bitstream_get (state, 1)) { /* baie */
|
||||
do_bit_alloc = 127;
|
||||
state->bai = bitstream_get (state, 11);
|
||||
}
|
||||
if (bitstream_get (1)) { /* snroffste */
|
||||
do_bit_alloc = -1;
|
||||
state->csnroffst = bitstream_get (6);
|
||||
if (bitstream_get (state, 1)) { /* snroffste */
|
||||
do_bit_alloc = 127;
|
||||
state->csnroffst = bitstream_get (state, 6);
|
||||
if (state->chincpl) /* cplinu */
|
||||
state->cplba.bai = bitstream_get (7);
|
||||
state->cplba.bai = bitstream_get (state, 7);
|
||||
for (i = 0; i < nfchans; i++)
|
||||
state->ba[i].bai = bitstream_get (7);
|
||||
state->ba[i].bai = bitstream_get (state, 7);
|
||||
if (state->lfeon)
|
||||
state->lfeba.bai = bitstream_get (7);
|
||||
state->lfeba.bai = bitstream_get (state, 7);
|
||||
}
|
||||
if ((state->chincpl) && (bitstream_get (1))) { /* cplinu, cplleake */
|
||||
if ((state->chincpl) && (bitstream_get (state, 1))) { /* cplleake */
|
||||
do_bit_alloc |= 64;
|
||||
state->cplfleak = 9 - bitstream_get (3);
|
||||
state->cplsleak = 9 - bitstream_get (3);
|
||||
state->cplfleak = 9 - bitstream_get (state, 3);
|
||||
state->cplsleak = 9 - bitstream_get (state, 3);
|
||||
}
|
||||
|
||||
if (bitstream_get (1)) { /* deltbaie */
|
||||
do_bit_alloc = -1;
|
||||
if (bitstream_get (state, 1)) { /* deltbaie */
|
||||
do_bit_alloc = 127;
|
||||
if (state->chincpl) /* cplinu */
|
||||
state->cplba.deltbae = bitstream_get (2);
|
||||
state->cplba.deltbae = bitstream_get (state, 2);
|
||||
for (i = 0; i < nfchans; i++)
|
||||
state->ba[i].deltbae = bitstream_get (2);
|
||||
state->ba[i].deltbae = bitstream_get (state, 2);
|
||||
if (state->chincpl && /* cplinu */
|
||||
(state->cplba.deltbae == DELTA_BIT_NEW) &&
|
||||
parse_deltba (state->cplba.deltba))
|
||||
parse_deltba (state, state->cplba.deltba))
|
||||
return 1;
|
||||
for (i = 0; i < nfchans; i++)
|
||||
if ((state->ba[i].deltbae == DELTA_BIT_NEW) &&
|
||||
parse_deltba (state->ba[i].deltba))
|
||||
parse_deltba (state, state->ba[i].deltba))
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -745,10 +797,10 @@ int a52_block (a52_state_t * state)
|
||||
}
|
||||
}
|
||||
|
||||
if (bitstream_get (1)) { /* skiple */
|
||||
i = bitstream_get (9); /* skipl */
|
||||
if (bitstream_get (state, 1)) { /* skiple */
|
||||
i = bitstream_get (state, 9); /* skipl */
|
||||
while (i--)
|
||||
bitstream_get (8);
|
||||
bitstream_get (state, 8);
|
||||
}
|
||||
|
||||
samples = state->samples;
|
||||
@ -758,20 +810,20 @@ int a52_block (a52_state_t * state)
|
||||
chanbias = a52_downmix_coeff (coeff, state->acmod, state->output,
|
||||
state->dynrng, state->clev, state->slev);
|
||||
|
||||
quantizer.q1_ptr = quantizer.q2_ptr = quantizer.q4_ptr = -1;
|
||||
quant.q1_ptr = quant.q2_ptr = quant.q4_ptr = -1;
|
||||
done_cpl = 0;
|
||||
|
||||
for (i = 0; i < nfchans; i++) {
|
||||
int j;
|
||||
|
||||
coeff_get (samples + 256 * i, state->fbw_expbap +i, &quantizer,
|
||||
coeff_get (state, samples + 256 * i, state->fbw_expbap +i, &quant,
|
||||
coeff[i], dithflag[i], state->endmant[i]);
|
||||
|
||||
if ((state->chincpl >> i) & 1) {
|
||||
if (!done_cpl) {
|
||||
done_cpl = 1;
|
||||
coeff_get_coupling (state, nfchans, coeff,
|
||||
(sample_t (*)[256])samples, &quantizer,
|
||||
(sample_t (*)[256])samples, &quant,
|
||||
dithflag);
|
||||
}
|
||||
j = state->cplendmant;
|
||||
@ -814,14 +866,14 @@ int a52_block (a52_state_t * state)
|
||||
|
||||
if (state->lfeon) {
|
||||
if (state->output & A52_LFE) {
|
||||
coeff_get (samples - 256, &state->lfe_expbap, &quantizer,
|
||||
coeff_get (state, samples - 256, &state->lfe_expbap, &quant,
|
||||
state->dynrng, 0, 7);
|
||||
for (i = 7; i < 256; i++)
|
||||
(samples-256)[i] = 0;
|
||||
a52_imdct_512 (samples - 256, samples + 1536 - 256, state->bias);
|
||||
} else {
|
||||
/* just skip the LFE coefficients */
|
||||
coeff_get (samples + 1280, &state->lfe_expbap, &quantizer,
|
||||
coeff_get (state, samples + 1280, &state->lfe_expbap, &quant,
|
||||
0, 0, 7);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* tables.h
|
||||
* Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
|
||||
* 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.
|
||||
@ -46,42 +46,44 @@ static const int8_t exp_3[128] = {
|
||||
25,25,25
|
||||
};
|
||||
|
||||
#define Q0 ((-2 << 15) / 3.0)
|
||||
#define Q1 (0)
|
||||
#define Q2 ((2 << 15) / 3.0)
|
||||
#define Q(x) ROUND (32768.0 * x)
|
||||
|
||||
static const sample_t q_1_0[32] = {
|
||||
Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,
|
||||
Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,
|
||||
Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,
|
||||
0,0,0,0,0
|
||||
#define Q0 Q (-2/3)
|
||||
#define Q1 Q (0)
|
||||
#define Q2 Q (2/3)
|
||||
|
||||
static const quantizer_t q_1_0[32] = {
|
||||
Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0,
|
||||
Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1,
|
||||
Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2,
|
||||
0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
static const sample_t q_1_1[32] = {
|
||||
Q0,Q0,Q0,Q1,Q1,Q1,Q2,Q2,Q2,
|
||||
Q0,Q0,Q0,Q1,Q1,Q1,Q2,Q2,Q2,
|
||||
Q0,Q0,Q0,Q1,Q1,Q1,Q2,Q2,Q2,
|
||||
0,0,0,0,0
|
||||
static const quantizer_t q_1_1[32] = {
|
||||
Q0, Q0, Q0, Q1, Q1, Q1, Q2, Q2, Q2,
|
||||
Q0, Q0, Q0, Q1, Q1, Q1, Q2, Q2, Q2,
|
||||
Q0, Q0, Q0, Q1, Q1, Q1, Q2, Q2, Q2,
|
||||
0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
static const sample_t q_1_2[32] = {
|
||||
Q0,Q1,Q2,Q0,Q1,Q2,Q0,Q1,Q2,
|
||||
Q0,Q1,Q2,Q0,Q1,Q2,Q0,Q1,Q2,
|
||||
Q0,Q1,Q2,Q0,Q1,Q2,Q0,Q1,Q2,
|
||||
0,0,0,0,0
|
||||
static const quantizer_t q_1_2[32] = {
|
||||
Q0, Q1, Q2, Q0, Q1, Q2, Q0, Q1, Q2,
|
||||
Q0, Q1, Q2, Q0, Q1, Q2, Q0, Q1, Q2,
|
||||
Q0, Q1, Q2, Q0, Q1, Q2, Q0, Q1, Q2,
|
||||
0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
#undef Q0
|
||||
#undef Q1
|
||||
#undef Q2
|
||||
|
||||
#define Q0 ((-4 << 15) / 5.0)
|
||||
#define Q1 ((-2 << 15) / 5.0)
|
||||
#define Q2 (0)
|
||||
#define Q3 ((2 << 15) / 5.0)
|
||||
#define Q4 ((4 << 15) / 5.0)
|
||||
#define Q0 Q (-4/5)
|
||||
#define Q1 Q (-2/5)
|
||||
#define Q2 Q (0)
|
||||
#define Q3 Q (2/5)
|
||||
#define Q4 Q (4/5)
|
||||
|
||||
static const sample_t q_2_0[128] = {
|
||||
static const quantizer_t q_2_0[128] = {
|
||||
Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,
|
||||
Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,
|
||||
Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,
|
||||
@ -90,7 +92,7 @@ static const sample_t q_2_0[128] = {
|
||||
0,0,0
|
||||
};
|
||||
|
||||
static const sample_t q_2_1[128] = {
|
||||
static const quantizer_t q_2_1[128] = {
|
||||
Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4,
|
||||
Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4,
|
||||
Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4,
|
||||
@ -99,7 +101,7 @@ static const sample_t q_2_1[128] = {
|
||||
0,0,0
|
||||
};
|
||||
|
||||
static const sample_t q_2_2[128] = {
|
||||
static const quantizer_t q_2_2[128] = {
|
||||
Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,
|
||||
Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,
|
||||
Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,
|
||||
@ -114,24 +116,23 @@ static const sample_t q_2_2[128] = {
|
||||
#undef Q3
|
||||
#undef Q4
|
||||
|
||||
static const sample_t q_3[8] = {
|
||||
(-6 << 15)/7.0, (-4 << 15)/7.0, (-2 << 15)/7.0, 0,
|
||||
( 2 << 15)/7.0, ( 4 << 15)/7.0, ( 6 << 15)/7.0, 0
|
||||
static const quantizer_t q_3[8] = {
|
||||
Q (-6/7), Q (-4/7), Q (-2/7), Q (0), Q (2/7), Q (4/7), Q (6/7), 0
|
||||
};
|
||||
|
||||
#define Q0 ((-10 << 15) / 11.0)
|
||||
#define Q1 ((-8 << 15) / 11.0)
|
||||
#define Q2 ((-6 << 15) / 11.0)
|
||||
#define Q3 ((-4 << 15) / 11.0)
|
||||
#define Q4 ((-2 << 15) / 11.0)
|
||||
#define Q5 (0)
|
||||
#define Q6 ((2 << 15) / 11.0)
|
||||
#define Q7 ((4 << 15) / 11.0)
|
||||
#define Q8 ((6 << 15) / 11.0)
|
||||
#define Q9 ((8 << 15) / 11.0)
|
||||
#define QA ((10 << 15) / 11.0)
|
||||
#define Q0 Q (-10/11)
|
||||
#define Q1 Q (-8/11)
|
||||
#define Q2 Q (-6/11)
|
||||
#define Q3 Q (-4/11)
|
||||
#define Q4 Q (-2/11)
|
||||
#define Q5 Q (0)
|
||||
#define Q6 Q (2/11)
|
||||
#define Q7 Q (4/11)
|
||||
#define Q8 Q (6/11)
|
||||
#define Q9 Q (8/11)
|
||||
#define QA Q (10/11)
|
||||
|
||||
static const sample_t q_4_0[128] = {
|
||||
static const quantizer_t q_4_0[128] = {
|
||||
Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0,
|
||||
Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1,
|
||||
Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2,
|
||||
@ -146,7 +147,7 @@ static const sample_t q_4_0[128] = {
|
||||
0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
static const sample_t q_4_1[128] = {
|
||||
static const quantizer_t q_4_1[128] = {
|
||||
Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
|
||||
Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
|
||||
Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
|
||||
@ -173,15 +174,13 @@ static const sample_t q_4_1[128] = {
|
||||
#undef Q9
|
||||
#undef QA
|
||||
|
||||
static const sample_t q_5[16] = {
|
||||
(-14 << 15)/15.0,(-12 << 15)/15.0,(-10 << 15)/15.0,
|
||||
( -8 << 15)/15.0,( -6 << 15)/15.0,( -4 << 15)/15.0,
|
||||
( -2 << 15)/15.0, 0 ,( 2 << 15)/15.0,
|
||||
( 4 << 15)/15.0,( 6 << 15)/15.0,( 8 << 15)/15.0,
|
||||
( 10 << 15)/15.0,( 12 << 15)/15.0,( 14 << 15)/15.0,
|
||||
0
|
||||
static const quantizer_t q_5[16] = {
|
||||
Q (-14/15), Q (-12/15), Q (-10/15), Q (-8/15), Q (-6/15),
|
||||
Q (-4/15), Q (-2/15), Q (0), Q (2/15), Q (4/15),
|
||||
Q (6/15), Q (8/15), Q (10/15), Q (12/15), Q (14/15), 0
|
||||
};
|
||||
|
||||
#ifndef LIBA52_FIXED
|
||||
static const sample_t scale_factor[25] = {
|
||||
0.000030517578125,
|
||||
0.0000152587890625,
|
||||
@ -209,6 +208,7 @@ static const sample_t scale_factor[25] = {
|
||||
0.00000000000363797880709171295166015625,
|
||||
0.000000000001818989403545856475830078125
|
||||
};
|
||||
#endif
|
||||
|
||||
static const uint16_t dither_lut[256] = {
|
||||
0x0000, 0xa011, 0xe033, 0x4022, 0x6077, 0xc066, 0x8044, 0x2055,
|
||||
|
Loading…
Reference in New Issue
Block a user