annotate dca.c @ 12211:5fbc541988f7 libavcodec

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