annotate atrac3.c @ 8673:5b7d5a33a3e2 libavcodec

Fix filenames in Doxygen comments.
author diego
date Mon, 26 Jan 2009 22:51:16 +0000
parents bf12bb0efb68
children e9d9d946f213
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1 /*
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
2 * Atrac 3 compatible decoder
6844
94dc0de175d9 Update copyright and text
banan
parents: 6843
diff changeset
3 * Copyright (c) 2006-2008 Maxim Poliakovski
94dc0de175d9 Update copyright and text
banan
parents: 6843
diff changeset
4 * Copyright (c) 2006-2008 Benjamin Larsson
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
5 *
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
6 * This file is part of FFmpeg.
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
7 *
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
12 *
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
16 * Lesser General Public License for more details.
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
17 *
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
21 */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
22
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
23 /**
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
24 * @file atrac3.c
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
25 * Atrac 3 compatible decoder.
6844
94dc0de175d9 Update copyright and text
banan
parents: 6843
diff changeset
26 * This decoder handles Sony's ATRAC3 data.
94dc0de175d9 Update copyright and text
banan
parents: 6843
diff changeset
27 *
94dc0de175d9 Update copyright and text
banan
parents: 6843
diff changeset
28 * Container formats used to store atrac 3 data:
94dc0de175d9 Update copyright and text
banan
parents: 6843
diff changeset
29 * RealMedia (.rm), RIFF WAV (.wav, .at3), Sony OpenMG (.oma, .aa3).
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
30 *
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
31 * To use this decoder, a calling application must supply the extradata
6844
94dc0de175d9 Update copyright and text
banan
parents: 6843
diff changeset
32 * bytes provided in the containers above.
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
33 */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
34
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
35 #include <math.h>
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
36 #include <stddef.h>
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
37 #include <stdio.h>
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
38
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
39 #include "avcodec.h"
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
40 #include "bitstream.h"
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
41 #include "dsputil.h"
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
42 #include "bytestream.h"
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
43
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
44 #include "atrac3data.h"
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
45
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
46 #define JOINT_STEREO 0x12
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
47 #define STEREO 0x2
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
48
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
49
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
50 /* These structures are needed to store the parsed gain control data. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
51 typedef struct {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
52 int num_gain_data;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
53 int levcode[8];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
54 int loccode[8];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
55 } gain_info;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
56
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
57 typedef struct {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
58 gain_info gBlock[4];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
59 } gain_block;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
60
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
61 typedef struct {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
62 int pos;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
63 int numCoefs;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
64 float coef[8];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
65 } tonal_component;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
66
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
67 typedef struct {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
68 int bandsCoded;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
69 int numComponents;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
70 tonal_component components[64];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
71 float prevFrame[1024];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
72 int gcBlkSwitch;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
73 gain_block gainBlock[2];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
74
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
75 DECLARE_ALIGNED_16(float, spectrum[1024]);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
76 DECLARE_ALIGNED_16(float, IMDCT_buf[1024]);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
77
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
78 float delayBuf1[46]; ///<qmf delay buffers
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
79 float delayBuf2[46];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
80 float delayBuf3[46];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
81 } channel_unit;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
82
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
83 typedef struct {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
84 GetBitContext gb;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
85 //@{
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
86 /** stream data */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
87 int channels;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
88 int codingMode;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
89 int bit_rate;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
90 int sample_rate;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
91 int samples_per_channel;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
92 int samples_per_frame;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
93
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
94 int bits_per_frame;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
95 int bytes_per_frame;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
96 int pBs;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
97 channel_unit* pUnits;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
98 //@}
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
99 //@{
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
100 /** joint-stereo related variables */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
101 int matrix_coeff_index_prev[4];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
102 int matrix_coeff_index_now[4];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
103 int matrix_coeff_index_next[4];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
104 int weighting_delay[6];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
105 //@}
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
106 //@{
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
107 /** data buffers */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
108 float outSamples[2048];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
109 uint8_t* decoded_bytes_buffer;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
110 float tempBuf[1070];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
111 //@}
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
112 //@{
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
113 /** extradata */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
114 int atrac3version;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
115 int delay;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
116 int scrambled_stream;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
117 int frame_factor;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
118 //@}
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
119 } ATRAC3Context;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
120
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
121 static DECLARE_ALIGNED_16(float,mdct_window[512]);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
122 static float qmf_window[48];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
123 static VLC spectral_coeff_tab[7];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
124 static float SFTable[64];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
125 static float gain_tab1[16];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
126 static float gain_tab2[31];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
127 static MDCTContext mdct_ctx;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
128 static DSPContext dsp;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
129
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
130
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
131 /* quadrature mirror synthesis filter */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
132
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
133 /**
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
134 * Quadrature mirror synthesis filter.
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
135 *
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
136 * @param inlo lower part of spectrum
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
137 * @param inhi higher part of spectrum
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
138 * @param nIn size of spectrum buffer
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
139 * @param pOut out buffer
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
140 * @param delayBuf delayBuf buffer
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
141 * @param temp temp buffer
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
142 */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
143
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
144
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
145 static void iqmf (float *inlo, float *inhi, unsigned int nIn, float *pOut, float *delayBuf, float *temp)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
146 {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
147 int i, j;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
148 float *p1, *p3;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
149
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
150 memcpy(temp, delayBuf, 46*sizeof(float));
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
151
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
152 p3 = temp + 46;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
153
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
154 /* loop1 */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
155 for(i=0; i<nIn; i+=2){
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
156 p3[2*i+0] = inlo[i ] + inhi[i ];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
157 p3[2*i+1] = inlo[i ] - inhi[i ];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
158 p3[2*i+2] = inlo[i+1] + inhi[i+1];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
159 p3[2*i+3] = inlo[i+1] - inhi[i+1];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
160 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
161
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
162 /* loop2 */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
163 p1 = temp;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
164 for (j = nIn; j != 0; j--) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
165 float s1 = 0.0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
166 float s2 = 0.0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
167
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
168 for (i = 0; i < 48; i += 2) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
169 s1 += p1[i] * qmf_window[i];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
170 s2 += p1[i+1] * qmf_window[i+1];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
171 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
172
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
173 pOut[0] = s2;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
174 pOut[1] = s1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
175
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
176 p1 += 2;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
177 pOut += 2;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
178 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
179
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
180 /* Update the delay buffer. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
181 memcpy(delayBuf, temp + nIn*2, 46*sizeof(float));
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
182 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
183
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
184 /**
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
185 * Regular 512 points IMDCT without overlapping, with the exception of the swapping of odd bands
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
186 * caused by the reverse spectra of the QMF.
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
187 *
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
188 * @param pInput float input
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
189 * @param pOutput float output
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
190 * @param odd_band 1 if the band is an odd band
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
191 */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
192
7546
97383e012cb9 remove mdct tmp buffer
lorenm
parents: 7451
diff changeset
193 static void IMLT(float *pInput, float *pOutput, int odd_band)
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
194 {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
195 int i;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
196
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
197 if (odd_band) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
198 /**
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
199 * Reverse the odd bands before IMDCT, this is an effect of the QMF transform
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
200 * or it gives better compression to do it this way.
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
201 * FIXME: It should be possible to handle this in ff_imdct_calc
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
202 * for that to happen a modification of the prerotation step of
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
203 * all SIMD code and C code is needed.
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
204 * Or fix the functions before so they generate a pre reversed spectrum.
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
205 */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
206
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
207 for (i=0; i<128; i++)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
208 FFSWAP(float, pInput[i], pInput[255-i]);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
209 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
210
7547
8226017a65ae mdct wrapper function to match fft
lorenm
parents: 7546
diff changeset
211 ff_imdct_calc(&mdct_ctx,pOutput,pInput);
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
212
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
213 /* Perform windowing on the output. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
214 dsp.vector_fmul(pOutput,mdct_window,512);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
215
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
216 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
217
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
218
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
219 /**
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
220 * Atrac 3 indata descrambling, only used for data coming from the rm container
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
221 *
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
222 * @param in pointer to 8 bit array of indata
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
223 * @param bits amount of bits
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
224 * @param out pointer to 8 bit array of outdata
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
225 */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
226
6228
michael
parents: 5523
diff changeset
227 static int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes){
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
228 int i, off;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
229 uint32_t c;
6228
michael
parents: 5523
diff changeset
230 const uint32_t* buf;
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
231 uint32_t* obuf = (uint32_t*) out;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
232
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
233 off = (int)((long)inbuffer & 3);
6228
michael
parents: 5523
diff changeset
234 buf = (const uint32_t*) (inbuffer - off);
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
235 c = be2me_32((0x537F6103 >> (off*8)) | (0x537F6103 << (32-(off*8))));
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
236 bytes += 3 + off;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
237 for (i = 0; i < bytes/4; i++)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
238 obuf[i] = c ^ buf[i];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
239
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
240 if (off)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
241 av_log(NULL,AV_LOG_DEBUG,"Offset of %d not handled, post sample on ffmpeg-dev.\n",off);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
242
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
243 return off;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
244 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
245
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
246
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
247 static void init_atrac3_transforms(ATRAC3Context *q) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
248 float enc_window[256];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
249 float s;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
250 int i;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
251
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
252 /* Generate the mdct window, for details see
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
253 * http://wiki.multimedia.cx/index.php?title=RealAudio_atrc#Windows */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
254 for (i=0 ; i<256; i++)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
255 enc_window[i] = (sin(((i + 0.5) / 256.0 - 0.5) * M_PI) + 1.0) * 0.5;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
256
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
257 if (!mdct_window[0])
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
258 for (i=0 ; i<256; i++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
259 mdct_window[i] = enc_window[i]/(enc_window[i]*enc_window[i] + enc_window[255-i]*enc_window[255-i]);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
260 mdct_window[511-i] = mdct_window[i];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
261 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
262
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
263 /* Generate the QMF window. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
264 for (i=0 ; i<24; i++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
265 s = qmf_48tap_half[i] * 2.0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
266 qmf_window[i] = s;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
267 qmf_window[47 - i] = s;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
268 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
269
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
270 /* Initialize the MDCT transform. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
271 ff_mdct_init(&mdct_ctx, 9, 1);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
272 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
273
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
274 /**
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
275 * Atrac3 uninit, free all allocated memory
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
276 */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
277
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
278 static int atrac3_decode_close(AVCodecContext *avctx)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
279 {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
280 ATRAC3Context *q = avctx->priv_data;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
281
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
282 av_free(q->pUnits);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
283 av_free(q->decoded_bytes_buffer);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
284
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
285 return 0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
286 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
287
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
288 /**
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
289 / * Mantissa decoding
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
290 *
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
291 * @param gb the GetBit context
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
292 * @param selector what table is the output values coded with
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
293 * @param codingFlag constant length coding or variable length coding
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
294 * @param mantissas mantissa output table
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
295 * @param numCodes amount of values to get
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
296 */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
297
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
298 static void readQuantSpectralCoeffs (GetBitContext *gb, int selector, int codingFlag, int* mantissas, int numCodes)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
299 {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
300 int numBits, cnt, code, huffSymb;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
301
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
302 if (selector == 1)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
303 numCodes /= 2;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
304
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
305 if (codingFlag != 0) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
306 /* constant length coding (CLC) */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
307 numBits = CLCLengthTab[selector];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
308
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
309 if (selector > 1) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
310 for (cnt = 0; cnt < numCodes; cnt++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
311 if (numBits)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
312 code = get_sbits(gb, numBits);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
313 else
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
314 code = 0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
315 mantissas[cnt] = code;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
316 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
317 } else {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
318 for (cnt = 0; cnt < numCodes; cnt++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
319 if (numBits)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
320 code = get_bits(gb, numBits); //numBits is always 4 in this case
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
321 else
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
322 code = 0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
323 mantissas[cnt*2] = seTab_0[code >> 2];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
324 mantissas[cnt*2+1] = seTab_0[code & 3];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
325 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
326 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
327 } else {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
328 /* variable length coding (VLC) */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
329 if (selector != 1) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
330 for (cnt = 0; cnt < numCodes; cnt++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
331 huffSymb = get_vlc2(gb, spectral_coeff_tab[selector-1].table, spectral_coeff_tab[selector-1].bits, 3);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
332 huffSymb += 1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
333 code = huffSymb >> 1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
334 if (huffSymb & 1)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
335 code = -code;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
336 mantissas[cnt] = code;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
337 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
338 } else {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
339 for (cnt = 0; cnt < numCodes; cnt++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
340 huffSymb = get_vlc2(gb, spectral_coeff_tab[selector-1].table, spectral_coeff_tab[selector-1].bits, 3);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
341 mantissas[cnt*2] = decTable1[huffSymb*2];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
342 mantissas[cnt*2+1] = decTable1[huffSymb*2+1];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
343 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
344 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
345 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
346 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
347
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
348 /**
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
349 * Restore the quantized band spectrum coefficients
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
350 *
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
351 * @param gb the GetBit context
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
352 * @param pOut decoded band spectrum
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
353 * @return outSubbands subband counter, fix for broken specification/files
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
354 */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
355
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
356 static int decodeSpectrum (GetBitContext *gb, float *pOut)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
357 {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
358 int numSubbands, codingMode, cnt, first, last, subbWidth, *pIn;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
359 int subband_vlc_index[32], SF_idxs[32];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
360 int mantissas[128];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
361 float SF;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
362
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
363 numSubbands = get_bits(gb, 5); // number of coded subbands
5513
9f8219a3b86f use get_bits1(..) instead get_bits(.., 1)
alex
parents: 5423
diff changeset
364 codingMode = get_bits1(gb); // coding Mode: 0 - VLC/ 1-CLC
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
365
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
366 /* Get the VLC selector table for the subbands, 0 means not coded. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
367 for (cnt = 0; cnt <= numSubbands; cnt++)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
368 subband_vlc_index[cnt] = get_bits(gb, 3);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
369
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
370 /* Read the scale factor indexes from the stream. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
371 for (cnt = 0; cnt <= numSubbands; cnt++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
372 if (subband_vlc_index[cnt] != 0)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
373 SF_idxs[cnt] = get_bits(gb, 6);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
374 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
375
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
376 for (cnt = 0; cnt <= numSubbands; cnt++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
377 first = subbandTab[cnt];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
378 last = subbandTab[cnt+1];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
379
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
380 subbWidth = last - first;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
381
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
382 if (subband_vlc_index[cnt] != 0) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
383 /* Decode spectral coefficients for this subband. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
384 /* TODO: This can be done faster is several blocks share the
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
385 * same VLC selector (subband_vlc_index) */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
386 readQuantSpectralCoeffs (gb, subband_vlc_index[cnt], codingMode, mantissas, subbWidth);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
387
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
388 /* Decode the scale factor for this subband. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
389 SF = SFTable[SF_idxs[cnt]] * iMaxQuant[subband_vlc_index[cnt]];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
390
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
391 /* Inverse quantize the coefficients. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
392 for (pIn=mantissas ; first<last; first++, pIn++)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
393 pOut[first] = *pIn * SF;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
394 } else {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
395 /* This subband was not coded, so zero the entire subband. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
396 memset(pOut+first, 0, subbWidth*sizeof(float));
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
397 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
398 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
399
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
400 /* Clear the subbands that were not coded. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
401 first = subbandTab[cnt];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
402 memset(pOut+first, 0, (1024 - first) * sizeof(float));
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
403 return numSubbands;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
404 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
405
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
406 /**
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
407 * Restore the quantized tonal components
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
408 *
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
409 * @param gb the GetBit context
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
410 * @param pComponent tone component
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
411 * @param numBands amount of coded bands
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
412 */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
413
4865
086291824752 Deobfuscade decodeTonalComponents calling logic.
banan
parents: 4856
diff changeset
414 static int decodeTonalComponents (GetBitContext *gb, tonal_component *pComponent, int numBands)
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
415 {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
416 int i,j,k,cnt;
4865
086291824752 Deobfuscade decodeTonalComponents calling logic.
banan
parents: 4856
diff changeset
417 int components, coding_mode_selector, coding_mode, coded_values_per_component;
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
418 int sfIndx, coded_values, max_coded_values, quant_step_index, coded_components;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
419 int band_flags[4], mantissa[8];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
420 float *pCoef;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
421 float scalefactor;
4865
086291824752 Deobfuscade decodeTonalComponents calling logic.
banan
parents: 4856
diff changeset
422 int component_count = 0;
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
423
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
424 components = get_bits(gb,5);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
425
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
426 /* no tonal components */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
427 if (components == 0)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
428 return 0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
429
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
430 coding_mode_selector = get_bits(gb,2);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
431 if (coding_mode_selector == 2)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
432 return -1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
433
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
434 coding_mode = coding_mode_selector & 1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
435
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
436 for (i = 0; i < components; i++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
437 for (cnt = 0; cnt <= numBands; cnt++)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
438 band_flags[cnt] = get_bits1(gb);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
439
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
440 coded_values_per_component = get_bits(gb,3);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
441
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
442 quant_step_index = get_bits(gb,3);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
443 if (quant_step_index <= 1)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
444 return -1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
445
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
446 if (coding_mode_selector == 3)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
447 coding_mode = get_bits1(gb);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
448
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
449 for (j = 0; j < (numBands + 1) * 4; j++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
450 if (band_flags[j >> 2] == 0)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
451 continue;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
452
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
453 coded_components = get_bits(gb,3);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
454
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
455 for (k=0; k<coded_components; k++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
456 sfIndx = get_bits(gb,6);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
457 pComponent[component_count].pos = j * 64 + (get_bits(gb,6));
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
458 max_coded_values = 1024 - pComponent[component_count].pos;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
459 coded_values = coded_values_per_component + 1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
460 coded_values = FFMIN(max_coded_values,coded_values);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
461
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
462 scalefactor = SFTable[sfIndx] * iMaxQuant[quant_step_index];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
463
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
464 readQuantSpectralCoeffs(gb, quant_step_index, coding_mode, mantissa, coded_values);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
465
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
466 pComponent[component_count].numCoefs = coded_values;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
467
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
468 /* inverse quant */
6843
bc8faf4f8b7d Fix decoding of 01-Untitled(1).oma, patch by Maxim Poliakovski
banan
parents: 6716
diff changeset
469 pCoef = pComponent[component_count].coef;
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
470 for (cnt = 0; cnt < coded_values; cnt++)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
471 pCoef[cnt] = mantissa[cnt] * scalefactor;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
472
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
473 component_count++;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
474 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
475 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
476 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
477
4865
086291824752 Deobfuscade decodeTonalComponents calling logic.
banan
parents: 4856
diff changeset
478 return component_count;
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
479 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
480
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
481 /**
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
482 * Decode gain parameters for the coded bands
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
483 *
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
484 * @param gb the GetBit context
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
485 * @param pGb the gainblock for the current band
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
486 * @param numBands amount of coded bands
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
487 */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
488
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
489 static int decodeGainControl (GetBitContext *gb, gain_block *pGb, int numBands)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
490 {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
491 int i, cf, numData;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
492 int *pLevel, *pLoc;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
493
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
494 gain_info *pGain = pGb->gBlock;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
495
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
496 for (i=0 ; i<=numBands; i++)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
497 {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
498 numData = get_bits(gb,3);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
499 pGain[i].num_gain_data = numData;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
500 pLevel = pGain[i].levcode;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
501 pLoc = pGain[i].loccode;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
502
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
503 for (cf = 0; cf < numData; cf++){
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
504 pLevel[cf]= get_bits(gb,4);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
505 pLoc [cf]= get_bits(gb,5);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
506 if(cf && pLoc[cf] <= pLoc[cf-1])
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
507 return -1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
508 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
509 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
510
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
511 /* Clear the unused blocks. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
512 for (; i<4 ; i++)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
513 pGain[i].num_gain_data = 0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
514
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
515 return 0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
516 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
517
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
518 /**
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
519 * Apply gain parameters and perform the MDCT overlapping part
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
520 *
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
521 * @param pIn input float buffer
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
522 * @param pPrev previous float buffer to perform overlap against
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
523 * @param pOut output float buffer
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
524 * @param pGain1 current band gain info
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
525 * @param pGain2 next band gain info
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
526 */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
527
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
528 static void gainCompensateAndOverlap (float *pIn, float *pPrev, float *pOut, gain_info *pGain1, gain_info *pGain2)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
529 {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
530 /* gain compensation function */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
531 float gain1, gain2, gain_inc;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
532 int cnt, numdata, nsample, startLoc, endLoc;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
533
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
534
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
535 if (pGain2->num_gain_data == 0)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
536 gain1 = 1.0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
537 else
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
538 gain1 = gain_tab1[pGain2->levcode[0]];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
539
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
540 if (pGain1->num_gain_data == 0) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
541 for (cnt = 0; cnt < 256; cnt++)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
542 pOut[cnt] = pIn[cnt] * gain1 + pPrev[cnt];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
543 } else {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
544 numdata = pGain1->num_gain_data;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
545 pGain1->loccode[numdata] = 32;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
546 pGain1->levcode[numdata] = 4;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
547
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
548 nsample = 0; // current sample = 0
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
549
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
550 for (cnt = 0; cnt < numdata; cnt++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
551 startLoc = pGain1->loccode[cnt] * 8;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
552 endLoc = startLoc + 8;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
553
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
554 gain2 = gain_tab1[pGain1->levcode[cnt]];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
555 gain_inc = gain_tab2[(pGain1->levcode[cnt+1] - pGain1->levcode[cnt])+15];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
556
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
557 /* interpolate */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
558 for (; nsample < startLoc; nsample++)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
559 pOut[nsample] = (pIn[nsample] * gain1 + pPrev[nsample]) * gain2;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
560
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
561 /* interpolation is done over eight samples */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
562 for (; nsample < endLoc; nsample++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
563 pOut[nsample] = (pIn[nsample] * gain1 + pPrev[nsample]) * gain2;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
564 gain2 *= gain_inc;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
565 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
566 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
567
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
568 for (; nsample < 256; nsample++)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
569 pOut[nsample] = (pIn[nsample] * gain1) + pPrev[nsample];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
570 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
571
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
572 /* Delay for the overlapping part. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
573 memcpy(pPrev, &pIn[256], 256*sizeof(float));
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
574 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
575
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
576 /**
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
577 * Combine the tonal band spectrum and regular band spectrum
6843
bc8faf4f8b7d Fix decoding of 01-Untitled(1).oma, patch by Maxim Poliakovski
banan
parents: 6716
diff changeset
578 * Return position of the last tonal coefficient
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
579 *
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
580 * @param pSpectrum output spectrum buffer
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
581 * @param numComponents amount of tonal components
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
582 * @param pComponent tonal components for this band
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
583 */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
584
6843
bc8faf4f8b7d Fix decoding of 01-Untitled(1).oma, patch by Maxim Poliakovski
banan
parents: 6716
diff changeset
585 static int addTonalComponents (float *pSpectrum, int numComponents, tonal_component *pComponent)
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
586 {
6843
bc8faf4f8b7d Fix decoding of 01-Untitled(1).oma, patch by Maxim Poliakovski
banan
parents: 6716
diff changeset
587 int cnt, i, lastPos = -1;
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
588 float *pIn, *pOut;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
589
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
590 for (cnt = 0; cnt < numComponents; cnt++){
6843
bc8faf4f8b7d Fix decoding of 01-Untitled(1).oma, patch by Maxim Poliakovski
banan
parents: 6716
diff changeset
591 lastPos = FFMAX(pComponent[cnt].pos + pComponent[cnt].numCoefs, lastPos);
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
592 pIn = pComponent[cnt].coef;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
593 pOut = &(pSpectrum[pComponent[cnt].pos]);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
594
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
595 for (i=0 ; i<pComponent[cnt].numCoefs ; i++)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
596 pOut[i] += pIn[i];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
597 }
6843
bc8faf4f8b7d Fix decoding of 01-Untitled(1).oma, patch by Maxim Poliakovski
banan
parents: 6716
diff changeset
598
bc8faf4f8b7d Fix decoding of 01-Untitled(1).oma, patch by Maxim Poliakovski
banan
parents: 6716
diff changeset
599 return lastPos;
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
600 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
601
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
602
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
603 #define INTERPOLATE(old,new,nsample) ((old) + (nsample)*0.125*((new)-(old)))
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
604
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
605 static void reverseMatrixing(float *su1, float *su2, int *pPrevCode, int *pCurrCode)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
606 {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
607 int i, band, nsample, s1, s2;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
608 float c1, c2;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
609 float mc1_l, mc1_r, mc2_l, mc2_r;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
610
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
611 for (i=0,band = 0; band < 4*256; band+=256,i++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
612 s1 = pPrevCode[i];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
613 s2 = pCurrCode[i];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
614 nsample = 0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
615
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
616 if (s1 != s2) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
617 /* Selector value changed, interpolation needed. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
618 mc1_l = matrixCoeffs[s1*2];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
619 mc1_r = matrixCoeffs[s1*2+1];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
620 mc2_l = matrixCoeffs[s2*2];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
621 mc2_r = matrixCoeffs[s2*2+1];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
622
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
623 /* Interpolation is done over the first eight samples. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
624 for(; nsample < 8; nsample++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
625 c1 = su1[band+nsample];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
626 c2 = su2[band+nsample];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
627 c2 = c1 * INTERPOLATE(mc1_l,mc2_l,nsample) + c2 * INTERPOLATE(mc1_r,mc2_r,nsample);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
628 su1[band+nsample] = c2;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
629 su2[band+nsample] = c1 * 2.0 - c2;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
630 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
631 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
632
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
633 /* Apply the matrix without interpolation. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
634 switch (s2) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
635 case 0: /* M/S decoding */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
636 for (; nsample < 256; nsample++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
637 c1 = su1[band+nsample];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
638 c2 = su2[band+nsample];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
639 su1[band+nsample] = c2 * 2.0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
640 su2[band+nsample] = (c1 - c2) * 2.0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
641 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
642 break;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
643
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
644 case 1:
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
645 for (; nsample < 256; nsample++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
646 c1 = su1[band+nsample];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
647 c2 = su2[band+nsample];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
648 su1[band+nsample] = (c1 + c2) * 2.0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
649 su2[band+nsample] = c2 * -2.0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
650 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
651 break;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
652 case 2:
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
653 case 3:
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
654 for (; nsample < 256; nsample++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
655 c1 = su1[band+nsample];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
656 c2 = su2[band+nsample];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
657 su1[band+nsample] = c1 + c2;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
658 su2[band+nsample] = c1 - c2;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
659 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
660 break;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
661 default:
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
662 assert(0);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
663 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
664 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
665 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
666
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
667 static void getChannelWeights (int indx, int flag, float ch[2]){
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
668
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
669 if (indx == 7) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
670 ch[0] = 1.0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
671 ch[1] = 1.0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
672 } else {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
673 ch[0] = (float)(indx & 7) / 7.0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
674 ch[1] = sqrt(2 - ch[0]*ch[0]);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
675 if(flag)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
676 FFSWAP(float, ch[0], ch[1]);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
677 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
678 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
679
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
680 static void channelWeighting (float *su1, float *su2, int *p3)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
681 {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
682 int band, nsample;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
683 /* w[x][y] y=0 is left y=1 is right */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
684 float w[2][2];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
685
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
686 if (p3[1] != 7 || p3[3] != 7){
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
687 getChannelWeights(p3[1], p3[0], w[0]);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
688 getChannelWeights(p3[3], p3[2], w[1]);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
689
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
690 for(band = 1; band < 4; band++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
691 /* scale the channels by the weights */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
692 for(nsample = 0; nsample < 8; nsample++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
693 su1[band*256+nsample] *= INTERPOLATE(w[0][0], w[0][1], nsample);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
694 su2[band*256+nsample] *= INTERPOLATE(w[1][0], w[1][1], nsample);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
695 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
696
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
697 for(; nsample < 256; nsample++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
698 su1[band*256+nsample] *= w[1][0];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
699 su2[band*256+nsample] *= w[1][1];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
700 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
701 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
702 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
703 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
704
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
705
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
706 /**
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
707 * Decode a Sound Unit
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
708 *
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
709 * @param gb the GetBit context
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
710 * @param pSnd the channel unit to be used
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
711 * @param pOut the decoded samples before IQMF in float representation
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
712 * @param channelNum channel number
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
713 * @param codingMode the coding mode (JOINT_STEREO or regular stereo/mono)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
714 */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
715
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
716
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
717 static int decodeChannelSoundUnit (ATRAC3Context *q, GetBitContext *gb, channel_unit *pSnd, float *pOut, int channelNum, int codingMode)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
718 {
6843
bc8faf4f8b7d Fix decoding of 01-Untitled(1).oma, patch by Maxim Poliakovski
banan
parents: 6716
diff changeset
719 int band, result=0, numSubbands, lastTonal, numBands;
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
720
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
721 if (codingMode == JOINT_STEREO && channelNum == 1) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
722 if (get_bits(gb,2) != 3) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
723 av_log(NULL,AV_LOG_ERROR,"JS mono Sound Unit id != 3.\n");
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
724 return -1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
725 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
726 } else {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
727 if (get_bits(gb,6) != 0x28) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
728 av_log(NULL,AV_LOG_ERROR,"Sound Unit id != 0x28.\n");
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
729 return -1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
730 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
731 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
732
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
733 /* number of coded QMF bands */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
734 pSnd->bandsCoded = get_bits(gb,2);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
735
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
736 result = decodeGainControl (gb, &(pSnd->gainBlock[pSnd->gcBlkSwitch]), pSnd->bandsCoded);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
737 if (result) return result;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
738
4865
086291824752 Deobfuscade decodeTonalComponents calling logic.
banan
parents: 4856
diff changeset
739 pSnd->numComponents = decodeTonalComponents (gb, pSnd->components, pSnd->bandsCoded);
086291824752 Deobfuscade decodeTonalComponents calling logic.
banan
parents: 4856
diff changeset
740 if (pSnd->numComponents == -1) return -1;
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
741
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
742 numSubbands = decodeSpectrum (gb, pSnd->spectrum);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
743
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
744 /* Merge the decoded spectrum and tonal components. */
6843
bc8faf4f8b7d Fix decoding of 01-Untitled(1).oma, patch by Maxim Poliakovski
banan
parents: 6716
diff changeset
745 lastTonal = addTonalComponents (pSnd->spectrum, pSnd->numComponents, pSnd->components);
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
746
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
747
6843
bc8faf4f8b7d Fix decoding of 01-Untitled(1).oma, patch by Maxim Poliakovski
banan
parents: 6716
diff changeset
748 /* calculate number of used MLT/QMF bands according to the amount of coded spectral lines */
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
749 numBands = (subbandTab[numSubbands] - 1) >> 8;
6843
bc8faf4f8b7d Fix decoding of 01-Untitled(1).oma, patch by Maxim Poliakovski
banan
parents: 6716
diff changeset
750 if (lastTonal >= 0)
bc8faf4f8b7d Fix decoding of 01-Untitled(1).oma, patch by Maxim Poliakovski
banan
parents: 6716
diff changeset
751 numBands = FFMAX((lastTonal + 256) >> 8, numBands);
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
752
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
753
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
754 /* Reconstruct time domain samples. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
755 for (band=0; band<4; band++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
756 /* Perform the IMDCT step without overlapping. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
757 if (band <= numBands) {
7546
97383e012cb9 remove mdct tmp buffer
lorenm
parents: 7451
diff changeset
758 IMLT(&(pSnd->spectrum[band*256]), pSnd->IMDCT_buf, band&1);
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
759 } else
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
760 memset(pSnd->IMDCT_buf, 0, 512 * sizeof(float));
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
761
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
762 /* gain compensation and overlapping */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
763 gainCompensateAndOverlap (pSnd->IMDCT_buf, &(pSnd->prevFrame[band*256]), &(pOut[band*256]),
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
764 &((pSnd->gainBlock[1 - (pSnd->gcBlkSwitch)]).gBlock[band]),
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
765 &((pSnd->gainBlock[pSnd->gcBlkSwitch]).gBlock[band]));
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
766 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
767
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
768 /* Swap the gain control buffers for the next frame. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
769 pSnd->gcBlkSwitch ^= 1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
770
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
771 return 0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
772 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
773
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
774 /**
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
775 * Frame handling
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
776 *
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
777 * @param q Atrac3 private context
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
778 * @param databuf the input data
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
779 */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
780
7939
cd8602533b62 atrac3: ensure input frame is not overwritten (it is const)
aurel
parents: 7547
diff changeset
781 static int decodeFrame(ATRAC3Context *q, const uint8_t* databuf)
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
782 {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
783 int result, i;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
784 float *p1, *p2, *p3, *p4;
7939
cd8602533b62 atrac3: ensure input frame is not overwritten (it is const)
aurel
parents: 7547
diff changeset
785 uint8_t *ptr1;
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
786
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
787 if (q->codingMode == JOINT_STEREO) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
788
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
789 /* channel coupling mode */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
790 /* decode Sound Unit 1 */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
791 init_get_bits(&q->gb,databuf,q->bits_per_frame);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
792
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
793 result = decodeChannelSoundUnit(q,&q->gb, q->pUnits, q->outSamples, 0, JOINT_STEREO);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
794 if (result != 0)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
795 return (result);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
796
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
797 /* Framedata of the su2 in the joint-stereo mode is encoded in
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
798 * reverse byte order so we need to swap it first. */
7939
cd8602533b62 atrac3: ensure input frame is not overwritten (it is const)
aurel
parents: 7547
diff changeset
799 if (databuf == q->decoded_bytes_buffer) {
cd8602533b62 atrac3: ensure input frame is not overwritten (it is const)
aurel
parents: 7547
diff changeset
800 uint8_t *ptr2 = q->decoded_bytes_buffer+q->bytes_per_frame-1;
cd8602533b62 atrac3: ensure input frame is not overwritten (it is const)
aurel
parents: 7547
diff changeset
801 ptr1 = q->decoded_bytes_buffer;
7987
bf12bb0efb68 atrac3dec: cosmetics: indentation
aurel
parents: 7939
diff changeset
802 for (i = 0; i < (q->bytes_per_frame/2); i++, ptr1++, ptr2--) {
bf12bb0efb68 atrac3dec: cosmetics: indentation
aurel
parents: 7939
diff changeset
803 FFSWAP(uint8_t,*ptr1,*ptr2);
bf12bb0efb68 atrac3dec: cosmetics: indentation
aurel
parents: 7939
diff changeset
804 }
7939
cd8602533b62 atrac3: ensure input frame is not overwritten (it is const)
aurel
parents: 7547
diff changeset
805 } else {
cd8602533b62 atrac3: ensure input frame is not overwritten (it is const)
aurel
parents: 7547
diff changeset
806 const uint8_t *ptr2 = databuf+q->bytes_per_frame-1;
cd8602533b62 atrac3: ensure input frame is not overwritten (it is const)
aurel
parents: 7547
diff changeset
807 for (i = 0; i < q->bytes_per_frame; i++)
cd8602533b62 atrac3: ensure input frame is not overwritten (it is const)
aurel
parents: 7547
diff changeset
808 q->decoded_bytes_buffer[i] = *ptr2--;
cd8602533b62 atrac3: ensure input frame is not overwritten (it is const)
aurel
parents: 7547
diff changeset
809 }
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
810
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
811 /* Skip the sync codes (0xF8). */
7939
cd8602533b62 atrac3: ensure input frame is not overwritten (it is const)
aurel
parents: 7547
diff changeset
812 ptr1 = q->decoded_bytes_buffer;
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
813 for (i = 4; *ptr1 == 0xF8; i++, ptr1++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
814 if (i >= q->bytes_per_frame)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
815 return -1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
816 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
817
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
818
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
819 /* set the bitstream reader at the start of the second Sound Unit*/
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
820 init_get_bits(&q->gb,ptr1,q->bits_per_frame);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
821
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
822 /* Fill the Weighting coeffs delay buffer */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
823 memmove(q->weighting_delay,&(q->weighting_delay[2]),4*sizeof(int));
5513
9f8219a3b86f use get_bits1(..) instead get_bits(.., 1)
alex
parents: 5423
diff changeset
824 q->weighting_delay[4] = get_bits1(&q->gb);
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
825 q->weighting_delay[5] = get_bits(&q->gb,3);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
826
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
827 for (i = 0; i < 4; i++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
828 q->matrix_coeff_index_prev[i] = q->matrix_coeff_index_now[i];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
829 q->matrix_coeff_index_now[i] = q->matrix_coeff_index_next[i];
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
830 q->matrix_coeff_index_next[i] = get_bits(&q->gb,2);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
831 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
832
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
833 /* Decode Sound Unit 2. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
834 result = decodeChannelSoundUnit(q,&q->gb, &q->pUnits[1], &q->outSamples[1024], 1, JOINT_STEREO);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
835 if (result != 0)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
836 return (result);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
837
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
838 /* Reconstruct the channel coefficients. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
839 reverseMatrixing(q->outSamples, &q->outSamples[1024], q->matrix_coeff_index_prev, q->matrix_coeff_index_now);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
840
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
841 channelWeighting(q->outSamples, &q->outSamples[1024], q->weighting_delay);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
842
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
843 } else {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
844 /* normal stereo mode or mono */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
845 /* Decode the channel sound units. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
846 for (i=0 ; i<q->channels ; i++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
847
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
848 /* Set the bitstream reader at the start of a channel sound unit. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
849 init_get_bits(&q->gb, databuf+((i*q->bytes_per_frame)/q->channels), (q->bits_per_frame)/q->channels);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
850
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
851 result = decodeChannelSoundUnit(q,&q->gb, &q->pUnits[i], &q->outSamples[i*1024], i, q->codingMode);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
852 if (result != 0)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
853 return (result);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
854 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
855 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
857 /* Apply the iQMF synthesis filter. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
858 p1= q->outSamples;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
859 for (i=0 ; i<q->channels ; i++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
860 p2= p1+256;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
861 p3= p2+256;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
862 p4= p3+256;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
863 iqmf (p1, p2, 256, p1, q->pUnits[i].delayBuf1, q->tempBuf);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
864 iqmf (p4, p3, 256, p3, q->pUnits[i].delayBuf2, q->tempBuf);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
865 iqmf (p1, p3, 512, p1, q->pUnits[i].delayBuf3, q->tempBuf);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
866 p1 +=1024;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
867 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
868
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
869 return 0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
870 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
871
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
872
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
873 /**
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
874 * Atrac frame decoding
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
875 *
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
876 * @param avctx pointer to the AVCodecContext
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
877 */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
878
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
879 static int atrac3_decode_frame(AVCodecContext *avctx,
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
880 void *data, int *data_size,
6228
michael
parents: 5523
diff changeset
881 const uint8_t *buf, int buf_size) {
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
882 ATRAC3Context *q = avctx->priv_data;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
883 int result = 0, i;
7939
cd8602533b62 atrac3: ensure input frame is not overwritten (it is const)
aurel
parents: 7547
diff changeset
884 const uint8_t* databuf;
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
885 int16_t* samples = data;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
886
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
887 if (buf_size < avctx->block_align)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
888 return buf_size;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
889
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
890 /* Check if we need to descramble and what buffer to pass on. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
891 if (q->scrambled_stream) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
892 decode_bytes(buf, q->decoded_bytes_buffer, avctx->block_align);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
893 databuf = q->decoded_bytes_buffer;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
894 } else {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
895 databuf = buf;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
896 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
897
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
898 result = decodeFrame(q, databuf);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
899
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
900 if (result != 0) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
901 av_log(NULL,AV_LOG_ERROR,"Frame decoding error!\n");
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
902 return -1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
903 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
904
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
905 if (q->channels == 1) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
906 /* mono */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
907 for (i = 0; i<1024; i++)
5523
c2ab2ac31edb use av_clip_int16() where it makes sense
aurel
parents: 5513
diff changeset
908 samples[i] = av_clip_int16(round(q->outSamples[i]));
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
909 *data_size = 1024 * sizeof(int16_t);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
910 } else {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
911 /* stereo */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
912 for (i = 0; i < 1024; i++) {
5523
c2ab2ac31edb use av_clip_int16() where it makes sense
aurel
parents: 5513
diff changeset
913 samples[i*2] = av_clip_int16(round(q->outSamples[i]));
c2ab2ac31edb use av_clip_int16() where it makes sense
aurel
parents: 5513
diff changeset
914 samples[i*2+1] = av_clip_int16(round(q->outSamples[1024+i]));
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
915 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
916 *data_size = 2048 * sizeof(int16_t);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
917 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
918
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
919 return avctx->block_align;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
920 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
921
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
922
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
923 /**
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
924 * Atrac3 initialization
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
925 *
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
926 * @param avctx pointer to the AVCodecContext
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
927 */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
928
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
929 static int atrac3_decode_init(AVCodecContext *avctx)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
930 {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
931 int i;
6228
michael
parents: 5523
diff changeset
932 const uint8_t *edata_ptr = avctx->extradata;
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
933 ATRAC3Context *q = avctx->priv_data;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
934
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
935 /* Take data from the AVCodecContext (RM container). */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
936 q->sample_rate = avctx->sample_rate;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
937 q->channels = avctx->channels;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
938 q->bit_rate = avctx->bit_rate;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
939 q->bits_per_frame = avctx->block_align * 8;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
940 q->bytes_per_frame = avctx->block_align;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
941
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
942 /* Take care of the codec-specific extradata. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
943 if (avctx->extradata_size == 14) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
944 /* Parse the extradata, WAV format */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
945 av_log(avctx,AV_LOG_DEBUG,"[0-1] %d\n",bytestream_get_le16(&edata_ptr)); //Unknown value always 1
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
946 q->samples_per_channel = bytestream_get_le32(&edata_ptr);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
947 q->codingMode = bytestream_get_le16(&edata_ptr);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
948 av_log(avctx,AV_LOG_DEBUG,"[8-9] %d\n",bytestream_get_le16(&edata_ptr)); //Dupe of coding mode
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
949 q->frame_factor = bytestream_get_le16(&edata_ptr); //Unknown always 1
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
950 av_log(avctx,AV_LOG_DEBUG,"[12-13] %d\n",bytestream_get_le16(&edata_ptr)); //Unknown always 0
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
951
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
952 /* setup */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
953 q->samples_per_frame = 1024 * q->channels;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
954 q->atrac3version = 4;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
955 q->delay = 0x88E;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
956 if (q->codingMode)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
957 q->codingMode = JOINT_STEREO;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
958 else
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
959 q->codingMode = STEREO;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
960
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
961 q->scrambled_stream = 0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
962
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
963 if ((q->bytes_per_frame == 96*q->channels*q->frame_factor) || (q->bytes_per_frame == 152*q->channels*q->frame_factor) || (q->bytes_per_frame == 192*q->channels*q->frame_factor)) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
964 } else {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
965 av_log(avctx,AV_LOG_ERROR,"Unknown frame/channel/frame_factor configuration %d/%d/%d\n", q->bytes_per_frame, q->channels, q->frame_factor);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
966 return -1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
967 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
968
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
969 } else if (avctx->extradata_size == 10) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
970 /* Parse the extradata, RM format. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
971 q->atrac3version = bytestream_get_be32(&edata_ptr);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
972 q->samples_per_frame = bytestream_get_be16(&edata_ptr);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
973 q->delay = bytestream_get_be16(&edata_ptr);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
974 q->codingMode = bytestream_get_be16(&edata_ptr);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
975
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
976 q->samples_per_channel = q->samples_per_frame / q->channels;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
977 q->scrambled_stream = 1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
978
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
979 } else {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
980 av_log(NULL,AV_LOG_ERROR,"Unknown extradata size %d.\n",avctx->extradata_size);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
981 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
982 /* Check the extradata. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
983
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
984 if (q->atrac3version != 4) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
985 av_log(avctx,AV_LOG_ERROR,"Version %d != 4.\n",q->atrac3version);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
986 return -1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
987 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
988
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
989 if (q->samples_per_frame != 1024 && q->samples_per_frame != 2048) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
990 av_log(avctx,AV_LOG_ERROR,"Unknown amount of samples per frame %d.\n",q->samples_per_frame);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
991 return -1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
992 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
993
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
994 if (q->delay != 0x88E) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
995 av_log(avctx,AV_LOG_ERROR,"Unknown amount of delay %x != 0x88E.\n",q->delay);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
996 return -1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
997 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
998
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
999 if (q->codingMode == STEREO) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1000 av_log(avctx,AV_LOG_DEBUG,"Normal stereo detected.\n");
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1001 } else if (q->codingMode == JOINT_STEREO) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1002 av_log(avctx,AV_LOG_DEBUG,"Joint stereo detected.\n");
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1003 } else {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1004 av_log(avctx,AV_LOG_ERROR,"Unknown channel coding mode %x!\n",q->codingMode);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1005 return -1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1006 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1007
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1008 if (avctx->channels <= 0 || avctx->channels > 2 /*|| ((avctx->channels * 1024) != q->samples_per_frame)*/) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1009 av_log(avctx,AV_LOG_ERROR,"Channel configuration error!\n");
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1010 return -1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1011 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1012
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1013
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1014 if(avctx->block_align >= UINT_MAX/2)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1015 return -1;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1016
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1017 /* Pad the data buffer with FF_INPUT_BUFFER_PADDING_SIZE,
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1018 * this is for the bitstream reader. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1019 if ((q->decoded_bytes_buffer = av_mallocz((avctx->block_align+(4-avctx->block_align%4) + FF_INPUT_BUFFER_PADDING_SIZE))) == NULL)
5407
91906ea3337f Replace a return of -1 with ENOMEM.
takis
parents: 4865
diff changeset
1020 return AVERROR(ENOMEM);
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1021
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1022
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1023 /* Initialize the VLC tables. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1024 for (i=0 ; i<7 ; i++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1025 init_vlc (&spectral_coeff_tab[i], 9, huff_tab_sizes[i],
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1026 huff_bits[i], 1, 1,
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1027 huff_codes[i], 1, 1, INIT_VLC_USE_STATIC);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1028 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1029
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1030 init_atrac3_transforms(q);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1031
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1032 /* Generate the scale factors. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1033 for (i=0 ; i<64 ; i++)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1034 SFTable[i] = pow(2.0, (i - 15) / 3.0);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1035
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1036 /* Generate gain tables. */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1037 for (i=0 ; i<16 ; i++)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1038 gain_tab1[i] = powf (2.0, (4 - i));
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1039
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1040 for (i=-15 ; i<16 ; i++)
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1041 gain_tab2[i+15] = powf (2.0, i * -0.125);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1042
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1043 /* init the joint-stereo decoding data */
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1044 q->weighting_delay[0] = 0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1045 q->weighting_delay[1] = 7;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1046 q->weighting_delay[2] = 0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1047 q->weighting_delay[3] = 7;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1048 q->weighting_delay[4] = 0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1049 q->weighting_delay[5] = 7;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1050
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1051 for (i=0; i<4; i++) {
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1052 q->matrix_coeff_index_prev[i] = 3;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1053 q->matrix_coeff_index_now[i] = 3;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1054 q->matrix_coeff_index_next[i] = 3;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1055 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1056
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1057 dsputil_init(&dsp, avctx);
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1058
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1059 q->pUnits = av_mallocz(sizeof(channel_unit)*q->channels);
5423
2c98d63a8956 Handle malloc failure
takis
parents: 5407
diff changeset
1060 if (!q->pUnits) {
2c98d63a8956 Handle malloc failure
takis
parents: 5407
diff changeset
1061 av_free(q->decoded_bytes_buffer);
2c98d63a8956 Handle malloc failure
takis
parents: 5407
diff changeset
1062 return AVERROR(ENOMEM);
2c98d63a8956 Handle malloc failure
takis
parents: 5407
diff changeset
1063 }
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1064
7451
85ab7655ad4d Modify all codecs to report their supported input and output sample format(s).
pross
parents: 7040
diff changeset
1065 avctx->sample_fmt = SAMPLE_FMT_S16;
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1066 return 0;
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1067 }
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1068
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1069
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1070 AVCodec atrac3_decoder =
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1071 {
6716
aa09311685b2 Transform codec names into single words.
diego
parents: 6710
diff changeset
1072 .name = "atrac3",
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1073 .type = CODEC_TYPE_AUDIO,
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1074 .id = CODEC_ID_ATRAC3,
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1075 .priv_data_size = sizeof(ATRAC3Context),
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1076 .init = atrac3_decode_init,
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1077 .close = atrac3_decode_close,
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1078 .decode = atrac3_decode_frame,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6997
diff changeset
1079 .long_name = NULL_IF_CONFIG_SMALL("Atrac 3 (Adaptive TRansform Acoustic Coding 3)"),
4856
5af8895c2805 Atrac3 decoder.
banan
parents:
diff changeset
1080 };