1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00
vdr/ac3dec/ac3_internal.h

354 lines
9.2 KiB
C
Raw Normal View History

2001-08-03 14:18:08 +02:00
/*
* ac3_internal.h
*
* Copyright (C) Aaron Holtzman - May 1999
*
* This file is part of ac3dec, a free Dolby AC-3 stream decoder.
*
* ac3dec 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, or (at your option)
* any later version.
*
* ac3dec 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 GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef __GNUC__
#define inline
#endif
2001-08-09 11:41:39 +02:00
#include <setjmp.h>
2001-08-03 14:18:08 +02:00
/* Exponent strategy constants */
#define EXP_REUSE (0)
#define EXP_D15 (1)
#define EXP_D25 (2)
#define EXP_D45 (3)
/* Delta bit allocation constants */
#define DELTA_BIT_REUSE (0)
#define DELTA_BIT_NEW (1)
#define DELTA_BIT_NONE (2)
#define DELTA_BIT_RESERVED (3)
/* samples work structure */
typedef float stream_samples_t[6][256];
/* global config structure */
extern ac3_config_t ac3_config;
/* global error flag */
2001-08-09 11:41:39 +02:00
extern jmp_buf error_jmp_mark;
#define HANDLE_ERROR() longjmp (error_jmp_mark, -1)
2001-08-03 14:18:08 +02:00
/* Everything you wanted to know about band structure */
/*
* The entire frequency domain is represented by 256 real
* floating point fourier coefficients. Only the lower 253
* coefficients are actually utilized however. We use arrays
* of 256 to be efficient in some cases.
*
* The 5 full bandwidth channels (fbw) can have their higher
* frequencies coupled together. These coupled channels then
* share their high frequency components.
*
* This coupling band is broken up into 18 sub-bands starting
* at mantissa number 37. Each sub-band is 12 bins wide.
*
* There are 50 bit allocation sub-bands which cover the entire
* frequency range. The sub-bands are of non-uniform width, and
* approximate a 1/6 octave scale.
*/
/* The following structures are filled in by their corresponding parse_*
* functions. See http://www.atsc.org/Standards/A52/a_52.pdf for
* full details on each field. Indented fields are used to denote
* conditional fields.
*/
typedef struct syncinfo_s
{
2001-08-09 11:41:39 +02:00
uint32_t magic;
2001-08-03 14:18:08 +02:00
/* Sync word == 0x0B77 */
2001-08-09 11:41:39 +02:00
uint16_t syncword;
2001-08-03 14:18:08 +02:00
/* crc for the first 5/8 of the sync block */
2001-08-09 11:41:39 +02:00
/* uint16_t crc1; */
2001-08-03 14:18:08 +02:00
/* Stream Sampling Rate (kHz) 0 = 48, 1 = 44.1, 2 = 32, 3 = reserved */
2001-08-09 11:41:39 +02:00
uint16_t fscod;
2001-08-03 14:18:08 +02:00
/* Frame size code */
2001-08-09 11:41:39 +02:00
uint16_t frmsizecod;
2001-08-03 14:18:08 +02:00
/* Information not in the AC-3 bitstream, but derived */
/* Frame size in 16 bit words */
2001-08-09 11:41:39 +02:00
uint16_t frame_size;
2001-08-03 14:18:08 +02:00
/* Bit rate in kilobits */
2001-08-09 11:41:39 +02:00
uint16_t bit_rate;
2001-08-03 14:18:08 +02:00
/* sampling rate in hertz */
2001-08-09 11:41:39 +02:00
uint32_t sampling_rate;
2001-08-03 14:18:08 +02:00
} syncinfo_t;
typedef struct bsi_s
{
2001-08-09 11:41:39 +02:00
uint32_t magic;
2001-08-03 14:18:08 +02:00
/* Bit stream identification == 0x8 */
2001-08-09 11:41:39 +02:00
uint16_t bsid;
2001-08-03 14:18:08 +02:00
/* Bit stream mode */
2001-08-09 11:41:39 +02:00
uint16_t bsmod;
2001-08-03 14:18:08 +02:00
/* Audio coding mode */
2001-08-09 11:41:39 +02:00
uint16_t acmod;
2001-08-03 14:18:08 +02:00
/* If we're using the centre channel then */
/* centre mix level */
2001-08-09 11:41:39 +02:00
uint16_t cmixlev;
2001-08-03 14:18:08 +02:00
/* If we're using the surround channel then */
/* surround mix level */
2001-08-09 11:41:39 +02:00
uint16_t surmixlev;
2001-08-03 14:18:08 +02:00
/* If we're in 2/0 mode then */
/* Dolby surround mix level - NOT USED - */
2001-08-09 11:41:39 +02:00
uint16_t dsurmod;
2001-08-03 14:18:08 +02:00
/* Low frequency effects on */
2001-08-09 11:41:39 +02:00
uint16_t lfeon;
2001-08-03 14:18:08 +02:00
/* Dialogue Normalization level */
2001-08-09 11:41:39 +02:00
uint16_t dialnorm;
2001-08-03 14:18:08 +02:00
/* Compression exists */
2001-08-09 11:41:39 +02:00
uint16_t compre;
2001-08-03 14:18:08 +02:00
/* Compression level */
2001-08-09 11:41:39 +02:00
uint16_t compr;
2001-08-03 14:18:08 +02:00
/* Language code exists */
2001-08-09 11:41:39 +02:00
uint16_t langcode;
2001-08-03 14:18:08 +02:00
/* Language code */
2001-08-09 11:41:39 +02:00
uint16_t langcod;
2001-08-03 14:18:08 +02:00
/* Audio production info exists*/
2001-08-09 11:41:39 +02:00
uint16_t audprodie;
uint16_t mixlevel;
uint16_t roomtyp;
2001-08-03 14:18:08 +02:00
/* If we're in dual mono mode (acmod == 0) then extra stuff */
2001-08-09 11:41:39 +02:00
uint16_t dialnorm2;
uint16_t compr2e;
uint16_t compr2;
uint16_t langcod2e;
uint16_t langcod2;
uint16_t audprodi2e;
uint16_t mixlevel2;
uint16_t roomtyp2;
2001-08-03 14:18:08 +02:00
/* Copyright bit */
2001-08-09 11:41:39 +02:00
uint16_t copyrightb;
2001-08-03 14:18:08 +02:00
/* Original bit */
2001-08-09 11:41:39 +02:00
uint16_t origbs;
2001-08-03 14:18:08 +02:00
/* Timecode 1 exists */
2001-08-09 11:41:39 +02:00
uint16_t timecod1e;
2001-08-03 14:18:08 +02:00
/* Timecode 1 */
2001-08-09 11:41:39 +02:00
uint16_t timecod1;
2001-08-03 14:18:08 +02:00
/* Timecode 2 exists */
2001-08-09 11:41:39 +02:00
uint16_t timecod2e;
2001-08-03 14:18:08 +02:00
/* Timecode 2 */
2001-08-09 11:41:39 +02:00
uint16_t timecod2;
2001-08-03 14:18:08 +02:00
/* Additional bit stream info exists */
2001-08-09 11:41:39 +02:00
uint16_t addbsie;
2001-08-03 14:18:08 +02:00
/* Additional bit stream length - 1 (in bytes) */
2001-08-09 11:41:39 +02:00
uint16_t addbsil;
2001-08-03 14:18:08 +02:00
/* Additional bit stream information (max 64 bytes) */
2001-08-09 11:41:39 +02:00
uint8_t addbsi[64];
2001-08-03 14:18:08 +02:00
/* Information not in the AC-3 bitstream, but derived */
/* Number of channels (excluding LFE)
* Derived from acmod */
2001-08-09 11:41:39 +02:00
uint16_t nfchans;
2001-08-03 14:18:08 +02:00
} bsi_t;
/* more pain */
typedef struct audblk_s
{
2001-08-09 11:41:39 +02:00
uint32_t magic1;
2001-08-03 14:18:08 +02:00
/* block switch bit indexed by channel num */
2001-08-09 11:41:39 +02:00
uint16_t blksw[5];
2001-08-03 14:18:08 +02:00
/* dither enable bit indexed by channel num */
2001-08-09 11:41:39 +02:00
uint16_t dithflag[5];
2001-08-03 14:18:08 +02:00
/* dynamic range gain exists */
2001-08-09 11:41:39 +02:00
uint16_t dynrnge;
2001-08-03 14:18:08 +02:00
/* dynamic range gain */
2001-08-09 11:41:39 +02:00
uint16_t dynrng;
2001-08-03 14:18:08 +02:00
/* if acmod==0 then */
/* dynamic range 2 gain exists */
2001-08-09 11:41:39 +02:00
uint16_t dynrng2e;
2001-08-03 14:18:08 +02:00
/* dynamic range 2 gain */
2001-08-09 11:41:39 +02:00
uint16_t dynrng2;
2001-08-03 14:18:08 +02:00
/* coupling strategy exists */
2001-08-09 11:41:39 +02:00
uint16_t cplstre;
2001-08-03 14:18:08 +02:00
/* coupling in use */
2001-08-09 11:41:39 +02:00
uint16_t cplinu;
2001-08-03 14:18:08 +02:00
/* channel coupled */
2001-08-09 11:41:39 +02:00
uint16_t chincpl[5];
2001-08-03 14:18:08 +02:00
/* if acmod==2 then */
/* Phase flags in use */
2001-08-09 11:41:39 +02:00
uint16_t phsflginu;
2001-08-03 14:18:08 +02:00
/* coupling begin frequency code */
2001-08-09 11:41:39 +02:00
uint16_t cplbegf;
2001-08-03 14:18:08 +02:00
/* coupling end frequency code */
2001-08-09 11:41:39 +02:00
uint16_t cplendf;
2001-08-03 14:18:08 +02:00
/* coupling band structure bits */
2001-08-09 11:41:39 +02:00
uint16_t cplbndstrc[18];
2001-08-03 14:18:08 +02:00
/* Do coupling co-ords exist for this channel? */
2001-08-09 11:41:39 +02:00
uint16_t cplcoe[5];
2001-08-03 14:18:08 +02:00
/* Master coupling co-ordinate */
2001-08-09 11:41:39 +02:00
uint16_t mstrcplco[5];
2001-08-03 14:18:08 +02:00
/* Per coupling band coupling co-ordinates */
2001-08-09 11:41:39 +02:00
uint16_t cplcoexp[5][18];
uint16_t cplcomant[5][18];
2001-08-03 14:18:08 +02:00
/* Phase flags for dual mono */
2001-08-09 11:41:39 +02:00
uint16_t phsflg[18];
2001-08-03 14:18:08 +02:00
/* Is there a rematrixing strategy */
2001-08-09 11:41:39 +02:00
uint16_t rematstr;
2001-08-03 14:18:08 +02:00
/* Rematrixing bits */
2001-08-09 11:41:39 +02:00
uint16_t rematflg[4];
2001-08-03 14:18:08 +02:00
/* Coupling exponent strategy */
2001-08-09 11:41:39 +02:00
uint16_t cplexpstr;
2001-08-03 14:18:08 +02:00
/* Exponent strategy for full bandwidth channels */
2001-08-09 11:41:39 +02:00
uint16_t chexpstr[5];
2001-08-03 14:18:08 +02:00
/* Exponent strategy for lfe channel */
2001-08-09 11:41:39 +02:00
uint16_t lfeexpstr;
2001-08-03 14:18:08 +02:00
/* Channel bandwidth for independent channels */
2001-08-09 11:41:39 +02:00
uint16_t chbwcod[5];
2001-08-03 14:18:08 +02:00
/* The absolute coupling exponent */
2001-08-09 11:41:39 +02:00
uint16_t cplabsexp;
2001-08-03 14:18:08 +02:00
/* Coupling channel exponents (D15 mode gives 18 * 12 /3 encoded exponents */
2001-08-09 11:41:39 +02:00
uint16_t cplexps[18 * 12 / 3];
2001-08-03 14:18:08 +02:00
/* Sanity checking constant */
2001-08-09 11:41:39 +02:00
uint32_t magic2;
2001-08-03 14:18:08 +02:00
/* fbw channel exponents */
2001-08-09 11:41:39 +02:00
uint16_t exps[5][252 / 3];
2001-08-03 14:18:08 +02:00
/* channel gain range */
2001-08-09 11:41:39 +02:00
uint16_t gainrng[5];
2001-08-03 14:18:08 +02:00
/* low frequency exponents */
2001-08-09 11:41:39 +02:00
uint16_t lfeexps[3];
2001-08-03 14:18:08 +02:00
/* Bit allocation info */
2001-08-09 11:41:39 +02:00
uint16_t baie;
2001-08-03 14:18:08 +02:00
/* Slow decay code */
2001-08-09 11:41:39 +02:00
uint16_t sdcycod;
2001-08-03 14:18:08 +02:00
/* Fast decay code */
2001-08-09 11:41:39 +02:00
uint16_t fdcycod;
2001-08-03 14:18:08 +02:00
/* Slow gain code */
2001-08-09 11:41:39 +02:00
uint16_t sgaincod;
2001-08-03 14:18:08 +02:00
/* dB per bit code */
2001-08-09 11:41:39 +02:00
uint16_t dbpbcod;
2001-08-03 14:18:08 +02:00
/* masking floor code */
2001-08-09 11:41:39 +02:00
uint16_t floorcod;
2001-08-03 14:18:08 +02:00
/* SNR offset info */
2001-08-09 11:41:39 +02:00
uint16_t snroffste;
2001-08-03 14:18:08 +02:00
/* coarse SNR offset */
2001-08-09 11:41:39 +02:00
uint16_t csnroffst;
2001-08-03 14:18:08 +02:00
/* coupling fine SNR offset */
2001-08-09 11:41:39 +02:00
uint16_t cplfsnroffst;
2001-08-03 14:18:08 +02:00
/* coupling fast gain code */
2001-08-09 11:41:39 +02:00
uint16_t cplfgaincod;
2001-08-03 14:18:08 +02:00
/* fbw fine SNR offset */
2001-08-09 11:41:39 +02:00
uint16_t fsnroffst[5];
2001-08-03 14:18:08 +02:00
/* fbw fast gain code */
2001-08-09 11:41:39 +02:00
uint16_t fgaincod[5];
2001-08-03 14:18:08 +02:00
/* lfe fine SNR offset */
2001-08-09 11:41:39 +02:00
uint16_t lfefsnroffst;
2001-08-03 14:18:08 +02:00
/* lfe fast gain code */
2001-08-09 11:41:39 +02:00
uint16_t lfefgaincod;
2001-08-03 14:18:08 +02:00
/* Coupling leak info */
2001-08-09 11:41:39 +02:00
uint16_t cplleake;
2001-08-03 14:18:08 +02:00
/* coupling fast leak initialization */
2001-08-09 11:41:39 +02:00
uint16_t cplfleak;
2001-08-03 14:18:08 +02:00
/* coupling slow leak initialization */
2001-08-09 11:41:39 +02:00
uint16_t cplsleak;
2001-08-03 14:18:08 +02:00
/* delta bit allocation info */
2001-08-09 11:41:39 +02:00
uint16_t deltbaie;
2001-08-03 14:18:08 +02:00
/* coupling delta bit allocation exists */
2001-08-09 11:41:39 +02:00
uint16_t cpldeltbae;
2001-08-03 14:18:08 +02:00
/* fbw delta bit allocation exists */
2001-08-09 11:41:39 +02:00
uint16_t deltbae[5];
2001-08-03 14:18:08 +02:00
/* number of cpl delta bit segments */
2001-08-09 11:41:39 +02:00
uint16_t cpldeltnseg;
2001-08-03 14:18:08 +02:00
/* coupling delta bit allocation offset */
2001-08-09 11:41:39 +02:00
uint16_t cpldeltoffst[8];
2001-08-03 14:18:08 +02:00
/* coupling delta bit allocation length */
2001-08-09 11:41:39 +02:00
uint16_t cpldeltlen[8];
2001-08-03 14:18:08 +02:00
/* coupling delta bit allocation length */
2001-08-09 11:41:39 +02:00
uint16_t cpldeltba[8];
2001-08-03 14:18:08 +02:00
/* number of delta bit segments */
2001-08-09 11:41:39 +02:00
uint16_t deltnseg[5];
2001-08-03 14:18:08 +02:00
/* fbw delta bit allocation offset */
2001-08-09 11:41:39 +02:00
uint16_t deltoffst[5][8];
2001-08-03 14:18:08 +02:00
/* fbw delta bit allocation length */
2001-08-09 11:41:39 +02:00
uint16_t deltlen[5][8];
2001-08-03 14:18:08 +02:00
/* fbw delta bit allocation length */
2001-08-09 11:41:39 +02:00
uint16_t deltba[5][8];
2001-08-03 14:18:08 +02:00
/* skip length exists */
2001-08-09 11:41:39 +02:00
uint16_t skiple;
2001-08-03 14:18:08 +02:00
/* skip length */
2001-08-09 11:41:39 +02:00
uint16_t skipl;
2001-08-03 14:18:08 +02:00
//Removed Feb 2000 -ah
2001-08-09 11:41:39 +02:00
//added Jul 2000 ++dent
2001-08-03 14:18:08 +02:00
/* channel mantissas */
2001-08-09 11:41:39 +02:00
uint16_t chmant[5][256];
2001-08-03 14:18:08 +02:00
/* coupling mantissas */
2001-08-09 11:41:39 +02:00
// uint16_t cplmant[256];
//Added Jun 2000 -MaXX
/* coupling floats */
float cpl_flt[ 256 ];
2001-08-03 14:18:08 +02:00
//Removed Feb 2000 -ah
2001-08-09 11:41:39 +02:00
//added Jul 2000 ++dent
2001-08-03 14:18:08 +02:00
/* coupling mantissas */
2001-08-09 11:41:39 +02:00
uint16_t lfemant[7];
2001-08-03 14:18:08 +02:00
/* -- Information not in the bitstream, but derived thereof -- */
/* Number of coupling sub-bands */
2001-08-09 11:41:39 +02:00
uint16_t ncplsubnd;
2001-08-03 14:18:08 +02:00
/* Number of combined coupling sub-bands
* Derived from ncplsubnd and cplbndstrc */
2001-08-09 11:41:39 +02:00
uint16_t ncplbnd;
2001-08-03 14:18:08 +02:00
/* Number of exponent groups by channel
* Derived from strmant, endmant */
2001-08-09 11:41:39 +02:00
uint16_t nchgrps[5];
2001-08-03 14:18:08 +02:00
/* Number of coupling exponent groups
* Derived from cplbegf, cplendf, cplexpstr */
2001-08-09 11:41:39 +02:00
uint16_t ncplgrps;
2001-08-03 14:18:08 +02:00
/* End mantissa numbers of fbw channels */
2001-08-09 11:41:39 +02:00
uint16_t endmant[5];
2001-08-03 14:18:08 +02:00
/* Start and end mantissa numbers for the coupling channel */
2001-08-09 11:41:39 +02:00
uint16_t cplstrtmant;
uint16_t cplendmant;
2001-08-03 14:18:08 +02:00
/* Decoded exponent info */
2001-08-09 11:41:39 +02:00
uint16_t fbw_exp[5][256];
uint16_t cpl_exp[256];
uint16_t lfe_exp[7];
2001-08-03 14:18:08 +02:00
/* Bit allocation pointer results */
2001-08-09 11:41:39 +02:00
uint16_t fbw_bap[5][256];
uint16_t cpl_bap[256];
uint16_t lfe_bap[7];
2001-08-03 14:18:08 +02:00
2001-08-09 11:41:39 +02:00
uint32_t magic3;
2001-08-03 14:18:08 +02:00
} audblk_t;