2 * Copyright (c) 2015 Mark Harmstone
3 * Copyright (c) 2015 Andrew Eikum for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define NONAMELESSUNION
25 #include "xaudio_private.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(xaudio2
);
35 WINE_DECLARE_DEBUG_CHANNEL(winediag
);
37 static ALCdevice
*(ALC_APIENTRY
*palcLoopbackOpenDeviceSOFT
)(const ALCchar
*);
38 static void (ALC_APIENTRY
*palcRenderSamplesSOFT
)(ALCdevice
*, ALCvoid
*, ALCsizei
);
39 static ALCboolean (ALC_APIENTRY
*palcSetThreadContext
)(ALCcontext
*);
41 static HINSTANCE instance
;
43 #define IN_AL_PERIODS 4
46 #define COMPAT_E_INVALID_CALL E_INVALIDARG
47 #define COMPAT_E_DEVICE_INVALIDATED XAUDIO20_E_DEVICE_INVALIDATED
49 #define COMPAT_E_INVALID_CALL XAUDIO2_E_INVALID_CALL
50 #define COMPAT_E_DEVICE_INVALIDATED XAUDIO2_E_DEVICE_INVALIDATED
53 static void dump_fmt(const WAVEFORMATEX
*fmt
)
55 TRACE("wFormatTag: 0x%x (", fmt
->wFormatTag
);
56 switch(fmt
->wFormatTag
){
57 #define DOCASE(x) case x: TRACE(#x); break;
58 DOCASE(WAVE_FORMAT_PCM
)
59 DOCASE(WAVE_FORMAT_IEEE_FLOAT
)
60 DOCASE(WAVE_FORMAT_EXTENSIBLE
)
68 TRACE("nChannels: %u\n", fmt
->nChannels
);
69 TRACE("nSamplesPerSec: %u\n", fmt
->nSamplesPerSec
);
70 TRACE("nAvgBytesPerSec: %u\n", fmt
->nAvgBytesPerSec
);
71 TRACE("nBlockAlign: %u\n", fmt
->nBlockAlign
);
72 TRACE("wBitsPerSample: %u\n", fmt
->wBitsPerSample
);
73 TRACE("cbSize: %u\n", fmt
->cbSize
);
75 if(fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
){
76 WAVEFORMATEXTENSIBLE
*fmtex
= (void*)fmt
;
77 TRACE("dwChannelMask: %08x\n", fmtex
->dwChannelMask
);
78 TRACE("Samples: %04x\n", fmtex
->Samples
.wReserved
);
79 TRACE("SubFormat: %s\n", wine_dbgstr_guid(&fmtex
->SubFormat
));
80 }else if(fmt
->wFormatTag
== WAVE_FORMAT_ADPCM
){
81 ADPCMWAVEFORMAT
*fmtadpcm
= (void*)fmt
;
82 TRACE("wSamplesPerBlock: %u\n", fmtadpcm
->wSamplesPerBlock
);
86 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD reason
, void *pReserved
)
88 TRACE("(%p, %d, %p)\n", hinstDLL
, reason
, pReserved
);
92 case DLL_WINE_PREATTACH
:
93 return FALSE
; /* prefer native version */
94 case DLL_PROCESS_ATTACH
:
96 DisableThreadLibraryCalls( hinstDLL
);
98 if(!alcIsExtensionPresent(NULL
, "ALC_SOFT_loopback") ||
99 !(palcLoopbackOpenDeviceSOFT
= alcGetProcAddress(NULL
, "alcLoopbackOpenDeviceSOFT")) ||
100 !(palcRenderSamplesSOFT
= alcGetProcAddress(NULL
, "alcRenderSamplesSOFT"))){
101 ERR("XAudio2 requires the ALC_SOFT_loopback extension (OpenAL-Soft >= 1.14)\n");
105 if(!alcIsExtensionPresent(NULL
, "ALC_EXT_thread_local_context") ||
106 !(palcSetThreadContext
= alcGetProcAddress(NULL
, "alcSetThreadContext"))){
107 ERR("XAudio2 requires the ALC_EXT_thread_local_context extension (OpenAL-Soft >= 1.12)\n");
116 HRESULT WINAPI
DllCanUnloadNow(void)
121 HRESULT WINAPI
DllRegisterServer(void)
124 return __wine_register_resources(instance
);
127 HRESULT WINAPI
DllUnregisterServer(void)
130 return __wine_unregister_resources(instance
);
133 static XA2SourceImpl
*impl_from_IXAudio2SourceVoice(IXAudio2SourceVoice
*iface
)
135 return CONTAINING_RECORD(iface
, XA2SourceImpl
, IXAudio2SourceVoice_iface
);
138 static XA2SubmixImpl
*impl_from_IXAudio2SubmixVoice(IXAudio2SubmixVoice
*iface
)
140 return CONTAINING_RECORD(iface
, XA2SubmixImpl
, IXAudio2SubmixVoice_iface
);
143 static inline IXAudio2Impl
*impl_from_IXAudio2(IXAudio2
*iface
)
145 return CONTAINING_RECORD(iface
, IXAudio2Impl
, IXAudio2_iface
);
148 static IXAudio2Impl
*impl_from_IXAudio2MasteringVoice(IXAudio2MasteringVoice
*iface
)
150 return CONTAINING_RECORD(iface
, IXAudio2Impl
, IXAudio2MasteringVoice_iface
);
153 static DWORD
get_channel_mask(unsigned int channels
)
159 return KSAUDIO_SPEAKER_MONO
;
161 return KSAUDIO_SPEAKER_STEREO
;
163 return KSAUDIO_SPEAKER_STEREO
| SPEAKER_LOW_FREQUENCY
;
165 return KSAUDIO_SPEAKER_QUAD
; /* not _SURROUND */
167 return KSAUDIO_SPEAKER_QUAD
| SPEAKER_LOW_FREQUENCY
;
169 return KSAUDIO_SPEAKER_5POINT1
; /* not 5POINT1_SURROUND */
171 return KSAUDIO_SPEAKER_5POINT1
| SPEAKER_BACK_CENTER
;
173 return KSAUDIO_SPEAKER_7POINT1_SURROUND
; /* Vista deprecates 7POINT1 */
175 FIXME("Unknown speaker configuration: %u\n", channels
);
179 static void WINAPI
XA2SRC_GetVoiceDetails(IXAudio2SourceVoice
*iface
,
180 XAUDIO2_VOICE_DETAILS
*pVoiceDetails
)
182 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
184 TRACE("%p, %p\n", This
, pVoiceDetails
);
186 pVoiceDetails
->CreationFlags
= 0;
187 pVoiceDetails
->ActiveFlags
= 0;
188 pVoiceDetails
->InputChannels
= This
->fmt
->nChannels
;
189 pVoiceDetails
->InputSampleRate
= This
->fmt
->nSamplesPerSec
;
192 static HRESULT WINAPI
XA2SRC_SetOutputVoices(IXAudio2SourceVoice
*iface
,
193 const XAUDIO2_VOICE_SENDS
*pSendList
)
195 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
197 XAUDIO2_VOICE_SENDS def_send
;
198 XAUDIO2_SEND_DESCRIPTOR def_desc
;
200 TRACE("%p, %p\n", This
, pSendList
);
204 def_desc
.pOutputVoice
= (IXAudio2Voice
*)&This
->xa2
->IXAudio2MasteringVoice_iface
;
206 def_send
.SendCount
= 1;
207 def_send
.pSends
= &def_desc
;
209 pSendList
= &def_send
;
212 if(TRACE_ON(xaudio2
)){
213 for(i
= 0; i
< pSendList
->SendCount
; ++i
){
214 XAUDIO2_SEND_DESCRIPTOR
*desc
= &pSendList
->pSends
[i
];
215 TRACE("Outputting to: 0x%x, %p\n", desc
->Flags
, desc
->pOutputVoice
);
219 if(This
->nsends
< pSendList
->SendCount
){
220 HeapFree(GetProcessHeap(), 0, This
->sends
);
221 This
->sends
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
->sends
) * pSendList
->SendCount
);
222 This
->nsends
= pSendList
->SendCount
;
224 memset(This
->sends
, 0, sizeof(*This
->sends
) * This
->nsends
);
226 memcpy(This
->sends
, pSendList
->pSends
, sizeof(*This
->sends
) * pSendList
->SendCount
);
231 static HRESULT WINAPI
XA2SRC_SetEffectChain(IXAudio2SourceVoice
*iface
,
232 const XAUDIO2_EFFECT_CHAIN
*pEffectChain
)
234 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
235 TRACE("%p, %p\n", This
, pEffectChain
);
239 static HRESULT WINAPI
XA2SRC_EnableEffect(IXAudio2SourceVoice
*iface
,
240 UINT32 EffectIndex
, UINT32 OperationSet
)
242 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
243 TRACE("%p, %u, 0x%x\n", This
, EffectIndex
, OperationSet
);
247 static HRESULT WINAPI
XA2SRC_DisableEffect(IXAudio2SourceVoice
*iface
,
248 UINT32 EffectIndex
, UINT32 OperationSet
)
250 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
251 TRACE("%p, %u, 0x%x\n", This
, EffectIndex
, OperationSet
);
255 static void WINAPI
XA2SRC_GetEffectState(IXAudio2SourceVoice
*iface
,
256 UINT32 EffectIndex
, BOOL
*pEnabled
)
258 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
259 TRACE("%p, %u, %p\n", This
, EffectIndex
, pEnabled
);
262 static HRESULT WINAPI
XA2SRC_SetEffectParameters(IXAudio2SourceVoice
*iface
,
263 UINT32 EffectIndex
, const void *pParameters
, UINT32 ParametersByteSize
,
266 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
267 TRACE("%p, %u, %p, 0x%x, 0x%x\n", This
, EffectIndex
, pParameters
,
268 ParametersByteSize
, OperationSet
);
272 static HRESULT WINAPI
XA2SRC_GetEffectParameters(IXAudio2SourceVoice
*iface
,
273 UINT32 EffectIndex
, void *pParameters
, UINT32 ParametersByteSize
)
275 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
276 TRACE("%p, %u, %p, 0x%x\n", This
, EffectIndex
, pParameters
,
281 static HRESULT WINAPI
XA2SRC_SetFilterParameters(IXAudio2SourceVoice
*iface
,
282 const XAUDIO2_FILTER_PARAMETERS
*pParameters
, UINT32 OperationSet
)
284 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
285 TRACE("%p, %p, 0x%x\n", This
, pParameters
, OperationSet
);
289 static void WINAPI
XA2SRC_GetFilterParameters(IXAudio2SourceVoice
*iface
,
290 XAUDIO2_FILTER_PARAMETERS
*pParameters
)
292 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
293 TRACE("%p, %p\n", This
, pParameters
);
296 static HRESULT WINAPI
XA2SRC_SetOutputFilterParameters(IXAudio2SourceVoice
*iface
,
297 IXAudio2Voice
*pDestinationVoice
,
298 const XAUDIO2_FILTER_PARAMETERS
*pParameters
, UINT32 OperationSet
)
300 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
301 TRACE("%p, %p, %p, 0x%x\n", This
, pDestinationVoice
, pParameters
, OperationSet
);
305 static void WINAPI
XA2SRC_GetOutputFilterParameters(IXAudio2SourceVoice
*iface
,
306 IXAudio2Voice
*pDestinationVoice
,
307 XAUDIO2_FILTER_PARAMETERS
*pParameters
)
309 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
310 TRACE("%p, %p, %p\n", This
, pDestinationVoice
, pParameters
);
313 static HRESULT WINAPI
XA2SRC_SetVolume(IXAudio2SourceVoice
*iface
, float Volume
,
316 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
319 TRACE("%p, %f, 0x%x\n", This
, Volume
, OperationSet
);
323 palcSetThreadContext(This
->xa2
->al_ctx
);
325 alSourcef(This
->al_src
, AL_GAIN
, al_gain
);
330 static void WINAPI
XA2SRC_GetVolume(IXAudio2SourceVoice
*iface
, float *pVolume
)
332 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
333 TRACE("%p, %p\n", This
, pVolume
);
336 static HRESULT WINAPI
XA2SRC_SetChannelVolumes(IXAudio2SourceVoice
*iface
,
337 UINT32 Channels
, const float *pVolumes
, UINT32 OperationSet
)
339 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
340 TRACE("%p, %u, %p, 0x%x\n", This
, Channels
, pVolumes
, OperationSet
);
344 static void WINAPI
XA2SRC_GetChannelVolumes(IXAudio2SourceVoice
*iface
,
345 UINT32 Channels
, float *pVolumes
)
347 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
348 TRACE("%p, %u, %p\n", This
, Channels
, pVolumes
);
351 static HRESULT WINAPI
XA2SRC_SetOutputMatrix(IXAudio2SourceVoice
*iface
,
352 IXAudio2Voice
*pDestinationVoice
, UINT32 SourceChannels
,
353 UINT32 DestinationChannels
, const float *pLevelMatrix
,
356 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
357 TRACE("%p, %p, %u, %u, %p, 0x%x\n", This
, pDestinationVoice
,
358 SourceChannels
, DestinationChannels
, pLevelMatrix
, OperationSet
);
362 static void WINAPI
XA2SRC_GetOutputMatrix(IXAudio2SourceVoice
*iface
,
363 IXAudio2Voice
*pDestinationVoice
, UINT32 SourceChannels
,
364 UINT32 DestinationChannels
, float *pLevelMatrix
)
366 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
367 TRACE("%p, %p, %u, %u, %p\n", This
, pDestinationVoice
,
368 SourceChannels
, DestinationChannels
, pLevelMatrix
);
371 static void WINAPI
XA2SRC_DestroyVoice(IXAudio2SourceVoice
*iface
)
373 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
378 palcSetThreadContext(This
->xa2
->al_ctx
);
380 EnterCriticalSection(&This
->lock
);
383 LeaveCriticalSection(&This
->lock
);
387 This
->in_use
= FALSE
;
389 This
->running
= FALSE
;
391 IXAudio2SourceVoice_Stop(iface
, 0, 0);
393 alSourceStop(This
->al_src
);
395 /* unqueue all buffers */
396 alSourcei(This
->al_src
, AL_BUFFER
, AL_NONE
);
398 alGetSourcei(This
->al_src
, AL_BUFFERS_PROCESSED
, &processed
);
401 ALuint al_buffers
[XAUDIO2_MAX_QUEUED_BUFFERS
];
403 alSourceUnqueueBuffers(This
->al_src
, processed
, al_buffers
);
406 HeapFree(GetProcessHeap(), 0, This
->fmt
);
408 alDeleteBuffers(XAUDIO2_MAX_QUEUED_BUFFERS
, This
->al_bufs
);
409 alDeleteSources(1, &This
->al_src
);
411 This
->in_al_bytes
= 0;
412 This
->al_bufs_used
= 0;
413 This
->played_frames
= 0;
418 LeaveCriticalSection(&This
->lock
);
421 static HRESULT WINAPI
XA2SRC_Start(IXAudio2SourceVoice
*iface
, UINT32 Flags
,
424 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
426 TRACE("%p, 0x%x, 0x%x\n", This
, Flags
, OperationSet
);
428 EnterCriticalSection(&This
->lock
);
430 This
->running
= TRUE
;
432 LeaveCriticalSection(&This
->lock
);
437 static HRESULT WINAPI
XA2SRC_Stop(IXAudio2SourceVoice
*iface
, UINT32 Flags
,
440 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
442 TRACE("%p, 0x%x, 0x%x\n", This
, Flags
, OperationSet
);
444 EnterCriticalSection(&This
->lock
);
446 This
->running
= FALSE
;
448 LeaveCriticalSection(&This
->lock
);
453 static ALenum
get_al_format(const WAVEFORMATEX
*fmt
)
455 WAVEFORMATEXTENSIBLE
*fmtex
= (WAVEFORMATEXTENSIBLE
*)fmt
;
456 if(fmt
->wFormatTag
== WAVE_FORMAT_PCM
||
457 (fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
458 IsEqualGUID(&fmtex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
))){
459 switch(fmt
->wBitsPerSample
){
461 switch(fmt
->nChannels
){
463 return AL_FORMAT_MONO8
;
465 return AL_FORMAT_STEREO8
;
467 return AL_FORMAT_QUAD8
;
469 return AL_FORMAT_51CHN8
;
471 return AL_FORMAT_61CHN8
;
473 return AL_FORMAT_71CHN8
;
477 switch(fmt
->nChannels
){
479 return AL_FORMAT_MONO16
;
481 return AL_FORMAT_STEREO16
;
483 return AL_FORMAT_QUAD16
;
485 return AL_FORMAT_51CHN16
;
487 return AL_FORMAT_61CHN16
;
489 return AL_FORMAT_71CHN16
;
493 }else if(fmt
->wFormatTag
== WAVE_FORMAT_IEEE_FLOAT
||
494 (fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
495 IsEqualGUID(&fmtex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
))){
496 if(fmt
->wBitsPerSample
== 32){
497 switch(fmt
->nChannels
){
499 return AL_FORMAT_MONO_FLOAT32
;
501 return AL_FORMAT_STEREO_FLOAT32
;
508 static HRESULT WINAPI
XA2SRC_SubmitSourceBuffer(IXAudio2SourceVoice
*iface
,
509 const XAUDIO2_BUFFER
*pBuffer
, const XAUDIO2_BUFFER_WMA
*pBufferWMA
)
511 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
515 TRACE("%p, %p, %p\n", This
, pBuffer
, pBufferWMA
);
517 if(TRACE_ON(xaudio2
)){
518 TRACE("Flags: 0x%x\n", pBuffer
->Flags
);
519 TRACE("AudioBytes: %u\n", pBuffer
->AudioBytes
);
520 TRACE("pAudioData: %p\n", pBuffer
->pAudioData
);
521 TRACE("PlayBegin: %u\n", pBuffer
->PlayBegin
);
522 TRACE("PlayLength: %u\n", pBuffer
->PlayLength
);
523 TRACE("LoopBegin: %u\n", pBuffer
->LoopBegin
);
524 TRACE("LoopLength: %u\n", pBuffer
->LoopLength
);
525 TRACE("LoopCount: %u\n", pBuffer
->LoopCount
);
526 TRACE("pContext: %p\n", pBuffer
->pContext
);
529 EnterCriticalSection(&This
->lock
);
531 if(This
->nbufs
>= XAUDIO2_MAX_QUEUED_BUFFERS
){
532 TRACE("Too many buffers queued!\n");
533 LeaveCriticalSection(&This
->lock
);
534 return COMPAT_E_INVALID_CALL
;
537 buf_idx
= (This
->first_buf
+ This
->nbufs
) % XAUDIO2_MAX_QUEUED_BUFFERS
;
538 buf
= &This
->buffers
[buf_idx
];
539 memset(buf
, 0, sizeof(*buf
));
541 /* API contract: pAudioData must remain valid until this buffer is played,
542 * but pBuffer itself may be reused immediately */
543 memcpy(&buf
->xa2buffer
, pBuffer
, sizeof(*pBuffer
));
546 if(buf
->xa2buffer
.LoopCount
== XAUDIO20_LOOP_INFINITE
)
547 buf
->xa2buffer
.LoopCount
= XAUDIO2_LOOP_INFINITE
;
550 /* convert samples offsets to bytes */
551 if(This
->fmt
->wFormatTag
== WAVE_FORMAT_ADPCM
){
552 /* ADPCM gives us a number of samples per block, so round down to
553 * nearest block and convert to bytes */
554 buf
->xa2buffer
.PlayBegin
= buf
->xa2buffer
.PlayBegin
/ ((ADPCMWAVEFORMAT
*)This
->fmt
)->wSamplesPerBlock
* This
->fmt
->nBlockAlign
;
555 buf
->xa2buffer
.PlayLength
= buf
->xa2buffer
.PlayLength
/ ((ADPCMWAVEFORMAT
*)This
->fmt
)->wSamplesPerBlock
* This
->fmt
->nBlockAlign
;
556 buf
->xa2buffer
.LoopBegin
= buf
->xa2buffer
.LoopBegin
/ ((ADPCMWAVEFORMAT
*)This
->fmt
)->wSamplesPerBlock
* This
->fmt
->nBlockAlign
;
557 buf
->xa2buffer
.LoopLength
= buf
->xa2buffer
.LoopLength
/ ((ADPCMWAVEFORMAT
*)This
->fmt
)->wSamplesPerBlock
* This
->fmt
->nBlockAlign
;
559 buf
->xa2buffer
.PlayBegin
*= This
->fmt
->nBlockAlign
;
560 buf
->xa2buffer
.PlayLength
*= This
->fmt
->nBlockAlign
;
561 buf
->xa2buffer
.LoopBegin
*= This
->fmt
->nBlockAlign
;
562 buf
->xa2buffer
.LoopLength
*= This
->fmt
->nBlockAlign
;
565 if(buf
->xa2buffer
.PlayLength
== 0)
566 /* set to end of buffer */
567 buf
->xa2buffer
.PlayLength
= buf
->xa2buffer
.AudioBytes
- buf
->xa2buffer
.PlayBegin
;
569 buf
->play_end_bytes
= buf
->xa2buffer
.PlayBegin
+ buf
->xa2buffer
.PlayLength
;
571 if(buf
->xa2buffer
.LoopCount
){
572 if(buf
->xa2buffer
.LoopLength
== 0)
573 /* set to end of play range */
574 buf
->xa2buffer
.LoopLength
= buf
->play_end_bytes
- buf
->xa2buffer
.LoopBegin
;
576 if(buf
->xa2buffer
.LoopBegin
>= buf
->play_end_bytes
){
577 /* this actually crashes on native xaudio 2.7 */
578 LeaveCriticalSection(&This
->lock
);
579 return COMPAT_E_INVALID_CALL
;
582 buf
->loop_end_bytes
= buf
->xa2buffer
.LoopBegin
+ buf
->xa2buffer
.LoopLength
;
584 /* xaudio 2.7 allows some invalid looping setups, but later versions
587 if(buf
->loop_end_bytes
> buf
->play_end_bytes
){
588 LeaveCriticalSection(&This
->lock
);
589 return COMPAT_E_INVALID_CALL
;
592 if(buf
->loop_end_bytes
<= buf
->xa2buffer
.PlayBegin
){
593 LeaveCriticalSection(&This
->lock
);
594 return COMPAT_E_INVALID_CALL
;
597 if(buf
->loop_end_bytes
<= buf
->xa2buffer
.PlayBegin
){
598 buf
->xa2buffer
.LoopCount
= 0;
599 buf
->loop_end_bytes
= buf
->play_end_bytes
;
603 buf
->xa2buffer
.LoopLength
= buf
->xa2buffer
.PlayLength
;
604 buf
->xa2buffer
.LoopBegin
= buf
->xa2buffer
.PlayBegin
;
605 buf
->loop_end_bytes
= buf
->play_end_bytes
;
608 buf
->offs_bytes
= buf
->xa2buffer
.PlayBegin
;
609 buf
->cur_end_bytes
= buf
->loop_end_bytes
;
611 buf
->latest_al_buf
= -1;
615 TRACE("%p: queued buffer %u (%u bytes), now %u buffers held\n",
616 This
, buf_idx
, buf
->xa2buffer
.AudioBytes
, This
->nbufs
);
618 LeaveCriticalSection(&This
->lock
);
623 static HRESULT WINAPI
XA2SRC_FlushSourceBuffers(IXAudio2SourceVoice
*iface
)
625 UINT i
, first
, last
, to_flush
;
626 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
630 EnterCriticalSection(&This
->lock
);
632 if(This
->running
&& This
->nbufs
> 0){
633 /* when running, flush only completely unused buffers; the rest remain
635 last
= (This
->first_buf
+ This
->nbufs
) % XAUDIO2_MAX_QUEUED_BUFFERS
;
636 first
= (This
->cur_buf
+ 1) % XAUDIO2_MAX_QUEUED_BUFFERS
;
637 if(This
->cur_buf
== last
)
640 else if(last
>= first
)
641 to_flush
= last
- first
;
643 to_flush
= last
+ XAUDIO2_MAX_QUEUED_BUFFERS
- first
;
645 /* when stopped, flush all buffers */
646 first
= This
->first_buf
;
647 last
= (This
->first_buf
+ This
->nbufs
) % XAUDIO2_MAX_QUEUED_BUFFERS
;
648 to_flush
= This
->nbufs
;
653 i
< (first
+ to_flush
) % XAUDIO2_MAX_QUEUED_BUFFERS
;
654 i
= (i
+ 1) % XAUDIO2_MAX_QUEUED_BUFFERS
){
656 IXAudio2VoiceCallback_OnBufferEnd(This
->cb
,
657 This
->buffers
[i
].xa2buffer
.pContext
);
660 This
->nbufs
-= to_flush
;
661 This
->cur_buf
= (This
->first_buf
+ This
->nbufs
) % XAUDIO2_MAX_QUEUED_BUFFERS
;
663 LeaveCriticalSection(&This
->lock
);
668 static HRESULT WINAPI
XA2SRC_Discontinuity(IXAudio2SourceVoice
*iface
)
670 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
674 EnterCriticalSection(&This
->lock
);
677 DWORD last
= (This
->first_buf
+ This
->nbufs
- 1) % XAUDIO2_MAX_QUEUED_BUFFERS
;
678 This
->buffers
[last
].xa2buffer
.Flags
|= XAUDIO2_END_OF_STREAM
;
681 LeaveCriticalSection(&This
->lock
);
686 static HRESULT WINAPI
XA2SRC_ExitLoop(IXAudio2SourceVoice
*iface
, UINT32 OperationSet
)
688 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
690 TRACE("%p, 0x%x\n", This
, OperationSet
);
692 EnterCriticalSection(&This
->lock
);
694 This
->buffers
[This
->cur_buf
].looped
= XAUDIO2_LOOP_INFINITE
;
696 LeaveCriticalSection(&This
->lock
);
701 static void WINAPI
XA2SRC_GetState(IXAudio2SourceVoice
*iface
,
702 XAUDIO2_VOICE_STATE
*pVoiceState
, UINT32 Flags
)
704 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
706 TRACE("%p, %p, 0x%x\n", This
, pVoiceState
, Flags
);
708 EnterCriticalSection(&This
->lock
);
710 if(!(Flags
& XAUDIO2_VOICE_NOSAMPLESPLAYED
))
711 pVoiceState
->SamplesPlayed
= This
->played_frames
;
713 pVoiceState
->SamplesPlayed
= 0;
716 pVoiceState
->pCurrentBufferContext
= This
->buffers
[This
->first_buf
].xa2buffer
.pContext
;
718 pVoiceState
->pCurrentBufferContext
= NULL
;
720 pVoiceState
->BuffersQueued
= This
->nbufs
;
722 LeaveCriticalSection(&This
->lock
);
724 TRACE("returning %s, queued: %u\n", wine_dbgstr_longlong(pVoiceState
->SamplesPlayed
), This
->nbufs
);
727 static HRESULT WINAPI
XA2SRC_SetFrequencyRatio(IXAudio2SourceVoice
*iface
,
728 float Ratio
, UINT32 OperationSet
)
730 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
733 TRACE("%p, %f, 0x%x\n", This
, Ratio
, OperationSet
);
735 if(Ratio
< XAUDIO2_MIN_FREQ_RATIO
)
736 r
= XAUDIO2_MIN_FREQ_RATIO
;
737 else if (Ratio
> XAUDIO2_MAX_FREQ_RATIO
)
738 r
= XAUDIO2_MAX_FREQ_RATIO
;
742 palcSetThreadContext(This
->xa2
->al_ctx
);
744 alSourcef(This
->al_src
, AL_PITCH
, r
);
749 static void WINAPI
XA2SRC_GetFrequencyRatio(IXAudio2SourceVoice
*iface
, float *pRatio
)
752 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
754 TRACE("%p, %p\n", This
, pRatio
);
756 palcSetThreadContext(This
->xa2
->al_ctx
);
758 alGetSourcef(This
->al_src
, AL_PITCH
, &ratio
);
763 static HRESULT WINAPI
XA2SRC_SetSourceSampleRate(
764 IXAudio2SourceVoice
*iface
,
765 UINT32 NewSourceSampleRate
)
767 XA2SourceImpl
*This
= impl_from_IXAudio2SourceVoice(iface
);
769 TRACE("%p, %u\n", This
, NewSourceSampleRate
);
771 EnterCriticalSection(&This
->lock
);
774 LeaveCriticalSection(&This
->lock
);
775 return COMPAT_E_INVALID_CALL
;
778 This
->fmt
->nSamplesPerSec
= NewSourceSampleRate
;
780 LeaveCriticalSection(&This
->lock
);
785 static const IXAudio2SourceVoiceVtbl XAudio2SourceVoice_Vtbl
= {
786 XA2SRC_GetVoiceDetails
,
787 XA2SRC_SetOutputVoices
,
788 XA2SRC_SetEffectChain
,
790 XA2SRC_DisableEffect
,
791 XA2SRC_GetEffectState
,
792 XA2SRC_SetEffectParameters
,
793 XA2SRC_GetEffectParameters
,
794 XA2SRC_SetFilterParameters
,
795 XA2SRC_GetFilterParameters
,
796 XA2SRC_SetOutputFilterParameters
,
797 XA2SRC_GetOutputFilterParameters
,
800 XA2SRC_SetChannelVolumes
,
801 XA2SRC_GetChannelVolumes
,
802 XA2SRC_SetOutputMatrix
,
803 XA2SRC_GetOutputMatrix
,
807 XA2SRC_SubmitSourceBuffer
,
808 XA2SRC_FlushSourceBuffers
,
809 XA2SRC_Discontinuity
,
812 XA2SRC_SetFrequencyRatio
,
813 XA2SRC_GetFrequencyRatio
,
814 XA2SRC_SetSourceSampleRate
817 static void WINAPI
XA2M_GetVoiceDetails(IXAudio2MasteringVoice
*iface
,
818 XAUDIO2_VOICE_DETAILS
*pVoiceDetails
)
820 IXAudio2Impl
*This
= impl_from_IXAudio2MasteringVoice(iface
);
821 TRACE("%p, %p\n", This
, pVoiceDetails
);
822 pVoiceDetails
->CreationFlags
= 0;
823 pVoiceDetails
->ActiveFlags
= 0;
824 pVoiceDetails
->InputChannels
= This
->fmt
.Format
.nChannels
;
825 pVoiceDetails
->InputSampleRate
= This
->fmt
.Format
.nSamplesPerSec
;
828 static HRESULT WINAPI
XA2M_SetOutputVoices(IXAudio2MasteringVoice
*iface
,
829 const XAUDIO2_VOICE_SENDS
*pSendList
)
831 IXAudio2Impl
*This
= impl_from_IXAudio2MasteringVoice(iface
);
832 TRACE("%p, %p\n", This
, pSendList
);
836 static HRESULT WINAPI
XA2M_SetEffectChain(IXAudio2MasteringVoice
*iface
,
837 const XAUDIO2_EFFECT_CHAIN
*pEffectChain
)
839 IXAudio2Impl
*This
= impl_from_IXAudio2MasteringVoice(iface
);
840 TRACE("%p, %p\n", This
, pEffectChain
);
844 static HRESULT WINAPI
XA2M_EnableEffect(IXAudio2MasteringVoice
*iface
, UINT32 EffectIndex
,
847 IXAudio2Impl
*This
= impl_from_IXAudio2MasteringVoice(iface
);
848 TRACE("%p, %u, 0x%x\n", This
, EffectIndex
, OperationSet
);
852 static HRESULT WINAPI
XA2M_DisableEffect(IXAudio2MasteringVoice
*iface
, UINT32 EffectIndex
,
855 IXAudio2Impl
*This
= impl_from_IXAudio2MasteringVoice(iface
);
856 TRACE("%p, %u, 0x%x\n", This
, EffectIndex
, OperationSet
);
860 static void WINAPI
XA2M_GetEffectState(IXAudio2MasteringVoice
*iface
, UINT32 EffectIndex
,
863 IXAudio2Impl
*This
= impl_from_IXAudio2MasteringVoice(iface
);
864 TRACE("%p, %u, %p\n", This
, EffectIndex
, pEnabled
);
867 static HRESULT WINAPI
XA2M_SetEffectParameters(IXAudio2MasteringVoice
*iface
,
868 UINT32 EffectIndex
, const void *pParameters
, UINT32 ParametersByteSize
,
871 IXAudio2Impl
*This
= impl_from_IXAudio2MasteringVoice(iface
);
872 TRACE("%p, %u, %p, 0x%x, 0x%x\n", This
, EffectIndex
, pParameters
,
873 ParametersByteSize
, OperationSet
);
877 static HRESULT WINAPI
XA2M_GetEffectParameters(IXAudio2MasteringVoice
*iface
,
878 UINT32 EffectIndex
, void *pParameters
, UINT32 ParametersByteSize
)
880 IXAudio2Impl
*This
= impl_from_IXAudio2MasteringVoice(iface
);
881 TRACE("%p, %u, %p, 0x%x\n", This
, EffectIndex
, pParameters
,
886 static HRESULT WINAPI
XA2M_SetFilterParameters(IXAudio2MasteringVoice
*iface
,
887 const XAUDIO2_FILTER_PARAMETERS
*pParameters
, UINT32 OperationSet
)
889 IXAudio2Impl
*This
= impl_from_IXAudio2MasteringVoice(iface
);
890 TRACE("%p, %p, 0x%x\n", This
, pParameters
, OperationSet
);
894 static void WINAPI
XA2M_GetFilterParameters(IXAudio2MasteringVoice
*iface
,
895 XAUDIO2_FILTER_PARAMETERS
*pParameters
)
897 IXAudio2Impl
*This
= impl_from_IXAudio2MasteringVoice(iface
);
898 TRACE("%p, %p\n", This
, pParameters
);
901 static HRESULT WINAPI
XA2M_SetOutputFilterParameters(IXAudio2MasteringVoice
*iface
,
902 IXAudio2Voice
*pDestinationVoice
,
903 const XAUDIO2_FILTER_PARAMETERS
*pParameters
, UINT32 OperationSet
)
905 IXAudio2Impl
*This
= impl_from_IXAudio2MasteringVoice(iface
);
906 TRACE("%p, %p, %p, 0x%x\n", This
, pDestinationVoice
, pParameters
, OperationSet
);
910 static void WINAPI
XA2M_GetOutputFilterParameters(IXAudio2MasteringVoice
*iface
,
911 IXAudio2Voice
*pDestinationVoice
,
912 XAUDIO2_FILTER_PARAMETERS
*pParameters
)
914 IXAudio2Impl
*This
= impl_from_IXAudio2MasteringVoice(iface
);
915 TRACE("%p, %p, %p\n", This
, pDestinationVoice
, pParameters
);
918 static HRESULT WINAPI
XA2M_SetVolume(IXAudio2MasteringVoice
*iface
, float Volume
,
921 IXAudio2Impl
*This
= impl_from_IXAudio2MasteringVoice(iface
);
922 TRACE("%p, %f, 0x%x\n", This
, Volume
, OperationSet
);
926 static void WINAPI
XA2M_GetVolume(IXAudio2MasteringVoice
*iface
, float *pVolume
)
928 IXAudio2Impl
*This
= impl_from_IXAudio2MasteringVoice(iface
);
929 TRACE("%p, %p\n", This
, pVolume
);
932 static HRESULT WINAPI
XA2M_SetChannelVolumes(IXAudio2MasteringVoice
*iface
, UINT32 Channels
,
933 const float *pVolumes
, UINT32 OperationSet
)
935 IXAudio2Impl
*This
= impl_from_IXAudio2MasteringVoice(iface
);
936 TRACE("%p, %u, %p, 0x%x\n", This
, Channels
, pVolumes
, OperationSet
);
940 static void WINAPI
XA2M_GetChannelVolumes(IXAudio2MasteringVoice
*iface
, UINT32 Channels
,
943 IXAudio2Impl
*This
= impl_from_IXAudio2MasteringVoice(iface
);
944 TRACE("%p, %u, %p\n", This
, Channels
, pVolumes
);
947 static HRESULT WINAPI
XA2M_SetOutputMatrix(IXAudio2MasteringVoice
*iface
,
948 IXAudio2Voice
*pDestinationVoice
, UINT32 SourceChannels
,
949 UINT32 DestinationChannels
, const float *pLevelMatrix
,
952 IXAudio2Impl
*This
= impl_from_IXAudio2MasteringVoice(iface
);
953 TRACE("%p, %p, %u, %u, %p, 0x%x\n", This
, pDestinationVoice
,
954 SourceChannels
, DestinationChannels
, pLevelMatrix
, OperationSet
);
958 static void WINAPI
XA2M_GetOutputMatrix(IXAudio2MasteringVoice
*iface
,
959 IXAudio2Voice
*pDestinationVoice
, UINT32 SourceChannels
,
960 UINT32 DestinationChannels
, float *pLevelMatrix
)
962 IXAudio2Impl
*This
= impl_from_IXAudio2MasteringVoice(iface
);
963 TRACE("%p, %p, %u, %u, %p\n", This
, pDestinationVoice
,
964 SourceChannels
, DestinationChannels
, pLevelMatrix
);
967 static void WINAPI
XA2M_DestroyVoice(IXAudio2MasteringVoice
*iface
)
969 IXAudio2Impl
*This
= impl_from_IXAudio2MasteringVoice(iface
);
973 EnterCriticalSection(&This
->lock
);
976 LeaveCriticalSection(&This
->lock
);
980 This
->running
= FALSE
;
982 IAudioRenderClient_Release(This
->render
);
985 IAudioClient_Release(This
->aclient
);
986 This
->aclient
= NULL
;
988 alcDestroyContext(This
->al_ctx
);
991 alcCloseDevice(This
->al_device
);
992 This
->al_device
= NULL
;
994 LeaveCriticalSection(&This
->lock
);
997 /* not present in XAudio2 2.7 */
998 static void WINAPI
XA2M_GetChannelMask(IXAudio2MasteringVoice
*iface
,
1001 IXAudio2Impl
*This
= impl_from_IXAudio2MasteringVoice(iface
);
1003 TRACE("%p %p\n", This
, pChannelMask
);
1005 *pChannelMask
= This
->fmt
.dwChannelMask
;
1008 static const struct IXAudio2MasteringVoiceVtbl XAudio2MasteringVoice_Vtbl
= {
1009 XA2M_GetVoiceDetails
,
1010 XA2M_SetOutputVoices
,
1011 XA2M_SetEffectChain
,
1014 XA2M_GetEffectState
,
1015 XA2M_SetEffectParameters
,
1016 XA2M_GetEffectParameters
,
1017 XA2M_SetFilterParameters
,
1018 XA2M_GetFilterParameters
,
1019 XA2M_SetOutputFilterParameters
,
1020 XA2M_GetOutputFilterParameters
,
1023 XA2M_SetChannelVolumes
,
1024 XA2M_GetChannelVolumes
,
1025 XA2M_SetOutputMatrix
,
1026 XA2M_GetOutputMatrix
,
1031 static void WINAPI
XA2SUB_GetVoiceDetails(IXAudio2SubmixVoice
*iface
,
1032 XAUDIO2_VOICE_DETAILS
*pVoiceDetails
)
1034 XA2SubmixImpl
*This
= impl_from_IXAudio2SubmixVoice(iface
);
1036 TRACE("%p, %p\n", This
, pVoiceDetails
);
1038 *pVoiceDetails
= This
->details
;
1041 static HRESULT WINAPI
XA2SUB_SetOutputVoices(IXAudio2SubmixVoice
*iface
,
1042 const XAUDIO2_VOICE_SENDS
*pSendList
)
1044 XA2SubmixImpl
*This
= impl_from_IXAudio2SubmixVoice(iface
);
1045 TRACE("%p, %p\n", This
, pSendList
);
1049 static HRESULT WINAPI
XA2SUB_SetEffectChain(IXAudio2SubmixVoice
*iface
,
1050 const XAUDIO2_EFFECT_CHAIN
*pEffectChain
)
1052 XA2SubmixImpl
*This
= impl_from_IXAudio2SubmixVoice(iface
);
1053 TRACE("%p, %p\n", This
, pEffectChain
);
1057 static HRESULT WINAPI
XA2SUB_EnableEffect(IXAudio2SubmixVoice
*iface
, UINT32 EffectIndex
,
1058 UINT32 OperationSet
)
1060 XA2SubmixImpl
*This
= impl_from_IXAudio2SubmixVoice(iface
);
1061 TRACE("%p, %u, 0x%x\n", This
, EffectIndex
, OperationSet
);
1065 static HRESULT WINAPI
XA2SUB_DisableEffect(IXAudio2SubmixVoice
*iface
, UINT32 EffectIndex
,
1066 UINT32 OperationSet
)
1068 XA2SubmixImpl
*This
= impl_from_IXAudio2SubmixVoice(iface
);
1069 TRACE("%p, %u, 0x%x\n", This
, EffectIndex
, OperationSet
);
1073 static void WINAPI
XA2SUB_GetEffectState(IXAudio2SubmixVoice
*iface
, UINT32 EffectIndex
,
1076 XA2SubmixImpl
*This
= impl_from_IXAudio2SubmixVoice(iface
);
1077 TRACE("%p, %u, %p\n", This
, EffectIndex
, pEnabled
);
1080 static HRESULT WINAPI
XA2SUB_SetEffectParameters(IXAudio2SubmixVoice
*iface
,
1081 UINT32 EffectIndex
, const void *pParameters
, UINT32 ParametersByteSize
,
1082 UINT32 OperationSet
)
1084 XA2SubmixImpl
*This
= impl_from_IXAudio2SubmixVoice(iface
);
1085 TRACE("%p, %u, %p, 0x%x, 0x%x\n", This
, EffectIndex
, pParameters
,
1086 ParametersByteSize
, OperationSet
);
1090 static HRESULT WINAPI
XA2SUB_GetEffectParameters(IXAudio2SubmixVoice
*iface
,
1091 UINT32 EffectIndex
, void *pParameters
, UINT32 ParametersByteSize
)
1093 XA2SubmixImpl
*This
= impl_from_IXAudio2SubmixVoice(iface
);
1094 TRACE("%p, %u, %p, 0x%x\n", This
, EffectIndex
, pParameters
,
1095 ParametersByteSize
);
1099 static HRESULT WINAPI
XA2SUB_SetFilterParameters(IXAudio2SubmixVoice
*iface
,
1100 const XAUDIO2_FILTER_PARAMETERS
*pParameters
, UINT32 OperationSet
)
1102 XA2SubmixImpl
*This
= impl_from_IXAudio2SubmixVoice(iface
);
1103 TRACE("%p, %p, 0x%x\n", This
, pParameters
, OperationSet
);
1107 static void WINAPI
XA2SUB_GetFilterParameters(IXAudio2SubmixVoice
*iface
,
1108 XAUDIO2_FILTER_PARAMETERS
*pParameters
)
1110 XA2SubmixImpl
*This
= impl_from_IXAudio2SubmixVoice(iface
);
1111 TRACE("%p, %p\n", This
, pParameters
);
1114 static HRESULT WINAPI
XA2SUB_SetOutputFilterParameters(IXAudio2SubmixVoice
*iface
,
1115 IXAudio2Voice
*pDestinationVoice
,
1116 const XAUDIO2_FILTER_PARAMETERS
*pParameters
, UINT32 OperationSet
)
1118 XA2SubmixImpl
*This
= impl_from_IXAudio2SubmixVoice(iface
);
1119 TRACE("%p, %p, %p, 0x%x\n", This
, pDestinationVoice
, pParameters
, OperationSet
);
1123 static void WINAPI
XA2SUB_GetOutputFilterParameters(IXAudio2SubmixVoice
*iface
,
1124 IXAudio2Voice
*pDestinationVoice
,
1125 XAUDIO2_FILTER_PARAMETERS
*pParameters
)
1127 XA2SubmixImpl
*This
= impl_from_IXAudio2SubmixVoice(iface
);
1128 TRACE("%p, %p, %p\n", This
, pDestinationVoice
, pParameters
);
1131 static HRESULT WINAPI
XA2SUB_SetVolume(IXAudio2SubmixVoice
*iface
, float Volume
,
1132 UINT32 OperationSet
)
1134 XA2SubmixImpl
*This
= impl_from_IXAudio2SubmixVoice(iface
);
1135 TRACE("%p, %f, 0x%x\n", This
, Volume
, OperationSet
);
1139 static void WINAPI
XA2SUB_GetVolume(IXAudio2SubmixVoice
*iface
, float *pVolume
)
1141 XA2SubmixImpl
*This
= impl_from_IXAudio2SubmixVoice(iface
);
1142 TRACE("%p, %p\n", This
, pVolume
);
1145 static HRESULT WINAPI
XA2SUB_SetChannelVolumes(IXAudio2SubmixVoice
*iface
, UINT32 Channels
,
1146 const float *pVolumes
, UINT32 OperationSet
)
1148 XA2SubmixImpl
*This
= impl_from_IXAudio2SubmixVoice(iface
);
1149 TRACE("%p, %u, %p, 0x%x\n", This
, Channels
, pVolumes
, OperationSet
);
1153 static void WINAPI
XA2SUB_GetChannelVolumes(IXAudio2SubmixVoice
*iface
, UINT32 Channels
,
1156 XA2SubmixImpl
*This
= impl_from_IXAudio2SubmixVoice(iface
);
1157 TRACE("%p, %u, %p\n", This
, Channels
, pVolumes
);
1160 static HRESULT WINAPI
XA2SUB_SetOutputMatrix(IXAudio2SubmixVoice
*iface
,
1161 IXAudio2Voice
*pDestinationVoice
, UINT32 SourceChannels
,
1162 UINT32 DestinationChannels
, const float *pLevelMatrix
,
1163 UINT32 OperationSet
)
1165 XA2SubmixImpl
*This
= impl_from_IXAudio2SubmixVoice(iface
);
1166 TRACE("%p, %p, %u, %u, %p, 0x%x\n", This
, pDestinationVoice
,
1167 SourceChannels
, DestinationChannels
, pLevelMatrix
, OperationSet
);
1171 static void WINAPI
XA2SUB_GetOutputMatrix(IXAudio2SubmixVoice
*iface
,
1172 IXAudio2Voice
*pDestinationVoice
, UINT32 SourceChannels
,
1173 UINT32 DestinationChannels
, float *pLevelMatrix
)
1175 XA2SubmixImpl
*This
= impl_from_IXAudio2SubmixVoice(iface
);
1176 TRACE("%p, %p, %u, %u, %p\n", This
, pDestinationVoice
,
1177 SourceChannels
, DestinationChannels
, pLevelMatrix
);
1180 static void WINAPI
XA2SUB_DestroyVoice(IXAudio2SubmixVoice
*iface
)
1182 XA2SubmixImpl
*This
= impl_from_IXAudio2SubmixVoice(iface
);
1184 TRACE("%p\n", This
);
1186 EnterCriticalSection(&This
->lock
);
1188 This
->in_use
= FALSE
;
1190 LeaveCriticalSection(&This
->lock
);
1193 static const struct IXAudio2SubmixVoiceVtbl XAudio2SubmixVoice_Vtbl
= {
1194 XA2SUB_GetVoiceDetails
,
1195 XA2SUB_SetOutputVoices
,
1196 XA2SUB_SetEffectChain
,
1197 XA2SUB_EnableEffect
,
1198 XA2SUB_DisableEffect
,
1199 XA2SUB_GetEffectState
,
1200 XA2SUB_SetEffectParameters
,
1201 XA2SUB_GetEffectParameters
,
1202 XA2SUB_SetFilterParameters
,
1203 XA2SUB_GetFilterParameters
,
1204 XA2SUB_SetOutputFilterParameters
,
1205 XA2SUB_GetOutputFilterParameters
,
1208 XA2SUB_SetChannelVolumes
,
1209 XA2SUB_GetChannelVolumes
,
1210 XA2SUB_SetOutputMatrix
,
1211 XA2SUB_GetOutputMatrix
,
1215 static HRESULT WINAPI
IXAudio2Impl_QueryInterface(IXAudio2
*iface
, REFIID riid
,
1218 IXAudio2Impl
*This
= impl_from_IXAudio2(iface
);
1220 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppvObject
);
1222 if(IsEqualGUID(riid
, &IID_IUnknown
) ||
1223 IsEqualGUID(riid
, &IID_IXAudio28
) ||
1224 IsEqualGUID(riid
, &IID_IXAudio2
))
1225 *ppvObject
= &This
->IXAudio2_iface
;
1226 else if(IsEqualGUID(riid
, &IID_IXAudio27
)){
1227 /* all xaudio versions before 28 share an IID */
1228 #if XAUDIO2_VER == 0
1229 *ppvObject
= &This
->IXAudio20_iface
;
1230 #elif XAUDIO2_VER <= 2
1231 *ppvObject
= &This
->IXAudio22_iface
;
1232 #elif XAUDIO2_VER <= 7
1233 *ppvObject
= &This
->IXAudio27_iface
;
1241 IUnknown_AddRef((IUnknown
*)*ppvObject
);
1245 FIXME("(%p)->(%s,%p), not found\n", This
,debugstr_guid(riid
), ppvObject
);
1247 return E_NOINTERFACE
;
1250 static ULONG WINAPI
IXAudio2Impl_AddRef(IXAudio2
*iface
)
1252 IXAudio2Impl
*This
= impl_from_IXAudio2(iface
);
1253 ULONG ref
= InterlockedIncrement(&This
->ref
);
1254 TRACE("(%p)->(): Refcount now %u\n", This
, ref
);
1258 static ULONG WINAPI
IXAudio2Impl_Release(IXAudio2
*iface
)
1260 IXAudio2Impl
*This
= impl_from_IXAudio2(iface
);
1261 ULONG ref
= InterlockedDecrement(&This
->ref
);
1263 TRACE("(%p)->(): Refcount now %u\n", This
, ref
);
1267 XA2SourceImpl
*src
, *src2
;
1268 XA2SubmixImpl
*sub
, *sub2
;
1271 This
->stop_engine
= TRUE
;
1272 SetEvent(This
->mmevt
);
1273 WaitForSingleObject(This
->engine
, INFINITE
);
1274 CloseHandle(This
->engine
);
1277 LIST_FOR_EACH_ENTRY_SAFE(src
, src2
, &This
->source_voices
, XA2SourceImpl
, entry
){
1278 HeapFree(GetProcessHeap(), 0, src
->sends
);
1279 IXAudio2SourceVoice_DestroyVoice(&src
->IXAudio2SourceVoice_iface
);
1280 src
->lock
.DebugInfo
->Spare
[0] = 0;
1281 DeleteCriticalSection(&src
->lock
);
1282 HeapFree(GetProcessHeap(), 0, src
);
1285 LIST_FOR_EACH_ENTRY_SAFE(sub
, sub2
, &This
->submix_voices
, XA2SubmixImpl
, entry
){
1286 IXAudio2SubmixVoice_DestroyVoice(&sub
->IXAudio2SubmixVoice_iface
);
1287 sub
->lock
.DebugInfo
->Spare
[0] = 0;
1288 DeleteCriticalSection(&sub
->lock
);
1289 HeapFree(GetProcessHeap(), 0, sub
);
1292 IXAudio2MasteringVoice_DestroyVoice(&This
->IXAudio2MasteringVoice_iface
);
1295 IMMDeviceEnumerator_Release(This
->devenum
);
1296 for(i
= 0; i
< This
->ndevs
; ++i
)
1297 CoTaskMemFree(This
->devids
[i
]);
1298 HeapFree(GetProcessHeap(), 0, This
->devids
);
1299 HeapFree(GetProcessHeap(), 0, This
->cbs
);
1301 CloseHandle(This
->mmevt
);
1303 This
->lock
.DebugInfo
->Spare
[0] = 0;
1304 DeleteCriticalSection(&This
->lock
);
1306 HeapFree(GetProcessHeap(), 0, This
);
1311 static HRESULT WINAPI
IXAudio2Impl_RegisterForCallbacks(IXAudio2
*iface
,
1312 IXAudio2EngineCallback
*pCallback
)
1314 IXAudio2Impl
*This
= impl_from_IXAudio2(iface
);
1317 TRACE("(%p)->(%p)\n", This
, pCallback
);
1319 EnterCriticalSection(&This
->lock
);
1321 for(i
= 0; i
< This
->ncbs
; ++i
){
1322 if(!This
->cbs
[i
] || This
->cbs
[i
] == pCallback
){
1323 This
->cbs
[i
] = pCallback
;
1324 LeaveCriticalSection(&This
->lock
);
1330 This
->cbs
= HeapReAlloc(GetProcessHeap(), 0, This
->cbs
, This
->ncbs
* sizeof(*This
->cbs
));
1332 This
->cbs
[i
] = pCallback
;
1334 LeaveCriticalSection(&This
->lock
);
1339 static void WINAPI
IXAudio2Impl_UnregisterForCallbacks(IXAudio2
*iface
,
1340 IXAudio2EngineCallback
*pCallback
)
1342 IXAudio2Impl
*This
= impl_from_IXAudio2(iface
);
1345 TRACE("(%p)->(%p)\n", This
, pCallback
);
1347 EnterCriticalSection(&This
->lock
);
1349 for(i
= 0; i
< This
->ncbs
; ++i
){
1350 if(This
->cbs
[i
] == pCallback
)
1354 for(; i
< This
->ncbs
- 1 && This
->cbs
[i
+ 1]; ++i
)
1355 This
->cbs
[i
] = This
->cbs
[i
+ 1];
1358 This
->cbs
[i
] = NULL
;
1360 LeaveCriticalSection(&This
->lock
);
1363 static WAVEFORMATEX
*copy_waveformat(const WAVEFORMATEX
*wfex
)
1367 if(wfex
->wFormatTag
== WAVE_FORMAT_PCM
){
1368 pwfx
= HeapAlloc(GetProcessHeap(), 0, sizeof(WAVEFORMATEX
));
1369 CopyMemory(pwfx
, wfex
, sizeof(PCMWAVEFORMAT
));
1372 pwfx
= HeapAlloc(GetProcessHeap(), 0, sizeof(WAVEFORMATEX
) + wfex
->cbSize
);
1373 CopyMemory(pwfx
, wfex
, sizeof(WAVEFORMATEX
) + wfex
->cbSize
);
1379 static HRESULT WINAPI
IXAudio2Impl_CreateSourceVoice(IXAudio2
*iface
,
1380 IXAudio2SourceVoice
**ppSourceVoice
, const WAVEFORMATEX
*pSourceFormat
,
1381 UINT32 flags
, float maxFrequencyRatio
,
1382 IXAudio2VoiceCallback
*pCallback
, const XAUDIO2_VOICE_SENDS
*pSendList
,
1383 const XAUDIO2_EFFECT_CHAIN
*pEffectChain
)
1385 IXAudio2Impl
*This
= impl_from_IXAudio2(iface
);
1389 TRACE("(%p)->(%p, %p, 0x%x, %f, %p, %p, %p)\n", This
, ppSourceVoice
,
1390 pSourceFormat
, flags
, maxFrequencyRatio
, pCallback
, pSendList
,
1393 dump_fmt(pSourceFormat
);
1395 palcSetThreadContext(This
->al_ctx
);
1397 EnterCriticalSection(&This
->lock
);
1399 LIST_FOR_EACH_ENTRY(src
, &This
->source_voices
, XA2SourceImpl
, entry
){
1400 EnterCriticalSection(&src
->lock
);
1403 LeaveCriticalSection(&src
->lock
);
1406 if(&src
->entry
== &This
->source_voices
){
1407 src
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*src
));
1409 LeaveCriticalSection(&This
->lock
);
1410 return E_OUTOFMEMORY
;
1413 list_add_head(&This
->source_voices
, &src
->entry
);
1415 src
->IXAudio2SourceVoice_iface
.lpVtbl
= &XAudio2SourceVoice_Vtbl
;
1417 #if XAUDIO2_VER == 0
1418 src
->IXAudio20SourceVoice_iface
.lpVtbl
= &XAudio20SourceVoice_Vtbl
;
1419 #elif XAUDIO2_VER <= 3
1420 src
->IXAudio23SourceVoice_iface
.lpVtbl
= &XAudio23SourceVoice_Vtbl
;
1421 #elif XAUDIO2_VER <= 7
1422 src
->IXAudio27SourceVoice_iface
.lpVtbl
= &XAudio27SourceVoice_Vtbl
;
1425 InitializeCriticalSection(&src
->lock
);
1426 src
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": XA2SourceImpl.lock");
1430 EnterCriticalSection(&src
->lock
);
1434 src
->running
= FALSE
;
1436 LeaveCriticalSection(&This
->lock
);
1438 src
->cb
= pCallback
;
1440 src
->al_fmt
= get_al_format(pSourceFormat
);
1442 src
->in_use
= FALSE
;
1443 LeaveCriticalSection(&src
->lock
);
1444 WARN("OpenAL can't convert this format!\n");
1445 return AUDCLNT_E_UNSUPPORTED_FORMAT
;
1448 src
->submit_blocksize
= pSourceFormat
->nBlockAlign
;
1450 src
->fmt
= copy_waveformat(pSourceFormat
);
1452 hr
= XA2SRC_SetOutputVoices(&src
->IXAudio2SourceVoice_iface
, pSendList
);
1454 HeapFree(GetProcessHeap(), 0, src
->fmt
);
1455 src
->in_use
= FALSE
;
1456 LeaveCriticalSection(&src
->lock
);
1460 alGenSources(1, &src
->al_src
);
1462 static int once
= 0;
1464 ERR_(winediag
)("OpenAL ran out of sources, consider increasing its source limit.\n");
1465 HeapFree(GetProcessHeap(), 0, src
->fmt
);
1466 src
->in_use
= FALSE
;
1467 LeaveCriticalSection(&src
->lock
);
1468 return E_OUTOFMEMORY
;
1471 alGenBuffers(XAUDIO2_MAX_QUEUED_BUFFERS
, src
->al_bufs
);
1473 alSourcePlay(src
->al_src
);
1475 LeaveCriticalSection(&src
->lock
);
1477 #if XAUDIO2_VER == 0
1478 *ppSourceVoice
= (IXAudio2SourceVoice
*)&src
->IXAudio20SourceVoice_iface
;
1479 #elif XAUDIO2_VER <= 3
1480 *ppSourceVoice
= (IXAudio2SourceVoice
*)&src
->IXAudio23SourceVoice_iface
;
1481 #elif XAUDIO2_VER <= 7
1482 *ppSourceVoice
= (IXAudio2SourceVoice
*)&src
->IXAudio27SourceVoice_iface
;
1484 *ppSourceVoice
= &src
->IXAudio2SourceVoice_iface
;
1487 TRACE("Created source voice: %p\n", src
);
1492 static HRESULT WINAPI
IXAudio2Impl_CreateSubmixVoice(IXAudio2
*iface
,
1493 IXAudio2SubmixVoice
**ppSubmixVoice
, UINT32 inputChannels
,
1494 UINT32 inputSampleRate
, UINT32 flags
, UINT32 processingStage
,
1495 const XAUDIO2_VOICE_SENDS
*pSendList
,
1496 const XAUDIO2_EFFECT_CHAIN
*pEffectChain
)
1498 IXAudio2Impl
*This
= impl_from_IXAudio2(iface
);
1501 TRACE("(%p)->(%p, %u, %u, 0x%x, %u, %p, %p)\n", This
, ppSubmixVoice
,
1502 inputChannels
, inputSampleRate
, flags
, processingStage
, pSendList
,
1505 EnterCriticalSection(&This
->lock
);
1507 LIST_FOR_EACH_ENTRY(sub
, &This
->submix_voices
, XA2SubmixImpl
, entry
){
1508 EnterCriticalSection(&sub
->lock
);
1511 LeaveCriticalSection(&sub
->lock
);
1514 if(&sub
->entry
== &This
->submix_voices
){
1515 sub
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*sub
));
1517 LeaveCriticalSection(&This
->lock
);
1518 return E_OUTOFMEMORY
;
1521 list_add_head(&This
->submix_voices
, &sub
->entry
);
1523 sub
->IXAudio2SubmixVoice_iface
.lpVtbl
= &XAudio2SubmixVoice_Vtbl
;
1525 #if XAUDIO2_VER == 0
1526 sub
->IXAudio20SubmixVoice_iface
.lpVtbl
= &XAudio20SubmixVoice_Vtbl
;
1527 #elif XAUDIO2_VER <= 3
1528 sub
->IXAudio23SubmixVoice_iface
.lpVtbl
= &XAudio23SubmixVoice_Vtbl
;
1529 #elif XAUDIO2_VER <= 7
1530 sub
->IXAudio27SubmixVoice_iface
.lpVtbl
= &XAudio27SubmixVoice_Vtbl
;
1533 InitializeCriticalSection(&sub
->lock
);
1534 sub
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": XA2SubmixImpl.lock");
1536 EnterCriticalSection(&sub
->lock
);
1541 sub
->details
.CreationFlags
= flags
;
1542 sub
->details
.ActiveFlags
= flags
;
1543 sub
->details
.InputChannels
= inputChannels
;
1544 sub
->details
.InputSampleRate
= inputSampleRate
;
1546 LeaveCriticalSection(&This
->lock
);
1547 LeaveCriticalSection(&sub
->lock
);
1549 #if XAUDIO2_VER == 0
1550 *ppSubmixVoice
= (IXAudio2SubmixVoice
*)&sub
->IXAudio20SubmixVoice_iface
;
1551 #elif XAUDIO2_VER <= 3
1552 *ppSubmixVoice
= (IXAudio2SubmixVoice
*)&sub
->IXAudio23SubmixVoice_iface
;
1553 #elif XAUDIO2_VER <= 7
1554 *ppSubmixVoice
= (IXAudio2SubmixVoice
*)&sub
->IXAudio27SubmixVoice_iface
;
1556 *ppSubmixVoice
= &sub
->IXAudio2SubmixVoice_iface
;
1559 TRACE("Created submix voice: %p\n", sub
);
1564 static ALenum
al_get_loopback_format(const WAVEFORMATEXTENSIBLE
*fmt
)
1566 if(fmt
->Format
.wFormatTag
== WAVE_FORMAT_PCM
||
1567 (fmt
->Format
.wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
1568 IsEqualGUID(&fmt
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
))){
1569 switch(fmt
->Format
.wBitsPerSample
){
1571 return ALC_UNSIGNED_BYTE_SOFT
;
1573 return ALC_SHORT_SOFT
;
1575 return ALC_INT_SOFT
;
1577 }else if(fmt
->Format
.wFormatTag
== WAVE_FORMAT_IEEE_FLOAT
||
1578 (fmt
->Format
.wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
1579 IsEqualGUID(&fmt
->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
))){
1580 if(fmt
->Format
.wBitsPerSample
== 32)
1581 return ALC_FLOAT_SOFT
;
1586 static HRESULT WINAPI
IXAudio2Impl_CreateMasteringVoice(IXAudio2
*iface
,
1587 IXAudio2MasteringVoice
**ppMasteringVoice
, UINT32 inputChannels
,
1588 UINT32 inputSampleRate
, UINT32 flags
, const WCHAR
*deviceId
,
1589 const XAUDIO2_EFFECT_CHAIN
*pEffectChain
,
1590 AUDIO_STREAM_CATEGORY streamCategory
)
1592 IXAudio2Impl
*This
= impl_from_IXAudio2(iface
);
1597 REFERENCE_TIME period
, bufdur
;
1599 TRACE("(%p)->(%p, %u, %u, 0x%x, %s, %p, 0x%x)\n", This
,
1600 ppMasteringVoice
, inputChannels
, inputSampleRate
, flags
,
1601 wine_dbgstr_w(deviceId
), pEffectChain
, streamCategory
);
1604 WARN("Unknown flags set: 0x%x\n", flags
);
1607 WARN("Effect chain is unimplemented\n");
1609 EnterCriticalSection(&This
->lock
);
1611 /* there can only be one Mastering Voice, so just build it into XA2 */
1613 LeaveCriticalSection(&This
->lock
);
1614 return COMPAT_E_INVALID_CALL
;
1618 if(This
->ndevs
== 0){
1619 LeaveCriticalSection(&This
->lock
);
1622 deviceId
= This
->devids
[0];
1625 hr
= IMMDeviceEnumerator_GetDevice(This
->devenum
, deviceId
, &dev
);
1627 WARN("GetDevice failed: %08x\n", hr
);
1628 hr
= COMPAT_E_DEVICE_INVALIDATED
;
1632 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
,
1633 CLSCTX_INPROC_SERVER
, NULL
, (void**)&This
->aclient
);
1635 WARN("Activate(IAudioClient) failed: %08x\n", hr
);
1636 IMMDevice_Release(dev
);
1637 hr
= COMPAT_E_DEVICE_INVALIDATED
;
1641 IMMDevice_Release(dev
);
1643 hr
= IAudioClient_GetMixFormat(This
->aclient
, &fmt
);
1645 WARN("GetMixFormat failed: %08x\n", hr
);
1646 hr
= COMPAT_E_DEVICE_INVALIDATED
;
1650 if(sizeof(WAVEFORMATEX
) + fmt
->cbSize
> sizeof(WAVEFORMATEXTENSIBLE
)){
1651 FIXME("Mix format doesn't fit into WAVEFORMATEXTENSIBLE!\n");
1652 hr
= COMPAT_E_DEVICE_INVALIDATED
;
1656 if(inputChannels
== XAUDIO2_DEFAULT_CHANNELS
)
1657 inputChannels
= fmt
->nChannels
;
1658 if(inputSampleRate
== XAUDIO2_DEFAULT_SAMPLERATE
)
1659 inputSampleRate
= fmt
->nSamplesPerSec
;
1661 memcpy(&This
->fmt
, fmt
, sizeof(WAVEFORMATEX
) + fmt
->cbSize
);
1662 This
->fmt
.Format
.nChannels
= inputChannels
;
1663 This
->fmt
.Format
.nSamplesPerSec
= inputSampleRate
;
1664 This
->fmt
.Format
.nBlockAlign
= This
->fmt
.Format
.nChannels
* This
->fmt
.Format
.wBitsPerSample
/ 8;
1665 This
->fmt
.Format
.nAvgBytesPerSec
= This
->fmt
.Format
.nSamplesPerSec
* This
->fmt
.Format
.nBlockAlign
;
1666 This
->fmt
.dwChannelMask
= get_channel_mask(This
->fmt
.Format
.nChannels
);
1671 hr
= IAudioClient_IsFormatSupported(This
->aclient
,
1672 AUDCLNT_SHAREMODE_SHARED
, &This
->fmt
.Format
, &fmt
);
1674 if(sizeof(WAVEFORMATEX
) + fmt
->cbSize
> sizeof(WAVEFORMATEXTENSIBLE
)){
1675 FIXME("Mix format doesn't fit into WAVEFORMATEXTENSIBLE!\n");
1676 hr
= COMPAT_E_DEVICE_INVALIDATED
;
1679 memcpy(&This
->fmt
, fmt
, sizeof(WAVEFORMATEX
) + fmt
->cbSize
);
1684 hr
= IAudioClient_GetDevicePeriod(This
->aclient
, &period
, NULL
);
1686 WARN("GetDevicePeriod failed: %08x\n", hr
);
1687 hr
= COMPAT_E_DEVICE_INVALIDATED
;
1691 /* 3 periods or 0.1 seconds */
1692 bufdur
= max(3 * period
, 1000000);
1694 hr
= IAudioClient_Initialize(This
->aclient
, AUDCLNT_SHAREMODE_SHARED
,
1695 AUDCLNT_STREAMFLAGS_EVENTCALLBACK
, bufdur
,
1696 0, &This
->fmt
.Format
, NULL
);
1698 WARN("Initialize failed: %08x\n", hr
);
1699 hr
= COMPAT_E_DEVICE_INVALIDATED
;
1703 This
->period_frames
= MulDiv(period
, inputSampleRate
, 10000000);
1705 hr
= IAudioClient_SetEventHandle(This
->aclient
, This
->mmevt
);
1707 WARN("Initialize failed: %08x\n", hr
);
1708 hr
= COMPAT_E_DEVICE_INVALIDATED
;
1712 hr
= IAudioClient_GetService(This
->aclient
, &IID_IAudioRenderClient
,
1713 (void**)&This
->render
);
1715 WARN("GetService(IAudioRenderClient) failed: %08x\n", hr
);
1716 hr
= COMPAT_E_DEVICE_INVALIDATED
;
1720 /* setup openal context */
1721 attrs
[0] = ALC_FORMAT_CHANNELS_SOFT
;
1722 switch(inputChannels
){
1724 attrs
[1] = ALC_MONO_SOFT
;
1727 attrs
[1] = ALC_STEREO_SOFT
;
1730 attrs
[1] = ALC_QUAD_SOFT
;
1733 attrs
[1] = ALC_5POINT1_SOFT
;
1736 attrs
[1] = ALC_6POINT1_SOFT
;
1739 attrs
[1] = ALC_7POINT1_SOFT
;
1742 WARN("OpenAL doesn't support %u channels\n", inputChannels
);
1743 LeaveCriticalSection(&This
->lock
);
1744 return AUDCLNT_E_UNSUPPORTED_FORMAT
;
1746 attrs
[2] = ALC_FREQUENCY
;
1747 attrs
[3] = inputSampleRate
;
1748 attrs
[4] = ALC_FORMAT_TYPE_SOFT
;
1749 attrs
[5] = al_get_loopback_format(&This
->fmt
);
1753 WARN("OpenAL can't output samples in this format\n");
1754 hr
= COMPAT_E_DEVICE_INVALIDATED
;
1758 This
->al_device
= palcLoopbackOpenDeviceSOFT(NULL
);
1759 if(!This
->al_device
){
1760 WARN("alcLoopbackOpenDeviceSOFT failed\n");
1761 hr
= COMPAT_E_DEVICE_INVALIDATED
;
1765 This
->al_ctx
= alcCreateContext(This
->al_device
, attrs
);
1767 WARN("alcCreateContext failed\n");
1768 hr
= COMPAT_E_DEVICE_INVALIDATED
;
1772 hr
= IAudioClient_Start(This
->aclient
);
1775 WARN("Start(IAudioClient) failed: %08x\n", hr
);
1776 hr
= COMPAT_E_DEVICE_INVALIDATED
;
1780 #if XAUDIO2_VER == 0
1781 *ppMasteringVoice
= (IXAudio2MasteringVoice
*)&This
->IXAudio20MasteringVoice_iface
;
1782 #elif XAUDIO2_VER <= 3
1783 *ppMasteringVoice
= (IXAudio2MasteringVoice
*)&This
->IXAudio23MasteringVoice_iface
;
1784 #elif XAUDIO2_VER <= 7
1785 *ppMasteringVoice
= (IXAudio2MasteringVoice
*)&This
->IXAudio27MasteringVoice_iface
;
1787 *ppMasteringVoice
= &This
->IXAudio2MasteringVoice_iface
;
1793 IAudioRenderClient_Release(This
->render
);
1794 This
->render
= NULL
;
1797 IAudioClient_Release(This
->aclient
);
1798 This
->aclient
= NULL
;
1801 alcDestroyContext(This
->al_ctx
);
1802 This
->al_ctx
= NULL
;
1804 if(This
->al_device
){
1805 alcCloseDevice(This
->al_device
);
1806 This
->al_device
= NULL
;
1810 LeaveCriticalSection(&This
->lock
);
1815 static DWORD WINAPI
engine_threadproc(void *arg
);
1817 static HRESULT WINAPI
IXAudio2Impl_StartEngine(IXAudio2
*iface
)
1819 IXAudio2Impl
*This
= impl_from_IXAudio2(iface
);
1821 TRACE("(%p)->()\n", This
);
1823 This
->running
= TRUE
;
1826 This
->engine
= CreateThread(NULL
, 0, engine_threadproc
, This
, 0, NULL
);
1831 static void WINAPI
IXAudio2Impl_StopEngine(IXAudio2
*iface
)
1833 IXAudio2Impl
*This
= impl_from_IXAudio2(iface
);
1835 TRACE("(%p)->()\n", This
);
1837 This
->running
= FALSE
;
1840 static HRESULT WINAPI
IXAudio2Impl_CommitChanges(IXAudio2
*iface
,
1841 UINT32 operationSet
)
1843 IXAudio2Impl
*This
= impl_from_IXAudio2(iface
);
1845 TRACE("(%p)->(0x%x): stub!\n", This
, operationSet
);
1850 static void WINAPI
IXAudio2Impl_GetPerformanceData(IXAudio2
*iface
,
1851 XAUDIO2_PERFORMANCE_DATA
*pPerfData
)
1853 IXAudio2Impl
*This
= impl_from_IXAudio2(iface
);
1855 TRACE("(%p)->(%p): stub!\n", This
, pPerfData
);
1857 memset(pPerfData
, 0, sizeof(*pPerfData
));
1860 static void WINAPI
IXAudio2Impl_SetDebugConfiguration(IXAudio2
*iface
,
1861 const XAUDIO2_DEBUG_CONFIGURATION
*pDebugConfiguration
,
1864 IXAudio2Impl
*This
= impl_from_IXAudio2(iface
);
1866 FIXME("(%p)->(%p, %p): stub!\n", This
, pDebugConfiguration
, pReserved
);
1870 static const IXAudio2Vtbl XAudio2_Vtbl
=
1872 IXAudio2Impl_QueryInterface
,
1873 IXAudio2Impl_AddRef
,
1874 IXAudio2Impl_Release
,
1875 IXAudio2Impl_RegisterForCallbacks
,
1876 IXAudio2Impl_UnregisterForCallbacks
,
1877 IXAudio2Impl_CreateSourceVoice
,
1878 IXAudio2Impl_CreateSubmixVoice
,
1879 IXAudio2Impl_CreateMasteringVoice
,
1880 IXAudio2Impl_StartEngine
,
1881 IXAudio2Impl_StopEngine
,
1882 IXAudio2Impl_CommitChanges
,
1883 IXAudio2Impl_GetPerformanceData
,
1884 IXAudio2Impl_SetDebugConfiguration
1888 IClassFactory IClassFactory_iface
;
1892 static struct xaudio2_cf
*impl_from_IClassFactory(IClassFactory
*iface
)
1894 return CONTAINING_RECORD(iface
, struct xaudio2_cf
, IClassFactory_iface
);
1897 static HRESULT WINAPI
XAudio2CF_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppobj
)
1899 if(IsEqualGUID(riid
, &IID_IUnknown
)
1900 || IsEqualGUID(riid
, &IID_IClassFactory
))
1902 IClassFactory_AddRef(iface
);
1908 WARN("(%p)->(%s, %p): interface not found\n", iface
, debugstr_guid(riid
), ppobj
);
1909 return E_NOINTERFACE
;
1912 static ULONG WINAPI
XAudio2CF_AddRef(IClassFactory
*iface
)
1914 struct xaudio2_cf
*This
= impl_from_IClassFactory(iface
);
1915 ULONG ref
= InterlockedIncrement(&This
->ref
);
1916 TRACE("(%p)->(): Refcount now %u\n", This
, ref
);
1920 static ULONG WINAPI
XAudio2CF_Release(IClassFactory
*iface
)
1922 struct xaudio2_cf
*This
= impl_from_IClassFactory(iface
);
1923 ULONG ref
= InterlockedDecrement(&This
->ref
);
1924 TRACE("(%p)->(): Refcount now %u\n", This
, ref
);
1926 HeapFree(GetProcessHeap(), 0, This
);
1930 static HRESULT
initialize_mmdevices(IXAudio2Impl
*This
)
1932 IMMDeviceCollection
*devcoll
;
1937 hr
= CoCreateInstance(&CLSID_MMDeviceEnumerator
, NULL
,
1938 CLSCTX_INPROC_SERVER
, &IID_IMMDeviceEnumerator
, (void**)&This
->devenum
);
1943 hr
= IMMDeviceEnumerator_EnumAudioEndpoints(This
->devenum
, eRender
,
1944 DEVICE_STATE_ACTIVE
, &devcoll
);
1949 hr
= IMMDeviceCollection_GetCount(devcoll
, &devcount
);
1951 IMMDeviceCollection_Release(devcoll
);
1957 IMMDevice
*dev
, *def_dev
;
1959 /* make sure that device 0 is the default device */
1960 IMMDeviceEnumerator_GetDefaultAudioEndpoint(This
->devenum
, eRender
, eConsole
, &def_dev
);
1962 This
->devids
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
*) * devcount
);
1964 for(i
= 0; i
< devcount
; ++i
){
1965 hr
= IMMDeviceCollection_Item(devcoll
, i
, &dev
);
1976 hr
= IMMDevice_GetId(dev
, &This
->devids
[idx
]);
1978 WARN("GetId failed: %08x\n", hr
);
1979 HeapFree(GetProcessHeap(), 0, This
->devids
);
1980 This
->devids
= NULL
;
1981 IMMDevice_Release(dev
);
1985 IMMDevice_Release(dev
);
1987 WARN("Item failed: %08x\n", hr
);
1988 HeapFree(GetProcessHeap(), 0, This
->devids
);
1989 This
->devids
= NULL
;
1990 IMMDeviceCollection_Release(devcoll
);
1996 IMMDeviceCollection_Release(devcoll
);
1998 This
->ndevs
= devcount
;
2003 static HRESULT WINAPI
XAudio2CF_CreateInstance(IClassFactory
*iface
, IUnknown
*pOuter
,
2004 REFIID riid
, void **ppobj
)
2006 struct xaudio2_cf
*This
= impl_from_IClassFactory(iface
);
2008 IXAudio2Impl
*object
;
2010 TRACE("(%p)->(%p,%s,%p)\n", This
, pOuter
, debugstr_guid(riid
), ppobj
);
2015 return CLASS_E_NOAGGREGATION
;
2017 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2019 return E_OUTOFMEMORY
;
2021 object
->IXAudio2_iface
.lpVtbl
= &XAudio2_Vtbl
;
2022 object
->IXAudio2MasteringVoice_iface
.lpVtbl
= &XAudio2MasteringVoice_Vtbl
;
2024 #if XAUDIO2_VER == 0
2025 object
->IXAudio20_iface
.lpVtbl
= &XAudio20_Vtbl
;
2026 #elif XAUDIO2_VER <= 2
2027 object
->IXAudio22_iface
.lpVtbl
= &XAudio22_Vtbl
;
2028 #elif XAUDIO2_VER <= 7
2029 object
->IXAudio27_iface
.lpVtbl
= &XAudio27_Vtbl
;
2032 #if XAUDIO2_VER == 0
2033 object
->IXAudio20MasteringVoice_iface
.lpVtbl
= &XAudio20MasteringVoice_Vtbl
;
2034 #elif XAUDIO2_VER <= 3
2035 object
->IXAudio23MasteringVoice_iface
.lpVtbl
= &XAudio23MasteringVoice_Vtbl
;
2036 #elif XAUDIO2_VER <= 7
2037 object
->IXAudio27MasteringVoice_iface
.lpVtbl
= &XAudio27MasteringVoice_Vtbl
;
2040 list_init(&object
->source_voices
);
2041 list_init(&object
->submix_voices
);
2043 object
->mmevt
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2044 InitializeCriticalSection(&object
->lock
);
2045 object
->lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": IXAudio2Impl.lock");
2047 hr
= IXAudio2_QueryInterface(&object
->IXAudio2_iface
, riid
, ppobj
);
2049 HeapFree(GetProcessHeap(), 0, object
);
2053 hr
= initialize_mmdevices(object
);
2055 IUnknown_Release((IUnknown
*)*ppobj
);
2060 object
->cbs
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, object
->ncbs
* sizeof(*object
->cbs
));
2062 IXAudio2_StartEngine(&object
->IXAudio2_iface
);
2064 TRACE("Created XAudio version %u: %p\n", 20 + XAUDIO2_VER
, object
);
2069 static HRESULT WINAPI
XAudio2CF_LockServer(IClassFactory
*iface
, BOOL dolock
)
2071 FIXME("(static)->(%d): stub!\n", dolock
);
2075 static const IClassFactoryVtbl XAudio2CF_Vtbl
=
2077 XAudio2CF_QueryInterface
,
2080 XAudio2CF_CreateInstance
,
2081 XAudio2CF_LockServer
2084 static IClassFactory
*make_xaudio2_factory(void)
2086 struct xaudio2_cf
*ret
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct xaudio2_cf
));
2087 ret
->IClassFactory_iface
.lpVtbl
= &XAudio2CF_Vtbl
;
2089 return &ret
->IClassFactory_iface
;
2092 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, void **ppv
)
2094 IClassFactory
*factory
= NULL
;
2096 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
2098 if(IsEqualGUID(rclsid
, &CLSID_XAudio20
) ||
2099 IsEqualGUID(rclsid
, &CLSID_XAudio21
) ||
2100 IsEqualGUID(rclsid
, &CLSID_XAudio22
) ||
2101 IsEqualGUID(rclsid
, &CLSID_XAudio23
) ||
2102 IsEqualGUID(rclsid
, &CLSID_XAudio24
) ||
2103 IsEqualGUID(rclsid
, &CLSID_XAudio25
) ||
2104 IsEqualGUID(rclsid
, &CLSID_XAudio26
) ||
2105 IsEqualGUID(rclsid
, &CLSID_XAudio27
)){
2106 factory
= make_xaudio2_factory();
2108 }else if(IsEqualGUID(rclsid
, &CLSID_AudioVolumeMeter20
) ||
2109 IsEqualGUID(rclsid
, &CLSID_AudioVolumeMeter21
) ||
2110 IsEqualGUID(rclsid
, &CLSID_AudioVolumeMeter22
) ||
2111 IsEqualGUID(rclsid
, &CLSID_AudioVolumeMeter23
) ||
2112 IsEqualGUID(rclsid
, &CLSID_AudioVolumeMeter24
) ||
2113 IsEqualGUID(rclsid
, &CLSID_AudioVolumeMeter25
) ||
2114 IsEqualGUID(rclsid
, &CLSID_AudioVolumeMeter26
) ||
2115 IsEqualGUID(rclsid
, &CLSID_AudioVolumeMeter27
)){
2116 factory
= make_xapo_factory(&CLSID_AudioVolumeMeter27
);
2118 }else if(IsEqualGUID(rclsid
, &CLSID_AudioReverb20
) ||
2119 IsEqualGUID(rclsid
, &CLSID_AudioReverb21
) ||
2120 IsEqualGUID(rclsid
, &CLSID_AudioReverb22
) ||
2121 IsEqualGUID(rclsid
, &CLSID_AudioReverb23
) ||
2122 IsEqualGUID(rclsid
, &CLSID_AudioReverb24
) ||
2123 IsEqualGUID(rclsid
, &CLSID_AudioReverb25
) ||
2124 IsEqualGUID(rclsid
, &CLSID_AudioReverb26
) ||
2125 IsEqualGUID(rclsid
, &CLSID_AudioReverb27
)){
2126 factory
= make_xapo_factory(&CLSID_FXReverb
);
2129 if(!factory
) return CLASS_E_CLASSNOTAVAILABLE
;
2131 return IClassFactory_QueryInterface(factory
, riid
, ppv
);
2134 HRESULT
xaudio2_initialize(IXAudio2Impl
*This
, UINT32 flags
, XAUDIO2_PROCESSOR proc
)
2137 FIXME("Unimplemented flags: 0x%x\n", flags
);
2141 #if XAUDIO2_VER >= 8
2142 HRESULT WINAPI
XAudio2Create(IXAudio2
**ppxa2
, UINT32 flags
, XAUDIO2_PROCESSOR proc
)
2148 TRACE("%p 0x%x 0x%x\n", ppxa2
, flags
, proc
);
2150 cf
= make_xaudio2_factory();
2152 hr
= IClassFactory_CreateInstance(cf
, NULL
, &IID_IXAudio2
, (void**)&xa2
);
2153 IClassFactory_Release(cf
);
2157 hr
= xaudio2_initialize(impl_from_IXAudio2(xa2
), flags
, proc
);
2159 IXAudio2_Release(xa2
);
2167 #endif /* XAUDIO2_VER >= 8 */
2169 /* returns TRUE if there is more data available in the buffer, FALSE if the
2170 * buffer's data has all been queued */
2171 static BOOL
xa2buffer_queue_period(XA2SourceImpl
*src
, XA2Buffer
*buf
, ALuint al_buf
)
2173 UINT32 submit_bytes
;
2174 const BYTE
*submit_buf
= NULL
;
2176 if(buf
->offs_bytes
>= buf
->cur_end_bytes
){
2177 WARN("Shouldn't happen: Trying to push frames from a spent buffer?\n");
2181 submit_bytes
= min(src
->xa2
->period_frames
* src
->submit_blocksize
, buf
->cur_end_bytes
- buf
->offs_bytes
);
2182 submit_buf
= buf
->xa2buffer
.pAudioData
+ buf
->offs_bytes
;
2183 buf
->offs_bytes
+= submit_bytes
;
2185 alBufferData(al_buf
, src
->al_fmt
, submit_buf
, submit_bytes
,
2186 src
->fmt
->nSamplesPerSec
);
2188 alSourceQueueBuffers(src
->al_src
, 1, &al_buf
);
2190 src
->in_al_bytes
+= submit_bytes
;
2191 src
->al_bufs_used
++;
2193 buf
->latest_al_buf
= al_buf
;
2195 TRACE("queueing %u bytes, now %u in AL\n", submit_bytes
, src
->in_al_bytes
);
2197 return buf
->offs_bytes
< buf
->cur_end_bytes
;
2201 static UINT32
get_underrun_warning(XA2SourceImpl
*src
)
2203 UINT32 period_bytes
= src
->xa2
->period_frames
* src
->submit_blocksize
;
2204 UINT32 total
= 0, i
;
2206 for(i
= 0; i
< src
->nbufs
&& total
< IN_AL_PERIODS
* period_bytes
; ++i
){
2207 XA2Buffer
*buf
= &src
->buffers
[(src
->first_buf
+ i
) % XAUDIO2_MAX_QUEUED_BUFFERS
];
2208 total
+= buf
->cur_end_bytes
- buf
->offs_bytes
;
2209 if(buf
->xa2buffer
.LoopCount
== XAUDIO2_LOOP_INFINITE
)
2211 if(buf
->xa2buffer
.LoopCount
> 0){
2212 total
+= (buf
->loop_end_bytes
- buf
->xa2buffer
.LoopBegin
) * (buf
->xa2buffer
.LoopCount
- buf
->looped
);
2213 total
+= buf
->play_end_bytes
- buf
->loop_end_bytes
;
2217 if(total
>= IN_AL_PERIODS
* period_bytes
)
2220 return ((IN_AL_PERIODS
* period_bytes
- total
) / period_bytes
+ 1) * period_bytes
;
2226 * The looped section of a buffer is a subset of the play area which is looped
2230 * vvvvvvvvvvvvvvvvvv PlayLength
2232 * [-----PPPLLLLLLLLPPPPPPP------]
2234 * ^^^^^^^^ LoopLength
2237 * In the simple case, playback will start at PlayBegin. At LoopEnd, playback
2238 * will move to LoopBegin and repeat that loop LoopCount times. Then, playback
2239 * will cease at PlayEnd.
2241 * If PlayLength is zero, then PlayEnd is the end of the buffer.
2243 * If LoopLength is zero, then LoopEnd is PlayEnd.
2245 * For corner cases and version differences, see tests.
2247 static void update_source_state(XA2SourceImpl
*src
)
2253 alGetSourcei(src
->al_src
, AL_BUFFERS_PROCESSED
, &processed
);
2256 ALuint al_buffers
[XAUDIO2_MAX_QUEUED_BUFFERS
];
2258 alSourceUnqueueBuffers(src
->al_src
, processed
, al_buffers
);
2259 src
->first_al_buf
+= processed
;
2260 src
->first_al_buf
%= XAUDIO2_MAX_QUEUED_BUFFERS
;
2261 src
->al_bufs_used
-= processed
;
2263 for(i
= 0; i
< processed
; ++i
){
2266 alGetBufferi(al_buffers
[i
], AL_SIZE
, &bufsize
);
2268 src
->in_al_bytes
-= bufsize
;
2269 src
->played_frames
+= bufsize
/ src
->submit_blocksize
;
2271 if(al_buffers
[i
] == src
->buffers
[src
->first_buf
].latest_al_buf
){
2272 DWORD old_buf
= src
->first_buf
;
2275 src
->first_buf
%= XAUDIO2_MAX_QUEUED_BUFFERS
;
2278 TRACE("%p: done with buffer %u\n", src
, old_buf
);
2280 if(src
->buffers
[old_buf
].xa2buffer
.Flags
& XAUDIO2_END_OF_STREAM
)
2281 src
->played_frames
= 0;
2284 IXAudio2VoiceCallback_OnBufferEnd(src
->cb
,
2285 src
->buffers
[old_buf
].xa2buffer
.pContext
);
2286 if(src
->buffers
[old_buf
].xa2buffer
.Flags
& XAUDIO2_END_OF_STREAM
)
2287 IXAudio2VoiceCallback_OnStreamEnd(src
->cb
);
2290 IXAudio2VoiceCallback_OnBufferStart(src
->cb
,
2291 src
->buffers
[src
->first_buf
].xa2buffer
.pContext
);
2297 alGetSourcei(src
->al_src
, AL_BYTE_OFFSET
, &bufpos
);
2299 /* maintain IN_AL_PERIODS periods in AL */
2300 while(src
->cur_buf
!= (src
->first_buf
+ src
->nbufs
) % XAUDIO2_MAX_QUEUED_BUFFERS
&&
2301 src
->in_al_bytes
- bufpos
< IN_AL_PERIODS
* src
->xa2
->period_frames
* src
->submit_blocksize
){
2302 TRACE("%p: going to queue a period from buffer %u\n", src
, src
->cur_buf
);
2304 /* starting from an empty buffer */
2305 if(src
->cb
&& src
->cur_buf
== src
->first_buf
&& src
->buffers
[src
->cur_buf
].offs_bytes
== 0 && !src
->buffers
[src
->cur_buf
].looped
)
2306 IXAudio2VoiceCallback_OnBufferStart(src
->cb
,
2307 src
->buffers
[src
->first_buf
].xa2buffer
.pContext
);
2309 if(!xa2buffer_queue_period(src
, &src
->buffers
[src
->cur_buf
],
2310 src
->al_bufs
[(src
->first_al_buf
+ src
->al_bufs_used
) % XAUDIO2_MAX_QUEUED_BUFFERS
])){
2311 XA2Buffer
*cur
= &src
->buffers
[src
->cur_buf
];
2313 if(cur
->looped
< cur
->xa2buffer
.LoopCount
){
2314 if(cur
->xa2buffer
.LoopCount
!= XAUDIO2_LOOP_INFINITE
)
2317 cur
->looped
= 1; /* indicate that we are executing a loop */
2319 cur
->offs_bytes
= cur
->xa2buffer
.LoopBegin
;
2320 if(cur
->looped
== cur
->xa2buffer
.LoopCount
)
2321 cur
->cur_end_bytes
= cur
->play_end_bytes
;
2323 cur
->cur_end_bytes
= cur
->loop_end_bytes
;
2326 IXAudio2VoiceCallback_OnLoopEnd(src
->cb
,
2327 src
->buffers
[src
->cur_buf
].xa2buffer
.pContext
);
2330 /* buffer is spent, move on */
2332 src
->cur_buf
%= XAUDIO2_MAX_QUEUED_BUFFERS
;
2338 static void do_engine_tick(IXAudio2Impl
*This
)
2343 UINT32 nframes
, i
, pad
;
2345 /* maintain up to 3 periods in mmdevapi */
2346 hr
= IAudioClient_GetCurrentPadding(This
->aclient
, &pad
);
2348 WARN("GetCurrentPadding failed: 0x%x\n", hr
);
2352 nframes
= This
->period_frames
* 3 - pad
;
2354 TRACE("frames available: %u\n", nframes
);
2356 if(nframes
< This
->period_frames
)
2362 for(i
= 0; i
< This
->ncbs
&& This
->cbs
[i
]; ++i
)
2363 IXAudio2EngineCallback_OnProcessingPassStart(This
->cbs
[i
]);
2365 LIST_FOR_EACH_ENTRY(src
, &This
->source_voices
, XA2SourceImpl
, entry
){
2368 EnterCriticalSection(&src
->lock
);
2370 if(!src
->in_use
|| !src
->running
){
2371 LeaveCriticalSection(&src
->lock
);
2376 #if XAUDIO2_VER == 0
2377 IXAudio20VoiceCallback_OnVoiceProcessingPassStart((IXAudio20VoiceCallback
*)src
->cb
);
2380 underrun
= get_underrun_warning(src
);
2382 TRACE("Calling OnVoiceProcessingPassStart with BytesRequired: %u\n", underrun
);
2383 IXAudio2VoiceCallback_OnVoiceProcessingPassStart(src
->cb
, underrun
);
2387 update_source_state(src
);
2389 alGetSourcei(src
->al_src
, AL_SOURCE_STATE
, &st
);
2390 if(st
!= AL_PLAYING
)
2391 alSourcePlay(src
->al_src
);
2394 IXAudio2VoiceCallback_OnVoiceProcessingPassEnd(src
->cb
);
2396 LeaveCriticalSection(&src
->lock
);
2399 hr
= IAudioRenderClient_GetBuffer(This
->render
, nframes
, &buf
);
2401 WARN("GetBuffer failed: %08x\n", hr
);
2403 palcRenderSamplesSOFT(This
->al_device
, buf
, nframes
);
2405 hr
= IAudioRenderClient_ReleaseBuffer(This
->render
, nframes
, 0);
2407 WARN("ReleaseBuffer failed: %08x\n", hr
);
2409 for(i
= 0; i
< This
->ncbs
&& This
->cbs
[i
]; ++i
)
2410 IXAudio2EngineCallback_OnProcessingPassEnd(This
->cbs
[i
]);
2413 static DWORD WINAPI
engine_threadproc(void *arg
)
2415 IXAudio2Impl
*This
= arg
;
2417 WaitForSingleObject(This
->mmevt
, INFINITE
);
2419 if(This
->stop_engine
)
2422 EnterCriticalSection(&This
->lock
);
2424 if(!This
->running
|| !This
->aclient
){
2425 LeaveCriticalSection(&This
->lock
);
2429 palcSetThreadContext(This
->al_ctx
);
2431 do_engine_tick(This
);
2433 LeaveCriticalSection(&This
->lock
);