How to play MP3? OpenGL and DirectX
Hi!
I like to know how i can play MP3 sound with directX and/or openGL.
A solution without using OpenGL and DirectX would be also useful.
PS: I can decode MPEG2 videos but then there is no sound. The video is already rendered into a texture. But now I need the matching sound in background!
Thanks for advance!
MP3s can not be played using OpenGL. Use DirectShow to play an MP3 file. Use Google and you should find a bunch of tutorials on the subject. There are other libraries that also play MP3s but I don't know of any specific ones off the top of my head.
FMOD has the capability to decode and play mp3s, though you're on your own when it comes to licensing.
If you want cross-platform, go with something like SDL_mixer: http://www.libsdl.org/projects/SDL_mixer/
If you are already using OpenGL for rendering, you'd probably want the similar interface for sound named OpenAL.
Quote:Original post by nife
If you are already using OpenGL for rendering, you'd probably want the similar interface for sound named OpenAL.
You can't use AL to load MP3. You need a decoder lib, then you pass the raw PCM data to AL... or whatever sound API you use.
FMOD has a built in MP3 decoder but for commercial projects, you have to buy it.
Writing a basic Ogg Vorbis decoder and coupling that with OpenAL is a free surefire way to have audio - and work on platforms that don't have directX. Considering, you are supporting OpenAL, you should also strive be be platform independent.
If you can't be bothered to write your own (I have, and is pretty simple), then, I strongly suggest Fmod. It is a great sound engine, and you can use it for free for free projects, and it works on Win32, Linux, Mac, etc. And, for small free apps, you can generally avoid paying any MP3 royalties either - but I still suggest ogg vorbis, Fmod can handle that fine.. And you will be supporting a superior coded :)
If you can't be bothered to write your own (I have, and is pretty simple), then, I strongly suggest Fmod. It is a great sound engine, and you can use it for free for free projects, and it works on Win32, Linux, Mac, etc. And, for small free apps, you can generally avoid paying any MP3 royalties either - but I still suggest ogg vorbis, Fmod can handle that fine.. And you will be supporting a superior coded :)
Quote:Original post by V-manQuote:Original post by nife
If you are already using OpenGL for rendering, you'd probably want the similar interface for sound named OpenAL.
You can't use AL to load MP3. You need a decoder lib, then you pass the raw PCM data to AL... or whatever sound API you use.
FMOD has a built in MP3 decoder but for commercial projects, you have to buy it.
This really isn't an issue. There are plenty of tutorials/examples on how to do this with OpenAL and you don't have to buy anything and it has a near identical API as OpenGL. DevMaster has great articles at the bottom of that link about how to load/play .ogg files. You can always convert .mp3 to .ogg (I think .ogg is a better format anyways but that's just me).
Best of luck.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement