compat.c 102 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
/*
 * Copyright (c) 2015 Andrew Eikum for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 *
 ***************
 *
 * Some versions of XAudio2 add or remove functions to the COM vtables, or
 * incompatibly change structures. This file provides implementations of the
 * older XAudio2 versions onto the new XAudio2 APIs.
 *
 * Below is a list of significant changes to the main XAudio2 interfaces and
 * API. There may be further changes to effects and other parts that Wine
 * doesn't currently implement.
 *
 * 2.0
 *   Initial version
 *
 * 2.1
 *   Change CLSID_XAudio2
 *   Re-order Error codes
 *   Change XAUDIO2_LOOP_INFINITE
 *   Change struct XAUDIO2_PERFORMANCE_DATA
 *   Change IXAudio2Voice::GetOutputMatrix return value to void
 *   Add parameter to IXAudio2VoiceCallback::OnVoiceProcessingPassStart
 *   Change struct XAPO_REGISTRATION_PROPERTIES. CAREFUL when using! Not all
 *       implementations of IXAPO are Wine implementations.
 *
 * 2.2
 *   Change CLSID_XAudio2
 *   No ABI break
 *
 * 2.3
 *   Change CLSID_XAudio2
 *   ABI break:
 *     Change struct XAUDIO2_PERFORMANCE_DATA
 *
 * 2.4
 *   Change CLSID_XAudio2
 *   ABI break:
 *     Add IXAudio2Voice::SetOutputFilterParameters
 *     Add IXAudio2Voice::GetOutputFilterParameters
 *     Add IXAudio2SourceVoice::SetSourceSampleRate
 *     Change struct XAUDIO2_VOICE_SENDS
 *
 * 2.5
 *   Change CLSID_XAudio2
 *   No ABI break
 *
 * 2.6
 *   Change CLSID_XAudio2
 *   No ABI break
 *
 * 2.7
 *   Change CLSID_XAudio2
 *   No ABI break
 *
 * 2.8
 *   Remove CLSID_XAudio2
 *   Change IID_IXAudio2
 *   Add xaudio2_8.XAudio2Create
 *   ABI break:
 *     Remove IXAudio2::GetDeviceCount
 *     Remove IXAudio2::GetDeviceDetails
 *     Remove IXAudio2::Initialize
 *     Change parameter of IXAudio2::CreateMasteringVoice
 *     Add Flags parameter to IXAudio2SourceVoice::GetState
 *     Add IXAudio2MasteringVoice::GetChannelMask
81
 *     Add DisableLateField member to XAUDIO2FX_REVERB_PARAMETERS
82
 *     Add ActiveFlags member to XAUDIO2_VOICE_DETAILS
83 84 85 86 87 88 89
 *
 * 2.9
 *   Change IID_IXAudio2
 *   New flags: XAUDIO2_STOP_ENGINE_WHEN_IDLE, XAUDIO2_1024_QUANTUM,
 *       XAUDIO2_NO_VIRTUAL_AUDIO_CLIENT
 *   ABI break:
 *     Add SideDelay member to XAUDIO2FX_REVERB_PARAMETERS
90 91 92 93 94 95 96 97 98 99 100 101 102 103
 */

#include "config.h"

#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#define COBJMACROS

#include <stdarg.h>

#include "xaudio_private.h"

#include "wine/debug.h"

104
#if XAUDIO2_VER <= 7
105
WINE_DEFAULT_DEBUG_CHANNEL(xaudio2);
106
#endif
107

108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
#if XAUDIO2_VER <= 3
static XAUDIO2_SEND_DESCRIPTOR *convert_send_descriptors23(const XAUDIO23_VOICE_SENDS *sends)
{
    XAUDIO2_SEND_DESCRIPTOR *ret;
    DWORD i;

    ret = HeapAlloc(GetProcessHeap(), 0, sends->OutputCount * sizeof(XAUDIO2_SEND_DESCRIPTOR));

    for(i = 0; i < sends->OutputCount; ++i){
        ret[i].Flags = 0;
        ret[i].pOutputVoice = sends->pOutputVoices[i];
    }

    return ret;
}
#endif

125 126
/* BEGIN IXAudio2SourceVoice */
#if XAUDIO2_VER == 0
127
XA2VoiceImpl *impl_from_IXAudio20SourceVoice(IXAudio20SourceVoice *iface)
128
{
129
    return CONTAINING_RECORD(iface, XA2VoiceImpl, IXAudio20SourceVoice_iface);
130 131
}

132
static void WINAPI XA20SRC_GetVoiceDetails(IXAudio20SourceVoice *iface,
133
        XAUDIO27_VOICE_DETAILS *pVoiceDetails)
134
{
135
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
136 137 138 139 140 141 142
    XAUDIO2_VOICE_DETAILS details;

    IXAudio2SourceVoice_GetVoiceDetails(&This->IXAudio2SourceVoice_iface, &details);

    pVoiceDetails->CreationFlags = details.CreationFlags;
    pVoiceDetails->InputChannels = details.InputChannels;
    pVoiceDetails->InputSampleRate = details.InputSampleRate;
143 144
}

145 146
static HRESULT WINAPI XA20SRC_SetOutputVoices(IXAudio20SourceVoice *iface,
        const XAUDIO23_VOICE_SENDS *pSendList)
147
{
148
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
149
    XAUDIO2_VOICE_SENDS sends, *psends = NULL;
150 151 152 153
    HRESULT hr;

    TRACE("%p, %p\n", This, pSendList);

154 155 156 157
    if(pSendList){
        sends.SendCount = pSendList->OutputCount;
        sends.pSends = convert_send_descriptors23(pSendList);
        psends = &sends;
158 159
    }

160
    hr = IXAudio2SourceVoice_SetOutputVoices(&This->IXAudio2SourceVoice_iface, psends);
161

162 163
    if(pSendList)
        HeapFree(GetProcessHeap(), 0, sends.pSends);
164 165

    return hr;
166 167
}

168
static HRESULT WINAPI XA20SRC_SetEffectChain(IXAudio20SourceVoice *iface,
169 170
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
{
171
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
172 173 174
    return IXAudio2SourceVoice_SetEffectChain(&This->IXAudio2SourceVoice_iface, pEffectChain);
}

175
static HRESULT WINAPI XA20SRC_EnableEffect(IXAudio20SourceVoice *iface,
176 177
        UINT32 EffectIndex, UINT32 OperationSet)
{
178
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
179 180
    return IXAudio2SourceVoice_EnableEffect(&This->IXAudio2SourceVoice_iface,
            EffectIndex, OperationSet);
181 182
}

183
static HRESULT WINAPI XA20SRC_DisableEffect(IXAudio20SourceVoice *iface,
184 185
        UINT32 EffectIndex, UINT32 OperationSet)
{
186
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
187 188
    return IXAudio2SourceVoice_DisableEffect(&This->IXAudio2SourceVoice_iface,
            EffectIndex, OperationSet);
189 190
}

191
static void WINAPI XA20SRC_GetEffectState(IXAudio20SourceVoice *iface,
192 193
        UINT32 EffectIndex, BOOL *pEnabled)
{
194
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
195 196
    return IXAudio2SourceVoice_GetEffectState(&This->IXAudio2SourceVoice_iface,
            EffectIndex, pEnabled);
197 198
}

199
static HRESULT WINAPI XA20SRC_SetEffectParameters(IXAudio20SourceVoice *iface,
200 201 202
        UINT32 EffectIndex, const void *pParameters, UINT32 ParametersByteSize,
        UINT32 OperationSet)
{
203
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
204 205 206 207
    return IXAudio2SourceVoice_SetEffectParameters(&This->IXAudio2SourceVoice_iface,
            EffectIndex, pParameters, ParametersByteSize, OperationSet);
}

208
static HRESULT WINAPI XA20SRC_GetEffectParameters(IXAudio20SourceVoice *iface,
209 210
        UINT32 EffectIndex, void *pParameters, UINT32 ParametersByteSize)
{
211
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
212 213 214 215
    return IXAudio2SourceVoice_GetEffectParameters(&This->IXAudio2SourceVoice_iface,
            EffectIndex, pParameters, ParametersByteSize);
}

216
static HRESULT WINAPI XA20SRC_SetFilterParameters(IXAudio20SourceVoice *iface,
217 218
        const XAUDIO2_FILTER_PARAMETERS *pParameters, UINT32 OperationSet)
{
219
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
220 221 222 223
    return IXAudio2SourceVoice_SetFilterParameters(&This->IXAudio2SourceVoice_iface,
            pParameters, OperationSet);
}

224
static void WINAPI XA20SRC_GetFilterParameters(IXAudio20SourceVoice *iface,
225 226
        XAUDIO2_FILTER_PARAMETERS *pParameters)
{
227
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
228
    return IXAudio2SourceVoice_GetFilterParameters(&This->IXAudio2SourceVoice_iface, pParameters);
229 230
}

231 232
static HRESULT WINAPI XA20SRC_SetVolume(IXAudio20SourceVoice *iface,
        float Volume, UINT32 OperationSet)
233
{
234
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
235 236
    return IXAudio2SourceVoice_SetVolume(&This->IXAudio2SourceVoice_iface,
            Volume, OperationSet);
237 238
}

239 240
static void WINAPI XA20SRC_GetVolume(IXAudio20SourceVoice *iface,
        float *pVolume)
241
{
242
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
243
    return IXAudio2SourceVoice_GetVolume(&This->IXAudio2SourceVoice_iface, pVolume);
244 245
}

246
static HRESULT WINAPI XA20SRC_SetChannelVolumes(IXAudio20SourceVoice *iface,
247 248
        UINT32 Channels, const float *pVolumes, UINT32 OperationSet)
{
249
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
250 251
    return IXAudio2SourceVoice_SetChannelVolumes(&This->IXAudio2SourceVoice_iface,
            Channels, pVolumes, OperationSet);
252 253
}

254
static void WINAPI XA20SRC_GetChannelVolumes(IXAudio20SourceVoice *iface,
255 256
        UINT32 Channels, float *pVolumes)
{
257
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
258 259
    return IXAudio2SourceVoice_GetChannelVolumes(&This->IXAudio2SourceVoice_iface,
            Channels, pVolumes);
260 261
}

262
static HRESULT WINAPI XA20SRC_SetOutputMatrix(IXAudio20SourceVoice *iface,
263 264 265 266
        IXAudio2Voice *pDestinationVoice, UINT32 SourceChannels,
        UINT32 DestinationChannels, const float *pLevelMatrix,
        UINT32 OperationSet)
{
267
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
268 269 270 271 272
    return IXAudio2SourceVoice_SetOutputMatrix(&This->IXAudio2SourceVoice_iface,
            pDestinationVoice, SourceChannels, DestinationChannels,
            pLevelMatrix, OperationSet);
}

273
static HRESULT WINAPI XA20SRC_GetOutputMatrix(IXAudio20SourceVoice *iface,
274 275 276
        IXAudio2Voice *pDestinationVoice, UINT32 SourceChannels,
        UINT32 DestinationChannels, float *pLevelMatrix)
{
277
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
278 279 280 281
    IXAudio2SourceVoice_GetOutputMatrix(&This->IXAudio2SourceVoice_iface,
            pDestinationVoice, SourceChannels, DestinationChannels,
            pLevelMatrix);
    return S_OK;
282 283
}

284
static void WINAPI XA20SRC_DestroyVoice(IXAudio20SourceVoice *iface)
285
{
286
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
287
    return IXAudio2SourceVoice_DestroyVoice(&This->IXAudio2SourceVoice_iface);
288 289
}

290
static HRESULT WINAPI XA20SRC_Start(IXAudio20SourceVoice *iface, UINT32 Flags,
291 292
        UINT32 OperationSet)
{
293
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
294 295 296
    return IXAudio2SourceVoice_Start(&This->IXAudio2SourceVoice_iface, Flags, OperationSet);
}

297
static HRESULT WINAPI XA20SRC_Stop(IXAudio20SourceVoice *iface, UINT32 Flags,
298 299
        UINT32 OperationSet)
{
300
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
301 302 303
    return IXAudio2SourceVoice_Stop(&This->IXAudio2SourceVoice_iface, Flags, OperationSet);
}

304
static HRESULT WINAPI XA20SRC_SubmitSourceBuffer(IXAudio20SourceVoice *iface,
305 306
        const XAUDIO2_BUFFER *pBuffer, const XAUDIO2_BUFFER_WMA *pBufferWMA)
{
307
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
308 309
    return IXAudio2SourceVoice_SubmitSourceBuffer(&This->IXAudio2SourceVoice_iface,
            pBuffer, pBufferWMA);
310 311
}

312
static HRESULT WINAPI XA20SRC_FlushSourceBuffers(IXAudio20SourceVoice *iface)
313
{
314
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
315 316 317
    return IXAudio2SourceVoice_FlushSourceBuffers(&This->IXAudio2SourceVoice_iface);
}

318
static HRESULT WINAPI XA20SRC_Discontinuity(IXAudio20SourceVoice *iface)
319
{
320
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
321 322 323
    return IXAudio2SourceVoice_Discontinuity(&This->IXAudio2SourceVoice_iface);
}

324 325
static HRESULT WINAPI XA20SRC_ExitLoop(IXAudio20SourceVoice *iface,
        UINT32 OperationSet)
326
{
327
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
328 329 330
    return IXAudio2SourceVoice_ExitLoop(&This->IXAudio2SourceVoice_iface, OperationSet);
}

331
static void WINAPI XA20SRC_GetState(IXAudio20SourceVoice *iface,
332 333
        XAUDIO2_VOICE_STATE *pVoiceState)
{
334
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
335 336 337
    return IXAudio2SourceVoice_GetState(&This->IXAudio2SourceVoice_iface, pVoiceState, 0);
}

338
static HRESULT WINAPI XA20SRC_SetFrequencyRatio(IXAudio20SourceVoice *iface,
339 340
        float Ratio, UINT32 OperationSet)
{
341
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
342 343
    return IXAudio2SourceVoice_SetFrequencyRatio(&This->IXAudio2SourceVoice_iface,
            Ratio, OperationSet);
344 345
}

346 347
static void WINAPI XA20SRC_GetFrequencyRatio(IXAudio20SourceVoice *iface,
        float *pRatio)
348
{
349
    XA2VoiceImpl *This = impl_from_IXAudio20SourceVoice(iface);
350 351 352
    return IXAudio2SourceVoice_GetFrequencyRatio(&This->IXAudio2SourceVoice_iface, pRatio);
}

353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
const IXAudio20SourceVoiceVtbl XAudio20SourceVoice_Vtbl = {
    XA20SRC_GetVoiceDetails,
    XA20SRC_SetOutputVoices,
    XA20SRC_SetEffectChain,
    XA20SRC_EnableEffect,
    XA20SRC_DisableEffect,
    XA20SRC_GetEffectState,
    XA20SRC_SetEffectParameters,
    XA20SRC_GetEffectParameters,
    XA20SRC_SetFilterParameters,
    XA20SRC_GetFilterParameters,
    XA20SRC_SetVolume,
    XA20SRC_GetVolume,
    XA20SRC_SetChannelVolumes,
    XA20SRC_GetChannelVolumes,
    XA20SRC_SetOutputMatrix,
    XA20SRC_GetOutputMatrix,
    XA20SRC_DestroyVoice,
    XA20SRC_Start,
    XA20SRC_Stop,
    XA20SRC_SubmitSourceBuffer,
    XA20SRC_FlushSourceBuffers,
    XA20SRC_Discontinuity,
    XA20SRC_ExitLoop,
    XA20SRC_GetState,
    XA20SRC_SetFrequencyRatio,
    XA20SRC_GetFrequencyRatio,
};

#elif XAUDIO2_VER <= 3

384
XA2VoiceImpl *impl_from_IXAudio23SourceVoice(IXAudio23SourceVoice *iface)
385
{
386
    return CONTAINING_RECORD(iface, XA2VoiceImpl, IXAudio23SourceVoice_iface);
387 388 389
}

static void WINAPI XA23SRC_GetVoiceDetails(IXAudio23SourceVoice *iface,
390
        XAUDIO27_VOICE_DETAILS *pVoiceDetails)
391
{
392
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
393 394 395 396 397 398 399
    XAUDIO2_VOICE_DETAILS details;

    IXAudio2SourceVoice_GetVoiceDetails(&This->IXAudio2SourceVoice_iface, &details);

    pVoiceDetails->CreationFlags = details.CreationFlags;
    pVoiceDetails->InputChannels = details.InputChannels;
    pVoiceDetails->InputSampleRate = details.InputSampleRate;
400 401 402 403 404
}

static HRESULT WINAPI XA23SRC_SetOutputVoices(IXAudio23SourceVoice *iface,
        const XAUDIO23_VOICE_SENDS *pSendList)
{
405
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
406
    XAUDIO2_VOICE_SENDS sends, *psends = NULL;
407 408 409 410
    HRESULT hr;

    TRACE("%p, %p\n", This, pSendList);

411 412 413 414
    if(pSendList){
        sends.SendCount = pSendList->OutputCount;
        sends.pSends = convert_send_descriptors23(pSendList);
        psends = &sends;
415 416
    }

417
    hr = IXAudio2SourceVoice_SetOutputVoices(&This->IXAudio2SourceVoice_iface, psends);
418

419 420
    if(pSendList)
        HeapFree(GetProcessHeap(), 0, sends.pSends);
421 422 423 424 425 426 427

    return hr;
}

static HRESULT WINAPI XA23SRC_SetEffectChain(IXAudio23SourceVoice *iface,
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
{
428
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
429 430 431 432 433 434
    return IXAudio2SourceVoice_SetEffectChain(&This->IXAudio2SourceVoice_iface, pEffectChain);
}

static HRESULT WINAPI XA23SRC_EnableEffect(IXAudio23SourceVoice *iface,
        UINT32 EffectIndex, UINT32 OperationSet)
{
435
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
436 437 438 439 440 441 442
    return IXAudio2SourceVoice_EnableEffect(&This->IXAudio2SourceVoice_iface,
            EffectIndex, OperationSet);
}

static HRESULT WINAPI XA23SRC_DisableEffect(IXAudio23SourceVoice *iface,
        UINT32 EffectIndex, UINT32 OperationSet)
{
443
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
444 445 446 447 448 449 450
    return IXAudio2SourceVoice_DisableEffect(&This->IXAudio2SourceVoice_iface,
            EffectIndex, OperationSet);
}

static void WINAPI XA23SRC_GetEffectState(IXAudio23SourceVoice *iface,
        UINT32 EffectIndex, BOOL *pEnabled)
{
451
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
452 453 454 455 456 457 458 459
    return IXAudio2SourceVoice_GetEffectState(&This->IXAudio2SourceVoice_iface,
            EffectIndex, pEnabled);
}

static HRESULT WINAPI XA23SRC_SetEffectParameters(IXAudio23SourceVoice *iface,
        UINT32 EffectIndex, const void *pParameters, UINT32 ParametersByteSize,
        UINT32 OperationSet)
{
460
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
461 462 463 464 465 466 467
    return IXAudio2SourceVoice_SetEffectParameters(&This->IXAudio2SourceVoice_iface,
            EffectIndex, pParameters, ParametersByteSize, OperationSet);
}

static HRESULT WINAPI XA23SRC_GetEffectParameters(IXAudio23SourceVoice *iface,
        UINT32 EffectIndex, void *pParameters, UINT32 ParametersByteSize)
{
468
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
469 470 471 472 473 474 475
    return IXAudio2SourceVoice_GetEffectParameters(&This->IXAudio2SourceVoice_iface,
            EffectIndex, pParameters, ParametersByteSize);
}

static HRESULT WINAPI XA23SRC_SetFilterParameters(IXAudio23SourceVoice *iface,
        const XAUDIO2_FILTER_PARAMETERS *pParameters, UINT32 OperationSet)
{
476
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
477 478 479 480 481 482 483
    return IXAudio2SourceVoice_SetFilterParameters(&This->IXAudio2SourceVoice_iface,
            pParameters, OperationSet);
}

static void WINAPI XA23SRC_GetFilterParameters(IXAudio23SourceVoice *iface,
        XAUDIO2_FILTER_PARAMETERS *pParameters)
{
484
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
485 486 487 488 489 490
    return IXAudio2SourceVoice_GetFilterParameters(&This->IXAudio2SourceVoice_iface, pParameters);
}

static HRESULT WINAPI XA23SRC_SetVolume(IXAudio23SourceVoice *iface,
        float Volume, UINT32 OperationSet)
{
491
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
492 493 494 495 496 497 498
    return IXAudio2SourceVoice_SetVolume(&This->IXAudio2SourceVoice_iface,
            Volume, OperationSet);
}

static void WINAPI XA23SRC_GetVolume(IXAudio23SourceVoice *iface,
        float *pVolume)
{
499
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
500 501 502 503 504 505
    return IXAudio2SourceVoice_GetVolume(&This->IXAudio2SourceVoice_iface, pVolume);
}

static HRESULT WINAPI XA23SRC_SetChannelVolumes(IXAudio23SourceVoice *iface,
        UINT32 Channels, const float *pVolumes, UINT32 OperationSet)
{
506
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
507 508 509 510 511 512 513
    return IXAudio2SourceVoice_SetChannelVolumes(&This->IXAudio2SourceVoice_iface,
            Channels, pVolumes, OperationSet);
}

static void WINAPI XA23SRC_GetChannelVolumes(IXAudio23SourceVoice *iface,
        UINT32 Channels, float *pVolumes)
{
514
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
515 516 517 518 519 520 521 522 523
    return IXAudio2SourceVoice_GetChannelVolumes(&This->IXAudio2SourceVoice_iface,
            Channels, pVolumes);
}

static HRESULT WINAPI XA23SRC_SetOutputMatrix(IXAudio23SourceVoice *iface,
        IXAudio2Voice *pDestinationVoice, UINT32 SourceChannels,
        UINT32 DestinationChannels, const float *pLevelMatrix,
        UINT32 OperationSet)
{
524
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
525 526 527 528 529 530 531 532 533
    return IXAudio2SourceVoice_SetOutputMatrix(&This->IXAudio2SourceVoice_iface,
            pDestinationVoice, SourceChannels, DestinationChannels,
            pLevelMatrix, OperationSet);
}

static void WINAPI XA23SRC_GetOutputMatrix(IXAudio23SourceVoice *iface,
        IXAudio2Voice *pDestinationVoice, UINT32 SourceChannels,
        UINT32 DestinationChannels, float *pLevelMatrix)
{
534
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
535 536 537 538 539 540 541
    return IXAudio2SourceVoice_GetOutputMatrix(&This->IXAudio2SourceVoice_iface,
            pDestinationVoice, SourceChannels, DestinationChannels,
            pLevelMatrix);
}

static void WINAPI XA23SRC_DestroyVoice(IXAudio23SourceVoice *iface)
{
542
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
543 544 545 546 547 548
    return IXAudio2SourceVoice_DestroyVoice(&This->IXAudio2SourceVoice_iface);
}

static HRESULT WINAPI XA23SRC_Start(IXAudio23SourceVoice *iface, UINT32 Flags,
        UINT32 OperationSet)
{
549
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
550 551 552 553 554 555
    return IXAudio2SourceVoice_Start(&This->IXAudio2SourceVoice_iface, Flags, OperationSet);
}

static HRESULT WINAPI XA23SRC_Stop(IXAudio23SourceVoice *iface, UINT32 Flags,
        UINT32 OperationSet)
{
556
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
557 558 559 560 561 562
    return IXAudio2SourceVoice_Stop(&This->IXAudio2SourceVoice_iface, Flags, OperationSet);
}

static HRESULT WINAPI XA23SRC_SubmitSourceBuffer(IXAudio23SourceVoice *iface,
        const XAUDIO2_BUFFER *pBuffer, const XAUDIO2_BUFFER_WMA *pBufferWMA)
{
563
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
564 565 566 567 568 569
    return IXAudio2SourceVoice_SubmitSourceBuffer(&This->IXAudio2SourceVoice_iface,
            pBuffer, pBufferWMA);
}

static HRESULT WINAPI XA23SRC_FlushSourceBuffers(IXAudio23SourceVoice *iface)
{
570
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
571 572 573 574 575
    return IXAudio2SourceVoice_FlushSourceBuffers(&This->IXAudio2SourceVoice_iface);
}

static HRESULT WINAPI XA23SRC_Discontinuity(IXAudio23SourceVoice *iface)
{
576
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
577 578 579 580 581 582
    return IXAudio2SourceVoice_Discontinuity(&This->IXAudio2SourceVoice_iface);
}

static HRESULT WINAPI XA23SRC_ExitLoop(IXAudio23SourceVoice *iface,
        UINT32 OperationSet)
{
583
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
584 585 586 587 588 589
    return IXAudio2SourceVoice_ExitLoop(&This->IXAudio2SourceVoice_iface, OperationSet);
}

static void WINAPI XA23SRC_GetState(IXAudio23SourceVoice *iface,
        XAUDIO2_VOICE_STATE *pVoiceState)
{
590
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
591 592 593 594 595 596
    return IXAudio2SourceVoice_GetState(&This->IXAudio2SourceVoice_iface, pVoiceState, 0);
}

static HRESULT WINAPI XA23SRC_SetFrequencyRatio(IXAudio23SourceVoice *iface,
        float Ratio, UINT32 OperationSet)
{
597
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
598 599 600 601 602 603 604
    return IXAudio2SourceVoice_SetFrequencyRatio(&This->IXAudio2SourceVoice_iface,
            Ratio, OperationSet);
}

static void WINAPI XA23SRC_GetFrequencyRatio(IXAudio23SourceVoice *iface,
        float *pRatio)
{
605
    XA2VoiceImpl *This = impl_from_IXAudio23SourceVoice(iface);
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
    return IXAudio2SourceVoice_GetFrequencyRatio(&This->IXAudio2SourceVoice_iface, pRatio);
}

const IXAudio23SourceVoiceVtbl XAudio23SourceVoice_Vtbl = {
    XA23SRC_GetVoiceDetails,
    XA23SRC_SetOutputVoices,
    XA23SRC_SetEffectChain,
    XA23SRC_EnableEffect,
    XA23SRC_DisableEffect,
    XA23SRC_GetEffectState,
    XA23SRC_SetEffectParameters,
    XA23SRC_GetEffectParameters,
    XA23SRC_SetFilterParameters,
    XA23SRC_GetFilterParameters,
    XA23SRC_SetVolume,
    XA23SRC_GetVolume,
    XA23SRC_SetChannelVolumes,
    XA23SRC_GetChannelVolumes,
    XA23SRC_SetOutputMatrix,
    XA23SRC_GetOutputMatrix,
    XA23SRC_DestroyVoice,
    XA23SRC_Start,
    XA23SRC_Stop,
    XA23SRC_SubmitSourceBuffer,
    XA23SRC_FlushSourceBuffers,
    XA23SRC_Discontinuity,
    XA23SRC_ExitLoop,
    XA23SRC_GetState,
    XA23SRC_SetFrequencyRatio,
    XA23SRC_GetFrequencyRatio,
};

638 639
#elif XAUDIO2_VER <= 7

640
XA2VoiceImpl *impl_from_IXAudio27SourceVoice(IXAudio27SourceVoice *iface)
641
{
642
    return CONTAINING_RECORD(iface, XA2VoiceImpl, IXAudio27SourceVoice_iface);
643 644
}

645
static void WINAPI XA27SRC_GetVoiceDetails(IXAudio27SourceVoice *iface,
646
        XAUDIO27_VOICE_DETAILS *pVoiceDetails)
647
{
648
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
649 650 651 652 653 654 655
    XAUDIO2_VOICE_DETAILS details;

    IXAudio2SourceVoice_GetVoiceDetails(&This->IXAudio2SourceVoice_iface, &details);

    pVoiceDetails->CreationFlags = details.CreationFlags;
    pVoiceDetails->InputChannels = details.InputChannels;
    pVoiceDetails->InputSampleRate = details.InputSampleRate;
656 657
}

658 659
static HRESULT WINAPI XA27SRC_SetOutputVoices(IXAudio27SourceVoice *iface,
        const XAUDIO2_VOICE_SENDS *pSendList)
660
{
661
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
662
    return IXAudio2SourceVoice_SetOutputVoices(&This->IXAudio2SourceVoice_iface, pSendList);
663 664
}

665
static HRESULT WINAPI XA27SRC_SetEffectChain(IXAudio27SourceVoice *iface,
666 667
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
{
668
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
669
    return IXAudio2SourceVoice_SetEffectChain(&This->IXAudio2SourceVoice_iface, pEffectChain);
670 671
}

672
static HRESULT WINAPI XA27SRC_EnableEffect(IXAudio27SourceVoice *iface,
673 674
        UINT32 EffectIndex, UINT32 OperationSet)
{
675
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
676
    return IXAudio2SourceVoice_EnableEffect(&This->IXAudio2SourceVoice_iface, EffectIndex, OperationSet);
677 678
}

679
static HRESULT WINAPI XA27SRC_DisableEffect(IXAudio27SourceVoice *iface,
680 681
        UINT32 EffectIndex, UINT32 OperationSet)
{
682
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
683
    return IXAudio2SourceVoice_DisableEffect(&This->IXAudio2SourceVoice_iface, EffectIndex, OperationSet);
684 685
}

686
static void WINAPI XA27SRC_GetEffectState(IXAudio27SourceVoice *iface,
687 688
        UINT32 EffectIndex, BOOL *pEnabled)
{
689
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
690
    IXAudio2SourceVoice_GetEffectState(&This->IXAudio2SourceVoice_iface, EffectIndex, pEnabled);
691 692
}

693
static HRESULT WINAPI XA27SRC_SetEffectParameters(IXAudio27SourceVoice *iface,
694 695 696
        UINT32 EffectIndex, const void *pParameters, UINT32 ParametersByteSize,
        UINT32 OperationSet)
{
697
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
698
    return IXAudio2SourceVoice_SetEffectParameters(&This->IXAudio2SourceVoice_iface,
699 700 701
            EffectIndex, pParameters, ParametersByteSize, OperationSet);
}

702
static HRESULT WINAPI XA27SRC_GetEffectParameters(IXAudio27SourceVoice *iface,
703 704
        UINT32 EffectIndex, void *pParameters, UINT32 ParametersByteSize)
{
705
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
706
    return IXAudio2SourceVoice_GetEffectParameters(&This->IXAudio2SourceVoice_iface,
707 708 709
            EffectIndex, pParameters, ParametersByteSize);
}

710
static HRESULT WINAPI XA27SRC_SetFilterParameters(IXAudio27SourceVoice *iface,
711 712
        const XAUDIO2_FILTER_PARAMETERS *pParameters, UINT32 OperationSet)
{
713
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
714
    return IXAudio2SourceVoice_SetFilterParameters(&This->IXAudio2SourceVoice_iface,
715 716 717
            pParameters, OperationSet);
}

718
static void WINAPI XA27SRC_GetFilterParameters(IXAudio27SourceVoice *iface,
719 720
        XAUDIO2_FILTER_PARAMETERS *pParameters)
{
721
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
722
    IXAudio2SourceVoice_GetFilterParameters(&This->IXAudio2SourceVoice_iface, pParameters);
723 724
}

725 726 727
static HRESULT WINAPI XA27SRC_SetOutputFilterParameters(IXAudio27SourceVoice *iface,
        IXAudio2Voice *pDestinationVoice,
        const XAUDIO2_FILTER_PARAMETERS *pParameters, UINT32 OperationSet)
728
{
729
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
730 731
    return IXAudio2SourceVoice_SetOutputFilterParameters(&This->IXAudio2SourceVoice_iface,
            pDestinationVoice, pParameters, OperationSet);
732 733
}

734 735 736
static void WINAPI XA27SRC_GetOutputFilterParameters(IXAudio27SourceVoice *iface,
        IXAudio2Voice *pDestinationVoice,
        XAUDIO2_FILTER_PARAMETERS *pParameters)
737
{
738
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
739 740
    IXAudio2SourceVoice_GetOutputFilterParameters(&This->IXAudio2SourceVoice_iface,
            pDestinationVoice, pParameters);
741 742
}

743 744 745
static HRESULT WINAPI XA27SRC_SetVolume(IXAudio27SourceVoice *iface, float Volume,
        UINT32 OperationSet)
{
746
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
747 748 749 750 751 752
    return IXAudio2SourceVoice_SetVolume(&This->IXAudio2SourceVoice_iface, Volume,
            OperationSet);
}

static void WINAPI XA27SRC_GetVolume(IXAudio27SourceVoice *iface, float *pVolume)
{
753
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
754 755 756 757
    IXAudio2SourceVoice_GetVolume(&This->IXAudio2SourceVoice_iface, pVolume);
}

static HRESULT WINAPI XA27SRC_SetChannelVolumes(IXAudio27SourceVoice *iface,
758 759
        UINT32 Channels, const float *pVolumes, UINT32 OperationSet)
{
760
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
761 762
    return IXAudio2SourceVoice_SetChannelVolumes(&This->IXAudio2SourceVoice_iface, Channels,
            pVolumes, OperationSet);
763 764
}

765
static void WINAPI XA27SRC_GetChannelVolumes(IXAudio27SourceVoice *iface,
766 767
        UINT32 Channels, float *pVolumes)
{
768
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
769 770
    IXAudio2SourceVoice_GetChannelVolumes(&This->IXAudio2SourceVoice_iface, Channels,
            pVolumes);
771 772
}

773 774
static HRESULT WINAPI XA27SRC_SetOutputMatrix(IXAudio27SourceVoice *iface,
        IXAudio2Voice *pDestinationVoice, UINT32 SourceChannels,
775 776 777
        UINT32 DestinationChannels, const float *pLevelMatrix,
        UINT32 OperationSet)
{
778
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
779 780
    return IXAudio2SourceVoice_SetOutputMatrix(&This->IXAudio2SourceVoice_iface,
            pDestinationVoice, SourceChannels, DestinationChannels,
781 782 783
            pLevelMatrix, OperationSet);
}

784 785
static void WINAPI XA27SRC_GetOutputMatrix(IXAudio27SourceVoice *iface,
        IXAudio2Voice *pDestinationVoice, UINT32 SourceChannels,
786 787
        UINT32 DestinationChannels, float *pLevelMatrix)
{
788
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
789 790
    IXAudio2SourceVoice_GetOutputMatrix(&This->IXAudio2SourceVoice_iface, pDestinationVoice,
            SourceChannels, DestinationChannels, pLevelMatrix);
791 792
}

793
static void WINAPI XA27SRC_DestroyVoice(IXAudio27SourceVoice *iface)
794
{
795
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
796
    IXAudio2SourceVoice_DestroyVoice(&This->IXAudio2SourceVoice_iface);
797 798
}

799 800
static HRESULT WINAPI XA27SRC_Start(IXAudio27SourceVoice *iface, UINT32 Flags,
        UINT32 OperationSet)
801
{
802
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
803
    return IXAudio2SourceVoice_Start(&This->IXAudio2SourceVoice_iface, Flags, OperationSet);
804 805
}

806 807
static HRESULT WINAPI XA27SRC_Stop(IXAudio27SourceVoice *iface, UINT32 Flags,
        UINT32 OperationSet)
808
{
809
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
810
    return IXAudio2SourceVoice_Stop(&This->IXAudio2SourceVoice_iface, Flags, OperationSet);
811 812
}

813 814
static HRESULT WINAPI XA27SRC_SubmitSourceBuffer(IXAudio27SourceVoice *iface,
        const XAUDIO2_BUFFER *pBuffer, const XAUDIO2_BUFFER_WMA *pBufferWMA)
815
{
816
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
817 818
    return IXAudio2SourceVoice_SubmitSourceBuffer(&This->IXAudio2SourceVoice_iface, pBuffer,
            pBufferWMA);
819 820
}

821
static HRESULT WINAPI XA27SRC_FlushSourceBuffers(IXAudio27SourceVoice *iface)
822
{
823
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
824
    return IXAudio2SourceVoice_FlushSourceBuffers(&This->IXAudio2SourceVoice_iface);
825 826
}

827
static HRESULT WINAPI XA27SRC_Discontinuity(IXAudio27SourceVoice *iface)
828
{
829
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
830
    return IXAudio2SourceVoice_Discontinuity(&This->IXAudio2SourceVoice_iface);
831 832
}

833
static HRESULT WINAPI XA27SRC_ExitLoop(IXAudio27SourceVoice *iface, UINT32 OperationSet)
834
{
835
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
836
    return IXAudio2SourceVoice_ExitLoop(&This->IXAudio2SourceVoice_iface, OperationSet);
837 838
}

839 840
static void WINAPI XA27SRC_GetState(IXAudio27SourceVoice *iface,
        XAUDIO2_VOICE_STATE *pVoiceState)
841
{
842
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
843
    return IXAudio2SourceVoice_GetState(&This->IXAudio2SourceVoice_iface, pVoiceState, 0);
844 845
}

846 847
static HRESULT WINAPI XA27SRC_SetFrequencyRatio(IXAudio27SourceVoice *iface,
        float Ratio, UINT32 OperationSet)
848
{
849
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
850
    return IXAudio2SourceVoice_SetFrequencyRatio(&This->IXAudio2SourceVoice_iface, Ratio, OperationSet);
851 852
}

853 854
static void WINAPI XA27SRC_GetFrequencyRatio(IXAudio27SourceVoice *iface, float *pRatio)
{
855
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
856 857 858 859 860 861 862
    return IXAudio2SourceVoice_GetFrequencyRatio(&This->IXAudio2SourceVoice_iface, pRatio);
}

static HRESULT WINAPI XA27SRC_SetSourceSampleRate(
    IXAudio27SourceVoice *iface,
    UINT32 NewSourceSampleRate)
{
863
    XA2VoiceImpl *This = impl_from_IXAudio27SourceVoice(iface);
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903
    return IXAudio2SourceVoice_SetSourceSampleRate(&This->IXAudio2SourceVoice_iface, NewSourceSampleRate);
}

const IXAudio27SourceVoiceVtbl XAudio27SourceVoice_Vtbl = {
    XA27SRC_GetVoiceDetails,
    XA27SRC_SetOutputVoices,
    XA27SRC_SetEffectChain,
    XA27SRC_EnableEffect,
    XA27SRC_DisableEffect,
    XA27SRC_GetEffectState,
    XA27SRC_SetEffectParameters,
    XA27SRC_GetEffectParameters,
    XA27SRC_SetFilterParameters,
    XA27SRC_GetFilterParameters,
    XA27SRC_SetOutputFilterParameters,
    XA27SRC_GetOutputFilterParameters,
    XA27SRC_SetVolume,
    XA27SRC_GetVolume,
    XA27SRC_SetChannelVolumes,
    XA27SRC_GetChannelVolumes,
    XA27SRC_SetOutputMatrix,
    XA27SRC_GetOutputMatrix,
    XA27SRC_DestroyVoice,
    XA27SRC_Start,
    XA27SRC_Stop,
    XA27SRC_SubmitSourceBuffer,
    XA27SRC_FlushSourceBuffers,
    XA27SRC_Discontinuity,
    XA27SRC_ExitLoop,
    XA27SRC_GetState,
    XA27SRC_SetFrequencyRatio,
    XA27SRC_GetFrequencyRatio,
    XA27SRC_SetSourceSampleRate
};
#endif
/* END IXAudio2SourceVoice */


/* BEGIN IXAudio2SubmixVoice */
#if XAUDIO2_VER == 0
904
XA2VoiceImpl *impl_from_IXAudio20SubmixVoice(IXAudio20SubmixVoice *iface)
905
{
906
    return CONTAINING_RECORD(iface, XA2VoiceImpl, IXAudio20SubmixVoice_iface);
907 908 909
}

static void WINAPI XA20SUB_GetVoiceDetails(IXAudio20SubmixVoice *iface,
910
        XAUDIO27_VOICE_DETAILS *pVoiceDetails)
911
{
912
    XA2VoiceImpl *This = impl_from_IXAudio20SubmixVoice(iface);
913 914 915 916 917 918 919
    XAUDIO2_VOICE_DETAILS details;

    IXAudio2SubmixVoice_GetVoiceDetails(&This->IXAudio2SubmixVoice_iface, &details);

    pVoiceDetails->CreationFlags = details.CreationFlags;
    pVoiceDetails->InputChannels = details.InputChannels;
    pVoiceDetails->InputSampleRate = details.InputSampleRate;
920 921 922 923 924
}

static HRESULT WINAPI XA20SUB_SetOutputVoices(IXAudio20SubmixVoice *iface,
        const XAUDIO23_VOICE_SENDS *pSendList)
{
925
    XA2VoiceImpl *This = impl_from_IXAudio20SubmixVoice(iface);
926
    XAUDIO2_VOICE_SENDS sends, *psends = NULL;
927 928 929 930
    HRESULT hr;

    TRACE("%p, %p\n", This, pSendList);

931 932 933 934
    if(pSendList){
        sends.SendCount = pSendList->OutputCount;
        sends.pSends = convert_send_descriptors23(pSendList);
        psends = &sends;
935 936
    }

937
    hr = IXAudio2SubmixVoice_SetOutputVoices(&This->IXAudio2SubmixVoice_iface, psends);
938

939 940
    if(pSendList)
        HeapFree(GetProcessHeap(), 0, sends.pSends);
941 942 943 944 945 946 947

    return hr;
}

static HRESULT WINAPI XA20SUB_SetEffectChain(IXAudio20SubmixVoice *iface,
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
{
948
    XA2VoiceImpl *This = impl_from_IXAudio20SubmixVoice(iface);
949 950 951 952 953 954
    return IXAudio2SubmixVoice_SetEffectChain(&This->IXAudio2SubmixVoice_iface, pEffectChain);
}

static HRESULT WINAPI XA20SUB_EnableEffect(IXAudio20SubmixVoice *iface,
        UINT32 EffectIndex, UINT32 OperationSet)
{
955
    XA2VoiceImpl *This = impl_from_IXAudio20SubmixVoice(iface);
956 957 958 959 960 961 962
    return IXAudio2SubmixVoice_EnableEffect(&This->IXAudio2SubmixVoice_iface,
            EffectIndex, OperationSet);
}

static HRESULT WINAPI XA20SUB_DisableEffect(IXAudio20SubmixVoice *iface,
        UINT32 EffectIndex, UINT32 OperationSet)
{
963
    XA2VoiceImpl *This = impl_from_IXAudio20SubmixVoice(iface);
964 965 966 967 968 969 970
    return IXAudio2SubmixVoice_DisableEffect(&This->IXAudio2SubmixVoice_iface,
            EffectIndex, OperationSet);
}

static void WINAPI XA20SUB_GetEffectState(IXAudio20SubmixVoice *iface,
        UINT32 EffectIndex, BOOL *pEnabled)
{
971
    XA2VoiceImpl *This = impl_from_IXAudio20SubmixVoice(iface);
972 973 974 975 976 977 978 979
    return IXAudio2SubmixVoice_GetEffectState(&This->IXAudio2SubmixVoice_iface,
            EffectIndex, pEnabled);
}

static HRESULT WINAPI XA20SUB_SetEffectParameters(IXAudio20SubmixVoice *iface,
        UINT32 EffectIndex, const void *pParameters, UINT32 ParametersByteSize,
        UINT32 OperationSet)
{
980
    XA2VoiceImpl *This = impl_from_IXAudio20SubmixVoice(iface);
981 982 983 984 985
    return IXAudio2SubmixVoice_SetEffectParameters(&This->IXAudio2SubmixVoice_iface,
            EffectIndex, pParameters, ParametersByteSize, OperationSet);
}

static HRESULT WINAPI XA20SUB_GetEffectParameters(IXAudio20SubmixVoice *iface,
986 987
        UINT32 EffectIndex, void *pParameters, UINT32 ParametersByteSize)
{
988
    XA2VoiceImpl *This = impl_from_IXAudio20SubmixVoice(iface);
989
    return IXAudio2SubmixVoice_GetEffectParameters(&This->IXAudio2SubmixVoice_iface,
990 991 992
            EffectIndex, pParameters, ParametersByteSize);
}

993
static HRESULT WINAPI XA20SUB_SetFilterParameters(IXAudio20SubmixVoice *iface,
994 995
        const XAUDIO2_FILTER_PARAMETERS *pParameters, UINT32 OperationSet)
{
996
    XA2VoiceImpl *This = impl_from_IXAudio20SubmixVoice(iface);
997
    return IXAudio2SubmixVoice_SetFilterParameters(&This->IXAudio2SubmixVoice_iface,
998 999 1000
            pParameters, OperationSet);
}

1001
static void WINAPI XA20SUB_GetFilterParameters(IXAudio20SubmixVoice *iface,
1002 1003
        XAUDIO2_FILTER_PARAMETERS *pParameters)
{
1004
    XA2VoiceImpl *This = impl_from_IXAudio20SubmixVoice(iface);
1005
    return IXAudio2SubmixVoice_GetFilterParameters(&This->IXAudio2SubmixVoice_iface, pParameters);
1006 1007
}

1008
static HRESULT WINAPI XA20SUB_SetVolume(IXAudio20SubmixVoice *iface,
1009 1010
        float Volume, UINT32 OperationSet)
{
1011
    XA2VoiceImpl *This = impl_from_IXAudio20SubmixVoice(iface);
1012
    return IXAudio2SubmixVoice_SetVolume(&This->IXAudio2SubmixVoice_iface,
1013 1014 1015
            Volume, OperationSet);
}

1016
static void WINAPI XA20SUB_GetVolume(IXAudio20SubmixVoice *iface,
1017 1018
        float *pVolume)
{
1019
    XA2VoiceImpl *This = impl_from_IXAudio20SubmixVoice(iface);
1020
    return IXAudio2SubmixVoice_GetVolume(&This->IXAudio2SubmixVoice_iface, pVolume);
1021 1022
}

1023
static HRESULT WINAPI XA20SUB_SetChannelVolumes(IXAudio20SubmixVoice *iface,
1024 1025
        UINT32 Channels, const float *pVolumes, UINT32 OperationSet)
{
1026
    XA2VoiceImpl *This = impl_from_IXAudio20SubmixVoice(iface);
1027
    return IXAudio2SubmixVoice_SetChannelVolumes(&This->IXAudio2SubmixVoice_iface,
1028 1029 1030
            Channels, pVolumes, OperationSet);
}

1031
static void WINAPI XA20SUB_GetChannelVolumes(IXAudio20SubmixVoice *iface,
1032 1033
        UINT32 Channels, float *pVolumes)
{
1034
    XA2VoiceImpl *This = impl_from_IXAudio20SubmixVoice(iface);
1035
    return IXAudio2SubmixVoice_GetChannelVolumes(&This->IXAudio2SubmixVoice_iface,
1036 1037 1038
            Channels, pVolumes);
}

1039 1040
static HRESULT WINAPI XA20SUB_SetOutputMatrix(IXAudio20SubmixVoice *iface,
        IXAudio2Voice *pDestinationVoice, UINT32 SubmixChannels,
1041 1042 1043
        UINT32 DestinationChannels, const float *pLevelMatrix,
        UINT32 OperationSet)
{
1044
    XA2VoiceImpl *This = impl_from_IXAudio20SubmixVoice(iface);
1045 1046
    return IXAudio2SubmixVoice_SetOutputMatrix(&This->IXAudio2SubmixVoice_iface,
            pDestinationVoice, SubmixChannels, DestinationChannels,
1047 1048 1049
            pLevelMatrix, OperationSet);
}

1050 1051
static HRESULT WINAPI XA20SUB_GetOutputMatrix(IXAudio20SubmixVoice *iface,
        IXAudio2Voice *pDestinationVoice, UINT32 SubmixChannels,
1052 1053
        UINT32 DestinationChannels, float *pLevelMatrix)
{
1054
    XA2VoiceImpl *This = impl_from_IXAudio20SubmixVoice(iface);
1055 1056
    IXAudio2SubmixVoice_GetOutputMatrix(&This->IXAudio2SubmixVoice_iface,
            pDestinationVoice, SubmixChannels, DestinationChannels,
1057
            pLevelMatrix);
1058
    return S_OK;
1059 1060
}

1061
static void WINAPI XA20SUB_DestroyVoice(IXAudio20SubmixVoice *iface)
1062
{
1063
    XA2VoiceImpl *This = impl_from_IXAudio20SubmixVoice(iface);
1064
    return IXAudio2SubmixVoice_DestroyVoice(&This->IXAudio2SubmixVoice_iface);
1065 1066
}

1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
const IXAudio20SubmixVoiceVtbl XAudio20SubmixVoice_Vtbl = {
    XA20SUB_GetVoiceDetails,
    XA20SUB_SetOutputVoices,
    XA20SUB_SetEffectChain,
    XA20SUB_EnableEffect,
    XA20SUB_DisableEffect,
    XA20SUB_GetEffectState,
    XA20SUB_SetEffectParameters,
    XA20SUB_GetEffectParameters,
    XA20SUB_SetFilterParameters,
    XA20SUB_GetFilterParameters,
    XA20SUB_SetVolume,
    XA20SUB_GetVolume,
    XA20SUB_SetChannelVolumes,
    XA20SUB_GetChannelVolumes,
    XA20SUB_SetOutputMatrix,
    XA20SUB_GetOutputMatrix,
    XA20SUB_DestroyVoice
1085
};
1086

1087
#elif XAUDIO2_VER <= 3
1088

1089
XA2VoiceImpl *impl_from_IXAudio23SubmixVoice(IXAudio23SubmixVoice *iface)
1090
{
1091
    return CONTAINING_RECORD(iface, XA2VoiceImpl, IXAudio23SubmixVoice_iface);
1092 1093
}

1094
static void WINAPI XA23SUB_GetVoiceDetails(IXAudio23SubmixVoice *iface,
1095
        XAUDIO27_VOICE_DETAILS *pVoiceDetails)
1096
{
1097
    XA2VoiceImpl *This = impl_from_IXAudio23SubmixVoice(iface);
1098 1099 1100 1101 1102 1103 1104
    XAUDIO2_VOICE_DETAILS details;

    IXAudio2SubmixVoice_GetVoiceDetails(&This->IXAudio2SubmixVoice_iface, &details);

    pVoiceDetails->CreationFlags = details.CreationFlags;
    pVoiceDetails->InputChannels = details.InputChannels;
    pVoiceDetails->InputSampleRate = details.InputSampleRate;
1105 1106
}

1107 1108
static HRESULT WINAPI XA23SUB_SetOutputVoices(IXAudio23SubmixVoice *iface,
        const XAUDIO23_VOICE_SENDS *pSendList)
1109
{
1110
    XA2VoiceImpl *This = impl_from_IXAudio23SubmixVoice(iface);
1111
    XAUDIO2_VOICE_SENDS sends, *psends = NULL;
1112
    HRESULT hr;
1113

1114
    TRACE("%p, %p\n", This, pSendList);
1115

1116 1117 1118 1119
    if(pSendList){
        sends.SendCount = pSendList->OutputCount;
        sends.pSends = convert_send_descriptors23(pSendList);
        psends = &sends;
1120 1121
    }

1122
    hr = IXAudio2SubmixVoice_SetOutputVoices(&This->IXAudio2SubmixVoice_iface, psends);
1123

1124 1125
    if(pSendList)
        HeapFree(GetProcessHeap(), 0, sends.pSends);
1126 1127 1128 1129

    return hr;
}

1130 1131
static HRESULT WINAPI XA23SUB_SetEffectChain(IXAudio23SubmixVoice *iface,
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
1132
{
1133
    XA2VoiceImpl *This = impl_from_IXAudio23SubmixVoice(iface);
1134
    return IXAudio2SubmixVoice_SetEffectChain(&This->IXAudio2SubmixVoice_iface, pEffectChain);
1135 1136
}

1137 1138
static HRESULT WINAPI XA23SUB_EnableEffect(IXAudio23SubmixVoice *iface,
        UINT32 EffectIndex, UINT32 OperationSet)
1139
{
1140
    XA2VoiceImpl *This = impl_from_IXAudio23SubmixVoice(iface);
1141 1142
    return IXAudio2SubmixVoice_EnableEffect(&This->IXAudio2SubmixVoice_iface,
            EffectIndex, OperationSet);
1143 1144
}

1145 1146
static HRESULT WINAPI XA23SUB_DisableEffect(IXAudio23SubmixVoice *iface,
        UINT32 EffectIndex, UINT32 OperationSet)
1147
{
1148
    XA2VoiceImpl *This = impl_from_IXAudio23SubmixVoice(iface);
1149 1150
    return IXAudio2SubmixVoice_DisableEffect(&This->IXAudio2SubmixVoice_iface,
            EffectIndex, OperationSet);
1151 1152
}

1153 1154
static void WINAPI XA23SUB_GetEffectState(IXAudio23SubmixVoice *iface,
        UINT32 EffectIndex, BOOL *pEnabled)
1155
{
1156
    XA2VoiceImpl *This = impl_from_IXAudio23SubmixVoice(iface);
1157 1158
    return IXAudio2SubmixVoice_GetEffectState(&This->IXAudio2SubmixVoice_iface,
            EffectIndex, pEnabled);
1159 1160
}

1161 1162 1163
static HRESULT WINAPI XA23SUB_SetEffectParameters(IXAudio23SubmixVoice *iface,
        UINT32 EffectIndex, const void *pParameters, UINT32 ParametersByteSize,
        UINT32 OperationSet)
1164
{
1165
    XA2VoiceImpl *This = impl_from_IXAudio23SubmixVoice(iface);
1166 1167
    return IXAudio2SubmixVoice_SetEffectParameters(&This->IXAudio2SubmixVoice_iface,
            EffectIndex, pParameters, ParametersByteSize, OperationSet);
1168 1169
}

1170 1171
static HRESULT WINAPI XA23SUB_GetEffectParameters(IXAudio23SubmixVoice *iface,
        UINT32 EffectIndex, void *pParameters, UINT32 ParametersByteSize)
1172
{
1173
    XA2VoiceImpl *This = impl_from_IXAudio23SubmixVoice(iface);
1174 1175
    return IXAudio2SubmixVoice_GetEffectParameters(&This->IXAudio2SubmixVoice_iface,
            EffectIndex, pParameters, ParametersByteSize);
1176 1177
}

1178 1179
static HRESULT WINAPI XA23SUB_SetFilterParameters(IXAudio23SubmixVoice *iface,
        const XAUDIO2_FILTER_PARAMETERS *pParameters, UINT32 OperationSet)
1180
{
1181
    XA2VoiceImpl *This = impl_from_IXAudio23SubmixVoice(iface);
1182 1183
    return IXAudio2SubmixVoice_SetFilterParameters(&This->IXAudio2SubmixVoice_iface,
            pParameters, OperationSet);
1184 1185
}

1186 1187
static void WINAPI XA23SUB_GetFilterParameters(IXAudio23SubmixVoice *iface,
        XAUDIO2_FILTER_PARAMETERS *pParameters)
1188
{
1189
    XA2VoiceImpl *This = impl_from_IXAudio23SubmixVoice(iface);
1190
    return IXAudio2SubmixVoice_GetFilterParameters(&This->IXAudio2SubmixVoice_iface, pParameters);
1191 1192
}

1193 1194
static HRESULT WINAPI XA23SUB_SetVolume(IXAudio23SubmixVoice *iface,
        float Volume, UINT32 OperationSet)
1195
{
1196
    XA2VoiceImpl *This = impl_from_IXAudio23SubmixVoice(iface);
1197 1198
    return IXAudio2SubmixVoice_SetVolume(&This->IXAudio2SubmixVoice_iface,
            Volume, OperationSet);
1199 1200
}

1201 1202
static void WINAPI XA23SUB_GetVolume(IXAudio23SubmixVoice *iface,
        float *pVolume)
1203
{
1204
    XA2VoiceImpl *This = impl_from_IXAudio23SubmixVoice(iface);
1205 1206
    return IXAudio2SubmixVoice_GetVolume(&This->IXAudio2SubmixVoice_iface, pVolume);
}
1207

1208 1209 1210
static HRESULT WINAPI XA23SUB_SetChannelVolumes(IXAudio23SubmixVoice *iface,
        UINT32 Channels, const float *pVolumes, UINT32 OperationSet)
{
1211
    XA2VoiceImpl *This = impl_from_IXAudio23SubmixVoice(iface);
1212 1213 1214
    return IXAudio2SubmixVoice_SetChannelVolumes(&This->IXAudio2SubmixVoice_iface,
            Channels, pVolumes, OperationSet);
}
1215

1216 1217 1218
static void WINAPI XA23SUB_GetChannelVolumes(IXAudio23SubmixVoice *iface,
        UINT32 Channels, float *pVolumes)
{
1219
    XA2VoiceImpl *This = impl_from_IXAudio23SubmixVoice(iface);
1220 1221 1222
    return IXAudio2SubmixVoice_GetChannelVolumes(&This->IXAudio2SubmixVoice_iface,
            Channels, pVolumes);
}
1223

1224 1225 1226 1227 1228
static HRESULT WINAPI XA23SUB_SetOutputMatrix(IXAudio23SubmixVoice *iface,
        IXAudio2Voice *pDestinationVoice, UINT32 SubmixChannels,
        UINT32 DestinationChannels, const float *pLevelMatrix,
        UINT32 OperationSet)
{
1229
    XA2VoiceImpl *This = impl_from_IXAudio23SubmixVoice(iface);
1230 1231 1232 1233
    return IXAudio2SubmixVoice_SetOutputMatrix(&This->IXAudio2SubmixVoice_iface,
            pDestinationVoice, SubmixChannels, DestinationChannels,
            pLevelMatrix, OperationSet);
}
1234

1235 1236 1237 1238
static void WINAPI XA23SUB_GetOutputMatrix(IXAudio23SubmixVoice *iface,
        IXAudio2Voice *pDestinationVoice, UINT32 SubmixChannels,
        UINT32 DestinationChannels, float *pLevelMatrix)
{
1239
    XA2VoiceImpl *This = impl_from_IXAudio23SubmixVoice(iface);
1240 1241 1242
    return IXAudio2SubmixVoice_GetOutputMatrix(&This->IXAudio2SubmixVoice_iface,
            pDestinationVoice, SubmixChannels, DestinationChannels,
            pLevelMatrix);
1243 1244
}

1245
static void WINAPI XA23SUB_DestroyVoice(IXAudio23SubmixVoice *iface)
1246
{
1247
    XA2VoiceImpl *This = impl_from_IXAudio23SubmixVoice(iface);
1248
    return IXAudio2SubmixVoice_DestroyVoice(&This->IXAudio2SubmixVoice_iface);
1249 1250
}

1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268
const IXAudio23SubmixVoiceVtbl XAudio23SubmixVoice_Vtbl = {
    XA23SUB_GetVoiceDetails,
    XA23SUB_SetOutputVoices,
    XA23SUB_SetEffectChain,
    XA23SUB_EnableEffect,
    XA23SUB_DisableEffect,
    XA23SUB_GetEffectState,
    XA23SUB_SetEffectParameters,
    XA23SUB_GetEffectParameters,
    XA23SUB_SetFilterParameters,
    XA23SUB_GetFilterParameters,
    XA23SUB_SetVolume,
    XA23SUB_GetVolume,
    XA23SUB_SetChannelVolumes,
    XA23SUB_GetChannelVolumes,
    XA23SUB_SetOutputMatrix,
    XA23SUB_GetOutputMatrix,
    XA23SUB_DestroyVoice
1269
};
1270 1271 1272

#elif XAUDIO2_VER <= 7

1273
XA2VoiceImpl *impl_from_IXAudio27SubmixVoice(IXAudio27SubmixVoice *iface)
1274
{
1275
    return CONTAINING_RECORD(iface, XA2VoiceImpl, IXAudio27SubmixVoice_iface);
1276 1277 1278 1279 1280
}

static void WINAPI XA27SUB_GetVoiceDetails(IXAudio27SubmixVoice *iface,
        XAUDIO27_VOICE_DETAILS *pVoiceDetails)
{
1281
    XA2VoiceImpl *This = impl_from_IXAudio27SubmixVoice(iface);
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293
    XAUDIO2_VOICE_DETAILS details;

    IXAudio2SubmixVoice_GetVoiceDetails(&This->IXAudio2SubmixVoice_iface, &details);

    pVoiceDetails->CreationFlags = details.CreationFlags;
    pVoiceDetails->InputChannels = details.InputChannels;
    pVoiceDetails->InputSampleRate = details.InputSampleRate;
}

static HRESULT WINAPI XA27SUB_SetOutputVoices(IXAudio27SubmixVoice *iface,
        const XAUDIO2_VOICE_SENDS *pSendList)
{
1294
    XA2VoiceImpl *This = impl_from_IXAudio27SubmixVoice(iface);
1295 1296 1297 1298 1299 1300
    return IXAudio2SubmixVoice_SetOutputVoices(&This->IXAudio2SubmixVoice_iface, pSendList);
}

static HRESULT WINAPI XA27SUB_SetEffectChain(IXAudio27SubmixVoice *iface,
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
{
1301
    XA2VoiceImpl *This = impl_from_IXAudio27SubmixVoice(iface);
1302 1303 1304 1305 1306 1307
    return IXAudio2SubmixVoice_SetEffectChain(&This->IXAudio2SubmixVoice_iface, pEffectChain);
}

static HRESULT WINAPI XA27SUB_EnableEffect(IXAudio27SubmixVoice *iface,
        UINT32 EffectIndex, UINT32 OperationSet)
{
1308
    XA2VoiceImpl *This = impl_from_IXAudio27SubmixVoice(iface);
1309 1310 1311 1312 1313 1314 1315
    return IXAudio2SubmixVoice_EnableEffect(&This->IXAudio2SubmixVoice_iface,
            EffectIndex, OperationSet);
}

static HRESULT WINAPI XA27SUB_DisableEffect(IXAudio27SubmixVoice *iface,
        UINT32 EffectIndex, UINT32 OperationSet)
{
1316
    XA2VoiceImpl *This = impl_from_IXAudio27SubmixVoice(iface);
1317 1318 1319 1320 1321 1322 1323
    return IXAudio2SubmixVoice_DisableEffect(&This->IXAudio2SubmixVoice_iface,
            EffectIndex, OperationSet);
}

static void WINAPI XA27SUB_GetEffectState(IXAudio27SubmixVoice *iface,
        UINT32 EffectIndex, BOOL *pEnabled)
{
1324
    XA2VoiceImpl *This = impl_from_IXAudio27SubmixVoice(iface);
1325 1326 1327 1328 1329 1330 1331 1332
    return IXAudio2SubmixVoice_GetEffectState(&This->IXAudio2SubmixVoice_iface,
            EffectIndex, pEnabled);
}

static HRESULT WINAPI XA27SUB_SetEffectParameters(IXAudio27SubmixVoice *iface,
        UINT32 EffectIndex, const void *pParameters, UINT32 ParametersByteSize,
        UINT32 OperationSet)
{
1333
    XA2VoiceImpl *This = impl_from_IXAudio27SubmixVoice(iface);
1334 1335 1336 1337 1338 1339 1340
    return IXAudio2SubmixVoice_SetEffectParameters(&This->IXAudio2SubmixVoice_iface,
            EffectIndex, pParameters, ParametersByteSize, OperationSet);
}

static HRESULT WINAPI XA27SUB_GetEffectParameters(IXAudio27SubmixVoice *iface,
        UINT32 EffectIndex, void *pParameters, UINT32 ParametersByteSize)
{
1341
    XA2VoiceImpl *This = impl_from_IXAudio27SubmixVoice(iface);
1342 1343 1344 1345 1346 1347 1348
    return IXAudio2SubmixVoice_GetEffectParameters(&This->IXAudio2SubmixVoice_iface,
            EffectIndex, pParameters, ParametersByteSize);
}

static HRESULT WINAPI XA27SUB_SetFilterParameters(IXAudio27SubmixVoice *iface,
        const XAUDIO2_FILTER_PARAMETERS *pParameters, UINT32 OperationSet)
{
1349
    XA2VoiceImpl *This = impl_from_IXAudio27SubmixVoice(iface);
1350 1351 1352 1353 1354 1355 1356
    return IXAudio2SubmixVoice_SetFilterParameters(&This->IXAudio2SubmixVoice_iface,
            pParameters, OperationSet);
}

static void WINAPI XA27SUB_GetFilterParameters(IXAudio27SubmixVoice *iface,
        XAUDIO2_FILTER_PARAMETERS *pParameters)
{
1357
    XA2VoiceImpl *This = impl_from_IXAudio27SubmixVoice(iface);
1358 1359 1360 1361 1362 1363 1364
    return IXAudio2SubmixVoice_GetFilterParameters(&This->IXAudio2SubmixVoice_iface, pParameters);
}

static HRESULT WINAPI XA27SUB_SetOutputFilterParameters(IXAudio27SubmixVoice *iface,
        IXAudio2Voice *pDestinationVoice,
        const XAUDIO2_FILTER_PARAMETERS *pParameters, UINT32 OperationSet)
{
1365
    XA2VoiceImpl *This = impl_from_IXAudio27SubmixVoice(iface);
1366 1367 1368 1369 1370 1371 1372 1373
    return IXAudio2SubmixVoice_SetOutputFilterParameters(&This->IXAudio2SubmixVoice_iface,
            pDestinationVoice, pParameters, OperationSet);
}

static void WINAPI XA27SUB_GetOutputFilterParameters(IXAudio27SubmixVoice *iface,
        IXAudio2Voice *pDestinationVoice,
        XAUDIO2_FILTER_PARAMETERS *pParameters)
{
1374
    XA2VoiceImpl *This = impl_from_IXAudio27SubmixVoice(iface);
1375 1376 1377 1378 1379 1380 1381
    IXAudio2SubmixVoice_GetOutputFilterParameters(&This->IXAudio2SubmixVoice_iface,
            pDestinationVoice, pParameters);
}

static HRESULT WINAPI XA27SUB_SetVolume(IXAudio27SubmixVoice *iface,
        float Volume, UINT32 OperationSet)
{
1382
    XA2VoiceImpl *This = impl_from_IXAudio27SubmixVoice(iface);
1383 1384 1385 1386 1387 1388 1389
    return IXAudio2SubmixVoice_SetVolume(&This->IXAudio2SubmixVoice_iface,
            Volume, OperationSet);
}

static void WINAPI XA27SUB_GetVolume(IXAudio27SubmixVoice *iface,
        float *pVolume)
{
1390
    XA2VoiceImpl *This = impl_from_IXAudio27SubmixVoice(iface);
1391 1392 1393 1394 1395 1396
    return IXAudio2SubmixVoice_GetVolume(&This->IXAudio2SubmixVoice_iface, pVolume);
}

static HRESULT WINAPI XA27SUB_SetChannelVolumes(IXAudio27SubmixVoice *iface,
        UINT32 Channels, const float *pVolumes, UINT32 OperationSet)
{
1397
    XA2VoiceImpl *This = impl_from_IXAudio27SubmixVoice(iface);
1398 1399 1400 1401 1402 1403 1404
    return IXAudio2SubmixVoice_SetChannelVolumes(&This->IXAudio2SubmixVoice_iface,
            Channels, pVolumes, OperationSet);
}

static void WINAPI XA27SUB_GetChannelVolumes(IXAudio27SubmixVoice *iface,
        UINT32 Channels, float *pVolumes)
{
1405
    XA2VoiceImpl *This = impl_from_IXAudio27SubmixVoice(iface);
1406 1407 1408 1409 1410 1411 1412 1413 1414
    return IXAudio2SubmixVoice_GetChannelVolumes(&This->IXAudio2SubmixVoice_iface,
            Channels, pVolumes);
}

static HRESULT WINAPI XA27SUB_SetOutputMatrix(IXAudio27SubmixVoice *iface,
        IXAudio2Voice *pDestinationVoice, UINT32 SubmixChannels,
        UINT32 DestinationChannels, const float *pLevelMatrix,
        UINT32 OperationSet)
{
1415
    XA2VoiceImpl *This = impl_from_IXAudio27SubmixVoice(iface);
1416 1417 1418 1419 1420 1421 1422 1423 1424
    return IXAudio2SubmixVoice_SetOutputMatrix(&This->IXAudio2SubmixVoice_iface,
            pDestinationVoice, SubmixChannels, DestinationChannels,
            pLevelMatrix, OperationSet);
}

static void WINAPI XA27SUB_GetOutputMatrix(IXAudio27SubmixVoice *iface,
        IXAudio2Voice *pDestinationVoice, UINT32 SubmixChannels,
        UINT32 DestinationChannels, float *pLevelMatrix)
{
1425
    XA2VoiceImpl *This = impl_from_IXAudio27SubmixVoice(iface);
1426 1427 1428 1429 1430 1431 1432
    return IXAudio2SubmixVoice_GetOutputMatrix(&This->IXAudio2SubmixVoice_iface,
            pDestinationVoice, SubmixChannels, DestinationChannels,
            pLevelMatrix);
}

static void WINAPI XA27SUB_DestroyVoice(IXAudio27SubmixVoice *iface)
{
1433
    XA2VoiceImpl *This = impl_from_IXAudio27SubmixVoice(iface);
1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457
    return IXAudio2SubmixVoice_DestroyVoice(&This->IXAudio2SubmixVoice_iface);
}

const IXAudio27SubmixVoiceVtbl XAudio27SubmixVoice_Vtbl = {
    XA27SUB_GetVoiceDetails,
    XA27SUB_SetOutputVoices,
    XA27SUB_SetEffectChain,
    XA27SUB_EnableEffect,
    XA27SUB_DisableEffect,
    XA27SUB_GetEffectState,
    XA27SUB_SetEffectParameters,
    XA27SUB_GetEffectParameters,
    XA27SUB_SetFilterParameters,
    XA27SUB_GetFilterParameters,
    XA27SUB_SetOutputFilterParameters,
    XA27SUB_GetOutputFilterParameters,
    XA27SUB_SetVolume,
    XA27SUB_GetVolume,
    XA27SUB_SetChannelVolumes,
    XA27SUB_GetChannelVolumes,
    XA27SUB_SetOutputMatrix,
    XA27SUB_GetOutputMatrix,
    XA27SUB_DestroyVoice
};
1458 1459
#endif
/* END IXAudio2SubmixVoice */
1460

1461 1462 1463

/* BEGIN IXAudio2MasteringVoice */
#if XAUDIO2_VER == 0
1464
XA2VoiceImpl *impl_from_IXAudio20MasteringVoice(IXAudio20MasteringVoice *iface)
1465
{
1466
    return CONTAINING_RECORD(iface, XA2VoiceImpl, IXAudio20MasteringVoice_iface);
1467 1468
}

1469
static void WINAPI XA20M_GetVoiceDetails(IXAudio20MasteringVoice *iface,
1470
        XAUDIO27_VOICE_DETAILS *pVoiceDetails)
1471
{
1472
    XA2VoiceImpl *This = impl_from_IXAudio20MasteringVoice(iface);
1473 1474 1475 1476 1477 1478 1479
    XAUDIO2_VOICE_DETAILS details;

    IXAudio2MasteringVoice_GetVoiceDetails(&This->IXAudio2MasteringVoice_iface, &details);

    pVoiceDetails->CreationFlags = details.CreationFlags;
    pVoiceDetails->InputChannels = details.InputChannels;
    pVoiceDetails->InputSampleRate = details.InputSampleRate;
1480 1481
}

1482
static HRESULT WINAPI XA20M_SetOutputVoices(IXAudio20MasteringVoice *iface,
1483 1484
        const XAUDIO23_VOICE_SENDS *pSendList)
{
1485
    XA2VoiceImpl *This = impl_from_IXAudio20MasteringVoice(iface);
1486
    XAUDIO2_VOICE_SENDS sends, *psends = NULL;
1487 1488 1489 1490
    HRESULT hr;

    TRACE("%p, %p\n", This, pSendList);

1491 1492 1493 1494
    if(pSendList){
        sends.SendCount = pSendList->OutputCount;
        sends.pSends = convert_send_descriptors23(pSendList);
        psends = &sends;
1495 1496
    }

1497
    hr = IXAudio2MasteringVoice_SetOutputVoices(&This->IXAudio2MasteringVoice_iface, psends);
1498

1499 1500
    if(pSendList)
        HeapFree(GetProcessHeap(), 0, sends.pSends);
1501 1502 1503 1504

    return hr;
}

1505
static HRESULT WINAPI XA20M_SetEffectChain(IXAudio20MasteringVoice *iface,
1506 1507
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
{
1508
    XA2VoiceImpl *This = impl_from_IXAudio20MasteringVoice(iface);
1509
    return IXAudio2MasteringVoice_SetEffectChain(&This->IXAudio2MasteringVoice_iface, pEffectChain);
1510 1511
}

1512
static HRESULT WINAPI XA20M_EnableEffect(IXAudio20MasteringVoice *iface,
1513 1514
        UINT32 EffectIndex, UINT32 OperationSet)
{
1515
    XA2VoiceImpl *This = impl_from_IXAudio20MasteringVoice(iface);
1516
    return IXAudio2MasteringVoice_EnableEffect(&This->IXAudio2MasteringVoice_iface,
1517 1518 1519
            EffectIndex, OperationSet);
}

1520
static HRESULT WINAPI XA20M_DisableEffect(IXAudio20MasteringVoice *iface,
1521 1522
        UINT32 EffectIndex, UINT32 OperationSet)
{
1523
    XA2VoiceImpl *This = impl_from_IXAudio20MasteringVoice(iface);
1524
    return IXAudio2MasteringVoice_DisableEffect(&This->IXAudio2MasteringVoice_iface,
1525 1526 1527
            EffectIndex, OperationSet);
}

1528
static void WINAPI XA20M_GetEffectState(IXAudio20MasteringVoice *iface,
1529 1530
        UINT32 EffectIndex, BOOL *pEnabled)
{
1531
    XA2VoiceImpl *This = impl_from_IXAudio20MasteringVoice(iface);
1532
    return IXAudio2MasteringVoice_GetEffectState(&This->IXAudio2MasteringVoice_iface,
1533 1534 1535
            EffectIndex, pEnabled);
}

1536
static HRESULT WINAPI XA20M_SetEffectParameters(IXAudio20MasteringVoice *iface,
1537 1538 1539
        UINT32 EffectIndex, const void *pParameters, UINT32 ParametersByteSize,
        UINT32 OperationSet)
{
1540
    XA2VoiceImpl *This = impl_from_IXAudio20MasteringVoice(iface);
1541
    return IXAudio2MasteringVoice_SetEffectParameters(&This->IXAudio2MasteringVoice_iface,
1542 1543 1544
            EffectIndex, pParameters, ParametersByteSize, OperationSet);
}

1545
static HRESULT WINAPI XA20M_GetEffectParameters(IXAudio20MasteringVoice *iface,
1546 1547
        UINT32 EffectIndex, void *pParameters, UINT32 ParametersByteSize)
{
1548
    XA2VoiceImpl *This = impl_from_IXAudio20MasteringVoice(iface);
1549
    return IXAudio2MasteringVoice_GetEffectParameters(&This->IXAudio2MasteringVoice_iface,
1550 1551 1552
            EffectIndex, pParameters, ParametersByteSize);
}

1553
static HRESULT WINAPI XA20M_SetFilterParameters(IXAudio20MasteringVoice *iface,
1554 1555
        const XAUDIO2_FILTER_PARAMETERS *pParameters, UINT32 OperationSet)
{
1556
    XA2VoiceImpl *This = impl_from_IXAudio20MasteringVoice(iface);
1557
    return IXAudio2MasteringVoice_SetFilterParameters(&This->IXAudio2MasteringVoice_iface,
1558 1559 1560
            pParameters, OperationSet);
}

1561
static void WINAPI XA20M_GetFilterParameters(IXAudio20MasteringVoice *iface,
1562 1563
        XAUDIO2_FILTER_PARAMETERS *pParameters)
{
1564
    XA2VoiceImpl *This = impl_from_IXAudio20MasteringVoice(iface);
1565
    return IXAudio2MasteringVoice_GetFilterParameters(&This->IXAudio2MasteringVoice_iface, pParameters);
1566 1567
}

1568
static HRESULT WINAPI XA20M_SetVolume(IXAudio20MasteringVoice *iface,
1569 1570
        float Volume, UINT32 OperationSet)
{
1571
    XA2VoiceImpl *This = impl_from_IXAudio20MasteringVoice(iface);
1572
    return IXAudio2MasteringVoice_SetVolume(&This->IXAudio2MasteringVoice_iface,
1573 1574 1575
            Volume, OperationSet);
}

1576
static void WINAPI XA20M_GetVolume(IXAudio20MasteringVoice *iface,
1577 1578
        float *pVolume)
{
1579
    XA2VoiceImpl *This = impl_from_IXAudio20MasteringVoice(iface);
1580
    return IXAudio2MasteringVoice_GetVolume(&This->IXAudio2MasteringVoice_iface, pVolume);
1581 1582
}

1583
static HRESULT WINAPI XA20M_SetChannelVolumes(IXAudio20MasteringVoice *iface,
1584 1585
        UINT32 Channels, const float *pVolumes, UINT32 OperationSet)
{
1586
    XA2VoiceImpl *This = impl_from_IXAudio20MasteringVoice(iface);
1587
    return IXAudio2MasteringVoice_SetChannelVolumes(&This->IXAudio2MasteringVoice_iface,
1588 1589 1590
            Channels, pVolumes, OperationSet);
}

1591
static void WINAPI XA20M_GetChannelVolumes(IXAudio20MasteringVoice *iface,
1592 1593
        UINT32 Channels, float *pVolumes)
{
1594
    XA2VoiceImpl *This = impl_from_IXAudio20MasteringVoice(iface);
1595
    return IXAudio2MasteringVoice_GetChannelVolumes(&This->IXAudio2MasteringVoice_iface,
1596 1597 1598
            Channels, pVolumes);
}

1599 1600
static HRESULT WINAPI XA20M_SetOutputMatrix(IXAudio20MasteringVoice *iface,
        IXAudio2Voice *pDestinationVoice, UINT32 MasteringChannels,
1601 1602 1603
        UINT32 DestinationChannels, const float *pLevelMatrix,
        UINT32 OperationSet)
{
1604
    XA2VoiceImpl *This = impl_from_IXAudio20MasteringVoice(iface);
1605 1606
    return IXAudio2MasteringVoice_SetOutputMatrix(&This->IXAudio2MasteringVoice_iface,
            pDestinationVoice, MasteringChannels, DestinationChannels,
1607 1608 1609
            pLevelMatrix, OperationSet);
}

1610 1611
static HRESULT WINAPI XA20M_GetOutputMatrix(IXAudio20MasteringVoice *iface,
        IXAudio2Voice *pDestinationVoice, UINT32 MasteringChannels,
1612 1613
        UINT32 DestinationChannels, float *pLevelMatrix)
{
1614
    XA2VoiceImpl *This = impl_from_IXAudio20MasteringVoice(iface);
1615 1616
    IXAudio2MasteringVoice_GetOutputMatrix(&This->IXAudio2MasteringVoice_iface,
            pDestinationVoice, MasteringChannels, DestinationChannels,
1617 1618 1619 1620
            pLevelMatrix);
    return S_OK;
}

1621
static void WINAPI XA20M_DestroyVoice(IXAudio20MasteringVoice *iface)
1622
{
1623
    XA2VoiceImpl *This = impl_from_IXAudio20MasteringVoice(iface);
1624
    return IXAudio2MasteringVoice_DestroyVoice(&This->IXAudio2MasteringVoice_iface);
1625 1626
}

1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648
const IXAudio20MasteringVoiceVtbl XAudio20MasteringVoice_Vtbl = {
    XA20M_GetVoiceDetails,
    XA20M_SetOutputVoices,
    XA20M_SetEffectChain,
    XA20M_EnableEffect,
    XA20M_DisableEffect,
    XA20M_GetEffectState,
    XA20M_SetEffectParameters,
    XA20M_GetEffectParameters,
    XA20M_SetFilterParameters,
    XA20M_GetFilterParameters,
    XA20M_SetVolume,
    XA20M_GetVolume,
    XA20M_SetChannelVolumes,
    XA20M_GetChannelVolumes,
    XA20M_SetOutputMatrix,
    XA20M_GetOutputMatrix,
    XA20M_DestroyVoice
};

#elif XAUDIO2_VER <= 3

1649
XA2VoiceImpl *impl_from_IXAudio23MasteringVoice(IXAudio23MasteringVoice *iface)
1650
{
1651
    return CONTAINING_RECORD(iface, XA2VoiceImpl, IXAudio23MasteringVoice_iface);
1652 1653
}

1654
static void WINAPI XA23M_GetVoiceDetails(IXAudio23MasteringVoice *iface,
1655
        XAUDIO27_VOICE_DETAILS *pVoiceDetails)
1656
{
1657
    XA2VoiceImpl *This = impl_from_IXAudio23MasteringVoice(iface);
1658 1659 1660 1661 1662 1663 1664
    XAUDIO2_VOICE_DETAILS details;

    IXAudio2MasteringVoice_GetVoiceDetails(&This->IXAudio2MasteringVoice_iface, &details);

    pVoiceDetails->CreationFlags = details.CreationFlags;
    pVoiceDetails->InputChannels = details.InputChannels;
    pVoiceDetails->InputSampleRate = details.InputSampleRate;
1665 1666
}

1667 1668
static HRESULT WINAPI XA23M_SetOutputVoices(IXAudio23MasteringVoice *iface,
        const XAUDIO23_VOICE_SENDS *pSendList)
1669
{
1670
    XA2VoiceImpl *This = impl_from_IXAudio23MasteringVoice(iface);
1671
    XAUDIO2_VOICE_SENDS sends, *psends = NULL;
1672 1673 1674 1675
    HRESULT hr;

    TRACE("%p, %p\n", This, pSendList);

1676 1677 1678 1679
    if(pSendList){
        sends.SendCount = pSendList->OutputCount;
        sends.pSends = convert_send_descriptors23(pSendList);
        psends = &sends;
1680 1681
    }

1682
    hr = IXAudio2MasteringVoice_SetOutputVoices(&This->IXAudio2MasteringVoice_iface, psends);
1683

1684 1685
    if(pSendList)
        HeapFree(GetProcessHeap(), 0, sends.pSends);
1686 1687

    return hr;
1688 1689
}

1690 1691
static HRESULT WINAPI XA23M_SetEffectChain(IXAudio23MasteringVoice *iface,
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
1692
{
1693
    XA2VoiceImpl *This = impl_from_IXAudio23MasteringVoice(iface);
1694
    return IXAudio2MasteringVoice_SetEffectChain(&This->IXAudio2MasteringVoice_iface, pEffectChain);
1695 1696
}

1697 1698
static HRESULT WINAPI XA23M_EnableEffect(IXAudio23MasteringVoice *iface,
        UINT32 EffectIndex, UINT32 OperationSet)
1699
{
1700
    XA2VoiceImpl *This = impl_from_IXAudio23MasteringVoice(iface);
1701 1702
    return IXAudio2MasteringVoice_EnableEffect(&This->IXAudio2MasteringVoice_iface,
            EffectIndex, OperationSet);
1703 1704
}

1705 1706
static HRESULT WINAPI XA23M_DisableEffect(IXAudio23MasteringVoice *iface,
        UINT32 EffectIndex, UINT32 OperationSet)
1707
{
1708
    XA2VoiceImpl *This = impl_from_IXAudio23MasteringVoice(iface);
1709 1710
    return IXAudio2MasteringVoice_DisableEffect(&This->IXAudio2MasteringVoice_iface,
            EffectIndex, OperationSet);
1711 1712
}

1713 1714
static void WINAPI XA23M_GetEffectState(IXAudio23MasteringVoice *iface,
        UINT32 EffectIndex, BOOL *pEnabled)
1715
{
1716
    XA2VoiceImpl *This = impl_from_IXAudio23MasteringVoice(iface);
1717 1718
    return IXAudio2MasteringVoice_GetEffectState(&This->IXAudio2MasteringVoice_iface,
            EffectIndex, pEnabled);
1719 1720
}

1721 1722 1723
static HRESULT WINAPI XA23M_SetEffectParameters(IXAudio23MasteringVoice *iface,
        UINT32 EffectIndex, const void *pParameters, UINT32 ParametersByteSize,
        UINT32 OperationSet)
1724
{
1725
    XA2VoiceImpl *This = impl_from_IXAudio23MasteringVoice(iface);
1726 1727
    return IXAudio2MasteringVoice_SetEffectParameters(&This->IXAudio2MasteringVoice_iface,
            EffectIndex, pParameters, ParametersByteSize, OperationSet);
1728 1729
}

1730 1731 1732
static HRESULT WINAPI XA23M_GetEffectParameters(IXAudio23MasteringVoice *iface,
        UINT32 EffectIndex, void *pParameters, UINT32 ParametersByteSize)
{
1733
    XA2VoiceImpl *This = impl_from_IXAudio23MasteringVoice(iface);
1734 1735
    return IXAudio2MasteringVoice_GetEffectParameters(&This->IXAudio2MasteringVoice_iface,
            EffectIndex, pParameters, ParametersByteSize);
1736 1737
}

1738 1739 1740
static HRESULT WINAPI XA23M_SetFilterParameters(IXAudio23MasteringVoice *iface,
        const XAUDIO2_FILTER_PARAMETERS *pParameters, UINT32 OperationSet)
{
1741
    XA2VoiceImpl *This = impl_from_IXAudio23MasteringVoice(iface);
1742 1743 1744 1745 1746 1747 1748
    return IXAudio2MasteringVoice_SetFilterParameters(&This->IXAudio2MasteringVoice_iface,
            pParameters, OperationSet);
}

static void WINAPI XA23M_GetFilterParameters(IXAudio23MasteringVoice *iface,
        XAUDIO2_FILTER_PARAMETERS *pParameters)
{
1749
    XA2VoiceImpl *This = impl_from_IXAudio23MasteringVoice(iface);
1750 1751 1752 1753 1754 1755
    return IXAudio2MasteringVoice_GetFilterParameters(&This->IXAudio2MasteringVoice_iface, pParameters);
}

static HRESULT WINAPI XA23M_SetVolume(IXAudio23MasteringVoice *iface,
        float Volume, UINT32 OperationSet)
{
1756
    XA2VoiceImpl *This = impl_from_IXAudio23MasteringVoice(iface);
1757 1758 1759 1760 1761 1762 1763
    return IXAudio2MasteringVoice_SetVolume(&This->IXAudio2MasteringVoice_iface,
            Volume, OperationSet);
}

static void WINAPI XA23M_GetVolume(IXAudio23MasteringVoice *iface,
        float *pVolume)
{
1764
    XA2VoiceImpl *This = impl_from_IXAudio23MasteringVoice(iface);
1765 1766 1767 1768 1769 1770
    return IXAudio2MasteringVoice_GetVolume(&This->IXAudio2MasteringVoice_iface, pVolume);
}

static HRESULT WINAPI XA23M_SetChannelVolumes(IXAudio23MasteringVoice *iface,
        UINT32 Channels, const float *pVolumes, UINT32 OperationSet)
{
1771
    XA2VoiceImpl *This = impl_from_IXAudio23MasteringVoice(iface);
1772 1773 1774 1775 1776 1777 1778
    return IXAudio2MasteringVoice_SetChannelVolumes(&This->IXAudio2MasteringVoice_iface,
            Channels, pVolumes, OperationSet);
}

static void WINAPI XA23M_GetChannelVolumes(IXAudio23MasteringVoice *iface,
        UINT32 Channels, float *pVolumes)
{
1779
    XA2VoiceImpl *This = impl_from_IXAudio23MasteringVoice(iface);
1780 1781 1782 1783 1784 1785 1786 1787 1788
    return IXAudio2MasteringVoice_GetChannelVolumes(&This->IXAudio2MasteringVoice_iface,
            Channels, pVolumes);
}

static HRESULT WINAPI XA23M_SetOutputMatrix(IXAudio23MasteringVoice *iface,
        IXAudio2Voice *pDestinationVoice, UINT32 MasteringChannels,
        UINT32 DestinationChannels, const float *pLevelMatrix,
        UINT32 OperationSet)
{
1789
    XA2VoiceImpl *This = impl_from_IXAudio23MasteringVoice(iface);
1790 1791 1792 1793 1794 1795 1796 1797 1798
    return IXAudio2MasteringVoice_SetOutputMatrix(&This->IXAudio2MasteringVoice_iface,
            pDestinationVoice, MasteringChannels, DestinationChannels,
            pLevelMatrix, OperationSet);
}

static void WINAPI XA23M_GetOutputMatrix(IXAudio23MasteringVoice *iface,
        IXAudio2Voice *pDestinationVoice, UINT32 MasteringChannels,
        UINT32 DestinationChannels, float *pLevelMatrix)
{
1799
    XA2VoiceImpl *This = impl_from_IXAudio23MasteringVoice(iface);
1800 1801 1802 1803 1804 1805 1806
    return IXAudio2MasteringVoice_GetOutputMatrix(&This->IXAudio2MasteringVoice_iface,
            pDestinationVoice, MasteringChannels, DestinationChannels,
            pLevelMatrix);
}

static void WINAPI XA23M_DestroyVoice(IXAudio23MasteringVoice *iface)
{
1807
    XA2VoiceImpl *This = impl_from_IXAudio23MasteringVoice(iface);
1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828
    return IXAudio2MasteringVoice_DestroyVoice(&This->IXAudio2MasteringVoice_iface);
}

const IXAudio23MasteringVoiceVtbl XAudio23MasteringVoice_Vtbl = {
    XA23M_GetVoiceDetails,
    XA23M_SetOutputVoices,
    XA23M_SetEffectChain,
    XA23M_EnableEffect,
    XA23M_DisableEffect,
    XA23M_GetEffectState,
    XA23M_SetEffectParameters,
    XA23M_GetEffectParameters,
    XA23M_SetFilterParameters,
    XA23M_GetFilterParameters,
    XA23M_SetVolume,
    XA23M_GetVolume,
    XA23M_SetChannelVolumes,
    XA23M_GetChannelVolumes,
    XA23M_SetOutputMatrix,
    XA23M_GetOutputMatrix,
    XA23M_DestroyVoice
1829
};
1830 1831 1832

#elif XAUDIO2_VER <= 7

1833
XA2VoiceImpl *impl_from_IXAudio27MasteringVoice(IXAudio27MasteringVoice *iface)
1834
{
1835
    return CONTAINING_RECORD(iface, XA2VoiceImpl, IXAudio27MasteringVoice_iface);
1836 1837 1838 1839 1840
}

static void WINAPI XA27M_GetVoiceDetails(IXAudio27MasteringVoice *iface,
        XAUDIO27_VOICE_DETAILS *pVoiceDetails)
{
1841
    XA2VoiceImpl *This = impl_from_IXAudio27MasteringVoice(iface);
1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853
    XAUDIO2_VOICE_DETAILS details;

    IXAudio2MasteringVoice_GetVoiceDetails(&This->IXAudio2MasteringVoice_iface, &details);

    pVoiceDetails->CreationFlags = details.CreationFlags;
    pVoiceDetails->InputChannels = details.InputChannels;
    pVoiceDetails->InputSampleRate = details.InputSampleRate;
}

static HRESULT WINAPI XA27M_SetOutputVoices(IXAudio27MasteringVoice *iface,
        const XAUDIO2_VOICE_SENDS *pSendList)
{
1854
    XA2VoiceImpl *This = impl_from_IXAudio27MasteringVoice(iface);
1855 1856 1857 1858 1859 1860
    return IXAudio2MasteringVoice_SetOutputVoices(&This->IXAudio2MasteringVoice_iface, pSendList);
}

static HRESULT WINAPI XA27M_SetEffectChain(IXAudio27MasteringVoice *iface,
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
{
1861
    XA2VoiceImpl *This = impl_from_IXAudio27MasteringVoice(iface);
1862 1863 1864 1865 1866 1867
    return IXAudio2MasteringVoice_SetEffectChain(&This->IXAudio2MasteringVoice_iface, pEffectChain);
}

static HRESULT WINAPI XA27M_EnableEffect(IXAudio27MasteringVoice *iface,
        UINT32 EffectIndex, UINT32 OperationSet)
{
1868
    XA2VoiceImpl *This = impl_from_IXAudio27MasteringVoice(iface);
1869 1870 1871 1872 1873 1874 1875
    return IXAudio2MasteringVoice_EnableEffect(&This->IXAudio2MasteringVoice_iface,
            EffectIndex, OperationSet);
}

static HRESULT WINAPI XA27M_DisableEffect(IXAudio27MasteringVoice *iface,
        UINT32 EffectIndex, UINT32 OperationSet)
{
1876
    XA2VoiceImpl *This = impl_from_IXAudio27MasteringVoice(iface);
1877 1878 1879 1880 1881 1882 1883
    return IXAudio2MasteringVoice_DisableEffect(&This->IXAudio2MasteringVoice_iface,
            EffectIndex, OperationSet);
}

static void WINAPI XA27M_GetEffectState(IXAudio27MasteringVoice *iface,
        UINT32 EffectIndex, BOOL *pEnabled)
{
1884
    XA2VoiceImpl *This = impl_from_IXAudio27MasteringVoice(iface);
1885 1886 1887 1888 1889 1890 1891 1892
    return IXAudio2MasteringVoice_GetEffectState(&This->IXAudio2MasteringVoice_iface,
            EffectIndex, pEnabled);
}

static HRESULT WINAPI XA27M_SetEffectParameters(IXAudio27MasteringVoice *iface,
        UINT32 EffectIndex, const void *pParameters, UINT32 ParametersByteSize,
        UINT32 OperationSet)
{
1893
    XA2VoiceImpl *This = impl_from_IXAudio27MasteringVoice(iface);
1894 1895 1896 1897 1898 1899 1900
    return IXAudio2MasteringVoice_SetEffectParameters(&This->IXAudio2MasteringVoice_iface,
            EffectIndex, pParameters, ParametersByteSize, OperationSet);
}

static HRESULT WINAPI XA27M_GetEffectParameters(IXAudio27MasteringVoice *iface,
        UINT32 EffectIndex, void *pParameters, UINT32 ParametersByteSize)
{
1901
    XA2VoiceImpl *This = impl_from_IXAudio27MasteringVoice(iface);
1902 1903 1904 1905 1906 1907 1908
    return IXAudio2MasteringVoice_GetEffectParameters(&This->IXAudio2MasteringVoice_iface,
            EffectIndex, pParameters, ParametersByteSize);
}

static HRESULT WINAPI XA27M_SetFilterParameters(IXAudio27MasteringVoice *iface,
        const XAUDIO2_FILTER_PARAMETERS *pParameters, UINT32 OperationSet)
{
1909
    XA2VoiceImpl *This = impl_from_IXAudio27MasteringVoice(iface);
1910 1911 1912 1913 1914 1915 1916
    return IXAudio2MasteringVoice_SetFilterParameters(&This->IXAudio2MasteringVoice_iface,
            pParameters, OperationSet);
}

static void WINAPI XA27M_GetFilterParameters(IXAudio27MasteringVoice *iface,
        XAUDIO2_FILTER_PARAMETERS *pParameters)
{
1917
    XA2VoiceImpl *This = impl_from_IXAudio27MasteringVoice(iface);
1918 1919 1920 1921 1922 1923 1924
    return IXAudio2MasteringVoice_GetFilterParameters(&This->IXAudio2MasteringVoice_iface, pParameters);
}

static HRESULT WINAPI XA27M_SetOutputFilterParameters(IXAudio27MasteringVoice *iface,
        IXAudio2Voice *pDestinationVoice,
        const XAUDIO2_FILTER_PARAMETERS *pParameters, UINT32 OperationSet)
{
1925
    XA2VoiceImpl *This = impl_from_IXAudio27MasteringVoice(iface);
1926 1927 1928 1929 1930 1931 1932 1933
    return IXAudio2MasteringVoice_SetOutputFilterParameters(&This->IXAudio2MasteringVoice_iface,
            pDestinationVoice, pParameters, OperationSet);
}

static void WINAPI XA27M_GetOutputFilterParameters(IXAudio27MasteringVoice *iface,
        IXAudio2Voice *pDestinationVoice,
        XAUDIO2_FILTER_PARAMETERS *pParameters)
{
1934
    XA2VoiceImpl *This = impl_from_IXAudio27MasteringVoice(iface);
1935 1936 1937 1938 1939 1940 1941
    IXAudio2MasteringVoice_GetOutputFilterParameters(&This->IXAudio2MasteringVoice_iface,
            pDestinationVoice, pParameters);
}

static HRESULT WINAPI XA27M_SetVolume(IXAudio27MasteringVoice *iface,
        float Volume, UINT32 OperationSet)
{
1942
    XA2VoiceImpl *This = impl_from_IXAudio27MasteringVoice(iface);
1943 1944 1945 1946 1947 1948 1949
    return IXAudio2MasteringVoice_SetVolume(&This->IXAudio2MasteringVoice_iface,
            Volume, OperationSet);
}

static void WINAPI XA27M_GetVolume(IXAudio27MasteringVoice *iface,
        float *pVolume)
{
1950
    XA2VoiceImpl *This = impl_from_IXAudio27MasteringVoice(iface);
1951 1952 1953 1954 1955 1956
    return IXAudio2MasteringVoice_GetVolume(&This->IXAudio2MasteringVoice_iface, pVolume);
}

static HRESULT WINAPI XA27M_SetChannelVolumes(IXAudio27MasteringVoice *iface,
        UINT32 Channels, const float *pVolumes, UINT32 OperationSet)
{
1957
    XA2VoiceImpl *This = impl_from_IXAudio27MasteringVoice(iface);
1958 1959 1960 1961 1962 1963 1964
    return IXAudio2MasteringVoice_SetChannelVolumes(&This->IXAudio2MasteringVoice_iface,
            Channels, pVolumes, OperationSet);
}

static void WINAPI XA27M_GetChannelVolumes(IXAudio27MasteringVoice *iface,
        UINT32 Channels, float *pVolumes)
{
1965
    XA2VoiceImpl *This = impl_from_IXAudio27MasteringVoice(iface);
1966 1967 1968 1969 1970 1971 1972 1973 1974
    return IXAudio2MasteringVoice_GetChannelVolumes(&This->IXAudio2MasteringVoice_iface,
            Channels, pVolumes);
}

static HRESULT WINAPI XA27M_SetOutputMatrix(IXAudio27MasteringVoice *iface,
        IXAudio2Voice *pDestinationVoice, UINT32 MasteringChannels,
        UINT32 DestinationChannels, const float *pLevelMatrix,
        UINT32 OperationSet)
{
1975
    XA2VoiceImpl *This = impl_from_IXAudio27MasteringVoice(iface);
1976 1977 1978 1979 1980 1981 1982 1983 1984
    return IXAudio2MasteringVoice_SetOutputMatrix(&This->IXAudio2MasteringVoice_iface,
            pDestinationVoice, MasteringChannels, DestinationChannels,
            pLevelMatrix, OperationSet);
}

static void WINAPI XA27M_GetOutputMatrix(IXAudio27MasteringVoice *iface,
        IXAudio2Voice *pDestinationVoice, UINT32 MasteringChannels,
        UINT32 DestinationChannels, float *pLevelMatrix)
{
1985
    XA2VoiceImpl *This = impl_from_IXAudio27MasteringVoice(iface);
1986 1987 1988 1989 1990 1991 1992
    return IXAudio2MasteringVoice_GetOutputMatrix(&This->IXAudio2MasteringVoice_iface,
            pDestinationVoice, MasteringChannels, DestinationChannels,
            pLevelMatrix);
}

static void WINAPI XA27M_DestroyVoice(IXAudio27MasteringVoice *iface)
{
1993
    XA2VoiceImpl *This = impl_from_IXAudio27MasteringVoice(iface);
1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017
    return IXAudio2MasteringVoice_DestroyVoice(&This->IXAudio2MasteringVoice_iface);
}

const IXAudio27MasteringVoiceVtbl XAudio27MasteringVoice_Vtbl = {
    XA27M_GetVoiceDetails,
    XA27M_SetOutputVoices,
    XA27M_SetEffectChain,
    XA27M_EnableEffect,
    XA27M_DisableEffect,
    XA27M_GetEffectState,
    XA27M_SetEffectParameters,
    XA27M_GetEffectParameters,
    XA27M_SetFilterParameters,
    XA27M_GetFilterParameters,
    XA27M_SetOutputFilterParameters,
    XA27M_GetOutputFilterParameters,
    XA27M_SetVolume,
    XA27M_GetVolume,
    XA27M_SetChannelVolumes,
    XA27M_GetChannelVolumes,
    XA27M_SetOutputMatrix,
    XA27M_GetOutputMatrix,
    XA27M_DestroyVoice
};
2018 2019
#endif
/* END IXAudio2MasteringVoice */
2020

2021 2022 2023 2024

/* BEGIN IXAudio2 */
#if XAUDIO2_VER == 0
static inline IXAudio2Impl *impl_from_IXAudio20(IXAudio20 *iface)
2025
{
2026
    return CONTAINING_RECORD(iface, IXAudio2Impl, IXAudio20_iface);
2027 2028
}

2029 2030
static HRESULT WINAPI XA20_QueryInterface(IXAudio20 *iface, REFIID riid,
        void **ppvObject)
2031
{
2032 2033
    IXAudio2Impl *This = impl_from_IXAudio20(iface);
    return IXAudio2_QueryInterface(&This->IXAudio2_iface, riid, ppvObject);
2034 2035
}

2036
static ULONG WINAPI XA20_AddRef(IXAudio20 *iface)
2037
{
2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051
    IXAudio2Impl *This = impl_from_IXAudio20(iface);
    return IXAudio2_AddRef(&This->IXAudio2_iface);
}

static ULONG WINAPI XA20_Release(IXAudio20 *iface)
{
    IXAudio2Impl *This = impl_from_IXAudio20(iface);
    return IXAudio2_Release(&This->IXAudio2_iface);
}

static HRESULT WINAPI XA20_GetDeviceCount(IXAudio20 *iface, UINT32 *pCount)
{
    IXAudio2Impl *This = impl_from_IXAudio20(iface);
    TRACE("%p, %p\n", This, pCount);
2052
    return FAudio_GetDeviceCount(This->faudio, pCount);
2053 2054 2055 2056 2057 2058 2059
}

static HRESULT WINAPI XA20_GetDeviceDetails(IXAudio20 *iface, UINT32 index,
        XAUDIO2_DEVICE_DETAILS *pDeviceDetails)
{
    IXAudio2Impl *This = impl_from_IXAudio20(iface);
    TRACE("%p, %u, %p\n", This, index, pDeviceDetails);
2060
    return FAudio_GetDeviceDetails(This->faudio, index, (FAudioDeviceDetails *)pDeviceDetails);
2061 2062
}

2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087
static HRESULT WINAPI XA20_Initialize(IXAudio20 *iface, UINT32 flags,
        XAUDIO2_PROCESSOR processor)
{
    IXAudio2Impl *This = impl_from_IXAudio20(iface);
    TRACE("(%p)->(0x%x, 0x%x)\n", This, flags, processor);
    return xaudio2_initialize(This, flags, processor);
}

static HRESULT WINAPI XA20_RegisterForCallbacks(IXAudio20 *iface,
        IXAudio2EngineCallback *pCallback)
{
    IXAudio2Impl *This = impl_from_IXAudio20(iface);
    return IXAudio2_RegisterForCallbacks(&This->IXAudio2_iface, pCallback);
}

static void WINAPI XA20_UnregisterForCallbacks(IXAudio20 *iface,
        IXAudio2EngineCallback *pCallback)
{
    IXAudio2Impl *This = impl_from_IXAudio20(iface);
    return IXAudio2_UnregisterForCallbacks(&This->IXAudio2_iface, pCallback);
}

static HRESULT WINAPI XA20_CreateSourceVoice(IXAudio20 *iface,
        IXAudio2SourceVoice **ppSourceVoice, const WAVEFORMATEX *pSourceFormat,
        UINT32 flags, float maxFrequencyRatio,
2088
        IXAudio2VoiceCallback *pCallback, const XAUDIO23_VOICE_SENDS *pSendList,
2089 2090
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
{
2091
    IXAudio2Impl *This = impl_from_IXAudio20(iface);
2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102
    XAUDIO2_VOICE_SENDS sends, *psends = NULL;
    HRESULT hr;

    if(pSendList){
        sends.SendCount = pSendList->OutputCount;
        sends.pSends = convert_send_descriptors23(pSendList);
        psends = &sends;
    }

    hr = IXAudio2_CreateSourceVoice(&This->IXAudio2_iface, ppSourceVoice,
            pSourceFormat, flags, maxFrequencyRatio, pCallback, psends,
2103
            pEffectChain);
2104 2105 2106 2107 2108

    if(pSendList)
        HeapFree(GetProcessHeap(), 0, sends.pSends);

    return hr;
2109 2110
}

2111 2112 2113
static HRESULT WINAPI XA20_CreateSubmixVoice(IXAudio20 *iface,
        IXAudio2SubmixVoice **ppSubmixVoice, UINT32 inputChannels,
        UINT32 inputSampleRate, UINT32 flags, UINT32 processingStage,
2114
        const XAUDIO23_VOICE_SENDS *pSendList,
2115
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
2116
{
2117
    IXAudio2Impl *This = impl_from_IXAudio20(iface);
2118
    XAUDIO2_VOICE_SENDS sends, *psends = NULL;
2119 2120 2121 2122 2123 2124 2125 2126 2127 2128
    HRESULT hr;

    if(pSendList){
        sends.SendCount = pSendList->OutputCount;
        sends.pSends = convert_send_descriptors23(pSendList);
        psends = &sends;
    }

    hr = IXAudio2_CreateSubmixVoice(&This->IXAudio2_iface, ppSubmixVoice,
            inputChannels, inputSampleRate, flags, processingStage, psends,
2129
            pEffectChain);
2130 2131 2132 2133 2134

    if(pSendList)
        HeapFree(GetProcessHeap(), 0, sends.pSends);

    return hr;
2135 2136
}

2137 2138 2139 2140
static HRESULT WINAPI XA20_CreateMasteringVoice(IXAudio20 *iface,
        IXAudio2MasteringVoice **ppMasteringVoice, UINT32 inputChannels,
        UINT32 inputSampleRate, UINT32 flags, UINT32 deviceIndex,
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
2141
{
2142 2143 2144 2145 2146 2147
    IXAudio2Impl *This = impl_from_IXAudio20(iface);

    TRACE("(%p)->(%p, %u, %u, 0x%x, %u, %p)\n", This, ppMasteringVoice,
            inputChannels, inputSampleRate, flags, deviceIndex,
            pEffectChain);

2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161
    EnterCriticalSection(&This->lock);

    /* XAUDIO2_VER == 0 */
    *ppMasteringVoice = (IXAudio2MasteringVoice*)&This->mst.IXAudio20MasteringVoice_iface;

    EnterCriticalSection(&This->mst.lock);

    if(This->mst.in_use){
        LeaveCriticalSection(&This->mst.lock);
        LeaveCriticalSection(&This->lock);
        return COMPAT_E_INVALID_CALL;
    }

    LeaveCriticalSection(&This->lock);
2162

2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182
    This->mst.effect_chain = wrap_effect_chain(pEffectChain);

    pthread_mutex_lock(&This->mst.engine_lock);

    This->mst.engine_thread = CreateThread(NULL, 0, &engine_thread, &This->mst, 0, NULL);

    pthread_cond_wait(&This->mst.engine_done, &This->mst.engine_lock);

    pthread_mutex_unlock(&This->mst.engine_lock);

    FAudio_SetEngineProcedureEXT(This->faudio, &engine_cb, &This->mst);

    FAudio_CreateMasteringVoice(This->faudio, &This->mst.faudio_voice, inputChannels,
            inputSampleRate, flags, deviceIndex, This->mst.effect_chain);

    This->mst.in_use = TRUE;

    LeaveCriticalSection(&This->mst.lock);

    return S_OK;
2183 2184
}

2185
static HRESULT WINAPI XA20_StartEngine(IXAudio20 *iface)
2186
{
2187 2188
    IXAudio2Impl *This = impl_from_IXAudio20(iface);
    return IXAudio2_StartEngine(&This->IXAudio2_iface);
2189 2190
}

2191
static void WINAPI XA20_StopEngine(IXAudio20 *iface)
2192
{
2193 2194
    IXAudio2Impl *This = impl_from_IXAudio20(iface);
    return IXAudio2_StopEngine(&This->IXAudio2_iface);
2195 2196
}

2197
static HRESULT WINAPI XA20_CommitChanges(IXAudio20 *iface, UINT32 operationSet)
2198
{
2199 2200
    IXAudio2Impl *This = impl_from_IXAudio20(iface);
    return IXAudio2_CommitChanges(&This->IXAudio2_iface, operationSet);
2201 2202
}

2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257
static void WINAPI XA20_GetPerformanceData(IXAudio20 *iface,
        XAUDIO20_PERFORMANCE_DATA *pPerfData)
{
    IXAudio2Impl *This = impl_from_IXAudio20(iface);
    XAUDIO2_PERFORMANCE_DATA data;

    IXAudio2_GetPerformanceData(&This->IXAudio2_iface, &data);

    pPerfData->AudioCyclesSinceLastQuery = data.AudioCyclesSinceLastQuery;
    pPerfData->TotalCyclesSinceLastQuery = data.TotalCyclesSinceLastQuery;
    pPerfData->MinimumCyclesPerQuantum = data.MinimumCyclesPerQuantum;
    pPerfData->MaximumCyclesPerQuantum = data.MaximumCyclesPerQuantum;
    pPerfData->MemoryUsageInBytes = data.MemoryUsageInBytes;
    pPerfData->CurrentLatencyInSamples = data.CurrentLatencyInSamples;
    pPerfData->GlitchesSinceLastQuery = data.GlitchesSinceEngineStarted - This->last_query_glitches;
    This->last_query_glitches = data.GlitchesSinceEngineStarted;
    pPerfData->ActiveSourceVoiceCount = data.ActiveSourceVoiceCount;
    pPerfData->TotalSourceVoiceCount = data.TotalSourceVoiceCount;

    pPerfData->ActiveSubmixVoiceCount = data.ActiveSubmixVoiceCount;
    pPerfData->TotalSubmixVoiceCount = data.ActiveSubmixVoiceCount;

    pPerfData->ActiveXmaSourceVoices = data.ActiveXmaSourceVoices;
    pPerfData->ActiveXmaStreams = data.ActiveXmaStreams;
}

static void WINAPI XA20_SetDebugConfiguration(IXAudio20 *iface,
        const XAUDIO2_DEBUG_CONFIGURATION *pDebugConfiguration,
        void *pReserved)
{
    IXAudio2Impl *This = impl_from_IXAudio20(iface);
    return IXAudio2_SetDebugConfiguration(&This->IXAudio2_iface,
            pDebugConfiguration, pReserved);
}

const IXAudio20Vtbl XAudio20_Vtbl = {
    XA20_QueryInterface,
    XA20_AddRef,
    XA20_Release,
    XA20_GetDeviceCount,
    XA20_GetDeviceDetails,
    XA20_Initialize,
    XA20_RegisterForCallbacks,
    XA20_UnregisterForCallbacks,
    XA20_CreateSourceVoice,
    XA20_CreateSubmixVoice,
    XA20_CreateMasteringVoice,
    XA20_StartEngine,
    XA20_StopEngine,
    XA20_CommitChanges,
    XA20_GetPerformanceData,
    XA20_SetDebugConfiguration
};

#elif XAUDIO2_VER <= 2
2258

2259
static inline IXAudio2Impl *impl_from_IXAudio22(IXAudio22 *iface)
2260
{
2261
    return CONTAINING_RECORD(iface, IXAudio2Impl, IXAudio22_iface);
2262 2263
}

2264 2265
static HRESULT WINAPI XA22_QueryInterface(IXAudio22 *iface, REFIID riid,
        void **ppvObject)
2266
{
2267 2268
    IXAudio2Impl *This = impl_from_IXAudio22(iface);
    return IXAudio2_QueryInterface(&This->IXAudio2_iface, riid, ppvObject);
2269 2270
}

2271
static ULONG WINAPI XA22_AddRef(IXAudio22 *iface)
2272
{
2273 2274
    IXAudio2Impl *This = impl_from_IXAudio22(iface);
    return IXAudio2_AddRef(&This->IXAudio2_iface);
2275 2276
}

2277
static ULONG WINAPI XA22_Release(IXAudio22 *iface)
2278
{
2279 2280
    IXAudio2Impl *This = impl_from_IXAudio22(iface);
    return IXAudio2_Release(&This->IXAudio2_iface);
2281 2282
}

2283
static HRESULT WINAPI XA22_GetDeviceCount(IXAudio22 *iface, UINT32 *pCount)
2284
{
2285 2286
    IXAudio2Impl *This = impl_from_IXAudio22(iface);
    TRACE("%p, %p\n", This, pCount);
2287
    return FAudio_GetDeviceCount(This->faudio, pCount);
2288 2289
}

2290 2291
static HRESULT WINAPI XA22_GetDeviceDetails(IXAudio22 *iface, UINT32 index,
        XAUDIO2_DEVICE_DETAILS *pDeviceDetails)
2292
{
2293 2294
    IXAudio2Impl *This = impl_from_IXAudio22(iface);
    TRACE("%p, %u, %p\n", This, index, pDeviceDetails);
2295
    return FAudio_GetDeviceDetails(This->faudio, index, (FAudioDeviceDetails *)pDeviceDetails);
2296 2297
}

2298 2299
static HRESULT WINAPI XA22_Initialize(IXAudio22 *iface, UINT32 flags,
        XAUDIO2_PROCESSOR processor)
2300
{
2301 2302 2303
    IXAudio2Impl *This = impl_from_IXAudio22(iface);
    TRACE("(%p)->(0x%x, 0x%x)\n", This, flags, processor);
    return xaudio2_initialize(This, flags, processor);
2304 2305
}

2306 2307
static HRESULT WINAPI XA22_RegisterForCallbacks(IXAudio22 *iface,
        IXAudio2EngineCallback *pCallback)
2308
{
2309 2310
    IXAudio2Impl *This = impl_from_IXAudio22(iface);
    return IXAudio2_RegisterForCallbacks(&This->IXAudio2_iface, pCallback);
2311 2312
}

2313 2314
static void WINAPI XA22_UnregisterForCallbacks(IXAudio22 *iface,
        IXAudio2EngineCallback *pCallback)
2315
{
2316 2317
    IXAudio2Impl *This = impl_from_IXAudio22(iface);
    IXAudio2_UnregisterForCallbacks(&This->IXAudio2_iface, pCallback);
2318 2319
}

2320 2321 2322
static HRESULT WINAPI XA22_CreateSourceVoice(IXAudio22 *iface,
        IXAudio2SourceVoice **ppSourceVoice, const WAVEFORMATEX *pSourceFormat,
        UINT32 flags, float maxFrequencyRatio,
2323
        IXAudio2VoiceCallback *pCallback, const XAUDIO23_VOICE_SENDS *pSendList,
2324
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
2325
{
2326
    IXAudio2Impl *This = impl_from_IXAudio22(iface);
2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337
    XAUDIO2_VOICE_SENDS sends, *psends = NULL;
    HRESULT hr;

    if(pSendList){
        sends.SendCount = pSendList->OutputCount;
        sends.pSends = convert_send_descriptors23(pSendList);
        psends = &sends;
    }

    hr = IXAudio2_CreateSourceVoice(&This->IXAudio2_iface, ppSourceVoice,
            pSourceFormat, flags, maxFrequencyRatio, pCallback, psends,
2338
            pEffectChain);
2339 2340 2341 2342 2343

    if(pSendList)
        HeapFree(GetProcessHeap(), 0, sends.pSends);

    return hr;
2344 2345
}

2346 2347 2348
static HRESULT WINAPI XA22_CreateSubmixVoice(IXAudio22 *iface,
        IXAudio2SubmixVoice **ppSubmixVoice, UINT32 inputChannels,
        UINT32 inputSampleRate, UINT32 flags, UINT32 processingStage,
2349
        const XAUDIO23_VOICE_SENDS *pSendList,
2350
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
2351
{
2352
    IXAudio2Impl *This = impl_from_IXAudio22(iface);
2353
    XAUDIO2_VOICE_SENDS sends, *psends = NULL;
2354 2355 2356 2357 2358 2359 2360 2361 2362 2363
    HRESULT hr;

    if(pSendList){
        sends.SendCount = pSendList->OutputCount;
        sends.pSends = convert_send_descriptors23(pSendList);
        psends = &sends;
    }

    hr = IXAudio2_CreateSubmixVoice(&This->IXAudio2_iface, ppSubmixVoice,
            inputChannels, inputSampleRate, flags, processingStage, psends,
2364
            pEffectChain);
2365 2366 2367 2368 2369

    if(pSendList)
        HeapFree(GetProcessHeap(), 0, sends.pSends);

    return hr;
2370 2371
}

2372 2373 2374 2375
static HRESULT WINAPI XA22_CreateMasteringVoice(IXAudio22 *iface,
        IXAudio2MasteringVoice **ppMasteringVoice, UINT32 inputChannels,
        UINT32 inputSampleRate, UINT32 flags, UINT32 deviceIndex,
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
2376
{
2377 2378 2379 2380 2381 2382
    IXAudio2Impl *This = impl_from_IXAudio22(iface);

    TRACE("(%p)->(%p, %u, %u, 0x%x, %u, %p)\n", This, ppMasteringVoice,
            inputChannels, inputSampleRate, flags, deviceIndex,
            pEffectChain);

2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408
    EnterCriticalSection(&This->lock);

    /* 1 <= XAUDIO2_VER <= 2 */
    *ppMasteringVoice = (IXAudio2MasteringVoice*)&This->mst.IXAudio23MasteringVoice_iface;

    EnterCriticalSection(&This->mst.lock);

    if(This->mst.in_use){
        LeaveCriticalSection(&This->mst.lock);
        LeaveCriticalSection(&This->lock);
        return COMPAT_E_INVALID_CALL;
    }

    LeaveCriticalSection(&This->lock);

    This->mst.effect_chain = wrap_effect_chain(pEffectChain);

    pthread_mutex_lock(&This->mst.engine_lock);

    This->mst.engine_thread = CreateThread(NULL, 0, &engine_thread, &This->mst, 0, NULL);

    pthread_cond_wait(&This->mst.engine_done, &This->mst.engine_lock);

    pthread_mutex_unlock(&This->mst.engine_lock);

    FAudio_SetEngineProcedureEXT(This->faudio, &engine_cb, &This->mst);
2409

2410 2411 2412 2413 2414 2415 2416 2417
    FAudio_CreateMasteringVoice(This->faudio, &This->mst.faudio_voice, inputChannels,
            inputSampleRate, flags, deviceIndex, This->mst.effect_chain);

    This->mst.in_use = TRUE;

    LeaveCriticalSection(&This->mst.lock);

    return S_OK;
2418 2419
}

2420
static HRESULT WINAPI XA22_StartEngine(IXAudio22 *iface)
2421
{
2422 2423
    IXAudio2Impl *This = impl_from_IXAudio22(iface);
    return IXAudio2_StartEngine(&This->IXAudio2_iface);
2424 2425
}

2426
static void WINAPI XA22_StopEngine(IXAudio22 *iface)
2427
{
2428 2429
    IXAudio2Impl *This = impl_from_IXAudio22(iface);
    return IXAudio2_StopEngine(&This->IXAudio2_iface);
2430 2431
}

2432
static HRESULT WINAPI XA22_CommitChanges(IXAudio22 *iface, UINT32 operationSet)
2433
{
2434 2435
    IXAudio2Impl *This = impl_from_IXAudio22(iface);
    return IXAudio2_CommitChanges(&This->IXAudio2_iface, operationSet);
2436 2437
}

2438 2439
static void WINAPI XA22_GetPerformanceData(IXAudio22 *iface,
        XAUDIO22_PERFORMANCE_DATA *pPerfData)
2440
{
2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460
    IXAudio2Impl *This = impl_from_IXAudio22(iface);
    XAUDIO2_PERFORMANCE_DATA data;

    IXAudio2_GetPerformanceData(&This->IXAudio2_iface, &data);

    pPerfData->AudioCyclesSinceLastQuery = data.AudioCyclesSinceLastQuery;
    pPerfData->TotalCyclesSinceLastQuery = data.TotalCyclesSinceLastQuery;
    pPerfData->MinimumCyclesPerQuantum = data.MinimumCyclesPerQuantum;
    pPerfData->MaximumCyclesPerQuantum = data.MaximumCyclesPerQuantum;
    pPerfData->MemoryUsageInBytes = data.MemoryUsageInBytes;
    pPerfData->CurrentLatencyInSamples = data.CurrentLatencyInSamples;
    pPerfData->GlitchesSinceEngineStarted = data.GlitchesSinceEngineStarted;
    pPerfData->ActiveSourceVoiceCount = data.ActiveSourceVoiceCount;
    pPerfData->TotalSourceVoiceCount = data.TotalSourceVoiceCount;

    pPerfData->ActiveSubmixVoiceCount = data.ActiveSubmixVoiceCount;
    pPerfData->TotalSubmixVoiceCount = data.ActiveSubmixVoiceCount;

    pPerfData->ActiveXmaSourceVoices = data.ActiveXmaSourceVoices;
    pPerfData->ActiveXmaStreams = data.ActiveXmaStreams;
2461 2462
}

2463 2464 2465
static void WINAPI XA22_SetDebugConfiguration(IXAudio22 *iface,
        const XAUDIO2_DEBUG_CONFIGURATION *pDebugConfiguration,
        void *pReserved)
2466
{
2467 2468 2469
    IXAudio2Impl *This = impl_from_IXAudio22(iface);
    return IXAudio2_SetDebugConfiguration(&This->IXAudio2_iface,
            pDebugConfiguration, pReserved);
2470 2471
}

2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488
const IXAudio22Vtbl XAudio22_Vtbl = {
    XA22_QueryInterface,
    XA22_AddRef,
    XA22_Release,
    XA22_GetDeviceCount,
    XA22_GetDeviceDetails,
    XA22_Initialize,
    XA22_RegisterForCallbacks,
    XA22_UnregisterForCallbacks,
    XA22_CreateSourceVoice,
    XA22_CreateSubmixVoice,
    XA22_CreateMasteringVoice,
    XA22_StartEngine,
    XA22_StopEngine,
    XA22_CommitChanges,
    XA22_GetPerformanceData,
    XA22_SetDebugConfiguration
2489 2490
};

2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706
#elif XAUDIO2_VER <= 3

static inline IXAudio2Impl *impl_from_IXAudio23(IXAudio23 *iface)
{
    return CONTAINING_RECORD(iface, IXAudio2Impl, IXAudio23_iface);
}

static HRESULT WINAPI XA23_QueryInterface(IXAudio23 *iface, REFIID riid,
        void **ppvObject)
{
    IXAudio2Impl *This = impl_from_IXAudio23(iface);
    return IXAudio2_QueryInterface(&This->IXAudio2_iface, riid, ppvObject);
}

static ULONG WINAPI XA23_AddRef(IXAudio23 *iface)
{
    IXAudio2Impl *This = impl_from_IXAudio23(iface);
    return IXAudio2_AddRef(&This->IXAudio2_iface);
}

static ULONG WINAPI XA23_Release(IXAudio23 *iface)
{
    IXAudio2Impl *This = impl_from_IXAudio23(iface);
    return IXAudio2_Release(&This->IXAudio2_iface);
}

static HRESULT WINAPI XA23_GetDeviceCount(IXAudio23 *iface, UINT32 *pCount)
{
    IXAudio2Impl *This = impl_from_IXAudio23(iface);
    TRACE("%p, %p\n", This, pCount);
    return FAudio_GetDeviceCount(This->faudio, pCount);
}

static HRESULT WINAPI XA23_GetDeviceDetails(IXAudio23 *iface, UINT32 index,
        XAUDIO2_DEVICE_DETAILS *pDeviceDetails)
{
    IXAudio2Impl *This = impl_from_IXAudio23(iface);
    TRACE("%p, %u, %p\n", This, index, pDeviceDetails);
    return FAudio_GetDeviceDetails(This->faudio, index, (FAudioDeviceDetails *)pDeviceDetails);
}

static HRESULT WINAPI XA23_Initialize(IXAudio23 *iface, UINT32 flags,
        XAUDIO2_PROCESSOR processor)
{
    IXAudio2Impl *This = impl_from_IXAudio23(iface);
    TRACE("(%p)->(0x%x, 0x%x)\n", This, flags, processor);
    return xaudio2_initialize(This, flags, processor);
}

static HRESULT WINAPI XA23_RegisterForCallbacks(IXAudio23 *iface,
        IXAudio2EngineCallback *pCallback)
{
    IXAudio2Impl *This = impl_from_IXAudio23(iface);
    return IXAudio2_RegisterForCallbacks(&This->IXAudio2_iface, pCallback);
}

static void WINAPI XA23_UnregisterForCallbacks(IXAudio23 *iface,
        IXAudio2EngineCallback *pCallback)
{
    IXAudio2Impl *This = impl_from_IXAudio23(iface);
    IXAudio2_UnregisterForCallbacks(&This->IXAudio2_iface, pCallback);
}

static HRESULT WINAPI XA23_CreateSourceVoice(IXAudio23 *iface,
        IXAudio2SourceVoice **ppSourceVoice, const WAVEFORMATEX *pSourceFormat,
        UINT32 flags, float maxFrequencyRatio,
        IXAudio2VoiceCallback *pCallback, const XAUDIO23_VOICE_SENDS *pSendList,
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
{
    IXAudio2Impl *This = impl_from_IXAudio23(iface);
    XAUDIO2_VOICE_SENDS sends, *psends = NULL;
    HRESULT hr;

    if(pSendList){
        sends.SendCount = pSendList->OutputCount;
        sends.pSends = convert_send_descriptors23(pSendList);
        psends = &sends;
    }

    hr = IXAudio2_CreateSourceVoice(&This->IXAudio2_iface, ppSourceVoice,
            pSourceFormat, flags, maxFrequencyRatio, pCallback, psends,
            pEffectChain);

    if(pSendList)
        HeapFree(GetProcessHeap(), 0, sends.pSends);

    return hr;
}

static HRESULT WINAPI XA23_CreateSubmixVoice(IXAudio23 *iface,
        IXAudio2SubmixVoice **ppSubmixVoice, UINT32 inputChannels,
        UINT32 inputSampleRate, UINT32 flags, UINT32 processingStage,
        const XAUDIO23_VOICE_SENDS *pSendList,
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
{
    IXAudio2Impl *This = impl_from_IXAudio23(iface);
    XAUDIO2_VOICE_SENDS sends, *psends = NULL;
    HRESULT hr;

    if(pSendList){
        sends.SendCount = pSendList->OutputCount;
        sends.pSends = convert_send_descriptors23(pSendList);
        psends = &sends;
    }

    hr = IXAudio2_CreateSubmixVoice(&This->IXAudio2_iface, ppSubmixVoice,
            inputChannels, inputSampleRate, flags, processingStage, psends,
            pEffectChain);

    if(pSendList)
        HeapFree(GetProcessHeap(), 0, sends.pSends);

    return hr;
}

static HRESULT WINAPI XA23_CreateMasteringVoice(IXAudio23 *iface,
        IXAudio2MasteringVoice **ppMasteringVoice, UINT32 inputChannels,
        UINT32 inputSampleRate, UINT32 flags, UINT32 deviceIndex,
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
{
    IXAudio2Impl *This = impl_from_IXAudio23(iface);

    TRACE("(%p)->(%p, %u, %u, 0x%x, %u, %p)\n", This, ppMasteringVoice,
            inputChannels, inputSampleRate, flags, deviceIndex,
            pEffectChain);

    EnterCriticalSection(&This->lock);

    /* XAUDIO2_VER == 3 */
    *ppMasteringVoice = (IXAudio2MasteringVoice*)&This->mst.IXAudio23MasteringVoice_iface;

    EnterCriticalSection(&This->mst.lock);

    if(This->mst.in_use){
        LeaveCriticalSection(&This->mst.lock);
        LeaveCriticalSection(&This->lock);
        return COMPAT_E_INVALID_CALL;
    }

    LeaveCriticalSection(&This->lock);

    This->mst.effect_chain = wrap_effect_chain(pEffectChain);

    pthread_mutex_lock(&This->mst.engine_lock);

    This->mst.engine_thread = CreateThread(NULL, 0, &engine_thread, &This->mst, 0, NULL);

    pthread_cond_wait(&This->mst.engine_done, &This->mst.engine_lock);

    pthread_mutex_unlock(&This->mst.engine_lock);

    FAudio_SetEngineProcedureEXT(This->faudio, &engine_cb, &This->mst);

    FAudio_CreateMasteringVoice(This->faudio, &This->mst.faudio_voice, inputChannels,
            inputSampleRate, flags, deviceIndex, This->mst.effect_chain);

    This->mst.in_use = TRUE;

    LeaveCriticalSection(&This->mst.lock);

    return S_OK;
}

static HRESULT WINAPI XA23_StartEngine(IXAudio23 *iface)
{
    IXAudio2Impl *This = impl_from_IXAudio23(iface);
    return IXAudio2_StartEngine(&This->IXAudio2_iface);
}

static void WINAPI XA23_StopEngine(IXAudio23 *iface)
{
    IXAudio2Impl *This = impl_from_IXAudio23(iface);
    return IXAudio2_StopEngine(&This->IXAudio2_iface);
}

static HRESULT WINAPI XA23_CommitChanges(IXAudio23 *iface, UINT32 operationSet)
{
    IXAudio2Impl *This = impl_from_IXAudio23(iface);
    return IXAudio2_CommitChanges(&This->IXAudio2_iface, operationSet);
}

static void WINAPI XA23_GetPerformanceData(IXAudio23 *iface,
        XAUDIO2_PERFORMANCE_DATA *pPerfData)
{
    IXAudio2Impl *This = impl_from_IXAudio23(iface);
    return IXAudio2_GetPerformanceData(&This->IXAudio2_iface, pPerfData);
}

static void WINAPI XA23_SetDebugConfiguration(IXAudio23 *iface,
        const XAUDIO2_DEBUG_CONFIGURATION *pDebugConfiguration,
        void *pReserved)
{
    IXAudio2Impl *This = impl_from_IXAudio23(iface);
    return IXAudio2_SetDebugConfiguration(&This->IXAudio2_iface,
            pDebugConfiguration, pReserved);
}

const IXAudio23Vtbl XAudio23_Vtbl = {
    XA23_QueryInterface,
    XA23_AddRef,
    XA23_Release,
    XA23_GetDeviceCount,
    XA23_GetDeviceDetails,
    XA23_Initialize,
    XA23_RegisterForCallbacks,
    XA23_UnregisterForCallbacks,
    XA23_CreateSourceVoice,
    XA23_CreateSubmixVoice,
    XA23_CreateMasteringVoice,
    XA23_StartEngine,
    XA23_StopEngine,
    XA23_CommitChanges,
    XA23_GetPerformanceData,
    XA23_SetDebugConfiguration
};

2707 2708 2709
#elif XAUDIO2_VER <= 7

static inline IXAudio2Impl *impl_from_IXAudio27(IXAudio27 *iface)
2710
{
2711
    return CONTAINING_RECORD(iface, IXAudio2Impl, IXAudio27_iface);
2712 2713
}

2714
static HRESULT WINAPI XA27_QueryInterface(IXAudio27 *iface, REFIID riid,
2715 2716
        void **ppvObject)
{
2717
    IXAudio2Impl *This = impl_from_IXAudio27(iface);
2718 2719 2720
    return IXAudio2_QueryInterface(&This->IXAudio2_iface, riid, ppvObject);
}

2721
static ULONG WINAPI XA27_AddRef(IXAudio27 *iface)
2722
{
2723
    IXAudio2Impl *This = impl_from_IXAudio27(iface);
2724 2725 2726
    return IXAudio2_AddRef(&This->IXAudio2_iface);
}

2727
static ULONG WINAPI XA27_Release(IXAudio27 *iface)
2728
{
2729
    IXAudio2Impl *This = impl_from_IXAudio27(iface);
2730 2731 2732
    return IXAudio2_Release(&This->IXAudio2_iface);
}

2733
static HRESULT WINAPI XA27_GetDeviceCount(IXAudio27 *iface, UINT32 *pCount)
2734
{
2735
    IXAudio2Impl *This = impl_from_IXAudio27(iface);
2736
    TRACE("%p, %p\n", This, pCount);
2737
    return FAudio_GetDeviceCount(This->faudio, pCount);
2738 2739
}

2740
static HRESULT WINAPI XA27_GetDeviceDetails(IXAudio27 *iface, UINT32 index,
2741 2742
        XAUDIO2_DEVICE_DETAILS *pDeviceDetails)
{
2743
    IXAudio2Impl *This = impl_from_IXAudio27(iface);
2744
    TRACE("%p, %u, %p\n", This, index, pDeviceDetails);
2745
    return FAudio_GetDeviceDetails(This->faudio, index, (FAudioDeviceDetails *)pDeviceDetails);
2746 2747
}

2748
static HRESULT WINAPI XA27_Initialize(IXAudio27 *iface, UINT32 flags,
2749 2750
        XAUDIO2_PROCESSOR processor)
{
2751
    IXAudio2Impl *This = impl_from_IXAudio27(iface);
2752
    TRACE("(%p)->(0x%x, 0x%x)\n", This, flags, processor);
2753
    return xaudio2_initialize(This, flags, processor);
2754 2755
}

2756
static HRESULT WINAPI XA27_RegisterForCallbacks(IXAudio27 *iface,
2757 2758
        IXAudio2EngineCallback *pCallback)
{
2759
    IXAudio2Impl *This = impl_from_IXAudio27(iface);
2760 2761 2762
    return IXAudio2_RegisterForCallbacks(&This->IXAudio2_iface, pCallback);
}

2763
static void WINAPI XA27_UnregisterForCallbacks(IXAudio27 *iface,
2764 2765
        IXAudio2EngineCallback *pCallback)
{
2766 2767
    IXAudio2Impl *This = impl_from_IXAudio27(iface);
    IXAudio2_UnregisterForCallbacks(&This->IXAudio2_iface, pCallback);
2768 2769
}

2770
static HRESULT WINAPI XA27_CreateSourceVoice(IXAudio27 *iface,
2771 2772 2773 2774 2775
        IXAudio2SourceVoice **ppSourceVoice, const WAVEFORMATEX *pSourceFormat,
        UINT32 flags, float maxFrequencyRatio,
        IXAudio2VoiceCallback *pCallback, const XAUDIO2_VOICE_SENDS *pSendList,
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
{
2776
    IXAudio2Impl *This = impl_from_IXAudio27(iface);
2777 2778 2779 2780 2781
    return IXAudio2_CreateSourceVoice(&This->IXAudio2_iface, ppSourceVoice,
            pSourceFormat, flags, maxFrequencyRatio, pCallback, pSendList,
            pEffectChain);
}

2782
static HRESULT WINAPI XA27_CreateSubmixVoice(IXAudio27 *iface,
2783 2784 2785 2786 2787
        IXAudio2SubmixVoice **ppSubmixVoice, UINT32 inputChannels,
        UINT32 inputSampleRate, UINT32 flags, UINT32 processingStage,
        const XAUDIO2_VOICE_SENDS *pSendList,
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
{
2788
    IXAudio2Impl *This = impl_from_IXAudio27(iface);
2789 2790 2791 2792 2793
    return IXAudio2_CreateSubmixVoice(&This->IXAudio2_iface, ppSubmixVoice,
            inputChannels, inputSampleRate, flags, processingStage, pSendList,
            pEffectChain);
}

2794
static HRESULT WINAPI XA27_CreateMasteringVoice(IXAudio27 *iface,
2795 2796 2797 2798
        IXAudio2MasteringVoice **ppMasteringVoice, UINT32 inputChannels,
        UINT32 inputSampleRate, UINT32 flags, UINT32 deviceIndex,
        const XAUDIO2_EFFECT_CHAIN *pEffectChain)
{
2799
    IXAudio2Impl *This = impl_from_IXAudio27(iface);
2800 2801 2802 2803 2804

    TRACE("(%p)->(%p, %u, %u, 0x%x, %u, %p)\n", This, ppMasteringVoice,
            inputChannels, inputSampleRate, flags, deviceIndex,
            pEffectChain);

2805
    EnterCriticalSection(&This->lock);
2806

2807
    /* 4 <= XAUDIO2_VER <= 7 */
2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839
    *ppMasteringVoice = (IXAudio2MasteringVoice*)&This->mst.IXAudio27MasteringVoice_iface;

    EnterCriticalSection(&This->mst.lock);

    if(This->mst.in_use){
        LeaveCriticalSection(&This->mst.lock);
        LeaveCriticalSection(&This->lock);
        return COMPAT_E_INVALID_CALL;
    }

    LeaveCriticalSection(&This->lock);

    This->mst.effect_chain = wrap_effect_chain(pEffectChain);

    pthread_mutex_lock(&This->mst.engine_lock);

    This->mst.engine_thread = CreateThread(NULL, 0, &engine_thread, &This->mst, 0, NULL);

    pthread_cond_wait(&This->mst.engine_done, &This->mst.engine_lock);

    pthread_mutex_unlock(&This->mst.engine_lock);

    FAudio_SetEngineProcedureEXT(This->faudio, &engine_cb, &This->mst);

    FAudio_CreateMasteringVoice(This->faudio, &This->mst.faudio_voice, inputChannels,
            inputSampleRate, flags, deviceIndex, This->mst.effect_chain);

    This->mst.in_use = TRUE;

    LeaveCriticalSection(&This->mst.lock);

    return S_OK;
2840 2841
}

2842
static HRESULT WINAPI XA27_StartEngine(IXAudio27 *iface)
2843
{
2844
    IXAudio2Impl *This = impl_from_IXAudio27(iface);
2845 2846 2847
    return IXAudio2_StartEngine(&This->IXAudio2_iface);
}

2848
static void WINAPI XA27_StopEngine(IXAudio27 *iface)
2849
{
2850
    IXAudio2Impl *This = impl_from_IXAudio27(iface);
2851 2852 2853
    return IXAudio2_StopEngine(&This->IXAudio2_iface);
}

2854
static HRESULT WINAPI XA27_CommitChanges(IXAudio27 *iface, UINT32 operationSet)
2855
{
2856
    IXAudio2Impl *This = impl_from_IXAudio27(iface);
2857 2858 2859
    return IXAudio2_CommitChanges(&This->IXAudio2_iface, operationSet);
}

2860 2861
static void WINAPI XA27_GetPerformanceData(IXAudio27 *iface,
        XAUDIO2_PERFORMANCE_DATA *pPerfData)
2862
{
2863 2864
    IXAudio2Impl *This = impl_from_IXAudio27(iface);
    return IXAudio2_GetPerformanceData(&This->IXAudio2_iface, pPerfData);
2865 2866
}

2867
static void WINAPI XA27_SetDebugConfiguration(IXAudio27 *iface,
2868 2869 2870
        const XAUDIO2_DEBUG_CONFIGURATION *pDebugConfiguration,
        void *pReserved)
{
2871
    IXAudio2Impl *This = impl_from_IXAudio27(iface);
2872 2873 2874 2875
    return IXAudio2_SetDebugConfiguration(&This->IXAudio2_iface,
            pDebugConfiguration, pReserved);
}

2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892
const IXAudio27Vtbl XAudio27_Vtbl = {
    XA27_QueryInterface,
    XA27_AddRef,
    XA27_Release,
    XA27_GetDeviceCount,
    XA27_GetDeviceDetails,
    XA27_Initialize,
    XA27_RegisterForCallbacks,
    XA27_UnregisterForCallbacks,
    XA27_CreateSourceVoice,
    XA27_CreateSubmixVoice,
    XA27_CreateMasteringVoice,
    XA27_StartEngine,
    XA27_StopEngine,
    XA27_CommitChanges,
    XA27_GetPerformanceData,
    XA27_SetDebugConfiguration
2893
};
2894 2895
#endif
/* END IXAudio2 */