开发者

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

开发者 https://www.devze.com 2023-01-22 03:54 出处:网络
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this
Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 3 years ago.

Improve this question

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开发者_C百科 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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号