49 #define JOINT_STEREO 0x12
52 #define SAMPLES_PER_FRAME 1024
107 int matrix_coeff_index_prev[4];
108 int matrix_coeff_index_now[4];
109 int matrix_coeff_index_next[4];
110 int weighting_delay[6];
114 float *outSamples[2];
160 for (i=0; i<128; i++)
161 FFSWAP(
float, pInput[i], pInput[255-i]);
180 static int decode_bytes(
const uint8_t* inbuffer, uint8_t* out,
int bytes){
184 uint32_t* obuf = (uint32_t*) out;
186 off = (intptr_t)inbuffer & 3;
187 buf = (
const uint32_t *)(inbuffer - off);
189 c =
av_be2ne32((0x537F6103U >> (off * 8)) | (0x537F6103U << (32 - (off * 8))));
193 for (i = 0; i < bytes/4; i++)
194 obuf[i] = c ^ buf[i];
204 float enc_window[256];
209 for (i=0 ; i<256; i++)
210 enc_window[i] = (sin(((i + 0.5) / 256.0 - 0.5) *
M_PI) + 1.0) * 0.5;
213 for (i=0 ; i<256; i++) {
214 mdct_window[i] = enc_window[i]/(enc_window[i]*enc_window[i] + enc_window[255-i]*enc_window[255-i]);
251 int numBits, cnt, code, huffSymb;
256 if (codingFlag != 0) {
261 for (cnt = 0; cnt < numCodes; cnt++) {
266 mantissas[cnt] = code;
269 for (cnt = 0; cnt < numCodes; cnt++) {
274 mantissas[cnt*2] =
seTab_0[code >> 2];
275 mantissas[cnt*2+1] =
seTab_0[code & 3];
281 for (cnt = 0; cnt < numCodes; cnt++) {
282 huffSymb =
get_vlc2(gb, spectral_coeff_tab[selector-1].table, spectral_coeff_tab[selector-1].
bits, 3);
284 code = huffSymb >> 1;
287 mantissas[cnt] = code;
290 for (cnt = 0; cnt < numCodes; cnt++) {
291 huffSymb =
get_vlc2(gb, spectral_coeff_tab[selector-1].table, spectral_coeff_tab[selector-1].
bits, 3);
292 mantissas[cnt*2] =
decTable1[huffSymb*2];
293 mantissas[cnt*2+1] =
decTable1[huffSymb*2+1];
309 int numSubbands, codingMode, cnt, first, last, subbWidth, *pIn;
310 int subband_vlc_index[32], SF_idxs[32];
318 for (cnt = 0; cnt <= numSubbands; cnt++)
319 subband_vlc_index[cnt] =
get_bits(gb, 3);
322 for (cnt = 0; cnt <= numSubbands; cnt++) {
323 if (subband_vlc_index[cnt] != 0)
327 for (cnt = 0; cnt <= numSubbands; cnt++) {
331 subbWidth = last - first;
333 if (subband_vlc_index[cnt] != 0) {
343 for (pIn=mantissas ; first<last; first++, pIn++)
344 pOut[first] = *pIn * SF;
347 memset(pOut+first, 0, subbWidth*
sizeof(
float));
368 int components, coding_mode_selector, coding_mode, coded_values_per_component;
369 int sfIndx, coded_values, max_coded_values, quant_step_index, coded_components;
370 int band_flags[4], mantissa[8];
373 int component_count = 0;
381 coding_mode_selector =
get_bits(gb,2);
382 if (coding_mode_selector == 2)
385 coding_mode = coding_mode_selector & 1;
387 for (i = 0; i < components; i++) {
388 for (cnt = 0; cnt <= numBands; cnt++)
391 coded_values_per_component =
get_bits(gb,3);
394 if (quant_step_index <= 1)
397 if (coding_mode_selector == 3)
400 for (j = 0; j < (numBands + 1) * 4; j++) {
401 if (band_flags[j >> 2] == 0)
406 for (k=0; k<coded_components; k++) {
408 if (component_count >= 64)
410 pComponent[component_count].
pos = j * 64 + (
get_bits(gb,6));
412 coded_values = coded_values_per_component + 1;
413 coded_values =
FFMIN(max_coded_values,coded_values);
419 pComponent[component_count].
numCoefs = coded_values;
422 pCoef = pComponent[component_count].
coef;
423 for (cnt = 0; cnt < coded_values; cnt++)
424 pCoef[cnt] = mantissa[cnt] * scalefactor;
431 return component_count;
449 for (i=0 ; i<=numBands; i++)
456 for (cf = 0; cf < numData; cf++){
459 if(cf && pLoc[cf] <= pLoc[cf-1])
466 pGain[i].num_gain_data = 0;
484 float gain1, gain2, gain_inc;
485 int cnt, numdata, nsample, startLoc, endLoc;
494 for (cnt = 0; cnt < 256; cnt++)
495 pOut[cnt] = pIn[cnt] * gain1 + pPrev[cnt];
503 for (cnt = 0; cnt < numdata; cnt++) {
504 startLoc = pGain1->
loccode[cnt] * 8;
505 endLoc = startLoc + 8;
511 for (; nsample < startLoc; nsample++)
512 pOut[nsample] = (pIn[nsample] * gain1 + pPrev[nsample]) * gain2;
515 for (; nsample < endLoc; nsample++) {
516 pOut[nsample] = (pIn[nsample] * gain1 + pPrev[nsample]) * gain2;
521 for (; nsample < 256; nsample++)
522 pOut[nsample] = (pIn[nsample] * gain1) + pPrev[nsample];
526 memcpy(pPrev, &pIn[256], 256*
sizeof(
float));
540 int cnt, i, lastPos = -1;
543 for (cnt = 0; cnt < numComponents; cnt++){
544 lastPos =
FFMAX(pComponent[cnt].pos + pComponent[cnt].numCoefs, lastPos);
545 pIn = pComponent[cnt].
coef;
546 pOut = &(pSpectrum[pComponent[cnt].
pos]);
548 for (i=0 ; i<pComponent[cnt].
numCoefs ; i++)
556 #define INTERPOLATE(old,new,nsample) ((old) + (nsample)*0.125*((new)-(old)))
560 int i, band, nsample,
s1,
s2;
562 float mc1_l, mc1_r, mc2_l, mc2_r;
564 for (i=0,band = 0; band < 4*256; band+=256,i++) {
577 for(; nsample < 8; nsample++) {
578 c1 = su1[band+nsample];
579 c2 = su2[band+nsample];
581 su1[band+nsample] =
c2;
582 su2[band+nsample] = c1 * 2.0 -
c2;
589 for (; nsample < 256; nsample++) {
590 c1 = su1[band+nsample];
591 c2 = su2[band+nsample];
592 su1[band+nsample] = c2 * 2.0;
593 su2[band+nsample] = (c1 -
c2) * 2.0;
598 for (; nsample < 256; nsample++) {
599 c1 = su1[band+nsample];
600 c2 = su2[band+nsample];
601 su1[band+nsample] = (c1 +
c2) * 2.0;
602 su2[band+nsample] = c2 * -2.0;
607 for (; nsample < 256; nsample++) {
608 c1 = su1[band+nsample];
609 c2 = su2[band+nsample];
610 su1[band+nsample] = c1 +
c2;
611 su2[band+nsample] = c1 -
c2;
626 ch[0] = (float)(indx & 7) / 7.0;
627 ch[1] = sqrt(2 - ch[0]*ch[0]);
629 FFSWAP(
float, ch[0], ch[1]);
639 if (p3[1] != 7 || p3[3] != 7){
643 for(band = 1; band < 4; band++) {
645 for(nsample = 0; nsample < 8; nsample++) {
646 su1[band*256+nsample] *=
INTERPOLATE(w[0][0], w[0][1], nsample);
647 su2[band*256+nsample] *=
INTERPOLATE(w[1][0], w[1][1], nsample);
650 for(; nsample < 256; nsample++) {
651 su1[band*256+nsample] *= w[1][0];
652 su2[band*256+nsample] *= w[1][1];
672 int band, result=0, numSubbands, lastTonal, numBands;
690 if (result)
return result;
702 numBands = (
subbandTab[numSubbands] - 1) >> 8;
704 numBands =
FFMAX((lastTonal + 256) >> 8, numBands);
708 for (band=0; band<4; band++) {
710 if (band <= numBands) {
713 memset(pSnd->
IMDCT_buf, 0, 512 *
sizeof(
float));
739 float *p1, *p2, *p3, *p4;
758 FFSWAP(uint8_t,*ptr1,*ptr2);
768 for (i = 4; *ptr1 == 0xF8; i++, ptr1++) {
782 for (i = 0; i < 4; i++) {
836 int *got_frame_ptr,
AVPacket *avpkt)
838 const uint8_t *buf = avpkt->
data;
839 int buf_size = avpkt->
size;
842 const uint8_t* databuf;
844 int16_t *samples_s16;
846 if (buf_size < avctx->block_align) {
848 "Frame too small (%d bytes). Truncated file?\n", buf_size);
859 samples_s16 = (int16_t *)q->
frame.
data[0];
906 const uint8_t *edata_ptr = avctx->
extradata;
908 static VLC_TYPE atrac3_vlc_table[4096][2];
909 static int vlcs_initialized = 0;
923 q->
codingMode = bytestream_get_le16(&edata_ptr);
949 q->
delay = bytestream_get_be16(&edata_ptr);
950 q->
codingMode = bytestream_get_be16(&edata_ptr);
970 if (q->
delay != 0x88E) {
1000 if (!vlcs_initialized) {
1001 for (i=0 ; i<7 ; i++) {
1003 spectral_coeff_tab[i].
table_allocated = atrac3_vlc_offs[i + 1] - atrac3_vlc_offs[i];
1008 vlcs_initialized = 1;
1025 for (i=0 ; i<16 ; i++)
1028 for (i=-15 ; i<16 ; i++)
1029 gain_tab2[i+15] = powf (2.0, i * -0.125);
1039 for (i=0; i<4; i++) {