Jump to content
  • Advertisement
Sign in to follow this  
JonathanCCC

Sound in Windows Text Game

This topic is 1411 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 have a couple of completed Text based (console app) role playing games. Compiled on Windows for Windows only.

 

I want to be able to add background music to loop while the game is running. Either in a wav or mp3. I think I have asked this before a while ago but couldn't really get anything to work. Which gives me the impression this is not as simple as it should be!!?

 

I basically want to bundle the .exe with an mp3 or wav file which the game plays on launch (always checking for the music file in the same directory)

 

How can I achieve this for Windows use only? EDIT: game is in C++11

 

Thanks!

Edited by JonathanCCC

Share this post


Link to post
Share on other sites
Advertisement

Use a sound library.

 

Learning the library will be a hump, but implementation should be trivial after that.

 

irrKlang is popular, but I haven't worked very much with sound and I haven't touched irrlicht in years, so maybe somebody else can give you a better suggestion for a library (or confirm that irrKlang is a good way to go).  My guess is it might be a bit heavy, but it should be well documented, and it's free.

Share this post


Link to post
Share on other sites

If it's just for looping 1 background music in a very simple app I would not go through the hassle of setting up a sound library as it's a bit of overkill. I would simply use winmm's PlaySound() function.

Share this post


Link to post
Share on other sites

If it's just for looping 1 background music in a very simple app I would not go through the hassle of setting up a sound library as it's a bit of overkill. I would simply use winmm's PlaySound() function.

 

Good point.  Doesn't that only play .wav though?

 

Although I guess he meant that he's happy using only wav or only mp3, and not that he needs the flexibility to play either wav or mp3.

Share this post


Link to post
Share on other sites

I have never tried to use sound in this context, but if you want a "Windows only" solution, just use "DirectSound."  I am pretty sure this will work.  The libraries will decode and play and sound format that 'Windows Media Player' can play.

 

EDIT: Most of the multi-platform libraries are going to wrap "DirectSound" for Windows decoding/playback anyways.

Edited by ByteTroll

Share this post


Link to post
Share on other sites

Thanks for the suggestions. I am trying the simple PlaySound() function. Though I'm having trouble getting it to work and not sure how to declare that function.

 

I've looked at this:

 

http://msdn.microsoft.com/en-gb/library/windows/desktop/dd743680%28v=vs.85%29.aspx

 

and it says - The following example plays a sound file:

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

so I have put my wav file in the same folder as the executable, replaced the "recycle" with my sound file name. But of course when I compile it says PlaySoundA@12 is an undefined reference.

 

I don't understand how to use this function.

Share this post


Link to post
Share on other sites

 

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Mmsystem.h (include Windows.h)

Library

Winmm.lib

DLL

Winmm.dll

 

I don't know what compiler your using but if you got that far you must have the windows SDK. So you just need to also tell it to use that library as listed in the docs.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!