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