Generate sound in C++?

Hey there,

I'm new to the forum, but not to the site, I've been using it for 2 years now, and so far all my questions were answered by just searching old topics. This one in special I just couldn't find any good help so far.

I need to write a program which will take an input string and, reading each char of the string, will generate a sound (like music notes: do, re, me, fa, so...). I've looked over some libraries but not many have really helped me, and Csound I just couldn't understand :(

I have tried the Beep() function, but the output isn't exaclty what I need.

That's why I'm here, I was wondering if any of you know a good library or API for generating sounds. Something like with and input of frequency, or the note itself (a string "re"), and the output being the "hearable" sound.
If are you on Windows, you should use the DirectX sound integration.
Oh, sorry, I forgot to say this: I'm on Windows, and the program does not need to be crossplatform.

EDIT: DirectX seems complicated, and if I had more time I would certanly study it, though this is for a college work and my time is really small.
The teacher has suggested using Javasound (for those programming in Java). If there is anything like that for C++, that's what I'm looking for.
Last edited on
SDL is simple enough to use, but you'll have to generate the tones manually.
sndPlaySound()
or PlaySound() in windows. The file must be a .wav or possibly a .mp3 to work. As for sounds based on raw data values, I know of OpenAL. BUT that is more complex.
Last edited on
PlaySound() in WINAPI would definitely be the easiest. If you need to synthesize the sounds yourself, then you can use the waveOut API (WINAPI also).
Sorry I'm late to the party.

If you're looking for a lib that allows you do say things like "play a C tone followed by a D# tone" etc... your best bet is some kind of MIDI creation lib. You won't find anything like that in a traditional audio lib because audio output typically doesn't work that way.

I don't know anything about existing MIDI libs or how to use them, so I can't help you there.


But if you want to generate the audio data yourself... that certainly can be done, but it is non-trivial. Believe it or not, someone asked this exact question before and I gave them a pretty detailed walkthrough on how it could be done:

http://www.cplusplus.com/forum/general/109119/
Topic archived. No new replies allowed.