summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-11-30 12:40:03 +0100
committerMichael Niedermayer <michaelni@gmx.at>2014-11-30 12:52:56 +0100
commit6b0ab561d019c12471920ae136c746d3a54878e8 (patch)
tree4a1afb2c196a8a0ab1ba31a4cb4e1ef01ebcd2c4
parent93f959b672b1673f5eab5ca072bf9bdcee4b21bd (diff)
avcodec/adxenc: match prediction used in the decoder
The prediction used in the encoder was not correct Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavcodec/adxenc.c25
-rw-r--r--tests/ref/acodec/adpcm-adx6
-rw-r--r--tests/ref/acodec/adpcm-adx-trellis6
3 files changed, 25 insertions, 12 deletions
diff --git a/libavcodec/adxenc.c b/libavcodec/adxenc.c
index 05e32455c7..aee444e42c 100644
--- a/libavcodec/adxenc.c
+++ b/libavcodec/adxenc.c
@@ -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);
}
diff --git a/tests/ref/acodec/adpcm-adx b/tests/ref/acodec/adpcm-adx
index b96d99a73a..33a502fbbf 100644
--- a/tests/ref/acodec/adpcm-adx
+++ b/tests/ref/acodec/adpcm-adx
@@ -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
diff --git a/tests/ref/acodec/adpcm-adx-trellis b/tests/ref/acodec/adpcm-adx-trellis
index fff0291228..a36e7f9882 100644
--- a/tests/ref/acodec/adpcm-adx-trellis
+++ b/tests/ref/acodec/adpcm-adx-trellis
@@ -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