comparison decoders/au.c @ 331:e683cb99f88f

Fixed seek implementation.
author Ryan C. Gordon <icculus@icculus.org>
date Mon, 20 May 2002 09:40:59 +0000
parents a81976ed5df7
children cbb15ecf423a
comparison
equal deleted inserted replaced
330:a81976ed5df7 331:e683cb99f88f
362 362
363 static int AU_seek(Sound_Sample *sample, Uint32 ms) 363 static int AU_seek(Sound_Sample *sample, Uint32 ms)
364 { 364 {
365 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; 365 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
366 struct audec *dec = (struct audec *) internal->decoder_private; 366 struct audec *dec = (struct audec *) internal->decoder_private;
367 int offset = dec->start_offset; 367 int offset = __Sound_convertMsToBytePos(&sample->actual, ms);
368 int frames = (int) (((float) sample->actual.rate / 1000.0) * ((float) ms));
369 int points = (int) (frames * sample->actual.channels);
370 int rc; 368 int rc;
371 369 int pos;
372 SNDDBG(("WARNING: AU_seek() may be buggy.\n")); /* !!! FIXME : remove this. */ 370
373 371 if (dec->encoding == AU_ENC_ULAW_8)
374 switch (dec->encoding) 372 offset >>= 1; /* halve the byte offset for compression. */
375 { 373
376 case AU_ENC_ULAW_8: /* halve the byte offset for compression. */ 374 pos = (int) (dec->start_offset + offset);
377 SNDDBG(("uLaw8 encoding\n")); /* !!! FIXME : remove this. */ 375 rc = SDL_RWseek(internal->rw, pos, SEEK_SET);
378 offset += ((sizeof (Uint8) * points) >> 1); 376 BAIL_IF_MACRO(rc != pos, ERR_IO_ERROR, 0);
379 break; 377 dec->remaining = dec->total - offset;
380
381 case AU_ENC_LINEAR_8:
382 SNDDBG(("linear8 encoding\n")); /* !!! FIXME : remove this. */
383 offset += (sizeof (Uint8) * points);
384 break;
385
386 case AU_ENC_LINEAR_16:
387 SNDDBG(("linear16 encoding\n")); /* !!! FIXME : remove this. */
388 offset += (sizeof (Uint16) * points);
389 break;
390
391 default:
392 BAIL_MACRO("Unexpected format. Something is very wrong.", 0);
393 break;
394 } /* switch */
395
396 SNDDBG(("Seek to %d (edge is %d).\n", (int) offset, (int) dec->total));
397
398 BAIL_IF_MACRO(offset >= dec->total, ERR_IO_ERROR, 0); /* seek past end? */
399
400 rc = SDL_RWseek(internal->rw, offset, SEEK_SET);
401 BAIL_IF_MACRO(rc != offset, ERR_IO_ERROR, 0);
402 dec->remaining = dec->total - (offset - 2);
403 return(1); 378 return(1);
404 } /* AU_seek */ 379 } /* AU_seek */
405 380
406 #endif /* SOUND_SUPPORTS_AU */ 381 #endif /* SOUND_SUPPORTS_AU */
407 382