# HG changeset patch # User Ryan C. Gordon # Date 1019424899 0 # Node ID eb7c929193ddede30d952d1ffac55d7b1106bbda # Parent c97be6e1bd27d688db527ea7692ed42b127349ad Added seek support for uncompressed WAVs. diff -r c97be6e1bd27 -r eb7c929193dd decoders/wav.c --- a/decoders/wav.c Sun Apr 21 18:39:47 2002 +0000 +++ b/decoders/wav.c Sun Apr 21 21:34:59 2002 +0000 @@ -149,6 +149,7 @@ void (*free)(struct S_WAV_FMT_T *fmt); Uint32 (*read_sample)(Sound_Sample *sample); int (*rewind_sample)(Sound_Sample *sample); + int (*seek_sample)(Sound_Sample *sample, Uint32 ms); union { @@ -275,6 +276,20 @@ } /* read_sample_fmt_normal */ +static int seek_sample_fmt_normal(Sound_Sample *sample, Uint32 ms) +{ + Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; + wav_t *w = (wav_t *) internal->decoder_private; + fmt_t *fmt = w->fmt; + int offset = __Sound_convertMsToBytePos(&sample->actual, ms); + int pos = (int) (fmt->data_starting_offset + offset); + int rc = SDL_RWseek(internal->rw, pos, SEEK_SET); + BAIL_IF_MACRO(rc != pos, ERR_IO_ERROR, 0); + w->bytesLeft = fmt->total_bytes - offset; + return(1); /* success. */ +} /* seek_sample_fmt_normal */ + + static int rewind_sample_fmt_normal(Sound_Sample *sample) { /* no-op. */ @@ -288,6 +303,7 @@ fmt->free = NULL; fmt->read_sample = read_sample_fmt_normal; fmt->rewind_sample = rewind_sample_fmt_normal; + fmt->seek_sample = seek_sample_fmt_normal; return(1); } /* read_fmt_normal */ @@ -509,8 +525,14 @@ } /* rewind_sample_fmt_adpcm */ +static int seek_sample_fmt_adpcm(Sound_Sample *sample, Uint32 ms) +{ + return(0); /* !!! FIXME: Can we reasonably implement this? */ +} /* seek_sample_fmt_adpcm */ + + /* - * Read in a the adpcm-specific info from disk. This makes this process + * Read in the adpcm-specific info from disk. This makes this process * safe regardless of the processor's byte order or how the fmt_t * structure is packed. */ @@ -663,6 +685,8 @@ internal->decoder_private = (void *) w; sample->flags = SOUND_SAMPLEFLAG_NONE; + if (fmt->wFormatTag == FMT_NORMAL) + sample->flags |= SOUND_SAMPLEFLAG_CANSEEK; SNDDBG(("WAV: Accepting data stream.\n")); return(1); /* we'll handle this data. */ @@ -724,7 +748,9 @@ static int WAV_seek(Sound_Sample *sample, Uint32 ms) { - BAIL_MACRO("!!! FIXME: Not implemented", 0); + Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; + wav_t *w = (wav_t *) internal->decoder_private; + return(w->fmt->seek_sample(sample, ms)); } /* WAV_seek */ #endif /* SOUND_SUPPORTS_WAV */