Mercurial > SDL_sound_CoreAudio
annotate decoders/voc.c @ 288:259daddc2d6b
PhysicsFS support tied into build system.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sat, 16 Mar 2002 08:48:00 +0000 |
parents | 1bafef18dabf |
children | ca43129df299 |
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 #include <assert.h> | |
50 | |
106
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
51 #include "SDL_sound.h" |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
52 |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
53 #define __SDL_SOUND_INTERNAL__ |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
54 #include "SDL_sound_internal.h" |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
55 |
47
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
56 static int VOC_init(void); |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
57 static void VOC_quit(void); |
14 | 58 static int VOC_open(Sound_Sample *sample, const char *ext); |
59 static void VOC_close(Sound_Sample *sample); | |
60 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
|
61 static int VOC_rewind(Sound_Sample *sample); |
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 */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
78 VOC_rewind /* rewind() method */ |
14 | 79 }; |
80 | |
81 | |
82 /* Private data for VOC file */ | |
83 typedef struct vocstuff { | |
84 Uint32 rest; /* bytes remaining in current block */ | |
85 Uint32 rate; /* rate code (byte) of this chunk */ | |
86 int silent; /* sound or silence? */ | |
87 Uint32 srate; /* rate code (byte) of silence */ | |
88 Uint32 blockseek; /* start of current output block */ | |
89 Uint32 samples; /* number of samples output */ | |
90 Uint32 size; /* word length of data */ | |
32
4a60ee42ca9a
Fixed a byte-ordering issue.
Ryan C. Gordon <icculus@icculus.org>
parents:
22
diff
changeset
|
91 Uint8 channels; /* number of sound channels */ |
14 | 92 int extended; /* Has an extended block been read? */ |
93 Uint32 bufpos; /* byte position in internal->buffer. */ | |
224
1bafef18dabf
Implemented rewind method.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
94 Uint32 start_pos; /* offset to seek to in stream when rewinding. */ |
14 | 95 } vs_t; |
96 | |
62
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
47
diff
changeset
|
97 /* Size field */ |
14 | 98 /* SJB: note that the 1st 3 are sometimes used as sizeof(type) */ |
99 #define ST_SIZE_BYTE 1 | |
100 #define ST_SIZE_8BIT 1 | |
101 #define ST_SIZE_WORD 2 | |
102 #define ST_SIZE_16BIT 2 | |
103 #define ST_SIZE_DWORD 4 | |
104 #define ST_SIZE_32BIT 4 | |
105 #define ST_SIZE_FLOAT 5 | |
106 #define ST_SIZE_DOUBLE 6 | |
107 #define ST_SIZE_IEEE 7 /* IEEE 80-bit floats. */ | |
108 | |
109 /* Style field */ | |
110 #define ST_ENCODING_UNSIGNED 1 /* unsigned linear: Sound Blaster */ | |
111 #define ST_ENCODING_SIGN2 2 /* signed linear 2's comp: Mac */ | |
112 #define ST_ENCODING_ULAW 3 /* U-law signed logs: US telephony, SPARC */ | |
113 #define ST_ENCODING_ALAW 4 /* A-law signed logs: non-US telephony */ | |
114 #define ST_ENCODING_ADPCM 5 /* Compressed PCM */ | |
115 #define ST_ENCODING_IMA_ADPCM 6 /* Compressed PCM */ | |
116 #define ST_ENCODING_GSM 7 /* GSM 6.10 33-byte frame lossy compression */ | |
117 | |
118 #define VOC_TERM 0 | |
119 #define VOC_DATA 1 | |
120 #define VOC_CONT 2 | |
121 #define VOC_SILENCE 3 | |
122 #define VOC_MARKER 4 | |
123 #define VOC_TEXT 5 | |
124 #define VOC_LOOP 6 | |
125 #define VOC_LOOPEND 7 | |
126 #define VOC_EXTENDED 8 | |
127 #define VOC_DATA_16 9 | |
128 | |
129 | |
47
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
130 static int VOC_init(void) |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
131 { |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
132 return(1); /* always succeeds. */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
133 } /* VOC_init */ |
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 |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
136 static void VOC_quit(void) |
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 /* it's a no-op. */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
32
diff
changeset
|
139 } /* VOC_quit */ |
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 |
14 | 142 static __inline__ int voc_check_header(SDL_RWops *src) |
143 { | |
144 /* VOC magic header */ | |
145 Uint8 signature[20]; /* "Creative Voice File\032" */ | |
146 Uint16 datablockofs; | |
147 | |
148 if (SDL_RWread(src, signature, sizeof (signature), 1) != 1) | |
149 return(0); | |
150 | |
151 if (memcmp(signature, "Creative Voice File\032", sizeof (signature)) != 0) { | |
152 Sound_SetError("Unrecognized file type (not VOC)"); | |
153 return(0); | |
154 } | |
155 | |
156 /* get the offset where the first datablock is located */ | |
157 if (SDL_RWread(src, &datablockofs, sizeof (Uint16), 1) != 1) | |
158 return(0); | |
159 | |
160 datablockofs = SDL_SwapLE16(datablockofs); | |
161 | |
162 if (SDL_RWseek(src, datablockofs, SEEK_SET) != datablockofs) | |
163 return(0); | |
164 | |
165 return(1); /* success! */ | |
166 } /* voc_check_header */ | |
167 | |
168 /* !!! FIXME : Add a flag to vs_t that distinguishes EOF and Error conditions. */ | |
169 | |
170 /* Read next block header, save info, leave position at start of data */ | |
171 static int voc_get_block(Sound_Sample *sample) | |
172 { | |
173 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
174 SDL_RWops *src = internal->rw; | |
175 vs_t *v = (vs_t *) internal->decoder_private; | |
176 Uint8 bits24[3]; | |
177 Uint8 uc, block; | |
178 Uint32 sblen; | |
179 Uint16 new_rate_short; | |
180 Uint32 new_rate_long; | |
181 Uint8 trash[6]; | |
182 Uint16 period; | |
183 int i; | |
184 | |
185 v->silent = 0; | |
186 while (v->rest == 0) | |
187 { | |
188 if (SDL_RWread(src, &block, sizeof (block), 1) != 1) | |
189 return 1; /* assume that's the end of the file. */ | |
190 | |
191 if (block == VOC_TERM) | |
192 return 1; | |
193 | |
194 if (SDL_RWread(src, bits24, sizeof (bits24), 1) != 1) | |
195 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
|
196 |
14 | 197 /* Size is an 24-bit value. Ugh. */ |
198 sblen = ( (bits24[0]) | (bits24[1] << 8) | (bits24[2] << 16) ); | |
199 | |
200 switch(block) | |
201 { | |
202 case VOC_DATA: | |
203 if (SDL_RWread(src, &uc, sizeof (uc), 1) != 1) | |
204 return 0; | |
205 | |
206 /* When DATA block preceeded by an EXTENDED */ | |
207 /* block, the DATA blocks rate value is invalid */ | |
208 if (!v->extended) | |
209 { | |
210 if (uc == 0) | |
211 { | |
212 Sound_SetError("VOC Sample rate is zero?"); | |
213 return 0; | |
214 } | |
215 | |
216 if ((v->rate != -1) && (uc != v->rate)) | |
217 { | |
218 Sound_SetError("VOC sample rate codes differ"); | |
219 return 0; | |
220 } | |
221 | |
222 v->rate = uc; | |
223 sample->actual.rate = 1000000.0/(256 - v->rate); | |
224 v->channels = 1; | |
225 } | |
226 | |
227 if (SDL_RWread(src, &uc, sizeof (uc), 1) != 1) | |
228 return 0; | |
229 | |
230 if (uc != 0) | |
231 { | |
232 Sound_SetError("VOC decoder only interprets 8-bit data"); | |
233 return 0; | |
234 } | |
235 | |
236 v->extended = 0; | |
237 v->rest = sblen - 2; | |
238 v->size = ST_SIZE_BYTE; | |
239 return 1; | |
240 | |
241 case VOC_DATA_16: | |
242 if (SDL_RWread(src, &new_rate_long, sizeof (new_rate_long), 1) != 1) | |
243 return 0; | |
244 new_rate_long = SDL_SwapLE32(new_rate_long); | |
245 if (new_rate_long == 0) | |
246 { | |
247 Sound_SetError("VOC Sample rate is zero?"); | |
248 return 0; | |
249 } | |
250 if ((v->rate != -1) && (new_rate_long != v->rate)) | |
251 { | |
252 Sound_SetError("VOC sample rate codes differ"); | |
253 return 0; | |
254 } | |
255 v->rate = new_rate_long; | |
256 sample->actual.rate = new_rate_long; | |
257 | |
258 if (SDL_RWread(src, &uc, sizeof (uc), 1) != 1) | |
259 return 0; | |
260 | |
261 switch (uc) | |
262 { | |
263 case 8: v->size = ST_SIZE_BYTE; break; | |
264 case 16: v->size = ST_SIZE_WORD; break; | |
265 default: | |
266 Sound_SetError("VOC with unknown data size"); | |
267 return 0; | |
268 } | |
269 | |
270 if (SDL_RWread(src, &v->channels, sizeof (Uint8), 1) != 1) | |
271 return 0; | |
272 | |
273 if (SDL_RWread(src, trash, sizeof (Uint8), 6) != 6) | |
274 return 0; | |
275 | |
276 v->rest = sblen - 12; | |
277 return 1; | |
278 | |
279 case VOC_CONT: | |
280 v->rest = sblen; | |
281 return 1; | |
282 | |
283 case VOC_SILENCE: | |
284 if (SDL_RWread(src, &period, sizeof (period), 1) != 1) | |
285 return 0; | |
286 period = SDL_SwapLE16(period); | |
287 | |
288 if (SDL_RWread(src, &uc, sizeof (uc), 1) != 1) | |
289 return 0; | |
290 if (uc == 0) | |
291 { | |
292 Sound_SetError("VOC silence sample rate is zero"); | |
293 return 0; | |
294 } | |
295 | |
296 /* | |
297 * Some silence-packed files have gratuitously | |
298 * different sample rate codes in silence. | |
299 * Adjust period. | |
300 */ | |
301 if ((v->rate != -1) && (uc != v->rate)) | |
302 period = (period * (256 - uc))/(256 - v->rate); | |
303 else | |
304 v->rate = uc; | |
305 v->rest = period; | |
306 v->silent = 1; | |
307 return 1; | |
308 | |
309 case VOC_LOOP: | |
310 case VOC_LOOPEND: | |
311 for(i = 0; i < sblen; i++) /* skip repeat loops. */ | |
312 { | |
313 if (SDL_RWread(src, trash, sizeof (Uint8), 1) != 1) | |
314 return 0; | |
315 } | |
316 break; | |
317 | |
318 case VOC_EXTENDED: | |
319 /* An Extended block is followed by a data block */ | |
320 /* Set this byte so we know to use the rate */ | |
321 /* value from the extended block and not the */ | |
322 /* data block. */ | |
323 v->extended = 1; | |
324 if (SDL_RWread(src, &new_rate_short, sizeof (new_rate_short), 1) != 1) | |
325 return 0; | |
326 new_rate_short = SDL_SwapLE16(new_rate_short); | |
327 if (new_rate_short == 0) | |
328 { | |
329 Sound_SetError("VOC sample rate is zero"); | |
330 return 0; | |
331 } | |
332 if ((v->rate != -1) && (new_rate_short != v->rate)) | |
333 { | |
334 Sound_SetError("VOC sample rate codes differ"); | |
335 return 0; | |
336 } | |
337 v->rate = new_rate_short; | |
338 | |
339 if (SDL_RWread(src, &uc, sizeof (uc), 1) != 1) | |
340 return 0; | |
341 | |
342 if (uc != 0) | |
343 { | |
344 Sound_SetError("VOC decoder only interprets 8-bit data"); | |
345 return 0; | |
346 } | |
347 | |
348 if (SDL_RWread(src, &uc, sizeof (uc), 1) != 1) | |
349 return 0; | |
350 | |
351 if (uc) | |
352 sample->actual.channels = 2; /* Stereo */ | |
353 /* Needed number of channels before finishing | |
354 compute for rate */ | |
355 sample->actual.rate = | |
356 (256000000L/(65536L - v->rate)) / sample->actual.channels; | |
357 /* An extended block must be followed by a data */ | |
358 /* block to be valid so loop back to top so it */ | |
359 /* can be grabed. */ | |
360 continue; | |
361 | |
362 case VOC_MARKER: | |
363 if (SDL_RWread(src, trash, sizeof (Uint8), 2) != 2) | |
364 return 0; | |
365 | |
366 /* Falling! Falling! */ | |
367 | |
368 default: /* text block or other krapola. */ | |
369 for(i = 0; i < sblen; i++) | |
370 { | |
371 if (SDL_RWread(src, &trash, sizeof (Uint8), 1) != 1) | |
372 return 0; | |
373 } | |
374 | |
375 if (block == VOC_TEXT) | |
376 continue; /* get next block */ | |
377 } | |
378 } | |
379 | |
380 return 1; | |
381 } | |
382 | |
383 | |
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
|
384 static int voc_read_waveform(Sound_Sample *sample) |
14 | 385 { |
386 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
387 SDL_RWops *src = internal->rw; | |
388 vs_t *v = (vs_t *) internal->decoder_private; | |
389 int done = 0; | |
390 Uint8 silence = 0x80; | |
391 Uint8 *buf = internal->buffer; | |
392 | |
393 if (v->rest == 0) | |
394 { | |
395 if (!voc_get_block(sample)) | |
396 return 0; | |
397 } | |
398 | |
399 if (v->rest == 0) | |
400 return 0; | |
401 | |
402 if (v->silent) | |
403 { | |
404 if (v->size == ST_SIZE_WORD) | |
405 silence = 0x00; | |
406 | |
407 /* Fill in silence */ | |
408 memset(buf, silence, v->rest); | |
409 done = v->rest; | |
410 v->rest = 0; | |
411 } | |
412 | |
413 else | |
414 { | |
415 Uint32 max = (v->rest < internal->buffer_size) ? | |
416 v->rest : internal->buffer_size; | |
417 done = SDL_RWread(src, buf + v->bufpos, 1, max); | |
418 v->rest -= done; | |
419 v->bufpos += done; | |
420 } | |
421 | |
422 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
|
423 } /* voc_read_waveform */ |
14 | 424 |
425 | |
426 static int VOC_open(Sound_Sample *sample, const char *ext) | |
427 { | |
428 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
429 vs_t *v = NULL; | |
430 | |
431 if (!voc_check_header(internal->rw)) | |
432 return(0); | |
433 | |
434 v = (vs_t *) malloc(sizeof (vs_t)); | |
435 BAIL_IF_MACRO(v == NULL, ERR_OUT_OF_MEMORY, 0); | |
436 memset(v, '\0', sizeof (vs_t)); | |
437 internal->decoder_private = v; | |
438 | |
224
1bafef18dabf
Implemented rewind method.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
439 v->start_pos = SDL_RWtell(internal->rw); |
14 | 440 v->rate = -1; |
441 if (!voc_get_block(sample)) | |
442 { | |
443 free(v); | |
444 return(0); | |
445 } /* if */ | |
446 | |
447 if (v->rate == -1) | |
448 { | |
449 Sound_SetError("VOC data had no sound!"); | |
450 free(v); | |
451 return(0); | |
452 } /* if */ | |
453 | |
62
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
47
diff
changeset
|
454 SNDDBG(("VOC: Accepting data stream.\n")); |
14 | 455 sample->actual.format = (v->size == ST_SIZE_WORD) ? AUDIO_S16LSB:AUDIO_U8; |
456 sample->actual.channels = v->channels; | |
457 sample->flags = SOUND_SAMPLEFLAG_NONE; | |
458 return(1); | |
459 } /* VOC_open */ | |
460 | |
461 | |
462 static void VOC_close(Sound_Sample *sample) | |
463 { | |
464 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
465 free(internal->decoder_private); | |
466 } /* VOC_close */ | |
467 | |
468 | |
469 static Uint32 VOC_read(Sound_Sample *sample) | |
470 { | |
471 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
472 vs_t *v = (vs_t *) internal->decoder_private; | |
473 | |
474 v->bufpos = 0; | |
475 while (v->bufpos < internal->buffer_size) | |
476 { | |
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
|
477 Uint32 rc = voc_read_waveform(sample); |
14 | 478 if (rc == 0) /* !!! FIXME: Could be an error... */ |
479 { | |
480 sample->flags |= SOUND_SAMPLEFLAG_EOF; | |
481 break; | |
482 } /* if */ | |
483 | |
484 if (!voc_get_block(sample)) | |
485 { | |
486 sample->flags |= SOUND_SAMPLEFLAG_ERROR; | |
487 break; | |
488 } /* if */ | |
489 } /* while */ | |
490 | |
491 return(v->bufpos); | |
492 } /* VOC_read */ | |
493 | |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
494 |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
495 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
|
496 { |
224
1bafef18dabf
Implemented rewind method.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
497 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
1bafef18dabf
Implemented rewind method.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
498 vs_t *v = (vs_t *) internal->decoder_private; |
1bafef18dabf
Implemented rewind method.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
499 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
|
500 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
|
501 v->rest = 0; |
1bafef18dabf
Implemented rewind method.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
502 return(1); |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
503 } /* VOC_rewind */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
504 |
64
40006625142a
Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
62
diff
changeset
|
505 #endif /* SOUND_SUPPORTS_VOC */ |
14 | 506 |
507 /* end of voc.c ... */ |