src/audio/xaudio2/SDL_xaudio2.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 02 Feb 2014 00:53:27 -0800
changeset 8149 681eb46b8ac4
parent 8093 b43765095a6f
child 8583 fb2933ca805f
permissions -rw-r--r--
Fixed bug 2374 - Update copyright for 2014...

Is it that time already??
icculus@5592
     1
/*
icculus@5592
     2
  Simple DirectMedia Layer
slouken@8149
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
icculus@5592
     4
icculus@5592
     5
  This software is provided 'as-is', without any express or implied
icculus@5592
     6
  warranty.  In no event will the authors be held liable for any damages
icculus@5592
     7
  arising from the use of this software.
icculus@5592
     8
icculus@5592
     9
  Permission is granted to anyone to use this software for any purpose,
icculus@5592
    10
  including commercial applications, and to alter it and redistribute it
icculus@5592
    11
  freely, subject to the following restrictions:
icculus@5592
    12
icculus@5592
    13
  1. The origin of this software must not be misrepresented; you must not
icculus@5592
    14
     claim that you wrote the original software. If you use this software
icculus@5592
    15
     in a product, an acknowledgment in the product documentation would be
icculus@5592
    16
     appreciated but is not required.
icculus@5592
    17
  2. Altered source versions must be plainly marked as such, and must not be
icculus@5592
    18
     misrepresented as being the original software.
icculus@5592
    19
  3. This notice may not be removed or altered from any source distribution.
icculus@5592
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
slouken@6044
    22
slouken@6044
    23
#if SDL_AUDIO_DRIVER_XAUDIO2
slouken@6044
    24
icculus@5592
    25
#include "../../core/windows/SDL_windows.h"
icculus@5592
    26
#include "SDL_audio.h"
icculus@5592
    27
#include "../SDL_audio_c.h"
icculus@5636
    28
#include "../SDL_sysaudio.h"
icculus@5592
    29
#include "SDL_assert.h"
icculus@5592
    30
slouken@7226
    31
#ifdef __GNUC__
slouken@7226
    32
/* The configure script already did any necessary checking */
slouken@7226
    33
#  define SDL_XAUDIO2_HAS_SDK 1
slouken@7226
    34
#else
slouken@7923
    35
/* XAudio2 exists as of the March 2008 DirectX SDK 
slouken@7923
    36
   The XAudio2 implementation available in the Windows 8 SDK targets Windows 8 and newer.
slouken@7923
    37
   If you want to build SDL with XAudio2 support you should install the DirectX SDK.
slouken@7923
    38
 */
slouken@7923
    39
#include <dxsdkver.h>
icculus@5636
    40
#if (!defined(_DXSDK_BUILD_MAJOR) || (_DXSDK_BUILD_MAJOR < 1284))
slouken@6161
    41
#  pragma message("Your DirectX SDK is too old. Disabling XAudio2 support.")
icculus@5636
    42
#else
icculus@5636
    43
#  define SDL_XAUDIO2_HAS_SDK 1
icculus@5635
    44
#endif
slouken@7226
    45
#endif /* __GNUC__ */
icculus@5592
    46
icculus@5636
    47
#ifdef SDL_XAUDIO2_HAS_SDK
icculus@5615
    48
icculus@5635
    49
#define INITGUID 1
slouken@7226
    50
#include <xaudio2.h>
icculus@5635
    51
icculus@5635
    52
/* Hidden "this" pointer for the audio functions */
slouken@7191
    53
#define _THIS   SDL_AudioDevice *this
icculus@5635
    54
slouken@7830
    55
/* Fixes bug 1210 where some versions of gcc need named parameters */
slouken@7830
    56
#ifdef __GNUC__
slouken@7830
    57
#ifdef THIS
slouken@7830
    58
#undef THIS
slouken@7830
    59
#endif
slouken@7830
    60
#define THIS    INTERFACE *p
slouken@7830
    61
#ifdef THIS_
slouken@7830
    62
#undef THIS_
slouken@7830
    63
#endif
slouken@7830
    64
#define THIS_   INTERFACE *p,
slouken@7830
    65
#endif
slouken@7830
    66
icculus@5635
    67
struct SDL_PrivateAudioData
icculus@5635
    68
{
icculus@5635
    69
    IXAudio2 *ixa2;
icculus@5635
    70
    IXAudio2SourceVoice *source;
icculus@5635
    71
    IXAudio2MasteringVoice *mastering;
icculus@5635
    72
    HANDLE semaphore;
icculus@5635
    73
    Uint8 *mixbuf;
icculus@5635
    74
    int mixlen;
icculus@5635
    75
    Uint8 *nextbuf;
icculus@5635
    76
};
icculus@5635
    77
icculus@5635
    78
icculus@5593
    79
static void
icculus@5593
    80
XAUDIO2_DetectDevices(int iscapture, SDL_AddAudioDevice addfn)
icculus@5592
    81
{
icculus@5592
    82
    IXAudio2 *ixa2 = NULL;
icculus@5592
    83
    UINT32 devcount = 0;
icculus@5592
    84
    UINT32 i = 0;
icculus@5592
    85
icculus@5592
    86
    if (iscapture) {
icculus@5592
    87
        SDL_SetError("XAudio2: capture devices unsupported.");
icculus@5593
    88
        return;
icculus@5592
    89
    } else if (XAudio2Create(&ixa2, 0, XAUDIO2_DEFAULT_PROCESSOR) != S_OK) {
philipp@7218
    90
        SDL_SetError("XAudio2: XAudio2Create() failed at detection.");
icculus@5593
    91
        return;
icculus@5592
    92
    } else if (IXAudio2_GetDeviceCount(ixa2, &devcount) != S_OK) {
icculus@5592
    93
        SDL_SetError("XAudio2: IXAudio2::GetDeviceCount() failed.");
icculus@5592
    94
        IXAudio2_Release(ixa2);
icculus@5593
    95
        return;
icculus@5592
    96
    }
icculus@5592
    97
icculus@5592
    98
    for (i = 0; i < devcount; i++) {
icculus@5592
    99
        XAUDIO2_DEVICE_DETAILS details;
icculus@5592
   100
        if (IXAudio2_GetDeviceDetails(ixa2, i, &details) == S_OK) {
icculus@7689
   101
            char *str = WIN_StringToUTF8(details.DisplayName);
icculus@5592
   102
            if (str != NULL) {
icculus@5593
   103
                addfn(str);
icculus@5593
   104
                SDL_free(str);  /* addfn() made a copy of the string. */
icculus@5592
   105
            }
icculus@5592
   106
        }
icculus@5592
   107
    }
icculus@5592
   108
icculus@5592
   109
    IXAudio2_Release(ixa2);
icculus@5592
   110
}
icculus@5592
   111
icculus@5592
   112
static void STDMETHODCALLTYPE
icculus@5592
   113
VoiceCBOnBufferEnd(THIS_ void *data)
icculus@5592
   114
{
icculus@5592
   115
    /* Just signal the SDL audio thread and get out of XAudio2's way. */
icculus@5592
   116
    SDL_AudioDevice *this = (SDL_AudioDevice *) data;
icculus@5592
   117
    ReleaseSemaphore(this->hidden->semaphore, 1, NULL);
icculus@5592
   118
}
icculus@5592
   119
icculus@5592
   120
static void STDMETHODCALLTYPE
icculus@5592
   121
VoiceCBOnVoiceError(THIS_ void *data, HRESULT Error)
icculus@5592
   122
{
icculus@5592
   123
    /* !!! FIXME: attempt to recover, or mark device disconnected. */
icculus@5592
   124
    SDL_assert(0 && "write me!");
icculus@5592
   125
}
icculus@5592
   126
icculus@5592
   127
/* no-op callbacks... */
icculus@5592
   128
static void STDMETHODCALLTYPE VoiceCBOnStreamEnd(THIS) {}
icculus@5592
   129
static void STDMETHODCALLTYPE VoiceCBOnVoiceProcessPassStart(THIS_ UINT32 b) {}
icculus@5592
   130
static void STDMETHODCALLTYPE VoiceCBOnVoiceProcessPassEnd(THIS) {}
icculus@5592
   131
static void STDMETHODCALLTYPE VoiceCBOnBufferStart(THIS_ void *data) {}
icculus@5592
   132
static void STDMETHODCALLTYPE VoiceCBOnLoopEnd(THIS_ void *data) {}
icculus@5592
   133
icculus@5592
   134
icculus@5592
   135
static Uint8 *
icculus@5592
   136
XAUDIO2_GetDeviceBuf(_THIS)
icculus@5592
   137
{
icculus@5592
   138
    return this->hidden->nextbuf;
icculus@5592
   139
}
icculus@5592
   140
icculus@5592
   141
static void
icculus@5592
   142
XAUDIO2_PlayDevice(_THIS)
icculus@5592
   143
{
icculus@5592
   144
    XAUDIO2_BUFFER buffer;
icculus@5592
   145
    Uint8 *mixbuf = this->hidden->mixbuf;
icculus@5592
   146
    Uint8 *nextbuf = this->hidden->nextbuf;
icculus@5592
   147
    const int mixlen = this->hidden->mixlen;
icculus@5592
   148
    IXAudio2SourceVoice *source = this->hidden->source;
icculus@5592
   149
    HRESULT result = S_OK;
icculus@5592
   150
icculus@5592
   151
    if (!this->enabled) { /* shutting down? */
icculus@5592
   152
        return;
icculus@5592
   153
    }
icculus@5592
   154
icculus@5592
   155
    /* Submit the next filled buffer */
icculus@5592
   156
    SDL_zero(buffer);
icculus@5592
   157
    buffer.AudioBytes = mixlen;
icculus@5592
   158
    buffer.pAudioData = nextbuf;
icculus@5592
   159
    buffer.pContext = this;
icculus@5592
   160
icculus@5592
   161
    if (nextbuf == mixbuf) {
icculus@5592
   162
        nextbuf += mixlen;
icculus@5592
   163
    } else {
icculus@5592
   164
        nextbuf = mixbuf;
icculus@5592
   165
    }
icculus@5592
   166
    this->hidden->nextbuf = nextbuf;
icculus@5592
   167
icculus@5592
   168
    result = IXAudio2SourceVoice_SubmitSourceBuffer(source, &buffer, NULL);
icculus@5592
   169
    if (result == XAUDIO2_E_DEVICE_INVALIDATED) {
icculus@5592
   170
        /* !!! FIXME: possibly disconnected or temporary lost. Recover? */
icculus@5592
   171
    }
icculus@5592
   172
icculus@5592
   173
    if (result != S_OK) {  /* uhoh, panic! */
icculus@5592
   174
        IXAudio2SourceVoice_FlushSourceBuffers(source);
icculus@5592
   175
        this->enabled = 0;
icculus@5592
   176
    }
icculus@5592
   177
}
icculus@5592
   178
icculus@5592
   179
static void
icculus@5592
   180
XAUDIO2_WaitDevice(_THIS)
icculus@5592
   181
{
icculus@5592
   182
    if (this->enabled) {
icculus@5592
   183
        WaitForSingleObject(this->hidden->semaphore, INFINITE);
icculus@5592
   184
    }
icculus@5592
   185
}
icculus@5592
   186
icculus@5592
   187
static void
icculus@5592
   188
XAUDIO2_WaitDone(_THIS)
icculus@5592
   189
{
icculus@5592
   190
    IXAudio2SourceVoice *source = this->hidden->source;
icculus@5592
   191
    XAUDIO2_VOICE_STATE state;
icculus@5592
   192
    SDL_assert(!this->enabled);  /* flag that stops playing. */
icculus@5592
   193
    IXAudio2SourceVoice_Discontinuity(source);
icculus@5592
   194
    IXAudio2SourceVoice_GetState(source, &state);
icculus@5592
   195
    while (state.BuffersQueued > 0) {
icculus@5592
   196
        WaitForSingleObject(this->hidden->semaphore, INFINITE);
icculus@5592
   197
        IXAudio2SourceVoice_GetState(source, &state);
icculus@5592
   198
    }
icculus@5592
   199
}
icculus@5592
   200
icculus@5592
   201
icculus@5592
   202
static void
icculus@5592
   203
XAUDIO2_CloseDevice(_THIS)
icculus@5592
   204
{
icculus@5592
   205
    if (this->hidden != NULL) {
icculus@5592
   206
        IXAudio2 *ixa2 = this->hidden->ixa2;
icculus@5592
   207
        IXAudio2SourceVoice *source = this->hidden->source;
icculus@5592
   208
        IXAudio2MasteringVoice *mastering = this->hidden->mastering;
icculus@5592
   209
icculus@5592
   210
        if (source != NULL) {
icculus@5592
   211
            IXAudio2SourceVoice_Stop(source, 0, XAUDIO2_COMMIT_NOW);
icculus@5592
   212
            IXAudio2SourceVoice_FlushSourceBuffers(source);
icculus@5592
   213
            IXAudio2SourceVoice_DestroyVoice(source);
icculus@5592
   214
        }
icculus@5592
   215
        if (ixa2 != NULL) {
icculus@5592
   216
            IXAudio2_StopEngine(ixa2);
icculus@5592
   217
        }
icculus@5592
   218
        if (mastering != NULL) {
icculus@5592
   219
            IXAudio2MasteringVoice_DestroyVoice(mastering);
icculus@5592
   220
        }
icculus@5592
   221
        if (ixa2 != NULL) {
icculus@5592
   222
            IXAudio2_Release(ixa2);
icculus@5592
   223
        }
slouken@7719
   224
        SDL_free(this->hidden->mixbuf);
icculus@5592
   225
        if (this->hidden->semaphore != NULL) {
icculus@5592
   226
            CloseHandle(this->hidden->semaphore);
icculus@5592
   227
        }
icculus@5592
   228
icculus@5592
   229
        SDL_free(this->hidden);
icculus@5592
   230
        this->hidden = NULL;
icculus@5592
   231
    }
icculus@5592
   232
}
icculus@5592
   233
icculus@5592
   234
static int
icculus@5592
   235
XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture)
icculus@5592
   236
{
icculus@5592
   237
    HRESULT result = S_OK;
icculus@5592
   238
    WAVEFORMATEX waveformat;
icculus@5592
   239
    int valid_format = 0;
icculus@5592
   240
    SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
icculus@5592
   241
    IXAudio2 *ixa2 = NULL;
icculus@5592
   242
    IXAudio2SourceVoice *source = NULL;
icculus@5592
   243
    UINT32 devId = 0;  /* 0 == system default device. */
icculus@5592
   244
slouken@7191
   245
    static IXAudio2VoiceCallbackVtbl callbacks_vtable = {
slouken@7191
   246
        VoiceCBOnVoiceProcessPassStart,
icculus@5592
   247
        VoiceCBOnVoiceProcessPassEnd,
icculus@5592
   248
        VoiceCBOnStreamEnd,
icculus@5592
   249
        VoiceCBOnBufferStart,
icculus@5592
   250
        VoiceCBOnBufferEnd,
icculus@5592
   251
        VoiceCBOnLoopEnd,
icculus@5592
   252
        VoiceCBOnVoiceError
slouken@7191
   253
    };
icculus@5592
   254
slouken@7191
   255
    static IXAudio2VoiceCallback callbacks = { &callbacks_vtable };
icculus@5592
   256
icculus@5592
   257
    if (iscapture) {
icculus@7038
   258
        return SDL_SetError("XAudio2: capture devices unsupported.");
icculus@5592
   259
    } else if (XAudio2Create(&ixa2, 0, XAUDIO2_DEFAULT_PROCESSOR) != S_OK) {
philipp@7218
   260
        return SDL_SetError("XAudio2: XAudio2Create() failed at open.");
icculus@5592
   261
    }
icculus@5592
   262
icculus@5592
   263
    if (devname != NULL) {
icculus@5592
   264
        UINT32 devcount = 0;
icculus@5592
   265
        UINT32 i = 0;
icculus@5592
   266
icculus@5592
   267
        if (IXAudio2_GetDeviceCount(ixa2, &devcount) != S_OK) {
icculus@5592
   268
            IXAudio2_Release(ixa2);
icculus@7038
   269
            return SDL_SetError("XAudio2: IXAudio2_GetDeviceCount() failed.");
icculus@5592
   270
        }
icculus@5592
   271
        for (i = 0; i < devcount; i++) {
icculus@5592
   272
            XAUDIO2_DEVICE_DETAILS details;
icculus@5592
   273
            if (IXAudio2_GetDeviceDetails(ixa2, i, &details) == S_OK) {
icculus@7689
   274
                char *str = WIN_StringToUTF8(details.DisplayName);
icculus@5592
   275
                if (str != NULL) {
icculus@5592
   276
                    const int match = (SDL_strcmp(str, devname) == 0);
icculus@5592
   277
                    SDL_free(str);
icculus@5592
   278
                    if (match) {
icculus@5592
   279
                        devId = i;
icculus@5592
   280
                        break;
icculus@5592
   281
                    }
icculus@5592
   282
                }
icculus@5592
   283
            }
icculus@5592
   284
        }
icculus@5592
   285
icculus@5592
   286
        if (i == devcount) {
icculus@5592
   287
            IXAudio2_Release(ixa2);
icculus@7038
   288
            return SDL_SetError("XAudio2: Requested device not found.");
icculus@5592
   289
        }
icculus@5592
   290
    }
icculus@5592
   291
icculus@5592
   292
    /* Initialize all variables that we clean on shutdown */
icculus@5592
   293
    this->hidden = (struct SDL_PrivateAudioData *)
icculus@5592
   294
        SDL_malloc((sizeof *this->hidden));
icculus@5592
   295
    if (this->hidden == NULL) {
icculus@5592
   296
        IXAudio2_Release(ixa2);
icculus@7038
   297
        return SDL_OutOfMemory();
icculus@5592
   298
    }
icculus@5592
   299
    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
icculus@5592
   300
icculus@5592
   301
    this->hidden->ixa2 = ixa2;
icculus@5592
   302
    this->hidden->semaphore = CreateSemaphore(NULL, 1, 2, NULL);
icculus@5592
   303
    if (this->hidden->semaphore == NULL) {
icculus@5592
   304
        XAUDIO2_CloseDevice(this);
icculus@7038
   305
        return SDL_SetError("XAudio2: CreateSemaphore() failed!");
icculus@5592
   306
    }
icculus@5592
   307
icculus@5592
   308
    while ((!valid_format) && (test_format)) {
icculus@5592
   309
        switch (test_format) {
icculus@5592
   310
        case AUDIO_U8:
icculus@5592
   311
        case AUDIO_S16:
icculus@5592
   312
        case AUDIO_S32:
icculus@5592
   313
        case AUDIO_F32:
icculus@5592
   314
            this->spec.format = test_format;
icculus@5592
   315
            valid_format = 1;
icculus@5592
   316
            break;
icculus@5592
   317
        }
icculus@5592
   318
        test_format = SDL_NextAudioFormat();
icculus@5592
   319
    }
icculus@5592
   320
icculus@5592
   321
    if (!valid_format) {
icculus@5592
   322
        XAUDIO2_CloseDevice(this);
icculus@7038
   323
        return SDL_SetError("XAudio2: Unsupported audio format");
icculus@5592
   324
    }
icculus@5592
   325
icculus@5592
   326
    /* Update the fragment size as size in bytes */
icculus@5592
   327
    SDL_CalculateAudioSpec(&this->spec);
icculus@5592
   328
icculus@5592
   329
    /* We feed a Source, it feeds the Mastering, which feeds the device. */
icculus@5592
   330
    this->hidden->mixlen = this->spec.size;
icculus@5592
   331
    this->hidden->mixbuf = (Uint8 *) SDL_malloc(2 * this->hidden->mixlen);
icculus@5592
   332
    if (this->hidden->mixbuf == NULL) {
icculus@5592
   333
        XAUDIO2_CloseDevice(this);
icculus@7038
   334
        return SDL_OutOfMemory();
icculus@5592
   335
    }
icculus@5592
   336
    this->hidden->nextbuf = this->hidden->mixbuf;
slouken@6352
   337
    SDL_memset(this->hidden->mixbuf, 0, 2 * this->hidden->mixlen);
icculus@5592
   338
icculus@5592
   339
    /* We use XAUDIO2_DEFAULT_CHANNELS instead of this->spec.channels. On
icculus@5592
   340
       Xbox360, this means 5.1 output, but on Windows, it means "figure out
icculus@5592
   341
       what the system has." It might be preferable to let XAudio2 blast
icculus@5592
   342
       stereo output to appropriate surround sound configurations
icculus@5592
   343
       instead of clamping to 2 channels, even though we'll configure the
icculus@5592
   344
       Source Voice for whatever number of channels you supply. */
icculus@5592
   345
    result = IXAudio2_CreateMasteringVoice(ixa2, &this->hidden->mastering,
icculus@5592
   346
                                           XAUDIO2_DEFAULT_CHANNELS,
icculus@5592
   347
                                           this->spec.freq, 0, devId, NULL);
icculus@5592
   348
    if (result != S_OK) {
icculus@5592
   349
        XAUDIO2_CloseDevice(this);
icculus@7038
   350
        return SDL_SetError("XAudio2: Couldn't create mastering voice");
icculus@5592
   351
    }
icculus@5592
   352
icculus@5592
   353
    SDL_zero(waveformat);
icculus@5592
   354
    if (SDL_AUDIO_ISFLOAT(this->spec.format)) {
icculus@5592
   355
        waveformat.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
icculus@5592
   356
    } else {
icculus@5592
   357
        waveformat.wFormatTag = WAVE_FORMAT_PCM;
icculus@5592
   358
    }
icculus@5592
   359
    waveformat.wBitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format);
icculus@5592
   360
    waveformat.nChannels = this->spec.channels;
icculus@5592
   361
    waveformat.nSamplesPerSec = this->spec.freq;
icculus@5592
   362
    waveformat.nBlockAlign =
icculus@5592
   363
        waveformat.nChannels * (waveformat.wBitsPerSample / 8);
icculus@5592
   364
    waveformat.nAvgBytesPerSec =
icculus@5592
   365
        waveformat.nSamplesPerSec * waveformat.nBlockAlign;
icculus@5592
   366
icculus@5592
   367
    result = IXAudio2_CreateSourceVoice(ixa2, &source, &waveformat,
icculus@5592
   368
                                        XAUDIO2_VOICE_NOSRC |
icculus@5592
   369
                                        XAUDIO2_VOICE_NOPITCH,
icculus@5592
   370
                                        1.0f, &callbacks, NULL, NULL);
icculus@5592
   371
    if (result != S_OK) {
icculus@5592
   372
        XAUDIO2_CloseDevice(this);
icculus@7038
   373
        return SDL_SetError("XAudio2: Couldn't create source voice");
icculus@5592
   374
    }
icculus@5592
   375
    this->hidden->source = source;
icculus@5592
   376
icculus@5592
   377
    /* Start everything playing! */
icculus@5592
   378
    result = IXAudio2_StartEngine(ixa2);
icculus@5592
   379
    if (result != S_OK) {
icculus@5592
   380
        XAUDIO2_CloseDevice(this);
icculus@7038
   381
        return SDL_SetError("XAudio2: Couldn't start engine");
icculus@5592
   382
    }
icculus@5592
   383
icculus@5592
   384
    result = IXAudio2SourceVoice_Start(source, 0, XAUDIO2_COMMIT_NOW);
icculus@5592
   385
    if (result != S_OK) {
icculus@5592
   386
        XAUDIO2_CloseDevice(this);
icculus@7038
   387
        return SDL_SetError("XAudio2: Couldn't start source voice");
icculus@5592
   388
    }
icculus@5592
   389
icculus@7038
   390
    return 0; /* good to go. */
icculus@5592
   391
}
icculus@5592
   392
icculus@5592
   393
static void
icculus@5592
   394
XAUDIO2_Deinitialize(void)
icculus@5592
   395
{
icculus@5592
   396
    WIN_CoUninitialize();
icculus@5592
   397
}
icculus@5592
   398
icculus@5636
   399
#endif  /* SDL_XAUDIO2_HAS_SDK */
icculus@5615
   400
icculus@5615
   401
icculus@5592
   402
static int
icculus@5592
   403
XAUDIO2_Init(SDL_AudioDriverImpl * impl)
icculus@5592
   404
{
icculus@5636
   405
#ifndef SDL_XAUDIO2_HAS_SDK
icculus@5636
   406
    SDL_SetError("XAudio2: SDL was built without XAudio2 support (old DirectX SDK).");
icculus@5615
   407
    return 0;  /* no XAudio2 support, ever. Update your SDK! */
icculus@5615
   408
#else
icculus@5592
   409
    /* XAudio2Create() is a macro that uses COM; we don't load the .dll */
icculus@5592
   410
    IXAudio2 *ixa2 = NULL;
icculus@5592
   411
    if (FAILED(WIN_CoInitialize())) {
icculus@5592
   412
        SDL_SetError("XAudio2: CoInitialize() failed");
icculus@5592
   413
        return 0;
icculus@5592
   414
    }
icculus@5592
   415
icculus@5592
   416
    if (XAudio2Create(&ixa2, 0, XAUDIO2_DEFAULT_PROCESSOR) != S_OK) {
icculus@5592
   417
        WIN_CoUninitialize();
philipp@7218
   418
        SDL_SetError("XAudio2: XAudio2Create() failed at initialization");
icculus@5592
   419
        return 0;  /* not available. */
icculus@5592
   420
    }
icculus@5592
   421
    IXAudio2_Release(ixa2);
icculus@5592
   422
icculus@5592
   423
    /* Set the function pointers */
icculus@5592
   424
    impl->DetectDevices = XAUDIO2_DetectDevices;
icculus@5592
   425
    impl->OpenDevice = XAUDIO2_OpenDevice;
icculus@5592
   426
    impl->PlayDevice = XAUDIO2_PlayDevice;
icculus@5592
   427
    impl->WaitDevice = XAUDIO2_WaitDevice;
icculus@5592
   428
    impl->WaitDone = XAUDIO2_WaitDone;
icculus@5592
   429
    impl->GetDeviceBuf = XAUDIO2_GetDeviceBuf;
icculus@5592
   430
    impl->CloseDevice = XAUDIO2_CloseDevice;
icculus@5592
   431
    impl->Deinitialize = XAUDIO2_Deinitialize;
icculus@5592
   432
icculus@5592
   433
    return 1;   /* this audio target is available. */
icculus@5615
   434
#endif
icculus@5592
   435
}
icculus@5592
   436
icculus@5592
   437
AudioBootStrap XAUDIO2_bootstrap = {
icculus@5592
   438
    "xaudio2", "XAudio2", XAUDIO2_Init, 0
icculus@5592
   439
};
icculus@5592
   440
icculus@5636
   441
#endif  /* SDL_AUDIO_DRIVER_XAUDIO2 */
icculus@5636
   442
icculus@5592
   443
/* vi: set ts=4 sw=4 expandtab: */