annotate dca.c @ 8103:069d7a8e2e75 libavcodec

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