RES: SDL_Sound simple exemple

tks for the exemple…

If you just want to play an MP3, consider SDL_mixer instead.

what i have to do to put my SDL_Mixer to play a mp3 file?
tks> ----- Mensagem original -----

De: Ryan C. Gordon [SMTP:icculus at clutteredmind.org]
Enviada em: sexta-feira, 26 de setembro de 2003 04:14
Para: sdl at libsdl.org
Assunto: Re: [SDL] SDL_Sound simple exemple

finally i get the sdl_sound running…

i took a look at the playsound.c but this exemple is complicated (i’m
learning C++)
i only want play an mp3 sample, can someone has an easy exemple to show
me how to do this

If you were to cut out all the extras from playsound, it’d look roughly
like this:

global:
static volatile int still_playing_audio = 1;

in main:
SDL_Init(SDL_INIT_AUDIO);
Sound_Init();
Sound_Sample *sample;
sample = Sound_NewSampleFromFile(“mysound.mp3”, NULL, 16384);

SDL_AudioSpec devspec;
memcpy(&devspec, &sample->actual, sizeof (SDL_AudioSpec));
devspec.callback = my_audio_callback;
devspec.samples = 4096;
devspec.userdata = sample;

Sound_Decode(sample);

still_playing_audio = 1;
SDL_OpenAudio(&devspec, NULL);
SDL_PauseAudio(0);

while (still_playing_audio)
SDL_Delay(10); // sleep awhile.

SDL_Quit();
Sound_FreeSample(sample);
return(0);

in my_audio_callback:

  • Cast the user-defined void * to a Sound_Sample *.
  • See if there’s data left in sample->buffer.
  • If not, call Sound_Decode().
  • memcpy() from appropriate place in sample->buffer to audio stream.
  • update state variables (where in sample->buffer you are, etc).
  • If sample->flags indicate error or eof and we’ve exhausted
    sample->buffer, set still_playing_audio to zero.
  • return.

If you just want to play an MP3, consider SDL_mixer instead.

–ryan.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Extract the SDL_mixer source and look at playmus.c.On Fri, Sep 26, 2003 at 09:21:49AM -0300, Ricardo Ferrari (SPO-LAB) wrote:

what i have to do to put my SDL_Mixer to play a mp3 file?
tks