comparison atrac3.c @ 6843:bc8faf4f8b7d libavcodec

Fix decoding of 01-Untitled(1).oma, patch by Maxim Poliakovski
author banan
date Thu, 22 May 2008 19:16:28 +0000
parents aa09311685b2
children 94dc0de175d9
comparison
equal deleted inserted replaced
6842:61ff2f1d36bb 6843:bc8faf4f8b7d
466 readQuantSpectralCoeffs(gb, quant_step_index, coding_mode, mantissa, coded_values); 466 readQuantSpectralCoeffs(gb, quant_step_index, coding_mode, mantissa, coded_values);
467 467
468 pComponent[component_count].numCoefs = coded_values; 468 pComponent[component_count].numCoefs = coded_values;
469 469
470 /* inverse quant */ 470 /* inverse quant */
471 pCoef = pComponent[k].coef; 471 pCoef = pComponent[component_count].coef;
472 for (cnt = 0; cnt < coded_values; cnt++) 472 for (cnt = 0; cnt < coded_values; cnt++)
473 pCoef[cnt] = mantissa[cnt] * scalefactor; 473 pCoef[cnt] = mantissa[cnt] * scalefactor;
474 474
475 component_count++; 475 component_count++;
476 } 476 }
575 memcpy(pPrev, &pIn[256], 256*sizeof(float)); 575 memcpy(pPrev, &pIn[256], 256*sizeof(float));
576 } 576 }
577 577
578 /** 578 /**
579 * Combine the tonal band spectrum and regular band spectrum 579 * Combine the tonal band spectrum and regular band spectrum
580 * Return position of the last tonal coefficient
580 * 581 *
581 * @param pSpectrum output spectrum buffer 582 * @param pSpectrum output spectrum buffer
582 * @param numComponents amount of tonal components 583 * @param numComponents amount of tonal components
583 * @param pComponent tonal components for this band 584 * @param pComponent tonal components for this band
584 */ 585 */
585 586
586 static void addTonalComponents (float *pSpectrum, int numComponents, tonal_component *pComponent) 587 static int addTonalComponents (float *pSpectrum, int numComponents, tonal_component *pComponent)
587 { 588 {
588 int cnt, i; 589 int cnt, i, lastPos = -1;
589 float *pIn, *pOut; 590 float *pIn, *pOut;
590 591
591 for (cnt = 0; cnt < numComponents; cnt++){ 592 for (cnt = 0; cnt < numComponents; cnt++){
593 lastPos = FFMAX(pComponent[cnt].pos + pComponent[cnt].numCoefs, lastPos);
592 pIn = pComponent[cnt].coef; 594 pIn = pComponent[cnt].coef;
593 pOut = &(pSpectrum[pComponent[cnt].pos]); 595 pOut = &(pSpectrum[pComponent[cnt].pos]);
594 596
595 for (i=0 ; i<pComponent[cnt].numCoefs ; i++) 597 for (i=0 ; i<pComponent[cnt].numCoefs ; i++)
596 pOut[i] += pIn[i]; 598 pOut[i] += pIn[i];
597 } 599 }
600
601 return lastPos;
598 } 602 }
599 603
600 604
601 #define INTERPOLATE(old,new,nsample) ((old) + (nsample)*0.125*((new)-(old))) 605 #define INTERPOLATE(old,new,nsample) ((old) + (nsample)*0.125*((new)-(old)))
602 606
712 */ 716 */
713 717
714 718
715 static int decodeChannelSoundUnit (ATRAC3Context *q, GetBitContext *gb, channel_unit *pSnd, float *pOut, int channelNum, int codingMode) 719 static int decodeChannelSoundUnit (ATRAC3Context *q, GetBitContext *gb, channel_unit *pSnd, float *pOut, int channelNum, int codingMode)
716 { 720 {
717 int band, result=0, numSubbands, numBands; 721 int band, result=0, numSubbands, lastTonal, numBands;
718 722
719 if (codingMode == JOINT_STEREO && channelNum == 1) { 723 if (codingMode == JOINT_STEREO && channelNum == 1) {
720 if (get_bits(gb,2) != 3) { 724 if (get_bits(gb,2) != 3) {
721 av_log(NULL,AV_LOG_ERROR,"JS mono Sound Unit id != 3.\n"); 725 av_log(NULL,AV_LOG_ERROR,"JS mono Sound Unit id != 3.\n");
722 return -1; 726 return -1;
738 if (pSnd->numComponents == -1) return -1; 742 if (pSnd->numComponents == -1) return -1;
739 743
740 numSubbands = decodeSpectrum (gb, pSnd->spectrum); 744 numSubbands = decodeSpectrum (gb, pSnd->spectrum);
741 745
742 /* Merge the decoded spectrum and tonal components. */ 746 /* Merge the decoded spectrum and tonal components. */
743 addTonalComponents (pSnd->spectrum, pSnd->numComponents, pSnd->components); 747 lastTonal = addTonalComponents (pSnd->spectrum, pSnd->numComponents, pSnd->components);
744 748
745 749
746 /* Convert number of subbands into number of MLT/QMF bands */ 750 /* calculate number of used MLT/QMF bands according to the amount of coded spectral lines */
747 numBands = (subbandTab[numSubbands] - 1) >> 8; 751 numBands = (subbandTab[numSubbands] - 1) >> 8;
752 if (lastTonal >= 0)
753 numBands = FFMAX((lastTonal + 256) >> 8, numBands);
748 754
749 755
750 /* Reconstruct time domain samples. */ 756 /* Reconstruct time domain samples. */
751 for (band=0; band<4; band++) { 757 for (band=0; band<4; band++) {
752 /* Perform the IMDCT step without overlapping. */ 758 /* Perform the IMDCT step without overlapping. */