Author image

Minimal XAudio v2.8 Windows library


Difficulty:
2/5


A high performance minimal XAudio 2.8 based library developed from scratch. It is almost as low level as one can get in Windows; such is the nature of XAudio2. It is flexible and extensible.

XAudio2 delegates sounds to the WASAPI backend. You don't need multiple threads for each playing sound; these are managed internally by WASAPI which mixes & matches them internally as it best sees fit.

I used:

  • Windows x86_64, Microsoft Visual Studio
  • XAudio v2.8
  • X3DAudio

If you're on Windows 10 you can use XAudio v2.9 dll without much, if any, change.

If you'd prefer a more graphical approach, I have a QT audio player project.

Usage

SoundManager is a singleton audio instance.

There is a maximum number of sound channels, which I have hardcoded to 64. But make sure that your hardware sound card can also support this.

You can find examples in main.cpp of how to create and play sounds.

  1. Create sound object: Sound mySound{filePath, soundName, soundCategory = L""};
  2. Play it: mySound.play( volume = 1.0f );
  3. Stop it: mySound.stop()

You can optionally provide a sound category (known as submix voice) as the third argument in the constructor, for example “sfx”, “music”, “ambience” etc. You can have up to 8 submixes (experimental - it should be possible to use more).

Only .wav sounds are supported at the moment. I have no intention to support other audio formats at the time of this writing. Note that your .wav file should have 2 or more channels (Stereo) with 16 bits per sample. It is recommended that the samples per second be 48KHz (if this is not the case then the audio will sound accelerated or decelerated accordingly).

Todo

  • Sound looping
  • Sound pausing & continuing
  • Support more sample rates and configurations
  • X3dAudio plugin and port to 3d game engine - KeyEngine

Github

Github repository link.

Acknowledgements

All demo sounds are in the public domain from freesound.org


0 likes