# MP3s in C++ **SOLVED**

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

## Recommended Posts

Alright, I looked into libraries like FMod, but the price and legal information had me actually screaming. I would like to know how to implement .MP3s for my DirectX games, but I think I should dumb down the API fixation and see if I can do it in C++. I imagine a .DLL has to come in, but I have zero knowledge in the subject. That is, of DLLs, and anything related to sound. The only thing I know about DLLs is that there are different calling methods, and with sound... I can hear it. I am really a blank slate to this, and I do not want to be paying, what was it, 3 grand for an FMOD license or conforming to any license standards except my own. Besides, I need the practice. Is there novice reading out there? I don't even know what to look for, even on Google. I have the worst luck of finding stuff that loses me on Google. [Edited by - zyrolasting on November 15, 2008 10:15:52 PM]

##### Share on other sites
Quote:
 Original post by zyrolastingAlright, I looked into libraries like FMod, but the price and legal information had me actually screaming.I would like to know how to implement .MP3s for my DirectX games, but I think I should dumb down the API fixation and see if I can do it in C++.I imagine a .DLL has to come in, but I have zero knowledge in the subject.That is, of DLLs, and anything related to sound. The only thing I know about DLLs is that there are different calling methods, and with sound... I can hear it.I am really a blank slate to this, and I do not want to be paying, what was it, 3 grand for an FMOD license or conforming to any license standards except my own. Besides, I need the practice. Is there novice reading out there? I don't even know what to look for, even on Google. I have the worst luck of finding stuff that loses me on Google.
Do you really need MP3? If you're using DirectX, I believe you can use DirectShow, since that uses the MP3 decoder that comes with the OS.

If you're doing this to play e.g. game music, I'd recommend looking into Ogg Vorbis, which is free to use, has pretty much the same quality and compression as MP3, and is really simple to get working with DirectSound.

Aside from that, FMod is free if your app is free. If you want to make it shareware or more commercial, then you have to pay.

##### Share on other sites
Oh, good to know. I actually love Vorbis, It grew on me when messing with conversion tools. I figured MP3 was just easier to implement, given common usage with past engines. Anyway, does DirectShow have any truly notable differences from FMod I should worry about? Again, only interested in the basics: Play, Stop, Pause, Seek. I'm pretty sure I'm not going to shovel 3 grand for that. Not interested in free either; I Intend to get small projects floating around on the net for some green.

Actually... I'm a little confused in the variation of APIs here... I've Seen DirectSound, XAudio, FMOD, and now DirectShow. I've been getting some encouragement from documentation to choose XAudio over DirectSound but... Can I get a little background? I think I should choose the one that balances simplicity and efficiency given my scenario.

##### Share on other sites
Quote:
 Original post by zyrolastingOh, good to know. I actually love Vorbis, It grew on me when messing with conversion tools. I figured MP3 was just easier to implement, given common usage with past engines. Anyway, does DirectShow have any truly notable differences from FMod I should worry about? Again, only interested in the basics: Play, Stop, Pause, Seek. I'm pretty sure I'm not going to shovel 3 grand for that. Not interested in free either; I Intend to get small projects floating around on the net for some green.
As far as I know (Although I may be wrong), there's no open source or free MP3 decoders available, since MP3 has licensing restrictions on it. Personally, I've always found DirectShow a pain in the ass to deal with, and Ogg Vorbis (And FMod) extremely simple.

Quote:
 Original post by zyrolastingActually... I'm a little confused in the variation of APIs here... I've Seen DirectSound, XAudio, FMOD, and now DirectShow. I've been getting some encouragement from documentation to choose XAudio over DirectSound but... Can I get a little background? I think I should choose the one that balances simplicity and efficiency given my scenario.
I didn't mean to recommend DirectSound; it's just the only sound API I've implemented OGG streaming with.

There's been a few posts in the DirectX Forum about the various audio APIs, although the only one I can find immediately is This one.

##### Share on other sites
I would agree about using FMOD. I used it for a homework in my game design class using XNA.

##### Share on other sites
It's not that I didn't like the look of FMOD, I just prefer to use a sound API that gives me the freedom of use no matter my release. Judging from the link Steve sent me, apparently I would be dealing with extra work just to get something playing on a DirectX sound related API.

I guess I could sacrifice such time if I make a good wrapper code, but is it insanely difficult to make my own library of this? I severely doubt I could do it with my current experience, but it's just something I'd like to do at some point.

I guess if DirectX APIs have less restrictive license agreements, I'll go with them for now. I take it I would use DirectSound for streaming basic sounds, while DirectMusic (Another one I didn't know existed) would be used for background music/Ambient sound.

I hope there are some novice tutorials lying around.

##### Share on other sites
If it's on Windows, MP3 is included with Win32 api...

##### Share on other sites
Quote:
 Original post by george135If it's on Windows, MP3 is included with Win32 api...
Is it? What functions?

##### Share on other sites
After a search, came across this. Apparently MP3 could be converted to a WAV stream through some struct tweaking...

In case you were curious, Steve.

http://www.codeguru.com/forum/archive/index.php/t-370446.html

##### Share on other sites
Quote:
 Original post by zyrolastingAfter a search, came across this. Apparently MP3 could be converted to a WAV stream through some struct tweaking...In case you were curious, Steve.http://www.codeguru.com/forum/archive/index.php/t-370446.html
Ah cool, I see - that'll only work for playback though, there's no Win32 decoding functions. And the Win32 audio API isn't really that powerful. Still, if it works, it might be a quick alternative.

##### Share on other sites
Quote:
 Original post by Evil Steve... As far as I know (Although I may be wrong), there's no open source or free MP3 decoders available, since MP3 has licensing restrictions on it...

I though of LAME right away, but it is an encoder, not sure if it does decode as well behind the scenes.

There must be something as MP3 files are playable on Linux, no money involved, either way, I'd stick with ogg, vorbis and openal just to avoid any mp3 licensing costs.

##### Share on other sites
Quote:
 I though of LAME right away, but it is an encoder, not sure if it does decode as well behind the scenes.There must be something as MP3 files are playable on Linux, no money involved, either way, I'd stick with ogg, vorbis and openal just to avoid any mp3 licensing costs.

However, I think I should stress again that my goal is to program all this myself.
(I know I'm still an novice, I'm just setting a long-term here)
Should I finish a project, however small it might be, I do not want licensing issues on my back, since I'm horrible at the subject and have enough to concern my projects with as is.

While I use libraries like FMOD or LAME to be able to hear BGM while under development, what should I be required to know to be able to program sound playback myself, down to encoding? Again, I know NOTHING of the subject. It's important for me to know, but I do not know a starting point. Primarily, I'm looking for a tutorial. All I found were above my league, and I don't know what topic is the base ground.

##### Share on other sites
I'm also using Vorbis in my C++ projects. There's at least one audio library, Audiere, that I know is free to use (even in commercial projects), includes full source code, is portable to linux as well and does contain an MP3 decoder as well as Vorbis, Flac and Speex decoders.

Of course, I am not a lawyer and it might be that you still have to pay Fraunhofer Institute if you're actually decide to use MP3s in your game. So Vorbis ist probably a good idea. By the way, all Unreal Engine games seem to use it ;)

##### Share on other sites
Alright, Alright... Thanks, but I have all the recommendations I can handle.

Any info on actually writing some of these? I'll make my own extension if need be, I just want to one day, not have to rely on any of these libraries.

##### Share on other sites
Quote:
 Original post by zyrolastingAfter a search, came across this. Apparently MP3 could be converted to a WAV stream through some struct tweaking...In case you were curious, Steve.http://www.codeguru.com/forum/archive/index.php/t-370446.html

You don't need to convert MP3 on Win32.
Just play them with various MM apis.

##### Share on other sites
Quote:
 Original post by Evil SteveAs far as I know (Although I may be wrong), there's no open source or free MP3 decoders available, since MP3 has licensing restrictions on it. Personally, I've always found DirectShow a pain in the ass to deal with, and Ogg Vorbis (And FMod) extremely simple.

You are wrong. There is an excellent free software MP3 decoder out there.

##### Share on other sites
Quote:
 Original post by zyrolastingAlright, Alright... Thanks, but I have all the recommendations I can handle.Any info on actually writing some of these? I'll make my own extension if need be, I just want to one day, not have to rely on any of these libraries.

The Vorbis specification is here. Similar documentation exists for MP3, but you'll probably have to pay for it: the specification itself is ISO standard 11172-3, which is copyrighted and costs around US$200. There are also additional royalty fees for implementations of MP3, although a lot of projects (particularly open source ones) manage to slide under the legal radar. Note that unless you are or plan to become a digital signal processing expert, trying to implement a modern audio codec yourself probably isn't a very good use of your time. Expect to spend quite a while just learning the math and terminology. #### Share this post ##### Link to post ##### Share on other sites Quote:  The Vorbis specification is here. Similar documentation exists for MP3, but you'll probably have to pay for it: the specification itself is ISO standard 11172-3, which is copyrighted and costs around US$200. There are also additional royalty fees for implementations of MP3, although a lot of projects (particularly open source ones) manage to slide under the legal radar.Note that unless you are or plan to become a digital signal processing expert, trying to implement a modern audio codec yourself probably isn't a very good use of your time. Expect to spend quite a while just learning the math and terminology.

This is valuable info... So from what I'm hearing, Mp3 in itself is copyrighted, so I'd be forking money no matter the outcome, but OGG can be free for my commercial use, given I find either...

A. A freeware library,
or
B. Understand the process of streaming it myself?

Well, even so, I've been hit with extensive studies before. Are you sure that "digital signal processing expert" is appropriate to mention for my goal here? Granted, I know it will be difficult, but I just want the four basics: Play, Stop, Pause and Seek through code. I think I'll at least be able to accomplish this, even if I study for a few months. (At least, I hope) Thanks so much for the info!

##### Share on other sites
Quote:
 Original post by zyrolastingSo from what I'm hearing, Mp3 in itself is copyrighted

Anyway, I totally forgot about ffmpeg, it provides you with libraries to handle both video and audio, though they are a bit complex to use, IE: if you want to get raw streams to feed to the hardware directly, ffmpeg will do just that for you.