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