C++ - Sound in the Console?

anewhobby 101 Apr 01, 2012 at 05:36

Hi there… I am a newbie programmer and have been palying about … and written a small text based game that I think is pretty cool.. as in I did it and have a nice feelign when i watch it run as it is my first program that wasn’t like “sort an array” or w/e…

Anyway, I would like to place some sounds in the app just to jazz it up a but for my own ammusment…. and leanring… anyway… there is “playsound” and I got it working.. BUT I can not get it to play more than 1 file at a time… any ideas whatI would need to do that…

#include <iostream>
#include <windows.h>
#include <mmsystem.h>

using namespace std;

int main(){
    PlaySound(TEXT("music.wav"), NULL, SND_FILENAME | SND_ASYNC);
    PlaySound(TEXT("soundeffect.wav"), NULL, SND_FILENAME | SND_ASYNC);
    int test = 0;
    return 0;

Anyway, the music plays fine and the applicaitons runs fine with it running, but when a sound effect gose off the music stops.. now I did some searching and aparently you cna not do this with this playsound thing and they recommend all these other things liek directX sound mappers and stuff but it is all to advanced for me and I do not know how to get meaning form the small code snipits in the various threads.

With out taking it out of a consol application.. how you would guys add sound? All it needs is a music file that can loop when it is over and the ability to stop it. And be able to play 1 other sound at the same time (a short sound effect file)

Thanks in advance

(Sorry for my newness)

PS - I am looking at SFML at this very moment.

1 Reply

Please log in or register to post a reply.

geon 101 Apr 01, 2012 at 09:46

Sadly, this kind of stuff is always messy in C/C++. I’d recommend SDL, but getting that set up and linking properly isn’t always easy.