Mercurial > libavcodec.hg
annotate ws-snd1.c @ 8054:4d4a55649586 libavcodec
Move declaration of mlp decoder dependency on mlp parser to the Makefile
where all other such dependencies are declared.
author | diego |
---|---|
date | Sat, 25 Oct 2008 01:21:43 +0000 |
parents | 85ab7655ad4d |
children | 2acf0ae7b041 |
rev | line source |
---|---|
2585 | 1 /* |
2 * Westwood SNDx codecs | |
3 * Copyright (c) 2005 Konstantin Shishkov | |
4 * | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
5 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
6 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
2585 | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
2585 | 11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
2585 | 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. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2967
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
2585 | 20 */ |
21 #include "avcodec.h" | |
22 | |
23 /** | |
24 * @file ws-snd.c | |
25 * Westwood SNDx codecs. | |
26 * | |
27 * Reference documents about VQA format and its audio codecs | |
28 * can be found here: | |
29 * http://www.multimedia.cx | |
30 */ | |
31 | |
32 static const char ws_adpcm_2bit[] = { -2, -1, 0, 1}; | |
33 static const char ws_adpcm_4bit[] = { | |
34 -9, -8, -6, -5, -4, -3, -2, -1, | |
35 0, 1, 2, 3, 4, 5, 6, 8 }; | |
36 | |
37 #define CLIP8(a) if(a>127)a=127;if(a<-128)a=-128; | |
38 | |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6299
diff
changeset
|
39 static av_cold int ws_snd_decode_init(AVCodecContext * avctx) |
2585 | 40 { |
41 // WSSNDContext *c = avctx->priv_data; | |
2967 | 42 |
7451
85ab7655ad4d
Modify all codecs to report their supported input and output sample format(s).
pross
parents:
7040
diff
changeset
|
43 avctx->sample_fmt = SAMPLE_FMT_S16; |
2585 | 44 return 0; |
45 } | |
46 | |
47 static int ws_snd_decode_frame(AVCodecContext *avctx, | |
48 void *data, int *data_size, | |
6299 | 49 const uint8_t *buf, int buf_size) |
2585 | 50 { |
51 // WSSNDContext *c = avctx->priv_data; | |
2967 | 52 |
2585 | 53 int in_size, out_size; |
54 int sample = 0; | |
55 int i; | |
56 short *samples = data; | |
2967 | 57 |
2585 | 58 if (!buf_size) |
59 return 0; | |
60 | |
4364 | 61 out_size = AV_RL16(&buf[0]); |
2585 | 62 *data_size = out_size * 2; |
4364 | 63 in_size = AV_RL16(&buf[2]); |
2585 | 64 buf += 4; |
2967 | 65 |
5674
ca944f1db2b3
Add checks on input/output buffers size for some audio decoders
kostya
parents:
4364
diff
changeset
|
66 if (out_size > *data_size) { |
ca944f1db2b3
Add checks on input/output buffers size for some audio decoders
kostya
parents:
4364
diff
changeset
|
67 av_log(avctx, AV_LOG_ERROR, "Frame is too large to fit in buffer\n"); |
ca944f1db2b3
Add checks on input/output buffers size for some audio decoders
kostya
parents:
4364
diff
changeset
|
68 return -1; |
ca944f1db2b3
Add checks on input/output buffers size for some audio decoders
kostya
parents:
4364
diff
changeset
|
69 } |
ca944f1db2b3
Add checks on input/output buffers size for some audio decoders
kostya
parents:
4364
diff
changeset
|
70 if (in_size > buf_size) { |
ca944f1db2b3
Add checks on input/output buffers size for some audio decoders
kostya
parents:
4364
diff
changeset
|
71 av_log(avctx, AV_LOG_ERROR, "Frame data is larger than input buffer\n"); |
ca944f1db2b3
Add checks on input/output buffers size for some audio decoders
kostya
parents:
4364
diff
changeset
|
72 return -1; |
ca944f1db2b3
Add checks on input/output buffers size for some audio decoders
kostya
parents:
4364
diff
changeset
|
73 } |
2585 | 74 if (in_size == out_size) { |
75 for (i = 0; i < out_size; i++) | |
76 *samples++ = (*buf++ - 0x80) << 8; | |
77 return buf_size; | |
78 } | |
2967 | 79 |
2585 | 80 while (out_size > 0) { |
81 int code; | |
82 uint8_t count; | |
83 code = (*buf) >> 6; | |
84 count = (*buf) & 0x3F; | |
85 buf++; | |
86 switch(code) { | |
87 case 0: /* ADPCM 2-bit */ | |
88 for (count++; count > 0; count--) { | |
89 code = *buf++; | |
90 sample += ws_adpcm_2bit[code & 0x3]; | |
91 CLIP8(sample); | |
92 *samples++ = sample << 8; | |
93 sample += ws_adpcm_2bit[(code >> 2) & 0x3]; | |
94 CLIP8(sample); | |
95 *samples++ = sample << 8; | |
96 sample += ws_adpcm_2bit[(code >> 4) & 0x3]; | |
97 CLIP8(sample); | |
98 *samples++ = sample << 8; | |
99 sample += ws_adpcm_2bit[(code >> 6) & 0x3]; | |
100 CLIP8(sample); | |
101 *samples++ = sample << 8; | |
102 out_size -= 4; | |
103 } | |
104 break; | |
105 case 1: /* ADPCM 4-bit */ | |
106 for (count++; count > 0; count--) { | |
107 code = *buf++; | |
108 sample += ws_adpcm_4bit[code & 0xF]; | |
109 CLIP8(sample); | |
110 *samples++ = sample << 8; | |
111 sample += ws_adpcm_4bit[code >> 4]; | |
112 CLIP8(sample); | |
113 *samples++ = sample << 8; | |
114 out_size -= 2; | |
115 } | |
116 break; | |
117 case 2: /* no compression */ | |
118 if (count & 0x20) { /* big delta */ | |
119 char t; | |
120 t = count; | |
121 t <<= 3; | |
122 sample += t >> 3; | |
123 *samples++ = sample << 8; | |
124 out_size--; | |
125 } else { /* copy */ | |
126 for (count++; count > 0; count--) { | |
127 *samples++ = (*buf++ - 0x80) << 8; | |
128 out_size--; | |
129 } | |
130 sample = buf[-1] - 0x80; | |
131 } | |
132 break; | |
133 default: /* run */ | |
134 for(count++; count > 0; count--) { | |
135 *samples++ = sample << 8; | |
136 out_size--; | |
137 } | |
138 } | |
139 } | |
2967 | 140 |
2585 | 141 return buf_size; |
142 } | |
143 | |
144 AVCodec ws_snd1_decoder = { | |
145 "ws_snd1", | |
146 CODEC_TYPE_AUDIO, | |
147 CODEC_ID_WESTWOOD_SND1, | |
4019 | 148 0, |
2585 | 149 ws_snd_decode_init, |
150 NULL, | |
151 NULL, | |
152 ws_snd_decode_frame, | |
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6717
diff
changeset
|
153 .long_name = NULL_IF_CONFIG_SMALL("Westwood Audio (SND1)"), |
2585 | 154 }; |