Making sound in windows

Is there a function that is somewhere between playsound() and Beep()?

I'm wanting a function that you can output a sound without causing a lag in message loops, but generates the noise that you code for like beep does. (so you don't need to include a sound file to your program for download/install)

Or maybe a way to create a sound file through code alone...

Is there anything like a device context for audio?
Last edited on
closed account (Dy7SLyTq)
so, while i am new to windows programming, i think i have a solution. so if the problem is the sound itself stops everything else, you can run it in a thread
I know there is a beep for the win API
Yes, but they're not as easy to use.

Look up the 'waveOut' series of functions (waveOutOpen, waveOutWrite, etc)

Making a separate thread is certainly another option... but ew.
closed account (Dy7SLyTq)
or... or... now just think it over... cout<< '\a';
Just to reiterate / clarify:


Or maybe a way to create a sound file through code alone...

Is there anything like a device context for audio?


What you're describing is PCM streaming. You generate the audio samples yourself in code and stream them out to the user.

As I previously mentioned, this can be done with the waveOut series of functions. Another option is going with other libs like OpenAL, BASS, Fmod, or one of the countless others.


But if all you want to do is load a single file and play it without blocking... you can still use PlaySound. Just specify the non-blocking option, SND_ASYNC:

 
PlaySoundA( "path/to/your/file", nullptr, SND_FILENAME | SND_ASYNC );
Topic archived. No new replies allowed.