Jump to content
  • Advertisement
Sign in to follow this  
EDEV

I've wasted 5 hours trying to figure out how to implement sound in my C++ program.

This topic is 2595 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

Hello, I've been using C++ these past few days, and I've been learning a lot and having fun. Right now I'm making small short games to test what I've learned so far. I want to play a song in one of my games...but I cannot figure out FOR THE LIFE OF ME, how to include/tie/associate libraries/headers so that the code will run. Right now I'm using Dev++, I've tried EVERYTHING, I've used devpaks, copied files into the include and lib folders...added libraries manually. Everytime I copy/paste some example code that should play a sound, I get linker errors and other errors out the wazoo. Is there a resource that will show me.

1. How to include files needed to get libraries to work/run on my compiler?
2. A VERY BASIC tutorial on how to get sound working with any library? The less calls/work I have to do the better. I just want something simple...playing a sound in my program. I figured out how to do this in VB in 10 minutes....5 hours in C++ has gotten me nowhere and its extremely discouraging.

Any help is VERY appreciated!

Share this post


Link to post
Share on other sites
Advertisement
Windows 7, file is .mp3/.wav, but I can transfer to any other format.

My first and biggest problem is Dev++ won't find/utilize any of the libraries, so when I use functions/code from examples, they don't compile they just give me errors.

Share this post


Link to post
Share on other sites
EDIT: Actually, I forgot to ask first, are you using some kind of external libraries? I don't mean source code, I mean things that maybe end in .a or .so or something like that.

I believe when you add external libraries to your project, you have to add them as arguments to your linker. Somewhere in your project settings you should have an option for additional arguments to pass to the linker where you'll have to add a line that resembles more or less: "-l<libraryName>" (obviously replacing <libraryName> with the actual name). What library are you using exactly?

DevC++ is an uber old IDE, unmaintained, and very buggy at that, so switching to something more modern will probably save you a whole lot of pain later on.
Learning to program with C++ can indeed be discouraging :D That's why people on the forums usually recommend something like C#, Python, or Java for people who are getting started.

Also,

Share this post


Link to post
Share on other sites
Your right about the IDE being old, its just the book I was using to follow along use this IDE. I'm going to us MS VC++, the code should just port over no problems, and I will see if I can get the libraries working from there.

Share this post


Link to post
Share on other sites
I have to strongly second boogymans' suggestion, DevC++ is probably making your life more difficult than it needs to be. If you are intending to stick with C++ I would download Visual C++ Express 2010 which is completely free. Less bugs, better documentation and easier to get support from.

Now given its win32 and you are trying to play a WAV the Win32 function PlaySound() is about as easy as it gets.

It looks complicated, but in reality boils down to:

PlaySound(TEXT("yourfile.wav"), NULL, SND_FILENAME);

[font=Arial]Just be sure to include winmm.lib in your libraries.[/font]

[font="Arial"]First though, download VS2K10, it really will make your life a ton easier. [/font]

Share this post


Link to post
Share on other sites
Wait so Visual C++ has a native call that I can use to play sound? No libraries involved? That's awesome!!!

2nd, whats VS2K10?

(In the midst of installing Visual C++ now)

Share this post


Link to post
Share on other sites
/* Scratch this part, Serapth probably knows better than I do */. It's from the win32 API which is probably what you're using now. As Serapth mentioned, you'll have to add winmm.lib to the list of libraries.

VS2K10 stands for Visual Studio 2010

Share this post


Link to post
Share on other sites

Wait so Visual C++ has a native call that I can use to play sound? No libraries involved? That's awesome!!!

2nd, whats VS2K10?

(In the midst of installing Visual C++ now)


VS2K10 == VIsual Studio 2010 written by a lazy person. You are installing what I want you to.

As to Visual C++ having a native call, thats right but misleading. It's actually part of the WIN32 API. It's a small grammatically distinction but it is an important one. For example, you could have actually called PlaySound just as effectively from DevC++ assuming you were targeting windows. It has nothing at all to do with Visual C++. Make sense?

Share this post


Link to post
Share on other sites
Ok I installed it and got it running, I copied my code over, but I can't find where I go to run/test the code?

EDIT: Is it debug? The option to debug is greyed out so...I'm not sure...maybe theres something I gotta add to my code first?

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!