Windows10 version 20H2.
I followed every step-Getting started with XAudio2-How to: Initialize XAudio2.
The link is here. https://learn.microsoft.com/en-us/windows/win32/xaudio2/getting-started
The code worked before the update. But now when I try to do something like this:
pXAudio2->CreateSourceVoice( &pSourceVoice, (WAVEFORMATEX*)&wfx )
It is said the value of pSourceVoice is nullptr.
I'm sure I have done all these code down here.
Microsoft::WRL::ComPtr<IXAudio2> XAudio2;
HRESULT hr;
if ( FAILED(hr = XAudio2Create( &XAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR ) ) )
throw Platform::Exception::CreateException(hr);
IXAudio2MasteringVoice* pMasterVoice = nullptr;
if ( FAILED(hr = pXAudio2->CreateMasteringVoice( &pMasterVoice ) ) )
return hr;
Is there anything I can do now?
The problem here seemed to be a mix of legacy DirectX SDK and newer Windows SDK headers in the build environment.
XAudio2 is fully supported on Windows 20H2 including it's various version.
Legacy XAudio 2.7 from the end-of-life DirectX SDK runs fine, as do all the legacy games and samples that use it. It is not part of the operating system and has to be installed via the legacy DirectX End-User Runtime package. See Not So DirectSetup. DO NOT attempt to use the legacy DirectX SDK headers/libs to build UWP apps as they are not supported.
XAudio 2.8 and XAudio 2.9 are both built into the operating system, so these versions both work as well. These require using the headers from the Windows 8.x SDK and/or Windows 10 SDK. You must also set _WINNT_WIN32
to 0x0602
(Windows 8), 0x0603
(Windows 8.1), or 0x0A00
(Windows 10) or these headers will error out. See this blog post.
If targeting Windows 10 only for Win32 desktop or UWP apps--or Xbox One/S/X and Xbox Series X/S development--use XAudio 2.9 which is built into the operating system.
If targeting Windows 7 SP1 or later, use the XAudio2Redist package which provides full XAudio 2.9 support with a simple side-by-side redist. This does not require the use of legacy DXSDK or DXSETUP.
If targeting Windows 8 or later, you can use XAudio 2.8 built in or XAudio2Redist if you want XAudio 2.9 for the xWMA support.
See also Where is the DirectX SDK (2021 Edition)?
If you are new to XAudio2, you should take a look at DirectX Tool Kit for Audio which is included in both the DirectX 11 and DirectX 12 packages. It's an open source, lightweight audio library that uses XAudio2 and X3DAudio. It implements one-shot sounds, positional audio with optional reverb, voice-management, streaming audio, and wavebanks. It supports PCM, ADPCM, xWMA, and XMA2 (Xbox only) data. See this blog post.