We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1863

Summary: Xaudio2: Xaudio2Create() failed
Product: SDL Reporter: Wouter van Oortmerssen <aardappel>
Component: audioAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED WONTFIX QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P1 CC: philipp.wiesemann
Version: 2.0.3   
Hardware: x86   
OS: Windows 7   

Description Wouter van Oortmerssen 2013-05-22 21:50:04 UTC
Summary says it all. No idea why this should fail. This is on macbook air running 32bit windows 7 that can play audio just fine in other applications. The audio code works just fine on other computers, too.

The code calls SDL_OpenAudioDevice with 44100, AUDIO_S16SYS, 1 channel, 512 samples and SDL_AUDIO_ALLOW_ANY_CHANGE, so I presume that should really always work.

There are further errors about not being able to create an audio thread, but I assume those are caused by this first error.
Comment 1 Philipp Wiesemann 2013-06-01 07:55:55 UTC
Is the error message containing "XAudio2Create() failed" caused in SDL_OpenAudioDevice() or already in SDL_Init*()?

Maybe XAudio2 is not used but an other audio backend.
Comment 2 Wouter van Oortmerssen 2013-06-02 14:34:46 UTC
It happens during SDL_InitSubSystem(SDL_INIT_AUDIO).
If another backend is being used, it must be a NULL driver, since there's no actual audio output.
The subsequent SDL_OpenAudioDevice returns 2, so that sounds plausible.
Comment 3 Wouter van Oortmerssen 2015-04-03 18:03:23 UTC
This problem is still happening in 2.0.3 (that I just upgraded to), I thought I'd look at it again, see if it gives any new output.

This is on Windows 7, VS 2013

The problem ONLY happens in release mode, which doesn't help with tracking it down.

If I just run it, the moment it tries to init audio, it outputs:
ERROR: Not enough resources to create thread
It then freezes. If I try to break the program, it looks stuck in 
ntdll.dll!_ZwWaitForSingleObject or on occasion in SDL_SemWaitTimeout

If I step through the code in the debugger (in release mode), I get through SDL_OpenAudioDevice without it hanging or giving the above message, but instead it says:
ERROR: XAudio2: Couldn't create mastering voice
So the issue seems timing related as well.

Again, my code, which I run upon the first sound I want to play, looks like:

    if (SDL_InitSubSystem(SDL_INIT_AUDIO))
        return false;

    SDL_zero(playbackspec);
    playbackspec.freq = 44100;
    playbackspec.format = AUDIO_S16SYS;
    playbackspec.channels = 1;
    playbackspec.samples = 512;
    playbackspec.callback = SDLAudioCallback;
    playbackspec.userdata = nullptr;
    audioid = SDL_OpenAudioDevice(nullptr, 0, &playbackspec, nullptr, SDL_AUDIO_ALLOW_ANY_CHANGE);

The audio devices I get are (in both debug and release):

LOG: Audio device 0: Speakers (Realtek High Definition Audio)
LOG: Audio device 1: Realtek Digital Output (Realtek High Definition Audio)
LOG: Audio device 2: Realtek Digital Output(Optical) (Realtek High Definition Audio)

and it returns audio device id 2 in debug.

passing any of these 2 names to SDL_OpenAudioDevice explicitly makes no difference.
Comment 4 Sam Lantinga 2017-08-14 05:07:25 UTC
We're removing XAudio2 in favor of WASAPI after the 2.0.6 release.