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