avcodec/adxenc: match prediction used in the decoder
authorMichael Niedermayer <michaelni@gmx.at>
Sun, 30 Nov 2014 11:40:03 +0000 (12:40 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Sun, 30 Nov 2014 11:52:56 +0000 (12:52 +0100)
The prediction used in the encoder was not correct

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavcodec/adxenc.c
tests/ref/acodec/adpcm-adx
tests/ref/acodec/adpcm-adx-trellis

index 05e3245..aee444e 100644 (file)
@@ -43,14 +43,12 @@ static void adx_encode(ADXContext *c, uint8_t *adx, const int16_t *wav,
     int s0, s1, s2, d;
     int max = 0;
     int min = 0;
-    int data[BLOCK_SAMPLES];
 
     s1 = prev->s1;
     s2 = prev->s2;
     for (i = 0, j = 0; j < 32; i += channels, j++) {
         s0 = wav[i];
         d = ((s0 << COEFF_BITS) - c->coeff[0] * s1 - c->coeff[1] * s2) >> COEFF_BITS;
-        data[j] = d;
         if (max < d)
             max = d;
         if (min > d)
@@ -58,10 +56,10 @@ static void adx_encode(ADXContext *c, uint8_t *adx, const int16_t *wav,
         s2 = s1;
         s1 = s0;
     }
-    prev->s1 = s1;
-    prev->s2 = s2;
 
     if (max == 0 && min == 0) {
+        prev->s1 = s1;
+        prev->s2 = s2;
         memset(adx, 0, BLOCK_SIZE);
         return;
     }
@@ -77,8 +75,23 @@ static void adx_encode(ADXContext *c, uint8_t *adx, const int16_t *wav,
     AV_WB16(adx, scale);
 
     init_put_bits(&pb, adx + 2, 16);
-    for (i = 0; i < BLOCK_SAMPLES; i++)
-        put_sbits(&pb, 4, av_clip(data[i] / scale, -8, 7));
+
+    s1 = prev->s1;
+    s2 = prev->s2;
+    for (i = 0, j = 0; j < 32; i += channels, j++) {
+        d = ((wav[i] << COEFF_BITS) - c->coeff[0] * s1 - c->coeff[1] * s2) >> COEFF_BITS;
+
+        d = av_clip(d / scale, -8, 7);
+
+        put_sbits(&pb, 4, d);
+
+        s0 = ((d << COEFF_BITS) * scale + c->coeff[0] * s1 + c->coeff[1] * s2) >> COEFF_BITS;
+        s2 = s1;
+        s1 = s0;
+    }
+    prev->s1 = s1;
+    prev->s2 = s2;
+
     flush_put_bits(&pb);
 }
 
index b96d99a..33a502f 100644 (file)
@@ -1,4 +1,4 @@
-0a30509d9296b857e134b762b76dbc31 *tests/data/fate/acodec-adpcm-adx.adx
+d82a87942d6500adb4d07d21cbcbdb78 *tests/data/fate/acodec-adpcm-adx.adx
 297720 tests/data/fate/acodec-adpcm-adx.adx
-7260139001fcac62384dad50a1023e75 *tests/data/fate/acodec-adpcm-adx.out.wav
-stddev: 6989.46 PSNR: 19.44 MAXDIFF:65398 bytes:  1058400/  1058432
+4e78a1153eb8fc4dfc050836f46b62f8 *tests/data/fate/acodec-adpcm-adx.out.wav
+stddev: 3096.24 PSNR: 26.51 MAXDIFF:53110 bytes:  1058400/  1058432
index fff0291..a36e7f9 100644 (file)
@@ -1,4 +1,4 @@
-0a30509d9296b857e134b762b76dbc31 *tests/data/fate/acodec-adpcm-adx-trellis.adx
+d82a87942d6500adb4d07d21cbcbdb78 *tests/data/fate/acodec-adpcm-adx-trellis.adx
 297720 tests/data/fate/acodec-adpcm-adx-trellis.adx
-7260139001fcac62384dad50a1023e75 *tests/data/fate/acodec-adpcm-adx-trellis.out.wav
-stddev: 6989.46 PSNR: 19.44 MAXDIFF:65398 bytes:  1058400/  1058432
+4e78a1153eb8fc4dfc050836f46b62f8 *tests/data/fate/acodec-adpcm-adx-trellis.out.wav
+stddev: 3096.24 PSNR: 26.51 MAXDIFF:53110 bytes:  1058400/  1058432