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)(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)(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 ok(mmtime
.wType
== TIME_BYTES
, "(waveOutGetPosition(%s): returned %s\n",
499 dev_name(device
), wave_time_format(mmtime
.wType
));
500 returned
= time_to_bytes(&mmtime
, pwfx
);
501 ok(returned
== bytes
, "waveOutGetPosition(%s): returned %d bytes, "
502 "should be %d\n", dev_name(device
), returned
, bytes
);
504 mmtime
.wType
= TIME_SAMPLES
;
505 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
506 ok(rc
==MMSYSERR_NOERROR
,
507 "waveOutGetPosition(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
508 ok(mmtime
.wType
== TIME_SAMPLES
, "(waveOutGetPosition(%s): returned %s\n",
509 dev_name(device
), wave_time_format(mmtime
.wType
));
510 returned
= time_to_bytes(&mmtime
, pwfx
);
511 ok(returned
== bytes
, "waveOutGetPosition(%s): returned %d samples "
512 "(%d bytes), should be %d (%d bytes)\n", dev_name(device
),
513 bytes_to_samples(returned
, pwfx
), returned
,
514 bytes_to_samples(bytes
, pwfx
), bytes
);
516 mmtime
.wType
= TIME_MS
;
517 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
518 ok(rc
==MMSYSERR_NOERROR
,
519 "waveOutGetPosition(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
520 ok(mmtime
.wType
== TIME_BYTES
, "(waveOutGetPosition(%s): returned %s\n",
521 dev_name(device
), wave_time_format(mmtime
.wType
));
522 returned
= time_to_bytes(&mmtime
, pwfx
);
523 ok(returned
== bytes
, "waveOutGetPosition(%s): TIME_MS test failed\n",
526 mmtime
.wType
= TIME_SMPTE
;
527 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
528 ok(rc
==MMSYSERR_NOERROR
,
529 "waveOutGetPosition(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
530 todo_wine
ok(mmtime
.wType
== TIME_BYTES
, "(waveOutGetPosition(%s): returned %s\n",
531 dev_name(device
), wave_time_format(mmtime
.wType
));
532 returned
= time_to_bytes(&mmtime
, pwfx
);
533 ok(returned
== bytes
, "waveOutGetPosition(%s): SMPTE test failed\n",
536 mmtime
.wType
= TIME_MIDI
;
537 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
538 ok(rc
==MMSYSERR_NOERROR
,
539 "waveOutGetPosition(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
540 ok(mmtime
.wType
== TIME_BYTES
, "(waveOutGetPosition(%s): returned %s\n",
541 dev_name(device
), wave_time_format(mmtime
.wType
));
542 returned
= time_to_bytes(&mmtime
, pwfx
);
543 ok(returned
== bytes
, "waveOutGetPosition(%s): MIDI test failed\n",
546 mmtime
.wType
= TIME_TICKS
;
547 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
548 ok(rc
==MMSYSERR_NOERROR
,
549 "waveOutGetPosition(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
550 ok(mmtime
.wType
== TIME_BYTES
, "(waveOutGetPosition(%s): returned %s\n",
551 dev_name(device
), wave_time_format(mmtime
.wType
));
552 returned
= time_to_bytes(&mmtime
, pwfx
);
553 ok(returned
== bytes
, "waveOutGetPosition(%s): TICKS test failed\n",
557 static void CALLBACK
callback_func(HWAVEOUT hwo
, UINT uMsg
,
558 DWORD_PTR dwInstance
,
559 DWORD dwParam1
, DWORD dwParam2
)
561 if(uMsg
== WOM_OPEN
|| uMsg
== WOM_CLOSE
)
562 ok(GetCurrentThreadId() == g_tid
, "Got different thread ID\n");
563 SetEvent((HANDLE
)dwInstance
);
566 static DWORD WINAPI
callback_thread(LPVOID lpParameter
)
570 PeekMessageW( &msg
, 0, 0, 0, PM_NOREMOVE
); /* make sure the thread has a message queue */
571 SetEvent(lpParameter
);
573 while (GetMessageA(&msg
, 0, 0, 0)) {
574 UINT message
= msg
.message
;
575 /* for some reason XP sends a WM_USER message before WOM_OPEN */
576 ok (message
== WOM_OPEN
|| message
== WOM_DONE
||
577 message
== WOM_CLOSE
|| message
== WM_USER
|| message
== WM_APP
,
578 "GetMessageA returned unexpected message: %u\n", message
);
579 if (message
== WOM_OPEN
|| message
== WOM_DONE
|| message
== WOM_CLOSE
)
580 SetEvent(lpParameter
);
581 else if (message
== WM_APP
) {
582 SetEvent(lpParameter
);
590 static void wave_out_test_deviceOut(int device
, double duration
, int headers
, int loops
,
591 WAVEFORMATEX
*pwfx
, DWORD format
, DWORD flags
, WAVEOUTCAPSA
*pcaps
, BOOL interactive
,
592 BOOL sine
, BOOL pause
)
594 HWAVEOUT wout
, wout2
;
595 HANDLE hevent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
600 WORD nChannels
= pwfx
->nChannels
;
601 WORD wBitsPerSample
= pwfx
->wBitsPerSample
;
602 DWORD nSamplesPerSec
= pwfx
->nSamplesPerSec
;
603 BOOL has_volume
= (pcaps
->dwSupport
& WAVECAPS_VOLUME
) != 0;
605 DWORD_PTR callback
= 0;
606 DWORD_PTR callback_instance
= 0;
614 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_EVENT
) {
615 callback
= (DWORD_PTR
)hevent
;
616 callback_instance
= 0;
617 } else if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_FUNCTION
) {
618 callback
= (DWORD_PTR
)callback_func
;
619 callback_instance
= (DWORD_PTR
)hevent
;
620 } else if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_THREAD
) {
621 thread
= CreateThread(NULL
, 0, callback_thread
, hevent
, 0, &thread_id
);
623 /* make sure thread is running */
624 WaitForSingleObject(hevent
,10000);
625 callback
= thread_id
;
626 callback_instance
= 0;
628 trace("CreateThread() failed\n");
632 } else if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_WINDOW
) {
633 trace("CALLBACK_THREAD not implemented\n");
636 } else if (flags
& CALLBACK_TYPEMASK
) {
637 trace("Undefined callback type!\n");
641 trace("CALLBACK_NULL not implemented\n");
646 g_tid
= GetCurrentThreadId();
647 rc
=waveOutOpen(&wout
,device
,pwfx
,callback
,callback_instance
,flags
);
648 /* Note: Win9x doesn't know WAVE_FORMAT_DIRECT */
649 /* It is acceptable to fail on formats that are not specified to work */
650 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_BADDEVICEID
||
651 rc
==MMSYSERR_NOTENABLED
|| rc
==MMSYSERR_NODRIVER
||
652 rc
==MMSYSERR_ALLOCATED
||
653 ((rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_NOTSUPPORTED
) &&
654 (flags
& WAVE_FORMAT_DIRECT
) && !(pcaps
->dwFormats
& format
)) ||
655 ((rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_NOTSUPPORTED
) &&
656 (!(flags
& WAVE_FORMAT_DIRECT
) || (flags
& WAVE_MAPPED
)) &&
657 !(pcaps
->dwFormats
& format
)) ||
658 (rc
==MMSYSERR_INVALFLAG
&& (flags
& WAVE_FORMAT_DIRECT
)),
659 "waveOutOpen(%s): format=%dx%2dx%d flags=%x(%s) rc=%s\n",
660 dev_name(device
),pwfx
->nSamplesPerSec
,pwfx
->wBitsPerSample
,
661 pwfx
->nChannels
,flags
,wave_open_flags(flags
),wave_out_error(rc
));
662 if ((rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_NOTSUPPORTED
) &&
663 (flags
& WAVE_FORMAT_DIRECT
) && (pcaps
->dwFormats
& format
))
664 trace(" Reason: The device lists this format as supported in its "
665 "capabilities but opening it failed.\n");
666 if ((rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_NOTSUPPORTED
) &&
667 !(pcaps
->dwFormats
& format
))
668 trace("waveOutOpen(%s): format=%dx%2dx%d %s rc=%s failed but format "
669 "not supported so OK.\n", dev_name(device
), pwfx
->nSamplesPerSec
,
670 pwfx
->wBitsPerSample
,pwfx
->nChannels
,
671 flags
& WAVE_FORMAT_DIRECT
? "flags=WAVE_FORMAT_DIRECT" :
672 flags
& WAVE_MAPPED
? "flags=WAVE_MAPPED" : "", mmsys_error(rc
));
673 if (rc
!=MMSYSERR_NOERROR
)
676 rc
=WaitForSingleObject(hevent
,9000);
677 ok(rc
==WAIT_OBJECT_0
, "missing WOM_OPEN notification\n");
679 ok(pwfx
->nChannels
==nChannels
&&
680 pwfx
->wBitsPerSample
==wBitsPerSample
&&
681 pwfx
->nSamplesPerSec
==nSamplesPerSec
,
682 "got the wrong format: %dx%2dx%d instead of %dx%2dx%d\n",
683 pwfx
->nSamplesPerSec
, pwfx
->wBitsPerSample
,
684 pwfx
->nChannels
, nSamplesPerSec
, wBitsPerSample
, nChannels
);
686 frags
= HeapAlloc(GetProcessHeap(), 0, headers
* sizeof(WAVEHDR
));
689 buffer
=wave_generate_la(pwfx
,duration
/ (loops
+ 1),&length
);
691 buffer
=wave_generate_silence(pwfx
,duration
/ (loops
+ 1),&length
);
693 rc
=waveOutGetVolume(wout
,0);
694 ok(rc
==MMSYSERR_INVALPARAM
,"waveOutGetVolume(%s,0) expected "
695 "MMSYSERR_INVALPARAM, got %s\n", dev_name(device
),wave_out_error(rc
));
696 rc
=waveOutGetVolume(wout
,&volume
);
697 if (rc
== MMSYSERR_NOTSUPPORTED
) has_volume
= FALSE
;
698 ok(has_volume
? rc
==MMSYSERR_NOERROR
: rc
==MMSYSERR_NOTSUPPORTED
,
699 "waveOutGetVolume(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
701 /* waveOutGetDevCaps allows an open handle instead of a device id */
702 rc
=waveOutGetDevCapsW(HandleToUlong(wout
),&capsW
,sizeof(capsW
));
703 ok(rc
==MMSYSERR_NOERROR
,
704 "waveOutGetDevCapsW(%s): MMSYSERR_NOERROR "
705 "expected, got %s\n",dev_name(device
),wave_out_error(rc
));
707 /* waveOutOpen does not allow an open handle instead of a device id */
708 rc
=waveOutOpen(&wout2
,HandleToUlong(wout
),pwfx
,0,0,CALLBACK_NULL
);
709 ok(rc
==MMSYSERR_BADDEVICEID
,
710 "waveOutOpen(%s): MMSYSERR_BADDEVICEID "
711 "expected, got %s\n",dev_name(device
),wave_out_error(rc
));
712 if(rc
==MMSYSERR_NOERROR
)
715 /* make sure fragment length is a multiple of block size */
716 frag_length
= ((length
/ headers
) / pwfx
->nBlockAlign
) * pwfx
->nBlockAlign
;
718 for (i
= 0; i
< headers
; i
++) {
719 frags
[i
].lpData
=buffer
+ (i
* frag_length
);
720 if (i
!= (headers
-1))
721 frags
[i
].dwBufferLength
=frag_length
;
723 /* use remainder of buffer for last fragment */
724 frags
[i
].dwBufferLength
=length
- (i
* frag_length
);
728 rc
=waveOutPrepareHeader(wout
, &frags
[i
], sizeof(frags
[0]));
729 ok(rc
==MMSYSERR_NOERROR
,
730 "waveOutPrepareHeader(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
733 if (interactive
&& rc
==MMSYSERR_NOERROR
) {
734 trace("Playing %g second %s at %5dx%2dx%d %2d header%s %d loop%s %d bytes %s %s\n",duration
,
735 sine
? "440 Hz tone" : "silence", pwfx
->nSamplesPerSec
,
736 pwfx
->wBitsPerSample
,pwfx
->nChannels
, headers
, headers
> 1 ? "s": " ",
737 loops
, loops
== 1 ? " " : "s", length
* (loops
+ 1),
738 get_format_str(pwfx
->wFormatTag
),
739 wave_open_flags(flags
));
740 if (sine
&& has_volume
&& volume
== 0)
741 trace("*** Warning the sound is muted, you will not hear the test\n");
743 /* Check that the position is 0 at start */
744 check_position(device
, wout
, 0, pwfx
);
746 rc
=waveOutSetVolume(wout
,0x20002000);
747 ok(has_volume
? rc
==MMSYSERR_NOERROR
: rc
==MMSYSERR_NOTSUPPORTED
,
748 "waveOutSetVolume(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
750 rc
=waveOutSetVolume(wout
,volume
);
751 ok(has_volume
? rc
==MMSYSERR_NOERROR
: rc
==MMSYSERR_NOTSUPPORTED
,
752 "waveOutSetVolume(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
754 rc
=waveOutWrite(wout
, &frags
[0], sizeof(frags
[0]));
755 ok(rc
==MMSYSERR_NOERROR
,"waveOutWrite(%s): rc=%s\n",
756 dev_name(device
),wave_out_error(rc
));
758 ok(frags
[0].dwFlags
==(WHDR_PREPARED
|WHDR_INQUEUE
),
759 "WHDR_INQUEUE WHDR_PREPARED expected, got= %s\n",
760 wave_header_flags(frags
[0].dwFlags
));
762 rc
=waveOutWrite(wout
, &frags
[0], sizeof(frags
[0]));
763 ok(rc
==WAVERR_STILLPLAYING
,
764 "waveOutWrite(%s): WAVE_STILLPLAYING expected, got %s\n",
765 dev_name(device
),wave_out_error(rc
));
767 ok(frags
[0].dwFlags
==(WHDR_PREPARED
|WHDR_INQUEUE
),
768 "WHDR_INQUEUE WHDR_PREPARED expected, got %s\n",
769 wave_header_flags(frags
[0].dwFlags
));
771 if (headers
== 1 && loops
== 0 && pause
) {
772 paused
= duration
/ 2;
773 Sleep(paused
* 1000);
774 rc
=waveOutPause(wout
);
775 ok(rc
==MMSYSERR_NOERROR
,"waveOutPause(%s): rc=%s\n",
776 dev_name(device
),wave_out_error(rc
));
777 trace("pausing for %g seconds\n", paused
);
778 Sleep(paused
* 1000);
779 rc
=waveOutRestart(wout
);
780 ok(rc
==MMSYSERR_NOERROR
,"waveOutRestart(%s): rc=%s\n",
781 dev_name(device
),wave_out_error(rc
));
784 for (j
= 0; j
<= loops
; j
++) {
785 for (i
= 0; i
< headers
; i
++) {
786 /* don't do last one */
787 if (!((j
== loops
) && (i
== (headers
- 1)))) {
789 frags
[(i
+1) % headers
].dwFlags
= WHDR_PREPARED
;
790 rc
=waveOutWrite(wout
, &frags
[(i
+1) % headers
], sizeof(frags
[0]));
791 ok(rc
==MMSYSERR_NOERROR
,"waveOutWrite(%s, header[%d]): rc=%s\n",
792 dev_name(device
),(i
+1)%headers
,wave_out_error(rc
));
794 rc
=WaitForSingleObject(hevent
,8000);
795 ok(rc
==WAIT_OBJECT_0
, "missing WOM_DONE notification\n");
799 for (i
= 0; i
< headers
; i
++) {
800 ok(frags
[i
].dwFlags
==(WHDR_DONE
|WHDR_PREPARED
) ||
801 broken((flags
& CALLBACK_TYPEMASK
)==CALLBACK_EVENT
&&
802 frags
[i
].dwFlags
==(WHDR_DONE
|WHDR_PREPARED
|0x1000)), /* < NT4 */
803 "(%02d) WHDR_DONE WHDR_PREPARED expected, got %s\n",
804 i
, wave_header_flags(frags
[i
].dwFlags
));
806 check_position(device
, wout
, length
* (loops
+ 1), pwfx
);
809 for (i
= 0; i
< headers
; i
++) {
810 rc
=waveOutUnprepareHeader(wout
, &frags
[i
], sizeof(frags
[0]));
811 ok(rc
==MMSYSERR_NOERROR
,
812 "waveOutUnprepareHeader(%s): rc=%s\n",dev_name(device
),
816 ok(frags
[0].dwFlags
==(interactive
? WHDR_DONE
: 0), "dwFlags(%d)=%x\n",device
,frags
[0].dwFlags
);
818 frags
[0].dwFlags
|= WHDR_DONE
;
819 rc
=waveOutUnprepareHeader(wout
, &frags
[0], sizeof(frags
[0]));
820 ok(rc
==MMSYSERR_NOERROR
, "waveOutUnprepareHeader(%d): rc=%s\n",device
,wave_out_error(rc
));
821 ok(frags
[0].dwFlags
==WHDR_DONE
, "dwFlags(%d)=%x\n",device
,frags
[0].dwFlags
);
823 frags
[0].dwFlags
|= WHDR_INQUEUE
;
824 rc
=waveOutPrepareHeader(wout
, &frags
[0], sizeof(frags
[0]));
825 ok(rc
==MMSYSERR_NOERROR
, "waveOutPrepareHeader(%d): rc=%s\n",device
,wave_out_error(rc
));
826 ok(frags
[0].dwFlags
==WHDR_PREPARED
, "dwFlags(%d)=%x\n",device
,frags
[0].dwFlags
);
828 frags
[0].dwFlags
|= WHDR_INQUEUE
;
829 rc
=waveOutPrepareHeader(wout
, &frags
[0], sizeof(frags
[0]));
830 ok(rc
==MMSYSERR_NOERROR
, "waveOutPrepareHeader(%d): rc=%s\n",device
,wave_out_error(rc
));
831 ok(frags
[0].dwFlags
==(WHDR_PREPARED
|WHDR_INQUEUE
), "dwFlags(%d)=%x\n",device
,frags
[0].dwFlags
);
833 frags
[0].dwFlags
&= ~(WHDR_INQUEUE
|WHDR_DONE
);
834 rc
=waveOutUnprepareHeader(wout
, &frags
[0], sizeof(frags
[0]));
835 ok(rc
==MMSYSERR_NOERROR
, "waveOutUnprepareHeader(%d): rc=%s\n",device
,wave_out_error(rc
));
836 ok(frags
[0].dwFlags
==0, "dwFlags(%d)=%x\n",device
,frags
[0].dwFlags
);
838 rc
=waveOutClose(wout
);
839 ok(rc
==MMSYSERR_NOERROR
,"waveOutClose(%s): rc=%s\n",dev_name(device
),
841 if (rc
==WAVERR_STILLPLAYING
) {
842 /* waveOutReset ought to return all buffers s.t. waveOutClose succeeds */
843 rc
=waveOutReset(wout
);
844 ok(rc
==MMSYSERR_NOERROR
,"waveOutReset(%s): rc=%s\n",dev_name(device
),
847 for (i
= 0; i
< headers
; i
++) {
848 rc
=waveOutUnprepareHeader(wout
, &frags
[i
], sizeof(frags
[0]));
849 ok(rc
==MMSYSERR_NOERROR
,
850 "waveOutUnprepareHeader(%s): rc=%s\n",dev_name(device
),
853 rc
=waveOutClose(wout
);
854 ok(rc
==MMSYSERR_NOERROR
,"waveOutClose(%s): rc=%s\n",dev_name(device
),
857 rc
=WaitForSingleObject(hevent
,1500);
858 ok(rc
==WAIT_OBJECT_0
, "missing WOM_CLOSE notification\n");
860 wout
= (HWAVEOUT
)0xdeadf00d;
861 rc
=waveOutOpen(&wout
,device
,pwfx
,callback
,callback_instance
,flags
|WAVE_FORMAT_QUERY
);
862 ok(rc
==MMSYSERR_NOERROR
, "WAVE_FORMAT_QUERY(%s): rc=%s\n",dev_name(device
),
864 ok(wout
==(HWAVEOUT
)0xdeadf00d, "WAVE_FORMAT_QUERY handle %p\n", wout
);
866 rc
=WaitForSingleObject(hevent
,20);
867 ok(rc
==WAIT_TIMEOUT
, "Notification from %s rc=%x\n",
868 wave_open_flags(flags
|WAVE_FORMAT_QUERY
),rc
);
870 HeapFree(GetProcessHeap(), 0, buffer
);
872 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_THREAD
) {
873 PostThreadMessageW(thread_id
, WM_APP
, 0, 0);
874 WaitForSingleObject(hevent
,10000);
877 HeapFree(GetProcessHeap(), 0, frags
);
880 static void wave_out_test_device(UINT_PTR device
)
885 WAVEFORMATEXTENSIBLE wfex
;
886 IMAADPCMWAVEFORMAT wfa
;
895 SYSTEM_INFO sSysInfo
;
899 GetSystemInfo(&sSysInfo
);
900 dwPageSize
= sSysInfo
.dwPageSize
;
902 rc
=waveOutGetDevCapsA(device
,&capsA
,sizeof(capsA
));
903 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_BADDEVICEID
||
904 rc
==MMSYSERR_NODRIVER
,
905 "waveOutGetDevCapsA(%s): failed to get capabilities: rc=%s\n",
906 dev_name(device
),wave_out_error(rc
));
907 if (rc
==MMSYSERR_BADDEVICEID
|| rc
==MMSYSERR_NODRIVER
)
910 rc
=waveOutGetDevCapsW(device
,&capsW
,sizeof(capsW
));
911 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_NOTSUPPORTED
,
912 "waveOutGetDevCapsW(%s): MMSYSERR_NOERROR or MMSYSERR_NOTSUPPORTED "
913 "expected, got %s\n",dev_name(device
),wave_out_error(rc
));
915 rc
=waveOutGetDevCapsA(device
,0,sizeof(capsA
));
916 ok(rc
==MMSYSERR_INVALPARAM
,
917 "waveOutGetDevCapsA(%s): MMSYSERR_INVALPARAM expected, "
918 "got %s\n",dev_name(device
),wave_out_error(rc
));
920 rc
=waveOutGetDevCapsW(device
,0,sizeof(capsW
));
921 ok(rc
==MMSYSERR_INVALPARAM
|| rc
==MMSYSERR_NOTSUPPORTED
,
922 "waveOutGetDevCapsW(%s): MMSYSERR_INVALPARAM or MMSYSERR_NOTSUPPORTED "
923 "expected, got %s\n",dev_name(device
),wave_out_error(rc
));
927 /* FIXME: this works on windows but crashes wine */
928 rc
=waveOutGetDevCapsA(device
,(LPWAVEOUTCAPSA
)1,sizeof(capsA
));
929 ok(rc
==MMSYSERR_INVALPARAM
,
930 "waveOutGetDevCapsA(%s): MMSYSERR_INVALPARAM expected, got %s\n",
931 dev_name(device
),wave_out_error(rc
));
933 rc
=waveOutGetDevCapsW(device
,(LPWAVEOUTCAPSW
)1,sizeof(capsW
));
934 ok(rc
==MMSYSERR_INVALPARAM
|| rc
==MMSYSERR_NOTSUPPORTED
,
935 "waveOutGetDevCapsW(%s): MMSYSERR_INVALPARAM or MMSYSERR_NOTSUPPORTED "
936 "expected, got %s\n",dev_name(device
),wave_out_error(rc
));
939 rc
=waveOutGetDevCapsA(device
,&capsA
,4);
940 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_INVALPARAM
,
941 "waveOutGetDevCapsA(%s): MMSYSERR_NOERROR or MMSYSERR_INVALPARAM "
942 "expected, got %s\n", dev_name(device
),wave_out_error(rc
));
944 rc
=waveOutGetDevCapsW(device
,&capsW
,4);
945 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_NOTSUPPORTED
||
946 rc
==MMSYSERR_INVALPARAM
, /* Vista, W2K8 */
947 "waveOutGetDevCapsW(%s): unexpected return value %s\n",
948 dev_name(device
),wave_out_error(rc
));
950 rc
=waveOutMessage((HWAVEOUT
)device
, DRV_QUERYMAPPABLE
, 0, 0);
951 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_NOTSUPPORTED
,
952 "DRV_QUERYMAPPABLE(%s): unexpected return value %s\n",
953 dev_name(device
),wave_out_error(rc
));
956 rc
=waveOutMessage((HWAVEOUT
)device
, DRV_QUERYDEVICEINTERFACESIZE
,
957 (DWORD_PTR
)&size
, 0);
958 ok(rc
==MMSYSERR_NOERROR
|| broken(rc
==MMSYSERR_INVALPARAM
||
959 rc
==MMSYSERR_NOTSUPPORTED
),
960 "waveOutMessage(%s): failed to get interface size, rc=%s\n",
961 dev_name(device
),wave_out_error(rc
));
962 if (rc
==MMSYSERR_NOERROR
) {
963 nameW
= HeapAlloc(GetProcessHeap(), 0, size
);
964 rc
=waveOutMessage((HWAVEOUT
)device
, DRV_QUERYDEVICEINTERFACE
,
965 (DWORD_PTR
)nameW
, size
);
966 ok(rc
==MMSYSERR_NOERROR
,"waveOutMessage(%s): failed to get interface "
967 "name, rc=%s\n",dev_name(device
),wave_out_error(rc
));
968 ok(lstrlenW(nameW
)+1==size
/sizeof(WCHAR
),"got an incorrect size %d\n",size
);
969 if (rc
==MMSYSERR_NOERROR
) {
970 nameA
= HeapAlloc(GetProcessHeap(), 0, size
/sizeof(WCHAR
));
971 WideCharToMultiByte(CP_ACP
, 0, nameW
, size
/sizeof(WCHAR
), nameA
,
972 size
/sizeof(WCHAR
), NULL
, NULL
);
974 HeapFree(GetProcessHeap(), 0, nameW
);
976 else if (rc
==MMSYSERR_NOTSUPPORTED
) {
977 nameA
=HeapAlloc(GetProcessHeap(), 0, sizeof("not supported"));
978 strcpy(nameA
, "not supported");
981 rc
=waveOutGetDevCapsA(device
,&capsA
,sizeof(capsA
));
982 ok(rc
==MMSYSERR_NOERROR
,
983 "waveOutGetDevCapsA(%s): MMSYSERR_NOERROR expected, got %s\n",
984 dev_name(device
),wave_out_error(rc
));
985 if (rc
!=MMSYSERR_NOERROR
)
987 HeapFree(GetProcessHeap(), 0, nameA
);
991 trace(" %s: \"%s\" (%s) %d.%d (%d:%d)\n",dev_name(device
),capsA
.szPname
,
992 (nameA
?nameA
:"failed"),capsA
.vDriverVersion
>> 8,
993 capsA
.vDriverVersion
& 0xff, capsA
.wMid
,capsA
.wPid
);
994 trace(" channels=%d formats=%05x support=%04x\n",
995 capsA
.wChannels
,capsA
.dwFormats
,capsA
.dwSupport
);
996 trace(" %s\n",wave_out_caps(capsA
.dwSupport
));
997 HeapFree(GetProcessHeap(), 0, nameA
);
999 if (winetest_interactive
&& (device
!= WAVE_MAPPER
))
1001 trace("Playing a 5 seconds reference tone.\n");
1002 trace("All subsequent tones should be identical to this one.\n");
1003 trace("Listen for stutter, changes in pitch, volume, etc.\n");
1004 format
.wFormatTag
=WAVE_FORMAT_PCM
;
1006 format
.wBitsPerSample
=8;
1007 format
.nSamplesPerSec
=22050;
1008 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
1009 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
1012 wave_out_test_deviceOut(device
,5.0,1,0,&format
,WAVE_FORMAT_2M08
,
1013 CALLBACK_EVENT
,&capsA
,TRUE
,TRUE
,FALSE
);
1014 wave_out_test_deviceOut(device
,5.0,1,0,&format
,WAVE_FORMAT_2M08
,
1015 CALLBACK_FUNCTION
,&capsA
,TRUE
,TRUE
,FALSE
);
1016 wave_out_test_deviceOut(device
,5.0,1,0,&format
,WAVE_FORMAT_2M08
,
1017 CALLBACK_THREAD
,&capsA
,TRUE
,TRUE
,FALSE
);
1019 wave_out_test_deviceOut(device
,5.0,10,0,&format
,WAVE_FORMAT_2M08
,
1020 CALLBACK_EVENT
,&capsA
,TRUE
,TRUE
,FALSE
);
1021 wave_out_test_deviceOut(device
,5.0,5,1,&format
,WAVE_FORMAT_2M08
,
1022 CALLBACK_EVENT
,&capsA
,TRUE
,TRUE
,FALSE
);
1024 format
.wFormatTag
=WAVE_FORMAT_PCM
;
1026 format
.wBitsPerSample
=8;
1027 format
.nSamplesPerSec
=22050;
1028 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
1029 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
1031 wave_out_test_deviceOut(device
,0.6,1,0,&format
,WAVE_FORMAT_2M08
,
1032 CALLBACK_EVENT
,&capsA
,TRUE
,FALSE
,FALSE
);
1033 wave_out_test_deviceOut(device
,0.6,1,0,&format
,WAVE_FORMAT_2M08
,
1034 CALLBACK_EVENT
,&capsA
,TRUE
,FALSE
,TRUE
);
1035 wave_out_test_deviceOut(device
,0.6,1,0,&format
,WAVE_FORMAT_2M08
,
1036 CALLBACK_FUNCTION
,&capsA
,TRUE
,FALSE
,FALSE
);
1037 wave_out_test_deviceOut(device
,0.6,1,0,&format
,WAVE_FORMAT_2M08
,
1038 CALLBACK_FUNCTION
,&capsA
,TRUE
,FALSE
,TRUE
);
1039 wave_out_test_deviceOut(device
,0.6,1,0,&format
,WAVE_FORMAT_2M08
,
1040 CALLBACK_THREAD
,&capsA
,TRUE
,FALSE
,FALSE
);
1041 wave_out_test_deviceOut(device
,0.6,1,0,&format
,WAVE_FORMAT_2M08
,
1042 CALLBACK_THREAD
,&capsA
,TRUE
,FALSE
,TRUE
);
1044 wave_out_test_deviceOut(device
,0.8,10,0,&format
,WAVE_FORMAT_2M08
,
1045 CALLBACK_EVENT
,&capsA
,TRUE
,FALSE
,FALSE
);
1046 wave_out_test_deviceOut(device
,1.0,5,1,&format
,WAVE_FORMAT_2M08
,
1047 CALLBACK_EVENT
,&capsA
,TRUE
,FALSE
,FALSE
);
1050 for (f
= 0; f
< ARRAY_SIZE(win_formats
); f
++) {
1051 format
.wFormatTag
=WAVE_FORMAT_PCM
;
1052 format
.nChannels
=win_formats
[f
][3];
1053 format
.wBitsPerSample
=win_formats
[f
][2];
1054 format
.nSamplesPerSec
=win_formats
[f
][1];
1055 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
1056 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
1058 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1059 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1061 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1062 CALLBACK_FUNCTION
,&capsA
,winetest_interactive
,
1064 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1065 CALLBACK_THREAD
,&capsA
,winetest_interactive
,
1068 wave_out_test_deviceOut(device
,1.0,10,0,&format
,win_formats
[f
][0],
1069 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1071 wave_out_test_deviceOut(device
,1.0,5,1,&format
,win_formats
[f
][0],
1072 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1075 if (winetest_interactive
) {
1076 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1077 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1079 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1080 CALLBACK_FUNCTION
,&capsA
,winetest_interactive
,
1082 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1083 CALLBACK_THREAD
,&capsA
,winetest_interactive
,
1086 wave_out_test_deviceOut(device
,1.0,10,0,&format
,win_formats
[f
][0],
1087 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1089 wave_out_test_deviceOut(device
,1.0,5,1,&format
,win_formats
[f
][0],
1090 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1093 if (device
!= WAVE_MAPPER
)
1095 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1096 CALLBACK_EVENT
|WAVE_FORMAT_DIRECT
,&capsA
,
1097 winetest_interactive
,TRUE
,FALSE
);
1098 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1099 CALLBACK_EVENT
|WAVE_MAPPED
,&capsA
,
1100 winetest_interactive
,TRUE
,FALSE
);
1101 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1102 CALLBACK_FUNCTION
|WAVE_FORMAT_DIRECT
,&capsA
,
1103 winetest_interactive
,TRUE
,FALSE
);
1104 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1105 CALLBACK_FUNCTION
|WAVE_MAPPED
,&capsA
,
1106 winetest_interactive
,TRUE
,FALSE
);
1107 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1108 CALLBACK_THREAD
|WAVE_FORMAT_DIRECT
,&capsA
,
1109 winetest_interactive
,TRUE
,FALSE
);
1110 wave_out_test_deviceOut(device
,1.0,1,0,&format
,win_formats
[f
][0],
1111 CALLBACK_THREAD
|WAVE_MAPPED
,&capsA
,
1112 winetest_interactive
,TRUE
,FALSE
);
1114 wave_out_test_deviceOut(device
,1.0,10,0,&format
,win_formats
[f
][0],
1115 CALLBACK_EVENT
|WAVE_FORMAT_DIRECT
,&capsA
,
1116 winetest_interactive
,TRUE
,FALSE
);
1117 wave_out_test_deviceOut(device
,1.0,5,1,&format
,win_formats
[f
][0],
1118 CALLBACK_EVENT
|WAVE_FORMAT_DIRECT
,&capsA
,
1119 winetest_interactive
,TRUE
,FALSE
);
1123 /* Try a PCMWAVEFORMAT aligned next to an unaccessible page for bounds
1125 twoPages
= VirtualAlloc(NULL
, 2 * dwPageSize
, MEM_RESERVE
| MEM_COMMIT
,
1127 ok(twoPages
!=NULL
,"Failed to allocate 2 pages of memory\n");
1129 res
= VirtualProtect(twoPages
+ dwPageSize
, dwPageSize
, PAGE_NOACCESS
,
1131 ok(res
, "Failed to set memory access on second page\n");
1133 LPWAVEFORMATEX pwfx
= (LPWAVEFORMATEX
)(twoPages
+ dwPageSize
-
1134 sizeof(PCMWAVEFORMAT
));
1135 pwfx
->wFormatTag
=WAVE_FORMAT_PCM
;
1137 pwfx
->wBitsPerSample
=8;
1138 pwfx
->nSamplesPerSec
=22050;
1139 pwfx
->nBlockAlign
=pwfx
->nChannels
*pwfx
->wBitsPerSample
/8;
1140 pwfx
->nAvgBytesPerSec
=pwfx
->nSamplesPerSec
*pwfx
->nBlockAlign
;
1141 wave_out_test_deviceOut(device
,1.0,1,0,pwfx
,WAVE_FORMAT_2M08
,
1142 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1144 wave_out_test_deviceOut(device
,1.0,10,0,pwfx
,WAVE_FORMAT_2M08
,
1145 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1147 wave_out_test_deviceOut(device
,1.0,5,1,pwfx
,WAVE_FORMAT_2M08
,
1148 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1150 if (device
!= WAVE_MAPPER
)
1152 wave_out_test_deviceOut(device
,1.0,1,0,pwfx
,WAVE_FORMAT_2M08
,
1153 CALLBACK_EVENT
|WAVE_FORMAT_DIRECT
,
1154 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1155 wave_out_test_deviceOut(device
,1.0,1,0,pwfx
,WAVE_FORMAT_2M08
,
1156 CALLBACK_EVENT
|WAVE_MAPPED
,&capsA
,
1157 winetest_interactive
,TRUE
,FALSE
);
1158 wave_out_test_deviceOut(device
,1.0,10,0,pwfx
,WAVE_FORMAT_2M08
,
1159 CALLBACK_EVENT
|WAVE_FORMAT_DIRECT
,
1160 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1161 wave_out_test_deviceOut(device
,1.0,10,0,pwfx
,WAVE_FORMAT_2M08
,
1162 CALLBACK_EVENT
|WAVE_MAPPED
,&capsA
,
1163 winetest_interactive
,TRUE
,FALSE
);
1164 wave_out_test_deviceOut(device
,1.0,5,1,pwfx
,WAVE_FORMAT_2M08
,
1165 CALLBACK_EVENT
|WAVE_FORMAT_DIRECT
,
1166 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1167 wave_out_test_deviceOut(device
,1.0,5,1,pwfx
,WAVE_FORMAT_2M08
,
1168 CALLBACK_EVENT
|WAVE_MAPPED
,&capsA
,
1169 winetest_interactive
,TRUE
,FALSE
);
1172 VirtualFree(twoPages
, 0, MEM_RELEASE
);
1175 /* try some non PCM formats */
1176 format
.wFormatTag
=WAVE_FORMAT_MULAW
;
1178 format
.wBitsPerSample
=8;
1179 format
.nSamplesPerSec
=8000;
1180 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
1181 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
1183 rc
=waveOutOpen(&wout
,device
,&format
,0,0,CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1184 ok(rc
==MMSYSERR_NOERROR
||rc
==WAVERR_BADFORMAT
||
1185 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1186 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1187 if (rc
==MMSYSERR_NOERROR
) {
1189 wave_out_test_deviceOut(device
,1.0,1,0,&format
,0,CALLBACK_EVENT
,
1190 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1191 wave_out_test_deviceOut(device
,1.0,10,0,&format
,0,CALLBACK_EVENT
,
1192 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1193 wave_out_test_deviceOut(device
,1.0,5,1,&format
,0,CALLBACK_EVENT
,
1194 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1198 trace("waveOutOpen(%s): WAVE_FORMAT_MULAW not supported\n",
1201 query_rc
= waveOutOpen(NULL
, device
, &format
, 0, 0, CALLBACK_NULL
| WAVE_FORMAT_QUERY
);
1202 ok(query_rc
==MMSYSERR_NOERROR
|| query_rc
==WAVERR_BADFORMAT
|| query_rc
==MMSYSERR_INVALPARAM
,
1203 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1205 rc
= waveOutOpen(&wout
, device
, &format
, 0, 0, CALLBACK_NULL
);
1207 "waveOutOpen(%s): returned different from query: %s\n",dev_name(device
),wave_out_error(rc
));
1208 if(rc
== MMSYSERR_NOERROR
)
1212 wfa
.wfx
.wFormatTag
=WAVE_FORMAT_IMA_ADPCM
;
1213 wfa
.wfx
.nChannels
=1;
1214 wfa
.wfx
.nSamplesPerSec
=11025;
1215 wfa
.wfx
.nAvgBytesPerSec
=5588;
1216 wfa
.wfx
.nBlockAlign
=256;
1217 wfa
.wfx
.wBitsPerSample
=4; /* see imaadp32.c */
1219 wfa
.wSamplesPerBlock
=505;
1220 rc
=waveOutOpen(&wout
,device
,&wfa
.wfx
,0,0,CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1221 ok(rc
==MMSYSERR_NOERROR
||rc
==WAVERR_BADFORMAT
||
1222 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1223 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1224 if (rc
==MMSYSERR_NOERROR
) {
1226 /* TODO: teach wave_generate_* ADPCM
1227 wave_out_test_deviceOut(device,1.0,1,0,&wfa.wfx,0,CALLBACK_EVENT,
1228 &capsA,winetest_interactive,TRUE,FALSE);
1229 wave_out_test_deviceOut(device,1.0,10,0,&wfa.wfx,0,CALLBACK_EVENT,
1230 &capsA,winetest_interactive,TRUE,FALSE);
1231 wave_out_test_deviceOut(device,1.0,5,1,&wfa.wfx,0,CALLBACK_EVENT,
1232 &capsA,winetest_interactive,TRUE,FALSE);
1235 trace("waveOutOpen(%s): WAVE_FORMAT_IMA_ADPCM not supported\n",
1238 /* test if WAVEFORMATEXTENSIBLE supported */
1239 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
1240 wfex
.Format
.nChannels
=2;
1241 wfex
.Format
.wBitsPerSample
=16;
1242 wfex
.Format
.nSamplesPerSec
=22050;
1243 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
1244 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
1245 wfex
.Format
.nBlockAlign
;
1246 wfex
.Format
.cbSize
=22;
1247 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
1248 wfex
.dwChannelMask
=SPEAKER_ALL
;
1249 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_PCM
;
1250 rc
=waveOutOpen(&wout
,device
,&wfex
.Format
,0,0,
1251 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1252 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
1253 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1254 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1255 if (rc
==MMSYSERR_NOERROR
) {
1257 wave_out_test_deviceOut(device
,1.0,1,0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1258 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1260 wave_out_test_deviceOut(device
,1.0,10,0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1261 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1263 wave_out_test_deviceOut(device
,1.0,5,1,&wfex
.Format
,WAVE_FORMAT_2M16
,
1264 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1267 trace("waveOutOpen(%s): WAVE_FORMAT_EXTENSIBLE not supported\n",
1270 /* test if 4 channels supported */
1271 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
1272 wfex
.Format
.nChannels
=4;
1273 wfex
.Format
.wBitsPerSample
=16;
1274 wfex
.Format
.nSamplesPerSec
=22050;
1275 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
1276 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
1277 wfex
.Format
.nBlockAlign
;
1278 wfex
.Format
.cbSize
=22;
1279 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
1280 wfex
.dwChannelMask
=SPEAKER_ALL
;
1281 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_PCM
;
1282 rc
=waveOutOpen(&wout
,device
,&wfex
.Format
,0,0,
1283 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1284 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
1285 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1286 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1287 if (rc
==MMSYSERR_NOERROR
) {
1289 wave_out_test_deviceOut(device
,1.0,1,0,&wfex
.Format
,0,CALLBACK_EVENT
,
1290 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1291 wave_out_test_deviceOut(device
,1.0,10,0,&wfex
.Format
,0,CALLBACK_EVENT
,
1292 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1293 wave_out_test_deviceOut(device
,1.0,5,1,&wfex
.Format
,0,CALLBACK_EVENT
,
1294 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1296 trace("waveOutOpen(%s): 4 channels not supported\n",
1299 /* test if 6 channels supported */
1300 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
1301 wfex
.Format
.nChannels
=6;
1302 wfex
.Format
.wBitsPerSample
=16;
1303 wfex
.Format
.nSamplesPerSec
=22050;
1304 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
1305 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
1306 wfex
.Format
.nBlockAlign
;
1307 wfex
.Format
.cbSize
=22;
1308 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
1309 wfex
.dwChannelMask
=SPEAKER_ALL
;
1310 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_PCM
;
1311 rc
=waveOutOpen(&wout
,device
,&wfex
.Format
,0,0,
1312 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1313 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
1314 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1315 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1316 if (rc
==MMSYSERR_NOERROR
) {
1318 wave_out_test_deviceOut(device
,1.0,1,0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1319 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1321 wave_out_test_deviceOut(device
,1.0,10,0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1322 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1324 wave_out_test_deviceOut(device
,1.0,5,1,&wfex
.Format
,WAVE_FORMAT_2M16
,
1325 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1328 trace("waveOutOpen(%s): 6 channels not supported\n",
1333 /* FIXME: ALSA doesn't like this format */
1334 /* test if 24 bit samples supported */
1335 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
1336 wfex
.Format
.nChannels
=2;
1337 wfex
.Format
.wBitsPerSample
=24;
1338 wfex
.Format
.nSamplesPerSec
=22050;
1339 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
1340 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
1341 wfex
.Format
.nBlockAlign
;
1342 wfex
.Format
.cbSize
=22;
1343 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
1344 wfex
.dwChannelMask
=SPEAKER_ALL
;
1345 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_PCM
;
1346 rc
=waveOutOpen(&wout
,device
,&wfex
.Format
,0,0,
1347 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1348 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
1349 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1350 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1351 if (rc
==MMSYSERR_NOERROR
) {
1353 wave_out_test_deviceOut(device
,1.0,1,0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1354 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1357 trace("waveOutOpen(%s): 24 bit samples not supported\n",
1361 /* test if 32 bit samples supported */
1362 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
1363 wfex
.Format
.nChannels
=2;
1364 wfex
.Format
.wBitsPerSample
=32;
1365 wfex
.Format
.nSamplesPerSec
=22050;
1366 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
1367 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
1368 wfex
.Format
.nBlockAlign
;
1369 wfex
.Format
.cbSize
=22;
1370 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
1371 wfex
.dwChannelMask
=SPEAKER_ALL
;
1372 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_PCM
;
1373 rc
=waveOutOpen(&wout
,device
,&wfex
.Format
,0,0,
1374 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1375 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
1376 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1377 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1378 if (rc
==MMSYSERR_NOERROR
) {
1380 wave_out_test_deviceOut(device
,1.0,1,0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1381 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1383 wave_out_test_deviceOut(device
,1.0,10,0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1384 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1386 wave_out_test_deviceOut(device
,1.0,5,1,&wfex
.Format
,WAVE_FORMAT_2M16
,
1387 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1390 trace("waveOutOpen(%s): 32 bit samples not supported\n",
1393 /* test if 32 bit float samples supported */
1394 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
1395 wfex
.Format
.nChannels
=2;
1396 wfex
.Format
.wBitsPerSample
=32;
1397 wfex
.Format
.nSamplesPerSec
=22050;
1398 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
1399 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
1400 wfex
.Format
.nBlockAlign
;
1401 wfex
.Format
.cbSize
=22;
1402 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
1403 wfex
.dwChannelMask
=SPEAKER_ALL
;
1404 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
;
1405 rc
=waveOutOpen(&wout
,device
,&wfex
.Format
,0,0,
1406 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1407 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
1408 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1409 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1410 if (rc
==MMSYSERR_NOERROR
) {
1412 wave_out_test_deviceOut(device
,1.0,1,0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1413 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1415 wave_out_test_deviceOut(device
,1.0,10,0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1416 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1418 wave_out_test_deviceOut(device
,1.0,5,1,&wfex
.Format
,WAVE_FORMAT_2M16
,
1419 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1422 trace("waveOutOpen(%s): 32 bit float samples not supported\n",
1425 /* Test invalid parameters */
1427 format
.wFormatTag
= WAVE_FORMAT_PCM
;
1428 format
.nChannels
= 1;
1429 format
.nSamplesPerSec
= 11025;
1430 format
.nBlockAlign
= 1;
1431 format
.nAvgBytesPerSec
= 11025 * 1;
1432 format
.wBitsPerSample
= 8;
1435 format
.nAvgBytesPerSec
= 0;
1436 rc
= waveOutOpen(&wout
, device
, &format
, 0, 0, 0);
1437 ok(rc
== MMSYSERR_NOERROR
,
1438 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1440 format
.nAvgBytesPerSec
= 11025 * 1;
1442 format
.nSamplesPerSec
= 0;
1443 rc
= waveOutOpen(&wout
, device
, &format
, 0, 0, 0);
1444 ok(rc
== MMSYSERR_INVALPARAM
|| rc
== WAVERR_BADFORMAT
, /* XP and lower return WAVERR_BADFORMAT */
1445 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1448 static void wave_out_tests(void)
1452 WAVEFORMATEX format
;
1455 DWORD preferred
, status
;
1458 ndev
=waveOutGetNumDevs();
1459 trace("found %d WaveOut devices\n",ndev
);
1461 rc
= waveOutMessage((HWAVEOUT
)WAVE_MAPPER
, DRVM_MAPPER_PREFERRED_GET
,
1462 (DWORD_PTR
)&preferred
, (DWORD_PTR
)&status
);
1463 ok((ndev
== 0 && (rc
== MMSYSERR_NODRIVER
|| rc
== MMSYSERR_BADDEVICEID
)) ||
1464 rc
== MMSYSERR_NOTSUPPORTED
||
1465 rc
== MMSYSERR_NOERROR
, "waveOutMessage(DRVM_MAPPER_PREFERRED_GET) failed: %u\n", rc
);
1467 if(rc
!= MMSYSERR_NOTSUPPORTED
)
1468 ok((ndev
== 0 && (preferred
== -1 || broken(preferred
!= -1))) ||
1469 preferred
< ndev
, "Got invalid preferred device: 0x%x\n", preferred
);
1471 rc
= waveOutMessage((HWAVEOUT
)WAVE_MAPPER
, DRVM_MAPPER_PREFERRED_GET
,
1473 ok(rc
== MMSYSERR_INVALPARAM
|| rc
== MMSYSERR_BADDEVICEID
, /* w2008+wvista */
1474 "waveOutMessage(DRVM_MAPPER_PREFERRED_GET) failed: %u\n", rc
);
1476 rc
= waveOutMessage((HWAVEOUT
)WAVE_MAPPER
, DRVM_MAPPER_PREFERRED_GET
,
1477 0, (DWORD_PTR
)&status
);
1478 ok(rc
== MMSYSERR_INVALPARAM
|| rc
== MMSYSERR_BADDEVICEID
, /* w2008+wvista */
1479 "waveOutMessage(DRVM_MAPPER_PREFERRED_GET) failed: %u\n", rc
);
1481 rc
=waveOutGetDevCapsA(ndev
+1,&capsA
,sizeof(capsA
));
1482 ok(rc
==MMSYSERR_BADDEVICEID
,
1483 "waveOutGetDevCapsA(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
1484 dev_name(ndev
+1),mmsys_error(rc
));
1486 rc
=waveOutGetDevCapsW(ndev
+1,&capsW
,sizeof(capsW
));
1487 ok(rc
==MMSYSERR_BADDEVICEID
|| rc
==MMSYSERR_NOTSUPPORTED
,
1488 "waveOutGetDevCapsW(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NOTSUPPORTED "
1489 "expected, got %s\n",dev_name(ndev
+1),mmsys_error(rc
));
1491 rc
=waveOutGetDevCapsA(WAVE_MAPPER
,&capsA
,sizeof(capsA
));
1493 ok(rc
==MMSYSERR_NOERROR
,
1494 "waveOutGetDevCapsA(%s): MMSYSERR_NOERROR expected, got %s\n",
1495 dev_name(WAVE_MAPPER
),mmsys_error(rc
));
1497 ok(rc
==MMSYSERR_BADDEVICEID
|| rc
==MMSYSERR_NODRIVER
,
1498 "waveOutGetDevCapsA(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NODRIVER "
1499 "expected, got %s\n",dev_name(WAVE_MAPPER
),mmsys_error(rc
));
1501 rc
=waveOutGetDevCapsW(WAVE_MAPPER
,&capsW
,sizeof(capsW
));
1503 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_NOTSUPPORTED
,
1504 "waveOutGetDevCapsW(%s): MMSYSERR_NOERROR or MMSYSERR_NOTSUPPORTED "
1505 "expected, got %s\n",dev_name(WAVE_MAPPER
),mmsys_error(rc
));
1507 ok(rc
==MMSYSERR_BADDEVICEID
|| rc
==MMSYSERR_NODRIVER
||
1508 rc
==MMSYSERR_NOTSUPPORTED
,
1509 "waveOutGetDevCapsW(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NODRIVER "
1510 " or MMSYSERR_NOTSUPPORTED expected, got %s\n",
1511 dev_name(WAVE_MAPPER
),mmsys_error(rc
));
1513 format
.wFormatTag
=WAVE_FORMAT_PCM
;
1515 format
.wBitsPerSample
=16;
1516 format
.nSamplesPerSec
=44100;
1517 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
1518 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
1520 rc
=waveOutOpen(&wout
,ndev
+1,&format
,0,0,CALLBACK_NULL
);
1521 ok(rc
==MMSYSERR_BADDEVICEID
,
1522 "waveOutOpen(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
1523 dev_name(ndev
+1),mmsys_error(rc
));
1525 if(winetest_interactive
)
1526 for (d
=0;d
<ndev
;d
++)
1527 wave_out_test_device(d
);
1530 wave_out_test_device(WAVE_MAPPER
);
1533 static void test_sndPlaySound(void)
1537 br
= sndPlaySoundA((LPCSTR
)SND_ALIAS_SYSTEMASTERISK
, SND_ALIAS_ID
|SND_SYNC
);
1538 ok(br
== TRUE
|| br
== FALSE
, "sndPlaySound gave strange return: %u\n", br
);
1540 br
= sndPlaySoundW((LPCWSTR
)SND_ALIAS_SYSTEMASTERISK
, SND_ALIAS_ID
|SND_SYNC
);
1541 ok(br
== TRUE
|| br
== FALSE
, "sndPlaySound gave strange return: %u\n", br
);
1543 br
= sndPlaySoundA((LPCSTR
)sndAlias('X','Y'), SND_ALIAS_ID
|SND_SYNC
);
1544 ok(br
== TRUE
|| br
== FALSE
, "sndPlaySound gave strange return: %u\n", br
);
1546 br
= sndPlaySoundW((LPCWSTR
)sndAlias('X','Y'), SND_ALIAS_ID
|SND_SYNC
);
1547 ok(br
== TRUE
|| br
== FALSE
, "sndPlaySound gave strange return: %u\n", br
);
1549 br
= sndPlaySoundA("SystemAsterisk", SND_ALIAS
|SND_SYNC
);
1550 ok(br
== TRUE
|| br
== FALSE
, "sndPlaySound gave strange return: %u\n", br
);
1552 br
= sndPlaySoundW(L
"SystemAsterisk", SND_ALIAS
|SND_SYNC
);
1553 ok(br
== TRUE
|| br
== FALSE
, "sndPlaySound gave strange return: %u\n", br
);
1555 br
= sndPlaySoundA("C:\not_exist.wav", SND_FILENAME
|SND_SYNC
);
1556 ok(br
== TRUE
|| br
== FALSE
, "sndPlaySound gave strange return: %u\n", br
);
1558 br
= sndPlaySoundW(L
"C:\\not_exist.wav", SND_FILENAME
|SND_SYNC
);
1559 ok(br
== TRUE
|| br
== FALSE
, "sndPlaySound gave strange return: %u\n", br
);
1562 static void test_fragmentsize(void)
1572 if(waveOutGetNumDevs() == 0)
1575 fmt
.wFormatTag
= WAVE_FORMAT_PCM
;
1577 fmt
.nSamplesPerSec
= 44100;
1578 fmt
.wBitsPerSample
= 16;
1579 fmt
.nBlockAlign
= fmt
.nChannels
* fmt
.wBitsPerSample
/ 8;
1580 fmt
.nAvgBytesPerSec
= fmt
.nBlockAlign
* fmt
.nSamplesPerSec
;
1581 fmt
.cbSize
= sizeof(WAVEFORMATEX
);
1583 hevent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1584 g_tid
= GetCurrentThreadId();
1586 rc
= waveOutOpen(&wout
, WAVE_MAPPER
, &fmt
, (DWORD_PTR
)callback_func
,
1587 (DWORD_PTR
)hevent
, CALLBACK_FUNCTION
);
1588 ok(rc
== MMSYSERR_NOERROR
|| rc
== WAVERR_BADFORMAT
||
1589 rc
== MMSYSERR_INVALFLAG
|| rc
== MMSYSERR_INVALPARAM
,
1590 "waveOutOpen(%s) failed: %s\n", dev_name(WAVE_MAPPER
), wave_out_error(rc
));
1591 if(rc
!= MMSYSERR_NOERROR
){
1592 CloseHandle(hevent
);
1596 wait
= WaitForSingleObject(hevent
, 1000);
1597 ok(wait
== WAIT_OBJECT_0
, "wave open callback missed\n");
1599 memset(hdr
, 0, sizeof(hdr
));
1600 hdr
[0].dwBufferLength
= (fmt
.nSamplesPerSec
* fmt
.nBlockAlign
/ 4) + 1;
1601 hdr
[1].dwBufferLength
= hdr
[0].dwBufferLength
- 2;
1602 hdr
[1].lpData
= hdr
[0].lpData
=
1603 HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, hdr
[0].dwBufferLength
);
1605 rc
= waveOutPrepareHeader(wout
, &hdr
[0], sizeof(hdr
[0]));
1606 ok(rc
== MMSYSERR_NOERROR
, "waveOutPrepareHeader failed: %s\n", wave_out_error(rc
));
1608 rc
= waveOutPrepareHeader(wout
, &hdr
[1], sizeof(hdr
[1]));
1609 ok(rc
== MMSYSERR_NOERROR
, "waveOutPrepareHeader failed: %s\n", wave_out_error(rc
));
1611 trace("writing %u bytes then %u bytes\n", hdr
[0].dwBufferLength
, hdr
[1].dwBufferLength
);
1612 rc
= waveOutWrite(wout
, &hdr
[0], sizeof(hdr
[0]));
1613 ok(rc
== MMSYSERR_NOERROR
, "waveOutWrite failed: %s\n", wave_out_error(rc
));
1615 rc
= waveOutWrite(wout
, &hdr
[1], sizeof(hdr
[1]));
1616 ok(rc
== MMSYSERR_NOERROR
, "waveOutWrite failed: %s\n", wave_out_error(rc
));
1618 wait
= WaitForSingleObject(hevent
, 1000);
1619 ok(wait
== WAIT_OBJECT_0
, "header 1 callback missed\n");
1621 wait
= WaitForSingleObject(hevent
, 1000);
1622 ok(wait
== WAIT_OBJECT_0
, "header 2 callback missed\n");
1624 memset(&mmtime
, 0, sizeof(mmtime
));
1625 mmtime
.wType
= TIME_BYTES
;
1627 rc
= waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
1628 ok(rc
== MMSYSERR_NOERROR
, "waveOutGetPosition failed: %s\n", wave_out_error(rc
));
1630 /* windows behavior is inconsistent */
1631 ok(mmtime
.u
.cb
== 88200 ||
1632 mmtime
.u
.cb
== 88196, "after position: %u\n", mmtime
.u
.cb
);
1634 rc
= waveOutClose(wout
);
1635 ok(rc
== MMSYSERR_NOERROR
, "waveOutClose failed: %s\n", wave_out_error(rc
));
1637 HeapFree(GetProcessHeap(), 0, hdr
[0].lpData
);
1638 CloseHandle(hevent
);
1641 static void create_wav_file(char *temp_file
)
1643 WAVEFORMATEX format
;
1645 MMCKINFO riff_chunk
, chunk
;
1651 format
.wFormatTag
=WAVE_FORMAT_PCM
;
1654 format
.wBitsPerSample
=8;
1655 format
.nSamplesPerSec
=8000;
1656 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
1657 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
1659 h
= mmioOpenA(temp_file
, NULL
, MMIO_ALLOCBUF
| MMIO_WRITE
| MMIO_CREATE
);
1660 ok(h
!= NULL
, "Can't open temp_file\n");
1662 riff_chunk
.fccType
= mmioFOURCC('W','A','V','E');
1663 riff_chunk
.cksize
= 0;
1664 rc
= mmioCreateChunk(h
, &riff_chunk
, MMIO_CREATERIFF
);
1665 ok(rc
== MMSYSERR_NOERROR
, "mmioCreateChunk failed, got %u\n", rc
);
1667 chunk
.ckid
= mmioFOURCC('f','m','t',' ');
1669 rc
= mmioCreateChunk(h
, &chunk
, 0);
1670 ok(rc
== MMSYSERR_NOERROR
, "mmioCreateChunk failed, got %u\n", rc
);
1671 written
= mmioWrite(h
, (char*)&format
, sizeof(format
));
1672 ok(written
== sizeof(format
), "mmioWrite failed, got %d\n", written
);
1673 rc
= mmioAscend(h
, &chunk
, 0);
1674 ok(rc
== MMSYSERR_NOERROR
, "mmioAscend failed, got %d\n", rc
);
1676 chunk
.ckid
= mmioFOURCC('d','a','t','a');
1677 rc
= mmioCreateChunk(h
, &chunk
, 0);
1678 ok(rc
== MMSYSERR_NOERROR
, "mmioCreateChunk failed, got %u\n", rc
);
1679 buffer
= wave_generate_silence(&format
, .1, &length
);
1680 written
= mmioWrite(h
, buffer
, length
);
1681 ok(written
== length
, "mmioWrite failed, got %d\n", written
);
1682 rc
= mmioAscend(h
, &chunk
, 0);
1683 ok(rc
== MMSYSERR_NOERROR
, "mmioAscend failed, got %d\n", rc
);
1684 HeapFree(GetProcessHeap(), 0, buffer
);
1686 rc
= mmioAscend(h
, &riff_chunk
, 0);
1687 ok(rc
== MMSYSERR_NOERROR
, "mmioAscend failed, got %d\n", rc
);
1689 rc
= mmioClose(h
, 0);
1690 ok(rc
== MMSYSERR_NOERROR
, "mmioClose failed, got %u\n", rc
);
1693 static void test_PlaySound(void)
1696 char test_file
[MAX_PATH
], temp
[MAX_PATH
], *exts
;
1697 void *psound_ordinal
, *psound_name
;
1698 HMODULE dll
= GetModuleHandleA("winmm.dll");
1700 psound_name
= GetProcAddress(dll
, "PlaySound");
1701 psound_ordinal
= GetProcAddress(dll
, (LPCSTR
) 2);
1702 ok(psound_name
== psound_ordinal
, "Expected ordinal 2 to be PlaySound function\n");
1704 if(waveOutGetNumDevs() == 0) {
1705 skip("No output devices available\n");
1709 GetTempPathA(sizeof(test_file
), test_file
);
1710 strcat(test_file
, "mysound.wav");
1711 create_wav_file(test_file
);
1713 br
= PlaySoundA(test_file
, NULL
, SND_FILENAME
| SND_NODEFAULT
);
1714 ok(br
, "PlaySound failed, got %d\n", br
);
1716 /* SND_ALIAS fallbacks to SND_FILENAME */
1717 br
= PlaySoundA(test_file
, NULL
, SND_ALIAS
| SND_NODEFAULT
);
1718 ok(br
, "PlaySound failed, got %d\n", br
);
1720 strcpy(temp
, test_file
);
1721 exts
= strrchr(temp
, '.');
1725 br
= PlaySoundA(temp
, NULL
, SND_FILENAME
| SND_NODEFAULT
);
1726 ok(br
, "PlaySound failed, got %d\n", br
);
1728 /* ends with a dot */
1730 br
= PlaySoundA(temp
, NULL
, SND_FILENAME
| SND_NODEFAULT
);
1731 ok(!br
|| broken(br
), "PlaySound succeeded, got %d\n", br
);
1733 DeleteFileA(test_file
);
1738 test_multiple_waveopens();
1740 test_sndPlaySound();
1741 test_fragmentsize();