music_ogg.c
changeset 312 8a536296ef3d
parent 281 33730d0864d8
child 353 21fe62f9c4c6
     1.1 --- a/music_ogg.c	Fri May 12 02:58:31 2006 +0000
     1.2 +++ b/music_ogg.c	Fri May 12 06:14:15 2006 +0000
     1.3 @@ -31,6 +31,7 @@
     1.4  #include <string.h>
     1.5  
     1.6  #include "SDL_mixer.h"
     1.7 +#include "dynamic_ogg.h"
     1.8  #include "music_ogg.h"
     1.9  
    1.10  /* This is the format of the audio mixer data */
    1.11 @@ -65,20 +66,25 @@
    1.12  		OGG_setvolume(music, MIX_MAX_VOLUME);
    1.13  		music->section = -1;
    1.14  
    1.15 +		if ( Mix_InitOgg() < 0 ) {
    1.16 +			return(NULL);
    1.17 +		}
    1.18  		fp = fopen(file, "rb");
    1.19  		if ( fp == NULL ) {
    1.20 +			free(music);
    1.21 +			Mix_QuitOgg();
    1.22  			SDL_SetError("Couldn't open %s", file);
    1.23 -			free(music);
    1.24  			return(NULL);
    1.25  		}
    1.26 -		if ( ov_open(fp, &music->vf, NULL, 0) < 0 ) {
    1.27 +		if ( vorbis.ov_open(fp, &music->vf, NULL, 0) < 0 ) {
    1.28 +			fclose(fp);
    1.29 +			free(music);
    1.30 +			Mix_QuitOgg();
    1.31  			SDL_SetError("Not an Ogg Vorbis audio stream");
    1.32 -			free(music);
    1.33 -			fclose(fp);
    1.34  			return(NULL);
    1.35  		}
    1.36  	} else {
    1.37 -		SDL_SetError("Out of memory");
    1.38 +		SDL_OutOfMemory();
    1.39  	}
    1.40  	return(music);
    1.41  }
    1.42 @@ -123,14 +129,18 @@
    1.43  		OGG_setvolume(music, MIX_MAX_VOLUME);
    1.44  		music->section = -1;
    1.45  
    1.46 -		if ( ov_open_callbacks(rw, &music->vf, NULL, 0, callbacks) < 0 ) {
    1.47 -			SDL_SetError("Not an Ogg Vorbis audio stream");
    1.48 +		if ( Mix_InitOgg() < 0 ) {
    1.49 +			return(NULL);
    1.50 +		}
    1.51 +		if ( vorbis.ov_open_callbacks(rw, &music->vf, NULL, 0, callbacks) < 0 ) {
    1.52  			free(music);
    1.53  			SDL_RWclose(rw);
    1.54 +			Mix_QuitOgg();
    1.55 +			SDL_SetError("Not an Ogg Vorbis audio stream");
    1.56  			return(NULL);
    1.57  		}
    1.58  	} else {
    1.59 -		SDL_SetError("Out of memory");
    1.60 +		SDL_OutOfMemory();
    1.61  	}
    1.62  	return(music);
    1.63  }
    1.64 @@ -155,7 +165,7 @@
    1.65  	char data[4096];
    1.66  	SDL_AudioCVT *cvt;
    1.67  
    1.68 -	len = ov_read(&music->vf, data, sizeof(data), 0, 2, 1, &section);
    1.69 +	len = vorbis.ov_read(&music->vf, data, sizeof(data), 0, 2, 1, &section);
    1.70  	if ( len <= 0 ) {
    1.71  		if ( len == 0 ) {
    1.72  			music->playing = 0;
    1.73 @@ -166,7 +176,7 @@
    1.74  	if ( section != music->section ) {
    1.75  		vorbis_info *vi;
    1.76  
    1.77 -		vi = ov_info(&music->vf, -1);
    1.78 +		vi = vorbis.ov_info(&music->vf, -1);
    1.79  		SDL_BuildAudioCVT(cvt, AUDIO_S16, vi->channels, vi->rate,
    1.80  		                       mixer.format,mixer.channels,mixer.freq);
    1.81  		if ( cvt->buf ) {
    1.82 @@ -232,15 +242,16 @@
    1.83  		if ( music->cvt.buf ) {
    1.84  			free(music->cvt.buf);
    1.85  		}
    1.86 -		ov_clear(&music->vf);
    1.87 +		vorbis.ov_clear(&music->vf);
    1.88  		free(music);
    1.89 +		Mix_QuitOgg();
    1.90  	}
    1.91  }
    1.92  
    1.93  /* Jump (seek) to a given position (time is in seconds) */
    1.94  void OGG_jump_to_time(OGG_music *music, double time)
    1.95  {
    1.96 -       ov_time_seek( &music->vf, time );
    1.97 +       vorbis.ov_time_seek( &music->vf, time );
    1.98  }
    1.99  
   1.100  #endif /* OGG_MUSIC */