]> git.sesse.net Git - ffmpeg/blob - libavcodec/8svx.c
8svx: remove duplicated author/file information
[ffmpeg] / libavcodec / 8svx.c
1 /*
2  * Copyright (C) 2008 Jaikrishnan Menon
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 /**
22  * @file
23  * 8svx audio decoder
24  * supports: fibonacci delta encoding
25  *         : exponential encoding
26  */
27
28 #include "avcodec.h"
29
30 /** decoder context */
31 typedef struct EightSvxContext {
32     int16_t fib_acc;
33     const int16_t *table;
34 } EightSvxContext;
35
36 static const int16_t fibonacci[16]   = { -34<<8, -21<<8, -13<<8,  -8<<8, -5<<8, -3<<8, -2<<8, -1<<8,
37                                           0, 1<<8, 2<<8, 3<<8, 5<<8, 8<<8, 13<<8, 21<<8 };
38 static const int16_t exponential[16] = { -128<<8, -64<<8, -32<<8, -16<<8, -8<<8, -4<<8, -2<<8, -1<<8,
39                                           0, 1<<8, 2<<8, 4<<8, 8<<8, 16<<8, 32<<8, 64<<8 };
40
41 /** decode a frame */
42 static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
43                                  AVPacket *avpkt)
44 {
45     const uint8_t *buf = avpkt->data;
46     int buf_size = avpkt->size;
47     EightSvxContext *esc = avctx->priv_data;
48     int16_t *out_data = data;
49     int consumed = buf_size;
50     const uint8_t *buf_end = buf + buf_size;
51
52     if((*data_size >> 2) < buf_size)
53         return -1;
54
55     if(avctx->frame_number == 0) {
56         esc->fib_acc = buf[1] << 8;
57         buf_size -= 2;
58         buf += 2;
59     }
60
61     *data_size = buf_size << 2;
62
63     while(buf < buf_end) {
64         uint8_t d = *buf++;
65         esc->fib_acc += esc->table[d & 0x0f];
66         *out_data++ = esc->fib_acc;
67         esc->fib_acc += esc->table[d >> 4];
68         *out_data++ = esc->fib_acc;
69     }
70
71     return consumed;
72 }
73
74 /** initialize 8svx decoder */
75 static av_cold int eightsvx_decode_init(AVCodecContext *avctx)
76 {
77     EightSvxContext *esc = avctx->priv_data;
78
79     switch(avctx->codec->id) {
80         case CODEC_ID_8SVX_FIB:
81           esc->table = fibonacci;
82           break;
83         case CODEC_ID_8SVX_EXP:
84           esc->table = exponential;
85           break;
86         default:
87           return -1;
88     }
89     avctx->sample_fmt = AV_SAMPLE_FMT_S16;
90     return 0;
91 }
92
93 AVCodec ff_eightsvx_fib_decoder = {
94   .name           = "8svx_fib",
95   .type           = AVMEDIA_TYPE_AUDIO,
96   .id             = CODEC_ID_8SVX_FIB,
97   .priv_data_size = sizeof (EightSvxContext),
98   .init           = eightsvx_decode_init,
99   .decode         = eightsvx_decode_frame,
100   .long_name      = NULL_IF_CONFIG_SMALL("8SVX fibonacci"),
101 };
102
103 AVCodec ff_eightsvx_exp_decoder = {
104   .name           = "8svx_exp",
105   .type           = AVMEDIA_TYPE_AUDIO,
106   .id             = CODEC_ID_8SVX_EXP,
107   .priv_data_size = sizeof (EightSvxContext),
108   .init           = eightsvx_decode_init,
109   .decode         = eightsvx_decode_frame,
110   .long_name      = NULL_IF_CONFIG_SMALL("8SVX exponential"),
111 };