diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2014-11-30 14:40:03 +0300 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-11-30 14:52:56 +0300 |
commit | 6b0ab561d019c12471920ae136c746d3a54878e8 (patch) | |
tree | 4a1afb2c196a8a0ab1ba31a4cb4e1ef01ebcd2c4 /libavcodec/adxenc.c | |
parent | 93f959b672b1673f5eab5ca072bf9bdcee4b21bd (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>
Diffstat (limited to 'libavcodec/adxenc.c')
-rw-r--r-- | libavcodec/adxenc.c | 25 |
1 files changed, 19 insertions, 6 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); } |