changeset 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 61ff2f1d36bb
children 94dc0de175d9
files atrac3.c
diffstat 1 files changed, 12 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/atrac3.c	Wed May 21 19:24:17 2008 +0000
+++ b/atrac3.c	Thu May 22 19:16:28 2008 +0000
@@ -468,7 +468,7 @@
                 pComponent[component_count].numCoefs = coded_values;
 
                 /* inverse quant */
-                pCoef = pComponent[k].coef;
+                pCoef = pComponent[component_count].coef;
                 for (cnt = 0; cnt < coded_values; cnt++)
                     pCoef[cnt] = mantissa[cnt] * scalefactor;
 
@@ -577,24 +577,28 @@
 
 /**
  * Combine the tonal band spectrum and regular band spectrum
+ * Return position of the last tonal coefficient
  *
  * @param pSpectrum     output spectrum buffer
  * @param numComponents amount of tonal components
  * @param pComponent    tonal components for this band
  */
 
-static void addTonalComponents (float *pSpectrum, int numComponents, tonal_component *pComponent)
+static int addTonalComponents (float *pSpectrum, int numComponents, tonal_component *pComponent)
 {
-    int   cnt, i;
+    int   cnt, i, lastPos = -1;
     float   *pIn, *pOut;
 
     for (cnt = 0; cnt < numComponents; cnt++){
+        lastPos = FFMAX(pComponent[cnt].pos + pComponent[cnt].numCoefs, lastPos);
         pIn = pComponent[cnt].coef;
         pOut = &(pSpectrum[pComponent[cnt].pos]);
 
         for (i=0 ; i<pComponent[cnt].numCoefs ; i++)
             pOut[i] += pIn[i];
     }
+
+    return lastPos;
 }
 
 
@@ -714,7 +718,7 @@
 
 static int decodeChannelSoundUnit (ATRAC3Context *q, GetBitContext *gb, channel_unit *pSnd, float *pOut, int channelNum, int codingMode)
 {
-    int   band, result=0, numSubbands, numBands;
+    int   band, result=0, numSubbands, lastTonal, numBands;
 
     if (codingMode == JOINT_STEREO && channelNum == 1) {
         if (get_bits(gb,2) != 3) {
@@ -740,11 +744,13 @@
     numSubbands = decodeSpectrum (gb, pSnd->spectrum);
 
     /* Merge the decoded spectrum and tonal components. */
-    addTonalComponents (pSnd->spectrum, pSnd->numComponents, pSnd->components);
+    lastTonal = addTonalComponents (pSnd->spectrum, pSnd->numComponents, pSnd->components);
 
 
-    /* Convert number of subbands into number of MLT/QMF bands */
+    /* calculate number of used MLT/QMF bands according to the amount of coded spectral lines */
     numBands = (subbandTab[numSubbands] - 1) >> 8;
+    if (lastTonal >= 0)
+        numBands = FFMAX((lastTonal + 256) >> 8, numBands);
 
 
     /* Reconstruct time domain samples. */