Which API should I use for playing audio on Windows?

Jader Dias picture Jader Dias · Oct 26, 2010 · Viewed 7.5k times · Source

There are many ways of playing sounds on Windows. Which are the differences, advantages and disavantages of each method?

I know there are at least 5 methods:

  1. 1991 WinMM.dll/mmsys.dll PlaySound
  2. 1995 MCIWnd (as suggested by @casablanca)
  3. 1996 DirectSound
  4. 1998 WaveOut
  5. 1999 ASIO
  6. 1999 Windows Media Player ActiveX control?
  7. 2005 WASAPI (which is used by XAudio2 - as suggested by @Han)
  8. 2007 XAudio2

Answer

Michael Aaron Safyan picture Michael Aaron Safyan · Oct 26, 2010

QSound, then it will fit right in with the rest of your Qt application, and it will work not only on Windows but also on Mac OS X and Linux, as well. It is not uncommon to find a core, platform-specific API that isn't very friendly to developers, and then a myriad of more developer friendly APIs built on top of the core. Using a core API may be negligibly faster, but using the layers on top of these core APIs is almost always more convenient and maintainable, and protects you from changes to the low-level core.

Edit
From the description of XAudio2:

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

So, it looks like that would be the API to use if you want a core, platform-specific 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 an 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 feature-capable library such as XAudio2 (which is a part of DirectX and is intended for creating sound as part of video games) would be the way to go.