-
Notifications
You must be signed in to change notification settings - Fork 528
Adding the DirectX Tool Kit for Audio
This lesson covers adding DirectX Tool Kit for Audio to your project.
After creating a new project in the The basic game loop or Using DeviceResources, then Adding the DirectX Tool Kit for this lesson.
If you used NuGet when Adding the DirectX Tool Kit, then you already have support for DirectX Tool Kit for Audio..
directxtk_desktop_2017 | This package is configured for Windows 7 Service Pack 1 support for graphics & input. DirectX Tool Kit for Audio is configured to use the XAudio2Redist NuGet package to support Windows 7 or later. |
directxtk_desktop_win10 directxtk_uwp directxtk12_uwp directxtk12_desktop_2017 |
These packages are configured for Windows 10 support for graphics, input, and make 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.
If you used project-to-project references when Adding the DirectX Tool Kit, then you need to add an additional DirectX Tool Kit for Audio project to your solution. There are four (4) choices depending on your platform target and deployment requirements:
XAudio 2.9 is built into Windows 10. Everything required is included in the operating system and the Windows 10 SDK. This version of DirectX Tool Kit for Audio is already included in those projects (DirectXTK*_Windows10_201x.vcxproj
, DirectXTK*_Desktop_201x_Win10.vcxproj
) and Xbox One (DirectXTK*_XboxOneXDK_201x.vcxproj
).
Complete the steps in Adding the headers below including the additional configuration for XAudio 2.9.
XAudio 2.8 is built into Windows 8.0 or later. Everything required is included in the operating system and the Windows 10 SDK.
- Right-click on your solution in the Solution Explorer, and select Add / Existing Project...
- Browse into the "DirectXTK\Audio" folder and select
DirectXTKAudio_Desktop_201x_Win8.vcxproj
, click "Open" - If Visual Studio presents a "Security Warning", select "OK". Optional: Uncheck "Ask me for every project in this solution" first.
- Right-click on your project in the Solution Explorer, and select Add / References...
- Check
DirectXTKAudio_Desktop_201x_Win8.vcxproj
and select "OK" - Select "OK"
Complete the steps in Adding the headers below including the additional configuration for XAudio 2.8.
XAudio 2.8 does not support xWMA
There is an XAudio 2.9 redistributable package available on NuGet that supports Windows 7 SP1, Windows 8, Windows 8.1, and Windows 10 for Win32 desktop applications. The required runtime DLL is included side-by-side with your application, and avoids the need to include any legacy DirectX SDK redist package.
- Right-click on your solution in the Solution Explorer, and select Add / Existing Project...
- Browse into the "DirectXTK\Audio" folder and select
DirectXTKAudio_Desktop_201x_Win7.vcxproj
, click "Open" - If Visual Studio presents a "Security Warning", select "OK". Optional: Uncheck "Ask me for every project in this solution" first.
- Right-click on your project in the Solution Explorer, and select Add / References...
- Check
DirectXTKAudio_Desktop_201x_Win7.vcxproj
and select "OK" - Select "OK"
In addition to the reference, you'll need to add the Microsoft.XAudio2.Redist
NuGet package to your project(s) to ensure you have the correct XAudio2 headers and link libraries for this option.
- From the drop-down menu, select Project / Manage NuGet Packages...
- Select "Browse" on the top tab, and make sure the Package source is set to "nuget.org"
- In the text search field type "XAudio2" and hit enter to search for the packages
- Select the package with the id Microsoft.XAudio2.Redist
- Select "Install"
- When finished, close the NuGet Manager
Complete the steps in Adding the headers below including the additional configuration for the XAudio2 Redistributable.
This is the preferred option for supporting XAudio2 on Windows 7, and is also a good choice if you want xWMA format support on Windows 8.x.
See Microsoft Docs.
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.
//
// pch.h
// Header for standard system include files.
//
#pragma once
...
#include "Audio.h"
...
For a desktop application that requires Windows 10, in your pch.h modify the following section:
#include <winsdkver.h>
#define _WIN32_WINNT 0x0A00
#include <sdkddkver.h>
For Windows 10 platforms other than Windows desktop, you do not need to explicitly set
_WIN32_WINNT
as it's already set appropriately.
If you are using XAudio 2.8, then your application should be built to require Windows 8.0 or later. In pch.h modify the following section:
#include <winsdkver.h>
#define _WIN32_WINNT 0x0602
#include <sdkddkver.h>
If you want to support Windows 7, be sure to verify _WIN32_WINT
is set to 0x0601
.
Troubleshooting: 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 usingAudio.h
Troubleshooting: If you get runtime errors related to not being able to find
XAUDIO2_9REDIST.DLL
, then you likely don't have theMicrosoft.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.
If you are using XAudio 2.8, then your application has a dependency on Windows 8.0 or later. If using XAudio 2.9, your application will only run on Windows 10 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
DirectX Tool Kit docs Audio
DirectX Tool Kit for Audio
XAudio2 and Windows 8
Twilight for Windows 7
All content and source code for this package are subject to the terms of the MIT License.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
- Universal Windows Platform apps
- Windows desktop apps
- Windows 11
- Windows 10
- Windows 8.1
- Xbox One
- x86
- x64
- ARM64
- Visual Studio 2022
- Visual Studio 2019 (16.11)
- clang/LLVM v12 - v20
- MinGW 12.2, 13.2
- CMake 3.21