Play a sound file or a simple beep from C++

May 30, 2010 at 11:09am
Hello!

I have read all these posts about sounds, but no one answered my questions.

Please note, that I do not want to complicate me with operating systems, and so on. If that is possible, I want to write a platform independent program in C++.

Please answer this short questions, do not send me to other sites. Please always specify any required #include commands.

Question A.
How can I play a simple beep?

Question B.
How can I play a .vaw file?
Last edited on May 30, 2010 at 11:09am
May 30, 2010 at 11:11am
Answers:

Any attempt to play a sound is OS-dependant, so the answers you have found so far are as good as it gets.

Don't instruct us. We'll volunteer any answer you get.
May 30, 2010 at 11:30am
Question A:
1
2
3
4
5
6
7
8
9
#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world!\7" << endl;
    return 0;
}


Question B:
Use other libraries like SDL
May 30, 2010 at 11:48am
There is a \ command for making a beep through the console i believe...

Edit: Try \a
Last edited on May 30, 2010 at 11:52am
May 30, 2010 at 5:53pm
blackcoder41, thank you!

It works, and I don't need anything else for the moment.

I am running a program in the background (it takes 10-20 minutes to finish), and I just need a sound when it has finished.
Last edited on May 30, 2010 at 5:53pm
May 30, 2010 at 5:57pm
The '\a' and '\7' escapes won't just not work on all operating systems, they won't even work on all terminal emulators. There's literally no way of producing a beep in an os-independant way except by accessing the PC speaker directly (which isn't pretty, not to mention that most operating systems won't let you do it).
May 30, 2010 at 6:19pm
The best way to play a beep or any other sound is to use a cross-platform audio or multimedia library, like SFML or SDL. Indeed, the \a, \7, and \b escapes don't work across all platforms or across all terminal emulators, so you need an alternative.

You requested that we don't send you to other sites, but I'm going to ignore that and give you a link to the SFML site. It's a really easy to use and quite good library and I am NOT part of the dev team.

http://www.sfml-dev.org/

-Albatross

May 30, 2010 at 6:34pm
I think ignoring it is justified given that it wasn't so much a request as a demand.
Topic archived. No new replies allowed.