3 * Copyright (c) 2005 Konstantin Shishkov
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * Westwood SNDx codecs.
25 * Reference documents about VQA format and its audio codecs
27 * http://www.multimedia.cx
33 static const char ws_adpcm_2bit
[] = { -2, -1, 0, 1};
34 static const char ws_adpcm_4bit
[] = {
35 -9, -8, -6, -5, -4, -3, -2, -1,
36 0, 1, 2, 3, 4, 5, 6, 8 };
38 #define CLIP8(a) if(a>127)a=127;if(a<-128)a=-128;
40 static int ws_snd_decode_init(AVCodecContext
* avctx
)
42 // WSSNDContext *c = avctx->priv_data;
47 static int ws_snd_decode_frame(AVCodecContext
*avctx
,
48 void *data
, int *data_size
,
49 uint8_t *buf
, int buf_size
)
51 // WSSNDContext *c = avctx->priv_data;
53 int in_size
, out_size
;
56 short *samples
= data
;
61 out_size
= LE_16(&buf
[0]);
62 *data_size
= out_size
* 2;
63 in_size
= LE_16(&buf
[2]);
66 if (in_size
== out_size
) {
67 for (i
= 0; i
< out_size
; i
++)
68 *samples
++ = (*buf
++ - 0x80) << 8;
72 while (out_size
> 0) {
76 count
= (*buf
) & 0x3F;
79 case 0: /* ADPCM 2-bit */
80 for (count
++; count
> 0; count
--) {
82 sample
+= ws_adpcm_2bit
[code
& 0x3];
84 *samples
++ = sample
<< 8;
85 sample
+= ws_adpcm_2bit
[(code
>> 2) & 0x3];
87 *samples
++ = sample
<< 8;
88 sample
+= ws_adpcm_2bit
[(code
>> 4) & 0x3];
90 *samples
++ = sample
<< 8;
91 sample
+= ws_adpcm_2bit
[(code
>> 6) & 0x3];
93 *samples
++ = sample
<< 8;
97 case 1: /* ADPCM 4-bit */
98 for (count
++; count
> 0; count
--) {
100 sample
+= ws_adpcm_4bit
[code
& 0xF];
102 *samples
++ = sample
<< 8;
103 sample
+= ws_adpcm_4bit
[code
>> 4];
105 *samples
++ = sample
<< 8;
109 case 2: /* no compression */
110 if (count
& 0x20) { /* big delta */
115 *samples
++ = sample
<< 8;
118 for (count
++; count
> 0; count
--) {
119 *samples
++ = (*buf
++ - 0x80) << 8;
122 sample
= buf
[-1] - 0x80;
126 for(count
++; count
> 0; count
--) {
127 *samples
++ = sample
<< 8;
136 AVCodec ws_snd1_decoder
= {
139 CODEC_ID_WESTWOOD_SND1
,
140 sizeof(WSSNDContext
),