3 * Copyright (C) 2008 Jaikrishnan Menon
5 * This file is part of Libav.
7 * Libav is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * Libav is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with Libav; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 * @author Jaikrishnan Menon
27 * supports: fibonacci delta encoding
28 * : exponential encoding
33 /** decoder context */
34 typedef struct EightSvxContext {
39 static const int16_t fibonacci[16] = { -34<<8, -21<<8, -13<<8, -8<<8, -5<<8, -3<<8, -2<<8, -1<<8,
40 0, 1<<8, 2<<8, 3<<8, 5<<8, 8<<8, 13<<8, 21<<8 };
41 static const int16_t exponential[16] = { -128<<8, -64<<8, -32<<8, -16<<8, -8<<8, -4<<8, -2<<8, -1<<8,
42 0, 1<<8, 2<<8, 4<<8, 8<<8, 16<<8, 32<<8, 64<<8 };
45 * Delta decode the compressed values in src, and put the resulting
46 * decoded samples in dst.
48 * @param[in,out] state starting value. it is saved for use in the next call.
50 static void delta_decode(int16_t *dst, const uint8_t *src, int src_size,
51 int16_t *state, const int16_t *table)
57 val = av_clip_int16(val + table[d & 0xF]);
59 val = av_clip_int16(val + table[d >> 4]);
67 static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
70 const uint8_t *buf = avpkt->data;
71 int buf_size = avpkt->size;
72 EightSvxContext *esc = avctx->priv_data;
73 int16_t *out_data = data;
74 int consumed = buf_size;
75 const uint8_t *buf_end = buf + buf_size;
77 if((*data_size >> 2) < buf_size)
80 if(avctx->frame_number == 0) {
81 esc->fib_acc = buf[1] << 8;
86 *data_size = buf_size << 2;
88 delta_decode(out_data, buf, buf_size, &esc->fib_acc, esc->table);
93 /** initialize 8svx decoder */
94 static av_cold int eightsvx_decode_init(AVCodecContext *avctx)
96 EightSvxContext *esc = avctx->priv_data;
98 switch(avctx->codec->id) {
99 case CODEC_ID_8SVX_FIB:
100 esc->table = fibonacci;
102 case CODEC_ID_8SVX_EXP:
103 esc->table = exponential;
108 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
112 AVCodec ff_eightsvx_fib_decoder = {
114 .type = AVMEDIA_TYPE_AUDIO,
115 .id = CODEC_ID_8SVX_FIB,
116 .priv_data_size = sizeof (EightSvxContext),
117 .init = eightsvx_decode_init,
118 .decode = eightsvx_decode_frame,
119 .long_name = NULL_IF_CONFIG_SMALL("8SVX fibonacci"),
122 AVCodec ff_eightsvx_exp_decoder = {
124 .type = AVMEDIA_TYPE_AUDIO,
125 .id = CODEC_ID_8SVX_EXP,
126 .priv_data_size = sizeof (EightSvxContext),
127 .init = eightsvx_decode_init,
128 .decode = eightsvx_decode_frame,
129 .long_name = NULL_IF_CONFIG_SMALL("8SVX exponential"),