3
* Copyright (C) 2008 Jaikrishnan Menon
5
* This file is part of FFmpeg.
7
* FFmpeg 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
* FFmpeg 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 FFmpeg; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25
* @author Jaikrishnan Menon
26
* supports: fibonacci delta encoding
27
* : exponential encoding
32
/** decoder context */
33
typedef struct EightSvxContext {
38
static const int16_t fibonacci[16] = { -34<<8, -21<<8, -13<<8, -8<<8, -5<<8, -3<<8, -2<<8, -1<<8,
39
0, 1<<8, 2<<8, 3<<8, 5<<8, 8<<8, 13<<8, 21<<8 };
40
static const int16_t exponential[16] = { -128<<8, -64<<8, -32<<8, -16<<8, -8<<8, -4<<8, -2<<8, -1<<8,
41
0, 1<<8, 2<<8, 4<<8, 8<<8, 16<<8, 32<<8, 64<<8 };
44
static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
47
const uint8_t *buf = avpkt->data;
48
int buf_size = avpkt->size;
49
EightSvxContext *esc = avctx->priv_data;
50
int16_t *out_data = data;
51
int consumed = buf_size;
52
const uint8_t *buf_end = buf + buf_size;
54
if((*data_size >> 2) < buf_size)
57
if(avctx->frame_number == 0) {
58
esc->fib_acc = buf[1] << 8;
63
*data_size = buf_size << 2;
65
while(buf < buf_end) {
67
esc->fib_acc += esc->table[d & 0x0f];
68
*out_data++ = esc->fib_acc;
69
esc->fib_acc += esc->table[d >> 4];
70
*out_data++ = esc->fib_acc;
76
/** initialize 8svx decoder */
77
static av_cold int eightsvx_decode_init(AVCodecContext *avctx)
79
EightSvxContext *esc = avctx->priv_data;
81
switch(avctx->codec->id) {
82
case CODEC_ID_8SVX_FIB:
83
esc->table = fibonacci;
85
case CODEC_ID_8SVX_EXP:
86
esc->table = exponential;
91
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
95
AVCodec eightsvx_fib_decoder = {
97
.type = AVMEDIA_TYPE_AUDIO,
98
.id = CODEC_ID_8SVX_FIB,
99
.priv_data_size = sizeof (EightSvxContext),
100
.init = eightsvx_decode_init,
101
.decode = eightsvx_decode_frame,
102
.long_name = NULL_IF_CONFIG_SMALL("8SVX fibonacci"),
105
AVCodec eightsvx_exp_decoder = {
107
.type = AVMEDIA_TYPE_AUDIO,
108
.id = CODEC_ID_8SVX_EXP,
109
.priv_data_size = sizeof (EightSvxContext),
110
.init = eightsvx_decode_init,
111
.decode = eightsvx_decode_frame,
112
.long_name = NULL_IF_CONFIG_SMALL("8SVX exponential"),