comparison SDL_sound.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 6fe6de401b63
children d62c05322a3e
comparison
equal deleted inserted replaced
305:c345a40a8a99 306:c97be6e1bd27
344 344
345 345
346 /* 346 /*
347 * This is declared in the internal header. 347 * This is declared in the internal header.
348 */ 348 */
349 void Sound_SetError(const char *str) 349 void __Sound_SetError(const char *str)
350 { 350 {
351 ErrMsg *err; 351 ErrMsg *err;
352 352
353 if (str == NULL) 353 if (str == NULL)
354 return; 354 return;
376 } /* if */ 376 } /* if */
377 377
378 err->error_available = 1; 378 err->error_available = 1;
379 strncpy(err->error_string, str, sizeof (err->error_string)); 379 strncpy(err->error_string, str, sizeof (err->error_string));
380 err->error_string[sizeof (err->error_string) - 1] = '\0'; 380 err->error_string[sizeof (err->error_string) - 1] = '\0';
381 } /* Sound_SetError */ 381 } /* __Sound_SetError */
382
383
384 Uint32 __Sound_convertMsToBytePos(Sound_AudioInfo *info, Uint32 ms)
385 {
386 /* "frames" == "sample frames" */
387 float frames_per_ms = ((float) info->rate) / 1000.0;
388 Uint32 frame_offset = (Uint32) (frames_per_ms * ((float) ms));
389 Uint32 frame_size = (Uint32) ((info->format & 0xFF) / 8) * info->channels;
390 return(frame_offset * frame_size);
391 } /* __Sound_convertMsToBytePos */
382 392
383 393
384 /* 394 /*
385 * -ansi and -pedantic flags prevent use of strcasecmp() on Linux, and 395 * -ansi and -pedantic flags prevent use of strcasecmp() on Linux, and
386 * I honestly don't want to mess around with figuring out if a given 396 * I honestly don't want to mess around with figuring out if a given
844 } /* if */ 854 } /* if */
845 855
846 sample->flags &= !SOUND_SAMPLEFLAG_EAGAIN; 856 sample->flags &= !SOUND_SAMPLEFLAG_EAGAIN;
847 sample->flags &= !SOUND_SAMPLEFLAG_ERROR; 857 sample->flags &= !SOUND_SAMPLEFLAG_ERROR;
848 sample->flags &= !SOUND_SAMPLEFLAG_EOF; 858 sample->flags &= !SOUND_SAMPLEFLAG_EOF;
859
849 return(1); 860 return(1);
850 } /* Sound_Rewind */ 861 } /* Sound_Rewind */
851 862
852 863
864 int Sound_Seek(Sound_Sample *sample, Uint32 ms)
865 {
866 Sound_SampleInternal *internal;
867
868 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
869 if (!(sample->flags & SOUND_SAMPLEFLAG_CANSEEK))
870 BAIL_MACRO(ERR_CANNOT_SEEK, 0);
871
872 internal = (Sound_SampleInternal *) sample->opaque;
873 BAIL_IF_MACRO(!internal->funcs->seek(sample, ms), NULL, 0);
874
875 sample->flags &= !SOUND_SAMPLEFLAG_EAGAIN;
876 sample->flags &= !SOUND_SAMPLEFLAG_ERROR;
877 sample->flags &= !SOUND_SAMPLEFLAG_EOF;
878
879 return(1);
880 } /* Sound_Rewind */
881
882
853 /* end of SDL_sound.c ... */ 883 /* end of SDL_sound.c ... */
854 884