changeset 331:e683cb99f88f

Fixed seek implementation.
author Ryan C. Gordon <icculus@icculus.org>
date Mon, 20 May 2002 09:40:59 +0000
parents a81976ed5df7
children 8ba541e81c1e
files decoders/au.c
diffstat 1 files changed, 8 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/decoders/au.c	Mon May 20 09:22:42 2002 +0000
+++ b/decoders/au.c	Mon May 20 09:40:59 2002 +0000
@@ -364,42 +364,17 @@
 {
     Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
     struct audec *dec = (struct audec *) internal->decoder_private;
-    int offset = dec->start_offset;
-    int frames = (int) (((float) sample->actual.rate / 1000.0) * ((float) ms));
-    int points = (int) (frames * sample->actual.channels);
+    int offset = __Sound_convertMsToBytePos(&sample->actual, ms);
     int rc;
-
-SNDDBG(("WARNING: AU_seek() may be buggy.\n")); /* !!! FIXME : remove this. */
-
-    switch (dec->encoding)
-    {
-        case AU_ENC_ULAW_8:  /* halve the byte offset for compression. */
-SNDDBG(("uLaw8 encoding\n")); /* !!! FIXME : remove this. */
-            offset += ((sizeof (Uint8) * points) >> 1);
-            break;
+    int pos;
 
-        case AU_ENC_LINEAR_8:
-SNDDBG(("linear8 encoding\n")); /* !!! FIXME : remove this. */
-            offset += (sizeof (Uint8) * points);
-            break;
-
-        case AU_ENC_LINEAR_16:
-SNDDBG(("linear16 encoding\n")); /* !!! FIXME : remove this. */
-            offset += (sizeof (Uint16) * points);
-            break;
+    if (dec->encoding == AU_ENC_ULAW_8)
+        offset >>= 1;  /* halve the byte offset for compression. */
 
-        default:
-            BAIL_MACRO("Unexpected format. Something is very wrong.", 0);
-            break;
-    } /* switch */
-
-SNDDBG(("Seek to %d (edge is %d).\n", (int) offset, (int) dec->total));
-
-    BAIL_IF_MACRO(offset >= dec->total, ERR_IO_ERROR, 0); /* seek past end? */
-
-    rc = SDL_RWseek(internal->rw, offset, SEEK_SET);
-    BAIL_IF_MACRO(rc != offset, ERR_IO_ERROR, 0);
-    dec->remaining = dec->total - (offset - 2);
+    pos = (int) (dec->start_offset + offset);
+    rc = SDL_RWseek(internal->rw, pos, SEEK_SET);
+    BAIL_IF_MACRO(rc != pos, ERR_IO_ERROR, 0);
+    dec->remaining = dec->total - offset;
     return(1);
 } /* AU_seek */