From ac68607bfe62000520db2e1c2416c11c51b3b295 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Tue, 6 Sep 2011 15:13:59 -0400 Subject: 8svx: split delta decoding into a separate function. Based on a patch by Stefano Sabatini. git.videolan.org/ffmpeg.git commit e280a4da2ae6fd44f0079358ecc5aa08e388a5ed --- libavcodec/8svx.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/libavcodec/8svx.c b/libavcodec/8svx.c index 4b60377128..dccaadddb0 100644 --- a/libavcodec/8svx.c +++ b/libavcodec/8svx.c @@ -41,6 +41,28 @@ static const int16_t fibonacci[16] = { -34<<8, -21<<8, -13<<8, -8<<8, -5<<8, static const int16_t exponential[16] = { -128<<8, -64<<8, -32<<8, -16<<8, -8<<8, -4<<8, -2<<8, -1<<8, 0, 1<<8, 2<<8, 4<<8, 8<<8, 16<<8, 32<<8, 64<<8 }; +/** + * Delta decode the compressed values in src, and put the resulting + * decoded samples in dst. + * + * @param[in,out] state starting value. it is saved for use in the next call. + */ +static void delta_decode(int16_t *dst, const uint8_t *src, int src_size, + int16_t *state, const int16_t *table) +{ + int val = *state; + + while (src_size--) { + uint8_t d = *src++; + val = av_clip_int16(val + table[d & 0xF]); + *dst++ = val; + val = av_clip_int16(val + table[d >> 4]); + *dst++ = val; + } + + *state = val; +} + /** decode a frame */ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) @@ -63,13 +85,7 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, int *data_si *data_size = buf_size << 2; - while(buf < buf_end) { - uint8_t d = *buf++; - esc->fib_acc += esc->table[d & 0x0f]; - *out_data++ = esc->fib_acc; - esc->fib_acc += esc->table[d >> 4]; - *out_data++ = esc->fib_acc; - } + delta_decode(out_data, buf, buf_size, &esc->fib_acc, esc->table); return consumed; } -- cgit v1.2.3