• Advertisement
Sign in to follow this  

How to play MP3? OpenGL and DirectX

This topic is 4312 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
FMOD has the capability to decode and play mp3s, though you're on your own when it comes to licensing.

Share this post


Link to post
Share on other sites
If you want cross-platform, go with something like SDL_mixer: http://www.libsdl.org/projects/SDL_mixer/

Share this post


Link to post
Share on other sites
If you are already using OpenGL for rendering, you'd probably want the similar interface for sound named OpenAL.

Share this post


Link to post
Share on other sites
The GL in OpenGL stands for Graphics Library. You can't play sounds with it.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
Quote:
Original post by V-man
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.


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.

Share this post


Link to post
Share on other sites
If you are selling / shipping anything which decodes mp3, you DO have to buy it ... mp3 is a patented technology, hence the reason why MS bothered to make WMA, apple made AAC (although that also had some other reasons) and the free speech community made Ogg Vorbis.

Share this post


Link to post
Share on other sites
I'm assuming you are using a windows platform. If you don't go the DirectShow route, there are a couple of libraries that will decode an MP3 into a buffer for you to push to your sound card (again assuming you have buffers for that up and running).

Here are some libraries which can decode MP3: (Yeah Google!)

FFMPEG http://ffmpeg.sourceforge.net/index.php
MAD http://www.underbit.com/products/mad/
FMOD http://www.fmod.org/
BASS http://www.un4seen.com/

They differ in licensening and ease of use. I like FFMPEG, but thats the one that use (for linux) so I can't speak about the others.


Cheers,

Bob

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement