diff decoders/raw.c @ 306:c97be6e1bd27

Added framework for Sound_Seek() support.
author Ryan C. Gordon <icculus@icculus.org>
date Sun, 21 Apr 2002 18:39:47 +0000
parents c9772a9f5271
children cbb15ecf423a
line wrap: on
line diff
--- a/decoders/raw.c	Sun Apr 21 17:48:11 2002 +0000
+++ b/decoders/raw.c	Sun Apr 21 18:39:47 2002 +0000
@@ -60,6 +60,7 @@
 static void RAW_close(Sound_Sample *sample);
 static Uint32 RAW_read(Sound_Sample *sample);
 static int RAW_rewind(Sound_Sample *sample);
+static int RAW_seek(Sound_Sample *sample, Uint32 ms);
 
 static const char *extensions_raw[] = { "RAW", NULL };
 const Sound_DecoderFunctions __Sound_DecoderFunctions_RAW =
@@ -76,7 +77,8 @@
     RAW_open,       /*   open() method */
     RAW_close,      /*  close() method */
     RAW_read,       /*   read() method */
-    RAW_rewind      /* rewind() method */
+    RAW_rewind,     /* rewind() method */
+    RAW_seek        /*   seek() method */
 };
 
 
@@ -123,7 +125,7 @@
          * We never convert raw samples; what you ask for is what you get.
          */
     memcpy(&sample->actual, &sample->desired, sizeof (Sound_AudioInfo));
-    sample->flags = SOUND_SAMPLEFLAG_NONE;
+    sample->flags = SOUND_SAMPLEFLAG_CANSEEK;
 
     return(1); /* we'll handle this data. */
 } /* RAW_open */
@@ -170,6 +172,16 @@
 } /* RAW_rewind */
 
 
+static int RAW_seek(Sound_Sample *sample, Uint32 ms)
+{
+    Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
+    int pos = (int) __Sound_convertMsToBytePos(&sample->actual, ms);
+    int err = (SDL_RWseek(internal->rw, pos, SEEK_SET) != pos);
+    BAIL_IF_MACRO(err, ERR_IO_ERROR, 0);
+    return(1);
+} /* RAW_seek */
+
+
 #endif /* SOUND_SUPPORTS_RAW */