dts_internal.h

00001 /*
00002  * dts_internal.h
00003  * Copyright (C) 2004 Gildas Bazin <[email protected]>
00004  * Copyright (C) 2000-2003 Michel Lespinasse <[email protected]>
00005  * Copyright (C) 1999-2000 Aaron Holtzman <[email protected]>
00006  *
00007  * This file is part of dtsdec, a free DTS Coherent Acoustics stream decoder.
00008  * See http://www.videolan.org/dtsdec.html for updates.
00009  *
00010  * dtsdec is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * dtsdec is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  */
00024 
00025 #define DTS_SUBFRAMES_MAX (16)
00026 #define DTS_PRIM_CHANNELS_MAX (5)
00027 #define DTS_SUBBANDS (32)
00028 #define DTS_ABITS_MAX (32) /* Should be 28 */
00029 #define DTS_SUBSUBFAMES_MAX (4)
00030 #define DTS_LFE_MAX (3)
00031 
00032 struct dts_state_s {
00033 
00034     /* Frame header */
00035     int frame_type;             /* type of the current frame */
00036     int samples_deficit;        /* deficit sample count */
00037     int crc_present;            /* crc is present in the bitstream */
00038     int sample_blocks;          /* number of PCM sample blocks */
00039     int frame_size;             /* primary frame byte size */
00040     int amode;                  /* audio channels arrangement */
00041     int sample_rate;            /* audio sampling rate */
00042     int bit_rate;               /* transmission bit rate */
00043 
00044     int downmix;                /* embedded downmix enabled */
00045     int dynrange;               /* embedded dynamic range flag */
00046     int timestamp;              /* embedded time stamp flag */
00047     int aux_data;               /* auxiliary data flag */
00048     int hdcd;                   /* source material is mastered in HDCD */
00049     int ext_descr;              /* extension audio descriptor flag */
00050     int ext_coding;             /* extended coding flag */
00051     int aspf;                   /* audio sync word insertion flag */
00052     int lfe;                    /* low frequency effects flag */
00053     int predictor_history;      /* predictor history flag */
00054     int header_crc;             /* header crc check bytes */
00055     int multirate_inter;        /* multirate interpolator switch */
00056     int version;                /* encoder software revision */
00057     int copy_history;           /* copy history */
00058     int source_pcm_res;         /* source pcm resolution */
00059     int front_sum;              /* front sum/difference flag */
00060     int surround_sum;           /* surround sum/difference flag */
00061     int dialog_norm;            /* dialog normalisation parameter */
00062 
00063     /* Primary audio coding header */
00064     int subframes;              /* number of subframes */
00065     int prim_channels;          /* number of primary audio channels */
00066     /* subband activity count */
00067     int subband_activity[DTS_PRIM_CHANNELS_MAX];
00068     /* high frequency vq start subband */
00069     int vq_start_subband[DTS_PRIM_CHANNELS_MAX];
00070     /* joint intensity coding index */
00071     int joint_intensity[DTS_PRIM_CHANNELS_MAX];
00072     /* transient mode code book */
00073     int transient_huffman[DTS_PRIM_CHANNELS_MAX];
00074     /* scale factor code book */
00075     int scalefactor_huffman[DTS_PRIM_CHANNELS_MAX];
00076     /* bit allocation quantizer select */
00077     int bitalloc_huffman[DTS_PRIM_CHANNELS_MAX];
00078     /* quantization index codebook select */
00079     int quant_index_huffman[DTS_PRIM_CHANNELS_MAX][DTS_ABITS_MAX];
00080     /* scale factor adjustment */
00081     float scalefactor_adj[DTS_PRIM_CHANNELS_MAX][DTS_ABITS_MAX];
00082 
00083     /* Primary audio coding side information */
00084     int subsubframes;           /* number of subsubframes */
00085     int partial_samples;        /* partial subsubframe samples count */
00086     /* prediction mode (ADPCM used or not) */
00087     int prediction_mode[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
00088     /* prediction VQ coefs */
00089     int prediction_vq[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
00090     /* bit allocation index */
00091     int bitalloc[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
00092     /* transition mode (transients) */
00093     int transition_mode[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
00094     /* scale factors (2 if transient)*/
00095     int scale_factor[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS][2];
00096     /* joint subband scale factors codebook */
00097     int joint_huff[DTS_PRIM_CHANNELS_MAX];
00098     /* joint subband scale factors */
00099     int joint_scale_factor[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
00100     /* stereo downmix coefficients */
00101     int downmix_coef[DTS_PRIM_CHANNELS_MAX][2];
00102     /* dynamic range coefficient */
00103     int dynrange_coef;
00104 
00105     /* VQ encoded high frequency subbands */
00106     int high_freq_vq[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
00107 
00108     /* Low frequency effect data */
00109     double lfe_data[2*DTS_SUBSUBFAMES_MAX*DTS_LFE_MAX * 2 /*history*/];
00110     int lfe_scale_factor;
00111 
00112     /* Subband samples history (for ADPCM) */
00113     double subband_samples_hist[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS][4];
00114     double subband_fir_hist[DTS_PRIM_CHANNELS_MAX][512];
00115     double subband_fir_noidea[DTS_PRIM_CHANNELS_MAX][64];
00116 
00117     /* Audio output */
00118     level_t clev;            /* centre channel mix level */
00119     level_t slev;            /* surround channels mix level */
00120 
00121     int output;              /* type of output */
00122     level_t level;           /* output level */
00123     sample_t bias;           /* output bias */
00124 
00125     sample_t * samples;      /* pointer to the internal audio samples buffer */
00126     int downmixed;
00127 
00128     int dynrnge;             /* apply dynamic range */
00129     level_t dynrng;          /* dynamic range */
00130     void * dynrngdata;       /* dynamic range callback funtion and data */
00131     level_t (* dynrngcall) (level_t range, void * dynrngdata);
00132 
00133     /* Bitstream handling */
00134     uint32_t * buffer_start;
00135     uint32_t bits_left;
00136     uint32_t current_word;
00137     int      word_mode;         /* 16/14 bits word format (1 -> 16, 0 -> 14) */
00138     int      bigendian_mode;    /* endianness (1 -> be, 0 -> le) */
00139 
00140     /* Current position in DTS frame */
00141     int current_subframe;
00142     int current_subsubframe;
00143 
00144     /* Pre-calculated cosine modulation coefs for the QMF */
00145     double cos_mod[544];
00146 
00147     /* Debug flag */
00148     int debug_flag;
00149 };
00150 
00151 #define LEVEL_PLUS6DB 2.0
00152 #define LEVEL_PLUS3DB 1.4142135623730951
00153 #define LEVEL_3DB 0.7071067811865476
00154 #define LEVEL_45DB 0.5946035575013605
00155 #define LEVEL_6DB 0.5
00156 
00157 int dts_downmix_init (int input, int flags, level_t * level,
00158                       level_t clev, level_t slev);
00159 int dts_downmix_coeff (level_t * coeff, int acmod, int output, level_t level,
00160                        level_t clev, level_t slev);
00161 void dts_downmix (sample_t * samples, int acmod, int output, sample_t bias,
00162                   level_t clev, level_t slev);
00163 void dts_upmix (sample_t * samples, int acmod, int output);
00164 
00165 #define ROUND(x) ((int)((x) + ((x) > 0 ? 0.5 : -0.5)))
00166 
00167 #ifndef LIBDTS_FIXED
00168 
00169 typedef sample_t quantizer_t;
00170 #define SAMPLE(x) (x)
00171 #define LEVEL(x) (x)
00172 #define MUL(a,b) ((a) * (b))
00173 #define MUL_L(a,b) ((a) * (b))
00174 #define MUL_C(a,b) ((a) * (b))
00175 #define DIV(a,b) ((a) / (b))
00176 #define BIAS(x) ((x) + bias)
00177 
00178 #else /* LIBDTS_FIXED */
00179 
00180 typedef int16_t quantizer_t;
00181 #define SAMPLE(x) (sample_t)((x) * (1 << 30))
00182 #define LEVEL(x) (level_t)((x) * (1 << 26))
00183 
00184 #if 0
00185 #define MUL(a,b) ((int)(((int64_t)(a) * (b) + (1 << 29)) >> 30))
00186 #define MUL_L(a,b) ((int)(((int64_t)(a) * (b) + (1 << 25)) >> 26))
00187 #elif 1
00188 #define MUL(a,b) \
00189 ({ int32_t _ta=(a), _tb=(b), _tc; \
00190    _tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)(((_tc >> 14))+ (((_ta >> 16)*(_tb >> 16)) << 2 )); })
00191 #define MUL_L(a,b) \
00192 ({ int32_t _ta=(a), _tb=(b), _tc; \
00193    _tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)((_tc >> 10) + (((_ta >> 16)*(_tb >> 16)) << 6)); })
00194 #else
00195 #define MUL(a,b) (((a) >> 15) * ((b) >> 15))
00196 #define MUL_L(a,b) (((a) >> 13) * ((b) >> 13))
00197 #endif
00198 
00199 #define MUL_C(a,b) MUL_L (a, LEVEL (b))
00200 #define DIV(a,b) ((((int64_t)LEVEL (a)) << 26) / (b))
00201 #define BIAS(x) (x)
00202 
00203 #endif

Generated on Tue Dec 13 14:47:28 2005 for guliverkli by  doxygen 1.4.5