Simple sounds in C++

Hi everyone,
I want to make some kind of simple sound playing program. I tried with the Windows Beep() function which lets you specify which note you want to play and for how long. This works fine, but you can only play one note at a time. So I wrote a multithreaded program, but it seems threads don't guarantee that the notes are played simultaneously. I figured this out too late and now I have to remake my whole program... I searched the net but C++ doesn't have a sound library. Is there a way of playing multiple notes simultaneously? Only the Hz of the note is necessary, a simple Beep()-like sine wave is enough, I don't need prerecorded piano notes of something similar, It just has to be able to play specified notes.
I'm using Windows vista and Orwell Dev-C++, if that matters.

Please help,
Niels Meijer
closed account (o3hC5Di1)
Hi there Niels,

As far as I'm aware that's not possible using out-of-the-box C++.
Your best bet might be to use a MIDI library.

MS MSDN wrote:
Beep() Generates simple tones on the speaker. The function is synchronous; it performs an alertable wait and does not return control to its caller until the sound finishes.


Here are some things I found online:

http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/63e8ec14-bd11-4a91-aaf0-87fc68ffc2b2/
http://www.gamedev.net/blog/1389/entry-2254176-playing-simultaneous-sounds-in-win32/

Hope any of that helps.

All the best,
NwN
Last edited on
Thanks for the tips NwN! I'm sorry I responded so late, I was trying to make a function with Beep() which tried to play every note of an accord for one millisecond after which it switched to the next note, but that seems to affect the frequency of the notes and thus making the whole accord sound like a chainsaw... Setting the duration to a higher rate doesn't help.

I actually considered a MIDI-library long ago, but I decided not to for whatever reason...

Your links and a quick search gave me the name portAudio which mentions sinewaves and perhaps also supports MIDI.

Thanks for your reply!

Niels Meijer
Topic archived. No new replies allowed.