Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which API should I use for playing audio on Windows? [closed]

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
like image 809
Jader Dias Avatar asked Oct 25 '10 23:10

Jader Dias


People also ask

What is audio device API?

The Core Audio APIs are: Multimedia Device (MMDevice) API. Clients use this API to enumerate the audio endpoint devices in the system. Windows Audio Session API (WASAPI). Clients use this API to create and manage audio streams to and from audio endpoint devices.

What does Web Audio API do?

The Web Audio API provides a powerful and versatile system for controlling audio on the Web, allowing developers to choose audio sources, add effects to audio, create audio visualizations, apply spatial effects (such as panning) and much more.

What is Wasapi exclusive mode?

WASAPI gives two options for audio rendering - Shared mode and Exclusive mode. In exclusive mode, you are the only application talking to the audio endpoint in question - all other applications cannot make any noise.

How do I run a program in exclusive mode?

To enable applications to use the device in exclusive mode, check the box labeled Allow applications to take exclusive control of this device. To disable exclusive-mode use of the device, clear the check box.


2 Answers

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.

like image 187
Michael Aaron Safyan Avatar answered Nov 15 '22 13:11

Michael Aaron Safyan


Really depends on what you want to do. For most common scenarios, I've found that the MCIWnd functions work well: they're really easy to use and can play any format for which a codec is installed.

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

The waveOut functions are the lowest level API you can get to and they are a kind of double-edged sword: you get to control exactly what goes out to the speakers, but they accept only 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.

like image 20
casablanca Avatar answered Nov 15 '22 13:11

casablanca