2 * Copyright 2010 Maarten Lankhorst 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
20 /* This test is for audio playback specific mechanisms
22 * - IAudioClient with eRender and IAudioRenderClient
28 #include "wine/test.h"
38 #include "mmdeviceapi.h"
40 #include "audioclient.h"
41 #include "audiopolicy.h"
42 #include "endpointvolume.h"
44 static const unsigned int win_formats
[][4] = {
45 { 8000, 8, 1}, { 8000, 8, 2}, { 8000, 16, 1}, { 8000, 16, 2},
46 {11025, 8, 1}, {11025, 8, 2}, {11025, 16, 1}, {11025, 16, 2},
47 {12000, 8, 1}, {12000, 8, 2}, {12000, 16, 1}, {12000, 16, 2},
48 {16000, 8, 1}, {16000, 8, 2}, {16000, 16, 1}, {16000, 16, 2},
49 {22050, 8, 1}, {22050, 8, 2}, {22050, 16, 1}, {22050, 16, 2},
50 {44100, 8, 1}, {44100, 8, 2}, {44100, 16, 1}, {44100, 16, 2},
51 {48000, 8, 1}, {48000, 8, 2}, {48000, 16, 1}, {48000, 16, 2},
52 {96000, 8, 1}, {96000, 8, 2}, {96000, 16, 1}, {96000, 16, 2}
54 #define NB_WIN_FORMATS (sizeof(win_formats)/sizeof(*win_formats))
56 #define NULL_PTR_ERR MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, RPC_X_NULL_REF_POINTER)
58 /* undocumented error code */
59 #define D3D11_ERROR_4E MAKE_HRESULT(SEVERITY_ERROR, FACILITY_DIRECT3D11, 0x4e)
61 static IMMDeviceEnumerator
*mme
= NULL
;
62 static IMMDevice
*dev
= NULL
;
63 static HRESULT hexcl
= S_OK
; /* or AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED */
64 static BOOL win10
= FALSE
;
66 static const LARGE_INTEGER ullZero
;
68 #define PI 3.14159265358979323846L
69 static DWORD
wave_generate_tone(PWAVEFORMATEX pwfx
, BYTE
* data
, UINT32 frames
)
71 static double phase
= 0.; /* normalized to unit, not 2*PI */
72 PWAVEFORMATEXTENSIBLE wfxe
= (PWAVEFORMATEXTENSIBLE
)pwfx
;
76 if(!winetest_interactive
)
77 return AUDCLNT_BUFFERFLAGS_SILENT
;
78 if(wfxe
->Format
.wBitsPerSample
!= ((wfxe
->Format
.wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
79 IsEqualGUID(&wfxe
->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
)) ? 8 * sizeof(float) : 16))
80 return AUDCLNT_BUFFERFLAGS_SILENT
;
82 for(delta
= phase
, cn
= 0; cn
< wfxe
->Format
.nChannels
;
83 delta
+= .5/wfxe
->Format
.nChannels
, cn
++){
84 for(i
= 0; i
< frames
; i
++){
85 y
= sin(2*PI
*(440.* i
/ wfxe
->Format
.nSamplesPerSec
+ delta
));
86 /* assume alignment is granted */
87 if(wfxe
->Format
.wBitsPerSample
== 16)
88 ((short*)data
)[cn
+i
*wfxe
->Format
.nChannels
] = y
* 32767.9;
90 ((float*)data
)[cn
+i
*wfxe
->Format
.nChannels
] = y
;
93 phase
+= 440.* frames
/ wfxe
->Format
.nSamplesPerSec
;
94 phase
-= floor(phase
);
98 static void test_uninitialized(IAudioClient
*ac
)
104 HANDLE handle
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
107 hr
= IAudioClient_GetBufferSize(ac
, &num
);
108 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized GetBufferSize call returns %08x\n", hr
);
110 hr
= IAudioClient_GetStreamLatency(ac
, &t1
);
111 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized GetStreamLatency call returns %08x\n", hr
);
113 hr
= IAudioClient_GetCurrentPadding(ac
, &num
);
114 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized GetCurrentPadding call returns %08x\n", hr
);
116 hr
= IAudioClient_Start(ac
);
117 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized Start call returns %08x\n", hr
);
119 hr
= IAudioClient_Stop(ac
);
120 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized Stop call returns %08x\n", hr
);
122 hr
= IAudioClient_Reset(ac
);
123 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized Reset call returns %08x\n", hr
);
125 hr
= IAudioClient_SetEventHandle(ac
, handle
);
126 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized SetEventHandle call returns %08x\n", hr
);
128 hr
= IAudioClient_GetService(ac
, &IID_IAudioStreamVolume
, (void**)&unk
);
129 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Uninitialized GetService call returns %08x\n", hr
);
134 static void test_audioclient(void)
140 WAVEFORMATEX
*pwfx
, *pwfx2
;
141 REFERENCE_TIME t1
, t2
;
144 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
146 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
150 handle
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
152 hr
= IAudioClient_QueryInterface(ac
, &IID_IUnknown
, NULL
);
153 ok(hr
== E_POINTER
, "QueryInterface(NULL) returned %08x\n", hr
);
155 unk
= (void*)(LONG_PTR
)0x12345678;
156 hr
= IAudioClient_QueryInterface(ac
, &IID_NULL
, (void**)&unk
);
157 ok(hr
== E_NOINTERFACE
, "QueryInterface(IID_NULL) returned %08x\n", hr
);
158 ok(!unk
, "QueryInterface(IID_NULL) returned non-null pointer %p\n", unk
);
160 hr
= IAudioClient_QueryInterface(ac
, &IID_IUnknown
, (void**)&unk
);
161 ok(hr
== S_OK
, "QueryInterface(IID_IUnknown) returned %08x\n", hr
);
164 ref
= IUnknown_Release(unk
);
165 ok(ref
== 1, "Released count is %u\n", ref
);
168 hr
= IAudioClient_QueryInterface(ac
, &IID_IAudioClient
, (void**)&unk
);
169 ok(hr
== S_OK
, "QueryInterface(IID_IAudioClient) returned %08x\n", hr
);
172 ref
= IUnknown_Release(unk
);
173 ok(ref
== 1, "Released count is %u\n", ref
);
176 hr
= IAudioClient_GetDevicePeriod(ac
, NULL
, NULL
);
177 ok(hr
== E_POINTER
, "Invalid GetDevicePeriod call returns %08x\n", hr
);
179 hr
= IAudioClient_GetDevicePeriod(ac
, &t1
, NULL
);
180 ok(hr
== S_OK
, "Valid GetDevicePeriod call returns %08x\n", hr
);
182 hr
= IAudioClient_GetDevicePeriod(ac
, NULL
, &t2
);
183 ok(hr
== S_OK
, "Valid GetDevicePeriod call returns %08x\n", hr
);
185 hr
= IAudioClient_GetDevicePeriod(ac
, &t1
, &t2
);
186 ok(hr
== S_OK
, "Valid GetDevicePeriod call returns %08x\n", hr
);
187 trace("Returned periods: %u.%04u ms %u.%04u ms\n",
188 (UINT
)(t1
/10000), (UINT
)(t1
% 10000),
189 (UINT
)(t2
/10000), (UINT
)(t2
% 10000));
191 hr
= IAudioClient_GetMixFormat(ac
, NULL
);
192 ok(hr
== E_POINTER
, "GetMixFormat returns %08x\n", hr
);
194 hr
= IAudioClient_GetMixFormat(ac
, &pwfx
);
195 ok(hr
== S_OK
, "Valid GetMixFormat returns %08x\n", hr
);
199 trace("pwfx: %p\n", pwfx
);
200 trace("Tag: %04x\n", pwfx
->wFormatTag
);
201 trace("bits: %u\n", pwfx
->wBitsPerSample
);
202 trace("chan: %u\n", pwfx
->nChannels
);
203 trace("rate: %u\n", pwfx
->nSamplesPerSec
);
204 trace("align: %u\n", pwfx
->nBlockAlign
);
205 trace("extra: %u\n", pwfx
->cbSize
);
206 ok(pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
, "wFormatTag is %x\n", pwfx
->wFormatTag
);
207 if (pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
209 WAVEFORMATEXTENSIBLE
*pwfxe
= (void*)pwfx
;
210 trace("Res: %u\n", pwfxe
->Samples
.wReserved
);
211 trace("Mask: %x\n", pwfxe
->dwChannelMask
);
213 IsEqualGUID(&pwfxe
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
)?"PCM":
214 (IsEqualGUID(&pwfxe
->SubFormat
,
215 &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
)?"FLOAT":"Other"));
218 hr
= IAudioClient_IsFormatSupported(ac
, AUDCLNT_SHAREMODE_SHARED
, pwfx
, &pwfx2
);
219 ok(hr
== S_OK
, "Valid IsFormatSupported(Shared) call returns %08x\n", hr
);
220 ok(pwfx2
== NULL
, "pwfx2 is non-null\n");
221 CoTaskMemFree(pwfx2
);
223 hr
= IAudioClient_IsFormatSupported(ac
, AUDCLNT_SHAREMODE_SHARED
, NULL
, NULL
);
224 ok(hr
== E_POINTER
, "IsFormatSupported(NULL) call returns %08x\n", hr
);
226 hr
= IAudioClient_IsFormatSupported(ac
, AUDCLNT_SHAREMODE_SHARED
, pwfx
, NULL
);
227 ok(hr
== E_POINTER
, "IsFormatSupported(Shared,NULL) call returns %08x\n", hr
);
229 hr
= IAudioClient_IsFormatSupported(ac
, AUDCLNT_SHAREMODE_EXCLUSIVE
, pwfx
, NULL
);
230 ok(hr
== S_OK
|| hr
== AUDCLNT_E_UNSUPPORTED_FORMAT
|| hr
== AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED
,
231 "IsFormatSupported(Exclusive) call returns %08x\n", hr
);
234 pwfx2
= (WAVEFORMATEX
*)0xDEADF00D;
235 hr
= IAudioClient_IsFormatSupported(ac
, AUDCLNT_SHAREMODE_EXCLUSIVE
, pwfx
, &pwfx2
);
236 ok(hr
== hexcl
, "IsFormatSupported(Exclusive) call returns %08x\n", hr
);
237 ok(pwfx2
== NULL
, "pwfx2 non-null on exclusive IsFormatSupported\n");
239 if (hexcl
!= AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED
)
242 hr
= IAudioClient_IsFormatSupported(ac
, 0xffffffff, pwfx
, NULL
);
243 ok(hr
== E_INVALIDARG
/*w32*/ ||
244 broken(hr
== AUDCLNT_E_UNSUPPORTED_FORMAT
/*w64 response from exclusive mode driver */),
245 "IsFormatSupported(0xffffffff) call returns %08x\n", hr
);
248 test_uninitialized(ac
);
250 hr
= IAudioClient_Initialize(ac
, 3, 0, 5000000, 0, pwfx
, NULL
);
251 ok(hr
== AUDCLNT_E_NOT_INITIALIZED
, "Initialize with invalid sharemode returns %08x\n", hr
);
253 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0xffffffff, 5000000, 0, pwfx
, NULL
);
254 ok(hr
== E_INVALIDARG
||
255 hr
== AUDCLNT_E_INVALID_STREAM_FLAG
, "Initialize with invalid flags returns %08x\n", hr
);
257 /* A period != 0 is ignored and the call succeeds.
258 * Since we can only initialize successfully once, skip those tests.
260 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0, 5000000, 0, NULL
, NULL
);
261 ok(hr
== E_POINTER
, "Initialize with null format returns %08x\n", hr
);
263 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0, 0, 0, pwfx
, NULL
);
264 ok(hr
== S_OK
, "Initialize with 0 buffer size returns %08x\n", hr
);
268 hr
= IAudioClient_GetBufferSize(ac
, &num
);
269 ok(hr
== S_OK
, "GetBufferSize from duration 0 returns %08x\n", hr
);
271 trace("Initialize(duration=0) GetBufferSize is %u\n", num
);
274 IAudioClient_Release(ac
);
276 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
278 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
280 if(pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
){
281 WAVEFORMATEXTENSIBLE
*fmtex
= (WAVEFORMATEXTENSIBLE
*)pwfx
;
282 WAVEFORMATEX
*fmt2
= NULL
;
284 ok(fmtex
->dwChannelMask
!= 0, "Got empty dwChannelMask\n");
286 fmtex
->dwChannelMask
= 0xffff;
288 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0, 5000000, 0, pwfx
, NULL
);
290 hr
== AUDCLNT_E_UNSUPPORTED_FORMAT
/* win10 */, "Initialize(dwChannelMask = 0xffff) returns %08x\n", hr
);
292 IAudioClient_Release(ac
);
294 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
296 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
298 fmtex
->dwChannelMask
= 0;
300 hr
= IAudioClient_IsFormatSupported(ac
, AUDCLNT_SHAREMODE_SHARED
, pwfx
, &fmt2
);
301 ok(hr
== S_OK
|| broken(hr
== S_FALSE
/* w7 Realtek HDA */),
302 "IsFormatSupported(dwChannelMask = 0) call returns %08x\n", hr
);
303 ok(fmtex
->dwChannelMask
== 0, "Passed format was modified\n");
307 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0, 5000000, 0, pwfx
, NULL
);
308 ok(hr
== S_OK
, "Initialize(dwChannelMask = 0) returns %08x\n", hr
);
310 IAudioClient_Release(ac
);
312 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
314 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
318 hr
= IAudioClient_GetMixFormat(ac
, &pwfx
);
319 ok(hr
== S_OK
, "Valid GetMixFormat returns %08x\n", hr
);
321 skip("Skipping dwChannelMask tests\n");
323 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0, 5000000, 0, pwfx
, NULL
);
324 ok(hr
== S_OK
, "Valid Initialize returns %08x\n", hr
);
327 IAudioClient_Release(ac
);
332 hr
= IAudioClient_GetStreamLatency(ac
, NULL
);
333 ok(hr
== E_POINTER
, "GetStreamLatency(NULL) call returns %08x\n", hr
);
335 hr
= IAudioClient_GetStreamLatency(ac
, &t2
);
336 ok(hr
== S_OK
, "Valid GetStreamLatency call returns %08x\n", hr
);
337 trace("Returned latency: %u.%04u ms\n",
338 (UINT
)(t2
/10000), (UINT
)(t2
% 10000));
339 ok(t2
>= t1
|| broken(t2
>= t1
/2 && pwfx
->nSamplesPerSec
> 48000) ||
340 broken(t2
== 0) /* (!) win10 */,
341 "Latency < default period, delta %dus (%x%08x vs %x%08x)\n",
342 (LONG
)((t2
-t1
)/10), (DWORD
)(t2
>> 32), (DWORD
)t2
, (DWORD
)(t1
>> 32), (DWORD
)t1
);
343 /* Native appears to add the engine period to the HW latency in shared mode */
347 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0, 5000000, 0, pwfx
, NULL
);
348 ok(hr
== AUDCLNT_E_ALREADY_INITIALIZED
, "Calling Initialize twice returns %08x\n", hr
);
350 hr
= IAudioClient_SetEventHandle(ac
, NULL
);
351 ok(hr
== E_INVALIDARG
, "SetEventHandle(NULL) returns %08x\n", hr
);
353 hr
= IAudioClient_SetEventHandle(ac
, handle
);
354 ok(hr
== AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED
||
355 broken(hr
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
)) ||
356 broken(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
)) /* Some 2k8 */ ||
357 broken(hr
== HRESULT_FROM_WIN32(ERROR_BAD_PATHNAME
)) /* Some Vista */
358 , "SetEventHandle returns %08x\n", hr
);
360 hr
= IAudioClient_Reset(ac
);
361 ok(hr
== S_OK
, "Reset on an initialized stream returns %08x\n", hr
);
363 hr
= IAudioClient_Reset(ac
);
364 ok(hr
== S_OK
, "Reset on an already reset stream returns %08x\n", hr
);
366 hr
= IAudioClient_Stop(ac
);
367 ok(hr
== S_FALSE
, "Stop on a stopped stream returns %08x\n", hr
);
369 hr
= IAudioClient_Start(ac
);
370 ok(hr
== S_OK
, "Start on a stopped stream returns %08x\n", hr
);
372 hr
= IAudioClient_Start(ac
);
373 ok(hr
== AUDCLNT_E_NOT_STOPPED
, "Start twice returns %08x\n", hr
);
375 IAudioClient_Release(ac
);
381 static void test_formats(AUDCLNT_SHAREMODE mode
)
385 WAVEFORMATEX fmt
, *pwfx
, *pwfx2
;
388 fmt
.wFormatTag
= WAVE_FORMAT_PCM
;
391 for(i
= 0; i
< NB_WIN_FORMATS
; i
++) {
392 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
394 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
398 hr
= IAudioClient_GetMixFormat(ac
, &pwfx
);
399 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
401 fmt
.nSamplesPerSec
= win_formats
[i
][0];
402 fmt
.wBitsPerSample
= win_formats
[i
][1];
403 fmt
.nChannels
= win_formats
[i
][2];
404 fmt
.nBlockAlign
= fmt
.nChannels
* fmt
.wBitsPerSample
/ 8;
405 fmt
.nAvgBytesPerSec
= fmt
.nBlockAlign
* fmt
.nSamplesPerSec
;
407 pwfx2
= (WAVEFORMATEX
*)0xDEADF00D;
408 hr
= IAudioClient_IsFormatSupported(ac
, mode
, &fmt
, &pwfx2
);
410 /* Only shared mode suggests something ... GetMixFormat! */
411 ok(hr
== S_OK
|| (mode
== AUDCLNT_SHAREMODE_SHARED
412 ? hr
== S_FALSE
|| broken(hr
== AUDCLNT_E_UNSUPPORTED_FORMAT
&&
413 /* 5:1 card exception when asked for 1 channel at mixer rate */
414 pwfx
->nChannels
> 2 && fmt
.nSamplesPerSec
== pwfx
->nSamplesPerSec
)
415 : (hr
== AUDCLNT_E_UNSUPPORTED_FORMAT
|| hr
== hexcl
)),
416 "IsFormatSupported(%d, %ux%2ux%u) returns %08x\n", mode
,
417 fmt
.nSamplesPerSec
, fmt
.wBitsPerSample
, fmt
.nChannels
, hr
);
419 trace("IsSupported(%s, %ux%2ux%u)\n",
420 mode
== AUDCLNT_SHAREMODE_SHARED
? "shared " : "exclus.",
421 fmt
.nSamplesPerSec
, fmt
.wBitsPerSample
, fmt
.nChannels
);
423 /* Change GetMixFormat wBitsPerSample only => S_OK */
424 if (mode
== AUDCLNT_SHAREMODE_SHARED
425 && fmt
.nSamplesPerSec
== pwfx
->nSamplesPerSec
426 && fmt
.nChannels
== pwfx
->nChannels
)
427 ok(hr
== S_OK
, "Varying BitsPerSample %u\n", fmt
.wBitsPerSample
);
429 ok((hr
== S_FALSE
)^(pwfx2
== NULL
), "hr %x<->suggest %p\n", hr
, pwfx2
);
430 if (pwfx2
== (WAVEFORMATEX
*)0xDEADF00D)
431 pwfx2
= NULL
; /* broken in Wine < 1.3.28 */
433 ok(pwfx2
->nSamplesPerSec
== pwfx
->nSamplesPerSec
&&
434 pwfx2
->nChannels
== pwfx
->nChannels
&&
435 pwfx2
->wBitsPerSample
== pwfx
->wBitsPerSample
,
436 "Suggestion %ux%2ux%u differs from GetMixFormat\n",
437 pwfx2
->nSamplesPerSec
, pwfx2
->wBitsPerSample
, pwfx2
->nChannels
);
440 /* Vista returns E_INVALIDARG upon AUDCLNT_STREAMFLAGS_RATEADJUST */
441 hr
= IAudioClient_Initialize(ac
, mode
, 0, 5000000, 0, &fmt
, NULL
);
442 if ((hrs
== S_OK
) ^ (hr
== S_OK
))
443 trace("Initialize (%s, %ux%2ux%u) returns %08x unlike IsFormatSupported\n",
444 mode
== AUDCLNT_SHAREMODE_SHARED
? "shared " : "exclus.",
445 fmt
.nSamplesPerSec
, fmt
.wBitsPerSample
, fmt
.nChannels
, hr
);
446 if (mode
== AUDCLNT_SHAREMODE_SHARED
)
447 ok(hrs
== S_OK
? hr
== S_OK
: hr
== AUDCLNT_E_UNSUPPORTED_FORMAT
,
448 "Initialize(shared, %ux%2ux%u) returns %08x\n",
449 fmt
.nSamplesPerSec
, fmt
.wBitsPerSample
, fmt
.nChannels
, hr
);
450 else if (hrs
== AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED
)
451 /* Unsupported format implies "create failed" and shadows "not allowed" */
452 ok(hrs
== hexcl
&& (hr
== AUDCLNT_E_ENDPOINT_CREATE_FAILED
|| hr
== hrs
),
453 "Initialize(noexcl., %ux%2ux%u) returns %08x(%08x)\n",
454 fmt
.nSamplesPerSec
, fmt
.wBitsPerSample
, fmt
.nChannels
, hr
, hrs
);
456 /* On testbot 48000x16x1 claims support, but does not Initialize.
457 * Some cards Initialize 44100|48000x16x1 yet claim no support;
458 * F. Gouget's w7 bots do that for 12000|96000x8|16x1|2 */
459 ok(hrs
== S_OK
? hr
== S_OK
|| broken(hr
== AUDCLNT_E_ENDPOINT_CREATE_FAILED
)
460 : hr
== AUDCLNT_E_ENDPOINT_CREATE_FAILED
|| hr
== AUDCLNT_E_UNSUPPORTED_FORMAT
||
462 ((fmt
.nChannels
== 1 && fmt
.wBitsPerSample
== 16) ||
463 (fmt
.nSamplesPerSec
== 12000 || fmt
.nSamplesPerSec
== 96000))),
464 "Initialize(exclus., %ux%2ux%u) returns %08x\n",
465 fmt
.nSamplesPerSec
, fmt
.wBitsPerSample
, fmt
.nChannels
, hr
);
467 /* Bug in native (Vista/w2k8/w7): after Initialize failed, better
468 * Release this ac and Activate a new one.
469 * A second call (with a known working format) would yield
470 * ALREADY_INITIALIZED in shared mode yet be unusable, and in exclusive
471 * mode some entity keeps a lock on the device, causing DEVICE_IN_USE to
472 * all subsequent calls until the audio engine service is restarted. */
474 CoTaskMemFree(pwfx2
);
476 IAudioClient_Release(ac
);
480 static void test_references(void)
483 IAudioRenderClient
*rc
;
484 ISimpleAudioVolume
*sav
;
485 IAudioStreamVolume
*asv
;
491 /* IAudioRenderClient */
492 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
494 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
498 hr
= IAudioClient_GetMixFormat(ac
, &pwfx
);
499 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
501 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0, 5000000,
503 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
507 hr
= IAudioClient_GetService(ac
, &IID_IAudioRenderClient
, (void**)&rc
);
508 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
510 IAudioClient_Release(ac
);
514 IAudioRenderClient_AddRef(rc
);
515 ref
= IAudioRenderClient_Release(rc
);
516 ok(ref
!= 0, "RenderClient_Release gave wrong refcount: %u\n", ref
);
518 ref
= IAudioClient_Release(ac
);
519 ok(ref
!= 0, "Client_Release gave wrong refcount: %u\n", ref
);
521 ref
= IAudioRenderClient_Release(rc
);
522 ok(ref
== 0, "RenderClient_Release gave wrong refcount: %u\n", ref
);
524 /* ISimpleAudioVolume */
525 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
527 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
531 hr
= IAudioClient_GetMixFormat(ac
, &pwfx
);
532 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
534 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0, 5000000,
536 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
540 hr
= IAudioClient_GetService(ac
, &IID_ISimpleAudioVolume
, (void**)&sav
);
541 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
543 ISimpleAudioVolume_AddRef(sav
);
544 ref
= ISimpleAudioVolume_Release(sav
);
545 ok(ref
!= 0, "SimpleAudioVolume_Release gave wrong refcount: %u\n", ref
);
547 ref
= IAudioClient_Release(ac
);
548 ok(ref
!= 0, "Client_Release gave wrong refcount: %u\n", ref
);
550 ref
= ISimpleAudioVolume_Release(sav
);
551 ok(ref
== 0, "SimpleAudioVolume_Release gave wrong refcount: %u\n", ref
);
554 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
556 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
560 hr
= IAudioClient_GetMixFormat(ac
, &pwfx
);
561 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
563 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0, 5000000,
565 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
569 hr
= IAudioClient_GetService(ac
, &IID_IAudioClock
, (void**)&acl
);
570 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
572 IAudioClock_AddRef(acl
);
573 ref
= IAudioClock_Release(acl
);
574 ok(ref
!= 0, "AudioClock_Release gave wrong refcount: %u\n", ref
);
576 ref
= IAudioClient_Release(ac
);
577 ok(ref
!= 0, "Client_Release gave wrong refcount: %u\n", ref
);
579 ref
= IAudioClock_Release(acl
);
580 ok(ref
== 0, "AudioClock_Release gave wrong refcount: %u\n", ref
);
582 /* IAudioStreamVolume */
583 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
585 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
589 hr
= IAudioClient_GetMixFormat(ac
, &pwfx
);
590 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
592 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0, 5000000,
594 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
598 hr
= IAudioClient_GetService(ac
, &IID_IAudioStreamVolume
, (void**)&asv
);
599 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
601 IAudioStreamVolume_AddRef(asv
);
602 ref
= IAudioStreamVolume_Release(asv
);
603 ok(ref
!= 0, "AudioStreamVolume_Release gave wrong refcount: %u\n", ref
);
605 ref
= IAudioClient_Release(ac
);
606 ok(ref
!= 0, "Client_Release gave wrong refcount: %u\n", ref
);
608 ref
= IAudioStreamVolume_Release(asv
);
609 ok(ref
== 0, "AudioStreamVolume_Release gave wrong refcount: %u\n", ref
);
612 static void test_event(void)
620 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
622 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
626 hr
= IAudioClient_GetMixFormat(ac
, &pwfx
);
627 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
629 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
,
630 AUDCLNT_STREAMFLAGS_EVENTCALLBACK
, 5000000,
632 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
636 event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
637 ok(event
!= NULL
, "CreateEvent failed\n");
639 hr
= IAudioClient_Start(ac
);
640 ok(hr
== AUDCLNT_E_EVENTHANDLE_NOT_SET
||
641 hr
== D3D11_ERROR_4E
/* win10 */, "Start failed: %08x\n", hr
);
643 hr
= IAudioClient_SetEventHandle(ac
, event
);
644 ok(hr
== S_OK
, "SetEventHandle failed: %08x\n", hr
);
646 hr
= IAudioClient_SetEventHandle(ac
, event
);
647 ok(hr
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
) ||
648 hr
== E_UNEXPECTED
/* win10 */, "SetEventHandle returns %08x\n", hr
);
650 r
= WaitForSingleObject(event
, 40);
651 ok(r
== WAIT_TIMEOUT
, "Wait(event) before Start gave %x\n", r
);
653 hr
= IAudioClient_Start(ac
);
654 ok(hr
== S_OK
, "Start failed: %08x\n", hr
);
656 r
= WaitForSingleObject(event
, 20);
657 ok(r
== WAIT_OBJECT_0
, "Wait(event) after Start gave %x\n", r
);
659 hr
= IAudioClient_Stop(ac
);
660 ok(hr
== S_OK
, "Stop failed: %08x\n", hr
);
662 ok(ResetEvent(event
), "ResetEvent\n");
664 /* Still receiving events! */
665 r
= WaitForSingleObject(event
, 20);
666 ok(r
== WAIT_OBJECT_0
, "Wait(event) after Stop gave %x\n", r
);
668 hr
= IAudioClient_Reset(ac
);
669 ok(hr
== S_OK
, "Reset failed: %08x\n", hr
);
671 ok(ResetEvent(event
), "ResetEvent\n");
673 r
= WaitForSingleObject(event
, 120);
674 ok(r
== WAIT_OBJECT_0
, "Wait(event) after Reset gave %x\n", r
);
676 hr
= IAudioClient_SetEventHandle(ac
, NULL
);
677 ok(hr
== E_INVALIDARG
, "SetEventHandle(NULL) returns %08x\n", hr
);
679 r
= WaitForSingleObject(event
, 70);
680 ok(r
== WAIT_OBJECT_0
, "Wait(NULL event) gave %x\n", r
);
682 /* test releasing a playing stream */
683 hr
= IAudioClient_Start(ac
);
684 ok(hr
== S_OK
, "Start failed: %08x\n", hr
);
685 IAudioClient_Release(ac
);
690 static void test_padding(void)
694 IAudioRenderClient
*arc
;
696 REFERENCE_TIME minp
, defp
;
698 UINT32 psize
, pad
, written
, i
;
700 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
702 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
706 hr
= IAudioClient_GetMixFormat(ac
, &pwfx
);
707 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
711 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
,
712 0, 5000000, 0, pwfx
, NULL
);
713 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
717 if(pwfx
->wBitsPerSample
== 8)
723 * Default (= shared) device period is 10ms (e.g. 441 frames at 44100),
724 * except when the HW/OS forces a particular alignment,
725 * e.g. 10.1587ms is 28 * 16 = 448 frames at 44100 with HDA.
726 * 441 observed with Vista, 448 with w7 on the same HW! */
727 hr
= IAudioClient_GetDevicePeriod(ac
, &defp
, &minp
);
728 ok(hr
== S_OK
, "GetDevicePeriod failed: %08x\n", hr
);
729 /* some wineXYZ.drv use 20ms, not seen on native */
730 ok(defp
== 100000 || broken(defp
== 101587) || defp
== 200000,
731 "Expected 10ms default period: %u\n", (ULONG
)defp
);
732 ok(minp
!= 0, "Minimum period is 0\n");
733 ok(minp
<= defp
, "Minimum period is greater than default period\n");
735 hr
= IAudioClient_GetService(ac
, &IID_IAudioRenderClient
, (void**)&arc
);
736 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
738 psize
= MulDiv(defp
, pwfx
->nSamplesPerSec
, 10000000) * 10;
741 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
742 ok(hr
== S_OK
, "GetCurrentPadding failed: %08x\n", hr
);
743 ok(pad
== written
, "GetCurrentPadding returned %u, should be %u\n", pad
, written
);
745 hr
= IAudioRenderClient_GetBuffer(arc
, psize
, &buf
);
746 ok(hr
== S_OK
, "GetBuffer failed: %08x\n", hr
);
747 ok(buf
!= NULL
, "NULL buffer returned\n");
749 /* win10 appears not to clear the buffer */
750 for(i
= 0; i
< psize
* pwfx
->nBlockAlign
; ++i
){
751 if(buf
[i
] != silence
){
752 ok(0, "buffer has data in it already, i: %u, valu: %f\n", i
, *((float*)buf
));
758 hr
= IAudioRenderClient_GetBuffer(arc
, 0, &buf
);
759 ok(hr
== AUDCLNT_E_OUT_OF_ORDER
, "GetBuffer 0 size failed: %08x\n", hr
);
760 ok(buf
== NULL
, "GetBuffer 0 gave %p\n", buf
);
761 /* MSDN instead documents buf remains untouched */
763 hr
= IAudioClient_Reset(ac
);
764 ok(hr
== AUDCLNT_E_BUFFER_OPERATION_PENDING
, "Reset failed: %08x\n", hr
);
766 hr
= IAudioRenderClient_ReleaseBuffer(arc
, psize
,
767 AUDCLNT_BUFFERFLAGS_SILENT
);
768 ok(hr
== S_OK
, "ReleaseBuffer failed: %08x\n", hr
);
769 if(hr
== S_OK
) written
+= psize
;
771 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
772 ok(hr
== S_OK
, "GetCurrentPadding failed: %08x\n", hr
);
773 ok(pad
== written
, "GetCurrentPadding returned %u, should be %u\n", pad
, written
);
775 psize
= MulDiv(minp
, pwfx
->nSamplesPerSec
, 10000000) * 10;
777 hr
= IAudioRenderClient_GetBuffer(arc
, psize
, &buf
);
778 ok(hr
== S_OK
, "GetBuffer failed: %08x\n", hr
);
779 ok(buf
!= NULL
, "NULL buffer returned\n");
781 hr
= IAudioRenderClient_ReleaseBuffer(arc
, psize
,
782 AUDCLNT_BUFFERFLAGS_SILENT
);
783 ok(hr
== S_OK
, "ReleaseBuffer failed: %08x\n", hr
);
786 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
787 ok(hr
== S_OK
, "GetCurrentPadding failed: %08x\n", hr
);
788 ok(pad
== written
, "GetCurrentPadding returned %u, should be %u\n", pad
, written
);
790 /* overfull buffer. requested 1/2s buffer size, so try
791 * to get a 1/2s buffer, which should fail */
792 psize
= pwfx
->nSamplesPerSec
/ 2;
793 buf
= (void*)0xDEADF00D;
794 hr
= IAudioRenderClient_GetBuffer(arc
, psize
, &buf
);
795 ok(hr
== AUDCLNT_E_BUFFER_TOO_LARGE
, "GetBuffer gave wrong error: %08x\n", hr
);
796 ok(buf
== NULL
, "NULL expected %p\n", buf
);
798 hr
= IAudioRenderClient_ReleaseBuffer(arc
, psize
, 0);
799 ok(hr
== AUDCLNT_E_OUT_OF_ORDER
, "ReleaseBuffer gave wrong error: %08x\n", hr
);
801 psize
= MulDiv(minp
, pwfx
->nSamplesPerSec
, 10000000) * 2;
803 hr
= IAudioRenderClient_GetBuffer(arc
, psize
, &buf
);
804 ok(hr
== S_OK
, "GetBuffer failed: %08x\n", hr
);
805 ok(buf
!= NULL
, "NULL buffer returned\n");
807 hr
= IAudioRenderClient_ReleaseBuffer(arc
, 0, 0);
808 ok(hr
== S_OK
, "ReleaseBuffer 0 gave wrong error: %08x\n", hr
);
810 buf
= (void*)0xDEADF00D;
811 hr
= IAudioRenderClient_GetBuffer(arc
, 0, &buf
);
812 ok(hr
== S_OK
, "GetBuffer 0 size failed: %08x\n", hr
);
813 ok(buf
== NULL
, "GetBuffer 0 gave %p\n", buf
);
814 /* MSDN instead documents buf remains untouched */
816 buf
= (void*)0xDEADF00D;
817 hr
= IAudioRenderClient_GetBuffer(arc
, 0, &buf
);
818 ok(hr
== S_OK
, "GetBuffer 0 size #2 failed: %08x\n", hr
);
819 ok(buf
== NULL
, "GetBuffer 0 #2 gave %p\n", buf
);
821 hr
= IAudioRenderClient_ReleaseBuffer(arc
, psize
, 0);
822 ok(hr
== AUDCLNT_E_OUT_OF_ORDER
, "ReleaseBuffer not size 0 gave %08x\n", hr
);
824 hr
= IAudioRenderClient_GetBuffer(arc
, psize
, &buf
);
825 ok(hr
== S_OK
, "GetBuffer failed: %08x\n", hr
);
826 ok(buf
!= NULL
, "NULL buffer returned\n");
828 hr
= IAudioRenderClient_ReleaseBuffer(arc
, 0, 0);
829 ok(hr
== S_OK
, "ReleaseBuffer 0 gave wrong error: %08x\n", hr
);
831 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
832 ok(hr
== S_OK
, "GetCurrentPadding failed: %08x\n", hr
);
833 ok(pad
== written
, "GetCurrentPadding returned %u, should be %u\n", pad
, written
);
835 hr
= IAudioRenderClient_GetBuffer(arc
, psize
, &buf
);
836 ok(hr
== S_OK
, "GetBuffer failed: %08x\n", hr
);
837 ok(buf
!= NULL
, "NULL buffer returned\n");
839 hr
= IAudioRenderClient_ReleaseBuffer(arc
, psize
+1, AUDCLNT_BUFFERFLAGS_SILENT
);
840 ok(hr
== AUDCLNT_E_INVALID_SIZE
, "ReleaseBuffer too large error: %08x\n", hr
);
841 /* todo_wine means Wine may overwrite memory */
842 if(hr
== S_OK
) written
+= psize
+1;
844 /* Buffer still hold */
845 hr
= IAudioRenderClient_ReleaseBuffer(arc
, psize
/2, AUDCLNT_BUFFERFLAGS_SILENT
);
846 ok(hr
== S_OK
, "ReleaseBuffer after error: %08x\n", hr
);
847 if(hr
== S_OK
) written
+= psize
/2;
849 hr
= IAudioRenderClient_ReleaseBuffer(arc
, 0, 0);
850 ok(hr
== S_OK
, "ReleaseBuffer 0 gave wrong error: %08x\n", hr
);
852 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
853 ok(hr
== S_OK
, "GetCurrentPadding failed: %08x\n", hr
);
854 ok(pad
== written
, "GetCurrentPadding returned %u, should be %u\n", pad
, written
);
858 IAudioRenderClient_Release(arc
);
859 IAudioClient_Release(ac
);
862 static void test_clock(int share
)
867 IAudioRenderClient
*arc
;
868 UINT64 freq
, pos
, pcpos0
, pcpos
, last
;
869 UINT32 pad
, gbsize
, bufsize
, fragment
, parts
, avail
, slept
= 0, sum
= 0;
872 LARGE_INTEGER hpctime
, hpctime0
, hpcfreq
;
873 REFERENCE_TIME minp
, defp
, t1
, t2
;
874 REFERENCE_TIME duration
= 5000000, period
= 150000;
877 ok(QueryPerformanceFrequency(&hpcfreq
), "PerfFrequency failed\n");
879 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
881 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
885 hr
= IAudioClient_GetMixFormat(ac
, &pwfx
);
886 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
890 hr
= IAudioClient_GetDevicePeriod(ac
, &defp
, &minp
);
891 ok(hr
== S_OK
, "GetDevicePeriod failed: %08x\n", hr
);
892 ok(minp
<= period
, "desired period %u too small for %u\n", (ULONG
)period
, (ULONG
)minp
);
895 trace("Testing shared mode\n");
896 /* period is ignored */
897 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
,
898 0, duration
, period
, pwfx
, NULL
);
901 pwfx
->wFormatTag
= WAVE_FORMAT_PCM
;
904 pwfx
->wBitsPerSample
= 16; /* no floating point */
905 pwfx
->nBlockAlign
= pwfx
->nChannels
* pwfx
->wBitsPerSample
/ 8;
906 pwfx
->nAvgBytesPerSec
= pwfx
->nSamplesPerSec
* pwfx
->nBlockAlign
;
907 trace("Testing exclusive mode at %u\n", pwfx
->nSamplesPerSec
);
909 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_EXCLUSIVE
,
910 0, duration
, period
, pwfx
, NULL
);
912 ok(share
? hr
== S_OK
: hr
== hexcl
|| hr
== AUDCLNT_E_DEVICE_IN_USE
, "Initialize failed: %08x\n", hr
);
915 IAudioClient_Release(ac
);
916 if(hr
== AUDCLNT_E_DEVICE_IN_USE
)
917 skip("Device in use, no %s access\n", share
? "shared" : "exclusive");
922 * Shared mode: 1x period + a little, but some 192000 devices return 5.3334ms.
923 * Exclusive mode: testbot returns 2x period + a little, but
924 * some HDA drivers return 1x period, some + a little. */
925 hr
= IAudioClient_GetStreamLatency(ac
, &t2
);
926 ok(hr
== S_OK
, "GetStreamLatency failed: %08x\n", hr
);
927 trace("Latency: %u.%04u ms\n", (UINT
)(t2
/10000), (UINT
)(t2
% 10000));
928 ok(t2
>= period
|| broken(t2
>= period
/2 && share
&& pwfx
->nSamplesPerSec
> 48000) ||
929 broken(t2
== 0) /* win10 */,
930 "Latency < default period, delta %ldus\n", (long)((t2
-period
)/10));
933 * BufferSize must be rounded up, maximum 2s says MSDN.
934 * Both is wrong. Rounding may lead to size a little smaller than duration;
935 * duration > 2s is accepted in shared mode.
936 * Shared mode: round solely w.r.t. mixer rate,
937 * duration is no multiple of period.
938 * Exclusive mode: size appears as a multiple of some fragment that
939 * is either the rounded period or a fixed constant like 1024,
940 * whatever the driver implements. */
941 hr
= IAudioClient_GetBufferSize(ac
, &gbsize
);
942 ok(hr
== S_OK
, "GetBufferSize failed: %08x\n", hr
);
944 bufsize
= MulDiv(duration
, pwfx
->nSamplesPerSec
, 10000000);
945 fragment
= MulDiv(period
, pwfx
->nSamplesPerSec
, 10000000);
946 parts
= MulDiv(bufsize
, 1, fragment
); /* instead of (duration, 1, period) */
947 trace("BufferSize %u estimated fragment %u x %u = %u\n", gbsize
, fragment
, parts
, fragment
* parts
);
948 /* fragment size (= period in frames) is rounded up.
949 * BufferSize must be rounded up, maximum 2s says MSDN
950 * but it is rounded down modulo fragment ! */
952 ok(gbsize
== bufsize
,
953 "BufferSize %u at rate %u\n", gbsize
, pwfx
->nSamplesPerSec
);
955 ok(gbsize
== parts
* fragment
|| gbsize
== MulDiv(bufsize
, 1, 1024) * 1024,
956 "BufferSize %u misfits fragment size %u at rate %u\n", gbsize
, fragment
, pwfx
->nSamplesPerSec
);
958 /* In shared mode, GetCurrentPadding decreases in multiples of
959 * fragment size (i.e. updated only at period ticks), whereas
960 * GetPosition appears to be reporting continuous positions.
961 * In exclusive mode, testbot behaves likewise, but native's Intel
962 * HDA driver shows no such deltas, GetCurrentPadding closely
963 * matches GetPosition, as in
964 * GetCurrentPadding = GetPosition - frames held in mmdevapi */
966 hr
= IAudioClient_GetService(ac
, &IID_IAudioClock
, (void**)&acl
);
967 ok(hr
== S_OK
, "GetService(IAudioClock) failed: %08x\n", hr
);
969 hr
= IAudioClock_GetFrequency(acl
, &freq
);
970 ok(hr
== S_OK
, "GetFrequency failed: %08x\n", hr
);
971 trace("Clock Frequency %u\n", (UINT
)freq
);
973 /* MSDN says it's arbitrary units, but shared mode is unlikely to change */
975 ok(freq
== pwfx
->nSamplesPerSec
* pwfx
->nBlockAlign
,
976 "Clock Frequency %u\n", (UINT
)freq
);
978 ok(freq
== pwfx
->nSamplesPerSec
,
979 "Clock Frequency %u\n", (UINT
)freq
);
981 hr
= IAudioClock_GetPosition(acl
, NULL
, NULL
);
982 ok(hr
== E_POINTER
, "GetPosition wrong error: %08x\n", hr
);
985 hr
= IAudioClock_GetPosition(acl
, &pos
, &pcpos0
);
986 ok(hr
== S_OK
, "GetPosition failed: %08x\n", hr
);
987 ok(pos
== 0, "GetPosition returned non-zero pos before being started\n");
988 ok(pcpos0
!= 0, "GetPosition returned zero pcpos\n");
990 hr
= IAudioClient_GetService(ac
, &IID_IAudioRenderClient
, (void**)&arc
);
991 ok(hr
== S_OK
, "GetService(IAudioRenderClient) failed: %08x\n", hr
);
993 hr
= IAudioRenderClient_GetBuffer(arc
, gbsize
+1, &data
);
994 ok(hr
== AUDCLNT_E_BUFFER_TOO_LARGE
, "GetBuffer too large failed: %08x\n", hr
);
998 hr
= IAudioRenderClient_GetBuffer(arc
, avail
, &data
);
999 ok(hr
== S_OK
, "GetBuffer failed: %08x\n", hr
);
1000 trace("data at %p\n", data
);
1002 hr
= IAudioRenderClient_ReleaseBuffer(arc
, avail
, winetest_debug
>2 ?
1003 wave_generate_tone(pwfx
, data
, avail
) : AUDCLNT_BUFFERFLAGS_SILENT
);
1004 ok(hr
== S_OK
, "ReleaseBuffer failed: %08x\n", hr
);
1005 if(hr
== S_OK
) sum
+= avail
;
1007 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
1008 ok(hr
== S_OK
, "GetCurrentPadding failed: %08x\n", hr
);
1009 ok(pad
== sum
, "padding %u prior to start\n", pad
);
1011 hr
= IAudioClock_GetPosition(acl
, &pos
, NULL
);
1012 ok(hr
== S_OK
, "GetPosition failed: %08x\n", hr
);
1013 ok(pos
== 0, "GetPosition returned non-zero pos before being started\n");
1015 hr
= IAudioClient_Start(ac
); /* #1 */
1016 ok(hr
== S_OK
, "Start failed: %08x\n", hr
);
1021 hr
= IAudioClient_GetStreamLatency(ac
, &t1
);
1022 ok(hr
== S_OK
, "GetStreamLatency failed: %08x\n", hr
);
1023 ok(t1
== t2
, "Latency not constant, delta %ld\n", (long)(t1
-t2
));
1025 hr
= IAudioClock_GetPosition(acl
, &pos
, NULL
);
1026 ok(hr
== S_OK
, "GetPosition failed: %08x\n", hr
);
1027 ok(pos
> 0, "Position %u vs. last %u\n", (UINT
)pos
,0);
1028 /* in rare cases is slept*1.1 not enough with dmix */
1029 ok(pos
*1000/freq
<= slept
*1.4, "Position %u too far after playing %ums\n", (UINT
)pos
, slept
);
1032 hr
= IAudioClient_Stop(ac
);
1033 ok(hr
== S_OK
, "Stop failed: %08x\n", hr
);
1035 hr
= IAudioClock_GetPosition(acl
, &pos
, NULL
);
1036 ok(hr
== S_OK
, "GetPosition failed: %08x\n", hr
);
1037 ok(pos
>= last
, "Position %u vs. last %u\n", (UINT
)pos
,(UINT
)last
);
1039 if(/*share &&*/ winetest_debug
>1)
1040 ok(pos
*1000/freq
<= slept
*1.1, "Position %u too far after stop %ums\n", (UINT
)pos
, slept
);
1042 hr
= IAudioClient_Start(ac
); /* #2 */
1043 ok(hr
== S_OK
, "Start failed: %08x\n", hr
);
1048 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
1049 ok(hr
== S_OK
, "GetCurrentPadding failed: %08x\n", hr
);
1050 trace("padding %u past sleep #2\n", pad
);
1052 /** IAudioClient_Stop
1053 * Exclusive mode: the audio engine appears to drop frames,
1054 * bumping GetPosition to a higher value than time allows, even
1055 * allowing GetPosition > sum Released - GetCurrentPadding (testbot)
1056 * Shared mode: no drop observed (or too small to be visible).
1057 * GetPosition = sum Released - GetCurrentPadding
1058 * Bugs: Some USB headset system drained the whole buffer, leaving
1059 * padding 0 and bumping pos to sum minus 17 frames! */
1061 hr
= IAudioClient_Stop(ac
);
1062 ok(hr
== S_OK
, "Stop failed: %08x\n", hr
);
1064 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
1065 ok(hr
== S_OK
, "GetCurrentPadding failed: %08x\n", hr
);
1067 hr
= IAudioClock_GetPosition(acl
, &pos
, NULL
);
1068 ok(hr
== S_OK
, "GetPosition failed: %08x\n", hr
);
1069 trace("padding %u position %u past stop #2\n", pad
, (UINT
)pos
);
1070 ok(pos
* pwfx
->nSamplesPerSec
<= sum
* freq
, "Position %u > written %u\n", (UINT
)pos
, sum
);
1071 /* Prove that Stop must not drop frames (in shared mode). */
1072 ok(pad
? pos
> last
: pos
>= last
, "Position %u vs. last %u\n", (UINT
)pos
,(UINT
)last
);
1073 if (share
&& pad
> 0 && winetest_debug
>1)
1074 ok(pos
*1000/freq
<= slept
*1.1, "Position %u too far after playing %ums\n", (UINT
)pos
, slept
);
1075 /* in exclusive mode, testbot's w7 machines yield pos > sum-pad */
1076 if(/*share &&*/ winetest_debug
>1)
1077 ok(pos
* pwfx
->nSamplesPerSec
== (sum
-pad
) * freq
,
1078 "Position %u after stop vs. %u padding\n", (UINT
)pos
, pad
);
1083 hr
= IAudioClock_GetPosition(acl
, &pos
, NULL
);
1084 ok(hr
== S_OK
, "GetPosition failed: %08x\n", hr
);
1085 ok(pos
== last
, "Position %u should stop.\n", (UINT
)pos
);
1087 /* Restart from 0 */
1088 hr
= IAudioClient_Reset(ac
);
1089 ok(hr
== S_OK
, "Reset failed: %08x\n", hr
);
1092 hr
= IAudioClient_Reset(ac
);
1093 ok(hr
== S_OK
, "Reset on an already reset stream returns %08x\n", hr
);
1095 hr
= IAudioClock_GetPosition(acl
, &pos
, &pcpos
);
1096 ok(hr
== S_OK
, "GetPosition failed: %08x\n", hr
);
1097 ok(pos
== 0, "GetPosition returned non-zero pos after Reset\n");
1098 ok(pcpos
> pcpos0
, "pcpos should increase\n");
1100 avail
= gbsize
; /* implies GetCurrentPadding == 0 */
1101 hr
= IAudioRenderClient_GetBuffer(arc
, avail
, &data
);
1102 ok(hr
== S_OK
, "GetBuffer failed: %08x\n", hr
);
1103 trace("data at %p\n", data
);
1105 hr
= IAudioRenderClient_ReleaseBuffer(arc
, avail
, winetest_debug
>2 ?
1106 wave_generate_tone(pwfx
, data
, avail
) : AUDCLNT_BUFFERFLAGS_SILENT
);
1107 ok(hr
== S_OK
, "ReleaseBuffer failed: %08x\n", hr
);
1108 if(hr
== S_OK
) sum
+= avail
;
1110 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
1111 ok(hr
== S_OK
, "GetCurrentPadding failed: %08x\n", hr
);
1112 ok(pad
== sum
, "padding %u prior to start\n", pad
);
1114 hr
= IAudioClock_GetPosition(acl
, &pos
, NULL
);
1115 ok(hr
== S_OK
, "GetPosition failed: %08x\n", hr
);
1116 ok(pos
== 0, "GetPosition returned non-zero pos after Reset\n");
1119 hr
= IAudioClient_Start(ac
); /* #3 */
1120 ok(hr
== S_OK
, "Start failed: %08x\n", hr
);
1125 hr
= IAudioClock_GetPosition(acl
, &pos
, NULL
);
1126 ok(hr
== S_OK
, "GetPosition failed: %08x\n", hr
);
1127 trace("position %u past %ums sleep #3\n", (UINT
)pos
, slept
);
1128 ok(pos
> last
, "Position %u vs. last %u\n", (UINT
)pos
,(UINT
)last
);
1129 ok(pos
* pwfx
->nSamplesPerSec
<= sum
* freq
, "Position %u > written %u\n", (UINT
)pos
, sum
);
1130 if (winetest_debug
>1)
1131 ok(pos
*1000/freq
<= slept
*1.1, "Position %u too far after playing %ums\n", (UINT
)pos
, slept
);
1133 skip("Rerun with WINETEST_DEBUG=2 for GetPosition tests.\n");
1136 hr
= IAudioClient_Reset(ac
);
1137 ok(hr
== AUDCLNT_E_NOT_STOPPED
, "Reset while playing: %08x\n", hr
);
1139 hr
= IAudioClient_Stop(ac
);
1140 ok(hr
== S_OK
, "Stop failed: %08x\n", hr
);
1142 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
1143 ok(hr
== S_OK
, "GetCurrentPadding failed: %08x\n", hr
);
1145 hr
= IAudioClock_GetPosition(acl
, &pos
, &pcpos
);
1146 ok(hr
== S_OK
, "GetPosition failed: %08x\n", hr
);
1147 trace("padding %u position %u past stop #3\n", pad
, (UINT
)pos
);
1148 ok(pos
>= last
, "Position %u vs. last %u\n", (UINT
)pos
,(UINT
)last
);
1149 ok(pcpos
> pcpos0
, "pcpos should increase\n");
1150 ok(pos
* pwfx
->nSamplesPerSec
<= sum
* freq
, "Position %u > written %u\n", (UINT
)pos
, sum
);
1151 if (pad
> 0 && winetest_debug
>1)
1152 ok(pos
*1000/freq
<= slept
*1.1, "Position %u too far after stop %ums\n", (UINT
)pos
, slept
);
1153 if(winetest_debug
>1)
1154 ok(pos
* pwfx
->nSamplesPerSec
== (sum
-pad
) * freq
,
1155 "Position %u after stop vs. %u padding\n", (UINT
)pos
, pad
);
1158 /* Begin the big loop */
1159 hr
= IAudioClient_Reset(ac
);
1160 ok(hr
== S_OK
, "Reset failed: %08x\n", hr
);
1161 slept
= last
= sum
= 0;
1164 ok(QueryPerformanceCounter(&hpctime0
), "PerfCounter unavailable\n");
1166 hr
= IAudioClient_Reset(ac
);
1167 ok(hr
== S_OK
, "Reset on an already reset stream returns %08x\n", hr
);
1169 hr
= IAudioClient_Start(ac
);
1170 ok(hr
== S_OK
, "Start failed: %08x\n", hr
);
1172 avail
= pwfx
->nSamplesPerSec
* 15 / 16 / 2;
1174 hr
= IAudioRenderClient_GetBuffer(arc
, avail
, &data
);
1175 ok(hr
== S_OK
, "GetBuffer failed: %08x\n", hr
);
1176 trace("data at %p for prefill %u\n", data
, avail
);
1178 if (winetest_debug
>2) {
1179 hr
= IAudioClient_Stop(ac
);
1180 ok(hr
== S_OK
, "Stop failed: %08x\n", hr
);
1185 hr
= IAudioClient_Reset(ac
);
1186 ok(hr
== AUDCLNT_E_BUFFER_OPERATION_PENDING
, "Reset failed: %08x\n", hr
);
1188 hr
= IAudioClient_Start(ac
);
1189 ok(hr
== S_OK
, "Start failed: %08x\n", hr
);
1192 /* Despite passed time, data must still point to valid memory... */
1193 hr
= IAudioRenderClient_ReleaseBuffer(arc
, avail
,
1194 wave_generate_tone(pwfx
, data
, avail
));
1195 ok(hr
== S_OK
, "ReleaseBuffer after stop+start failed: %08x\n", hr
);
1196 if(hr
== S_OK
) sum
+= avail
;
1198 /* GetCurrentPadding(GCP) == 0 does not mean an underrun happened, as the
1199 * mixer may still have a little data. We believe an underrun will occur
1200 * when the mixer finds GCP smaller than a period size at the *end* of a
1201 * period cycle, i.e. shortly before calling SetEvent to signal the app
1202 * that it has ~10ms to supply data for the next cycle. IOW, a zero GCP
1203 * with no data written for over a period causes an underrun. */
1207 ok(QueryPerformanceCounter(&hpctime
), "PerfCounter failed\n");
1208 trace("hpctime %u after %ums\n",
1209 (ULONG
)((hpctime
.QuadPart
-hpctime0
.QuadPart
)*1000/hpcfreq
.QuadPart
), slept
);
1211 hr
= IAudioClock_GetPosition(acl
, &pos
, &pcpos
);
1212 ok(hr
== S_OK
, "GetPosition failed: %08x\n", hr
);
1213 ok(pos
> last
, "Position %u vs. last %u\n", (UINT
)pos
,(UINT
)last
);
1216 for(i
=0; i
< 9; i
++) {
1220 hr
= IAudioClock_GetPosition(acl
, &pos
, &pcpos
);
1221 ok(hr
== S_OK
, "GetPosition failed: %08x\n", hr
);
1223 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
1224 ok(hr
== S_OK
, "GetCurrentPadding failed: %08x\n", hr
);
1226 ok(QueryPerformanceCounter(&hpctime
), "PerfCounter failed\n");
1227 trace("hpctime %u pcpos %u\n",
1228 (ULONG
)((hpctime
.QuadPart
-hpctime0
.QuadPart
)*1000/hpcfreq
.QuadPart
),
1229 (ULONG
)((pcpos
-pcpos0
)/10000));
1231 /* Use sum-pad to see whether position is ahead padding or not. */
1232 trace("padding %u position %u/%u slept %ums iteration %d\n", pad
, (UINT
)pos
, sum
-pad
, slept
, i
);
1233 ok(pad
? pos
> last
: pos
>= last
, "No position increase at iteration %d\n", i
);
1234 ok(pos
* pwfx
->nSamplesPerSec
<= sum
* freq
, "Position %u > written %u\n", (UINT
)pos
, sum
);
1235 if (winetest_debug
>1) {
1236 /* Padding does not lag behind by much */
1237 ok(pos
* pwfx
->nSamplesPerSec
<= (sum
-pad
+fragment
) * freq
, "Position %u > written %u\n", (UINT
)pos
, sum
);
1238 ok(pos
*1000/freq
<= slept
*1.1, "Position %u too far after %ums\n", (UINT
)pos
, slept
);
1239 if (pad
) /* not in case of underrun */
1240 ok((pos
-last
)*1000/freq
>= 90 && 110 >= (pos
-last
)*1000/freq
,
1241 "Position delta %ld not regular: %ld ms\n", (long)(pos
-last
), (long)((pos
-last
)*1000/freq
));
1245 hr
= IAudioClient_GetStreamLatency(ac
, &t1
);
1246 ok(hr
== S_OK
, "GetStreamLatency failed: %08x\n", hr
);
1247 ok(t1
== t2
, "Latency not constant, delta %ld\n", (long)(t1
-t2
));
1249 avail
= pwfx
->nSamplesPerSec
* 15 / 16 / 2;
1251 hr
= IAudioRenderClient_GetBuffer(arc
, avail
, &data
);
1252 /* ok(hr == AUDCLNT_E_BUFFER_TOO_LARGE || (hr == S_OK && i==0) without todo_wine */
1253 ok(hr
== S_OK
|| hr
== AUDCLNT_E_BUFFER_TOO_LARGE
,
1254 "GetBuffer large (%u) failed: %08x\n", avail
, hr
);
1255 if(hr
== S_OK
&& i
) ok(FALSE
, "GetBuffer large (%u) at iteration %d\n", avail
, i
);
1256 /* Only the first iteration should allow that large a buffer
1257 * as prefill was drained during the first 350+100ms sleep.
1258 * Afterwards, only 100ms of data should find room per iteration. */
1261 trace("data at %p\n", data
);
1263 avail
= gbsize
- pad
;
1264 hr
= IAudioRenderClient_GetBuffer(arc
, avail
, &data
);
1265 ok(hr
== S_OK
, "GetBuffer small %u failed: %08x\n", avail
, hr
);
1266 trace("data at %p (small %u)\n", data
, avail
);
1268 ok(data
!= NULL
, "NULL buffer returned\n");
1269 if(i
% 3 && !winetest_interactive
) {
1270 memset(data
, 0, avail
* pwfx
->nBlockAlign
);
1271 hr
= IAudioRenderClient_ReleaseBuffer(arc
, avail
, 0);
1273 hr
= IAudioRenderClient_ReleaseBuffer(arc
, avail
,
1274 wave_generate_tone(pwfx
, data
, avail
));
1276 ok(hr
== S_OK
, "ReleaseBuffer failed: %08x\n", hr
);
1277 if(hr
== S_OK
) sum
+= avail
;
1280 hr
= IAudioClock_GetPosition(acl
, &pos
, NULL
);
1281 ok(hr
== S_OK
, "GetPosition failed: %08x\n", hr
);
1282 trace("position %u\n", (UINT
)pos
);
1284 Sleep(1000); /* 500ms buffer underrun past full buffer */
1286 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
1287 ok(hr
== S_OK
, "GetCurrentPadding failed: %08x\n", hr
);
1289 hr
= IAudioClock_GetPosition(acl
, &pos
, NULL
);
1290 ok(hr
== S_OK
, "GetPosition failed: %08x\n", hr
);
1291 trace("position %u past underrun, %u padding left, %u frames written\n", (UINT
)pos
, pad
, sum
);
1294 /* Following underrun, all samples were played */
1295 ok(pad
== 0, "GetCurrentPadding returned %u, should be 0\n", pad
);
1296 ok(pos
* pwfx
->nSamplesPerSec
== sum
* freq
,
1297 "Position %u at end vs. %u submitted frames\n", (UINT
)pos
, sum
);
1299 /* Vista and w2k8 leave partial fragments behind */
1300 ok(pad
== 0 /* w7, w2k8R2 */||
1301 pos
* pwfx
->nSamplesPerSec
== (sum
-pad
) * freq
, "GetCurrentPadding returned %u, should be 0\n", pad
);
1302 /* expect at most 5 fragments (75ms) away */
1303 ok(pos
* pwfx
->nSamplesPerSec
<= sum
* freq
&&
1304 pos
* pwfx
->nSamplesPerSec
+ 5 * fragment
* freq
>= sum
* freq
,
1305 "Position %u at end vs. %u submitted frames\n", (UINT
)pos
, sum
);
1308 hr
= IAudioClient_GetStreamLatency(ac
, &t1
);
1309 ok(hr
== S_OK
, "GetStreamLatency failed: %08x\n", hr
);
1310 ok(t1
== t2
, "Latency not constant, delta %ld\n", (long)(t1
-t2
));
1312 ok(QueryPerformanceCounter(&hpctime
), "PerfCounter failed\n");
1313 trace("hpctime %u after underrun\n", (ULONG
)((hpctime
.QuadPart
-hpctime0
.QuadPart
)*1000/hpcfreq
.QuadPart
));
1315 hr
= IAudioClient_Stop(ac
);
1316 ok(hr
== S_OK
, "Stop failed: %08x\n", hr
);
1318 CoTaskMemFree(pwfx
);
1320 IAudioClock_Release(acl
);
1321 IAudioRenderClient_Release(arc
);
1322 IAudioClient_Release(ac
);
1325 static void test_session(void)
1327 IAudioClient
*ses1_ac1
, *ses1_ac2
, *cap_ac
;
1328 IAudioSessionControl2
*ses1_ctl
, *ses1_ctl2
, *cap_ctl
= NULL
;
1331 AudioSessionState state
;
1336 hr
= CoCreateGuid(&ses1_guid
);
1337 ok(hr
== S_OK
, "CoCreateGuid failed: %08x\n", hr
);
1339 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
1340 NULL
, (void**)&ses1_ac1
);
1341 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
1342 if (FAILED(hr
)) return;
1344 hr
= IAudioClient_GetMixFormat(ses1_ac1
, &pwfx
);
1345 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
1347 hr
= IAudioClient_Initialize(ses1_ac1
, AUDCLNT_SHAREMODE_SHARED
,
1348 0, 5000000, 0, pwfx
, &ses1_guid
);
1349 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
1352 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
1353 NULL
, (void**)&ses1_ac2
);
1354 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
1357 skip("Unable to open the same device twice. Skipping session tests\n");
1359 ref
= IAudioClient_Release(ses1_ac1
);
1360 ok(ref
== 0, "AudioClient wasn't released: %u\n", ref
);
1361 CoTaskMemFree(pwfx
);
1365 hr
= IAudioClient_Initialize(ses1_ac2
, AUDCLNT_SHAREMODE_SHARED
,
1366 0, 5000000, 0, pwfx
, &ses1_guid
);
1367 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
1369 hr
= IMMDeviceEnumerator_GetDefaultAudioEndpoint(mme
, eCapture
,
1370 eMultimedia
, &cap_dev
);
1372 hr
= IMMDevice_Activate(cap_dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
1373 NULL
, (void**)&cap_ac
);
1374 ok((hr
== S_OK
)^(cap_ac
== NULL
), "Activate %08x &out pointer\n", hr
);
1375 ok(hr
== S_OK
, "Activate failed: %08x\n", hr
);
1376 IMMDevice_Release(cap_dev
);
1379 WAVEFORMATEX
*cap_pwfx
;
1381 hr
= IAudioClient_GetMixFormat(cap_ac
, &cap_pwfx
);
1382 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
1384 hr
= IAudioClient_Initialize(cap_ac
, AUDCLNT_SHAREMODE_SHARED
,
1385 0, 5000000, 0, cap_pwfx
, &ses1_guid
);
1386 ok(hr
== S_OK
, "Initialize failed for capture in rendering session: %08x\n", hr
);
1387 CoTaskMemFree(cap_pwfx
);
1390 hr
= IAudioClient_GetService(cap_ac
, &IID_IAudioSessionControl
, (void**)&cap_ctl
);
1391 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
1395 skip("No capture session: %08x; skipping capture device in render session tests\n", hr
);
1397 hr
= IAudioClient_GetService(ses1_ac1
, &IID_IAudioSessionControl2
, (void**)&ses1_ctl
);
1398 ok(hr
== E_NOINTERFACE
, "GetService gave wrong error: %08x\n", hr
);
1400 hr
= IAudioClient_GetService(ses1_ac1
, &IID_IAudioSessionControl
, (void**)&ses1_ctl
);
1401 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
1403 hr
= IAudioClient_GetService(ses1_ac1
, &IID_IAudioSessionControl
, (void**)&ses1_ctl2
);
1404 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
1405 ok(ses1_ctl
== ses1_ctl2
, "Got different controls: %p %p\n", ses1_ctl
, ses1_ctl2
);
1406 ref
= IAudioSessionControl2_Release(ses1_ctl2
);
1407 ok(ref
!= 0, "AudioSessionControl was destroyed\n");
1409 hr
= IAudioClient_GetService(ses1_ac2
, &IID_IAudioSessionControl
, (void**)&ses1_ctl2
);
1410 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
1412 hr
= IAudioSessionControl2_GetState(ses1_ctl
, NULL
);
1413 ok(hr
== NULL_PTR_ERR
, "GetState gave wrong error: %08x\n", hr
);
1415 hr
= IAudioSessionControl2_GetState(ses1_ctl
, &state
);
1416 ok(hr
== S_OK
, "GetState failed: %08x\n", hr
);
1417 ok(state
== AudioSessionStateInactive
, "Got wrong state: %d\n", state
);
1419 hr
= IAudioSessionControl2_GetState(ses1_ctl2
, &state
);
1420 ok(hr
== S_OK
, "GetState failed: %08x\n", hr
);
1421 ok(state
== AudioSessionStateInactive
, "Got wrong state: %d\n", state
);
1424 hr
= IAudioSessionControl2_GetState(cap_ctl
, &state
);
1425 ok(hr
== S_OK
, "GetState failed: %08x\n", hr
);
1426 ok(state
== AudioSessionStateInactive
, "Got wrong state: %d\n", state
);
1429 hr
= IAudioClient_Start(ses1_ac1
);
1430 ok(hr
== S_OK
, "Start failed: %08x\n", hr
);
1432 hr
= IAudioSessionControl2_GetState(ses1_ctl
, &state
);
1433 ok(hr
== S_OK
, "GetState failed: %08x\n", hr
);
1434 ok(state
== AudioSessionStateActive
, "Got wrong state: %d\n", state
);
1436 hr
= IAudioSessionControl2_GetState(ses1_ctl2
, &state
);
1437 ok(hr
== S_OK
, "GetState failed: %08x\n", hr
);
1438 ok(state
== AudioSessionStateActive
, "Got wrong state: %d\n", state
);
1441 hr
= IAudioSessionControl2_GetState(cap_ctl
, &state
);
1442 ok(hr
== S_OK
, "GetState failed: %08x\n", hr
);
1443 ok(state
== AudioSessionStateInactive
, "Got wrong state: %d\n", state
);
1446 hr
= IAudioClient_Stop(ses1_ac1
);
1447 ok(hr
== S_OK
, "Start failed: %08x\n", hr
);
1449 hr
= IAudioSessionControl2_GetState(ses1_ctl
, &state
);
1450 ok(hr
== S_OK
, "GetState failed: %08x\n", hr
);
1451 ok(state
== AudioSessionStateInactive
, "Got wrong state: %d\n", state
);
1453 hr
= IAudioSessionControl2_GetState(ses1_ctl2
, &state
);
1454 ok(hr
== S_OK
, "GetState failed: %08x\n", hr
);
1455 ok(state
== AudioSessionStateInactive
, "Got wrong state: %d\n", state
);
1458 hr
= IAudioSessionControl2_GetState(cap_ctl
, &state
);
1459 ok(hr
== S_OK
, "GetState failed: %08x\n", hr
);
1460 ok(state
== AudioSessionStateInactive
, "Got wrong state: %d\n", state
);
1462 hr
= IAudioClient_Start(cap_ac
);
1463 ok(hr
== S_OK
, "Start failed: %08x\n", hr
);
1465 hr
= IAudioSessionControl2_GetState(ses1_ctl
, &state
);
1466 ok(hr
== S_OK
, "GetState failed: %08x\n", hr
);
1467 ok(state
== AudioSessionStateInactive
, "Got wrong state: %d\n", state
);
1469 hr
= IAudioSessionControl2_GetState(ses1_ctl2
, &state
);
1470 ok(hr
== S_OK
, "GetState failed: %08x\n", hr
);
1471 ok(state
== AudioSessionStateInactive
, "Got wrong state: %d\n", state
);
1473 hr
= IAudioSessionControl2_GetState(cap_ctl
, &state
);
1474 ok(hr
== S_OK
, "GetState failed: %08x\n", hr
);
1475 ok(state
== AudioSessionStateActive
, "Got wrong state: %d\n", state
);
1477 hr
= IAudioClient_Stop(cap_ac
);
1478 ok(hr
== S_OK
, "Stop failed: %08x\n", hr
);
1480 hr
= IAudioSessionControl2_GetState(ses1_ctl
, &state
);
1481 ok(hr
== S_OK
, "GetState failed: %08x\n", hr
);
1482 ok(state
== AudioSessionStateInactive
, "Got wrong state: %d\n", state
);
1484 hr
= IAudioSessionControl2_GetState(ses1_ctl2
, &state
);
1485 ok(hr
== S_OK
, "GetState failed: %08x\n", hr
);
1486 ok(state
== AudioSessionStateInactive
, "Got wrong state: %d\n", state
);
1488 hr
= IAudioSessionControl2_GetState(cap_ctl
, &state
);
1489 ok(hr
== S_OK
, "GetState failed: %08x\n", hr
);
1490 ok(state
== AudioSessionStateInactive
, "Got wrong state: %d\n", state
);
1492 ref
= IAudioSessionControl2_Release(cap_ctl
);
1493 ok(ref
== 0, "AudioSessionControl wasn't released: %u\n", ref
);
1495 ref
= IAudioClient_Release(cap_ac
);
1496 ok(ref
== 0, "AudioClient wasn't released: %u\n", ref
);
1499 ref
= IAudioSessionControl2_Release(ses1_ctl
);
1500 ok(ref
== 0, "AudioSessionControl wasn't released: %u\n", ref
);
1502 ref
= IAudioClient_Release(ses1_ac1
);
1503 ok(ref
== 0, "AudioClient wasn't released: %u\n", ref
);
1505 ref
= IAudioClient_Release(ses1_ac2
);
1506 ok(ref
== 1, "AudioClient had wrong refcount: %u\n", ref
);
1508 /* we've released all of our IAudioClient references, so check GetState */
1509 hr
= IAudioSessionControl2_GetState(ses1_ctl2
, &state
);
1510 ok(hr
== S_OK
, "GetState failed: %08x\n", hr
);
1511 ok(state
== AudioSessionStateInactive
, "Got wrong state: %d\n", state
);
1513 ref
= IAudioSessionControl2_Release(ses1_ctl2
);
1514 ok(ref
== 0, "AudioSessionControl wasn't released: %u\n", ref
);
1516 CoTaskMemFree(pwfx
);
1519 static void test_streamvolume(void)
1522 IAudioStreamVolume
*asv
;
1528 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
1530 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
1534 hr
= IAudioClient_GetMixFormat(ac
, &fmt
);
1535 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
1537 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0, 5000000,
1539 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
1542 hr
= IAudioClient_GetService(ac
, &IID_IAudioStreamVolume
, (void**)&asv
);
1543 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
1546 IAudioClient_Release(ac
);
1551 hr
= IAudioStreamVolume_GetChannelCount(asv
, NULL
);
1552 ok(hr
== E_POINTER
, "GetChannelCount gave wrong error: %08x\n", hr
);
1554 hr
= IAudioStreamVolume_GetChannelCount(asv
, &chans
);
1555 ok(hr
== S_OK
, "GetChannelCount failed: %08x\n", hr
);
1556 ok(chans
== fmt
->nChannels
, "GetChannelCount gave wrong number of channels: %d\n", chans
);
1558 hr
= IAudioStreamVolume_GetChannelVolume(asv
, fmt
->nChannels
, NULL
);
1559 ok(hr
== E_POINTER
, "GetChannelCount gave wrong error: %08x\n", hr
);
1561 hr
= IAudioStreamVolume_GetChannelVolume(asv
, fmt
->nChannels
, &vol
);
1562 ok(hr
== E_INVALIDARG
, "GetChannelCount gave wrong error: %08x\n", hr
);
1564 hr
= IAudioStreamVolume_GetChannelVolume(asv
, 0, NULL
);
1565 ok(hr
== E_POINTER
, "GetChannelCount gave wrong error: %08x\n", hr
);
1567 hr
= IAudioStreamVolume_GetChannelVolume(asv
, 0, &vol
);
1568 ok(hr
== S_OK
, "GetChannelCount failed: %08x\n", hr
);
1569 ok(vol
== 1.f
, "Channel volume was not 1: %f\n", vol
);
1571 hr
= IAudioStreamVolume_SetChannelVolume(asv
, fmt
->nChannels
, -1.f
);
1572 ok(hr
== E_INVALIDARG
, "SetChannelVolume gave wrong error: %08x\n", hr
);
1574 hr
= IAudioStreamVolume_SetChannelVolume(asv
, 0, -1.f
);
1575 ok(hr
== E_INVALIDARG
, "SetChannelVolume gave wrong error: %08x\n", hr
);
1577 hr
= IAudioStreamVolume_SetChannelVolume(asv
, 0, 2.f
);
1578 ok(hr
== E_INVALIDARG
, "SetChannelVolume gave wrong error: %08x\n", hr
);
1580 hr
= IAudioStreamVolume_SetChannelVolume(asv
, 0, 0.2f
);
1581 ok(hr
== S_OK
, "SetChannelVolume failed: %08x\n", hr
);
1583 hr
= IAudioStreamVolume_GetChannelVolume(asv
, 0, &vol
);
1584 ok(hr
== S_OK
, "GetChannelCount failed: %08x\n", hr
);
1585 ok(fabsf(vol
- 0.2f
) < 0.05f
, "Channel volume wasn't 0.2: %f\n", vol
);
1587 hr
= IAudioStreamVolume_GetAllVolumes(asv
, 0, NULL
);
1588 ok(hr
== E_POINTER
, "GetAllVolumes gave wrong error: %08x\n", hr
);
1590 hr
= IAudioStreamVolume_GetAllVolumes(asv
, fmt
->nChannels
, NULL
);
1591 ok(hr
== E_POINTER
, "GetAllVolumes gave wrong error: %08x\n", hr
);
1593 vols
= HeapAlloc(GetProcessHeap(), 0, fmt
->nChannels
* sizeof(float));
1594 ok(vols
!= NULL
, "HeapAlloc failed\n");
1596 hr
= IAudioStreamVolume_GetAllVolumes(asv
, fmt
->nChannels
- 1, vols
);
1597 ok(hr
== E_INVALIDARG
, "GetAllVolumes gave wrong error: %08x\n", hr
);
1599 hr
= IAudioStreamVolume_GetAllVolumes(asv
, fmt
->nChannels
, vols
);
1600 ok(hr
== S_OK
, "GetAllVolumes failed: %08x\n", hr
);
1601 ok(fabsf(vols
[0] - 0.2f
) < 0.05f
, "Channel 0 volume wasn't 0.2: %f\n", vol
);
1602 for(i
= 1; i
< fmt
->nChannels
; ++i
)
1603 ok(vols
[i
] == 1.f
, "Channel %d volume is not 1: %f\n", i
, vols
[i
]);
1605 hr
= IAudioStreamVolume_SetAllVolumes(asv
, 0, NULL
);
1606 ok(hr
== E_POINTER
, "SetAllVolumes gave wrong error: %08x\n", hr
);
1608 hr
= IAudioStreamVolume_SetAllVolumes(asv
, fmt
->nChannels
, NULL
);
1609 ok(hr
== E_POINTER
, "SetAllVolumes gave wrong error: %08x\n", hr
);
1611 hr
= IAudioStreamVolume_SetAllVolumes(asv
, fmt
->nChannels
- 1, vols
);
1612 ok(hr
== E_INVALIDARG
, "SetAllVolumes gave wrong error: %08x\n", hr
);
1614 hr
= IAudioStreamVolume_SetAllVolumes(asv
, fmt
->nChannels
, vols
);
1615 ok(hr
== S_OK
, "SetAllVolumes failed: %08x\n", hr
);
1617 HeapFree(GetProcessHeap(), 0, vols
);
1618 IAudioStreamVolume_Release(asv
);
1619 IAudioClient_Release(ac
);
1623 static void test_channelvolume(void)
1626 IChannelAudioVolume
*acv
;
1632 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
1634 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
1638 hr
= IAudioClient_GetMixFormat(ac
, &fmt
);
1639 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
1641 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
,
1642 AUDCLNT_STREAMFLAGS_NOPERSIST
, 5000000, 0, fmt
, NULL
);
1643 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
1646 hr
= IAudioClient_GetService(ac
, &IID_IChannelAudioVolume
, (void**)&acv
);
1647 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
1650 IAudioClient_Release(ac
);
1655 hr
= IChannelAudioVolume_GetChannelCount(acv
, NULL
);
1656 ok(hr
== NULL_PTR_ERR
, "GetChannelCount gave wrong error: %08x\n", hr
);
1658 hr
= IChannelAudioVolume_GetChannelCount(acv
, &chans
);
1659 ok(hr
== S_OK
, "GetChannelCount failed: %08x\n", hr
);
1660 ok(chans
== fmt
->nChannels
, "GetChannelCount gave wrong number of channels: %d\n", chans
);
1662 hr
= IChannelAudioVolume_GetChannelVolume(acv
, fmt
->nChannels
, NULL
);
1663 ok(hr
== NULL_PTR_ERR
, "GetChannelCount gave wrong error: %08x\n", hr
);
1665 hr
= IChannelAudioVolume_GetChannelVolume(acv
, fmt
->nChannels
, &vol
);
1666 ok(hr
== E_INVALIDARG
, "GetChannelCount gave wrong error: %08x\n", hr
);
1668 hr
= IChannelAudioVolume_GetChannelVolume(acv
, 0, NULL
);
1669 ok(hr
== NULL_PTR_ERR
, "GetChannelCount gave wrong error: %08x\n", hr
);
1671 hr
= IChannelAudioVolume_GetChannelVolume(acv
, 0, &vol
);
1672 ok(hr
== S_OK
, "GetChannelCount failed: %08x\n", hr
);
1673 ok(vol
== 1.f
, "Channel volume was not 1: %f\n", vol
);
1675 hr
= IChannelAudioVolume_SetChannelVolume(acv
, fmt
->nChannels
, -1.f
, NULL
);
1676 ok(hr
== E_INVALIDARG
, "SetChannelVolume gave wrong error: %08x\n", hr
);
1678 hr
= IChannelAudioVolume_SetChannelVolume(acv
, 0, -1.f
, NULL
);
1679 ok(hr
== E_INVALIDARG
, "SetChannelVolume gave wrong error: %08x\n", hr
);
1681 hr
= IChannelAudioVolume_SetChannelVolume(acv
, 0, 2.f
, NULL
);
1682 ok(hr
== E_INVALIDARG
, "SetChannelVolume gave wrong error: %08x\n", hr
);
1684 hr
= IChannelAudioVolume_SetChannelVolume(acv
, 0, 0.2f
, NULL
);
1685 ok(hr
== S_OK
, "SetChannelVolume failed: %08x\n", hr
);
1687 hr
= IChannelAudioVolume_GetChannelVolume(acv
, 0, &vol
);
1688 ok(hr
== S_OK
, "GetChannelCount failed: %08x\n", hr
);
1689 ok(fabsf(vol
- 0.2f
) < 0.05f
, "Channel volume wasn't 0.2: %f\n", vol
);
1691 hr
= IChannelAudioVolume_GetAllVolumes(acv
, 0, NULL
);
1692 ok(hr
== NULL_PTR_ERR
, "GetAllVolumes gave wrong error: %08x\n", hr
);
1694 hr
= IChannelAudioVolume_GetAllVolumes(acv
, fmt
->nChannels
, NULL
);
1695 ok(hr
== NULL_PTR_ERR
, "GetAllVolumes gave wrong error: %08x\n", hr
);
1697 vols
= HeapAlloc(GetProcessHeap(), 0, fmt
->nChannels
* sizeof(float));
1698 ok(vols
!= NULL
, "HeapAlloc failed\n");
1700 hr
= IChannelAudioVolume_GetAllVolumes(acv
, fmt
->nChannels
- 1, vols
);
1701 ok(hr
== E_INVALIDARG
, "GetAllVolumes gave wrong error: %08x\n", hr
);
1703 hr
= IChannelAudioVolume_GetAllVolumes(acv
, fmt
->nChannels
, vols
);
1704 ok(hr
== S_OK
, "GetAllVolumes failed: %08x\n", hr
);
1705 ok(fabsf(vols
[0] - 0.2f
) < 0.05f
, "Channel 0 volume wasn't 0.2: %f\n", vol
);
1706 for(i
= 1; i
< fmt
->nChannels
; ++i
)
1707 ok(vols
[i
] == 1.f
, "Channel %d volume is not 1: %f\n", i
, vols
[i
]);
1709 hr
= IChannelAudioVolume_SetAllVolumes(acv
, 0, NULL
, NULL
);
1710 ok(hr
== NULL_PTR_ERR
, "SetAllVolumes gave wrong error: %08x\n", hr
);
1712 hr
= IChannelAudioVolume_SetAllVolumes(acv
, fmt
->nChannels
, NULL
, NULL
);
1713 ok(hr
== NULL_PTR_ERR
, "SetAllVolumes gave wrong error: %08x\n", hr
);
1715 hr
= IChannelAudioVolume_SetAllVolumes(acv
, fmt
->nChannels
- 1, vols
, NULL
);
1716 ok(hr
== E_INVALIDARG
, "SetAllVolumes gave wrong error: %08x\n", hr
);
1718 hr
= IChannelAudioVolume_SetAllVolumes(acv
, fmt
->nChannels
, vols
, NULL
);
1719 ok(hr
== S_OK
, "SetAllVolumes failed: %08x\n", hr
);
1721 hr
= IChannelAudioVolume_SetChannelVolume(acv
, 0, 1.0f
, NULL
);
1722 ok(hr
== S_OK
, "SetChannelVolume failed: %08x\n", hr
);
1724 HeapFree(GetProcessHeap(), 0, vols
);
1725 IChannelAudioVolume_Release(acv
);
1726 IAudioClient_Release(ac
);
1730 static void test_simplevolume(void)
1733 ISimpleAudioVolume
*sav
;
1739 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
1741 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
1745 hr
= IAudioClient_GetMixFormat(ac
, &fmt
);
1746 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
1748 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
,
1749 AUDCLNT_STREAMFLAGS_NOPERSIST
, 5000000, 0, fmt
, NULL
);
1750 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
1753 hr
= IAudioClient_GetService(ac
, &IID_ISimpleAudioVolume
, (void**)&sav
);
1754 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
1757 IAudioClient_Release(ac
);
1762 hr
= ISimpleAudioVolume_GetMasterVolume(sav
, NULL
);
1763 ok(hr
== NULL_PTR_ERR
, "GetMasterVolume gave wrong error: %08x\n", hr
);
1765 hr
= ISimpleAudioVolume_GetMasterVolume(sav
, &vol
);
1766 ok(hr
== S_OK
, "GetMasterVolume failed: %08x\n", hr
);
1767 ok(vol
== 1.f
, "Master volume wasn't 1: %f\n", vol
);
1769 hr
= ISimpleAudioVolume_SetMasterVolume(sav
, -1.f
, NULL
);
1770 ok(hr
== E_INVALIDARG
, "SetMasterVolume gave wrong error: %08x\n", hr
);
1772 hr
= ISimpleAudioVolume_SetMasterVolume(sav
, 2.f
, NULL
);
1773 ok(hr
== E_INVALIDARG
, "SetMasterVolume gave wrong error: %08x\n", hr
);
1775 hr
= ISimpleAudioVolume_SetMasterVolume(sav
, 0.2f
, NULL
);
1776 ok(hr
== S_OK
, "SetMasterVolume failed: %08x\n", hr
);
1778 hr
= ISimpleAudioVolume_GetMasterVolume(sav
, &vol
);
1779 ok(hr
== S_OK
, "GetMasterVolume failed: %08x\n", hr
);
1780 ok(fabsf(vol
- 0.2f
) < 0.05f
, "Master volume wasn't 0.2: %f\n", vol
);
1782 hr
= ISimpleAudioVolume_GetMute(sav
, NULL
);
1783 ok(hr
== NULL_PTR_ERR
, "GetMute gave wrong error: %08x\n", hr
);
1786 hr
= ISimpleAudioVolume_GetMute(sav
, &mute
);
1787 ok(hr
== S_OK
, "GetMute failed: %08x\n", hr
);
1788 ok(mute
== FALSE
, "Session is already muted\n");
1790 hr
= ISimpleAudioVolume_SetMute(sav
, TRUE
, NULL
);
1791 ok(hr
== S_OK
, "SetMute failed: %08x\n", hr
);
1794 hr
= ISimpleAudioVolume_GetMute(sav
, &mute
);
1795 ok(hr
== S_OK
, "GetMute failed: %08x\n", hr
);
1796 ok(mute
== TRUE
, "Session should have been muted\n");
1798 hr
= ISimpleAudioVolume_GetMasterVolume(sav
, &vol
);
1799 ok(hr
== S_OK
, "GetMasterVolume failed: %08x\n", hr
);
1800 ok(fabsf(vol
- 0.2f
) < 0.05f
, "Master volume wasn't 0.2: %f\n", vol
);
1802 hr
= ISimpleAudioVolume_SetMasterVolume(sav
, 1.f
, NULL
);
1803 ok(hr
== S_OK
, "SetMasterVolume failed: %08x\n", hr
);
1806 hr
= ISimpleAudioVolume_GetMute(sav
, &mute
);
1807 ok(hr
== S_OK
, "GetMute failed: %08x\n", hr
);
1808 ok(mute
== TRUE
, "Session should have been muted\n");
1810 hr
= ISimpleAudioVolume_SetMute(sav
, FALSE
, NULL
);
1811 ok(hr
== S_OK
, "SetMute failed: %08x\n", hr
);
1813 ISimpleAudioVolume_Release(sav
);
1814 IAudioClient_Release(ac
);
1818 static void test_volume_dependence(void)
1820 IAudioClient
*ac
, *ac2
;
1821 ISimpleAudioVolume
*sav
;
1822 IChannelAudioVolume
*cav
;
1823 IAudioStreamVolume
*asv
;
1830 hr
= CoCreateGuid(&session
);
1831 ok(hr
== S_OK
, "CoCreateGuid failed: %08x\n", hr
);
1833 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
1835 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
1839 hr
= IAudioClient_GetMixFormat(ac
, &fmt
);
1840 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
1842 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
,
1843 AUDCLNT_STREAMFLAGS_NOPERSIST
, 5000000, 0, fmt
, &session
);
1844 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
1847 hr
= IAudioClient_GetService(ac
, &IID_ISimpleAudioVolume
, (void**)&sav
);
1848 ok(hr
== S_OK
, "GetService (SimpleAudioVolume) failed: %08x\n", hr
);
1851 IAudioClient_Release(ac
);
1856 hr
= IAudioClient_GetService(ac
, &IID_IChannelAudioVolume
, (void**)&cav
);
1857 ok(hr
== S_OK
, "GetService (ChannelAudioVolume) failed: %08x\n", hr
);
1859 hr
= IAudioClient_GetService(ac
, &IID_IAudioStreamVolume
, (void**)&asv
);
1860 ok(hr
== S_OK
, "GetService (AudioStreamVolume) failed: %08x\n", hr
);
1862 hr
= IAudioStreamVolume_SetChannelVolume(asv
, 0, 0.2f
);
1863 ok(hr
== S_OK
, "ASV_SetChannelVolume failed: %08x\n", hr
);
1865 hr
= IChannelAudioVolume_SetChannelVolume(cav
, 0, 0.4f
, NULL
);
1866 ok(hr
== S_OK
, "CAV_SetChannelVolume failed: %08x\n", hr
);
1868 hr
= ISimpleAudioVolume_SetMasterVolume(sav
, 0.6f
, NULL
);
1869 ok(hr
== S_OK
, "SAV_SetMasterVolume failed: %08x\n", hr
);
1871 hr
= IAudioStreamVolume_GetChannelVolume(asv
, 0, &vol
);
1872 ok(hr
== S_OK
, "ASV_GetChannelVolume failed: %08x\n", hr
);
1873 ok(fabsf(vol
- 0.2f
) < 0.05f
, "ASV_GetChannelVolume gave wrong volume: %f\n", vol
);
1875 hr
= IChannelAudioVolume_GetChannelVolume(cav
, 0, &vol
);
1876 ok(hr
== S_OK
, "CAV_GetChannelVolume failed: %08x\n", hr
);
1877 ok(fabsf(vol
- 0.4f
) < 0.05f
, "CAV_GetChannelVolume gave wrong volume: %f\n", vol
);
1879 hr
= ISimpleAudioVolume_GetMasterVolume(sav
, &vol
);
1880 ok(hr
== S_OK
, "SAV_GetMasterVolume failed: %08x\n", hr
);
1881 ok(fabsf(vol
- 0.6f
) < 0.05f
, "SAV_GetMasterVolume gave wrong volume: %f\n", vol
);
1883 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
1884 NULL
, (void**)&ac2
);
1885 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
1888 hr
= IAudioClient_Initialize(ac2
, AUDCLNT_SHAREMODE_SHARED
,
1889 AUDCLNT_STREAMFLAGS_NOPERSIST
, 5000000, 0, fmt
, &session
);
1890 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
1892 IAudioClient_Release(ac2
);
1896 IChannelAudioVolume
*cav2
;
1897 IAudioStreamVolume
*asv2
;
1899 hr
= IAudioClient_GetService(ac2
, &IID_IChannelAudioVolume
, (void**)&cav2
);
1900 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
1902 hr
= IAudioClient_GetService(ac2
, &IID_IAudioStreamVolume
, (void**)&asv2
);
1903 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
1905 hr
= IChannelAudioVolume_GetChannelVolume(cav2
, 0, &vol
);
1906 ok(hr
== S_OK
, "CAV_GetChannelVolume failed: %08x\n", hr
);
1907 ok(fabsf(vol
- 0.4f
) < 0.05f
, "CAV_GetChannelVolume gave wrong volume: %f\n", vol
);
1909 hr
= IAudioStreamVolume_GetChannelVolume(asv2
, 0, &vol
);
1910 ok(hr
== S_OK
, "ASV_GetChannelVolume failed: %08x\n", hr
);
1911 ok(vol
== 1.f
, "ASV_GetChannelVolume gave wrong volume: %f\n", vol
);
1913 hr
= IChannelAudioVolume_GetChannelCount(cav2
, &nch
);
1914 ok(hr
== S_OK
, "GetChannelCount failed: %08x\n", hr
);
1915 ok(nch
== fmt
->nChannels
, "Got wrong channel count, expected %u: %u\n", fmt
->nChannels
, nch
);
1917 hr
= IAudioStreamVolume_GetChannelCount(asv2
, &nch
);
1918 ok(hr
== S_OK
, "GetChannelCount failed: %08x\n", hr
);
1919 ok(nch
== fmt
->nChannels
, "Got wrong channel count, expected %u: %u\n", fmt
->nChannels
, nch
);
1921 IAudioStreamVolume_Release(asv2
);
1922 IChannelAudioVolume_Release(cav2
);
1923 IAudioClient_Release(ac2
);
1925 skip("Unable to open the same device twice. Skipping session volume control tests\n");
1927 hr
= IChannelAudioVolume_SetChannelVolume(cav
, 0, 1.f
, NULL
);
1928 ok(hr
== S_OK
, "CAV_SetChannelVolume failed: %08x\n", hr
);
1930 hr
= ISimpleAudioVolume_SetMasterVolume(sav
, 1.f
, NULL
);
1931 ok(hr
== S_OK
, "SAV_SetMasterVolume failed: %08x\n", hr
);
1934 ISimpleAudioVolume_Release(sav
);
1935 IChannelAudioVolume_Release(cav
);
1936 IAudioStreamVolume_Release(asv
);
1937 IAudioClient_Release(ac
);
1940 static void test_session_creation(void)
1944 IAudioSessionManager
*sesm
;
1945 ISimpleAudioVolume
*sav
;
1951 CoCreateGuid(&session_guid
);
1953 hr
= IMMDevice_Activate(dev
, &IID_IAudioSessionManager
,
1954 CLSCTX_INPROC_SERVER
, NULL
, (void**)&sesm
);
1955 ok((hr
== S_OK
)^(sesm
== NULL
), "Activate %08x &out pointer\n", hr
);
1956 ok(hr
== S_OK
, "Activate failed: %08x\n", hr
);
1958 hr
= IAudioSessionManager_GetSimpleAudioVolume(sesm
, &session_guid
,
1960 ok(hr
== S_OK
, "GetSimpleAudioVolume failed: %08x\n", hr
);
1962 hr
= ISimpleAudioVolume_SetMasterVolume(sav
, 0.6f
, NULL
);
1963 ok(hr
== S_OK
, "SetMasterVolume failed: %08x\n", hr
);
1965 /* Release completely to show session persistence */
1966 ISimpleAudioVolume_Release(sav
);
1967 IAudioSessionManager_Release(sesm
);
1969 /* test if we can create a capture audioclient in the session we just
1970 * created from a SessionManager derived from a render device */
1971 hr
= IMMDeviceEnumerator_GetDefaultAudioEndpoint(mme
, eCapture
,
1972 eMultimedia
, &cap_dev
);
1974 WAVEFORMATEX
*cap_pwfx
;
1975 IAudioClient
*cap_ac
;
1976 ISimpleAudioVolume
*cap_sav
;
1977 IAudioSessionManager
*cap_sesm
;
1979 hr
= IMMDevice_Activate(cap_dev
, &IID_IAudioSessionManager
,
1980 CLSCTX_INPROC_SERVER
, NULL
, (void**)&cap_sesm
);
1981 ok((hr
== S_OK
)^(cap_sesm
== NULL
), "Activate %08x &out pointer\n", hr
);
1982 ok(hr
== S_OK
, "Activate failed: %08x\n", hr
);
1984 hr
= IAudioSessionManager_GetSimpleAudioVolume(cap_sesm
, &session_guid
,
1986 ok(hr
== S_OK
, "GetSimpleAudioVolume failed: %08x\n", hr
);
1989 hr
= ISimpleAudioVolume_GetMasterVolume(cap_sav
, &vol
);
1990 ok(hr
== S_OK
, "GetMasterVolume failed: %08x\n", hr
);
1992 ISimpleAudioVolume_Release(cap_sav
);
1993 IAudioSessionManager_Release(cap_sesm
);
1995 hr
= IMMDevice_Activate(cap_dev
, &IID_IAudioClient
,
1996 CLSCTX_INPROC_SERVER
, NULL
, (void**)&cap_ac
);
1997 ok(hr
== S_OK
, "Activate failed: %08x\n", hr
);
1999 IMMDevice_Release(cap_dev
);
2001 hr
= IAudioClient_GetMixFormat(cap_ac
, &cap_pwfx
);
2002 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
2004 hr
= IAudioClient_Initialize(cap_ac
, AUDCLNT_SHAREMODE_SHARED
,
2005 0, 5000000, 0, cap_pwfx
, &session_guid
);
2006 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
2008 CoTaskMemFree(cap_pwfx
);
2011 hr
= IAudioClient_GetService(cap_ac
, &IID_ISimpleAudioVolume
,
2013 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
2017 hr
= ISimpleAudioVolume_GetMasterVolume(cap_sav
, &vol
);
2018 ok(hr
== S_OK
, "GetMasterVolume failed: %08x\n", hr
);
2020 ISimpleAudioVolume_Release(cap_sav
);
2023 IAudioClient_Release(cap_ac
);
2026 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
2028 ok((hr
== S_OK
)^(ac
== NULL
), "Activate %08x &out pointer\n", hr
);
2029 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
2033 hr
= IAudioClient_GetMixFormat(ac
, &fmt
);
2034 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
2036 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
,
2037 AUDCLNT_STREAMFLAGS_NOPERSIST
, 5000000, 0, fmt
, &session_guid
);
2038 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
2040 hr
= IAudioClient_GetService(ac
, &IID_ISimpleAudioVolume
, (void**)&sav
);
2041 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
2044 hr
= ISimpleAudioVolume_GetMasterVolume(sav
, &vol
);
2045 ok(hr
== S_OK
, "GetMasterVolume failed: %08x\n", hr
);
2046 ok(fabs(vol
- 0.6f
) < 0.05f
, "Got wrong volume: %f\n", vol
);
2048 ISimpleAudioVolume_Release(sav
);
2052 IAudioClient_Release(ac
);
2055 static void test_worst_case(void)
2060 IAudioRenderClient
*arc
;
2063 REFERENCE_TIME defp
;
2064 UINT64 freq
, pos
, pcpos0
, pcpos
;
2067 UINT32 pad
, fragment
, sum
;
2070 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
2072 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
2076 hr
= IAudioClient_GetMixFormat(ac
, &pwfx
);
2077 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
2079 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
,
2080 AUDCLNT_STREAMFLAGS_EVENTCALLBACK
, 500000, 0, pwfx
, NULL
);
2081 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
2085 hr
= IAudioClient_GetDevicePeriod(ac
, &defp
, NULL
);
2086 ok(hr
== S_OK
, "GetDevicePeriod failed: %08x\n", hr
);
2088 fragment
= MulDiv(defp
, pwfx
->nSamplesPerSec
, 10000000);
2090 event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2091 ok(event
!= NULL
, "CreateEvent failed\n");
2093 hr
= IAudioClient_SetEventHandle(ac
, event
);
2094 ok(hr
== S_OK
, "SetEventHandle failed: %08x\n", hr
);
2096 hr
= IAudioClient_GetService(ac
, &IID_IAudioRenderClient
, (void**)&arc
);
2097 ok(hr
== S_OK
, "GetService(IAudioRenderClient) failed: %08x\n", hr
);
2099 hr
= IAudioClient_GetService(ac
, &IID_IAudioClock
, (void**)&acl
);
2100 ok(hr
== S_OK
, "GetService(IAudioClock) failed: %08x\n", hr
);
2102 hr
= IAudioClock_GetFrequency(acl
, &freq
);
2103 ok(hr
== S_OK
, "GetFrequency failed: %08x\n", hr
);
2105 for(j
= 0; j
<= (winetest_interactive
? 9 : 2); j
++){
2107 trace("Should play %ums continuous tone with fragment size %u.\n",
2108 (ULONG
)(defp
/100), fragment
);
2110 hr
= IAudioClock_GetPosition(acl
, &pos
, &pcpos0
);
2111 ok(hr
== S_OK
, "GetPosition failed: %08x\n", hr
);
2113 /* XAudio2 prefills one period, play without it */
2114 if(winetest_debug
>2){
2115 hr
= IAudioRenderClient_GetBuffer(arc
, fragment
, &data
);
2116 ok(hr
== S_OK
, "GetBuffer failed: %08x\n", hr
);
2118 hr
= IAudioRenderClient_ReleaseBuffer(arc
, fragment
, AUDCLNT_BUFFERFLAGS_SILENT
);
2119 ok(hr
== S_OK
, "ReleaseBuffer failed: %08x\n", hr
);
2124 hr
= IAudioClient_Start(ac
);
2125 ok(hr
== S_OK
, "Start failed: %08x\n", hr
);
2127 for(i
= 0; i
<= 99; i
++){ /* 100 x 10ms = 1 second */
2128 r
= WaitForSingleObject(event
, 60 + defp
/ 10000);
2129 ok(r
== WAIT_OBJECT_0
, "Wait iteration %d gave %x\n", i
, r
);
2131 /* the app has nearly one period time to feed data */
2132 Sleep((i
% 10) * defp
/ 120000);
2134 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
2135 ok(hr
== S_OK
, "GetCurrentPadding failed: %08x\n", hr
);
2137 /* XAudio2 writes only when there's little data left */
2138 if(pad
<= fragment
){
2139 hr
= IAudioRenderClient_GetBuffer(arc
, fragment
, &data
);
2140 ok(hr
== S_OK
, "GetBuffer failed: %08x\n", hr
);
2142 hr
= IAudioRenderClient_ReleaseBuffer(arc
, fragment
,
2143 wave_generate_tone(pwfx
, data
, fragment
));
2144 ok(hr
== S_OK
, "ReleaseBuffer failed: %08x\n", hr
);
2150 hr
= IAudioClient_Stop(ac
);
2151 ok(hr
== S_OK
, "Stop failed: %08x\n", hr
);
2153 hr
= IAudioClient_GetCurrentPadding(ac
, &pad
);
2154 ok(hr
== S_OK
, "GetCurrentPadding failed: %08x\n", hr
);
2156 hr
= IAudioClock_GetPosition(acl
, &pos
, &pcpos
);
2157 ok(hr
== S_OK
, "GetPosition failed: %08x\n", hr
);
2161 trace("Released %u=%ux%u -%u frames at %u worth %ums in %ums\n",
2162 sum
, sum
/fragment
, fragment
, pad
,
2163 pwfx
->nSamplesPerSec
, MulDiv(sum
-pad
, 1000, pwfx
->nSamplesPerSec
),
2164 (ULONG
)((pcpos
-pcpos0
)/10000));
2166 ok(pos
* pwfx
->nSamplesPerSec
== (sum
-pad
) * freq
,
2167 "Position %u at end vs. %u-%u submitted frames\n", (UINT
)pos
, sum
, pad
);
2169 hr
= IAudioClient_Reset(ac
);
2170 ok(hr
== S_OK
, "Reset failed: %08x\n", hr
);
2175 CoTaskMemFree(pwfx
);
2176 IAudioClient_Release(ac
);
2177 IAudioClock_Release(acl
);
2178 IAudioRenderClient_Release(arc
);
2181 static void test_marshal(void)
2184 IAudioClient
*ac
, *acDest
;
2185 IAudioRenderClient
*rc
, *rcDest
;
2189 /* IAudioRenderClient */
2190 hr
= IMMDevice_Activate(dev
, &IID_IAudioClient
, CLSCTX_INPROC_SERVER
,
2192 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
2196 hr
= IAudioClient_GetMixFormat(ac
, &pwfx
);
2197 ok(hr
== S_OK
, "GetMixFormat failed: %08x\n", hr
);
2199 hr
= IAudioClient_Initialize(ac
, AUDCLNT_SHAREMODE_SHARED
, 0, 5000000,
2201 ok(hr
== S_OK
, "Initialize failed: %08x\n", hr
);
2203 CoTaskMemFree(pwfx
);
2205 hr
= IAudioClient_GetService(ac
, &IID_IAudioRenderClient
, (void**)&rc
);
2206 ok(hr
== S_OK
, "GetService failed: %08x\n", hr
);
2208 IAudioClient_Release(ac
);
2212 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
2213 ok(hr
== S_OK
, "CreateStreamOnHGlobal failed 0x%08x\n", hr
);
2215 /* marshal IAudioClient */
2217 hr
= CoMarshalInterface(pStream
, &IID_IAudioClient
, (IUnknown
*)ac
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
2218 ok(hr
== S_OK
, "CoMarshalInterface IAudioClient failed 0x%08x\n", hr
);
2220 IStream_Seek(pStream
, ullZero
, STREAM_SEEK_SET
, NULL
);
2221 hr
= CoUnmarshalInterface(pStream
, &IID_IAudioClient
, (void **)&acDest
);
2222 ok(hr
== S_OK
, "CoUnmarshalInterface IAudioClient failed 0x%08x\n", hr
);
2224 IAudioClient_Release(acDest
);
2226 IStream_Seek(pStream
, ullZero
, STREAM_SEEK_SET
, NULL
);
2227 /* marshal IAudioRenderClient */
2229 hr
= CoMarshalInterface(pStream
, &IID_IAudioRenderClient
, (IUnknown
*)rc
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
2230 ok(hr
== S_OK
, "CoMarshalInterface IAudioRenderClient failed 0x%08x\n", hr
);
2232 IStream_Seek(pStream
, ullZero
, STREAM_SEEK_SET
, NULL
);
2233 hr
= CoUnmarshalInterface(pStream
, &IID_IAudioRenderClient
, (void **)&rcDest
);
2234 ok(hr
== S_OK
, "CoUnmarshalInterface IAudioRenderClient failed 0x%08x\n", hr
);
2236 IAudioRenderClient_Release(rcDest
);
2239 IStream_Release(pStream
);
2241 IAudioClient_Release(ac
);
2242 IAudioRenderClient_Release(rc
);
2246 static void test_endpointvolume(void)
2249 IAudioEndpointVolume
*aev
;
2250 float mindb
, maxdb
, increment
, volume
;
2253 hr
= IMMDevice_Activate(dev
, &IID_IAudioEndpointVolume
,
2254 CLSCTX_INPROC_SERVER
, NULL
, (void**)&aev
);
2255 ok(hr
== S_OK
, "Activation failed with %08x\n", hr
);
2259 hr
= IAudioEndpointVolume_GetVolumeRange(aev
, &mindb
, NULL
, NULL
);
2260 ok(hr
== E_POINTER
, "GetVolumeRange should have failed with E_POINTER: 0x%08x\n", hr
);
2262 hr
= IAudioEndpointVolume_GetVolumeRange(aev
, &mindb
, &maxdb
, &increment
);
2263 ok(hr
== S_OK
, "GetVolumeRange failed: 0x%08x\n", hr
);
2264 trace("got range: [%f,%f]/%f\n", mindb
, maxdb
, increment
);
2266 hr
= IAudioEndpointVolume_SetMasterVolumeLevel(aev
, mindb
- increment
, NULL
);
2267 ok(hr
== E_INVALIDARG
, "SetMasterVolumeLevel failed: 0x%08x\n", hr
);
2269 hr
= IAudioEndpointVolume_GetMasterVolumeLevel(aev
, &volume
);
2270 ok(hr
== S_OK
, "GetMasterVolumeLevel failed: 0x%08x\n", hr
);
2272 hr
= IAudioEndpointVolume_SetMasterVolumeLevel(aev
, volume
, NULL
);
2273 ok(hr
== S_OK
, "SetMasterVolumeLevel failed: 0x%08x\n", hr
);
2275 hr
= IAudioEndpointVolume_GetMute(aev
, &mute
);
2276 ok(hr
== S_OK
, "GetMute failed: %08x\n", hr
);
2278 hr
= IAudioEndpointVolume_SetMute(aev
, mute
, NULL
);
2279 ok(hr
== S_OK
|| hr
== S_FALSE
, "SetMute failed: %08x\n", hr
);
2281 IAudioEndpointVolume_Release(aev
);
2288 CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
2289 hr
= CoCreateInstance(&CLSID_MMDeviceEnumerator
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IMMDeviceEnumerator
, (void**)&mme
);
2292 skip("mmdevapi not available: 0x%08x\n", hr
);
2296 hr
= IMMDeviceEnumerator_GetDefaultAudioEndpoint(mme
, eRender
, eMultimedia
, &dev
);
2297 ok(hr
== S_OK
|| hr
== E_NOTFOUND
, "GetDefaultAudioEndpoint failed: 0x%08x\n", hr
);
2298 if (hr
!= S_OK
|| !dev
)
2300 if (hr
== E_NOTFOUND
)
2301 skip("No sound card available\n");
2303 skip("GetDefaultAudioEndpoint returns 0x%08x\n", hr
);
2308 test_formats(AUDCLNT_SHAREMODE_EXCLUSIVE
);
2309 test_formats(AUDCLNT_SHAREMODE_SHARED
);
2312 trace("Output to a MS-DOS console is particularly slow and disturbs timing.\n");
2313 trace("Please redirect output to a file.\n");
2319 test_streamvolume();
2320 test_channelvolume();
2321 test_simplevolume();
2322 test_volume_dependence();
2323 test_session_creation();
2325 test_endpointvolume();
2327 IMMDevice_Release(dev
);
2331 IMMDeviceEnumerator_Release(mme
);