示例#1
0
/* Load an OGG stream from an SDL_RWops object */
OGG_music *OGG_new_RW(SDL_RWops *rw)
{
    OGG_music *music;
    ov_callbacks callbacks;

    callbacks.read_func = sdl_read_func;
    callbacks.seek_func = sdl_seek_func;
    callbacks.close_func = sdl_close_func;
    callbacks.tell_func = sdl_tell_func;

    music = (OGG_music *)malloc(sizeof *music);
    if ( music ) {
        /* Initialize the music structure */
        memset(music, 0, (sizeof *music));
        OGG_stop(music);
        OGG_setvolume(music, MIX_MAX_VOLUME);
        music->section = -1;

        if ( Mix_InitOgg() < 0 ) {
            return(NULL);
        }
        if ( vorbis.ov_open_callbacks(rw, &music->vf, NULL, 0, callbacks) < 0 ) {
            free(music);
            SDL_RWclose(rw);
            Mix_QuitOgg();
            SDL_SetError("Not an Ogg Vorbis audio stream");
            return(NULL);
        }
    } else {
        SDL_OutOfMemory();
    }
    return(music);
}
示例#2
0
int Mix_Init(int flags)
{
	int result = 0;

	if (flags & MIX_INIT_FLUIDSYNTH) {
#ifdef USE_FLUIDSYNTH_MIDI
		if ((initialized & MIX_INIT_FLUIDSYNTH) || Mix_InitFluidSynth() == 0) {
			result |= MIX_INIT_FLUIDSYNTH;
		}
#else
		Mix_SetError("Mixer not built with FluidSynth support");
#endif
	}
	if (flags & MIX_INIT_FLAC) {
#ifdef FLAC_MUSIC
		if ((initialized & MIX_INIT_FLAC) || Mix_InitFLAC() == 0) {
			result |= MIX_INIT_FLAC;
		}
#else
		Mix_SetError("Mixer not built with FLAC support");
#endif
	}
	if (flags & MIX_INIT_MOD) {
#ifdef MOD_MUSIC
		if ((initialized & MIX_INIT_MOD) || Mix_InitMOD() == 0) {
			result |= MIX_INIT_MOD;
		}
#else
		Mix_SetError("Mixer not built with MOD support");
#endif
	}
	if (flags & MIX_INIT_MP3) {
#ifdef MP3_MUSIC
		if ((initialized & MIX_INIT_MP3) || Mix_InitMP3() == 0) {
			result |= MIX_INIT_MP3;
		}
#else
		Mix_SetError("Mixer not built with MP3 support");
#endif
	}
	if (flags & MIX_INIT_OGG) {
#ifdef OGG_MUSIC
		if ((initialized & MIX_INIT_OGG) || Mix_InitOgg() == 0) {
			result |= MIX_INIT_OGG;
		}
#else
		Mix_SetError("Mixer not built with Ogg Vorbis support");
#endif
	}
	initialized |= result;

	return (result);
}
示例#3
0
文件: mixer.c 项目: jcemelanda/wormux
int Mix_Init(int flags)
{
 int result = 0;

 if (flags & MIX_INIT_OGG) {
#ifdef OGG_MUSIC
   if ((initialized & MIX_INIT_OGG) || Mix_InitOgg() == 0) {
     result |= MIX_INIT_OGG;
   }
#else
   Mix_SetError("Mixer not built with Ogg Vorbis support");
#endif
 }
 initialized |= result;

 return (result);
}
示例#4
0
/* don't call this directly; use Mix_LoadWAV_RW() for now. */
SDL_AudioSpec *Mix_LoadOGG_RW (SDL_RWops *src, int freesrc,
        SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len)
{
    OggVorbis_File vf;
    ov_callbacks callbacks;
    vorbis_info *info;
    Uint8 *buf;
    int bitstream = -1;
    long samplesize;
    long samples;
    int read, to_read;
    int must_close = 1;
    int was_error = 1;
    
    if ( (!src) || (!audio_buf) || (!audio_len) )   /* sanity checks. */
        goto done;

    if ( Mix_InitOgg() < 0 )
        goto done;

    callbacks.read_func = sdl_read_func;
    callbacks.seek_func = sdl_seek_func;
    callbacks.tell_func = sdl_tell_func;
    callbacks.close_func = freesrc ? 
                           sdl_close_func_freesrc : sdl_close_func_nofreesrc;

    if (vorbis.ov_open_callbacks(src, &vf, NULL, 0, callbacks) != 0)
    {
        SDL_SetError("OGG bitstream is not valid Vorbis stream!");
        goto done;
    }

    must_close = 0;
    
    info = vorbis.ov_info(&vf, -1);
    
    *audio_buf = NULL;
    *audio_len = 0;
    memset(spec, '\0', sizeof (SDL_AudioSpec));

    spec->format = AUDIO_S16;
    spec->channels = info->channels;
    spec->freq = info->rate;
    spec->samples = 4096; /* buffer size */
    
    samples = (long)vorbis.ov_pcm_total(&vf, -1);

    *audio_len = spec->size = samples * spec->channels * 2;
    *audio_buf = malloc(*audio_len);
    if (*audio_buf == NULL)
        goto done;

    buf = *audio_buf;
    to_read = *audio_len;
#ifdef OGG_USE_TREMOR
    for (read = vorbis.ov_read(&vf, (char *)buf, to_read, &bitstream);
	 read > 0;
	 read = vorbis.ov_read(&vf, (char *)buf, to_read, &bitstream))
#else
    for (read = vorbis.ov_read(&vf, (char *)buf, to_read, 1/*LE*/, 2/*16bit*/, 1/*signed*/, &bitstream);
         read > 0;
         read = vorbis.ov_read(&vf, (char *)buf, to_read, 1, 2, 1, &bitstream))
#endif	 
    {
        if (read == OV_HOLE || read == OV_EBADLINK)
            break; /* error */
        
        to_read -= read;
        buf += read;
    }

    vorbis.ov_clear(&vf);
    was_error = 0;

    /* Don't return a buffer that isn't a multiple of samplesize */
    samplesize = ((spec->format & 0xFF)/8)*spec->channels;
    *audio_len &= ~(samplesize-1);

done:
    if (src && must_close)
    {
        if (freesrc)
            SDL_RWclose(src);
        else
            SDL_RWseek(src, 0, SEEK_SET);
    }

    if ( was_error )
        spec = NULL;

    Mix_QuitOgg();

    return(spec);
} /* Mix_LoadOGG_RW */