Advertisement

Sound in Windows Text Game

Started by October 04, 2014 06:32 PM
5 comments, last by SyncViews 10 years, 3 months ago

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!

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.

Advertisement

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.

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.

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.

"The code you write when you learn a new language is shit.
You either already know that and you are wise, or you don’t realize it for many years and you are an idiot. Either way, your learning code is objectively shit." - L. Spiro

"This is called programming. The art of typing shit into an editor/IDE is not programming, it's basically data entry. The part that makes a programmer a programmer is their problem solving skills." - Serapth

"The 'friend' relationship in c++ is the tightest coupling you can give two objects. Friends can reach out and touch your privates." - frob

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.

Advertisement

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.

This topic is closed to new replies.

Advertisement