00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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)
00029 #define DTS_SUBSUBFAMES_MAX (4)
00030 #define DTS_LFE_MAX (3)
00031
00032 struct dts_state_s {
00033
00034
00035 int frame_type;
00036 int samples_deficit;
00037 int crc_present;
00038 int sample_blocks;
00039 int frame_size;
00040 int amode;
00041 int sample_rate;
00042 int bit_rate;
00043
00044 int downmix;
00045 int dynrange;
00046 int timestamp;
00047 int aux_data;
00048 int hdcd;
00049 int ext_descr;
00050 int ext_coding;
00051 int aspf;
00052 int lfe;
00053 int predictor_history;
00054 int header_crc;
00055 int multirate_inter;
00056 int version;
00057 int copy_history;
00058 int source_pcm_res;
00059 int front_sum;
00060 int surround_sum;
00061 int dialog_norm;
00062
00063
00064 int subframes;
00065 int prim_channels;
00066
00067 int subband_activity[DTS_PRIM_CHANNELS_MAX];
00068
00069 int vq_start_subband[DTS_PRIM_CHANNELS_MAX];
00070
00071 int joint_intensity[DTS_PRIM_CHANNELS_MAX];
00072
00073 int transient_huffman[DTS_PRIM_CHANNELS_MAX];
00074
00075 int scalefactor_huffman[DTS_PRIM_CHANNELS_MAX];
00076
00077 int bitalloc_huffman[DTS_PRIM_CHANNELS_MAX];
00078
00079 int quant_index_huffman[DTS_PRIM_CHANNELS_MAX][DTS_ABITS_MAX];
00080
00081 float scalefactor_adj[DTS_PRIM_CHANNELS_MAX][DTS_ABITS_MAX];
00082
00083
00084 int subsubframes;
00085 int partial_samples;
00086
00087 int prediction_mode[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
00088
00089 int prediction_vq[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
00090
00091 int bitalloc[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
00092
00093 int transition_mode[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
00094
00095 int scale_factor[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS][2];
00096
00097 int joint_huff[DTS_PRIM_CHANNELS_MAX];
00098
00099 int joint_scale_factor[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
00100
00101 int downmix_coef[DTS_PRIM_CHANNELS_MAX][2];
00102
00103 int dynrange_coef;
00104
00105
00106 int high_freq_vq[DTS_PRIM_CHANNELS_MAX][DTS_SUBBANDS];
00107
00108
00109 double lfe_data[2*DTS_SUBSUBFAMES_MAX*DTS_LFE_MAX * 2 ];
00110 int lfe_scale_factor;
00111
00112
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
00118 level_t clev;
00119 level_t slev;
00120
00121 int output;
00122 level_t level;
00123 sample_t bias;
00124
00125 sample_t * samples;
00126 int downmixed;
00127
00128 int dynrnge;
00129 level_t dynrng;
00130 void * dynrngdata;
00131 level_t (* dynrngcall) (level_t range, void * dynrngdata);
00132
00133
00134 uint32_t * buffer_start;
00135 uint32_t bits_left;
00136 uint32_t current_word;
00137 int word_mode;
00138 int bigendian_mode;
00139
00140
00141 int current_subframe;
00142 int current_subsubframe;
00143
00144
00145 double cos_mod[544];
00146
00147
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
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