SDL, SDL_Mixer and SMPEG For mp3 Playback

Started by
20 comments, last by Crash 22 years, 3 months ago
Has anyone here used SDL, SDL_Mixer and SMPEG for mp3 playback? It was recommended to me by someone on this board but unfortunatley Im having some problems with it as it is my first time using SDL. So does anyone know of any tutorials on SDL_Mixer and/or SMPEG that are aavailable apart from the one on the SDL website? Or if anyone has used it could you post some code for me to look over? Hoping someone can help, Crash, "We Must Move Forwards NOT Backwards, Sideways NOT Forwards And Always Twirling Twirling Towards Success." - 2000 "If You Keep Looking Forward Your Gonna End Up Looking Backwards At Yourself Running Sideways!" - 2001
"We Must Move Forwards NOT Backwards, Sideways NOT Forwards And Always Twirling Twirling Towards Success." - 2000"If You Keep Looking Forward Your Gonna End Up Looking Backwards At Yourself Running Sideways!" - 2001
Advertisement
Oh another question, I assume you can use OpenGL for graphics and SDL for the sound and keyboard input, am I right?

Still Hoping,
Crash,

"We Must Move Forwards NOT Backwards, Sideways NOT Forwards And Always Twirling Twirling Towards Success." - 2000

"If You Keep Looking Forward Your Gonna End Up Looking Backwards At Yourself Running Sideways!" - 2001
"We Must Move Forwards NOT Backwards, Sideways NOT Forwards And Always Twirling Twirling Towards Success." - 2000"If You Keep Looking Forward Your Gonna End Up Looking Backwards At Yourself Running Sideways!" - 2001
quote:Original post by Crash
Has anyone here used SDL, SDL_Mixer and SMPEG for mp3 playback?

SDL Games Page
SDL Applications page
quote:So does anyone know of any tutorials on SDL_Mixer and/or SMPEG that are aavailable apart from the one on the SDL website?

Some of the projects on the pages referred to above are Open Source.
quote:...I assume you can use OpenGL for graphics and SDL for the sound and keyboard input, am I right?

Yes.

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
If you want an actual answer read Oluseyi''s post . However: I found OpenAL much easier than bothering with SDL''s sound output and SDL_Mixer. I am using VorbisFile to easily stream from a compressed audio file (the OGG format is as good as, and debatably better, than the MP3 format ). So, if you get bored (or stuck), give it a try or something.

[Resist Windows XP''s Invasive Production Activation Technology!]
I guess that means OpenAL doesn''t support mp3''s then Null And Void?

If not I cant use it really because I want to use mp3''s so that it is easier for the users to add their own music.
"We Must Move Forwards NOT Backwards, Sideways NOT Forwards And Always Twirling Twirling Towards Success." - 2000"If You Keep Looking Forward Your Gonna End Up Looking Backwards At Yourself Running Sideways!" - 2001
   #include "SDL.h" #include "SDL_mixer.h" SDL_InitSubSystem(SDL_INIT_AUDIO); Mix_Music *music = Mix_LoadMUS("music.mp3");   /* -1 will loop forever */ MIX_PlayMusic(music, -1);   /* only one music can play at a given time (unlike sounds), so Mix_HaltMusic() takes no parameter.  */ while (0 == MIX_PlayingMusic())   SDL_Wait(10);  /* don''t hang the CPU in a busy loop */ Mix_HaltMusic(); Miix_FreeMusic(m_pMusic); SDL_Quit();  


You can do much more (adjust volume, pause, etc), but that''s the barebone to play a mp3. Of course if you want 3D sound, go for OpenAL.
For the rest, I strongly suggest than check out the source of SDL. It''s very easy to understand and is heavily commented.

Remeber to link it against the SDL_mixer library.

Hope this helps a bit.
Thanks anonymous for that, I do though have one further problem. When I d/l SDL_Mixer it said I needed SMPEG to playback mp3''s with SDL_Mixer. Is this right? If so where do i need to use it? because your code and other code I have seen doesn''t seem to refer to it at all.
"We Must Move Forwards NOT Backwards, Sideways NOT Forwards And Always Twirling Twirling Towards Success." - 2000"If You Keep Looking Forward Your Gonna End Up Looking Backwards At Yourself Running Sideways!" - 2001
SDL_Mixer acts as a sort of a front end to two other libraries (SMPEG and Ogg). It will use SMPEG to decode MP3 and the Ogg Vorbis library for Ogg. However, you don''t need to include any header other than SDL_mixer. You only have to install these libraries and to make sure than SDL_mixer was compiled with MP3 support.

If you compile SDL_mixer yourself (and have SMPEG installed), it will compile MP3 support by default. If you use precompiled binaries, it is probably built-in already ..
Thanks again anonymous, I''ll go try that code and see if I can get it to work.
"We Must Move Forwards NOT Backwards, Sideways NOT Forwards And Always Twirling Twirling Towards Success." - 2000"If You Keep Looking Forward Your Gonna End Up Looking Backwards At Yourself Running Sideways!" - 2001
You''re welcome .

I just spotted an error in my (mockery of a) code. SDL_Wait() doesn''t exist, it should be SDL_Delay(). Sorry if it caused any problem.

This topic is closed to new replies.

Advertisement