comparison decoders/wav.c @ 307:eb7c929193dd

Added seek support for uncompressed WAVs.
author Ryan C. Gordon <icculus@icculus.org>
date Sun, 21 Apr 2002 21:34:59 +0000
parents c97be6e1bd27
children 565ae12fa74e
comparison
equal deleted inserted replaced
306:c97be6e1bd27 307:eb7c929193dd
147 Uint32 total_bytes; 147 Uint32 total_bytes;
148 148
149 void (*free)(struct S_WAV_FMT_T *fmt); 149 void (*free)(struct S_WAV_FMT_T *fmt);
150 Uint32 (*read_sample)(Sound_Sample *sample); 150 Uint32 (*read_sample)(Sound_Sample *sample);
151 int (*rewind_sample)(Sound_Sample *sample); 151 int (*rewind_sample)(Sound_Sample *sample);
152 int (*seek_sample)(Sound_Sample *sample, Uint32 ms);
152 153
153 union 154 union
154 { 155 {
155 struct 156 struct
156 { 157 {
273 274
274 return(retval); 275 return(retval);
275 } /* read_sample_fmt_normal */ 276 } /* read_sample_fmt_normal */
276 277
277 278
279 static int seek_sample_fmt_normal(Sound_Sample *sample, Uint32 ms)
280 {
281 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
282 wav_t *w = (wav_t *) internal->decoder_private;
283 fmt_t *fmt = w->fmt;
284 int offset = __Sound_convertMsToBytePos(&sample->actual, ms);
285 int pos = (int) (fmt->data_starting_offset + offset);
286 int rc = SDL_RWseek(internal->rw, pos, SEEK_SET);
287 BAIL_IF_MACRO(rc != pos, ERR_IO_ERROR, 0);
288 w->bytesLeft = fmt->total_bytes - offset;
289 return(1); /* success. */
290 } /* seek_sample_fmt_normal */
291
292
278 static int rewind_sample_fmt_normal(Sound_Sample *sample) 293 static int rewind_sample_fmt_normal(Sound_Sample *sample)
279 { 294 {
280 /* no-op. */ 295 /* no-op. */
281 return(1); 296 return(1);
282 } /* rewind_sample_fmt_normal */ 297 } /* rewind_sample_fmt_normal */
286 { 301 {
287 /* (don't need to read more from the RWops...) */ 302 /* (don't need to read more from the RWops...) */
288 fmt->free = NULL; 303 fmt->free = NULL;
289 fmt->read_sample = read_sample_fmt_normal; 304 fmt->read_sample = read_sample_fmt_normal;
290 fmt->rewind_sample = rewind_sample_fmt_normal; 305 fmt->rewind_sample = rewind_sample_fmt_normal;
306 fmt->seek_sample = seek_sample_fmt_normal;
291 return(1); 307 return(1);
292 } /* read_fmt_normal */ 308 } /* read_fmt_normal */
293 309
294 310
295 311
507 w->fmt->fmt.adpcm.samples_left_in_block = 0; 523 w->fmt->fmt.adpcm.samples_left_in_block = 0;
508 return(1); 524 return(1);
509 } /* rewind_sample_fmt_adpcm */ 525 } /* rewind_sample_fmt_adpcm */
510 526
511 527
512 /* 528 static int seek_sample_fmt_adpcm(Sound_Sample *sample, Uint32 ms)
513 * Read in a the adpcm-specific info from disk. This makes this process 529 {
530 return(0); /* !!! FIXME: Can we reasonably implement this? */
531 } /* seek_sample_fmt_adpcm */
532
533
534 /*
535 * Read in the adpcm-specific info from disk. This makes this process
514 * safe regardless of the processor's byte order or how the fmt_t 536 * safe regardless of the processor's byte order or how the fmt_t
515 * structure is packed. 537 * structure is packed.
516 */ 538 */
517 static int read_fmt_adpcm(SDL_RWops *rw, fmt_t *fmt) 539 static int read_fmt_adpcm(SDL_RWops *rw, fmt_t *fmt)
518 { 540 {
661 sample->actual.channels ); 683 sample->actual.channels );
662 684
663 internal->decoder_private = (void *) w; 685 internal->decoder_private = (void *) w;
664 686
665 sample->flags = SOUND_SAMPLEFLAG_NONE; 687 sample->flags = SOUND_SAMPLEFLAG_NONE;
688 if (fmt->wFormatTag == FMT_NORMAL)
689 sample->flags |= SOUND_SAMPLEFLAG_CANSEEK;
666 690
667 SNDDBG(("WAV: Accepting data stream.\n")); 691 SNDDBG(("WAV: Accepting data stream.\n"));
668 return(1); /* we'll handle this data. */ 692 return(1); /* we'll handle this data. */
669 } /* WAV_open_internal */ 693 } /* WAV_open_internal */
670 694
722 } /* WAV_rewind */ 746 } /* WAV_rewind */
723 747
724 748
725 static int WAV_seek(Sound_Sample *sample, Uint32 ms) 749 static int WAV_seek(Sound_Sample *sample, Uint32 ms)
726 { 750 {
727 BAIL_MACRO("!!! FIXME: Not implemented", 0); 751 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
752 wav_t *w = (wav_t *) internal->decoder_private;
753 return(w->fmt->seek_sample(sample, ms));
728 } /* WAV_seek */ 754 } /* WAV_seek */
729 755
730 #endif /* SOUND_SUPPORTS_WAV */ 756 #endif /* SOUND_SUPPORTS_WAV */
731 757
732 /* end of wav.c ... */ 758 /* end of wav.c ... */