Mercurial > libavcodec.hg
annotate dca.c @ 11909:3bfcb8fd3dc9 libavcodec
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
Patch by Nick Brereton, nick at nbrereton dot net
| author | mstorsjo |
|---|---|
| date | Tue, 22 Jun 2010 08:33:00 +0000 |
| parents | 9b1095b2616a |
| children | 284f85e281fc |
| rev | line source |
|---|---|
| 4599 | 1 /* |
| 2 * DCA compatible decoder | |
| 3 * Copyright (C) 2004 Gildas Bazin | |
| 4 * Copyright (C) 2004 Benjamin Zores | |
| 5 * Copyright (C) 2006 Benjamin Larsson | |
| 6 * Copyright (C) 2007 Konstantin Shishkov | |
| 7 * | |
| 8 * This file is part of FFmpeg. | |
| 9 * | |
| 10 * FFmpeg is free software; you can redistribute it and/or | |
| 11 * modify it under the terms of the GNU Lesser General Public | |
| 12 * License as published by the Free Software Foundation; either | |
| 13 * version 2.1 of the License, or (at your option) any later version. | |
| 14 * | |
| 15 * FFmpeg is distributed in the hope that it will be useful, | |
| 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 18 * Lesser General Public License for more details. | |
| 19 * | |
| 20 * You should have received a copy of the GNU Lesser General Public | |
| 21 * License along with FFmpeg; if not, write to the Free Software | |
| 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 23 */ | |
| 24 | |
| 25 #include <math.h> | |
| 26 #include <stddef.h> | |
| 27 #include <stdio.h> | |
| 28 | |
| 11611 | 29 #include "libavutil/intmath.h" |
| 11606 | 30 #include "libavutil/intreadwrite.h" |
| 4599 | 31 #include "avcodec.h" |
| 32 #include "dsputil.h" | |
| 11370 | 33 #include "fft.h" |
| 9428 | 34 #include "get_bits.h" |
|
9411
4cb7c65fc775
Split bitstream.h, put the bitstream writer stuff in the new file
stefano
parents:
9393
diff
changeset
|
35 #include "put_bits.h" |
| 4599 | 36 #include "dcadata.h" |
| 37 #include "dcahuff.h" | |
| 4899 | 38 #include "dca.h" |
| 10467 | 39 #include "synth_filter.h" |
|
11617
bb17732c00ef
DCA: break out lfe_interpolation_fir() inner loops to a function
mru
parents:
11611
diff
changeset
|
40 #include "dcadsp.h" |
| 4599 | 41 |
| 42 //#define TRACE | |
| 43 | |
| 44 #define DCA_PRIM_CHANNELS_MAX (5) | |
| 45 #define DCA_SUBBANDS (32) | |
| 46 #define DCA_ABITS_MAX (32) /* Should be 28 */ | |
| 11898 | 47 #define DCA_SUBSUBFRAMES_MAX (4) |
|
11908
9b1095b2616a
Support DTS-ES extension (XCh) in dca: move subband_samples into context structure
mstorsjo
parents:
11898
diff
changeset
|
48 #define DCA_BLOCKS_MAX (16) |
| 4599 | 49 #define DCA_LFE_MAX (3) |
| 50 | |
| 51 enum DCAMode { | |
| 52 DCA_MONO = 0, | |
| 53 DCA_CHANNEL, | |
| 54 DCA_STEREO, | |
| 55 DCA_STEREO_SUMDIFF, | |
| 56 DCA_STEREO_TOTAL, | |
| 57 DCA_3F, | |
| 58 DCA_2F1R, | |
| 59 DCA_3F1R, | |
| 60 DCA_2F2R, | |
| 61 DCA_3F2R, | |
| 62 DCA_4F2R | |
| 63 }; | |
| 64 | |
| 8100 | 65 /* Tables for mapping dts channel configurations to libavcodec multichannel api. |
| 66 * Some compromises have been made for special configurations. Most configurations | |
| 67 * are never used so complete accuracy is not needed. | |
| 68 * | |
| 69 * L = left, R = right, C = center, S = surround, F = front, R = rear, T = total, OV = overhead. | |
| 8126 | 70 * S -> side, when both rear and back are configured move one of them to the side channel |
| 8100 | 71 * OV -> center back |
|
8102
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8101
diff
changeset
|
72 * All 2 channel configurations -> CH_LAYOUT_STEREO |
| 8100 | 73 */ |
| 74 | |
| 75 static const int64_t dca_core_channel_layout[] = { | |
|
8102
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8101
diff
changeset
|
76 CH_FRONT_CENTER, ///< 1, A |
|
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8101
diff
changeset
|
77 CH_LAYOUT_STEREO, ///< 2, A + B (dual mono) |
|
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8101
diff
changeset
|
78 CH_LAYOUT_STEREO, ///< 2, L + R (stereo) |
|
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8101
diff
changeset
|
79 CH_LAYOUT_STEREO, ///< 2, (L+R) + (L-R) (sum-difference) |
|
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8101
diff
changeset
|
80 CH_LAYOUT_STEREO, ///< 2, LT +RT (left and right total) |
| 8103 | 81 CH_LAYOUT_STEREO|CH_FRONT_CENTER, ///< 3, C+L+R |
| 82 CH_LAYOUT_STEREO|CH_BACK_CENTER, ///< 3, L+R+S | |
| 83 CH_LAYOUT_STEREO|CH_FRONT_CENTER|CH_BACK_CENTER, ///< 4, C + L + R+ S | |
| 84 CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_SIDE_RIGHT, ///< 4, L + R +SL+ SR | |
| 85 CH_LAYOUT_STEREO|CH_FRONT_CENTER|CH_SIDE_LEFT|CH_SIDE_RIGHT, ///< 5, C + L + R+ SL+SR | |
| 86 CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_SIDE_RIGHT|CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER, ///< 6, CL + CR + L + R + SL + SR | |
| 87 CH_LAYOUT_STEREO|CH_BACK_LEFT|CH_BACK_RIGHT|CH_FRONT_CENTER|CH_BACK_CENTER, ///< 6, C + L + R+ LR + RR + OV | |
| 88 CH_FRONT_CENTER|CH_FRONT_RIGHT_OF_CENTER|CH_FRONT_LEFT_OF_CENTER|CH_BACK_CENTER|CH_BACK_LEFT|CH_BACK_RIGHT, ///< 6, CF+ CR+LF+ RF+LR + RR | |
| 89 CH_FRONT_LEFT_OF_CENTER|CH_FRONT_CENTER|CH_FRONT_RIGHT_OF_CENTER|CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_SIDE_RIGHT, ///< 7, CL + C + CR + L + R + SL + SR | |
|
8102
04295cbc0e9b
Change multichannel API define prefix from "CHANNEL_" to "CH_".
andoma
parents:
8101
diff
changeset
|
90 CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER|CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_SIDE_RIGHT|CH_BACK_LEFT|CH_BACK_RIGHT, ///< 8, CL + CR + L + R + SL1 + SL2+ SR1 + SR2 |
| 8103 | 91 CH_FRONT_LEFT_OF_CENTER|CH_FRONT_CENTER|CH_FRONT_RIGHT_OF_CENTER|CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_BACK_CENTER|CH_SIDE_RIGHT, ///< 8, CL + C+ CR + L + R + SL + S+ SR |
| 8100 | 92 }; |
| 93 | |
|
8148
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
94 static const int8_t dca_lfe_index[] = { |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
95 1,2,2,2,2,3,2,3,2,3,2,3,1,3,2,3 |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
96 }; |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
97 |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
98 static const int8_t dca_channel_reorder_lfe[][8] = { |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
99 { 0, -1, -1, -1, -1, -1, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
100 { 0, 1, -1, -1, -1, -1, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
101 { 0, 1, -1, -1, -1, -1, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
102 { 0, 1, -1, -1, -1, -1, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
103 { 0, 1, -1, -1, -1, -1, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
104 { 2, 0, 1, -1, -1, -1, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
105 { 0, 1, 3, -1, -1, -1, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
106 { 2, 0, 1, 4, -1, -1, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
107 { 0, 1, 3, 4, -1, -1, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
108 { 2, 0, 1, 4, 5, -1, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
109 { 3, 4, 0, 1, 5, 6, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
110 { 2, 0, 1, 4, 5, 6, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
111 { 0, 6, 4, 5, 2, 3, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
112 { 4, 2, 5, 0, 1, 6, 7, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
113 { 5, 6, 0, 1, 7, 3, 8, 4}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
114 { 4, 2, 5, 0, 1, 6, 8, 7}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
115 }; |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
116 |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
117 static const int8_t dca_channel_reorder_nolfe[][8] = { |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
118 { 0, -1, -1, -1, -1, -1, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
119 { 0, 1, -1, -1, -1, -1, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
120 { 0, 1, -1, -1, -1, -1, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
121 { 0, 1, -1, -1, -1, -1, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
122 { 0, 1, -1, -1, -1, -1, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
123 { 2, 0, 1, -1, -1, -1, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
124 { 0, 1, 2, -1, -1, -1, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
125 { 2, 0, 1, 3, -1, -1, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
126 { 0, 1, 2, 3, -1, -1, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
127 { 2, 0, 1, 3, 4, -1, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
128 { 2, 3, 0, 1, 4, 5, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
129 { 2, 0, 1, 3, 4, 5, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
130 { 0, 5, 3, 4, 1, 2, -1, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
131 { 3, 2, 4, 0, 1, 5, 6, -1}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
132 { 4, 5, 0, 1, 6, 2, 7, 3}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
133 { 3, 2, 4, 0, 1, 5, 7, 6}, |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
134 }; |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
135 |
| 8100 | 136 |
| 4599 | 137 #define DCA_DOLBY 101 /* FIXME */ |
| 138 | |
| 139 #define DCA_CHANNEL_BITS 6 | |
| 140 #define DCA_CHANNEL_MASK 0x3F | |
| 141 | |
| 142 #define DCA_LFE 0x80 | |
| 143 | |
| 144 #define HEADER_SIZE 14 | |
| 145 | |
|
7670
dabe2516abe2
Increase buffer size to 16384 patch by Alexander E. Patrakov" patrakov gmail
michael
parents:
7451
diff
changeset
|
146 #define DCA_MAX_FRAME_SIZE 16384 |
| 4599 | 147 |
| 148 /** Bit allocation */ | |
| 149 typedef struct { | |
| 150 int offset; ///< code values offset | |
| 151 int maxbits[8]; ///< max bits in VLC | |
| 152 int wrap; ///< wrap for get_vlc2() | |
| 153 VLC vlc[8]; ///< actual codes | |
| 154 } BitAlloc; | |
| 155 | |
| 156 static BitAlloc dca_bitalloc_index; ///< indexes for samples VLC select | |
| 157 static BitAlloc dca_tmode; ///< transition mode VLCs | |
| 158 static BitAlloc dca_scalefactor; ///< scalefactor VLCs | |
| 159 static BitAlloc dca_smpl_bitalloc[11]; ///< samples VLCs | |
| 160 | |
|
4908
777f250df232
Fix multiple "?inline/static? is not at beginning of declaration" warnings.
diego
parents:
4899
diff
changeset
|
161 static av_always_inline int get_bitalloc(GetBitContext *gb, BitAlloc *ba, int idx) |
| 4599 | 162 { |
| 163 return get_vlc2(gb, ba->vlc[idx].table, ba->vlc[idx].bits, ba->wrap) + ba->offset; | |
| 164 } | |
| 165 | |
| 166 typedef struct { | |
| 167 AVCodecContext *avctx; | |
| 168 /* Frame header */ | |
| 169 int frame_type; ///< type of the current frame | |
| 170 int samples_deficit; ///< deficit sample count | |
| 171 int crc_present; ///< crc is present in the bitstream | |
| 172 int sample_blocks; ///< number of PCM sample blocks | |
| 173 int frame_size; ///< primary frame byte size | |
| 174 int amode; ///< audio channels arrangement | |
| 175 int sample_rate; ///< audio sampling rate | |
| 176 int bit_rate; ///< transmission bit rate | |
| 8077 | 177 int bit_rate_index; ///< transmission bit rate index |
| 4599 | 178 |
| 179 int downmix; ///< embedded downmix enabled | |
| 180 int dynrange; ///< embedded dynamic range flag | |
| 181 int timestamp; ///< embedded time stamp flag | |
| 182 int aux_data; ///< auxiliary data flag | |
| 183 int hdcd; ///< source material is mastered in HDCD | |
| 184 int ext_descr; ///< extension audio descriptor flag | |
| 185 int ext_coding; ///< extended coding flag | |
| 186 int aspf; ///< audio sync word insertion flag | |
| 187 int lfe; ///< low frequency effects flag | |
| 188 int predictor_history; ///< predictor history flag | |
| 189 int header_crc; ///< header crc check bytes | |
| 190 int multirate_inter; ///< multirate interpolator switch | |
| 191 int version; ///< encoder software revision | |
| 192 int copy_history; ///< copy history | |
| 193 int source_pcm_res; ///< source pcm resolution | |
| 194 int front_sum; ///< front sum/difference flag | |
| 195 int surround_sum; ///< surround sum/difference flag | |
| 196 int dialog_norm; ///< dialog normalisation parameter | |
| 197 | |
| 198 /* Primary audio coding header */ | |
| 199 int subframes; ///< number of subframes | |
| 6463 | 200 int total_channels; ///< number of channels including extensions |
| 4599 | 201 int prim_channels; ///< number of primary audio channels |
| 202 int subband_activity[DCA_PRIM_CHANNELS_MAX]; ///< subband activity count | |
| 203 int vq_start_subband[DCA_PRIM_CHANNELS_MAX]; ///< high frequency vq start subband | |
| 204 int joint_intensity[DCA_PRIM_CHANNELS_MAX]; ///< joint intensity coding index | |
| 205 int transient_huffman[DCA_PRIM_CHANNELS_MAX]; ///< transient mode code book | |
| 206 int scalefactor_huffman[DCA_PRIM_CHANNELS_MAX]; ///< scale factor code book | |
| 207 int bitalloc_huffman[DCA_PRIM_CHANNELS_MAX]; ///< bit allocation quantizer select | |
| 208 int quant_index_huffman[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]; ///< quantization index codebook select | |
| 209 float scalefactor_adj[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]; ///< scale factor adjustment | |
| 210 | |
| 211 /* Primary audio coding side information */ | |
| 212 int subsubframes; ///< number of subsubframes | |
| 213 int partial_samples; ///< partial subsubframe samples count | |
| 214 int prediction_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< prediction mode (ADPCM used or not) | |
| 215 int prediction_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< prediction VQ coefs | |
| 216 int bitalloc[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< bit allocation index | |
| 217 int transition_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< transition mode (transients) | |
| 218 int scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][2]; ///< scale factors (2 if transient) | |
| 219 int joint_huff[DCA_PRIM_CHANNELS_MAX]; ///< joint subband scale factors codebook | |
| 220 int joint_scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< joint subband scale factors | |
| 221 int downmix_coef[DCA_PRIM_CHANNELS_MAX][2]; ///< stereo downmix coefficients | |
| 222 int dynrange_coef; ///< dynamic range coefficient | |
| 223 | |
| 224 int high_freq_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< VQ encoded high frequency subbands | |
| 225 | |
|
11909
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
226 float lfe_data[2 * DCA_LFE_MAX * (DCA_BLOCKS_MAX + 4)]; ///< Low frequency effect data |
| 4599 | 227 int lfe_scale_factor; |
| 228 | |
| 229 /* Subband samples history (for ADPCM) */ | |
| 230 float subband_samples_hist[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][4]; | |
| 11369 | 231 DECLARE_ALIGNED(16, float, subband_fir_hist)[DCA_PRIM_CHANNELS_MAX][512]; |
| 11591 | 232 DECLARE_ALIGNED(16, float, subband_fir_noidea)[DCA_PRIM_CHANNELS_MAX][32]; |
| 7737 | 233 int hist_index[DCA_PRIM_CHANNELS_MAX]; |
| 11369 | 234 DECLARE_ALIGNED(16, float, raXin)[32]; |
| 4599 | 235 |
| 236 int output; ///< type of output | |
|
8062
17aeecee2a97
Fix dca decoder with non simd float2int16 conversion
banan
parents:
8061
diff
changeset
|
237 float add_bias; ///< output bias |
|
17aeecee2a97
Fix dca decoder with non simd float2int16 conversion
banan
parents:
8061
diff
changeset
|
238 float scale_bias; ///< output scale |
| 4599 | 239 |
|
11908
9b1095b2616a
Support DTS-ES extension (XCh) in dca: move subband_samples into context structure
mstorsjo
parents:
11898
diff
changeset
|
240 DECLARE_ALIGNED(16, float, subband_samples)[DCA_BLOCKS_MAX][DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][8]; |
| 11369 | 241 DECLARE_ALIGNED(16, float, samples)[1536]; /* 6 * 256 = 1536, might only need 5 */ |
| 7726 | 242 const float *samples_chanptr[6]; |
| 4599 | 243 |
| 244 uint8_t dca_buffer[DCA_MAX_FRAME_SIZE]; | |
| 245 int dca_buffer_size; ///< how much data is in the dca_buffer | |
| 246 | |
|
8148
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
247 const int8_t* channel_order_tab; ///< channel reordering table, lfe and non lfe |
| 4599 | 248 GetBitContext gb; |
| 249 /* Current position in DCA frame */ | |
| 250 int current_subframe; | |
| 251 int current_subsubframe; | |
| 252 | |
| 253 int debug_flag; ///< used for suppressing repeated error messages output | |
| 254 DSPContext dsp; | |
| 10199 | 255 FFTContext imdct; |
| 11592 | 256 SynthFilterContext synth; |
|
11617
bb17732c00ef
DCA: break out lfe_interpolation_fir() inner loops to a function
mru
parents:
11611
diff
changeset
|
257 DCADSPContext dcadsp; |
| 4599 | 258 } DCAContext; |
| 259 | |
|
9526
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
260 static const uint16_t dca_vlc_offs[] = { |
|
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
261 0, 512, 640, 768, 1282, 1794, 2436, 3080, 3770, 4454, 5364, |
|
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
262 5372, 5380, 5388, 5392, 5396, 5412, 5420, 5428, 5460, 5492, 5508, |
|
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
263 5572, 5604, 5668, 5796, 5860, 5892, 6412, 6668, 6796, 7308, 7564, |
|
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
264 7820, 8076, 8620, 9132, 9388, 9910, 10166, 10680, 11196, 11726, 12240, |
|
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
265 12752, 13298, 13810, 14326, 14840, 15500, 16022, 16540, 17158, 17678, 18264, |
|
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
266 18796, 19352, 19926, 20468, 21472, 22398, 23014, 23622, |
|
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
267 }; |
|
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
268 |
|
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6463
diff
changeset
|
269 static av_cold void dca_init_vlcs(void) |
| 4599 | 270 { |
| 6350 | 271 static int vlcs_initialized = 0; |
|
9526
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
272 int i, j, c = 14; |
|
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
273 static VLC_TYPE dca_table[23622][2]; |
| 4599 | 274 |
| 6350 | 275 if (vlcs_initialized) |
| 4599 | 276 return; |
| 277 | |
| 278 dca_bitalloc_index.offset = 1; | |
| 5070 | 279 dca_bitalloc_index.wrap = 2; |
|
9526
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
280 for (i = 0; i < 5; i++) { |
|
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
281 dca_bitalloc_index.vlc[i].table = &dca_table[dca_vlc_offs[i]]; |
|
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
282 dca_bitalloc_index.vlc[i].table_allocated = dca_vlc_offs[i + 1] - dca_vlc_offs[i]; |
| 4599 | 283 init_vlc(&dca_bitalloc_index.vlc[i], bitalloc_12_vlc_bits[i], 12, |
| 284 bitalloc_12_bits[i], 1, 1, | |
|
9526
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
285 bitalloc_12_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC); |
|
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
286 } |
| 4599 | 287 dca_scalefactor.offset = -64; |
| 288 dca_scalefactor.wrap = 2; | |
|
9526
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
289 for (i = 0; i < 5; i++) { |
|
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
290 dca_scalefactor.vlc[i].table = &dca_table[dca_vlc_offs[i + 5]]; |
|
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
291 dca_scalefactor.vlc[i].table_allocated = dca_vlc_offs[i + 6] - dca_vlc_offs[i + 5]; |
| 4599 | 292 init_vlc(&dca_scalefactor.vlc[i], SCALES_VLC_BITS, 129, |
| 293 scales_bits[i], 1, 1, | |
|
9526
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
294 scales_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC); |
|
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
295 } |
| 4599 | 296 dca_tmode.offset = 0; |
| 297 dca_tmode.wrap = 1; | |
|
9526
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
298 for (i = 0; i < 4; i++) { |
|
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
299 dca_tmode.vlc[i].table = &dca_table[dca_vlc_offs[i + 10]]; |
|
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
300 dca_tmode.vlc[i].table_allocated = dca_vlc_offs[i + 11] - dca_vlc_offs[i + 10]; |
| 4599 | 301 init_vlc(&dca_tmode.vlc[i], tmode_vlc_bits[i], 4, |
| 302 tmode_bits[i], 1, 1, | |
|
9526
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
303 tmode_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC); |
|
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
304 } |
| 4599 | 305 |
| 306 for(i = 0; i < 10; i++) | |
| 307 for(j = 0; j < 7; j++){ | |
| 308 if(!bitalloc_codes[i][j]) break; | |
| 309 dca_smpl_bitalloc[i+1].offset = bitalloc_offsets[i]; | |
| 310 dca_smpl_bitalloc[i+1].wrap = 1 + (j > 4); | |
|
9526
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
311 dca_smpl_bitalloc[i+1].vlc[j].table = &dca_table[dca_vlc_offs[c]]; |
|
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
312 dca_smpl_bitalloc[i+1].vlc[j].table_allocated = dca_vlc_offs[c + 1] - dca_vlc_offs[c]; |
| 4599 | 313 init_vlc(&dca_smpl_bitalloc[i+1].vlc[j], bitalloc_maxbits[i][j], |
| 314 bitalloc_sizes[i], | |
| 315 bitalloc_bits[i][j], 1, 1, | |
|
9526
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
316 bitalloc_codes[i][j], 2, 2, INIT_VLC_USE_NEW_STATIC); |
|
b9216a975c7f
Make VLC tables in DCA decoder use INIT_VLC_USE_NEW_STATIC
kostya
parents:
9428
diff
changeset
|
317 c++; |
| 4599 | 318 } |
| 6350 | 319 vlcs_initialized = 1; |
| 4599 | 320 } |
| 321 | |
| 322 static inline void get_array(GetBitContext *gb, int *dst, int len, int bits) | |
| 323 { | |
| 324 while(len--) | |
| 325 *dst++ = get_bits(gb, bits); | |
| 326 } | |
| 327 | |
|
11909
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
328 static int dca_parse_audio_coding_header(DCAContext * s) |
| 4599 | 329 { |
| 330 int i, j; | |
| 331 static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 }; | |
| 332 static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 }; | |
| 333 static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 }; | |
| 334 | |
|
11909
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
335 s->total_channels = get_bits(&s->gb, 3) + 1; |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
336 s->prim_channels = s->total_channels; |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
337 if (s->prim_channels > DCA_PRIM_CHANNELS_MAX) |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
338 s->prim_channels = DCA_PRIM_CHANNELS_MAX; /* We only support DTS core */ |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
339 |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
340 |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
341 for (i = 0; i < s->prim_channels; i++) { |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
342 s->subband_activity[i] = get_bits(&s->gb, 5) + 2; |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
343 if (s->subband_activity[i] > DCA_SUBBANDS) |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
344 s->subband_activity[i] = DCA_SUBBANDS; |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
345 } |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
346 for (i = 0; i < s->prim_channels; i++) { |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
347 s->vq_start_subband[i] = get_bits(&s->gb, 5) + 1; |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
348 if (s->vq_start_subband[i] > DCA_SUBBANDS) |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
349 s->vq_start_subband[i] = DCA_SUBBANDS; |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
350 } |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
351 get_array(&s->gb, s->joint_intensity, s->prim_channels, 3); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
352 get_array(&s->gb, s->transient_huffman, s->prim_channels, 2); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
353 get_array(&s->gb, s->scalefactor_huffman, s->prim_channels, 3); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
354 get_array(&s->gb, s->bitalloc_huffman, s->prim_channels, 3); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
355 |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
356 /* Get codebooks quantization indexes */ |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
357 memset(s->quant_index_huffman, 0, sizeof(s->quant_index_huffman)); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
358 for (j = 1; j < 11; j++) |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
359 for (i = 0; i < s->prim_channels; i++) |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
360 s->quant_index_huffman[i][j] = get_bits(&s->gb, bitlen[j]); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
361 |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
362 /* Get scale factor adjustment */ |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
363 for (j = 0; j < 11; j++) |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
364 for (i = 0; i < s->prim_channels; i++) |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
365 s->scalefactor_adj[i][j] = 1; |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
366 |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
367 for (j = 1; j < 11; j++) |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
368 for (i = 0; i < s->prim_channels; i++) |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
369 if (s->quant_index_huffman[i][j] < thr[j]) |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
370 s->scalefactor_adj[i][j] = adj_table[get_bits(&s->gb, 2)]; |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
371 |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
372 if (s->crc_present) { |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
373 /* Audio header CRC check */ |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
374 get_bits(&s->gb, 16); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
375 } |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
376 |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
377 s->current_subframe = 0; |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
378 s->current_subsubframe = 0; |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
379 |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
380 #ifdef TRACE |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
381 av_log(s->avctx, AV_LOG_DEBUG, "subframes: %i\n", s->subframes); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
382 av_log(s->avctx, AV_LOG_DEBUG, "prim channels: %i\n", s->prim_channels); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
383 for (i = 0; i < s->prim_channels; i++){ |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
384 av_log(s->avctx, AV_LOG_DEBUG, "subband activity: %i\n", s->subband_activity[i]); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
385 av_log(s->avctx, AV_LOG_DEBUG, "vq start subband: %i\n", s->vq_start_subband[i]); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
386 av_log(s->avctx, AV_LOG_DEBUG, "joint intensity: %i\n", s->joint_intensity[i]); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
387 av_log(s->avctx, AV_LOG_DEBUG, "transient mode codebook: %i\n", s->transient_huffman[i]); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
388 av_log(s->avctx, AV_LOG_DEBUG, "scale factor codebook: %i\n", s->scalefactor_huffman[i]); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
389 av_log(s->avctx, AV_LOG_DEBUG, "bit allocation quantizer: %i\n", s->bitalloc_huffman[i]); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
390 av_log(s->avctx, AV_LOG_DEBUG, "quant index huff:"); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
391 for (j = 0; j < 11; j++) |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
392 av_log(s->avctx, AV_LOG_DEBUG, " %i", |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
393 s->quant_index_huffman[i][j]); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
394 av_log(s->avctx, AV_LOG_DEBUG, "\n"); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
395 av_log(s->avctx, AV_LOG_DEBUG, "scalefac adj:"); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
396 for (j = 0; j < 11; j++) |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
397 av_log(s->avctx, AV_LOG_DEBUG, " %1.3f", s->scalefactor_adj[i][j]); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
398 av_log(s->avctx, AV_LOG_DEBUG, "\n"); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
399 } |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
400 #endif |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
401 |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
402 return 0; |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
403 } |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
404 |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
405 static int dca_parse_frame_header(DCAContext * s) |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
406 { |
| 4599 | 407 init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8); |
| 408 | |
| 409 /* Sync code */ | |
| 410 get_bits(&s->gb, 32); | |
| 411 | |
| 412 /* Frame header */ | |
| 413 s->frame_type = get_bits(&s->gb, 1); | |
| 414 s->samples_deficit = get_bits(&s->gb, 5) + 1; | |
| 415 s->crc_present = get_bits(&s->gb, 1); | |
| 416 s->sample_blocks = get_bits(&s->gb, 7) + 1; | |
| 417 s->frame_size = get_bits(&s->gb, 14) + 1; | |
| 418 if (s->frame_size < 95) | |
| 419 return -1; | |
| 420 s->amode = get_bits(&s->gb, 6); | |
| 421 s->sample_rate = dca_sample_rates[get_bits(&s->gb, 4)]; | |
| 422 if (!s->sample_rate) | |
| 423 return -1; | |
| 8078 | 424 s->bit_rate_index = get_bits(&s->gb, 5); |
| 8077 | 425 s->bit_rate = dca_bit_rates[s->bit_rate_index]; |
| 4599 | 426 if (!s->bit_rate) |
| 427 return -1; | |
| 428 | |
| 429 s->downmix = get_bits(&s->gb, 1); | |
| 430 s->dynrange = get_bits(&s->gb, 1); | |
| 431 s->timestamp = get_bits(&s->gb, 1); | |
| 432 s->aux_data = get_bits(&s->gb, 1); | |
| 433 s->hdcd = get_bits(&s->gb, 1); | |
| 434 s->ext_descr = get_bits(&s->gb, 3); | |
| 435 s->ext_coding = get_bits(&s->gb, 1); | |
| 436 s->aspf = get_bits(&s->gb, 1); | |
| 437 s->lfe = get_bits(&s->gb, 2); | |
| 438 s->predictor_history = get_bits(&s->gb, 1); | |
| 439 | |
| 440 /* TODO: check CRC */ | |
| 441 if (s->crc_present) | |
| 442 s->header_crc = get_bits(&s->gb, 16); | |
| 443 | |
| 444 s->multirate_inter = get_bits(&s->gb, 1); | |
| 445 s->version = get_bits(&s->gb, 4); | |
| 446 s->copy_history = get_bits(&s->gb, 2); | |
| 447 s->source_pcm_res = get_bits(&s->gb, 3); | |
| 448 s->front_sum = get_bits(&s->gb, 1); | |
| 449 s->surround_sum = get_bits(&s->gb, 1); | |
| 450 s->dialog_norm = get_bits(&s->gb, 4); | |
| 451 | |
| 452 /* FIXME: channels mixing levels */ | |
| 4893 | 453 s->output = s->amode; |
| 454 if(s->lfe) s->output |= DCA_LFE; | |
| 4599 | 455 |
| 456 #ifdef TRACE | |
| 457 av_log(s->avctx, AV_LOG_DEBUG, "frame type: %i\n", s->frame_type); | |
| 458 av_log(s->avctx, AV_LOG_DEBUG, "samples deficit: %i\n", s->samples_deficit); | |
| 459 av_log(s->avctx, AV_LOG_DEBUG, "crc present: %i\n", s->crc_present); | |
| 460 av_log(s->avctx, AV_LOG_DEBUG, "sample blocks: %i (%i samples)\n", | |
| 461 s->sample_blocks, s->sample_blocks * 32); | |
| 462 av_log(s->avctx, AV_LOG_DEBUG, "frame size: %i bytes\n", s->frame_size); | |
| 463 av_log(s->avctx, AV_LOG_DEBUG, "amode: %i (%i channels)\n", | |
| 464 s->amode, dca_channels[s->amode]); | |
| 8061 | 465 av_log(s->avctx, AV_LOG_DEBUG, "sample rate: %i Hz\n", |
| 466 s->sample_rate); | |
| 467 av_log(s->avctx, AV_LOG_DEBUG, "bit rate: %i bits/s\n", | |
| 468 s->bit_rate); | |
| 4599 | 469 av_log(s->avctx, AV_LOG_DEBUG, "downmix: %i\n", s->downmix); |
| 470 av_log(s->avctx, AV_LOG_DEBUG, "dynrange: %i\n", s->dynrange); | |
| 471 av_log(s->avctx, AV_LOG_DEBUG, "timestamp: %i\n", s->timestamp); | |
| 472 av_log(s->avctx, AV_LOG_DEBUG, "aux_data: %i\n", s->aux_data); | |
| 473 av_log(s->avctx, AV_LOG_DEBUG, "hdcd: %i\n", s->hdcd); | |
| 474 av_log(s->avctx, AV_LOG_DEBUG, "ext descr: %i\n", s->ext_descr); | |
| 475 av_log(s->avctx, AV_LOG_DEBUG, "ext coding: %i\n", s->ext_coding); | |
| 476 av_log(s->avctx, AV_LOG_DEBUG, "aspf: %i\n", s->aspf); | |
| 477 av_log(s->avctx, AV_LOG_DEBUG, "lfe: %i\n", s->lfe); | |
| 478 av_log(s->avctx, AV_LOG_DEBUG, "predictor history: %i\n", | |
| 479 s->predictor_history); | |
| 480 av_log(s->avctx, AV_LOG_DEBUG, "header crc: %i\n", s->header_crc); | |
| 481 av_log(s->avctx, AV_LOG_DEBUG, "multirate inter: %i\n", | |
| 482 s->multirate_inter); | |
| 483 av_log(s->avctx, AV_LOG_DEBUG, "version number: %i\n", s->version); | |
| 484 av_log(s->avctx, AV_LOG_DEBUG, "copy history: %i\n", s->copy_history); | |
| 485 av_log(s->avctx, AV_LOG_DEBUG, | |
| 486 "source pcm resolution: %i (%i bits/sample)\n", | |
| 487 s->source_pcm_res, dca_bits_per_sample[s->source_pcm_res]); | |
| 488 av_log(s->avctx, AV_LOG_DEBUG, "front sum: %i\n", s->front_sum); | |
| 489 av_log(s->avctx, AV_LOG_DEBUG, "surround sum: %i\n", s->surround_sum); | |
| 490 av_log(s->avctx, AV_LOG_DEBUG, "dialog norm: %i\n", s->dialog_norm); | |
| 491 av_log(s->avctx, AV_LOG_DEBUG, "\n"); | |
| 492 #endif | |
| 493 | |
| 494 /* Primary audio coding header */ | |
| 495 s->subframes = get_bits(&s->gb, 4) + 1; | |
| 496 | |
|
11909
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
497 return dca_parse_audio_coding_header(s); |
| 4599 | 498 } |
| 499 | |
| 500 | |
|
4876
384c95879d8b
1000l to myself as used VLC indexes were totally wrong
kostya
parents:
4783
diff
changeset
|
501 static inline int get_scale(GetBitContext *gb, int level, int value) |
| 4599 | 502 { |
| 503 if (level < 5) { | |
| 504 /* huffman encoded */ | |
|
4876
384c95879d8b
1000l to myself as used VLC indexes were totally wrong
kostya
parents:
4783
diff
changeset
|
505 value += get_bitalloc(gb, &dca_scalefactor, level); |
| 4599 | 506 } else if(level < 8) |
| 507 value = get_bits(gb, level + 1); | |
| 508 return value; | |
| 509 } | |
| 510 | |
|
11909
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
511 static int dca_subframe_header(DCAContext * s, int block_index) |
| 4599 | 512 { |
| 513 /* Primary audio coding side information */ | |
| 514 int j, k; | |
| 515 | |
| 516 s->subsubframes = get_bits(&s->gb, 2) + 1; | |
| 517 s->partial_samples = get_bits(&s->gb, 3); | |
| 518 for (j = 0; j < s->prim_channels; j++) { | |
| 519 for (k = 0; k < s->subband_activity[j]; k++) | |
| 520 s->prediction_mode[j][k] = get_bits(&s->gb, 1); | |
| 521 } | |
| 522 | |
| 523 /* Get prediction codebook */ | |
| 524 for (j = 0; j < s->prim_channels; j++) { | |
| 525 for (k = 0; k < s->subband_activity[j]; k++) { | |
| 526 if (s->prediction_mode[j][k] > 0) { | |
| 527 /* (Prediction coefficient VQ address) */ | |
| 528 s->prediction_vq[j][k] = get_bits(&s->gb, 12); | |
| 529 } | |
| 530 } | |
| 531 } | |
| 532 | |
| 533 /* Bit allocation index */ | |
| 534 for (j = 0; j < s->prim_channels; j++) { | |
| 535 for (k = 0; k < s->vq_start_subband[j]; k++) { | |
| 536 if (s->bitalloc_huffman[j] == 6) | |
| 537 s->bitalloc[j][k] = get_bits(&s->gb, 5); | |
| 538 else if (s->bitalloc_huffman[j] == 5) | |
| 539 s->bitalloc[j][k] = get_bits(&s->gb, 4); | |
| 6463 | 540 else if (s->bitalloc_huffman[j] == 7) { |
| 541 av_log(s->avctx, AV_LOG_ERROR, | |
| 542 "Invalid bit allocation index\n"); | |
| 543 return -1; | |
| 544 } else { | |
| 4599 | 545 s->bitalloc[j][k] = |
|
4876
384c95879d8b
1000l to myself as used VLC indexes were totally wrong
kostya
parents:
4783
diff
changeset
|
546 get_bitalloc(&s->gb, &dca_bitalloc_index, s->bitalloc_huffman[j]); |
| 4599 | 547 } |
| 548 | |
| 549 if (s->bitalloc[j][k] > 26) { | |
| 550 // av_log(s->avctx,AV_LOG_DEBUG,"bitalloc index [%i][%i] too big (%i)\n", | |
| 551 // j, k, s->bitalloc[j][k]); | |
| 552 return -1; | |
| 553 } | |
| 554 } | |
| 555 } | |
| 556 | |
| 557 /* Transition mode */ | |
| 558 for (j = 0; j < s->prim_channels; j++) { | |
| 559 for (k = 0; k < s->subband_activity[j]; k++) { | |
| 560 s->transition_mode[j][k] = 0; | |
| 561 if (s->subsubframes > 1 && | |
| 562 k < s->vq_start_subband[j] && s->bitalloc[j][k] > 0) { | |
| 563 s->transition_mode[j][k] = | |
| 564 get_bitalloc(&s->gb, &dca_tmode, s->transient_huffman[j]); | |
| 565 } | |
| 566 } | |
| 567 } | |
| 568 | |
| 569 for (j = 0; j < s->prim_channels; j++) { | |
| 6214 | 570 const uint32_t *scale_table; |
| 4599 | 571 int scale_sum; |
| 572 | |
| 573 memset(s->scale_factor[j], 0, s->subband_activity[j] * sizeof(s->scale_factor[0][0][0]) * 2); | |
| 574 | |
| 575 if (s->scalefactor_huffman[j] == 6) | |
| 6214 | 576 scale_table = scale_factor_quant7; |
| 4599 | 577 else |
| 6214 | 578 scale_table = scale_factor_quant6; |
| 4599 | 579 |
| 580 /* When huffman coded, only the difference is encoded */ | |
| 581 scale_sum = 0; | |
| 582 | |
| 583 for (k = 0; k < s->subband_activity[j]; k++) { | |
| 584 if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0) { | |
|
4876
384c95879d8b
1000l to myself as used VLC indexes were totally wrong
kostya
parents:
4783
diff
changeset
|
585 scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum); |
| 4599 | 586 s->scale_factor[j][k][0] = scale_table[scale_sum]; |
| 587 } | |
| 588 | |
| 589 if (k < s->vq_start_subband[j] && s->transition_mode[j][k]) { | |
| 590 /* Get second scale factor */ | |
|
4876
384c95879d8b
1000l to myself as used VLC indexes were totally wrong
kostya
parents:
4783
diff
changeset
|
591 scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum); |
| 4599 | 592 s->scale_factor[j][k][1] = scale_table[scale_sum]; |
| 593 } | |
| 594 } | |
| 595 } | |
| 596 | |
| 597 /* Joint subband scale factor codebook select */ | |
| 598 for (j = 0; j < s->prim_channels; j++) { | |
| 599 /* Transmitted only if joint subband coding enabled */ | |
| 600 if (s->joint_intensity[j] > 0) | |
| 601 s->joint_huff[j] = get_bits(&s->gb, 3); | |
| 602 } | |
| 603 | |
| 604 /* Scale factors for joint subband coding */ | |
| 605 for (j = 0; j < s->prim_channels; j++) { | |
| 606 int source_channel; | |
| 607 | |
| 608 /* Transmitted only if joint subband coding enabled */ | |
| 609 if (s->joint_intensity[j] > 0) { | |
| 610 int scale = 0; | |
| 611 source_channel = s->joint_intensity[j] - 1; | |
| 612 | |
| 613 /* When huffman coded, only the difference is encoded | |
| 614 * (is this valid as well for joint scales ???) */ | |
| 615 | |
| 616 for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++) { | |
|
4876
384c95879d8b
1000l to myself as used VLC indexes were totally wrong
kostya
parents:
4783
diff
changeset
|
617 scale = get_scale(&s->gb, s->joint_huff[j], 0); |
| 4599 | 618 scale += 64; /* bias */ |
| 619 s->joint_scale_factor[j][k] = scale; /*joint_scale_table[scale]; */ | |
| 620 } | |
| 621 | |
| 10380 | 622 if (!(s->debug_flag & 0x02)) { |
| 4599 | 623 av_log(s->avctx, AV_LOG_DEBUG, |
| 624 "Joint stereo coding not supported\n"); | |
| 625 s->debug_flag |= 0x02; | |
| 626 } | |
| 627 } | |
| 628 } | |
| 629 | |
| 630 /* Stereo downmix coefficients */ | |
| 4894 | 631 if (s->prim_channels > 2) { |
| 632 if(s->downmix) { | |
| 4895 | 633 for (j = 0; j < s->prim_channels; j++) { |
| 634 s->downmix_coef[j][0] = get_bits(&s->gb, 7); | |
| 635 s->downmix_coef[j][1] = get_bits(&s->gb, 7); | |
| 636 } | |
| 4894 | 637 } else { |
| 638 int am = s->amode & DCA_CHANNEL_MASK; | |
| 639 for (j = 0; j < s->prim_channels; j++) { | |
| 640 s->downmix_coef[j][0] = dca_default_coeffs[am][j][0]; | |
| 641 s->downmix_coef[j][1] = dca_default_coeffs[am][j][1]; | |
| 642 } | |
| 643 } | |
| 4599 | 644 } |
| 645 | |
| 646 /* Dynamic range coefficient */ | |
| 647 if (s->dynrange) | |
| 648 s->dynrange_coef = get_bits(&s->gb, 8); | |
| 649 | |
| 650 /* Side information CRC check word */ | |
| 651 if (s->crc_present) { | |
| 652 get_bits(&s->gb, 16); | |
| 653 } | |
| 654 | |
| 655 /* | |
| 656 * Primary audio data arrays | |
| 657 */ | |
| 658 | |
| 659 /* VQ encoded high frequency subbands */ | |
| 660 for (j = 0; j < s->prim_channels; j++) | |
| 661 for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++) | |
| 662 /* 1 vector -> 32 samples */ | |
| 663 s->high_freq_vq[j][k] = get_bits(&s->gb, 10); | |
| 664 | |
| 665 /* Low frequency effect data */ | |
| 666 if (s->lfe) { | |
| 667 /* LFE samples */ | |
|
11909
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
668 int lfe_samples = 2 * s->lfe * (4 + block_index); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
669 int lfe_end_sample = 2 * s->lfe * (4 + block_index + s->subsubframes); |
| 4599 | 670 float lfe_scale; |
| 671 | |
|
11909
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
672 for (j = lfe_samples; j < lfe_end_sample; j++) { |
| 4599 | 673 /* Signed 8 bits int */ |
| 674 s->lfe_data[j] = get_sbits(&s->gb, 8); | |
| 675 } | |
| 676 | |
| 677 /* Scale factor index */ | |
| 678 s->lfe_scale_factor = scale_factor_quant7[get_bits(&s->gb, 8)]; | |
| 679 | |
| 680 /* Quantization step size * scale factor */ | |
| 681 lfe_scale = 0.035 * s->lfe_scale_factor; | |
| 682 | |
|
11909
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
683 for (j = lfe_samples; j < lfe_end_sample; j++) |
| 4599 | 684 s->lfe_data[j] *= lfe_scale; |
| 685 } | |
| 686 | |
| 687 #ifdef TRACE | |
| 688 av_log(s->avctx, AV_LOG_DEBUG, "subsubframes: %i\n", s->subsubframes); | |
| 689 av_log(s->avctx, AV_LOG_DEBUG, "partial samples: %i\n", | |
| 690 s->partial_samples); | |
| 691 for (j = 0; j < s->prim_channels; j++) { | |
| 692 av_log(s->avctx, AV_LOG_DEBUG, "prediction mode:"); | |
| 693 for (k = 0; k < s->subband_activity[j]; k++) | |
| 694 av_log(s->avctx, AV_LOG_DEBUG, " %i", s->prediction_mode[j][k]); | |
| 695 av_log(s->avctx, AV_LOG_DEBUG, "\n"); | |
| 696 } | |
| 697 for (j = 0; j < s->prim_channels; j++) { | |
| 698 for (k = 0; k < s->subband_activity[j]; k++) | |
| 699 av_log(s->avctx, AV_LOG_DEBUG, | |
| 700 "prediction coefs: %f, %f, %f, %f\n", | |
| 701 (float) adpcm_vb[s->prediction_vq[j][k]][0] / 8192, | |
| 702 (float) adpcm_vb[s->prediction_vq[j][k]][1] / 8192, | |
| 703 (float) adpcm_vb[s->prediction_vq[j][k]][2] / 8192, | |
| 704 (float) adpcm_vb[s->prediction_vq[j][k]][3] / 8192); | |
| 705 } | |
| 706 for (j = 0; j < s->prim_channels; j++) { | |
| 707 av_log(s->avctx, AV_LOG_DEBUG, "bitalloc index: "); | |
| 708 for (k = 0; k < s->vq_start_subband[j]; k++) | |
| 709 av_log(s->avctx, AV_LOG_DEBUG, "%2.2i ", s->bitalloc[j][k]); | |
| 710 av_log(s->avctx, AV_LOG_DEBUG, "\n"); | |
| 711 } | |
| 712 for (j = 0; j < s->prim_channels; j++) { | |
| 713 av_log(s->avctx, AV_LOG_DEBUG, "Transition mode:"); | |
| 714 for (k = 0; k < s->subband_activity[j]; k++) | |
| 715 av_log(s->avctx, AV_LOG_DEBUG, " %i", s->transition_mode[j][k]); | |
| 716 av_log(s->avctx, AV_LOG_DEBUG, "\n"); | |
| 717 } | |
| 718 for (j = 0; j < s->prim_channels; j++) { | |
| 719 av_log(s->avctx, AV_LOG_DEBUG, "Scale factor:"); | |
| 720 for (k = 0; k < s->subband_activity[j]; k++) { | |
| 721 if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0) | |
| 722 av_log(s->avctx, AV_LOG_DEBUG, " %i", s->scale_factor[j][k][0]); | |
| 723 if (k < s->vq_start_subband[j] && s->transition_mode[j][k]) | |
| 724 av_log(s->avctx, AV_LOG_DEBUG, " %i(t)", s->scale_factor[j][k][1]); | |
| 725 } | |
| 726 av_log(s->avctx, AV_LOG_DEBUG, "\n"); | |
| 727 } | |
| 728 for (j = 0; j < s->prim_channels; j++) { | |
| 729 if (s->joint_intensity[j] > 0) { | |
| 5069 | 730 int source_channel = s->joint_intensity[j] - 1; |
| 4599 | 731 av_log(s->avctx, AV_LOG_DEBUG, "Joint scale factor index:\n"); |
| 732 for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++) | |
| 733 av_log(s->avctx, AV_LOG_DEBUG, " %i", s->joint_scale_factor[j][k]); | |
| 734 av_log(s->avctx, AV_LOG_DEBUG, "\n"); | |
| 735 } | |
| 736 } | |
| 737 if (s->prim_channels > 2 && s->downmix) { | |
| 738 av_log(s->avctx, AV_LOG_DEBUG, "Downmix coeffs:\n"); | |
| 739 for (j = 0; j < s->prim_channels; j++) { | |
| 740 av_log(s->avctx, AV_LOG_DEBUG, "Channel 0,%d = %f\n", j, dca_downmix_coeffs[s->downmix_coef[j][0]]); | |
| 741 av_log(s->avctx, AV_LOG_DEBUG, "Channel 1,%d = %f\n", j, dca_downmix_coeffs[s->downmix_coef[j][1]]); | |
| 742 } | |
| 743 av_log(s->avctx, AV_LOG_DEBUG, "\n"); | |
| 744 } | |
| 745 for (j = 0; j < s->prim_channels; j++) | |
| 746 for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++) | |
| 747 av_log(s->avctx, AV_LOG_DEBUG, "VQ index: %i\n", s->high_freq_vq[j][k]); | |
| 748 if(s->lfe){ | |
|
11909
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
749 int lfe_samples = 2 * s->lfe * (4 + block_index); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
750 int lfe_end_sample = 2 * s->lfe * (4 + block_index + s->subsubframes[s->current_subframe]); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
751 |
| 4599 | 752 av_log(s->avctx, AV_LOG_DEBUG, "LFE samples:\n"); |
|
11909
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
753 for (j = lfe_samples; j < lfe_end_sample; j++) |
| 4599 | 754 av_log(s->avctx, AV_LOG_DEBUG, " %f", s->lfe_data[j]); |
| 755 av_log(s->avctx, AV_LOG_DEBUG, "\n"); | |
| 756 } | |
| 757 #endif | |
| 758 | |
| 759 return 0; | |
| 760 } | |
| 761 | |
| 762 static void qmf_32_subbands(DCAContext * s, int chans, | |
| 763 float samples_in[32][8], float *samples_out, | |
| 764 float scale, float bias) | |
| 765 { | |
|
5974
ae05d6d12f12
Use the correct "const float *" type for variable instead of casting const away.
reimar
parents:
5645
diff
changeset
|
766 const float *prCoeff; |
| 10468 | 767 int i; |
| 4599 | 768 |
| 11607 | 769 int sb_act = s->subband_activity[chans]; |
|
7738
93ba37a9098c
Replace obfuscated mdct in qmf_32_subbands() by ff_imdct_half().
michael
parents:
7737
diff
changeset
|
770 int subindex; |
| 4599 | 771 |
|
7738
93ba37a9098c
Replace obfuscated mdct in qmf_32_subbands() by ff_imdct_half().
michael
parents:
7737
diff
changeset
|
772 scale *= sqrt(1/8.0); |
| 4599 | 773 |
| 774 /* Select filter */ | |
| 775 if (!s->multirate_inter) /* Non-perfect reconstruction */ | |
|
5974
ae05d6d12f12
Use the correct "const float *" type for variable instead of casting const away.
reimar
parents:
5645
diff
changeset
|
776 prCoeff = fir_32bands_nonperfect; |
| 4599 | 777 else /* Perfect reconstruction */ |
|
5974
ae05d6d12f12
Use the correct "const float *" type for variable instead of casting const away.
reimar
parents:
5645
diff
changeset
|
778 prCoeff = fir_32bands_perfect; |
| 4599 | 779 |
| 780 /* Reconstructed channel sample index */ | |
| 781 for (subindex = 0; subindex < 8; subindex++) { | |
| 782 /* Load in one sample from each subband and clear inactive subbands */ | |
| 11607 | 783 for (i = 0; i < sb_act; i++){ |
| 11606 | 784 uint32_t v = AV_RN32A(&samples_in[i][subindex]) ^ ((i-1)&2)<<30; |
| 785 AV_WN32A(&s->raXin[i], v); | |
|
7738
93ba37a9098c
Replace obfuscated mdct in qmf_32_subbands() by ff_imdct_half().
michael
parents:
7737
diff
changeset
|
786 } |
| 4599 | 787 for (; i < 32; i++) |
| 10152 | 788 s->raXin[i] = 0.0; |
| 4599 | 789 |
| 11592 | 790 s->synth.synth_filter_float(&s->imdct, |
| 10467 | 791 s->subband_fir_hist[chans], &s->hist_index[chans], |
| 792 s->subband_fir_noidea[chans], prCoeff, | |
| 793 samples_out, s->raXin, scale, bias); | |
|
7738
93ba37a9098c
Replace obfuscated mdct in qmf_32_subbands() by ff_imdct_half().
michael
parents:
7737
diff
changeset
|
794 samples_out+= 32; |
| 4599 | 795 |
| 796 } | |
| 797 } | |
| 798 | |
|
11617
bb17732c00ef
DCA: break out lfe_interpolation_fir() inner loops to a function
mru
parents:
11611
diff
changeset
|
799 static void lfe_interpolation_fir(DCAContext *s, int decimation_select, |
| 4599 | 800 int num_deci_sample, float *samples_in, |
| 801 float *samples_out, float scale, | |
| 802 float bias) | |
| 803 { | |
| 804 /* samples_in: An array holding decimated samples. | |
| 805 * Samples in current subframe starts from samples_in[0], | |
| 806 * while samples_in[-1], samples_in[-2], ..., stores samples | |
| 807 * from last subframe as history. | |
| 808 * | |
| 809 * samples_out: An array holding interpolated samples | |
| 810 */ | |
| 811 | |
|
11617
bb17732c00ef
DCA: break out lfe_interpolation_fir() inner loops to a function
mru
parents:
11611
diff
changeset
|
812 int decifactor; |
| 4599 | 813 const float *prCoeff; |
| 814 int deciindex; | |
| 815 | |
| 816 /* Select decimation filter */ | |
| 817 if (decimation_select == 1) { | |
| 11608 | 818 decifactor = 64; |
| 4599 | 819 prCoeff = lfe_fir_128; |
| 820 } else { | |
| 11608 | 821 decifactor = 32; |
| 4599 | 822 prCoeff = lfe_fir_64; |
| 823 } | |
| 824 /* Interpolation */ | |
| 825 for (deciindex = 0; deciindex < num_deci_sample; deciindex++) { | |
|
11617
bb17732c00ef
DCA: break out lfe_interpolation_fir() inner loops to a function
mru
parents:
11611
diff
changeset
|
826 s->dcadsp.lfe_fir(samples_out, samples_in, prCoeff, decifactor, |
|
bb17732c00ef
DCA: break out lfe_interpolation_fir() inner loops to a function
mru
parents:
11611
diff
changeset
|
827 scale, bias); |
| 11608 | 828 samples_in++; |
|
11617
bb17732c00ef
DCA: break out lfe_interpolation_fir() inner loops to a function
mru
parents:
11611
diff
changeset
|
829 samples_out += 2 * decifactor; |
| 4599 | 830 } |
| 831 } | |
| 832 | |
| 833 /* downmixing routines */ | |
| 4894 | 834 #define MIX_REAR1(samples, si1, rs, coef) \ |
| 835 samples[i] += samples[si1] * coef[rs][0]; \ | |
| 836 samples[i+256] += samples[si1] * coef[rs][1]; | |
| 4599 | 837 |
| 4894 | 838 #define MIX_REAR2(samples, si1, si2, rs, coef) \ |
| 839 samples[i] += samples[si1] * coef[rs][0] + samples[si2] * coef[rs+1][0]; \ | |
| 840 samples[i+256] += samples[si1] * coef[rs][1] + samples[si2] * coef[rs+1][1]; | |
| 4599 | 841 |
| 4894 | 842 #define MIX_FRONT3(samples, coef) \ |
| 4599 | 843 t = samples[i]; \ |
| 4894 | 844 samples[i] = t * coef[0][0] + samples[i+256] * coef[1][0] + samples[i+512] * coef[2][0]; \ |
| 845 samples[i+256] = t * coef[0][1] + samples[i+256] * coef[1][1] + samples[i+512] * coef[2][1]; | |
| 4599 | 846 |
| 847 #define DOWNMIX_TO_STEREO(op1, op2) \ | |
| 848 for(i = 0; i < 256; i++){ \ | |
| 849 op1 \ | |
| 850 op2 \ | |
| 851 } | |
| 852 | |
| 4894 | 853 static void dca_downmix(float *samples, int srcfmt, |
| 854 int downmix_coef[DCA_PRIM_CHANNELS_MAX][2]) | |
| 4599 | 855 { |
| 856 int i; | |
| 857 float t; | |
| 4894 | 858 float coef[DCA_PRIM_CHANNELS_MAX][2]; |
| 859 | |
| 860 for(i=0; i<DCA_PRIM_CHANNELS_MAX; i++) { | |
| 861 coef[i][0] = dca_downmix_coeffs[downmix_coef[i][0]]; | |
| 862 coef[i][1] = dca_downmix_coeffs[downmix_coef[i][1]]; | |
| 863 } | |
| 4599 | 864 |
| 865 switch (srcfmt) { | |
| 866 case DCA_MONO: | |
| 867 case DCA_CHANNEL: | |
| 868 case DCA_STEREO_TOTAL: | |
| 869 case DCA_STEREO_SUMDIFF: | |
| 870 case DCA_4F2R: | |
| 871 av_log(NULL, 0, "Not implemented!\n"); | |
| 872 break; | |
| 873 case DCA_STEREO: | |
| 874 break; | |
| 875 case DCA_3F: | |
| 4894 | 876 DOWNMIX_TO_STEREO(MIX_FRONT3(samples, coef),); |
| 4599 | 877 break; |
| 878 case DCA_2F1R: | |
| 4894 | 879 DOWNMIX_TO_STEREO(MIX_REAR1(samples, i + 512, 2, coef),); |
| 4599 | 880 break; |
| 881 case DCA_3F1R: | |
| 4894 | 882 DOWNMIX_TO_STEREO(MIX_FRONT3(samples, coef), |
| 883 MIX_REAR1(samples, i + 768, 3, coef)); | |
| 4599 | 884 break; |
| 885 case DCA_2F2R: | |
| 4894 | 886 DOWNMIX_TO_STEREO(MIX_REAR2(samples, i + 512, i + 768, 2, coef),); |
| 4599 | 887 break; |
| 888 case DCA_3F2R: | |
| 4894 | 889 DOWNMIX_TO_STEREO(MIX_FRONT3(samples, coef), |
| 890 MIX_REAR2(samples, i + 768, i + 1024, 3, coef)); | |
| 4599 | 891 break; |
| 892 } | |
| 893 } | |
| 894 | |
| 895 | |
| 896 /* Very compact version of the block code decoder that does not use table | |
| 897 * look-up but is slightly slower */ | |
| 898 static int decode_blockcode(int code, int levels, int *values) | |
| 899 { | |
| 900 int i; | |
| 901 int offset = (levels - 1) >> 1; | |
| 902 | |
| 903 for (i = 0; i < 4; i++) { | |
| 11611 | 904 int div = FASTDIV(code, levels); |
| 905 values[i] = code - offset - div*levels; | |
| 906 code = div; | |
| 4599 | 907 } |
| 908 | |
| 909 if (code == 0) | |
| 910 return 0; | |
| 911 else { | |
| 912 av_log(NULL, AV_LOG_ERROR, "ERROR: block code look-up failed\n"); | |
| 913 return -1; | |
| 914 } | |
| 915 } | |
| 916 | |
| 917 static const uint8_t abits_sizes[7] = { 7, 10, 12, 13, 15, 17, 19 }; | |
| 918 static const uint8_t abits_levels[7] = { 3, 5, 7, 9, 13, 17, 25 }; | |
| 919 | |
|
11908
9b1095b2616a
Support DTS-ES extension (XCh) in dca: move subband_samples into context structure
mstorsjo
parents:
11898
diff
changeset
|
920 static int dca_subsubframe(DCAContext * s, int block_index) |
| 4599 | 921 { |
| 922 int k, l; | |
| 923 int subsubframe = s->current_subsubframe; | |
| 924 | |
| 6214 | 925 const float *quant_step_table; |
| 4599 | 926 |
| 927 /* FIXME */ | |
|
11908
9b1095b2616a
Support DTS-ES extension (XCh) in dca: move subband_samples into context structure
mstorsjo
parents:
11898
diff
changeset
|
928 float (*subband_samples)[DCA_SUBBANDS][8] = s->subband_samples[block_index]; |
| 11625 | 929 LOCAL_ALIGNED_16(int, block, [8]); |
| 4599 | 930 |
| 931 /* | |
| 932 * Audio data | |
| 933 */ | |
| 934 | |
| 935 /* Select quantization step size table */ | |
| 8077 | 936 if (s->bit_rate_index == 0x1f) |
| 6214 | 937 quant_step_table = lossless_quant_d; |
| 4599 | 938 else |
| 6214 | 939 quant_step_table = lossy_quant_d; |
| 4599 | 940 |
| 941 for (k = 0; k < s->prim_channels; k++) { | |
| 942 for (l = 0; l < s->vq_start_subband[k]; l++) { | |
| 943 int m; | |
| 944 | |
| 945 /* Select the mid-tread linear quantizer */ | |
| 946 int abits = s->bitalloc[k][l]; | |
| 947 | |
| 948 float quant_step_size = quant_step_table[abits]; | |
| 949 | |
| 950 /* | |
| 951 * Determine quantization index code book and its type | |
| 952 */ | |
| 953 | |
| 954 /* Select quantization index code book */ | |
| 955 int sel = s->quant_index_huffman[k][abits]; | |
| 956 | |
| 957 /* | |
| 958 * Extract bits from the bit stream | |
| 959 */ | |
| 960 if(!abits){ | |
| 961 memset(subband_samples[k][l], 0, 8 * sizeof(subband_samples[0][0][0])); | |
| 11625 | 962 } else { |
| 963 /* Deal with transients */ | |
| 964 int sfi = s->transition_mode[k][l] && subsubframe >= s->transition_mode[k][l]; | |
| 965 float rscale = quant_step_size * s->scale_factor[k][l][sfi] * s->scalefactor_adj[k][sel]; | |
| 966 | |
| 967 if(abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].table){ | |
| 11626 | 968 if(abits <= 7){ |
| 969 /* Block code */ | |
| 970 int block_code1, block_code2, size, levels; | |
| 4599 | 971 |
| 11626 | 972 size = abits_sizes[abits-1]; |
| 973 levels = abits_levels[abits-1]; | |
| 4599 | 974 |
| 11626 | 975 block_code1 = get_bits(&s->gb, size); |
| 976 /* FIXME Should test return value */ | |
| 977 decode_blockcode(block_code1, levels, block); | |
| 978 block_code2 = get_bits(&s->gb, size); | |
| 979 decode_blockcode(block_code2, levels, &block[4]); | |
| 980 }else{ | |
| 981 /* no coding */ | |
| 982 for (m = 0; m < 8; m++) | |
| 983 block[m] = get_sbits(&s->gb, abits - 3); | |
| 984 } | |
| 4599 | 985 }else{ |
| 11626 | 986 /* Huffman coded */ |
| 4599 | 987 for (m = 0; m < 8; m++) |
| 11626 | 988 block[m] = get_bitalloc(&s->gb, &dca_smpl_bitalloc[abits], sel); |
| 4599 | 989 } |
| 990 | |
| 11625 | 991 s->dsp.int32_to_float_fmul_scalar(subband_samples[k][l], |
| 992 block, rscale, 8); | |
| 993 } | |
| 4599 | 994 |
| 995 /* | |
| 996 * Inverse ADPCM if in prediction mode | |
| 997 */ | |
| 998 if (s->prediction_mode[k][l]) { | |
| 999 int n; | |
| 1000 for (m = 0; m < 8; m++) { | |
| 1001 for (n = 1; n <= 4; n++) | |
| 1002 if (m >= n) | |
| 1003 subband_samples[k][l][m] += | |
| 1004 (adpcm_vb[s->prediction_vq[k][l]][n - 1] * | |
| 1005 subband_samples[k][l][m - n] / 8192); | |
| 1006 else if (s->predictor_history) | |
| 1007 subband_samples[k][l][m] += | |
| 1008 (adpcm_vb[s->prediction_vq[k][l]][n - 1] * | |
| 1009 s->subband_samples_hist[k][l][m - n + | |
| 1010 4] / 8192); | |
| 1011 } | |
| 1012 } | |
| 1013 } | |
| 1014 | |
| 1015 /* | |
| 1016 * Decode VQ encoded high frequencies | |
| 1017 */ | |
| 1018 for (l = s->vq_start_subband[k]; l < s->subband_activity[k]; l++) { | |
| 1019 /* 1 vector -> 32 samples but we only need the 8 samples | |
| 1020 * for this subsubframe. */ | |
| 1021 int m; | |
| 1022 | |
| 1023 if (!s->debug_flag & 0x01) { | |
| 1024 av_log(s->avctx, AV_LOG_DEBUG, "Stream with high frequencies VQ coding\n"); | |
| 1025 s->debug_flag |= 0x01; | |
| 1026 } | |
| 1027 | |
| 1028 for (m = 0; m < 8; m++) { | |
| 1029 subband_samples[k][l][m] = | |
| 1030 high_freq_vq[s->high_freq_vq[k][l]][subsubframe * 8 + | |
| 1031 m] | |
| 1032 * (float) s->scale_factor[k][l][0] / 16.0; | |
| 1033 } | |
| 1034 } | |
| 1035 } | |
| 1036 | |
| 1037 /* Check for DSYNC after subsubframe */ | |
| 1038 if (s->aspf || subsubframe == s->subsubframes - 1) { | |
| 1039 if (0xFFFF == get_bits(&s->gb, 16)) { /* 0xFFFF */ | |
| 1040 #ifdef TRACE | |
| 1041 av_log(s->avctx, AV_LOG_DEBUG, "Got subframe DSYNC\n"); | |
| 1042 #endif | |
| 1043 } else { | |
| 1044 av_log(s->avctx, AV_LOG_ERROR, "Didn't get subframe DSYNC\n"); | |
| 1045 } | |
| 1046 } | |
| 1047 | |
| 1048 /* Backup predictor history for adpcm */ | |
| 1049 for (k = 0; k < s->prim_channels; k++) | |
| 1050 for (l = 0; l < s->vq_start_subband[k]; l++) | |
| 1051 memcpy(s->subband_samples_hist[k][l], &subband_samples[k][l][4], | |
| 1052 4 * sizeof(subband_samples[0][0][0])); | |
| 1053 | |
|
11909
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1054 return 0; |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1055 } |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1056 |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1057 static int dca_filter_channels(DCAContext * s, int block_index) |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1058 { |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1059 float (*subband_samples)[DCA_SUBBANDS][8] = s->subband_samples[block_index]; |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1060 int k; |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1061 |
| 4599 | 1062 /* 32 subbands QMF */ |
| 1063 for (k = 0; k < s->prim_channels; k++) { | |
| 1064 /* static float pcm_to_double[8] = | |
| 1065 {32768.0, 32768.0, 524288.0, 524288.0, 0, 8388608.0, 8388608.0};*/ | |
|
8148
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
1066 qmf_32_subbands(s, k, subband_samples[k], &s->samples[256 * s->channel_order_tab[k]], |
|
8062
17aeecee2a97
Fix dca decoder with non simd float2int16 conversion
banan
parents:
8061
diff
changeset
|
1067 M_SQRT1_2*s->scale_bias /*pcm_to_double[s->source_pcm_res] */ , |
|
17aeecee2a97
Fix dca decoder with non simd float2int16 conversion
banan
parents:
8061
diff
changeset
|
1068 s->add_bias ); |
| 4599 | 1069 } |
| 1070 | |
| 1071 /* Down mixing */ | |
|
11909
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1072 if (s->avctx->request_channels == 2 && s->prim_channels > 2) { |
| 4894 | 1073 dca_downmix(s->samples, s->amode, s->downmix_coef); |
| 4599 | 1074 } |
| 1075 | |
| 1076 /* Generate LFE samples for this subsubframe FIXME!!! */ | |
| 1077 if (s->output & DCA_LFE) { | |
|
11617
bb17732c00ef
DCA: break out lfe_interpolation_fir() inner loops to a function
mru
parents:
11611
diff
changeset
|
1078 lfe_interpolation_fir(s, s->lfe, 2 * s->lfe, |
|
11909
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1079 s->lfe_data + 2 * s->lfe * (block_index + 4), |
|
8148
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
1080 &s->samples[256 * dca_lfe_index[s->amode]], |
|
8062
17aeecee2a97
Fix dca decoder with non simd float2int16 conversion
banan
parents:
8061
diff
changeset
|
1081 (1.0/256.0)*s->scale_bias, s->add_bias); |
| 4599 | 1082 /* Outputs 20bits pcm samples */ |
| 1083 } | |
| 1084 | |
| 1085 return 0; | |
| 1086 } | |
| 1087 | |
| 1088 | |
| 1089 static int dca_subframe_footer(DCAContext * s) | |
| 1090 { | |
| 1091 int aux_data_count = 0, i; | |
| 1092 | |
| 1093 /* | |
| 1094 * Unpack optional information | |
| 1095 */ | |
| 1096 | |
| 1097 if (s->timestamp) | |
| 1098 get_bits(&s->gb, 32); | |
| 1099 | |
| 1100 if (s->aux_data) | |
| 1101 aux_data_count = get_bits(&s->gb, 6); | |
| 1102 | |
| 1103 for (i = 0; i < aux_data_count; i++) | |
| 1104 get_bits(&s->gb, 8); | |
| 1105 | |
| 1106 if (s->crc_present && (s->downmix || s->dynrange)) | |
| 1107 get_bits(&s->gb, 16); | |
| 1108 | |
| 1109 return 0; | |
| 1110 } | |
| 1111 | |
| 1112 /** | |
| 1113 * Decode a dca frame block | |
| 1114 * | |
| 1115 * @param s pointer to the DCAContext | |
| 1116 */ | |
| 1117 | |
|
11908
9b1095b2616a
Support DTS-ES extension (XCh) in dca: move subband_samples into context structure
mstorsjo
parents:
11898
diff
changeset
|
1118 static int dca_decode_block(DCAContext * s, int block_index) |
| 4599 | 1119 { |
| 1120 | |
| 1121 /* Sanity check */ | |
| 1122 if (s->current_subframe >= s->subframes) { | |
| 1123 av_log(s->avctx, AV_LOG_DEBUG, "check failed: %i>%i", | |
| 1124 s->current_subframe, s->subframes); | |
| 1125 return -1; | |
| 1126 } | |
| 1127 | |
| 1128 if (!s->current_subsubframe) { | |
| 1129 #ifdef TRACE | |
| 1130 av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subframe_header\n"); | |
| 1131 #endif | |
| 1132 /* Read subframe header */ | |
|
11909
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1133 if (dca_subframe_header(s, block_index)) |
| 4599 | 1134 return -1; |
| 1135 } | |
| 1136 | |
| 1137 /* Read subsubframe */ | |
| 1138 #ifdef TRACE | |
| 1139 av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subsubframe\n"); | |
| 1140 #endif | |
|
11908
9b1095b2616a
Support DTS-ES extension (XCh) in dca: move subband_samples into context structure
mstorsjo
parents:
11898
diff
changeset
|
1141 if (dca_subsubframe(s, block_index)) |
| 4599 | 1142 return -1; |
| 1143 | |
| 1144 /* Update state */ | |
| 1145 s->current_subsubframe++; | |
| 1146 if (s->current_subsubframe >= s->subsubframes) { | |
| 1147 s->current_subsubframe = 0; | |
| 1148 s->current_subframe++; | |
| 1149 } | |
| 1150 if (s->current_subframe >= s->subframes) { | |
| 1151 #ifdef TRACE | |
| 1152 av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subframe_footer\n"); | |
| 1153 #endif | |
| 1154 /* Read subframe footer */ | |
| 1155 if (dca_subframe_footer(s)) | |
| 1156 return -1; | |
| 1157 } | |
| 1158 | |
| 1159 return 0; | |
| 1160 } | |
| 1161 | |
| 1162 /** | |
| 1163 * Convert bitstream to one representation based on sync marker | |
| 1164 */ | |
| 6214 | 1165 static int dca_convert_bitstream(const uint8_t * src, int src_size, uint8_t * dst, |
| 4599 | 1166 int max_size) |
| 1167 { | |
| 1168 uint32_t mrk; | |
| 1169 int i, tmp; | |
| 6214 | 1170 const uint16_t *ssrc = (const uint16_t *) src; |
| 1171 uint16_t *sdst = (uint16_t *) dst; | |
| 4599 | 1172 PutBitContext pb; |
| 1173 | |
| 5027 | 1174 if((unsigned)src_size > (unsigned)max_size) { |
|
8226
ee1b8c54a603
Add support for parsing and decoding DCA-HD streams.
kostya
parents:
8148
diff
changeset
|
1175 // av_log(NULL, AV_LOG_ERROR, "Input frame size larger then DCA_MAX_FRAME_SIZE!\n"); |
|
ee1b8c54a603
Add support for parsing and decoding DCA-HD streams.
kostya
parents:
8148
diff
changeset
|
1176 // return -1; |
|
ee1b8c54a603
Add support for parsing and decoding DCA-HD streams.
kostya
parents:
8148
diff
changeset
|
1177 src_size = max_size; |
| 5027 | 1178 } |
| 4883 | 1179 |
| 4599 | 1180 mrk = AV_RB32(src); |
| 1181 switch (mrk) { | |
| 1182 case DCA_MARKER_RAW_BE: | |
| 7671 | 1183 memcpy(dst, src, src_size); |
| 1184 return src_size; | |
| 4599 | 1185 case DCA_MARKER_RAW_LE: |
| 7671 | 1186 for (i = 0; i < (src_size + 1) >> 1; i++) |
| 4599 | 1187 *sdst++ = bswap_16(*ssrc++); |
| 7671 | 1188 return src_size; |
| 4599 | 1189 case DCA_MARKER_14B_BE: |
| 1190 case DCA_MARKER_14B_LE: | |
| 1191 init_put_bits(&pb, dst, max_size); | |
| 1192 for (i = 0; i < (src_size + 1) >> 1; i++, src += 2) { | |
| 1193 tmp = ((mrk == DCA_MARKER_14B_BE) ? AV_RB16(src) : AV_RL16(src)) & 0x3FFF; | |
| 1194 put_bits(&pb, 14, tmp); | |
| 1195 } | |
| 1196 flush_put_bits(&pb); | |
| 1197 return (put_bits_count(&pb) + 7) >> 3; | |
| 1198 default: | |
| 1199 return -1; | |
| 1200 } | |
| 1201 } | |
| 1202 | |
| 1203 /** | |
| 1204 * Main frame decoding function | |
| 1205 * FIXME add arguments | |
| 1206 */ | |
| 1207 static int dca_decode_frame(AVCodecContext * avctx, | |
| 1208 void *data, int *data_size, | |
|
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
1209 AVPacket *avpkt) |
| 4599 | 1210 { |
|
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
1211 const uint8_t *buf = avpkt->data; |
|
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
1212 int buf_size = avpkt->size; |
| 4599 | 1213 |
|
11909
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1214 int lfe_samples; |
|
7724
ea9aa2aa4caa
dca: Do float -> int16 interleaving in-place using s->dsp.float_to_int16_interleave()
andoma
parents:
7680
diff
changeset
|
1215 int i; |
| 4599 | 1216 int16_t *samples = data; |
| 1217 DCAContext *s = avctx->priv_data; | |
| 1218 int channels; | |
| 1219 | |
| 1220 | |
| 1221 s->dca_buffer_size = dca_convert_bitstream(buf, buf_size, s->dca_buffer, DCA_MAX_FRAME_SIZE); | |
| 1222 if (s->dca_buffer_size == -1) { | |
| 5027 | 1223 av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\n"); |
| 4599 | 1224 return -1; |
| 1225 } | |
| 1226 | |
| 1227 init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8); | |
| 1228 if (dca_parse_frame_header(s) < 0) { | |
| 1229 //seems like the frame is corrupt, try with the next one | |
| 5645 | 1230 *data_size=0; |
| 4599 | 1231 return buf_size; |
| 1232 } | |
| 1233 //set AVCodec values with parsed data | |
| 1234 avctx->sample_rate = s->sample_rate; | |
| 1235 avctx->bit_rate = s->bit_rate; | |
| 1236 | |
|
11909
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1237 for (i = 0; i < (s->sample_blocks / 8); i++) { |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1238 dca_decode_block(s, i); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1239 } |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1240 |
| 4893 | 1241 channels = s->prim_channels + !!s->lfe; |
|
8148
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
1242 |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
1243 if (s->amode<16) { |
| 8100 | 1244 avctx->channel_layout = dca_core_channel_layout[s->amode]; |
| 1245 | |
|
8148
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
1246 if (s->lfe) { |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
1247 avctx->channel_layout |= CH_LOW_FREQUENCY; |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
1248 s->channel_order_tab = dca_channel_reorder_lfe[s->amode]; |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
1249 } else |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
1250 s->channel_order_tab = dca_channel_reorder_nolfe[s->amode]; |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
1251 |
|
11304
3ef04d1190f0
Fixed a segfault in the DCA decoder with corrupted streams.
fenrir
parents:
10961
diff
changeset
|
1252 if (s->prim_channels > 0 && |
|
3ef04d1190f0
Fixed a segfault in the DCA decoder with corrupted streams.
fenrir
parents:
10961
diff
changeset
|
1253 s->channel_order_tab[s->prim_channels - 1] < 0) |
|
3ef04d1190f0
Fixed a segfault in the DCA decoder with corrupted streams.
fenrir
parents:
10961
diff
changeset
|
1254 return -1; |
|
3ef04d1190f0
Fixed a segfault in the DCA decoder with corrupted streams.
fenrir
parents:
10961
diff
changeset
|
1255 |
|
8148
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
1256 if(avctx->request_channels == 2 && s->prim_channels > 2) { |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
1257 channels = 2; |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
1258 s->output = DCA_STEREO; |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
1259 avctx->channel_layout = CH_LAYOUT_STEREO; |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
1260 } |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
1261 } else { |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
1262 av_log(avctx, AV_LOG_ERROR, "Non standard configuration %d !\n",s->amode); |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
1263 return -1; |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
1264 } |
|
146ac82af1e5
Proper channel output reordering for the dca decoder.
banan
parents:
8126
diff
changeset
|
1265 |
| 4893 | 1266 |
|
6577
1b90003d4d60
Only set channels in the stream if previously unset, fixes resampling crash on broken dca frames
banan
parents:
6517
diff
changeset
|
1267 /* There is nothing that prevents a dts frame to change channel configuration |
|
1b90003d4d60
Only set channels in the stream if previously unset, fixes resampling crash on broken dca frames
banan
parents:
6517
diff
changeset
|
1268 but FFmpeg doesn't support that so only set the channels if it is previously |
|
1b90003d4d60
Only set channels in the stream if previously unset, fixes resampling crash on broken dca frames
banan
parents:
6517
diff
changeset
|
1269 unset. Ideally during the first probe for channels the crc should be checked |
|
1b90003d4d60
Only set channels in the stream if previously unset, fixes resampling crash on broken dca frames
banan
parents:
6517
diff
changeset
|
1270 and only set avctx->channels when the crc is ok. Right now the decoder could |
|
1b90003d4d60
Only set channels in the stream if previously unset, fixes resampling crash on broken dca frames
banan
parents:
6517
diff
changeset
|
1271 set the channels based on a broken first frame.*/ |
|
1b90003d4d60
Only set channels in the stream if previously unset, fixes resampling crash on broken dca frames
banan
parents:
6517
diff
changeset
|
1272 if (!avctx->channels) |
|
1b90003d4d60
Only set channels in the stream if previously unset, fixes resampling crash on broken dca frames
banan
parents:
6517
diff
changeset
|
1273 avctx->channels = channels; |
|
1b90003d4d60
Only set channels in the stream if previously unset, fixes resampling crash on broken dca frames
banan
parents:
6517
diff
changeset
|
1274 |
| 4599 | 1275 if(*data_size < (s->sample_blocks / 8) * 256 * sizeof(int16_t) * channels) |
| 1276 return -1; | |
| 7725 | 1277 *data_size = 256 / 8 * s->sample_blocks * sizeof(int16_t) * channels; |
|
11909
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1278 |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1279 /* filter to get final output */ |
| 4599 | 1280 for (i = 0; i < (s->sample_blocks / 8); i++) { |
|
11909
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1281 dca_filter_channels(s, i); |
|
7724
ea9aa2aa4caa
dca: Do float -> int16 interleaving in-place using s->dsp.float_to_int16_interleave()
andoma
parents:
7680
diff
changeset
|
1282 s->dsp.float_to_int16_interleave(samples, s->samples_chanptr, 256, channels); |
|
ea9aa2aa4caa
dca: Do float -> int16 interleaving in-place using s->dsp.float_to_int16_interleave()
andoma
parents:
7680
diff
changeset
|
1283 samples += 256 * channels; |
| 4599 | 1284 } |
| 1285 | |
|
11909
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1286 /* update lfe history */ |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1287 lfe_samples = 2 * s->lfe * (s->sample_blocks / 8); |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1288 for (i = 0; i < 2 * s->lfe * 4; i++) { |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1289 s->lfe_data[i] = s->lfe_data[i + lfe_samples]; |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1290 } |
|
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1291 |
| 4599 | 1292 return buf_size; |
| 1293 } | |
| 1294 | |
| 1295 | |
| 1296 | |
| 1297 /** | |
| 1298 * DCA initialization | |
| 1299 * | |
| 1300 * @param avctx pointer to the AVCodecContext | |
| 1301 */ | |
| 1302 | |
|
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6463
diff
changeset
|
1303 static av_cold int dca_decode_init(AVCodecContext * avctx) |
| 4599 | 1304 { |
| 1305 DCAContext *s = avctx->priv_data; | |
|
7724
ea9aa2aa4caa
dca: Do float -> int16 interleaving in-place using s->dsp.float_to_int16_interleave()
andoma
parents:
7680
diff
changeset
|
1306 int i; |
| 4599 | 1307 |
| 1308 s->avctx = avctx; | |
| 1309 dca_init_vlcs(); | |
| 1310 | |
| 1311 dsputil_init(&s->dsp, avctx); | |
|
9658
67a20f0eb42c
Support for getting (i)MDCT output multiplied by a constant scaling factor.
serge
parents:
9526
diff
changeset
|
1312 ff_mdct_init(&s->imdct, 6, 1, 1.0); |
| 11592 | 1313 ff_synth_filter_init(&s->synth); |
|
11617
bb17732c00ef
DCA: break out lfe_interpolation_fir() inner loops to a function
mru
parents:
11611
diff
changeset
|
1314 ff_dcadsp_init(&s->dcadsp); |
| 6120 | 1315 |
|
11909
3bfcb8fd3dc9
Support DTS-ES extension (XCh) in dca: move original code around to allow reused by DTS-ES code
mstorsjo
parents:
11908
diff
changeset
|
1316 for (i = 0; i < DCA_PRIM_CHANNELS_MAX+1; i++) |
|
7724
ea9aa2aa4caa
dca: Do float -> int16 interleaving in-place using s->dsp.float_to_int16_interleave()
andoma
parents:
7680
diff
changeset
|
1317 s->samples_chanptr[i] = s->samples + i * 256; |
|
7451
85ab7655ad4d
Modify all codecs to report their supported input and output sample format(s).
pross
parents:
7040
diff
changeset
|
1318 avctx->sample_fmt = SAMPLE_FMT_S16; |
|
8062
17aeecee2a97
Fix dca decoder with non simd float2int16 conversion
banan
parents:
8061
diff
changeset
|
1319 |
|
10377
98816e4d5522
dca and aac decoders use float_to_int16_interleave, so check for
conrad
parents:
10199
diff
changeset
|
1320 if(s->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) { |
|
8062
17aeecee2a97
Fix dca decoder with non simd float2int16 conversion
banan
parents:
8061
diff
changeset
|
1321 s->add_bias = 385.0f; |
|
17aeecee2a97
Fix dca decoder with non simd float2int16 conversion
banan
parents:
8061
diff
changeset
|
1322 s->scale_bias = 1.0 / 32768.0; |
|
17aeecee2a97
Fix dca decoder with non simd float2int16 conversion
banan
parents:
8061
diff
changeset
|
1323 } else { |
|
17aeecee2a97
Fix dca decoder with non simd float2int16 conversion
banan
parents:
8061
diff
changeset
|
1324 s->add_bias = 0.0f; |
|
17aeecee2a97
Fix dca decoder with non simd float2int16 conversion
banan
parents:
8061
diff
changeset
|
1325 s->scale_bias = 1.0; |
|
8063
6bc70b15451d
Disable codec downmix when not using simd instead of silently produce silence
banan
parents:
8062
diff
changeset
|
1326 |
|
6bc70b15451d
Disable codec downmix when not using simd instead of silently produce silence
banan
parents:
8062
diff
changeset
|
1327 /* allow downmixing to stereo */ |
|
6bc70b15451d
Disable codec downmix when not using simd instead of silently produce silence
banan
parents:
8062
diff
changeset
|
1328 if (avctx->channels > 0 && avctx->request_channels < avctx->channels && |
|
6bc70b15451d
Disable codec downmix when not using simd instead of silently produce silence
banan
parents:
8062
diff
changeset
|
1329 avctx->request_channels == 2) { |
|
6bc70b15451d
Disable codec downmix when not using simd instead of silently produce silence
banan
parents:
8062
diff
changeset
|
1330 avctx->channels = avctx->request_channels; |
|
6bc70b15451d
Disable codec downmix when not using simd instead of silently produce silence
banan
parents:
8062
diff
changeset
|
1331 } |
|
8062
17aeecee2a97
Fix dca decoder with non simd float2int16 conversion
banan
parents:
8061
diff
changeset
|
1332 } |
|
17aeecee2a97
Fix dca decoder with non simd float2int16 conversion
banan
parents:
8061
diff
changeset
|
1333 |
|
17aeecee2a97
Fix dca decoder with non simd float2int16 conversion
banan
parents:
8061
diff
changeset
|
1334 |
| 4599 | 1335 return 0; |
| 1336 } | |
| 1337 | |
|
7738
93ba37a9098c
Replace obfuscated mdct in qmf_32_subbands() by ff_imdct_half().
michael
parents:
7737
diff
changeset
|
1338 static av_cold int dca_decode_end(AVCodecContext * avctx) |
|
93ba37a9098c
Replace obfuscated mdct in qmf_32_subbands() by ff_imdct_half().
michael
parents:
7737
diff
changeset
|
1339 { |
|
93ba37a9098c
Replace obfuscated mdct in qmf_32_subbands() by ff_imdct_half().
michael
parents:
7737
diff
changeset
|
1340 DCAContext *s = avctx->priv_data; |
|
93ba37a9098c
Replace obfuscated mdct in qmf_32_subbands() by ff_imdct_half().
michael
parents:
7737
diff
changeset
|
1341 ff_mdct_end(&s->imdct); |
|
93ba37a9098c
Replace obfuscated mdct in qmf_32_subbands() by ff_imdct_half().
michael
parents:
7737
diff
changeset
|
1342 return 0; |
|
93ba37a9098c
Replace obfuscated mdct in qmf_32_subbands() by ff_imdct_half().
michael
parents:
7737
diff
changeset
|
1343 } |
| 4599 | 1344 |
| 1345 AVCodec dca_decoder = { | |
| 1346 .name = "dca", | |
|
11560
8a4984c5cacc
Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents:
11370
diff
changeset
|
1347 .type = AVMEDIA_TYPE_AUDIO, |
| 4599 | 1348 .id = CODEC_ID_DTS, |
| 1349 .priv_data_size = sizeof(DCAContext), | |
| 1350 .init = dca_decode_init, | |
| 1351 .decode = dca_decode_frame, | |
|
7738
93ba37a9098c
Replace obfuscated mdct in qmf_32_subbands() by ff_imdct_half().
michael
parents:
7737
diff
changeset
|
1352 .close = dca_decode_end, |
|
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6710
diff
changeset
|
1353 .long_name = NULL_IF_CONFIG_SMALL("DCA (DTS Coherent Acoustics)"), |
| 4599 | 1354 }; |
