50 #define JOINT_STEREO 0x12
53 #define SAMPLES_PER_FRAME 1024
108 int matrix_coeff_index_prev[4];
109 int matrix_coeff_index_now[4];
110 int matrix_coeff_index_next[4];
111 int weighting_delay[6];
115 float *outSamples[2];
161 for (i=0; i<128; i++)
162 FFSWAP(
float, pInput[i], pInput[255-i]);
181 static int decode_bytes(
const uint8_t* inbuffer, uint8_t* out,
int bytes){
185 uint32_t* obuf = (uint32_t*) out;
187 off = (intptr_t)inbuffer & 3;
188 buf = (
const uint32_t *)(inbuffer - off);
190 c =
av_be2ne32((0x537F6103U >> (off * 8)) | (0x537F6103U << (32 - (off * 8))));
194 for (i = 0; i < bytes/4; i++)
195 obuf[i] = c ^ buf[i];
205 float enc_window[256];
210 for (i=0 ; i<256; i++)
211 enc_window[i] = (sin(((i + 0.5) / 256.0 - 0.5) *
M_PI) + 1.0) * 0.5;
214 for (i=0 ; i<256; i++) {
215 mdct_window[i] = enc_window[i]/(enc_window[i]*enc_window[i] + enc_window[255-i]*enc_window[255-i]);
252 int numBits, cnt, code, huffSymb;
257 if (codingFlag != 0) {
262 for (cnt = 0; cnt < numCodes; cnt++) {
267 mantissas[cnt] = code;
270 for (cnt = 0; cnt < numCodes; cnt++) {
275 mantissas[cnt*2] =
seTab_0[code >> 2];
276 mantissas[cnt*2+1] =
seTab_0[code & 3];
282 for (cnt = 0; cnt < numCodes; cnt++) {
283 huffSymb =
get_vlc2(gb, spectral_coeff_tab[selector-1].table, spectral_coeff_tab[selector-1].
bits, 3);
285 code = huffSymb >> 1;
288 mantissas[cnt] = code;
291 for (cnt = 0; cnt < numCodes; cnt++) {
292 huffSymb =
get_vlc2(gb, spectral_coeff_tab[selector-1].table, spectral_coeff_tab[selector-1].
bits, 3);
293 mantissas[cnt*2] =
decTable1[huffSymb*2];
294 mantissas[cnt*2+1] =
decTable1[huffSymb*2+1];
310 int numSubbands, codingMode, cnt, first, last, subbWidth, *pIn;
311 int subband_vlc_index[32], SF_idxs[32];
319 for (cnt = 0; cnt <= numSubbands; cnt++)
320 subband_vlc_index[cnt] =
get_bits(gb, 3);
323 for (cnt = 0; cnt <= numSubbands; cnt++) {
324 if (subband_vlc_index[cnt] != 0)
328 for (cnt = 0; cnt <= numSubbands; cnt++) {
332 subbWidth = last - first;
334 if (subband_vlc_index[cnt] != 0) {
344 for (pIn=mantissas ; first<last; first++, pIn++)
345 pOut[first] = *pIn * SF;
348 memset(pOut+first, 0, subbWidth*
sizeof(
float));
369 int components, coding_mode_selector, coding_mode, coded_values_per_component;
370 int sfIndx, coded_values, max_coded_values, quant_step_index, coded_components;
371 int band_flags[4], mantissa[8];
374 int component_count = 0;
382 coding_mode_selector =
get_bits(gb,2);
383 if (coding_mode_selector == 2)
386 coding_mode = coding_mode_selector & 1;
388 for (i = 0; i < components; i++) {
389 for (cnt = 0; cnt <= numBands; cnt++)
392 coded_values_per_component =
get_bits(gb,3);
395 if (quant_step_index <= 1)
398 if (coding_mode_selector == 3)
401 for (j = 0; j < (numBands + 1) * 4; j++) {
402 if (band_flags[j >> 2] == 0)
407 for (k=0; k<coded_components; k++) {
409 if (component_count >= 64)
411 pComponent[component_count].
pos = j * 64 + (
get_bits(gb,6));
413 coded_values = coded_values_per_component + 1;
414 coded_values =
FFMIN(max_coded_values,coded_values);
420 pComponent[component_count].
numCoefs = coded_values;
423 pCoef = pComponent[component_count].
coef;
424 for (cnt = 0; cnt < coded_values; cnt++)
425 pCoef[cnt] = mantissa[cnt] * scalefactor;
432 return component_count;
450 for (i=0 ; i<=numBands; i++)
457 for (cf = 0; cf < numData; cf++){
460 if(cf && pLoc[cf] <= pLoc[cf-1])
467 pGain[i].num_gain_data = 0;
485 float gain1, gain2, gain_inc;
486 int cnt, numdata, nsample, startLoc, endLoc;
495 for (cnt = 0; cnt < 256; cnt++)
496 pOut[cnt] = pIn[cnt] * gain1 + pPrev[cnt];
504 for (cnt = 0; cnt < numdata; cnt++) {
505 startLoc = pGain1->
loccode[cnt] * 8;
506 endLoc = startLoc + 8;
512 for (; nsample < startLoc; nsample++)
513 pOut[nsample] = (pIn[nsample] * gain1 + pPrev[nsample]) * gain2;
516 for (; nsample < endLoc; nsample++) {
517 pOut[nsample] = (pIn[nsample] * gain1 + pPrev[nsample]) * gain2;
522 for (; nsample < 256; nsample++)
523 pOut[nsample] = (pIn[nsample] * gain1) + pPrev[nsample];
527 memcpy(pPrev, &pIn[256], 256*
sizeof(
float));
541 int cnt, i, lastPos = -1;
544 for (cnt = 0; cnt < numComponents; cnt++){
545 lastPos =
FFMAX(pComponent[cnt].pos + pComponent[cnt].numCoefs, lastPos);
546 pIn = pComponent[cnt].
coef;
547 pOut = &(pSpectrum[pComponent[cnt].
pos]);
549 for (i=0 ; i<pComponent[cnt].
numCoefs ; i++)
557 #define INTERPOLATE(old,new,nsample) ((old) + (nsample)*0.125*((new)-(old)))
561 int i, band, nsample,
s1,
s2;
563 float mc1_l, mc1_r, mc2_l, mc2_r;
565 for (i=0,band = 0; band < 4*256; band+=256,i++) {
578 for(; nsample < 8; nsample++) {
579 c1 = su1[band+nsample];
580 c2 = su2[band+nsample];
582 su1[band+nsample] =
c2;
583 su2[band+nsample] = c1 * 2.0 -
c2;
590 for (; nsample < 256; nsample++) {
591 c1 = su1[band+nsample];
592 c2 = su2[band+nsample];
593 su1[band+nsample] = c2 * 2.0;
594 su2[band+nsample] = (c1 -
c2) * 2.0;
599 for (; nsample < 256; nsample++) {
600 c1 = su1[band+nsample];
601 c2 = su2[band+nsample];
602 su1[band+nsample] = (c1 +
c2) * 2.0;
603 su2[band+nsample] = c2 * -2.0;
608 for (; nsample < 256; nsample++) {
609 c1 = su1[band+nsample];
610 c2 = su2[band+nsample];
611 su1[band+nsample] = c1 +
c2;
612 su2[band+nsample] = c1 -
c2;
627 ch[0] = (float)(indx & 7) / 7.0;
628 ch[1] = sqrt(2 - ch[0]*ch[0]);
630 FFSWAP(
float, ch[0], ch[1]);
640 if (p3[1] != 7 || p3[3] != 7){
644 for(band = 1; band < 4; band++) {
646 for(nsample = 0; nsample < 8; nsample++) {
647 su1[band*256+nsample] *=
INTERPOLATE(w[0][0], w[0][1], nsample);
648 su2[band*256+nsample] *=
INTERPOLATE(w[1][0], w[1][1], nsample);
651 for(; nsample < 256; nsample++) {
652 su1[band*256+nsample] *= w[1][0];
653 su2[band*256+nsample] *= w[1][1];
673 int band, result=0, numSubbands, lastTonal, numBands;
691 if (result)
return result;
704 numBands = (
subbandTab[numSubbands] - 1) >> 8;
706 numBands =
FFMAX((lastTonal + 256) >> 8, numBands);
710 for (band=0; band<4; band++) {
712 if (band <= numBands) {
715 memset(pSnd->
IMDCT_buf, 0, 512 *
sizeof(
float));
741 float *p1, *p2, *p3, *p4;
760 FFSWAP(uint8_t,*ptr1,*ptr2);
770 for (i = 4; *ptr1 == 0xF8; i++, ptr1++) {
784 for (i = 0; i < 4; i++) {
838 int *got_frame_ptr,
AVPacket *avpkt)
840 const uint8_t *buf = avpkt->
data;
841 int buf_size = avpkt->
size;
844 const uint8_t* databuf;
846 int16_t *samples_s16;
848 if (buf_size < avctx->block_align) {
850 "Frame too small (%d bytes). Truncated file?\n", buf_size);
861 samples_s16 = (int16_t *)q->
frame.
data[0];
908 const uint8_t *edata_ptr = avctx->
extradata;
910 static VLC_TYPE atrac3_vlc_table[4096][2];
911 static int vlcs_initialized = 0;
925 q->
codingMode = bytestream_get_le16(&edata_ptr);
951 q->
delay = bytestream_get_be16(&edata_ptr);
952 q->
codingMode = bytestream_get_be16(&edata_ptr);
972 if (q->
delay != 0x88E) {
1004 if (!vlcs_initialized) {
1005 for (i=0 ; i<7 ; i++) {
1007 spectral_coeff_tab[i].
table_allocated = atrac3_vlc_offs[i + 1] - atrac3_vlc_offs[i];
1012 vlcs_initialized = 1;
1029 for (i=0 ; i<16 ; i++)
1032 for (i=-15 ; i<16 ; i++)
1033 gain_tab2[i+15] = powf (2.0, i * -0.125);
1043 for (i=0; i<4; i++) {