I’m making a game in native vc++ (not .Net)
I’m looking for a way to play a noise (maybe 8 bit or something) through the real speakers (not internal). I know about PlaySound, but I don’t want to make my EXE big. I want to program the sound.
Is there an api way (kinda like Beep() ) but that plays through the real speakers?
Thanks
You mention that you know about
PlaySound. One of the it’s flags (SND_MEMORY) will allow you to play a WAVE that is already loaded into memory, i.e. a buffer that you have created yourself. As long as the buffer has the appropriate WAVE header, whatever you you put in there should play through the speakers.The header is a 44 byte block that is fairly straight forward
You’d set up your buffer with something similar to:
So you use it something like:
I’m assuming that you’re going to be using you generated sound for the lifetime of you app. If you aren’t, be careful with that
SND_ASYNCflag. That is, don’t go freeing the buffer directly after you call PlaySound (while it is still in use).MSDN PlaySound Docs
A page with more detail on the WAV header (OLD – not working now)
DirectX also supports playing audio from in-memory buffers and is a much more powerful API, but it maybe overkill for what you need to do 🙂