How to play MP3? OpenGL and DirectX

Started by
11 comments, last by Scourage 18 years ago
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!
Project4Hire.com - Find Freelance Game Developers and Graphic Designers for all your project needs
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.
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/
deathkrushPS3/Xbox360 Graphics Programmer, Mass Media.Completed Projects: Stuntman Ignition (PS3), Saints Row 2 (PS3), Darksiders(PS3, 360)
If you are already using OpenGL for rendering, you'd probably want the similar interface for sound named OpenAL.
Killers don't end up in jailThey end up on a high-score!
The GL in OpenGL stands for Graphics Library. You can't play sounds with it.
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.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
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 :)
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.

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

This site should help get you going: http://www.fmod.org/

This topic is closed to new replies.

Advertisement