Audio Engine hanging a lot when loading

Sep 9, 2015 at 4:21 PM
I've got a game that was recently published using DirectX Took Kit for Windows Phone / Windows 8.1 / Windows 10 (

What I'm seeing a lot of is hanging when the audio engine is loading. Sometimes 8.1 phone users will report having to start the game multiple times before it actually will start. Sometimes even in the development environment the Windows 10 PC version will hang for nearly 10 seconds while the audio engine is trying to load. It will eventually load but after 10 seconds or more. I assume this is what causes the hang crash on the published version too. If I break during this hang time it shows there is nothing actually running, so nothing that I can trace. However it's definitely because of loading the audio engine because you can follow the code line by line with breaks until the audio engine loads, and then it never progresses.

I'm loading the audio engine the same/standard way it's done here. Nothing special. And again, this doesn't happen all the time, but more often on phones, and sometimes on PC.

I could be wrong about my assumptions on this, but any help on this one is appreciated. Has anybody else experienced this sort of thing?
Sep 9, 2015 at 7:47 PM
Are you using the 'default' audio device or enumerating them?
Sep 9, 2015 at 7:49 PM
I am not enumerating them, so the default device.
Sep 9, 2015 at 7:53 PM
I would try stepping through the audio engine init and see where it is blocking, or add OutputDebugStringA verbose output so you can track where it's getting stuck.

Does this happen with the Debug build ever or only Release?
Sep 9, 2015 at 8:26 PM
Edited Sep 9, 2015 at 8:49 PM
It does happen sometimes while debugging, yes. In those cases I might have to wait 10+ seconds for it load and continue execution.

Today, for example, I switched from speakers to some bluetooth headphones between debugging sessions. When I ran the program again the problem happened again. It would startup but not get past the loading of the audio engine. Upon pausing execution while it was hanging the only code running was external and there was nothing to show/debug.

However, this happens with or without the bluetooth headphones. That was just one example.
Sep 15, 2015 at 4:44 PM
Edited Sep 15, 2015 at 4:53 PM
As an update, the specific moment it hangs is:

in AudioEngine.cpp
    hr = xaudio2->CreateMasteringVoice( &mMasterVoice,
                                        (wfx) ? wfx->nChannels : XAUDIO2_DEFAULT_CHANNELS,
                                        (wfx) ? wfx->nSamplesPerSec : XAUDIO2_DEFAULT_SAMPLERATE,
                                        0, deviceId, nullptr, mCategory );
The values being passed to this function are:
&mMasterVoice = NULL
wfx = NULL
deviceId = NULL
mCategory = AudioCategory_GameEffects (6) never returns from this function call. There is no error message, no crash, just hangs and never returns from this. I can't seem to find the actual contents of this function so I can't follow the flow within it.

Any thoughts?
Sep 15, 2015 at 10:15 PM
Edited Sep 15, 2015 at 10:17 PM
The main thing that happens in that function is that WASAPI (the underlying Windows core audio API) is initialized. You said that on PC it might hang for 10 seconds. Are you saying it 'never' returns from this or only on Windows phone 8.1?

Is the repro as simple as trying to use the app above on a Windows phone 8.1, or is there anything about the phone setup in particular?