music_ogg.c
changeset 246 9fa5d0f9d042
parent 241 503416fca921
child 281 33730d0864d8
     1.1 --- a/music_ogg.c	Sat Aug 21 12:27:02 2004 +0000
     1.2 +++ b/music_ogg.c	Sun Aug 22 07:55:14 2004 +0000
     1.3 @@ -83,6 +83,58 @@
     1.4  	return(music);
     1.5  }
     1.6  
     1.7 +
     1.8 +static size_t sdl_read_func(void *ptr, size_t size, size_t nmemb, void *datasource)
     1.9 +{
    1.10 +    return SDL_RWread((SDL_RWops*)datasource, ptr, size, nmemb);
    1.11 +}
    1.12 +
    1.13 +static int sdl_seek_func(void *datasource, ogg_int64_t offset, int whence)
    1.14 +{
    1.15 +    return SDL_RWseek((SDL_RWops*)datasource, (int)offset, whence);
    1.16 +}
    1.17 +
    1.18 +static int sdl_close_func(void *datasource)
    1.19 +{
    1.20 +    return SDL_RWclose((SDL_RWops*)datasource);
    1.21 +}
    1.22 +
    1.23 +static long sdl_tell_func(void *datasource)
    1.24 +{
    1.25 +    return SDL_RWtell((SDL_RWops*)datasource);
    1.26 +}
    1.27 +
    1.28 +/* Load an OGG stream from an SDL_RWops object */
    1.29 +OGG_music *OGG_new_RW(SDL_RWops *rw)
    1.30 +{
    1.31 +	OGG_music *music;
    1.32 +	ov_callbacks callbacks;
    1.33 +
    1.34 +	callbacks.read_func = sdl_read_func;
    1.35 +	callbacks.seek_func = sdl_seek_func;
    1.36 +	callbacks.close_func = sdl_close_func;
    1.37 +	callbacks.tell_func = sdl_tell_func;
    1.38 +
    1.39 +	music = (OGG_music *)malloc(sizeof *music);
    1.40 +	if ( music ) {
    1.41 +		/* Initialize the music structure */
    1.42 +		memset(music, 0, (sizeof *music));
    1.43 +		OGG_stop(music);
    1.44 +		OGG_setvolume(music, MIX_MAX_VOLUME);
    1.45 +		music->section = -1;
    1.46 +
    1.47 +		if ( ov_open_callbacks(rw, &music->vf, NULL, 0, callbacks) < 0 ) {
    1.48 +			SDL_SetError("Not an Ogg Vorbis audio stream");
    1.49 +			free(music);
    1.50 +			SDL_RWclose(rw);
    1.51 +			return(NULL);
    1.52 +		}
    1.53 +	} else {
    1.54 +		SDL_SetError("Out of memory");
    1.55 +	}
    1.56 +	return(music);
    1.57 +}
    1.58 +
    1.59  /* Start playback of a given OGG stream */
    1.60  void OGG_play(OGG_music *music)
    1.61  {