Mercurial > SDL_sound_CoreAudio
annotate decoders/voc.c @ 385:9efb760c4a6b
FIXME removal and cleanups.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Fri, 05 Jul 2002 22:32:54 +0000 |
parents | cbb15ecf423a |
children | fb519e6028e3 |
rev | line source |
---|---|
14 | 1 /* |
2 * SDL_sound -- An abstract sound format decoding API. | |
3 * Copyright (C) 2001 Ryan C. Gordon. | |
4 * | |
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.1 of the License, or (at your option) any later version. | |
9 * | |
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. | |
14 * | |
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 */ | |
19 | |
20 /* | |
21 * VOC decoder for SDL_sound. | |
22 * | |
23 * This driver handles Creative Labs VOC audio data...this is a legacy format, | |
24 * but there's some game ports that could make use of such a decoder. Plus, | |
25 * VOC is fairly straightforward to decode, so this is a more complex, but | |
26 * still palatable example of an SDL_sound decoder. Y'know, in case the | |
27 * RAW decoder didn't do it for you. :) | |
28 * | |
29 * This code was ripped from a decoder I had written for SDL_mixer, which was | |
30 * largely ripped from sox v12.17.1's voc.c. | |
31 * | |
32 * SDL_mixer: http://www.libsdl.org/projects/SDL_mixer/ | |
33 * sox: http://www.freshmeat.net/projects/sox/ | |
34 * | |
184
47cc2de2ae36
Changed reference to "LICENSE" file to "COPYING".
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
35 * Please see the file COPYING in the source's root directory. |
14 | 36 * |
37 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org) | |
38 */ | |
39 | |
106
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
40 #if HAVE_CONFIG_H |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
41 # include <config.h> |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
42 #endif |
100
6d9fdec2f708
added config.h, added --enable-debug flag, various other changes to the build system
fingolfin
parents:
64
diff
changeset
|
43 |
114
dd95a12539fd
Changed an #if defined to #ifdef, for consistency with the other
Ryan C. Gordon <icculus@icculus.org>
parents:
106
diff
changeset
|
44 #ifdef SOUND_SUPPORTS_VOC |
104
103cfcb3c014
Updated to fix build system problem.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
45 |
14 | 46 #include <stdio.h> |
47 #include <stdlib.h> | |
48 #include <string.h> | |
49 | |
106
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
50 #include "SDL_sound.h" |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
51 |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
52 #define __SDL_SOUND_INTERNAL__ |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
53 #include "SDL_sound_internal.h" |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
54 |
47
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
55 static int VOC_init(void); |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
56 static void VOC_quit(void); |
14 | 57 static int VOC_open(Sound_Sample *sample, const char *ext); |
58 static void VOC_close(Sound_Sample *sample); | |
59 static Uint32 VOC_read(Sound_Sample *sample); | |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
60 static int VOC_rewind(Sound_Sample *sample); |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
61 static int VOC_seek(Sound_Sample *sample, Uint32 ms); |
14 | 62 |
149
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
114
diff
changeset
|
63 static const char *extensions_voc[] = { "VOC", NULL }; |
14 | 64 const Sound_DecoderFunctions __Sound_DecoderFunctions_VOC = |
65 { | |
66 { | |
149
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
114
diff
changeset
|
67 extensions_voc, |
14 | 68 "Creative Labs Voice format", |
69 "Ryan C. Gordon <icculus@clutteredmind.org>", | |
70 "http://www.icculus.org/SDL_sound/" | |
71 }, | |
72 | |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
73 VOC_init, /* init() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
74 VOC_quit, /* quit() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
75 VOC_open, /* open() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
76 VOC_close, /* close() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
77 VOC_read, /* read() method */ |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
78 VOC_rewind, /* rewind() method */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
79 VOC_seek /* seek() method */ |
14 | 80 }; |
81 | |
82 | |
83 /* Private data for VOC file */ | |
84 typedef struct vocstuff { | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
85 Uint32 rest; /* bytes remaining in current block */ |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
86 Uint32 rate; /* rate code (byte) of this chunk */ |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
87 int silent; /* sound or silence? */ |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
88 Uint32 srate; /* rate code (byte) of silence */ |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
89 Uint32 blockseek; /* start of current output block */ |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
90 Uint32 samples; /* number of samples output */ |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
91 Uint32 size; /* word length of data */ |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
92 Uint8 channels; /* number of sound channels */ |
14 | 93 int extended; /* Has an extended block been read? */ |
94 Uint32 bufpos; /* byte position in internal->buffer. */ | |
224
1bafef18dabf
Implemented rewind method.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
95 Uint32 start_pos; /* offset to seek to in stream when rewinding. */ |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
96 int error; /* error condition (as opposed to EOF). */ |
14 | 97 } vs_t; |
98 | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
99 |
62
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
47
diff
changeset
|
100 /* Size field */ |
14 | 101 /* SJB: note that the 1st 3 are sometimes used as sizeof(type) */ |
102 #define ST_SIZE_BYTE 1 | |
103 #define ST_SIZE_8BIT 1 | |
104 #define ST_SIZE_WORD 2 | |
105 #define ST_SIZE_16BIT 2 | |
106 #define ST_SIZE_DWORD 4 | |
107 #define ST_SIZE_32BIT 4 | |
108 #define ST_SIZE_FLOAT 5 | |
109 #define ST_SIZE_DOUBLE 6 | |
110 #define ST_SIZE_IEEE 7 /* IEEE 80-bit floats. */ | |
111 | |
112 /* Style field */ | |
113 #define ST_ENCODING_UNSIGNED 1 /* unsigned linear: Sound Blaster */ | |
114 #define ST_ENCODING_SIGN2 2 /* signed linear 2's comp: Mac */ | |
115 #define ST_ENCODING_ULAW 3 /* U-law signed logs: US telephony, SPARC */ | |
116 #define ST_ENCODING_ALAW 4 /* A-law signed logs: non-US telephony */ | |
117 #define ST_ENCODING_ADPCM 5 /* Compressed PCM */ | |
118 #define ST_ENCODING_IMA_ADPCM 6 /* Compressed PCM */ | |
119 #define ST_ENCODING_GSM 7 /* GSM 6.10 33-byte frame lossy compression */ | |
120 | |
121 #define VOC_TERM 0 | |
122 #define VOC_DATA 1 | |
123 #define VOC_CONT 2 | |
124 #define VOC_SILENCE 3 | |
125 #define VOC_MARKER 4 | |
126 #define VOC_TEXT 5 | |
127 #define VOC_LOOP 6 | |
128 #define VOC_LOOPEND 7 | |
129 #define VOC_EXTENDED 8 | |
130 #define VOC_DATA_16 9 | |
131 | |
132 | |
47
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
133 static int VOC_init(void) |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
134 { |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
135 return(1); /* always succeeds. */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
136 } /* VOC_init */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
137 |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
138 |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
139 static void VOC_quit(void) |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
140 { |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
141 /* it's a no-op. */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
142 } /* VOC_quit */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
143 |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
144 |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
145 static inline int voc_readbytes(SDL_RWops *src, vs_t *v, void *p, int size) |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
146 { |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
147 if (SDL_RWread(src, p, size, 1) != 1) |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
148 { |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
149 Sound_SetError("VOC: i/o error"); |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
150 v->error = 1; |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
151 return 0; |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
152 } /* if */ |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
153 |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
154 return(1); |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
155 } /* voc_readbytes */ |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
156 |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
157 |
301 | 158 static inline int voc_check_header(SDL_RWops *src) |
14 | 159 { |
160 /* VOC magic header */ | |
161 Uint8 signature[20]; /* "Creative Voice File\032" */ | |
162 Uint16 datablockofs; | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
163 vs_t v; /* dummy struct for voc_readbytes */ |
14 | 164 |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
165 if (!voc_readbytes(src, &v, signature, sizeof (signature))) |
14 | 166 return(0); |
167 | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
168 if (memcmp(signature, "Creative Voice File\032", sizeof (signature)) != 0) |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
169 { |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
170 Sound_SetError("VOC: Wrong signature; not a VOC file."); |
14 | 171 return(0); |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
172 } /* if */ |
14 | 173 |
174 /* get the offset where the first datablock is located */ | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
175 if (!voc_readbytes(src, &v, &datablockofs, sizeof (Uint16))) |
14 | 176 return(0); |
177 | |
178 datablockofs = SDL_SwapLE16(datablockofs); | |
179 | |
180 if (SDL_RWseek(src, datablockofs, SEEK_SET) != datablockofs) | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
181 { |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
182 Sound_SetError("VOC: Failed to seek to data block."); |
14 | 183 return(0); |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
184 } /* if */ |
14 | 185 |
186 return(1); /* success! */ | |
187 } /* voc_check_header */ | |
188 | |
189 | |
190 /* Read next block header, save info, leave position at start of data */ | |
191 static int voc_get_block(Sound_Sample *sample) | |
192 { | |
193 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
194 SDL_RWops *src = internal->rw; | |
195 vs_t *v = (vs_t *) internal->decoder_private; | |
196 Uint8 bits24[3]; | |
197 Uint8 uc, block; | |
198 Uint32 sblen; | |
199 Uint16 new_rate_short; | |
200 Uint32 new_rate_long; | |
201 Uint8 trash[6]; | |
202 Uint16 period; | |
203 int i; | |
204 | |
205 v->silent = 0; | |
206 while (v->rest == 0) | |
207 { | |
208 if (SDL_RWread(src, &block, sizeof (block), 1) != 1) | |
209 return 1; /* assume that's the end of the file. */ | |
210 | |
211 if (block == VOC_TERM) | |
212 return 1; | |
213 | |
214 if (SDL_RWread(src, bits24, sizeof (bits24), 1) != 1) | |
215 return 1; /* assume that's the end of the file. */ | |
62
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
47
diff
changeset
|
216 |
14 | 217 /* Size is an 24-bit value. Ugh. */ |
218 sblen = ( (bits24[0]) | (bits24[1] << 8) | (bits24[2] << 16) ); | |
219 | |
220 switch(block) | |
221 { | |
222 case VOC_DATA: | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
223 if (!voc_readbytes(src, v, &uc, sizeof (uc))) |
14 | 224 return 0; |
225 | |
226 /* When DATA block preceeded by an EXTENDED */ | |
227 /* block, the DATA blocks rate value is invalid */ | |
228 if (!v->extended) | |
229 { | |
230 if (uc == 0) | |
231 { | |
232 Sound_SetError("VOC Sample rate is zero?"); | |
233 return 0; | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
234 } /* if */ |
14 | 235 |
236 if ((v->rate != -1) && (uc != v->rate)) | |
237 { | |
238 Sound_SetError("VOC sample rate codes differ"); | |
239 return 0; | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
240 } /* if */ |
14 | 241 |
242 v->rate = uc; | |
243 sample->actual.rate = 1000000.0/(256 - v->rate); | |
244 v->channels = 1; | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
245 } /* if */ |
14 | 246 |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
247 if (!voc_readbytes(src, v, &uc, sizeof (uc))) |
14 | 248 return 0; |
249 | |
250 if (uc != 0) | |
251 { | |
252 Sound_SetError("VOC decoder only interprets 8-bit data"); | |
253 return 0; | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
254 } /* if */ |
14 | 255 |
256 v->extended = 0; | |
257 v->rest = sblen - 2; | |
258 v->size = ST_SIZE_BYTE; | |
259 return 1; | |
260 | |
261 case VOC_DATA_16: | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
262 if (!voc_readbytes(src, v, &new_rate_long, sizeof (Uint32))) |
14 | 263 return 0; |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
264 |
14 | 265 new_rate_long = SDL_SwapLE32(new_rate_long); |
266 if (new_rate_long == 0) | |
267 { | |
268 Sound_SetError("VOC Sample rate is zero?"); | |
269 return 0; | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
270 } /* if */ |
14 | 271 if ((v->rate != -1) && (new_rate_long != v->rate)) |
272 { | |
273 Sound_SetError("VOC sample rate codes differ"); | |
274 return 0; | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
275 } /* if */ |
14 | 276 v->rate = new_rate_long; |
277 sample->actual.rate = new_rate_long; | |
278 | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
279 if (!voc_readbytes(src, v, &uc, sizeof (uc))) |
14 | 280 return 0; |
281 | |
282 switch (uc) | |
283 { | |
284 case 8: v->size = ST_SIZE_BYTE; break; | |
285 case 16: v->size = ST_SIZE_WORD; break; | |
286 default: | |
287 Sound_SetError("VOC with unknown data size"); | |
288 return 0; | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
289 } /* switch */ |
14 | 290 |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
291 if (!voc_readbytes(src, v, &v->channels, sizeof (Uint8))) |
14 | 292 return 0; |
293 | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
294 if (!voc_readbytes(src, v, trash, sizeof (Uint8) * 6)) |
14 | 295 return 0; |
296 | |
297 v->rest = sblen - 12; | |
298 return 1; | |
299 | |
300 case VOC_CONT: | |
301 v->rest = sblen; | |
302 return 1; | |
303 | |
304 case VOC_SILENCE: | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
305 if (!voc_readbytes(src, v, &period, sizeof (period))) |
14 | 306 return 0; |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
307 |
14 | 308 period = SDL_SwapLE16(period); |
309 | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
310 if (!voc_readbytes(src, v, &uc, sizeof (uc))) |
14 | 311 return 0; |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
312 |
14 | 313 if (uc == 0) |
314 { | |
315 Sound_SetError("VOC silence sample rate is zero"); | |
316 return 0; | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
317 } /* if */ |
14 | 318 |
319 /* | |
320 * Some silence-packed files have gratuitously | |
321 * different sample rate codes in silence. | |
322 * Adjust period. | |
323 */ | |
324 if ((v->rate != -1) && (uc != v->rate)) | |
325 period = (period * (256 - uc))/(256 - v->rate); | |
326 else | |
327 v->rate = uc; | |
328 v->rest = period; | |
329 v->silent = 1; | |
330 return 1; | |
331 | |
332 case VOC_LOOP: | |
333 case VOC_LOOPEND: | |
334 for(i = 0; i < sblen; i++) /* skip repeat loops. */ | |
335 { | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
336 if (!voc_readbytes(src, v, trash, sizeof (Uint8))) |
14 | 337 return 0; |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
338 } /* for */ |
14 | 339 break; |
340 | |
341 case VOC_EXTENDED: | |
342 /* An Extended block is followed by a data block */ | |
343 /* Set this byte so we know to use the rate */ | |
344 /* value from the extended block and not the */ | |
345 /* data block. */ | |
346 v->extended = 1; | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
347 if (!voc_readbytes(src, v, &new_rate_short, sizeof (Uint16))) |
14 | 348 return 0; |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
349 |
14 | 350 new_rate_short = SDL_SwapLE16(new_rate_short); |
351 if (new_rate_short == 0) | |
352 { | |
353 Sound_SetError("VOC sample rate is zero"); | |
354 return 0; | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
355 } /* if */ |
14 | 356 if ((v->rate != -1) && (new_rate_short != v->rate)) |
357 { | |
358 Sound_SetError("VOC sample rate codes differ"); | |
359 return 0; | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
360 } /* if */ |
14 | 361 v->rate = new_rate_short; |
362 | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
363 if (!voc_readbytes(src, v, &uc, sizeof (uc))) |
14 | 364 return 0; |
365 | |
366 if (uc != 0) | |
367 { | |
368 Sound_SetError("VOC decoder only interprets 8-bit data"); | |
369 return 0; | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
370 } /* if */ |
14 | 371 |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
372 if (!voc_readbytes(src, v, &uc, sizeof (uc))) |
14 | 373 return 0; |
374 | |
375 if (uc) | |
376 sample->actual.channels = 2; /* Stereo */ | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
377 |
14 | 378 /* Needed number of channels before finishing |
379 compute for rate */ | |
380 sample->actual.rate = | |
381 (256000000L/(65536L - v->rate)) / sample->actual.channels; | |
382 /* An extended block must be followed by a data */ | |
383 /* block to be valid so loop back to top so it */ | |
384 /* can be grabed. */ | |
385 continue; | |
386 | |
387 case VOC_MARKER: | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
388 if (!voc_readbytes(src, v, trash, sizeof (Uint8) * 2)) |
14 | 389 return 0; |
390 | |
391 /* Falling! Falling! */ | |
392 | |
393 default: /* text block or other krapola. */ | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
394 if (!voc_readbytes(src, v, &trash, sizeof (Uint8) * sblen)) |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
395 return 0; |
14 | 396 |
397 if (block == VOC_TEXT) | |
398 continue; /* get next block */ | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
399 } /* switch */ |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
400 } /* while */ |
14 | 401 |
402 return 1; | |
335
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
403 } /* voc_get_block */ |
14 | 404 |
405 | |
335
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
406 static int voc_read_waveform(Sound_Sample *sample, int fill_buf, Uint32 max) |
14 | 407 { |
408 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
409 SDL_RWops *src = internal->rw; | |
410 vs_t *v = (vs_t *) internal->decoder_private; | |
411 int done = 0; | |
412 Uint8 silence = 0x80; | |
413 Uint8 *buf = internal->buffer; | |
414 | |
415 if (v->rest == 0) | |
416 { | |
417 if (!voc_get_block(sample)) | |
418 return 0; | |
335
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
419 } /* if */ |
14 | 420 |
421 if (v->rest == 0) | |
422 return 0; | |
423 | |
335
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
424 max = (v->rest < max) ? v->rest : max; |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
425 |
14 | 426 if (v->silent) |
427 { | |
428 if (v->size == ST_SIZE_WORD) | |
429 silence = 0x00; | |
430 | |
431 /* Fill in silence */ | |
335
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
432 if (fill_buf) |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
433 memset(buf + v->bufpos, silence, max); |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
434 |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
435 done = max; |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
436 v->rest -= done; |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
437 } /* if */ |
14 | 438 |
439 else | |
440 { | |
335
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
441 if (fill_buf) |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
442 { |
335
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
443 done = SDL_RWread(src, buf + v->bufpos, 1, max); |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
444 if (done < max) |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
445 { |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
446 Sound_SetError("VOC: i/o error"); |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
447 sample->flags |= SOUND_SAMPLEFLAG_ERROR; |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
448 } /* if */ |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
449 } /* if */ |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
450 |
335
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
451 else |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
452 { |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
453 int cur, rc; |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
454 cur = SDL_RWtell(src); |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
455 if (cur >= 0) |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
456 { |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
457 rc = SDL_RWseek(src, max, SEEK_CUR); |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
458 if (rc >= 0) |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
459 done = rc - cur; |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
460 else |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
461 { |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
462 Sound_SetError("VOC: seek error"); |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
463 sample->flags |= SOUND_SAMPLEFLAG_ERROR; |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
464 } /* else */ |
335
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
465 } /* if */ |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
466 } /* else */ |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
467 |
14 | 468 v->rest -= done; |
469 v->bufpos += done; | |
335
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
470 } /* else */ |
14 | 471 |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
472 return(done); |
22
f6e679afe88b
Byte ordering fix, changed voc_read to voc_read_waveform, and cleaned up
Ryan C. Gordon <icculus@icculus.org>
parents:
14
diff
changeset
|
473 } /* voc_read_waveform */ |
14 | 474 |
475 | |
476 static int VOC_open(Sound_Sample *sample, const char *ext) | |
477 { | |
478 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
479 vs_t *v = NULL; | |
480 | |
481 if (!voc_check_header(internal->rw)) | |
482 return(0); | |
483 | |
484 v = (vs_t *) malloc(sizeof (vs_t)); | |
485 BAIL_IF_MACRO(v == NULL, ERR_OUT_OF_MEMORY, 0); | |
486 memset(v, '\0', sizeof (vs_t)); | |
487 internal->decoder_private = v; | |
488 | |
224
1bafef18dabf
Implemented rewind method.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
489 v->start_pos = SDL_RWtell(internal->rw); |
14 | 490 v->rate = -1; |
491 if (!voc_get_block(sample)) | |
492 { | |
493 free(v); | |
494 return(0); | |
495 } /* if */ | |
496 | |
497 if (v->rate == -1) | |
498 { | |
499 Sound_SetError("VOC data had no sound!"); | |
500 free(v); | |
501 return(0); | |
502 } /* if */ | |
503 | |
62
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
47
diff
changeset
|
504 SNDDBG(("VOC: Accepting data stream.\n")); |
14 | 505 sample->actual.format = (v->size == ST_SIZE_WORD) ? AUDIO_S16LSB:AUDIO_U8; |
506 sample->actual.channels = v->channels; | |
335
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
507 sample->flags = SOUND_SAMPLEFLAG_CANSEEK; |
14 | 508 return(1); |
509 } /* VOC_open */ | |
510 | |
511 | |
512 static void VOC_close(Sound_Sample *sample) | |
513 { | |
514 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
515 free(internal->decoder_private); | |
516 } /* VOC_close */ | |
517 | |
518 | |
519 static Uint32 VOC_read(Sound_Sample *sample) | |
520 { | |
521 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
522 vs_t *v = (vs_t *) internal->decoder_private; | |
523 | |
524 v->bufpos = 0; | |
525 while (v->bufpos < internal->buffer_size) | |
526 { | |
335
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
527 Uint32 rc = voc_read_waveform(sample, 1, internal->buffer_size); |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
528 if (rc == 0) |
14 | 529 { |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
530 sample->flags |= (v->error) ? |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
531 SOUND_SAMPLEFLAG_ERROR : |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
532 SOUND_SAMPLEFLAG_EOF; |
14 | 533 break; |
534 } /* if */ | |
535 | |
536 if (!voc_get_block(sample)) | |
537 { | |
385
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
538 sample->flags |= (v->error) ? |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
539 SOUND_SAMPLEFLAG_ERROR : |
9efb760c4a6b
FIXME removal and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
540 SOUND_SAMPLEFLAG_EOF; |
14 | 541 break; |
542 } /* if */ | |
543 } /* while */ | |
544 | |
545 return(v->bufpos); | |
546 } /* VOC_read */ | |
547 | |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
548 |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
549 static int VOC_rewind(Sound_Sample *sample) |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
550 { |
224
1bafef18dabf
Implemented rewind method.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
551 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
1bafef18dabf
Implemented rewind method.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
552 vs_t *v = (vs_t *) internal->decoder_private; |
1bafef18dabf
Implemented rewind method.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
553 int rc = SDL_RWseek(internal->rw, v->start_pos, SEEK_SET); |
1bafef18dabf
Implemented rewind method.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
554 BAIL_IF_MACRO(rc != v->start_pos, ERR_IO_ERROR, 0); |
1bafef18dabf
Implemented rewind method.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
555 v->rest = 0; |
1bafef18dabf
Implemented rewind method.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
556 return(1); |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
557 } /* VOC_rewind */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
558 |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
559 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
560 static int VOC_seek(Sound_Sample *sample, Uint32 ms) |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
561 { |
335
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
562 /* |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
563 * VOCs don't lend themselves well to seeking, since you have to |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
564 * parse each section, which is an arbitrary size. The best we can do |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
565 * is rewind, set a flag saying not to write the waveforms to a buffer, |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
566 * and decode to the point that we want. Ugh. Fortunately, there's |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
567 * really no such thing as a large VOC, due to the era and hardware that |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
568 * spawned them, so even though this is inefficient, this is still a |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
569 * relatively fast operation in most cases. |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
570 */ |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
571 |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
572 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
573 vs_t *v = (vs_t *) internal->decoder_private; |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
574 int offset = __Sound_convertMsToBytePos(&sample->actual, ms); |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
575 int origpos = SDL_RWtell(internal->rw); |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
576 int origrest = v->rest; |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
577 |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
578 BAIL_IF_MACRO(!VOC_rewind(sample), NULL, 0); |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
579 |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
580 v->bufpos = 0; |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
581 |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
582 while (offset > 0) |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
583 { |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
584 Uint32 rc = voc_read_waveform(sample, 0, offset); |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
585 if ( (rc == 0) || (!voc_get_block(sample)) ) |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
586 { |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
587 SDL_RWseek(internal->rw, origpos, SEEK_SET); |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
588 v->rest = origrest; |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
589 return(0); |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
590 } /* if */ |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
591 |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
592 offset -= rc; |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
593 } /* while */ |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
594 |
f6475949cd59
Implemented seek method.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
595 return(1); |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
596 } /* VOC_seek */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
597 |
64
40006625142a
Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
62
diff
changeset
|
598 #endif /* SOUND_SUPPORTS_VOC */ |
14 | 599 |
600 /* end of voc.c ... */ |