Skip to content

Adding the DirectX Tool Kit for Audio

Chuck Walbourn edited this page Mar 26, 2025 · 61 revisions
Getting Started for DX11 Getting Started for DX12

This lesson covers adding the DirectX Tool Kit for Audio library and headers to your project.

Setup

First create a new project using the instructions from the earlier lessons: Using DeviceResources and Adding the DirectX Tool Kit which we will use for this lesson.

If using DirectX Tool Kit for DX12, use Using DeviceResources and Adding the DirectX Tool Kit. In this case, the only thing to do in this lesson is adding #include <Audio.h> and #define _USE_MATH_DEFINES to pch.h.

NuGet package manager

If you used NuGet when Adding the DirectX Tool Kit, then you already have support for DirectX Tool Kit for Audio..

directxtk_desktop_2019 This package is configured for Windows 8.1, and makes use of XAudio 2.8 for DirectX Tool Kit for Audio.
directxtk_desktop_win10
directxtk_uwp
directxtk12_uwp
directxtk12_desktop_2019
directxtk12_desktop_win10
These packages are configured for Windows 10 and Windows 11, and makes use of XAudio 2.9 for DirectX Tool Kit for Audio.

Complete the steps in Adding the headers below including the additional configuration for XAudio2 Redistributable or XAudio 2.9.

CMake projects

The DirectX Tool Kit CMake projects have a build option for different XAudio2 versions. The vcpkg port for directxtk includes three different features: [xaudio2redist], [xaudio2-9], and [xaudio2-8]. See this page for details.

Click here for troubleshooting advice

If using the MinGW toolset, you will likely get unresolved link errors for KSCATEGORY_AUDIO. You should explicitly link to ksguid.lib to fix this.

Adding the headers

Now that we have the DirectX Tool Kit for Audio usable in your project, the next step is to include the library header into your project. You should also make sure _USE_MATH_DEFINES is set before any header includes math.h or cmath since XAudio2 headers require values like _M_PI to be defined.

//
// pch.h
// Header for standard system include files.
//

#pragma once

// Make sure math.h defines M_PI
#define _USE_MATH_DEFINES

...

#include "Audio.h"

...

XAudio 2.9

For a desktop application that requires Windows 10 or Windows 11, in your pch.h modify the following section:

#include <winsdkver.h>
#define _WIN32_WINNT 0x0A00
#include <sdkddkver.h>

For Windows 10 / Windows 11 platforms other than Windows desktop, you do not need to explicitly set _WIN32_WINNT as it's already set appropriately.

XAudio 2.8

If you are using XAudio 2.8, then your application should be built to require Windows 8.1 or later. In pch.h modify the following section:

#include <winsdkver.h>
#define _WIN32_WINNT 0x0603
#include <sdkddkver.h>
Click here for troubleshooting advice

If you get a compilation error related to DirectX SDK headers, then you likely don't have the Microsoft.XAudio2.Redist NuGet package set up for the project that is using Audio.h

If you get runtime errors related to not being able to find XAUDIO2_9REDIST.DLL, then you likely don't have the Microsoft.XAudio2.Redist NuGet package set up for the project that generates the EXE, or you need to include that DLL from the NuGet package in your installer/deployment.

Deployment

If you are using XAudio 2.8, then your application has a dependency on Windows 8 or later. If using XAudio 2.9, your application will only run on Windows 10 or Windows 11 devices.

If you are using the XAudio2 Redistributable, then you will need to include the XAUDIO2_9REDIST.DLL from the NuGet package as part of your application.

Next lesson: Adding audio to your project

Further reading

DirectX Tool Kit docs Audio

DirectX Tool Kit for Audio

XAudio2 and Windows 8

Twilight for Windows 7

For Use

  • Universal Windows Platform apps
  • Windows desktop apps
  • Windows 11
  • Windows 10
  • Windows 8.1
  • Xbox One

Architecture

  • x86
  • x64
  • ARM64

For Development

  • Visual Studio 2022
  • Visual Studio 2019 (16.11)
  • clang/LLVM v12 - v19
  • MinGW 12.2, 13.2
  • CMake 3.20

Related Projects

DirectX Tool Kit for DirectX 12

DirectXMesh

DirectXTex

DirectXMath

Win2D

Tools

Test Suite

Model Viewer

Content Exporter

DxCapsViewer

Clone this wiki locally