home github email bird of the day (site last updated on 10/29/21)

Playing audio with XAudio2 and Mingw-w64

posted on 7/8/18

Playing audio using XAudio2 in a very minimal Win32 environment posed more of a challenge than I expected. After finally getting something working I put together a simple project demonstration which you can find here

Since I wanted to figure this out using Mingw-w64 there wasn't much material out there on the web at all. One of the biggest problems I faced was not using the correct XAudio2 header with the compiler supplied XAudio2.8 library due to my own negligence haha. I was using an old one(v2.7) from the DirectX 10 SDK but I ended up locating the correct header that is included in the Windows 8.1 SDK. Which is apart of Visual Studio 2017. Now the header unfortunately wasn't compiling nicely with Mingw-w64 but after a couple very, very minor adjustments it compiled fine. I might get yelled at but I included the modified XAudio2.h header file in the demo project. Also there is a small memmem implementation I found the suited my needs for easily locating a byte sequence in a data buffer.

Quick note - you may be thinking why did I not just use the included XAudio2.h header that comes with Mingw-w64? Well as of this writing, it currently does not. It only includes the library. So in the future when Mingw-w64 includes the missing XAudio2.h header then the build process will be easier.

Here are the adjustments I made to the Windows 8.1 SDK XAudio2.h file:

The demo project is loading a ADPCM encoded, 512 samples per block, 8bit unsigned WAV file from resource but it could easily be adapted to load an audio file from disk. Here's a good example

The tool I used to encode the WAV file is called AdpcmEncode and more info about it can be found here

go back