annotate 8svx.c @ 6808:c5ecf570f1b1 libavcodec

Declare vars as const when possible
author vitor
date Thu, 15 May 2008 18:39:07 +0000
parents 78c7765d9618
children e943e1409077
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6547
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
1 /*
6555
77bb7984b15e minor typo fixes
diego
parents: 6554
diff changeset
2 * 8SVX audio decoder
6547
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
3 * Copyright (C) 2008 Jaikrishnan Menon
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
4 *
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
5 * This file is part of FFmpeg.
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
6 *
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
11 *
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
15 * Lesser General Public License for more details.
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
16 *
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
20 */
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
21
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
22 /**
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
23 * @file 8svx.c
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
24 * 8svx audio decoder
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
25 * @author Jaikrishnan Menon
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
26 * supports: fibonacci delta encoding
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
27 * : exponential encoding
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
28 */
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
29
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
30 #include "avcodec.h"
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
31
6554
a8a3c0be40c7 cosmetics: Write some Doxygen comments in a more compact fashion.
diego
parents: 6547
diff changeset
32 /** decoder context */
6547
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
33 typedef struct EightSvxContext {
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
34 int16_t fib_acc;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
35 int16_t *table;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
36 } EightSvxContext;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
37
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
38 const static int16_t fibonacci[16] = { -34<<8, -21<<8, -13<<8, -8<<8, -5<<8, -3<<8, -2<<8, -1<<8,
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
39 0, 1<<8, 2<<8, 3<<8, 5<<8, 8<<8, 13<<8, 21<<8 };
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
40 const static int16_t exponential[16] = { -128<<8, -64<<8, -32<<8, -16<<8, -8<<8, -4<<8, -2<<8, -1<<8,
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
41 0, 1<<8, 2<<8, 4<<8, 8<<8, 16<<8, 32<<8, 64<<8 };
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
42
6554
a8a3c0be40c7 cosmetics: Write some Doxygen comments in a more compact fashion.
diego
parents: 6547
diff changeset
43 /** decode a frame */
6547
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
44 static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
45 const uint8_t *buf, int buf_size)
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
46 {
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
47 EightSvxContext *esc = avctx->priv_data;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
48 int16_t *out_data = data;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
49 int consumed = buf_size;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
50 const uint8_t *buf_end = buf + buf_size;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
51
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
52 if((*data_size >> 2) < buf_size)
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
53 return -1;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
54
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
55 if(avctx->frame_number == 0) {
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
56 esc->fib_acc = buf[1] << 8;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
57 buf_size -= 2;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
58 buf += 2;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
59 }
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
60
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
61 *data_size = buf_size << 2;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
62
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
63 while(buf < buf_end) {
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
64 uint8_t d = *buf++;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
65 esc->fib_acc += esc->table[d & 0x0f];
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
66 *out_data++ = esc->fib_acc;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
67 esc->fib_acc += esc->table[d >> 4];
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
68 *out_data++ = esc->fib_acc;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
69 }
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
70
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
71 return consumed;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
72 }
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
73
6554
a8a3c0be40c7 cosmetics: Write some Doxygen comments in a more compact fashion.
diego
parents: 6547
diff changeset
74 /** initialize 8svx decoder */
6547
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
75 static av_cold int eightsvx_decode_init(AVCodecContext *avctx)
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
76 {
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
77 EightSvxContext *esc = avctx->priv_data;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
78
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
79 switch(avctx->codec->id) {
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
80 case CODEC_ID_8SVX_FIB:
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
81 esc->table = fibonacci;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
82 break;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
83 case CODEC_ID_8SVX_EXP:
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
84 esc->table = exponential;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
85 break;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
86 default:
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
87 return -1;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
88 }
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
89 return 0;
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
90 }
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
91
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
92 AVCodec eightsvx_fib_decoder = {
6711
78c7765d9618 Make 8SVX codec names just a single word for consistency with other codec names.
diego
parents: 6710
diff changeset
93 .name = "8svx_fib",
6547
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
94 .type = CODEC_TYPE_AUDIO,
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
95 .id = CODEC_ID_8SVX_FIB,
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
96 .priv_data_size = sizeof (EightSvxContext),
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
97 .init = eightsvx_decode_init,
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
98 .decode = eightsvx_decode_frame,
6710
a4104482ceef Add long names to many AVCodec declarations.
diego
parents: 6555
diff changeset
99 .long_name = "8SVX fibonacci",
6547
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
100 };
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
101
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
102 AVCodec eightsvx_exp_decoder = {
6711
78c7765d9618 Make 8SVX codec names just a single word for consistency with other codec names.
diego
parents: 6710
diff changeset
103 .name = "8svx_exp",
6547
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
104 .type = CODEC_TYPE_AUDIO,
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
105 .id = CODEC_ID_8SVX_EXP,
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
106 .priv_data_size = sizeof (EightSvxContext),
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
107 .init = eightsvx_decode_init,
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
108 .decode = eightsvx_decode_frame,
6710
a4104482ceef Add long names to many AVCodec declarations.
diego
parents: 6555
diff changeset
109 .long_name = "8SVX exponential",
6547
ed204467a154 8SVX decoder
vitor
parents:
diff changeset
110 };