-
Notifications
You must be signed in to change notification settings - Fork 511
Using positional audio
This lesson covers the playing sounds with DirectX Tool Kit for Audio using 3D positional audio effects.
First create a new project. For this lesson, use the DeviceResources variant described in Using DeviceResources, then use the instructions in Adding the DirectX Tool Kit, then Adding the DirectX Tool Kit for Audio, and finally Adding audio to your project which we will use for this lesson.
Games provide an immersive visual and audio experience, and often use 3D audio effects to enhance the audio. The effect modifies the speaker position, pitch, and volume of a sound to provide audial cues to place it in the 3D environment. XAudio2 itself provides the ability to specify a complex per-channel volume mapping, pitch modification, and other parameters to generate these 3D effects, but does not perform the computations. The X3DAudio library is used by DirectX Tool Kit for Audio to compute the virtual placement of the sound.
See Microsoft Docs for more information on X3DAudio.
Save the this file to your new project's folder: heli.wav. Use the top menu and select Project / Add Existing Item.... Select the heli.wav
file and hit "OK".
In the Game.h file, add the following variables to the bottom of the Game class's private declarations:
std::unique_ptr<DirectX::SoundEffect> m_soundEffect;
In Game.cpp, add to the end of Initialize:
m_soundEffect = std::make_unique<SoundEffect>( m_audEngine.get(), L"heli.wav" );
Build and run. No sounds will be heard, but the audio file is loaded.
Troubleshooting: If you get a runtime exception, then you may have the
.wav
file in the wrong folder, have modified the "Working Directory" in the "Debugging" configuration settings, or otherwise changed the expected paths at runtime of the application. You should set a break-point onstd::make_unique<SoundEffect>
and step into the code to find the exact problem.
UNDER CONSTRUCTION
DirectX Tool Kit docs AudioListener, AudioEmitter, SoundEffectInstance
XAudio2Sound3D, SimplePlay3DSoundUWP samples
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
- Windows 7 Service Pack 1
- Xbox One
- x86
- x64
- ARM64
- Visual Studio 2022
- Visual Studio 2019 (16.11)
- clang/LLVM v12 - v18
- MinGW 12.2, 13.2
- CMake 3.20