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);
188 c =
av_be2ne32((0x537F6103 >> (off*8)) | (0x537F6103 << (32-(off*8))));
190 for (i = 0; i < bytes/4; i++)
191 obuf[i] = c ^ buf[i];
201 float enc_window[256];
206 for (i=0 ; i<256; i++)
207 enc_window[i] = (sin(((i + 0.5) / 256.0 - 0.5) *
M_PI) + 1.0) * 0.5;
210 for (i=0 ; i<256; i++) {
211 mdct_window[i] = enc_window[i]/(enc_window[i]*enc_window[i] + enc_window[255-i]*enc_window[255-i]);
248 int numBits, cnt, code, huffSymb;
253 if (codingFlag != 0) {
258 for (cnt = 0; cnt < numCodes; cnt++) {
263 mantissas[cnt] = code;
266 for (cnt = 0; cnt < numCodes; cnt++) {
271 mantissas[cnt*2] =
seTab_0[code >> 2];
272 mantissas[cnt*2+1] =
seTab_0[code & 3];
278 for (cnt = 0; cnt < numCodes; cnt++) {
279 huffSymb =
get_vlc2(gb, spectral_coeff_tab[selector-1].table, spectral_coeff_tab[selector-1].
bits, 3);
281 code = huffSymb >> 1;
284 mantissas[cnt] = code;
287 for (cnt = 0; cnt < numCodes; cnt++) {
288 huffSymb =
get_vlc2(gb, spectral_coeff_tab[selector-1].table, spectral_coeff_tab[selector-1].
bits, 3);
289 mantissas[cnt*2] =
decTable1[huffSymb*2];
290 mantissas[cnt*2+1] =
decTable1[huffSymb*2+1];
306 int numSubbands, codingMode, cnt, first, last, subbWidth, *pIn;
307 int subband_vlc_index[32], SF_idxs[32];
315 for (cnt = 0; cnt <= numSubbands; cnt++)
316 subband_vlc_index[cnt] =
get_bits(gb, 3);
319 for (cnt = 0; cnt <= numSubbands; cnt++) {
320 if (subband_vlc_index[cnt] != 0)
324 for (cnt = 0; cnt <= numSubbands; cnt++) {
328 subbWidth = last - first;
330 if (subband_vlc_index[cnt] != 0) {
340 for (pIn=mantissas ; first<last; first++, pIn++)
341 pOut[first] = *pIn * SF;
344 memset(pOut+first, 0, subbWidth*
sizeof(
float));
365 int components, coding_mode_selector, coding_mode, coded_values_per_component;
366 int sfIndx, coded_values, max_coded_values, quant_step_index, coded_components;
367 int band_flags[4], mantissa[8];
370 int component_count = 0;
378 coding_mode_selector =
get_bits(gb,2);
379 if (coding_mode_selector == 2)
382 coding_mode = coding_mode_selector & 1;
384 for (i = 0; i < components; i++) {
385 for (cnt = 0; cnt <= numBands; cnt++)
388 coded_values_per_component =
get_bits(gb,3);
391 if (quant_step_index <= 1)
394 if (coding_mode_selector == 3)
397 for (j = 0; j < (numBands + 1) * 4; j++) {
398 if (band_flags[j >> 2] == 0)
403 for (k=0; k<coded_components; k++) {
405 if (component_count >= 64)
407 pComponent[component_count].
pos = j * 64 + (
get_bits(gb,6));
409 coded_values = coded_values_per_component + 1;
410 coded_values =
FFMIN(max_coded_values,coded_values);
416 pComponent[component_count].
numCoefs = coded_values;
419 pCoef = pComponent[component_count].
coef;
420 for (cnt = 0; cnt < coded_values; cnt++)
421 pCoef[cnt] = mantissa[cnt] * scalefactor;
428 return component_count;
446 for (i=0 ; i<=numBands; i++)
453 for (cf = 0; cf < numData; cf++){
456 if(cf && pLoc[cf] <= pLoc[cf-1])
463 pGain[i].num_gain_data = 0;
481 float gain1, gain2, gain_inc;
482 int cnt, numdata, nsample, startLoc, endLoc;
491 for (cnt = 0; cnt < 256; cnt++)
492 pOut[cnt] = pIn[cnt] * gain1 + pPrev[cnt];
500 for (cnt = 0; cnt < numdata; cnt++) {
501 startLoc = pGain1->
loccode[cnt] * 8;
502 endLoc = startLoc + 8;
508 for (; nsample < startLoc; nsample++)
509 pOut[nsample] = (pIn[nsample] * gain1 + pPrev[nsample]) * gain2;
512 for (; nsample < endLoc; nsample++) {
513 pOut[nsample] = (pIn[nsample] * gain1 + pPrev[nsample]) * gain2;
518 for (; nsample < 256; nsample++)
519 pOut[nsample] = (pIn[nsample] * gain1) + pPrev[nsample];
523 memcpy(pPrev, &pIn[256], 256*
sizeof(
float));
537 int cnt, i, lastPos = -1;
540 for (cnt = 0; cnt < numComponents; cnt++){
541 lastPos =
FFMAX(pComponent[cnt].pos + pComponent[cnt].numCoefs, lastPos);
542 pIn = pComponent[cnt].
coef;
543 pOut = &(pSpectrum[pComponent[cnt].
pos]);
545 for (i=0 ; i<pComponent[cnt].
numCoefs ; i++)
553 #define INTERPOLATE(old,new,nsample) ((old) + (nsample)*0.125*((new)-(old)))
557 int i, band, nsample,
s1,
s2;
559 float mc1_l, mc1_r, mc2_l, mc2_r;
561 for (i=0,band = 0; band < 4*256; band+=256,i++) {
574 for(; nsample < 8; nsample++) {
575 c1 = su1[band+nsample];
576 c2 = su2[band+nsample];
578 su1[band+nsample] =
c2;
579 su2[band+nsample] = c1 * 2.0 -
c2;
586 for (; nsample < 256; nsample++) {
587 c1 = su1[band+nsample];
588 c2 = su2[band+nsample];
589 su1[band+nsample] = c2 * 2.0;
590 su2[band+nsample] = (c1 -
c2) * 2.0;
595 for (; nsample < 256; nsample++) {
596 c1 = su1[band+nsample];
597 c2 = su2[band+nsample];
598 su1[band+nsample] = (c1 +
c2) * 2.0;
599 su2[band+nsample] = c2 * -2.0;
604 for (; nsample < 256; nsample++) {
605 c1 = su1[band+nsample];
606 c2 = su2[band+nsample];
607 su1[band+nsample] = c1 +
c2;
608 su2[band+nsample] = c1 -
c2;
623 ch[0] = (float)(indx & 7) / 7.0;
624 ch[1] = sqrt(2 - ch[0]*ch[0]);
626 FFSWAP(
float, ch[0], ch[1]);
636 if (p3[1] != 7 || p3[3] != 7){
640 for(band = 1; band < 4; band++) {
642 for(nsample = 0; nsample < 8; nsample++) {
643 su1[band*256+nsample] *=
INTERPOLATE(w[0][0], w[0][1], nsample);
644 su2[band*256+nsample] *=
INTERPOLATE(w[1][0], w[1][1], nsample);
647 for(; nsample < 256; nsample++) {
648 su1[band*256+nsample] *= w[1][0];
649 su2[band*256+nsample] *= w[1][1];
669 int band, result=0, numSubbands, lastTonal, numBands;
687 if (result)
return result;
699 numBands = (
subbandTab[numSubbands] - 1) >> 8;
701 numBands =
FFMAX((lastTonal + 256) >> 8, numBands);
705 for (band=0; band<4; band++) {
707 if (band <= numBands) {
710 memset(pSnd->
IMDCT_buf, 0, 512 *
sizeof(
float));
736 float *p1, *p2, *p3, *p4;
755 FFSWAP(uint8_t,*ptr1,*ptr2);
765 for (i = 4; *ptr1 == 0xF8; i++, ptr1++) {
779 for (i = 0; i < 4; i++) {
833 int *got_frame_ptr,
AVPacket *avpkt)
835 const uint8_t *buf = avpkt->
data;
836 int buf_size = avpkt->
size;
839 const uint8_t* databuf;
841 int16_t *samples_s16;
843 if (buf_size < avctx->block_align) {
845 "Frame too small (%d bytes). Truncated file?\n", buf_size);
856 samples_s16 = (int16_t *)q->
frame.
data[0];
903 const uint8_t *edata_ptr = avctx->
extradata;
905 static VLC_TYPE atrac3_vlc_table[4096][2];
906 static int vlcs_initialized = 0;
920 q->
codingMode = bytestream_get_le16(&edata_ptr);
946 q->
delay = bytestream_get_be16(&edata_ptr);
947 q->
codingMode = bytestream_get_be16(&edata_ptr);
967 if (q->
delay != 0x88E) {
997 if (!vlcs_initialized) {
998 for (i=0 ; i<7 ; i++) {
1000 spectral_coeff_tab[i].
table_allocated = atrac3_vlc_offs[i + 1] - atrac3_vlc_offs[i];
1005 vlcs_initialized = 1;
1022 for (i=0 ; i<16 ; i++)
1025 for (i=-15 ; i<16 ; i++)
1026 gain_tab2[i+15] = powf (2.0, i * -0.125);
1036 for (i=0; i<4; i++) {