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