Which API should I use to play sound on Windows?

There are many ways to play sounds in Windows. What are the differences, advantages and disadvantages of each method?

I know that there are at least 5 methods:

+5
source share
2 answers

It really depends on what you want to do. For most common scenarios, I found that MCIWnd functions work well: they are very easy to use and can play any format for which the codec is.

DirectSound is somewhat more difficult to use, but gives you more control over the output; It allows you to add special effects and simulate 3D positioning.

The waveOut functions are the lowest level API you can reach, and they are a kind of double-edged sword: you can precisely control what happens with the speakers, but they only accept raw waveform data, which means you are responsible for all decoding and post processing of input data. PlaySound essentially provides a nice wrapper around this.

+1
source

QSound , it will fit all of your other Qt applications, and it will work not only on Windows, but also on Mac OS X and Linux. You can often find a kernel specific to an API platform that is not very friendly to developers, and then many more API-friendly kernel-based APIs. Using a basic API can be negligible, but using layers on top of these cells makes the API almost always more convenient and easy to maintain and protects you from changes in the low-level kernel.

Edit
From the description of XAudio2 :

XAudio2 is a low-level, cross-platform audio API for Microsoft Windows and the Xbox 360. It provides signal processing and mixing for games similar to its predecessors, DirectSound and XAudio. For game developers, Windows XAudio2 is the long-awaited replacement for DirectSound.

So, it looks like it will be an API to be used if you want to use a basic, platform-based audio library.

Edit 2
I was a little quick with my first answer ... really, it depends on what you want to do. If all you want to do is play the audio file, then QSound is the way to go. If, however, you want to mix and generate audio on the fly, then using a more functional library such as XAudio2 (which is part of DirectX and is designed to create sound as part of video games) will be the way to go.

+5
source

All Articles