Skip to content

Commit

Permalink
8svx: avoid custom clip, avoid +128 for compressed data.
Browse files Browse the repository at this point in the history
Based on:
	commit e371878
	Author: Justin Ruggles <justin.ruggles@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
  • Loading branch information
michaelni committed Oct 3, 2012
1 parent 6eed92a commit 26d1c7d
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions libavcodec/8svx.c
Expand Up @@ -66,31 +66,36 @@ static const int8_t exponential[16] = { -128, -64, -32, -16, -8, -4, -2, -1, 0,
* @param table delta sequence table
* @return size in bytes of the decoded data, must be src_size*2
*/
static int delta_decode(int8_t *dst, const uint8_t *src, int src_size,
int8_t val, const int8_t *table)
static int delta_decode(uint8_t *dst, const uint8_t *src, int src_size,
unsigned val, const int8_t *table)
{
int n = src_size;
int8_t *dst0 = dst;
uint8_t *dst0 = dst;

while (n--) {
while (src_size--) {
uint8_t d = *src++;
val = av_clip(val + table[d & 0x0f], -128, 127);
val = av_clip_uint8(val + table[d & 0xF]);
*dst++ = val;
val = av_clip(val + table[d >> 4] , -128, 127);
val = av_clip_uint8(val + table[d >> 4]);
*dst++ = val;
}

return dst-dst0;
}

static void raw_decode(uint8_t *dst, const int8_t *src, int src_size)
{
while (src_size--)
*dst++ = *src++ + 128;
}

/** decode a frame */
static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame_ptr, AVPacket *avpkt)
{
EightSvxContext *esc = avctx->priv_data;
int n, out_data_size;
int ch, ret;
uint8_t *src, *dst;
uint8_t *src;

/* decode and interleave the first packet */
if (!esc->samples && avpkt) {
Expand Down Expand Up @@ -122,13 +127,13 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
/* the uncompressed starting value is contained in the first byte */
dst = esc->samples;
for (i = 0; i < avctx->channels; i++) {
*(dst++) = buf[0];
delta_decode(dst, buf + 1, buf_size / avctx->channels - 1, buf[0], esc->table);
*(dst++) = buf[0]+128;
delta_decode(dst, buf + 1, buf_size / avctx->channels - 1, (buf[0]+128)&0xFF, esc->table);
buf += buf_size / avctx->channels;
dst += n / avctx->channels - 1;
}
} else {
memcpy(esc->samples, avpkt->data, esc->samples_size);
raw_decode(esc->samples, avpkt->data, esc->samples_size);
}
}

Expand All @@ -145,10 +150,8 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,

out_data_size = esc->frame.nb_samples;
for (ch = 0; ch<avctx->channels; ch++) {
dst = esc->frame.data[ch];
src = esc->samples + esc->samples_idx / avctx->channels + ch * esc->samples_size / avctx->channels;
for (n = out_data_size; n > 0; n--)
*dst++ = *src++ + 128;
memcpy(esc->frame.data[ch], src, out_data_size);
}
out_data_size *= avctx->channels;
esc->samples_idx += out_data_size;
Expand Down

0 comments on commit 26d1c7d

Please sign in to comment.