2 * Test winmm sound playback in each sound format
4 * Copyright (c) 2002 Francois Gouget
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
39 #include "winmm_test.h"
43 static void test_multiple_waveopens(void)
45 HWAVEOUT handle1
, handle2
;
49 wfx
.wFormatTag
= WAVE_FORMAT_PCM
;
51 wfx
.nSamplesPerSec
= 11025;
53 wfx
.nAvgBytesPerSec
= wfx
.nSamplesPerSec
* wfx
.nBlockAlign
;
54 wfx
.wBitsPerSample
= 8;
57 ret
= waveOutOpen(&handle1
, 0, &wfx
, 0, 0, 0);
58 if (ret
!= MMSYSERR_NOERROR
)
60 skip("Could not do the duplicate waveopen test\n");
64 ret
= waveOutOpen(&handle2
, 0, &wfx
, 0, 0, 0);
65 /* Modern Windows allows for wave-out devices to be opened multiple times.
66 * Some Wine audio drivers allow that and some don't. To avoid false alarms
67 * for those that do, don't "todo_wine ok(...)" on success.
69 if (ret
!= MMSYSERR_NOERROR
)
71 todo_wine
ok(ret
== MMSYSERR_NOERROR
|| broken(ret
== MMSYSERR_ALLOCATED
), /* winME */
72 "second waveOutOpen returns: %x\n", ret
);
75 waveOutClose(handle2
);
77 waveOutClose(handle1
);
81 * Note that in most of this test we may get MMSYSERR_BADDEVICEID errors
82 * at about any time if the user starts another application that uses the
83 * sound device. So we should not report these as test failures.
85 * This test can play a test tone. But this only makes sense if someone
86 * is going to carefully listen to it, and would only bother everyone else.
87 * So this is only done if the test is being run in interactive mode.
90 #define PI 3.14159265358979323846
91 static char* wave_generate_la(WAVEFORMATEX
* wfx
, double duration
, DWORD
* size
)
97 WAVEFORMATEXTENSIBLE
*wfex
= (WAVEFORMATEXTENSIBLE
*)wfx
;
99 nb_samples
=(int)(duration
*wfx
->nSamplesPerSec
);
100 *size
=nb_samples
*wfx
->nBlockAlign
;
101 b
=buf
=HeapAlloc(GetProcessHeap(), 0, *size
);
102 for (i
=0;i
<nb_samples
;i
++) {
103 double y
=sin(440.0*2*PI
*i
/wfx
->nSamplesPerSec
);
104 if (wfx
->wBitsPerSample
==8) {
105 unsigned char sample
=(unsigned char)((double)127.5*(y
+1.0));
106 for (j
= 0; j
< wfx
->nChannels
; j
++)
108 } else if (wfx
->wBitsPerSample
==16) {
109 signed short sample
=(signed short)((double)32767.5*y
-0.5);
110 for (j
= 0; j
< wfx
->nChannels
; j
++) {
115 } else if (wfx
->wBitsPerSample
==24) {
116 signed int sample
=(signed int)(((double)0x7fffff+0.5)*y
-0.5);
117 for (j
= 0; j
< wfx
->nChannels
; j
++) {
119 b
[1]=(sample
>> 8) & 0xff;
120 b
[2]=(sample
>> 16) & 0xff;
123 } else if ((wfx
->wBitsPerSample
==32) && ((wfx
->wFormatTag
== WAVE_FORMAT_PCM
) ||
124 ((wfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
) &&
125 IsEqualGUID(&wfex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
)))) {
126 signed int sample
=(signed int)(((double)0x7fffffff+0.5)*y
-0.5);
127 for (j
= 0; j
< wfx
->nChannels
; j
++) {
129 b
[1]=(sample
>> 8) & 0xff;
130 b
[2]=(sample
>> 16) & 0xff;
131 b
[3]=(sample
>> 24) & 0xff;
134 } else if ((wfx
->wBitsPerSample
==32) && (wfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
) &&
135 IsEqualGUID(&wfex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
)) {
136 union { float f
; char c
[4]; } sample
;
138 for (j
= 0; j
< wfx
->nChannels
; j
++) {
150 static char* wave_generate_silence(WAVEFORMATEX
* wfx
, double duration
, DWORD
* size
)
156 WAVEFORMATEXTENSIBLE
*wfex
= (WAVEFORMATEXTENSIBLE
*)wfx
;
158 nb_samples
=(int)(duration
*wfx
->nSamplesPerSec
);
159 *size
=nb_samples
*wfx
->nBlockAlign
;
160 b
=buf
=HeapAlloc(GetProcessHeap(), 0, *size
);
161 for (i
=0;i
<nb_samples
;i
++) {
162 if (wfx
->wBitsPerSample
==8) {
163 for (j
= 0; j
< wfx
->nChannels
; j
++)
165 } else if (wfx
->wBitsPerSample
==16) {
166 for (j
= 0; j
< wfx
->nChannels
; j
++) {
171 } else if (wfx
->wBitsPerSample
==24) {
172 for (j
= 0; j
< wfx
->nChannels
; j
++) {
178 } else if ((wfx
->wBitsPerSample
==32) && ((wfx
->wFormatTag
== WAVE_FORMAT_PCM
) ||
179 ((wfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
) &&
180 IsEqualGUID(&wfex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
)))) {
181 for (j
= 0; j
< wfx
->nChannels
; j
++) {
188 } else if ((wfx
->wBitsPerSample
==32) && (wfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
) &&
189 IsEqualGUID(&wfex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
)) {
190 union { float f
; char c
[4]; } sample
;
192 for (j
= 0; j
< wfx
->nChannels
; j
++) {
204 const char * dev_name(int device
)
206 static char name
[16];
207 if (device
== WAVE_MAPPER
)
208 return "WAVE_MAPPER";
209 sprintf(name
, "%d", device
);
213 const char* mmsys_error(MMRESULT error
)
215 #define ERR_TO_STR(dev) case dev: return #dev
216 static char unknown
[32];
218 ERR_TO_STR(MMSYSERR_NOERROR
);
219 ERR_TO_STR(MMSYSERR_ERROR
);
220 ERR_TO_STR(MMSYSERR_BADDEVICEID
);
221 ERR_TO_STR(MMSYSERR_NOTENABLED
);
222 ERR_TO_STR(MMSYSERR_ALLOCATED
);
223 ERR_TO_STR(MMSYSERR_INVALHANDLE
);
224 ERR_TO_STR(MMSYSERR_NODRIVER
);
225 ERR_TO_STR(MMSYSERR_NOMEM
);
226 ERR_TO_STR(MMSYSERR_NOTSUPPORTED
);
227 ERR_TO_STR(MMSYSERR_BADERRNUM
);
228 ERR_TO_STR(MMSYSERR_INVALFLAG
);
229 ERR_TO_STR(MMSYSERR_INVALPARAM
);
230 ERR_TO_STR(WAVERR_BADFORMAT
);
231 ERR_TO_STR(WAVERR_STILLPLAYING
);
232 ERR_TO_STR(WAVERR_UNPREPARED
);
233 ERR_TO_STR(WAVERR_SYNC
);
234 ERR_TO_STR(MIDIERR_UNPREPARED
);
235 ERR_TO_STR(MIDIERR_STILLPLAYING
);
236 ERR_TO_STR(MIDIERR_NOTREADY
);
237 ERR_TO_STR(MIDIERR_NODEVICE
);
238 ERR_TO_STR(MIDIERR_INVALIDSETUP
);
239 ERR_TO_STR(TIMERR_NOCANDO
);
240 ERR_TO_STR(TIMERR_STRUCT
);
241 ERR_TO_STR(JOYERR_PARMS
);
242 ERR_TO_STR(JOYERR_NOCANDO
);
243 ERR_TO_STR(JOYERR_UNPLUGGED
);
244 ERR_TO_STR(MIXERR_INVALLINE
);
245 ERR_TO_STR(MIXERR_INVALCONTROL
);
246 ERR_TO_STR(MIXERR_INVALVALUE
);
247 ERR_TO_STR(MMIOERR_FILENOTFOUND
);
248 ERR_TO_STR(MMIOERR_OUTOFMEMORY
);
249 ERR_TO_STR(MMIOERR_CANNOTOPEN
);
250 ERR_TO_STR(MMIOERR_CANNOTCLOSE
);
251 ERR_TO_STR(MMIOERR_CANNOTREAD
);
252 ERR_TO_STR(MMIOERR_CANNOTWRITE
);
253 ERR_TO_STR(MMIOERR_CANNOTSEEK
);
254 ERR_TO_STR(MMIOERR_CANNOTEXPAND
);
255 ERR_TO_STR(MMIOERR_CHUNKNOTFOUND
);
256 ERR_TO_STR(MMIOERR_UNBUFFERED
);
258 sprintf(unknown
, "Unknown(0x%08x)", error
);
263 const char* wave_out_error(MMRESULT error
)
265 static char msg
[1024];
266 static char long_msg
[1100];
269 rc
= waveOutGetErrorTextA(error
, msg
, sizeof(msg
));
270 if (rc
!= MMSYSERR_NOERROR
)
271 sprintf(long_msg
, "waveOutGetErrorTextA(%x) failed with error %x", error
, rc
);
273 sprintf(long_msg
, "%s(%s)", mmsys_error(error
), msg
);
277 const char * wave_open_flags(DWORD flags
)
279 static char msg
[1024];
282 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_EVENT
) {
283 strcat(msg
, "CALLBACK_EVENT");
286 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_FUNCTION
) {
287 if (!first
) strcat(msg
, "|");
288 strcat(msg
, "CALLBACK_FUNCTION");
291 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_NULL
) {
292 if (!first
) strcat(msg
, "|");
293 strcat(msg
, "CALLBACK_NULL");
296 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_THREAD
) {
297 if (!first
) strcat(msg
, "|");
298 strcat(msg
, "CALLBACK_THREAD");
301 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_WINDOW
) {
302 if (!first
) strcat(msg
, "|");
303 strcat(msg
, "CALLBACK_WINDOW");
306 if ((flags
& WAVE_ALLOWSYNC
) == WAVE_ALLOWSYNC
) {
307 if (!first
) strcat(msg
, "|");
308 strcat(msg
, "WAVE_ALLOWSYNC");
311 if ((flags
& WAVE_FORMAT_DIRECT
) == WAVE_FORMAT_DIRECT
) {
312 if (!first
) strcat(msg
, "|");
313 strcat(msg
, "WAVE_FORMAT_DIRECT");
316 if ((flags
& WAVE_FORMAT_QUERY
) == WAVE_FORMAT_QUERY
) {
317 if (!first
) strcat(msg
, "|");
318 strcat(msg
, "WAVE_FORMAT_QUERY");
321 if ((flags
& WAVE_MAPPED
) == WAVE_MAPPED
) {
322 if (!first
) strcat(msg
, "|");
323 strcat(msg
, "WAVE_MAPPED");
328 static const char * wave_header_flags(DWORD flags
)
330 #define WHDR_MASK (WHDR_BEGINLOOP|WHDR_DONE|WHDR_ENDLOOP|WHDR_INQUEUE|WHDR_PREPARED)
331 static char msg
[1024];
334 if (flags
& WHDR_BEGINLOOP
) {
335 strcat(msg
, "WHDR_BEGINLOOP");
338 if (flags
& WHDR_DONE
) {
339 if (!first
) strcat(msg
, " ");
340 strcat(msg
, "WHDR_DONE");
343 if (flags
& WHDR_ENDLOOP
) {
344 if (!first
) strcat(msg
, " ");
345 strcat(msg
, "WHDR_ENDLOOP");
348 if (flags
& WHDR_INQUEUE
) {
349 if (!first
) strcat(msg
, " ");
350 strcat(msg
, "WHDR_INQUEUE");
353 if (flags
& WHDR_PREPARED
) {
354 if (!first
) strcat(msg
, " ");
355 strcat(msg
, "WHDR_PREPARED");
358 if (flags
& ~WHDR_MASK
) {
360 sprintf(temp
, "UNKNOWN(0x%08x)", flags
& ~WHDR_MASK
);
361 if (!first
) strcat(msg
, " ");
367 static const char * wave_out_caps(DWORD dwSupport
)
369 #define ADD_FLAG(f) if (dwSupport & f) strcat(msg, " " #f)
370 static char msg
[256];
373 ADD_FLAG(WAVECAPS_PITCH
);
374 ADD_FLAG(WAVECAPS_PLAYBACKRATE
);
375 ADD_FLAG(WAVECAPS_VOLUME
);
376 ADD_FLAG(WAVECAPS_LRVOLUME
);
377 ADD_FLAG(WAVECAPS_SYNC
);
378 ADD_FLAG(WAVECAPS_SAMPLEACCURATE
);
380 return msg
[0] ? msg
+ 1 : "";
384 const char * wave_time_format(UINT type
)
387 #define TIME_FORMAT(f) case f: return #f
389 TIME_FORMAT(TIME_MS
);
390 TIME_FORMAT(TIME_SAMPLES
);
391 TIME_FORMAT(TIME_BYTES
);
392 TIME_FORMAT(TIME_SMPTE
);
393 TIME_FORMAT(TIME_MIDI
);
394 TIME_FORMAT(TIME_TICKS
);
397 sprintf(msg
, "Unknown(0x%04x)", type
);
401 const char * get_format_str(WORD format
)
404 #define WAVE_FORMAT(f) case f: return #f
406 WAVE_FORMAT(WAVE_FORMAT_PCM
);
407 WAVE_FORMAT(WAVE_FORMAT_ADPCM
);
408 WAVE_FORMAT(WAVE_FORMAT_IBM_CVSD
);
409 WAVE_FORMAT(WAVE_FORMAT_ALAW
);
410 WAVE_FORMAT(WAVE_FORMAT_MULAW
);
411 WAVE_FORMAT(WAVE_FORMAT_OKI_ADPCM
);
412 WAVE_FORMAT(WAVE_FORMAT_IMA_ADPCM
);
413 WAVE_FORMAT(WAVE_FORMAT_MEDIASPACE_ADPCM
);
414 WAVE_FORMAT(WAVE_FORMAT_SIERRA_ADPCM
);
415 WAVE_FORMAT(WAVE_FORMAT_G723_ADPCM
);
416 WAVE_FORMAT(WAVE_FORMAT_DIGISTD
);
417 WAVE_FORMAT(WAVE_FORMAT_DIGIFIX
);
418 WAVE_FORMAT(WAVE_FORMAT_DIALOGIC_OKI_ADPCM
);
419 WAVE_FORMAT(WAVE_FORMAT_YAMAHA_ADPCM
);
420 WAVE_FORMAT(WAVE_FORMAT_SONARC
);
421 WAVE_FORMAT(WAVE_FORMAT_DSPGROUP_TRUESPEECH
);
422 WAVE_FORMAT(WAVE_FORMAT_ECHOSC1
);
423 WAVE_FORMAT(WAVE_FORMAT_AUDIOFILE_AF36
);
424 WAVE_FORMAT(WAVE_FORMAT_APTX
);
425 WAVE_FORMAT(WAVE_FORMAT_AUDIOFILE_AF10
);
426 WAVE_FORMAT(WAVE_FORMAT_DOLBY_AC2
);
427 WAVE_FORMAT(WAVE_FORMAT_GSM610
);
428 WAVE_FORMAT(WAVE_FORMAT_ANTEX_ADPCME
);
429 WAVE_FORMAT(WAVE_FORMAT_CONTROL_RES_VQLPC
);
430 WAVE_FORMAT(WAVE_FORMAT_DIGIREAL
);
431 WAVE_FORMAT(WAVE_FORMAT_DIGIADPCM
);
432 WAVE_FORMAT(WAVE_FORMAT_CONTROL_RES_CR10
);
433 WAVE_FORMAT(WAVE_FORMAT_NMS_VBXADPCM
);
434 WAVE_FORMAT(WAVE_FORMAT_G721_ADPCM
);
435 WAVE_FORMAT(WAVE_FORMAT_MPEG
);
436 WAVE_FORMAT(WAVE_FORMAT_MPEGLAYER3
);
437 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_ADPCM
);
438 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_FASTSPEECH8
);
439 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_FASTSPEECH10
);
440 WAVE_FORMAT(WAVE_FORMAT_FM_TOWNS_SND
);
441 WAVE_FORMAT(WAVE_FORMAT_OLIGSM
);
442 WAVE_FORMAT(WAVE_FORMAT_OLIADPCM
);
443 WAVE_FORMAT(WAVE_FORMAT_OLICELP
);
444 WAVE_FORMAT(WAVE_FORMAT_OLISBC
);
445 WAVE_FORMAT(WAVE_FORMAT_OLIOPR
);
446 WAVE_FORMAT(WAVE_FORMAT_DEVELOPMENT
);
447 WAVE_FORMAT(WAVE_FORMAT_EXTENSIBLE
);
450 sprintf(msg
, "Unknown(0x%04x)", format
);
454 DWORD
bytes_to_samples(DWORD bytes
, LPWAVEFORMATEX pwfx
)
456 return bytes
/ pwfx
->nBlockAlign
;
459 DWORD
bytes_to_ms(DWORD bytes
, LPWAVEFORMATEX pwfx
)
461 return bytes_to_samples(bytes
, pwfx
) * 1000 / pwfx
->nSamplesPerSec
;
464 DWORD
time_to_bytes(LPMMTIME mmtime
, LPWAVEFORMATEX pwfx
)
466 if (mmtime
->wType
== TIME_BYTES
)
468 else if (mmtime
->wType
== TIME_SAMPLES
)
469 return mmtime
->u
.sample
* pwfx
->nBlockAlign
;
470 else if (mmtime
->wType
== TIME_MS
)
471 return mmtime
->u
.ms
* pwfx
->nAvgBytesPerSec
/ 1000;
472 else if (mmtime
->wType
== TIME_SMPTE
)
473 return ((mmtime
->u
.smpte
.hour
* 60 * 60) +
474 (mmtime
->u
.smpte
.min
* 60) +
475 (mmtime
->u
.smpte
.sec
)) * pwfx
->nAvgBytesPerSec
+
476 mmtime
->u
.smpte
.frame
* pwfx
->nAvgBytesPerSec
/ 30;
478 trace("FIXME: time_to_bytes() type not supported\n");
482 static void check_position(int device
, HWAVEOUT wout
, DWORD bytes
,
483 LPWAVEFORMATEX pwfx
)
489 mmtime
.wType
= TIME_BYTES
;
490 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
) - 1);
491 ok(rc
==MMSYSERR_ERROR
,
492 "waveOutGetPosition(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
494 mmtime
.wType
= TIME_BYTES
;
495 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
) + 1);
496 ok(rc
==MMSYSERR_NOERROR
,
497 "waveOutGetPosition(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
498 if (mmtime
.wType
!= TIME_BYTES
&& winetest_debug
> 1)
499 trace("waveOutGetPosition(%s): TIME_BYTES not supported, returned %s\n",
500 dev_name(device
),wave_time_format(mmtime
.wType
));
501 returned
= time_to_bytes(&mmtime
, pwfx
);
502 ok(returned
== bytes
, "waveOutGetPosition(%s): returned %d bytes, "
503 "should be %d\n", dev_name(device
), returned
, bytes
);
505 mmtime
.wType
= TIME_SAMPLES
;
506 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
507 ok(rc
==MMSYSERR_NOERROR
,
508 "waveOutGetPosition(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
509 if (mmtime
.wType
!= TIME_SAMPLES
&& winetest_debug
> 1)
510 trace("waveOutGetPosition(%s): TIME_SAMPLES not supported, "
511 "returned %s\n",dev_name(device
),wave_time_format(mmtime
.wType
));
512 returned
= time_to_bytes(&mmtime
, pwfx
);
513 ok(returned
== bytes
, "waveOutGetPosition(%s): returned %d samples "
514 "(%d bytes), should be %d (%d bytes)\n", dev_name(device
),
515 bytes_to_samples(returned
, pwfx
), returned
,
516 bytes_to_samples(bytes
, pwfx
), bytes
);
518 mmtime
.wType
= TIME_MS
;
519 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
520 ok(rc
==MMSYSERR_NOERROR
,
521 "waveOutGetPosition(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
522 if (mmtime
.wType
!= TIME_MS
&& winetest_debug
> 1)
523 trace("waveOutGetPosition(%s): TIME_MS not supported, returned %s\n",
524 dev_name(device
), wave_time_format(mmtime
.wType
));
525 returned
= time_to_bytes(&mmtime
, pwfx
);
526 ok(returned
== bytes
, "waveOutGetPosition(%s): returned %d ms, "
527 "(%d bytes), should be %d (%d bytes)\n", dev_name(device
),
528 bytes_to_ms(returned
, pwfx
), returned
,
529 bytes_to_ms(bytes
, pwfx
), bytes
);
531 mmtime
.wType
= TIME_SMPTE
;
532 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
533 ok(rc
==MMSYSERR_NOERROR
,
534 "waveOutGetPosition(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
535 if (mmtime
.wType
!= TIME_SMPTE
&& winetest_debug
> 1)
536 trace("waveOutGetPosition(%s): TIME_SMPTE not supported, returned %s\n",
537 dev_name(device
),wave_time_format(mmtime
.wType
));
538 returned
= time_to_bytes(&mmtime
, pwfx
);
539 ok(returned
== bytes
, "waveOutGetPosition(%s): SMPTE test failed\n",
542 mmtime
.wType
= TIME_MIDI
;
543 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
544 ok(rc
==MMSYSERR_NOERROR
,
545 "waveOutGetPosition(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
546 if (mmtime
.wType
!= TIME_MIDI
&& winetest_debug
> 1)
547 trace("waveOutGetPosition(%s): TIME_MIDI not supported, returned %s\n",
548 dev_name(device
),wave_time_format(mmtime
.wType
));
549 returned
= time_to_bytes(&mmtime
, pwfx
);
550 ok(returned
== bytes
, "waveOutGetPosition(%s): MIDI test failed\n",
553 mmtime
.wType
= TIME_TICKS
;
554 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
555 ok(rc
==MMSYSERR_NOERROR
,
556 "waveOutGetPosition(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
557 if (mmtime
.wType
!= TIME_TICKS
&& winetest_debug
> 1)
558 trace("waveOutGetPosition(%s): TIME_TICKS not supported, returned %s\n",
559 dev_name(device
),wave_time_format(mmtime
.wType
));
560 returned
= time_to_bytes(&mmtime
, pwfx
);
561 ok(returned
== bytes
, "waveOutGetPosition(%s): TICKS test failed\n",
565 static void CALLBACK
callback_func(HWAVEOUT hwo
, UINT uMsg
,
566 DWORD_PTR dwInstance
,
567 DWORD dwParam1
, DWORD dwParam2
)
569 if(uMsg
== WOM_OPEN
|| uMsg
== WOM_CLOSE
)
570 ok(GetCurrentThreadId() == g_tid
, "Got different thread ID\n");
571 SetEvent((HANDLE
)dwInstance
);
574 static DWORD WINAPI
callback_thread(LPVOID lpParameter
)
578 PeekMessageW( &msg
, 0, 0, 0, PM_NOREMOVE
); /* make sure the thread has a message queue */
579 SetEvent(lpParameter
);
581 while (GetMessageA(&msg
, 0, 0, 0)) {
582 UINT message
= msg
.message
;
583 /* for some reason XP sends a WM_USER message before WOM_OPEN */
584 ok (message
== WOM_OPEN
|| message
== WOM_DONE
||
585 message
== WOM_CLOSE
|| message
== WM_USER
|| message
== WM_APP
,
586 "GetMessageA returned unexpected message: %u\n", message
);
587 if (message
== WOM_OPEN
|| message
== WOM_DONE
|| message
== WOM_CLOSE
)
588 SetEvent(lpParameter
);
589 else if (message
== WM_APP
) {
590 SetEvent(lpParameter
);
598 static void wave_out_test_deviceOut(int device
, double duration
, int headers
, int loops
,
599 WAVEFORMATEX
*pwfx
, DWORD format
, DWORD flags
, WAVEOUTCAPSA
*pcaps
, BOOL interactive
,
600 BOOL sine
, BOOL pause
)
603 HANDLE hevent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
607 WORD nChannels
= pwfx
->nChannels
;
608 WORD wBitsPerSample
= pwfx
->wBitsPerSample
;
609 DWORD nSamplesPerSec
= pwfx
->nSamplesPerSec
;
610 BOOL has_volume
= (pcaps
->dwSupport
& WAVECAPS_VOLUME
) != 0;
612 DWORD_PTR callback
= 0;
613 DWORD_PTR callback_instance
= 0;
621 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_EVENT
) {
622 callback
= (DWORD_PTR
)hevent
;
623 callback_instance
= 0;
624 } else if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_FUNCTION
) {
625 callback
= (DWORD_PTR
)callback_func
;
626 callback_instance
= (DWORD_PTR
)hevent
;
627 } else if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_THREAD
) {
628 thread
= CreateThread(NULL
, 0, callback_thread
, hevent
, 0, &thread_id
);
630 /* make sure thread is running */
631 WaitForSingleObject(hevent
,10000);
632 callback
= thread_id
;
633 callback_instance
= 0;
635 trace("CreateThread() failed\n");
639 } else if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_WINDOW
) {
640 trace("CALLBACK_THREAD not implemented\n");
643 } else if (flags
& CALLBACK_TYPEMASK
) {
644 trace("Undefined callback type!\n");
648 trace("CALLBACK_NULL not implemented\n");
653 g_tid
= GetCurrentThreadId();
654 rc
=waveOutOpen(&wout
,device
,pwfx
,callback
,callback_instance
,flags
);
655 /* Note: Win9x doesn't know WAVE_FORMAT_DIRECT */
656 /* It is acceptable to fail on formats that are not specified to work */
657 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_BADDEVICEID
||
658 rc
==MMSYSERR_NOTENABLED
|| rc
==MMSYSERR_NODRIVER
||
659 rc
==MMSYSERR_ALLOCATED
||
660 ((rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_NOTSUPPORTED
) &&
661 (flags
& WAVE_FORMAT_DIRECT
) && !(pcaps
->dwFormats
& format
)) ||
662 ((rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_NOTSUPPORTED
) &&
663 (!(flags
& WAVE_FORMAT_DIRECT
) || (flags
& WAVE_MAPPED
)) &&
664 !(pcaps
->dwFormats
& format
)) ||
665 (rc
==MMSYSERR_INVALFLAG
&& (flags
& WAVE_FORMAT_DIRECT
)),
666 "waveOutOpen(%s): format=%dx%2dx%d flags=%x(%s) rc=%s\n",
667 dev_name(device
),pwfx
->nSamplesPerSec
,pwfx
->wBitsPerSample
,
668 pwfx
->nChannels
,CALLBACK_EVENT
|flags
,
669 wave_open_flags(CALLBACK_EVENT
|flags
),wave_out_error(rc
));
670 if ((rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_NOTSUPPORTED
) &&
671 (flags
& WAVE_FORMAT_DIRECT
) && (pcaps
->dwFormats
& format
))
672 trace(" Reason: The device lists this format as supported in its "
673 "capabilities but opening it failed.\n");
674 if ((rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_NOTSUPPORTED
) &&
675 !(pcaps
->dwFormats
& format
))
676 trace("waveOutOpen(%s): format=%dx%2dx%d %s rc=%s failed but format "
677 "not supported so OK.\n", dev_name(device
), pwfx
->nSamplesPerSec
,
678 pwfx
->wBitsPerSample
,pwfx
->nChannels
,
679 flags
& WAVE_FORMAT_DIRECT
? "flags=WAVE_FORMAT_DIRECT" :
680 flags
& WAVE_MAPPED
? "flags=WAVE_MAPPED" : "", mmsys_error(rc
));
681 if (rc
!=MMSYSERR_NOERROR
)
684 rc
=WaitForSingleObject(hevent
,9000);
685 ok(rc
==WAIT_OBJECT_0
, "missing WOM_OPEN notification\n");
687 ok(pwfx
->nChannels
==nChannels
&&
688 pwfx
->wBitsPerSample
==wBitsPerSample
&&
689 pwfx
->nSamplesPerSec
==nSamplesPerSec
,
690 "got the wrong format: %dx%2dx%d instead of %dx%2dx%d\n",
691 pwfx
->nSamplesPerSec
, pwfx
->wBitsPerSample
,
692 pwfx
->nChannels
, nSamplesPerSec
, wBitsPerSample
, nChannels
);
694 frags
= HeapAlloc(GetProcessHeap(), 0, headers
* sizeof(WAVEHDR
));
697 buffer
=wave_generate_la(pwfx
,duration
/ (loops
+ 1),&length
);
699 buffer
=wave_generate_silence(pwfx
,duration
/ (loops
+ 1),&length
);
701 rc
=waveOutGetVolume(wout
,0);
702 ok(rc
==MMSYSERR_INVALPARAM
,"waveOutGetVolume(%s,0) expected "
703 "MMSYSERR_INVALPARAM, got %s\n", dev_name(device
),wave_out_error(rc
));
704 rc
=waveOutGetVolume(wout
,&volume
);
705 if (rc
== MMSYSERR_NOTSUPPORTED
) has_volume
= FALSE
;
706 ok(has_volume
? rc
==MMSYSERR_NOERROR
: rc
==MMSYSERR_NOTSUPPORTED
,
707 "waveOutGetVolume(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
709 /* make sure fragment length is a multiple of block size */
710 frag_length
= ((length
/ headers
) / pwfx
->nBlockAlign
) * pwfx
->nBlockAlign
;
712 for (i
= 0; i
< headers
; i
++) {
713 frags
[i
].lpData
=buffer
+ (i
* frag_length
);
714 if (i
!= (headers
-1))
715 frags
[i
].dwBufferLength
=frag_length
;
717 /* use remainder of buffer for last fragment */
718 frags
[i
].dwBufferLength
=length
- (i
* frag_length
);
722 rc
=waveOutPrepareHeader(wout
, &frags
[i
], sizeof(frags
[0]));
723 ok(rc
==MMSYSERR_NOERROR
,
724 "waveOutPrepareHeader(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
727 if (interactive
&& rc
==MMSYSERR_NOERROR
) {
728 trace("Playing %g second %s at %5dx%2dx%d %2d header%s %d loop%s %d bytes %s %s\n",duration
,
729 sine
? "440 Hz tone" : "silence", pwfx
->nSamplesPerSec
,
730 pwfx
->wBitsPerSample
,pwfx
->nChannels
, headers
, headers
> 1 ? "s": " ",
731 loops
, loops
== 1 ? " " : "s", length
* (loops
+ 1),
732 get_format_str(pwfx
->wFormatTag
),
733 wave_open_flags(flags
));
734 if (sine
&& has_volume
&& volume
== 0)
735 trace("*** Warning the sound is muted, you will not hear the test\n");
737 /* Check that the position is 0 at start */
738 check_position(device
, wout
, 0, pwfx
);
740 rc
=waveOutSetVolume(wout
,0x20002000);
741 ok(has_volume
? rc
==MMSYSERR_NOERROR
: rc
==MMSYSERR_NOTSUPPORTED
,
742 "waveOutSetVolume(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
744 rc
=waveOutSetVolume(wout
,volume
);
745 ok(has_volume
? rc
==MMSYSERR_NOERROR
: rc
==MMSYSERR_NOTSUPPORTED
,
746 "waveOutSetVolume(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
748 rc
=waveOutWrite(wout
, &frags
[0], sizeof(frags
[0]));
749 ok(rc
==MMSYSERR_NOERROR
,"waveOutWrite(%s): rc=%s\n",
750 dev_name(device
),wave_out_error(rc
));
752 ok(frags
[0].dwFlags
==(WHDR_PREPARED
|WHDR_INQUEUE
),
753 "WHDR_INQUEUE WHDR_PREPARED expected, got= %s\n",
754 wave_header_flags(frags
[0].dwFlags
));
756 rc
=waveOutWrite(wout
, &frags
[0], sizeof(frags
[0]));
757 ok(rc
==WAVERR_STILLPLAYING
,
758 "waveOutWrite(%s): WAVE_STILLPLAYING expected, got %s\n",
759 dev_name(device
),wave_out_error(rc
));
761 ok(frags
[0].dwFlags
==(WHDR_PREPARED
|WHDR_INQUEUE
),
762 "WHDR_INQUEUE WHDR_PREPARED expected, got %s\n",
763 wave_header_flags(frags
[0].dwFlags
));
765 if (headers
== 1 && loops
== 0 && pause
) {
766 paused
= duration
/ 2;
767 Sleep(paused
* 1000);
768 rc
=waveOutPause(wout
);
769 ok(rc
==MMSYSERR_NOERROR
,"waveOutPause(%s): rc=%s\n",
770 dev_name(device
),wave_out_error(rc
));
771 trace("pausing for %g seconds\n", paused
);
772 Sleep(paused
* 1000);
773 rc
=waveOutRestart(wout
);
774 ok(rc
==MMSYSERR_NOERROR
,"waveOutRestart(%s): rc=%s\n",
775 dev_name(device
),wave_out_error(rc
));
778 for (j
= 0; j
<= loops
; j
++) {
779 for (i
= 0; i
< headers
; i
++) {
780 /* don't do last one */
781 if (!((j
== loops
) && (i
== (headers
- 1)))) {
783 frags
[(i
+1) % headers
].dwFlags
= WHDR_PREPARED
;
784 rc
=waveOutWrite(wout
, &frags
[(i
+1) % headers
], sizeof(frags
[0]));
785 ok(rc
==MMSYSERR_NOERROR
,"waveOutWrite(%s, header[%d]): rc=%s\n",
786 dev_name(device
),(i
+1)%headers
,wave_out_error(rc
));
788 rc
=WaitForSingleObject(hevent
,8000);
789 ok(rc
==WAIT_OBJECT_0
, "missing WOM_DONE notification\n");
793 for (i
= 0; i
< headers
; i
++) {
794 ok(frags
[i
].dwFlags
==(WHDR_DONE
|WHDR_PREPARED
) ||
795 broken((flags
& CALLBACK_TYPEMASK
)==CALLBACK_EVENT
&&
796 frags
[i
].dwFlags
==(WHDR_DONE
|WHDR_PREPARED
|0x1000)), /* < NT4 */
797 "(%02d) WHDR_DONE WHDR_PREPARED expected, got %s\n",
798 i
, wave_header_flags(frags
[i
].dwFlags
));
800 check_position(device
, wout
, length
* (loops
+ 1), pwfx
);
803 for (i
= 0; i
< headers
; i
++) {
804 rc
=waveOutUnprepareHeader(wout
, &frags
[i
], sizeof(frags
[0]));
805 ok(rc
==MMSYSERR_NOERROR
,
806 "waveOutUnprepareHeader(%s): rc=%s\n",dev_name(device
),
810 ok(frags
[0].dwFlags
==(interactive
? WHDR_DONE
: 0), "dwFlags(%d)=%x\n",device
,frags
[0].dwFlags
);
812 frags
[0].dwFlags
|= WHDR_DONE
;
813 rc
=waveOutUnprepareHeader(wout
, &frags
[0], sizeof(frags
[0]));
814 ok(rc
==MMSYSERR_NOERROR
, "waveOutUnprepareHeader(%d): rc=%s\n",device
,wave_out_error(rc
));
815 ok(frags
[0].dwFlags
==WHDR_DONE
, "dwFlags(%d)=%x\n",device
,frags
[0].dwFlags
);
817 frags
[0].dwFlags
|= WHDR_INQUEUE
;
818 rc
=waveOutPrepareHeader(wout
, &frags
[0], sizeof(frags
[0]));
819 ok(rc
==MMSYSERR_NOERROR
, "waveOutPrepareHeader(%d): rc=%s\n",device
,wave_out_error(rc
));
820 ok(frags
[0].dwFlags
==WHDR_PREPARED
, "dwFlags(%d)=%x\n",device
,frags
[0].dwFlags
);
822 frags
[0].dwFlags
|= WHDR_INQUEUE
;
823 rc
=waveOutPrepareHeader(wout
, &frags
[0], sizeof(frags
[0]));
824 ok(rc
==MMSYSERR_NOERROR
, "waveOutPrepareHeader(%d): rc=%s\n",device
,wave_out_error(rc
));
825 ok(frags
[0].dwFlags
==(WHDR_PREPARED
|WHDR_INQUEUE
), "dwFlags(%d)=%x\n",device
,frags
[0].dwFlags
);
827 frags
[0].dwFlags
&= ~(WHDR_INQUEUE
|WHDR_DONE
);
828 rc
=waveOutUnprepareHeader(wout
, &frags
[0], sizeof(frags
[0]));
829 ok(rc
==MMSYSERR_NOERROR
, "waveOutUnprepareHeader(%d): rc=%s\n",device
,wave_out_error(rc
));
830 ok(frags
[0].dwFlags
==0, "dwFlags(%d)=%x\n",device
,frags
[0].dwFlags
);
832 rc
=waveOutClose(wout
);
833 ok(rc
==MMSYSERR_NOERROR
,"waveOutClose(%s): rc=%s\n",dev_name(device
),
835 if (rc
==WAVERR_STILLPLAYING
) {
836 /* waveOutReset ought to return all buffers s.t. waveOutClose succeeds */
837 rc
=waveOutReset(wout
);
838 ok(rc
==MMSYSERR_NOERROR
,"waveOutReset(%s): rc=%s\n",dev_name(device
),
841 for (i
= 0; i
< headers
; i
++) {
842 rc
=waveOutUnprepareHeader(wout
, &frags
[i
], sizeof(frags
[0]));
843 ok(rc
==MMSYSERR_NOERROR
,
844 "waveOutUnprepareHeader(%s): rc=%s\n",dev_name(device
),
847 rc
=waveOutClose(wout
);
848 ok(rc
==MMSYSERR_NOERROR
,"waveOutClose(%s): rc=%s\n",dev_name(device
),
851 rc
=WaitForSingleObject(hevent
,1500);
852 ok(rc
==WAIT_OBJECT_0
, "missing WOM_CLOSE notification\n");
854 wout
= (HWAVEOUT
)0xdeadf00d;
855 rc
=waveOutOpen(&wout
,device
,pwfx
,callback
,callback_instance
,flags
|WAVE_FORMAT_QUERY
);
856 ok(rc
==MMSYSERR_NOERROR
, "WAVE_FORMAT_QUERY(%s): rc=%s\n",dev_name(device
),
858 ok(wout
==(HWAVEOUT
)0xdeadf00d, "WAVE_FORMAT_QUERY handle %p\n", wout
);
860 rc
=WaitForSingleObject(hevent
,20);
861 ok(rc
==WAIT_TIMEOUT
, "Notification from %s rc=%x\n",
862 wave_open_flags(flags
|WAVE_FORMAT_QUERY
),rc
);
864 HeapFree(GetProcessHeap(), 0, buffer
);
866 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_THREAD
) {
867 PostThreadMessageW(thread_id
, WM_APP
, 0, 0);
868 WaitForSingleObject(hevent
,10000);
871 HeapFree(GetProcessHeap(), 0, frags
);
874 static void wave_out_test_device(UINT_PTR device
)
879 WAVEFORMATEXTENSIBLE wfex
;
880 IMAADPCMWAVEFORMAT wfa
;
889 SYSTEM_INFO sSysInfo
;
893 GetSystemInfo(&sSysInfo
);
894 dwPageSize
= sSysInfo
.dwPageSize
;
896 rc
=waveOutGetDevCapsA(device
,&capsA
,sizeof(capsA
));
897 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_BADDEVICEID
||
898 rc
==MMSYSERR_NODRIVER
,
899 "waveOutGetDevCapsA(%s): failed to get capabilities: rc=%s\n",
900 dev_name(device
),wave_out_error(rc
));
901 if (rc
==MMSYSERR_BADDEVICEID
|| rc
==MMSYSERR_NODRIVER
)
904 rc
=waveOutGetDevCapsW(device
,&capsW
,sizeof(capsW
));
905 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_NOTSUPPORTED
,
906 "waveOutGetDevCapsW(%s): MMSYSERR_NOERROR or MMSYSERR_NOTSUPPORTED "
907 "expected, got %s\n",dev_name(device
),wave_out_error(rc
));
909 rc
=waveOutGetDevCapsA(device
,0,sizeof(capsA
));
910 ok(rc
==MMSYSERR_INVALPARAM
,
911 "waveOutGetDevCapsA(%s): MMSYSERR_INVALPARAM expected, "
912 "got %s\n",dev_name(device
),wave_out_error(rc
));
914 rc
=waveOutGetDevCapsW(device
,0,sizeof(capsW
));
915 ok(rc
==MMSYSERR_INVALPARAM
|| rc
==MMSYSERR_NOTSUPPORTED
,
916 "waveOutGetDevCapsW(%s): MMSYSERR_INVALPARAM or MMSYSERR_NOTSUPPORTED "
917 "expected, got %s\n",dev_name(device
),wave_out_error(rc
));
921 /* FIXME: this works on windows but crashes wine */
922 rc
=waveOutGetDevCapsA(device
,(LPWAVEOUTCAPSA
)1,sizeof(capsA
));
923 ok(rc
==MMSYSERR_INVALPARAM
,
924 "waveOutGetDevCapsA(%s): MMSYSERR_INVALPARAM expected, got %s\n",
925 dev_name(device
),wave_out_error(rc
));
927 rc
=waveOutGetDevCapsW(device
,(LPWAVEOUTCAPSW
)1,sizeof(capsW
));
928 ok(rc
==MMSYSERR_INVALPARAM
|| rc
==MMSYSERR_NOTSUPPORTED
,
929 "waveOutGetDevCapsW(%s): MMSYSERR_INVALPARAM or MMSYSERR_NOTSUPPORTED "
930 "expected, got %s\n",dev_name(device
),wave_out_error(rc
));
933 rc
=waveOutGetDevCapsA(device
,&capsA
,4);
934 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_INVALPARAM
,
935 "waveOutGetDevCapsA(%s): MMSYSERR_NOERROR or MMSYSERR_INVALPARAM "
936 "expected, got %s\n", dev_name(device
),wave_out_error(rc
));
938 rc
=waveOutGetDevCapsW(device
,&capsW
,4);
939 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_NOTSUPPORTED
||
940 rc
==MMSYSERR_INVALPARAM
, /* Vista, W2K8 */
941 "waveOutGetDevCapsW(%s): unexpected return value %s\n",
942 dev_name(device
),wave_out_error(rc
));
944 rc
=waveOutMessage((HWAVEOUT
)device
, DRV_QUERYMAPPABLE
, 0, 0);
945 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_NOTSUPPORTED
,
946 "DRV_QUERYMAPPABLE(%s): unexpected return value %s\n",
947 dev_name(device
),wave_out_error(rc
));
950 rc
=waveOutMessage((HWAVEOUT
)device
, DRV_QUERYDEVICEINTERFACESIZE
,
951 (DWORD_PTR
)&size
, 0);
952 ok(rc
==MMSYSERR_NOERROR
|| broken(rc
==MMSYSERR_INVALPARAM
||
953 rc
==MMSYSERR_NOTSUPPORTED
),
954 "waveOutMessage(%s): failed to get interface size, rc=%s\n",
955 dev_name(device
),wave_out_error(rc
));
956 if (rc
==MMSYSERR_NOERROR
) {
957 nameW
= HeapAlloc(GetProcessHeap(), 0, size
);
958 rc
=waveOutMessage((HWAVEOUT
)device
, DRV_QUERYDEVICEINTERFACE
,
959 (DWORD_PTR
)nameW
, size
);
960 ok(rc
==MMSYSERR_NOERROR
,"waveOutMessage(%s): failed to get interface "
961 "name, rc=%s\n",dev_name(device
),wave_out_error(rc
));
962 ok(lstrlenW(nameW
)+1==size
/sizeof(WCHAR
),"got an incorrect size %d\n",size
);
963 if (rc
==MMSYSERR_NOERROR
) {
964 nameA
= HeapAlloc(GetProcessHeap(), 0, size
/sizeof(WCHAR
));
965 WideCharToMultiByte(CP_ACP
, 0, nameW
, size
/sizeof(WCHAR
), nameA
,
966 size
/sizeof(WCHAR
), NULL
, NULL
);
968 HeapFree(GetProcessHeap(), 0, nameW
);
970 else if (rc
==MMSYSERR_NOTSUPPORTED
) {
971 nameA
=HeapAlloc(GetProcessHeap(), 0, sizeof("not supported"));
972 strcpy(nameA
, "not supported");
975 rc
=waveOutGetDevCapsA(device
,&capsA
,sizeof(capsA
));
976 ok(rc
==MMSYSERR_NOERROR
,
977 "waveOutGetDevCapsA(%s): MMSYSERR_NOERROR expected, got %s\n",
978 dev_name(device
),wave_out_error(rc
));
979 if (rc
!=MMSYSERR_NOERROR
)
982 trace(" %s: \"%s\" (%s) %d.%d (%d:%d)\n",dev_name(device
),capsA
.szPname
,
983 (nameA
?nameA
:"failed"),capsA
.vDriverVersion
>> 8,
984 capsA
.vDriverVersion
& 0xff, capsA
.wMid
,capsA
.wPid
);
985 trace(" channels=%d formats=%05x support=%04x\n",
986 capsA
.wChannels
,capsA
.dwFormats
,capsA
.dwSupport
);
987 trace(" %s\n",wave_out_caps(capsA
.dwSupport
));
988 HeapFree(GetProcessHeap(), 0, nameA
);
990 if (winetest_interactive
&& (device
!= WAVE_MAPPER
))
992 trace("Playing a 5 seconds reference tone.\n");
993 trace("All subsequent tones should be identical to this one.\n");
994 trace("Listen for stutter, changes in pitch, volume, etc.\n");
995 format
.wFormatTag
=WAVE_FORMAT_PCM
;
997 format
.wBitsPerSample
=8;
998 format
.nSamplesPerSec
=22050;
999 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
1000 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
1003 wave_out_test_deviceOut(device
,5.0,1,0,&format
,WAVE_FORMAT_2M08
,
1004 CALLBACK_EVENT
,&capsA
,TRUE
,TRUE
,FALSE
);
1005 wave_out_test_deviceOut(device
,5.0,1,0,&format
,WAVE_FORMAT_2M08
,
1006 CALLBACK_FUNCTION
,&capsA
,TRUE
,TRUE
,FALSE
);
1007 wave_out_test_deviceOut(device
,5.0,1,0,&format
,WAVE_FORMAT_2M08
,
1008 CALLBACK_THREAD
,&capsA
,TRUE
,TRUE
,FALSE
);
1010 wave_out_test_deviceOut(device
,5.0,10,0,&format
,WAVE_FORMAT_2M08
,
1011 CALLBACK_EVENT
,&capsA
,TRUE
,TRUE
,FALSE
);
1012 wave_out_test_deviceOut(device
,5.0,5,1,&format
,WAVE_FORMAT_2M08
,
1013 CALLBACK_EVENT
,&capsA
,TRUE
,TRUE
,FALSE
);
1015 format
.wFormatTag
=WAVE_FORMAT_PCM
;
1017 format
.wBitsPerSample
=8;
1018 format
.nSamplesPerSec
=22050;
1019 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
1020 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
1022 wave_out_test_deviceOut(device
,0.6,1,0,&format
,WAVE_FORMAT_2M08
,
1023 CALLBACK_EVENT
,&capsA
,TRUE
,FALSE
,FALSE
);
1024 wave_out_test_deviceOut(device
,0.6,1,0,&format
,WAVE_FORMAT_2M08
,
1025 CALLBACK_EVENT
,&capsA
,TRUE
,FALSE
,TRUE
);
1026 wave_out_test_deviceOut(device
,0.6,1,0,&format
,WAVE_FORMAT_2M08
,
1027 CALLBACK_FUNCTION
,&capsA
,TRUE
,FALSE
,FALSE
);
1028 wave_out_test_deviceOut(device
,0.6,1,0,&format
,WAVE_FORMAT_2M08
,
1029 CALLBACK_FUNCTION
,&capsA
,TRUE
,FALSE
,TRUE
);
1030 wave_out_test_deviceOut(device
,0.6,1,0,&format
,WAVE_FORMAT_2M08
,
1031 CALLBACK_THREAD
,&capsA
,TRUE
,FALSE
,FALSE
);
1032 wave_out_test_deviceOut(device
,0.6,1,0,&format
,WAVE_FORMAT_2M08
,
1033 CALLBACK_THREAD
,&capsA
,TRUE
,FALSE
,TRUE
);
1035 wave_out_test_deviceOut(device
,0.8,10,0,&format
,WAVE_FORMAT_2M08
,
1036 CALLBACK_EVENT
,&capsA
,TRUE
,FALSE
,FALSE
);
1037 wave_out_test_deviceOut(device
,1.0,5,1,&format
,WAVE_FORMAT_2M08
,
1038 CALLBACK_EVENT
,&capsA
,TRUE
,FALSE
,FALSE
);
1041 for (f
=0;f
<NB_WIN_FORMATS
;f
++) {
1042 format
.wFormatTag
=WAVE_FORMAT_PCM
;
1043 format
.nChannels
=win_formats
[f
][3];
1044 format
.wBitsPerSample
=win_formats
[f
][2];
1045 format
.nSamplesPerSec
=win_formats
[f
][1];
1046 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
1047 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
1049 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1050 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1052 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1053 CALLBACK_FUNCTION
,&capsA
,winetest_interactive
,
1055 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1056 CALLBACK_THREAD
,&capsA
,winetest_interactive
,
1059 wave_out_test_deviceOut(device
,1.0,10,0,&format
,win_formats
[f
][0],
1060 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1062 wave_out_test_deviceOut(device
,1.0,5,1,&format
,win_formats
[f
][0],
1063 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1066 if (winetest_interactive
) {
1067 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1068 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1070 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1071 CALLBACK_FUNCTION
,&capsA
,winetest_interactive
,
1073 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1074 CALLBACK_THREAD
,&capsA
,winetest_interactive
,
1077 wave_out_test_deviceOut(device
,1.0,10,0,&format
,win_formats
[f
][0],
1078 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1080 wave_out_test_deviceOut(device
,1.0,5,1,&format
,win_formats
[f
][0],
1081 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1084 if (device
!= WAVE_MAPPER
)
1086 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1087 CALLBACK_EVENT
|WAVE_FORMAT_DIRECT
,&capsA
,
1088 winetest_interactive
,TRUE
,FALSE
);
1089 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1090 CALLBACK_EVENT
|WAVE_MAPPED
,&capsA
,
1091 winetest_interactive
,TRUE
,FALSE
);
1092 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1093 CALLBACK_FUNCTION
|WAVE_FORMAT_DIRECT
,&capsA
,
1094 winetest_interactive
,TRUE
,FALSE
);
1095 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1096 CALLBACK_FUNCTION
|WAVE_MAPPED
,&capsA
,
1097 winetest_interactive
,TRUE
,FALSE
);
1098 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1099 CALLBACK_THREAD
|WAVE_FORMAT_DIRECT
,&capsA
,
1100 winetest_interactive
,TRUE
,FALSE
);
1101 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1102 CALLBACK_THREAD
|WAVE_MAPPED
,&capsA
,
1103 winetest_interactive
,TRUE
,FALSE
);
1105 wave_out_test_deviceOut(device
,1.0,10,0,&format
,win_formats
[f
][0],
1106 CALLBACK_EVENT
|WAVE_FORMAT_DIRECT
,&capsA
,
1107 winetest_interactive
,TRUE
,FALSE
);
1108 wave_out_test_deviceOut(device
,1.0,5,1,&format
,win_formats
[f
][0],
1109 CALLBACK_EVENT
|WAVE_FORMAT_DIRECT
,&capsA
,
1110 winetest_interactive
,TRUE
,FALSE
);
1114 /* Try a PCMWAVEFORMAT aligned next to an unaccessible page for bounds
1116 twoPages
= VirtualAlloc(NULL
, 2 * dwPageSize
, MEM_RESERVE
| MEM_COMMIT
,
1118 ok(twoPages
!=NULL
,"Failed to allocate 2 pages of memory\n");
1120 res
= VirtualProtect(twoPages
+ dwPageSize
, dwPageSize
, PAGE_NOACCESS
,
1122 ok(res
, "Failed to set memory access on second page\n");
1124 LPWAVEFORMATEX pwfx
= (LPWAVEFORMATEX
)(twoPages
+ dwPageSize
-
1125 sizeof(PCMWAVEFORMAT
));
1126 pwfx
->wFormatTag
=WAVE_FORMAT_PCM
;
1128 pwfx
->wBitsPerSample
=8;
1129 pwfx
->nSamplesPerSec
=22050;
1130 pwfx
->nBlockAlign
=pwfx
->nChannels
*pwfx
->wBitsPerSample
/8;
1131 pwfx
->nAvgBytesPerSec
=pwfx
->nSamplesPerSec
*pwfx
->nBlockAlign
;
1132 wave_out_test_deviceOut(device
,1.0,1,0,pwfx
,WAVE_FORMAT_2M08
,
1133 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1135 wave_out_test_deviceOut(device
,1.0,10,0,pwfx
,WAVE_FORMAT_2M08
,
1136 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1138 wave_out_test_deviceOut(device
,1.0,5,1,pwfx
,WAVE_FORMAT_2M08
,
1139 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1141 if (device
!= WAVE_MAPPER
)
1143 wave_out_test_deviceOut(device
,1.0,1,0,pwfx
,WAVE_FORMAT_2M08
,
1144 CALLBACK_EVENT
|WAVE_FORMAT_DIRECT
,
1145 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1146 wave_out_test_deviceOut(device
,1.0,1,0,pwfx
,WAVE_FORMAT_2M08
,
1147 CALLBACK_EVENT
|WAVE_MAPPED
,&capsA
,
1148 winetest_interactive
,TRUE
,FALSE
);
1149 wave_out_test_deviceOut(device
,1.0,10,0,pwfx
,WAVE_FORMAT_2M08
,
1150 CALLBACK_EVENT
|WAVE_FORMAT_DIRECT
,
1151 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1152 wave_out_test_deviceOut(device
,1.0,10,0,pwfx
,WAVE_FORMAT_2M08
,
1153 CALLBACK_EVENT
|WAVE_MAPPED
,&capsA
,
1154 winetest_interactive
,TRUE
,FALSE
);
1155 wave_out_test_deviceOut(device
,1.0,5,1,pwfx
,WAVE_FORMAT_2M08
,
1156 CALLBACK_EVENT
|WAVE_FORMAT_DIRECT
,
1157 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1158 wave_out_test_deviceOut(device
,1.0,5,1,pwfx
,WAVE_FORMAT_2M08
,
1159 CALLBACK_EVENT
|WAVE_MAPPED
,&capsA
,
1160 winetest_interactive
,TRUE
,FALSE
);
1163 VirtualFree(twoPages
, 0, MEM_RELEASE
);
1166 /* try some non PCM formats */
1167 format
.wFormatTag
=WAVE_FORMAT_MULAW
;
1169 format
.wBitsPerSample
=8;
1170 format
.nSamplesPerSec
=8000;
1171 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
1172 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
1174 rc
=waveOutOpen(&wout
,device
,&format
,0,0,CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1175 ok(rc
==MMSYSERR_NOERROR
||rc
==WAVERR_BADFORMAT
||
1176 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1177 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1178 if (rc
==MMSYSERR_NOERROR
) {
1180 wave_out_test_deviceOut(device
,1.0,1,0,&format
,0,CALLBACK_EVENT
,
1181 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1182 wave_out_test_deviceOut(device
,1.0,10,0,&format
,0,CALLBACK_EVENT
,
1183 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1184 wave_out_test_deviceOut(device
,1.0,5,1,&format
,0,CALLBACK_EVENT
,
1185 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1189 trace("waveOutOpen(%s): WAVE_FORMAT_MULAW not supported\n",
1192 query_rc
= waveOutOpen(NULL
, device
, &format
, 0, 0, CALLBACK_NULL
| WAVE_FORMAT_QUERY
);
1193 ok(query_rc
==MMSYSERR_NOERROR
|| query_rc
==WAVERR_BADFORMAT
|| query_rc
==MMSYSERR_INVALPARAM
,
1194 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1196 rc
= waveOutOpen(&wout
, device
, &format
, 0, 0, CALLBACK_NULL
);
1198 "waveOutOpen(%s): returned different from query: %s\n",dev_name(device
),wave_out_error(rc
));
1199 if(rc
== MMSYSERR_NOERROR
)
1203 wfa
.wfx
.wFormatTag
=WAVE_FORMAT_IMA_ADPCM
;
1204 wfa
.wfx
.nChannels
=1;
1205 wfa
.wfx
.nSamplesPerSec
=11025;
1206 wfa
.wfx
.nAvgBytesPerSec
=5588;
1207 wfa
.wfx
.nBlockAlign
=256;
1208 wfa
.wfx
.wBitsPerSample
=4; /* see imaadp32.c */
1210 wfa
.wSamplesPerBlock
=505;
1211 rc
=waveOutOpen(&wout
,device
,&wfa
.wfx
,0,0,CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1212 ok(rc
==MMSYSERR_NOERROR
||rc
==WAVERR_BADFORMAT
||
1213 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1214 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1215 if (rc
==MMSYSERR_NOERROR
) {
1217 /* TODO: teach wave_generate_* ADPCM
1218 wave_out_test_deviceOut(device,1.0,1,0,&wfa.wfx,0,CALLBACK_EVENT,
1219 &capsA,winetest_interactive,TRUE,FALSE);
1220 wave_out_test_deviceOut(device,1.0,10,0,&wfa.wfx,0,CALLBACK_EVENT,
1221 &capsA,winetest_interactive,TRUE,FALSE);
1222 wave_out_test_deviceOut(device,1.0,5,1,&wfa.wfx,0,CALLBACK_EVENT,
1223 &capsA,winetest_interactive,TRUE,FALSE);
1226 trace("waveOutOpen(%s): WAVE_FORMAT_IMA_ADPCM not supported\n",
1229 /* test if WAVEFORMATEXTENSIBLE supported */
1230 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
1231 wfex
.Format
.nChannels
=2;
1232 wfex
.Format
.wBitsPerSample
=16;
1233 wfex
.Format
.nSamplesPerSec
=22050;
1234 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
1235 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
1236 wfex
.Format
.nBlockAlign
;
1237 wfex
.Format
.cbSize
=22;
1238 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
1239 wfex
.dwChannelMask
=SPEAKER_ALL
;
1240 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_PCM
;
1241 rc
=waveOutOpen(&wout
,device
,&wfex
.Format
,0,0,
1242 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1243 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
1244 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1245 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1246 if (rc
==MMSYSERR_NOERROR
) {
1248 wave_out_test_deviceOut(device
,1.0,1,0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1249 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1251 wave_out_test_deviceOut(device
,1.0,10,0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1252 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1254 wave_out_test_deviceOut(device
,1.0,5,1,&wfex
.Format
,WAVE_FORMAT_2M16
,
1255 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1258 trace("waveOutOpen(%s): WAVE_FORMAT_EXTENSIBLE not supported\n",
1261 /* test if 4 channels supported */
1262 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
1263 wfex
.Format
.nChannels
=4;
1264 wfex
.Format
.wBitsPerSample
=16;
1265 wfex
.Format
.nSamplesPerSec
=22050;
1266 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
1267 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
1268 wfex
.Format
.nBlockAlign
;
1269 wfex
.Format
.cbSize
=22;
1270 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
1271 wfex
.dwChannelMask
=SPEAKER_ALL
;
1272 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_PCM
;
1273 rc
=waveOutOpen(&wout
,device
,&wfex
.Format
,0,0,
1274 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1275 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
1276 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1277 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1278 if (rc
==MMSYSERR_NOERROR
) {
1280 wave_out_test_deviceOut(device
,1.0,1,0,&wfex
.Format
,0,CALLBACK_EVENT
,
1281 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1282 wave_out_test_deviceOut(device
,1.0,10,0,&wfex
.Format
,0,CALLBACK_EVENT
,
1283 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1284 wave_out_test_deviceOut(device
,1.0,5,1,&wfex
.Format
,0,CALLBACK_EVENT
,
1285 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1287 trace("waveOutOpen(%s): 4 channels not supported\n",
1290 /* test if 6 channels supported */
1291 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
1292 wfex
.Format
.nChannels
=6;
1293 wfex
.Format
.wBitsPerSample
=16;
1294 wfex
.Format
.nSamplesPerSec
=22050;
1295 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
1296 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
1297 wfex
.Format
.nBlockAlign
;
1298 wfex
.Format
.cbSize
=22;
1299 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
1300 wfex
.dwChannelMask
=SPEAKER_ALL
;
1301 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_PCM
;
1302 rc
=waveOutOpen(&wout
,device
,&wfex
.Format
,0,0,
1303 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1304 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
1305 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1306 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1307 if (rc
==MMSYSERR_NOERROR
) {
1309 wave_out_test_deviceOut(device
,1.0,1,0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1310 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1312 wave_out_test_deviceOut(device
,1.0,10,0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1313 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1315 wave_out_test_deviceOut(device
,1.0,5,1,&wfex
.Format
,WAVE_FORMAT_2M16
,
1316 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1319 trace("waveOutOpen(%s): 6 channels not supported\n",
1324 /* FIXME: ALSA doesn't like this format */
1325 /* test if 24 bit samples supported */
1326 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
1327 wfex
.Format
.nChannels
=2;
1328 wfex
.Format
.wBitsPerSample
=24;
1329 wfex
.Format
.nSamplesPerSec
=22050;
1330 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
1331 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
1332 wfex
.Format
.nBlockAlign
;
1333 wfex
.Format
.cbSize
=22;
1334 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
1335 wfex
.dwChannelMask
=SPEAKER_ALL
;
1336 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_PCM
;
1337 rc
=waveOutOpen(&wout
,device
,&wfex
.Format
,0,0,
1338 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1339 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
1340 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1341 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1342 if (rc
==MMSYSERR_NOERROR
) {
1344 wave_out_test_deviceOut(device
,1.0,1,0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1345 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1348 trace("waveOutOpen(%s): 24 bit samples not supported\n",
1352 /* test if 32 bit samples supported */
1353 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
1354 wfex
.Format
.nChannels
=2;
1355 wfex
.Format
.wBitsPerSample
=32;
1356 wfex
.Format
.nSamplesPerSec
=22050;
1357 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
1358 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
1359 wfex
.Format
.nBlockAlign
;
1360 wfex
.Format
.cbSize
=22;
1361 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
1362 wfex
.dwChannelMask
=SPEAKER_ALL
;
1363 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_PCM
;
1364 rc
=waveOutOpen(&wout
,device
,&wfex
.Format
,0,0,
1365 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1366 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
1367 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1368 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1369 if (rc
==MMSYSERR_NOERROR
) {
1371 wave_out_test_deviceOut(device
,1.0,1,0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1372 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1374 wave_out_test_deviceOut(device
,1.0,10,0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1375 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1377 wave_out_test_deviceOut(device
,1.0,5,1,&wfex
.Format
,WAVE_FORMAT_2M16
,
1378 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1381 trace("waveOutOpen(%s): 32 bit samples not supported\n",
1384 /* test if 32 bit float samples supported */
1385 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
1386 wfex
.Format
.nChannels
=2;
1387 wfex
.Format
.wBitsPerSample
=32;
1388 wfex
.Format
.nSamplesPerSec
=22050;
1389 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
1390 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
1391 wfex
.Format
.nBlockAlign
;
1392 wfex
.Format
.cbSize
=22;
1393 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
1394 wfex
.dwChannelMask
=SPEAKER_ALL
;
1395 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
;
1396 rc
=waveOutOpen(&wout
,device
,&wfex
.Format
,0,0,
1397 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1398 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
1399 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1400 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1401 if (rc
==MMSYSERR_NOERROR
) {
1403 wave_out_test_deviceOut(device
,1.0,1,0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1404 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1406 wave_out_test_deviceOut(device
,1.0,10,0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1407 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1409 wave_out_test_deviceOut(device
,1.0,5,1,&wfex
.Format
,WAVE_FORMAT_2M16
,
1410 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1413 trace("waveOutOpen(%s): 32 bit float samples not supported\n",
1417 static void wave_out_tests(void)
1421 WAVEFORMATEX format
;
1424 DWORD preferred
, status
;
1427 ndev
=waveOutGetNumDevs();
1428 trace("found %d WaveOut devices\n",ndev
);
1430 rc
= waveOutMessage((HWAVEOUT
)WAVE_MAPPER
, DRVM_MAPPER_PREFERRED_GET
,
1431 (DWORD_PTR
)&preferred
, (DWORD_PTR
)&status
);
1432 ok((ndev
== 0 && (rc
== MMSYSERR_NODRIVER
|| rc
== MMSYSERR_BADDEVICEID
)) ||
1433 rc
== MMSYSERR_NOTSUPPORTED
||
1434 rc
== MMSYSERR_NOERROR
, "waveOutMessage(DRVM_MAPPER_PREFERRED_GET) failed: %u\n", rc
);
1436 if(rc
!= MMSYSERR_NOTSUPPORTED
)
1437 ok((ndev
== 0 && (preferred
== -1 || broken(preferred
!= -1))) ||
1438 preferred
< ndev
, "Got invalid preferred device: 0x%x\n", preferred
);
1440 rc
=waveOutGetDevCapsA(ndev
+1,&capsA
,sizeof(capsA
));
1441 ok(rc
==MMSYSERR_BADDEVICEID
,
1442 "waveOutGetDevCapsA(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
1443 dev_name(ndev
+1),mmsys_error(rc
));
1445 rc
=waveOutGetDevCapsW(ndev
+1,&capsW
,sizeof(capsW
));
1446 ok(rc
==MMSYSERR_BADDEVICEID
|| rc
==MMSYSERR_NOTSUPPORTED
,
1447 "waveOutGetDevCapsW(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NOTSUPPORTED "
1448 "expected, got %s\n",dev_name(ndev
+1),mmsys_error(rc
));
1450 rc
=waveOutGetDevCapsA(WAVE_MAPPER
,&capsA
,sizeof(capsA
));
1452 ok(rc
==MMSYSERR_NOERROR
,
1453 "waveOutGetDevCapsA(%s): MMSYSERR_NOERROR expected, got %s\n",
1454 dev_name(WAVE_MAPPER
),mmsys_error(rc
));
1456 ok(rc
==MMSYSERR_BADDEVICEID
|| rc
==MMSYSERR_NODRIVER
,
1457 "waveOutGetDevCapsA(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NODRIVER "
1458 "expected, got %s\n",dev_name(WAVE_MAPPER
),mmsys_error(rc
));
1460 rc
=waveOutGetDevCapsW(WAVE_MAPPER
,&capsW
,sizeof(capsW
));
1462 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_NOTSUPPORTED
,
1463 "waveOutGetDevCapsW(%s): MMSYSERR_NOERROR or MMSYSERR_NOTSUPPORTED "
1464 "expected, got %s\n",dev_name(WAVE_MAPPER
),mmsys_error(rc
));
1466 ok(rc
==MMSYSERR_BADDEVICEID
|| rc
==MMSYSERR_NODRIVER
||
1467 rc
==MMSYSERR_NOTSUPPORTED
,
1468 "waveOutGetDevCapsW(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NODRIVER "
1469 " or MMSYSERR_NOTSUPPORTED expected, got %s\n",
1470 dev_name(WAVE_MAPPER
),mmsys_error(rc
));
1472 format
.wFormatTag
=WAVE_FORMAT_PCM
;
1474 format
.wBitsPerSample
=16;
1475 format
.nSamplesPerSec
=44100;
1476 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
1477 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
1479 rc
=waveOutOpen(&wout
,ndev
+1,&format
,0,0,CALLBACK_NULL
);
1480 ok(rc
==MMSYSERR_BADDEVICEID
,
1481 "waveOutOpen(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
1482 dev_name(ndev
+1),mmsys_error(rc
));
1484 if(winetest_interactive
)
1485 for (d
=0;d
<ndev
;d
++)
1486 wave_out_test_device(d
);
1489 wave_out_test_device(WAVE_MAPPER
);
1492 static void test_sndPlaySound(void)
1496 static const WCHAR not_existW
[] = {'C',':','\\','n','o','t','_','e','x','i','s','t','.','w','a','v',0};
1497 static const WCHAR SystemAsteriskW
[] = {'S','y','s','t','e','m','A','s','t','e','r','i','s','k',0};
1499 br
= sndPlaySoundA((LPCSTR
)SND_ALIAS_SYSTEMASTERISK
, SND_ALIAS_ID
|SND_SYNC
);
1500 ok(br
== TRUE
|| br
== FALSE
, "sndPlaySound gave strange return: %u\n", br
);
1502 br
= sndPlaySoundW((LPCWSTR
)SND_ALIAS_SYSTEMASTERISK
, SND_ALIAS_ID
|SND_SYNC
);
1503 ok(br
== TRUE
|| br
== FALSE
, "sndPlaySound gave strange return: %u\n", br
);
1505 br
= sndPlaySoundA((LPCSTR
)sndAlias('X','Y'), SND_ALIAS_ID
|SND_SYNC
);
1506 ok(br
== TRUE
|| br
== FALSE
, "sndPlaySound gave strange return: %u\n", br
);
1508 br
= sndPlaySoundW((LPCWSTR
)sndAlias('X','Y'), SND_ALIAS_ID
|SND_SYNC
);
1509 ok(br
== TRUE
|| br
== FALSE
, "sndPlaySound gave strange return: %u\n", br
);
1511 br
= sndPlaySoundA("SystemAsterisk", SND_ALIAS
|SND_SYNC
);
1512 ok(br
== TRUE
|| br
== FALSE
, "sndPlaySound gave strange return: %u\n", br
);
1514 br
= sndPlaySoundW(SystemAsteriskW
, SND_ALIAS
|SND_SYNC
);
1515 ok(br
== TRUE
|| br
== FALSE
, "sndPlaySound gave strange return: %u\n", br
);
1517 br
= sndPlaySoundA("C:\not_exist.wav", SND_FILENAME
|SND_SYNC
);
1518 ok(br
== TRUE
|| br
== FALSE
, "sndPlaySound gave strange return: %u\n", br
);
1520 br
= sndPlaySoundW(not_existW
, SND_FILENAME
|SND_SYNC
);
1521 ok(br
== TRUE
|| br
== FALSE
, "sndPlaySound gave strange return: %u\n", br
);
1524 static void test_fragmentsize(void)
1534 if(waveOutGetNumDevs() == 0)
1537 fmt
.wFormatTag
= WAVE_FORMAT_PCM
;
1539 fmt
.nSamplesPerSec
= 44100;
1540 fmt
.wBitsPerSample
= 16;
1541 fmt
.nBlockAlign
= fmt
.nChannels
* fmt
.wBitsPerSample
/ 8;
1542 fmt
.nAvgBytesPerSec
= fmt
.nBlockAlign
* fmt
.nSamplesPerSec
;
1543 fmt
.cbSize
= sizeof(WAVEFORMATEX
);
1545 hevent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1546 g_tid
= GetCurrentThreadId();
1548 rc
= waveOutOpen(&wout
, WAVE_MAPPER
, &fmt
, (DWORD_PTR
)callback_func
,
1549 (DWORD_PTR
)hevent
, CALLBACK_FUNCTION
);
1550 ok(rc
== MMSYSERR_NOERROR
|| rc
== WAVERR_BADFORMAT
||
1551 rc
== MMSYSERR_INVALFLAG
|| rc
== MMSYSERR_INVALPARAM
,
1552 "waveOutOpen(%s) failed: %s\n", dev_name(WAVE_MAPPER
), wave_out_error(rc
));
1553 if(rc
!= MMSYSERR_NOERROR
){
1554 CloseHandle(hevent
);
1558 wait
= WaitForSingleObject(hevent
, 1000);
1559 ok(wait
== WAIT_OBJECT_0
, "wave open callback missed\n");
1561 memset(hdr
, 0, sizeof(hdr
));
1562 hdr
[0].dwBufferLength
= (fmt
.nSamplesPerSec
* fmt
.nBlockAlign
/ 4) + 1;
1563 hdr
[1].dwBufferLength
= hdr
[0].dwBufferLength
- 2;
1564 hdr
[1].lpData
= hdr
[0].lpData
=
1565 HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, hdr
[0].dwBufferLength
);
1567 rc
= waveOutPrepareHeader(wout
, &hdr
[0], sizeof(hdr
[0]));
1568 ok(rc
== MMSYSERR_NOERROR
, "waveOutPrepareHeader failed: %s\n", wave_out_error(rc
));
1570 rc
= waveOutPrepareHeader(wout
, &hdr
[1], sizeof(hdr
[1]));
1571 ok(rc
== MMSYSERR_NOERROR
, "waveOutPrepareHeader failed: %s\n", wave_out_error(rc
));
1573 trace("writing %u bytes then %u bytes\n", hdr
[0].dwBufferLength
, hdr
[1].dwBufferLength
);
1574 rc
= waveOutWrite(wout
, &hdr
[0], sizeof(hdr
[0]));
1575 ok(rc
== MMSYSERR_NOERROR
, "waveOutWrite failed: %s\n", wave_out_error(rc
));
1577 rc
= waveOutWrite(wout
, &hdr
[1], sizeof(hdr
[1]));
1578 ok(rc
== MMSYSERR_NOERROR
, "waveOutWrite failed: %s\n", wave_out_error(rc
));
1580 wait
= WaitForSingleObject(hevent
, 1000);
1581 ok(wait
== WAIT_OBJECT_0
, "header 1 callback missed\n");
1583 wait
= WaitForSingleObject(hevent
, 1000);
1584 ok(wait
== WAIT_OBJECT_0
, "header 2 callback missed\n");
1586 memset(&mmtime
, 0, sizeof(mmtime
));
1587 mmtime
.wType
= TIME_BYTES
;
1589 rc
= waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
1590 ok(rc
== MMSYSERR_NOERROR
, "waveOutGetPosition failed: %s\n", wave_out_error(rc
));
1592 /* windows behavior is inconsistent */
1593 ok(mmtime
.u
.cb
== 88200 ||
1594 mmtime
.u
.cb
== 88196, "after position: %u\n", mmtime
.u
.cb
);
1596 rc
= waveOutClose(wout
);
1597 ok(rc
== MMSYSERR_NOERROR
, "waveOutClose failed: %s\n", wave_out_error(rc
));
1599 HeapFree(GetProcessHeap(), 0, hdr
[0].lpData
);
1600 CloseHandle(hevent
);
1603 static void create_wav_file(char *temp_file
)
1605 WAVEFORMATEX format
;
1607 MMCKINFO riff_chunk
, chunk
;
1613 format
.wFormatTag
=WAVE_FORMAT_PCM
;
1616 format
.wBitsPerSample
=8;
1617 format
.nSamplesPerSec
=8000;
1618 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
1619 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
1621 h
= mmioOpenA(temp_file
, NULL
, MMIO_ALLOCBUF
| MMIO_WRITE
| MMIO_CREATE
);
1622 ok(h
!= NULL
, "Can't open temp_file\n");
1624 riff_chunk
.fccType
= mmioFOURCC('W','A','V','E');
1625 riff_chunk
.cksize
= 0;
1626 rc
= mmioCreateChunk(h
, &riff_chunk
, MMIO_CREATERIFF
);
1627 ok(rc
== MMSYSERR_NOERROR
, "mmioCreateChunk failed, got %u\n", rc
);
1629 chunk
.ckid
= mmioFOURCC('f','m','t',' ');
1631 rc
= mmioCreateChunk(h
, &chunk
, 0);
1632 ok(rc
== MMSYSERR_NOERROR
, "mmioCreateChunk failed, got %u\n", rc
);
1633 written
= mmioWrite(h
, (char*)&format
, sizeof(format
));
1634 ok(written
== sizeof(format
), "mmioWrite failed, got %d\n", written
);
1635 rc
= mmioAscend(h
, &chunk
, 0);
1636 ok(rc
== MMSYSERR_NOERROR
, "mmioAscend failed, got %d\n", rc
);
1638 chunk
.ckid
= mmioFOURCC('d','a','t','a');
1639 rc
= mmioCreateChunk(h
, &chunk
, 0);
1640 ok(rc
== MMSYSERR_NOERROR
, "mmioCreateChunk failed, got %u\n", rc
);
1641 buffer
= wave_generate_silence(&format
, .1, &length
);
1642 written
= mmioWrite(h
, buffer
, length
);
1643 ok(written
== length
, "mmioWrite failed, got %d\n", written
);
1644 rc
= mmioAscend(h
, &chunk
, 0);
1645 ok(rc
== MMSYSERR_NOERROR
, "mmioAscend failed, got %d\n", rc
);
1646 HeapFree(GetProcessHeap(), 0, buffer
);
1648 rc
= mmioAscend(h
, &riff_chunk
, 0);
1649 ok(rc
== MMSYSERR_NOERROR
, "mmioAscend failed, got %d\n", rc
);
1651 rc
= mmioClose(h
, 0);
1652 ok(rc
== MMSYSERR_NOERROR
, "mmioClose failed, got %u\n", rc
);
1655 static void test_PlaySound(void)
1658 char test_file
[MAX_PATH
], temp
[MAX_PATH
], *exts
;
1659 void *psound_ordinal
, *psound_name
;
1660 HMODULE dll
= GetModuleHandleA("winmm.dll");
1662 psound_name
= GetProcAddress(dll
, "PlaySound");
1663 psound_ordinal
= GetProcAddress(dll
, (LPCSTR
) 2);
1664 ok(psound_name
== psound_ordinal
, "Expected ordinal 2 to be PlaySound function\n");
1666 if(waveOutGetNumDevs() == 0) {
1667 skip("No output devices available\n");
1671 GetTempPathA(sizeof(test_file
), test_file
);
1672 strcat(test_file
, "mysound.wav");
1673 create_wav_file(test_file
);
1675 br
= PlaySoundA(test_file
, NULL
, SND_FILENAME
| SND_NODEFAULT
);
1676 ok(br
, "PlaySound failed, got %d\n", br
);
1678 /* SND_ALIAS fallbacks to SND_FILENAME */
1679 br
= PlaySoundA(test_file
, NULL
, SND_ALIAS
| SND_NODEFAULT
);
1680 ok(br
, "PlaySound failed, got %d\n", br
);
1682 strcpy(temp
, test_file
);
1683 exts
= strrchr(temp
, '.');
1687 br
= PlaySoundA(temp
, NULL
, SND_FILENAME
| SND_NODEFAULT
);
1688 ok(br
, "PlaySound failed, got %d\n", br
);
1690 /* ends with a dot */
1692 br
= PlaySoundA(temp
, NULL
, SND_FILENAME
| SND_NODEFAULT
);
1693 ok(!br
|| broken(br
), "PlaySound succeeded, got %d\n", br
);
1695 DeleteFileA(test_file
);
1700 test_multiple_waveopens();
1702 test_sndPlaySound();
1703 test_fragmentsize();