Add AppDefaults app selection to control panel
[wine/gsoc-2012-control.git] / dlls / winmm / tests / wave.c
blob111dd1c2ed9cd5314aef618499baadcc158c07e3
1 /*
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
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <math.h>
26 #include "wine/test.h"
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "winnls.h"
31 #include "mmsystem.h"
32 #define NOBITMAP
33 #include "mmddk.h"
34 #include "mmreg.h"
35 #include "ks.h"
36 #include "ksguid.h"
37 #include "ksmedia.h"
39 #include "winmm_test.h"
41 static DWORD g_tid;
43 static void test_multiple_waveopens(void)
45 HWAVEOUT handle1, handle2;
46 MMRESULT ret;
47 WAVEFORMATEX wfx;
49 wfx.wFormatTag = WAVE_FORMAT_PCM;
50 wfx.nChannels = 1;
51 wfx.nSamplesPerSec = 11025;
52 wfx.nBlockAlign = 1;
53 wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
54 wfx.wBitsPerSample = 8;
55 wfx.cbSize = 0;
57 ret = waveOutOpen(&handle1, 0, &wfx, 0, 0, 0);
58 if (ret != MMSYSERR_NOERROR)
60 skip("Could not do the duplicate waveopen test\n");
61 return;
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);
74 else
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)
93 int i,j;
94 int nb_samples;
95 char* buf;
96 char* b;
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++)
107 *b++=sample;
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++) {
111 b[0]=sample & 0xff;
112 b[1]=sample >> 8;
113 b+=2;
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++) {
118 b[0]=sample & 0xff;
119 b[1]=(sample >> 8) & 0xff;
120 b[2]=(sample >> 16) & 0xff;
121 b+=3;
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++) {
128 b[0]=sample & 0xff;
129 b[1]=(sample >> 8) & 0xff;
130 b[2]=(sample >> 16) & 0xff;
131 b[3]=(sample >> 24) & 0xff;
132 b+=4;
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;
137 sample.f=(float)y;
138 for (j = 0; j < wfx->nChannels; j++) {
139 b[0]=sample.c[0];
140 b[1]=sample.c[1];
141 b[2]=sample.c[2];
142 b[3]=sample.c[3];
143 b+=4;
147 return buf;
150 static char* wave_generate_silence(WAVEFORMATEX* wfx, double duration, DWORD* size)
152 int i,j;
153 int nb_samples;
154 char* buf;
155 char* b;
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++)
164 *b++=128;
165 } else if (wfx->wBitsPerSample==16) {
166 for (j = 0; j < wfx->nChannels; j++) {
167 b[0]=0;
168 b[1]=0;
169 b+=2;
171 } else if (wfx->wBitsPerSample==24) {
172 for (j = 0; j < wfx->nChannels; j++) {
173 b[0]=0;
174 b[1]=0;
175 b[2]=0;
176 b+=3;
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++) {
182 b[0]=0;
183 b[1]=0;
184 b[2]=0;
185 b[3]=0;
186 b+=4;
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;
191 sample.f=0;
192 for (j = 0; j < wfx->nChannels; j++) {
193 b[0]=sample.c[0];
194 b[1]=sample.c[1];
195 b[2]=sample.c[2];
196 b[3]=sample.c[3];
197 b+=4;
201 return buf;
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);
210 return name;
213 const char* mmsys_error(MMRESULT error)
215 #define ERR_TO_STR(dev) case dev: return #dev
216 static char unknown[32];
217 switch (error) {
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);
259 return unknown;
260 #undef ERR_TO_STR
263 const char* wave_out_error(MMRESULT error)
265 static char msg[1024];
266 static char long_msg[1100];
267 MMRESULT rc;
269 rc = waveOutGetErrorText(error, msg, sizeof(msg));
270 if (rc != MMSYSERR_NOERROR)
271 sprintf(long_msg, "waveOutGetErrorText(%x) failed with error %x",
272 error, rc);
273 else
274 sprintf(long_msg, "%s(%s)", mmsys_error(error), msg);
275 return long_msg;
278 const char * wave_open_flags(DWORD flags)
280 static char msg[1024];
281 int first = TRUE;
282 msg[0] = 0;
283 if ((flags & CALLBACK_TYPEMASK) == CALLBACK_EVENT) {
284 strcat(msg, "CALLBACK_EVENT");
285 first = FALSE;
287 if ((flags & CALLBACK_TYPEMASK) == CALLBACK_FUNCTION) {
288 if (!first) strcat(msg, "|");
289 strcat(msg, "CALLBACK_FUNCTION");
290 first = FALSE;
292 if ((flags & CALLBACK_TYPEMASK) == CALLBACK_NULL) {
293 if (!first) strcat(msg, "|");
294 strcat(msg, "CALLBACK_NULL");
295 first = FALSE;
297 if ((flags & CALLBACK_TYPEMASK) == CALLBACK_THREAD) {
298 if (!first) strcat(msg, "|");
299 strcat(msg, "CALLBACK_THREAD");
300 first = FALSE;
302 if ((flags & CALLBACK_TYPEMASK) == CALLBACK_WINDOW) {
303 if (!first) strcat(msg, "|");
304 strcat(msg, "CALLBACK_WINDOW");
305 first = FALSE;
307 if ((flags & WAVE_ALLOWSYNC) == WAVE_ALLOWSYNC) {
308 if (!first) strcat(msg, "|");
309 strcat(msg, "WAVE_ALLOWSYNC");
310 first = FALSE;
312 if ((flags & WAVE_FORMAT_DIRECT) == WAVE_FORMAT_DIRECT) {
313 if (!first) strcat(msg, "|");
314 strcat(msg, "WAVE_FORMAT_DIRECT");
315 first = FALSE;
317 if ((flags & WAVE_FORMAT_QUERY) == WAVE_FORMAT_QUERY) {
318 if (!first) strcat(msg, "|");
319 strcat(msg, "WAVE_FORMAT_QUERY");
320 first = FALSE;
322 if ((flags & WAVE_MAPPED) == WAVE_MAPPED) {
323 if (!first) strcat(msg, "|");
324 strcat(msg, "WAVE_MAPPED");
326 return msg;
329 static const char * wave_header_flags(DWORD flags)
331 #define WHDR_MASK (WHDR_BEGINLOOP|WHDR_DONE|WHDR_ENDLOOP|WHDR_INQUEUE|WHDR_PREPARED)
332 static char msg[1024];
333 int first = TRUE;
334 msg[0] = 0;
335 if (flags & WHDR_BEGINLOOP) {
336 strcat(msg, "WHDR_BEGINLOOP");
337 first = FALSE;
339 if (flags & WHDR_DONE) {
340 if (!first) strcat(msg, " ");
341 strcat(msg, "WHDR_DONE");
342 first = FALSE;
344 if (flags & WHDR_ENDLOOP) {
345 if (!first) strcat(msg, " ");
346 strcat(msg, "WHDR_ENDLOOP");
347 first = FALSE;
349 if (flags & WHDR_INQUEUE) {
350 if (!first) strcat(msg, " ");
351 strcat(msg, "WHDR_INQUEUE");
352 first = FALSE;
354 if (flags & WHDR_PREPARED) {
355 if (!first) strcat(msg, " ");
356 strcat(msg, "WHDR_PREPARED");
357 first = FALSE;
359 if (flags & ~WHDR_MASK) {
360 char temp[32];
361 sprintf(temp, "UNKNOWN(0x%08x)", flags & ~WHDR_MASK);
362 if (!first) strcat(msg, " ");
363 strcat(msg, temp);
365 return msg;
368 static const char * wave_out_caps(DWORD dwSupport)
370 #define ADD_FLAG(f) if (dwSupport & f) strcat(msg, " " #f)
371 static char msg[256];
372 msg[0] = 0;
374 ADD_FLAG(WAVECAPS_PITCH);
375 ADD_FLAG(WAVECAPS_PLAYBACKRATE);
376 ADD_FLAG(WAVECAPS_VOLUME);
377 ADD_FLAG(WAVECAPS_LRVOLUME);
378 ADD_FLAG(WAVECAPS_SYNC);
379 ADD_FLAG(WAVECAPS_SAMPLEACCURATE);
381 return msg[0] ? msg + 1 : "";
382 #undef ADD_FLAG
385 const char * wave_time_format(UINT type)
387 static char msg[32];
388 #define TIME_FORMAT(f) case f: return #f
389 switch (type) {
390 TIME_FORMAT(TIME_MS);
391 TIME_FORMAT(TIME_SAMPLES);
392 TIME_FORMAT(TIME_BYTES);
393 TIME_FORMAT(TIME_SMPTE);
394 TIME_FORMAT(TIME_MIDI);
395 TIME_FORMAT(TIME_TICKS);
397 #undef TIME_FORMAT
398 sprintf(msg, "Unknown(0x%04x)", type);
399 return msg;
402 const char * get_format_str(WORD format)
404 static char msg[32];
405 #define WAVE_FORMAT(f) case f: return #f
406 switch (format) {
407 WAVE_FORMAT(WAVE_FORMAT_PCM);
408 WAVE_FORMAT(WAVE_FORMAT_ADPCM);
409 WAVE_FORMAT(WAVE_FORMAT_IBM_CVSD);
410 WAVE_FORMAT(WAVE_FORMAT_ALAW);
411 WAVE_FORMAT(WAVE_FORMAT_MULAW);
412 WAVE_FORMAT(WAVE_FORMAT_OKI_ADPCM);
413 WAVE_FORMAT(WAVE_FORMAT_IMA_ADPCM);
414 WAVE_FORMAT(WAVE_FORMAT_MEDIASPACE_ADPCM);
415 WAVE_FORMAT(WAVE_FORMAT_SIERRA_ADPCM);
416 WAVE_FORMAT(WAVE_FORMAT_G723_ADPCM);
417 WAVE_FORMAT(WAVE_FORMAT_DIGISTD);
418 WAVE_FORMAT(WAVE_FORMAT_DIGIFIX);
419 WAVE_FORMAT(WAVE_FORMAT_DIALOGIC_OKI_ADPCM);
420 WAVE_FORMAT(WAVE_FORMAT_YAMAHA_ADPCM);
421 WAVE_FORMAT(WAVE_FORMAT_SONARC);
422 WAVE_FORMAT(WAVE_FORMAT_DSPGROUP_TRUESPEECH);
423 WAVE_FORMAT(WAVE_FORMAT_ECHOSC1);
424 WAVE_FORMAT(WAVE_FORMAT_AUDIOFILE_AF36);
425 WAVE_FORMAT(WAVE_FORMAT_APTX);
426 WAVE_FORMAT(WAVE_FORMAT_AUDIOFILE_AF10);
427 WAVE_FORMAT(WAVE_FORMAT_DOLBY_AC2);
428 WAVE_FORMAT(WAVE_FORMAT_GSM610);
429 WAVE_FORMAT(WAVE_FORMAT_ANTEX_ADPCME);
430 WAVE_FORMAT(WAVE_FORMAT_CONTROL_RES_VQLPC);
431 WAVE_FORMAT(WAVE_FORMAT_DIGIREAL);
432 WAVE_FORMAT(WAVE_FORMAT_DIGIADPCM);
433 WAVE_FORMAT(WAVE_FORMAT_CONTROL_RES_CR10);
434 WAVE_FORMAT(WAVE_FORMAT_NMS_VBXADPCM);
435 WAVE_FORMAT(WAVE_FORMAT_G721_ADPCM);
436 WAVE_FORMAT(WAVE_FORMAT_MPEG);
437 WAVE_FORMAT(WAVE_FORMAT_MPEGLAYER3);
438 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_ADPCM);
439 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_FASTSPEECH8);
440 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_FASTSPEECH10);
441 WAVE_FORMAT(WAVE_FORMAT_FM_TOWNS_SND);
442 WAVE_FORMAT(WAVE_FORMAT_OLIGSM);
443 WAVE_FORMAT(WAVE_FORMAT_OLIADPCM);
444 WAVE_FORMAT(WAVE_FORMAT_OLICELP);
445 WAVE_FORMAT(WAVE_FORMAT_OLISBC);
446 WAVE_FORMAT(WAVE_FORMAT_OLIOPR);
447 WAVE_FORMAT(WAVE_FORMAT_DEVELOPMENT);
448 WAVE_FORMAT(WAVE_FORMAT_EXTENSIBLE);
450 #undef WAVE_FORMAT
451 sprintf(msg, "Unknown(0x%04x)", format);
452 return msg;
455 DWORD bytes_to_samples(DWORD bytes, LPWAVEFORMATEX pwfx)
457 return bytes / pwfx->nBlockAlign;
460 DWORD bytes_to_ms(DWORD bytes, LPWAVEFORMATEX pwfx)
462 return bytes_to_samples(bytes, pwfx) * 1000 / pwfx->nSamplesPerSec;
465 DWORD time_to_bytes(LPMMTIME mmtime, LPWAVEFORMATEX pwfx)
467 if (mmtime->wType == TIME_BYTES)
468 return mmtime->u.cb;
469 else if (mmtime->wType == TIME_SAMPLES)
470 return mmtime->u.sample * pwfx->nBlockAlign;
471 else if (mmtime->wType == TIME_MS)
472 return mmtime->u.ms * pwfx->nAvgBytesPerSec / 1000;
473 else if (mmtime->wType == TIME_SMPTE)
474 return ((mmtime->u.smpte.hour * 60 * 60) +
475 (mmtime->u.smpte.min * 60) +
476 (mmtime->u.smpte.sec)) * pwfx->nAvgBytesPerSec +
477 mmtime->u.smpte.frame * pwfx->nAvgBytesPerSec / 30;
479 trace("FIXME: time_to_bytes() type not supported\n");
480 return -1;
483 static void check_position(int device, HWAVEOUT wout, DWORD bytes,
484 LPWAVEFORMATEX pwfx )
486 MMTIME mmtime;
487 MMRESULT rc;
488 DWORD returned;
490 mmtime.wType = TIME_BYTES;
491 rc=waveOutGetPosition(wout, &mmtime, sizeof(mmtime));
492 ok(rc==MMSYSERR_NOERROR,
493 "waveOutGetPosition(%s): rc=%s\n",dev_name(device),wave_out_error(rc));
494 if (mmtime.wType != TIME_BYTES && winetest_debug > 1)
495 trace("waveOutGetPosition(%s): TIME_BYTES not supported, returned %s\n",
496 dev_name(device),wave_time_format(mmtime.wType));
497 returned = time_to_bytes(&mmtime, pwfx);
498 ok(returned == bytes, "waveOutGetPosition(%s): returned %d bytes, "
499 "should be %d\n", dev_name(device), returned, bytes);
501 mmtime.wType = TIME_SAMPLES;
502 rc=waveOutGetPosition(wout, &mmtime, sizeof(mmtime));
503 ok(rc==MMSYSERR_NOERROR,
504 "waveOutGetPosition(%s): rc=%s\n",dev_name(device),wave_out_error(rc));
505 if (mmtime.wType != TIME_SAMPLES && winetest_debug > 1)
506 trace("waveOutGetPosition(%s): TIME_SAMPLES not supported, "
507 "returned %s\n",dev_name(device),wave_time_format(mmtime.wType));
508 returned = time_to_bytes(&mmtime, pwfx);
509 ok(returned == bytes, "waveOutGetPosition(%s): returned %d samples "
510 "(%d bytes), should be %d (%d bytes)\n", dev_name(device),
511 bytes_to_samples(returned, pwfx), returned,
512 bytes_to_samples(bytes, pwfx), bytes);
514 mmtime.wType = TIME_MS;
515 rc=waveOutGetPosition(wout, &mmtime, sizeof(mmtime));
516 ok(rc==MMSYSERR_NOERROR,
517 "waveOutGetPosition(%s): rc=%s\n",dev_name(device),wave_out_error(rc));
518 if (mmtime.wType != TIME_MS && winetest_debug > 1)
519 trace("waveOutGetPosition(%s): TIME_MS not supported, returned %s\n",
520 dev_name(device), wave_time_format(mmtime.wType));
521 returned = time_to_bytes(&mmtime, pwfx);
522 ok(returned == bytes, "waveOutGetPosition(%s): returned %d ms, "
523 "(%d bytes), should be %d (%d bytes)\n", dev_name(device),
524 bytes_to_ms(returned, pwfx), returned,
525 bytes_to_ms(bytes, pwfx), bytes);
527 mmtime.wType = TIME_SMPTE;
528 rc=waveOutGetPosition(wout, &mmtime, sizeof(mmtime));
529 ok(rc==MMSYSERR_NOERROR,
530 "waveOutGetPosition(%s): rc=%s\n",dev_name(device),wave_out_error(rc));
531 if (mmtime.wType != TIME_SMPTE && winetest_debug > 1)
532 trace("waveOutGetPosition(%s): TIME_SMPTE not supported, returned %s\n",
533 dev_name(device),wave_time_format(mmtime.wType));
534 returned = time_to_bytes(&mmtime, pwfx);
535 ok(returned == bytes, "waveOutGetPosition(%s): SMPTE test failed\n",
536 dev_name(device));
538 mmtime.wType = TIME_MIDI;
539 rc=waveOutGetPosition(wout, &mmtime, sizeof(mmtime));
540 ok(rc==MMSYSERR_NOERROR,
541 "waveOutGetPosition(%s): rc=%s\n",dev_name(device),wave_out_error(rc));
542 if (mmtime.wType != TIME_MIDI && winetest_debug > 1)
543 trace("waveOutGetPosition(%s): TIME_MIDI not supported, returned %s\n",
544 dev_name(device),wave_time_format(mmtime.wType));
545 returned = time_to_bytes(&mmtime, pwfx);
546 ok(returned == bytes, "waveOutGetPosition(%s): MIDI test failed\n",
547 dev_name(device));
549 mmtime.wType = TIME_TICKS;
550 rc=waveOutGetPosition(wout, &mmtime, sizeof(mmtime));
551 ok(rc==MMSYSERR_NOERROR,
552 "waveOutGetPosition(%s): rc=%s\n",dev_name(device),wave_out_error(rc));
553 if (mmtime.wType != TIME_TICKS && winetest_debug > 1)
554 trace("waveOutGetPosition(%s): TIME_TICKS not supported, returned %s\n",
555 dev_name(device),wave_time_format(mmtime.wType));
556 returned = time_to_bytes(&mmtime, pwfx);
557 ok(returned == bytes, "waveOutGetPosition(%s): TICKS test failed\n",
558 dev_name(device));
561 static void CALLBACK callback_func(HWAVEOUT hwo, UINT uMsg,
562 DWORD_PTR dwInstance,
563 DWORD dwParam1, DWORD dwParam2)
565 if(uMsg == WOM_OPEN || uMsg == WOM_CLOSE)
566 ok(GetCurrentThreadId() == g_tid, "Got different thread ID\n");
567 SetEvent((HANDLE)dwInstance);
570 static DWORD WINAPI callback_thread(LPVOID lpParameter)
572 MSG msg;
574 PeekMessageW( &msg, 0, 0, 0, PM_NOREMOVE ); /* make sure the thread has a message queue */
575 SetEvent(lpParameter);
577 while (GetMessage(&msg, 0, 0, 0)) {
578 UINT message = msg.message;
579 /* for some reason XP sends a WM_USER message before WOM_OPEN */
580 ok (message == WOM_OPEN || message == WOM_DONE ||
581 message == WOM_CLOSE || message == WM_USER || message == WM_APP,
582 "GetMessage returned unexpected message: %u\n", message);
583 if (message == WOM_OPEN || message == WOM_DONE || message == WOM_CLOSE)
584 SetEvent(lpParameter);
585 else if (message == WM_APP) {
586 SetEvent(lpParameter);
587 return 0;
591 return 0;
594 static void wave_out_test_deviceOut(int device, double duration,
595 int headers, int loops,
596 LPWAVEFORMATEX pwfx, DWORD format,
597 DWORD flags, LPWAVEOUTCAPS pcaps,
598 BOOL interactive, BOOL sine, BOOL pause)
600 HWAVEOUT wout;
601 HANDLE hevent;
602 WAVEHDR *frags = 0;
603 MMRESULT rc;
604 DWORD volume;
605 WORD nChannels = pwfx->nChannels;
606 WORD wBitsPerSample = pwfx->wBitsPerSample;
607 DWORD nSamplesPerSec = pwfx->nSamplesPerSec;
608 BOOL has_volume = pcaps->dwSupport & WAVECAPS_VOLUME ? TRUE : FALSE;
609 double paused = 0.0;
610 DWORD_PTR callback = 0;
611 DWORD_PTR callback_instance = 0;
612 HANDLE thread = 0;
613 DWORD thread_id;
614 char * buffer;
615 DWORD length;
616 DWORD frag_length;
617 int i, j;
619 hevent=CreateEvent(NULL,FALSE,FALSE,NULL);
620 ok(hevent!=NULL,"CreateEvent(): error=%d\n",GetLastError());
621 if (hevent==NULL)
622 return;
624 if ((flags & CALLBACK_TYPEMASK) == CALLBACK_EVENT) {
625 callback = (DWORD_PTR)hevent;
626 callback_instance = 0;
627 } else if ((flags & CALLBACK_TYPEMASK) == CALLBACK_FUNCTION) {
628 callback = (DWORD_PTR)callback_func;
629 callback_instance = (DWORD_PTR)hevent;
630 } else if ((flags & CALLBACK_TYPEMASK) == CALLBACK_THREAD) {
631 thread = CreateThread(NULL, 0, callback_thread, hevent, 0, &thread_id);
632 if (thread) {
633 /* make sure thread is running */
634 WaitForSingleObject(hevent,10000);
635 callback = thread_id;
636 callback_instance = 0;
637 } else {
638 trace("CreateThread() failed\n");
639 CloseHandle(hevent);
640 return;
642 } else if ((flags & CALLBACK_TYPEMASK) == CALLBACK_WINDOW) {
643 trace("CALLBACK_THREAD not implemented\n");
644 CloseHandle(hevent);
645 return;
646 } else if (flags & CALLBACK_TYPEMASK) {
647 trace("Undefined callback type!\n");
648 CloseHandle(hevent);
649 return;
650 } else {
651 trace("CALLBACK_NULL not implemented\n");
652 CloseHandle(hevent);
653 return;
655 wout=NULL;
656 g_tid = GetCurrentThreadId();
657 rc=waveOutOpen(&wout,device,pwfx,callback,callback_instance,flags);
658 /* Note: Win9x doesn't know WAVE_FORMAT_DIRECT */
659 /* It is acceptable to fail on formats that are not specified to work */
660 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_BADDEVICEID ||
661 rc==MMSYSERR_NOTENABLED || rc==MMSYSERR_NODRIVER ||
662 rc==MMSYSERR_ALLOCATED ||
663 ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
664 (flags & WAVE_FORMAT_DIRECT) && !(pcaps->dwFormats & format)) ||
665 ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
666 (!(flags & WAVE_FORMAT_DIRECT) || (flags & WAVE_MAPPED)) &&
667 !(pcaps->dwFormats & format)) ||
668 (rc==MMSYSERR_INVALFLAG && (flags & WAVE_FORMAT_DIRECT)),
669 "waveOutOpen(%s): format=%dx%2dx%d flags=%x(%s) rc=%s\n",
670 dev_name(device),pwfx->nSamplesPerSec,pwfx->wBitsPerSample,
671 pwfx->nChannels,CALLBACK_EVENT|flags,
672 wave_open_flags(CALLBACK_EVENT|flags),wave_out_error(rc));
673 if ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
674 (flags & WAVE_FORMAT_DIRECT) && (pcaps->dwFormats & format))
675 trace(" Reason: The device lists this format as supported in it's "
676 "capabilities but opening it failed.\n");
677 if ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
678 !(pcaps->dwFormats & format))
679 trace("waveOutOpen(%s): format=%dx%2dx%d %s rc=%s failed but format "
680 "not supported so OK.\n", dev_name(device), pwfx->nSamplesPerSec,
681 pwfx->wBitsPerSample,pwfx->nChannels,
682 flags & WAVE_FORMAT_DIRECT ? "flags=WAVE_FORMAT_DIRECT" :
683 flags & WAVE_MAPPED ? "flags=WAVE_MAPPED" : "", mmsys_error(rc));
684 if (rc!=MMSYSERR_NOERROR)
685 goto EXIT;
687 rc=WaitForSingleObject(hevent,9000);
688 ok(rc==WAIT_OBJECT_0, "missing WOM_OPEN notification\n");
690 ok(pwfx->nChannels==nChannels &&
691 pwfx->wBitsPerSample==wBitsPerSample &&
692 pwfx->nSamplesPerSec==nSamplesPerSec,
693 "got the wrong format: %dx%2dx%d instead of %dx%2dx%d\n",
694 pwfx->nSamplesPerSec, pwfx->wBitsPerSample,
695 pwfx->nChannels, nSamplesPerSec, wBitsPerSample, nChannels);
697 frags = HeapAlloc(GetProcessHeap(), 0, headers * sizeof(WAVEHDR));
699 if (sine)
700 buffer=wave_generate_la(pwfx,duration / (loops + 1),&length);
701 else
702 buffer=wave_generate_silence(pwfx,duration / (loops + 1),&length);
704 rc=waveOutGetVolume(wout,0);
705 ok(rc==MMSYSERR_INVALPARAM,"waveOutGetVolume(%s,0) expected "
706 "MMSYSERR_INVALPARAM, got %s\n", dev_name(device),wave_out_error(rc));
707 rc=waveOutGetVolume(wout,&volume);
708 if (rc == MMSYSERR_NOTSUPPORTED) has_volume = FALSE;
709 ok(has_volume ? rc==MMSYSERR_NOERROR : rc==MMSYSERR_NOTSUPPORTED,
710 "waveOutGetVolume(%s): rc=%s\n",dev_name(device),wave_out_error(rc));
712 /* make sure fragment length is a multiple of block size */
713 frag_length = ((length / headers) / pwfx->nBlockAlign) * pwfx->nBlockAlign;
715 for (i = 0; i < headers; i++) {
716 frags[i].lpData=buffer + (i * frag_length);
717 if (i != (headers-1))
718 frags[i].dwBufferLength=frag_length;
719 else {
720 /* use remainder of buffer for last fragment */
721 frags[i].dwBufferLength=length - (i * frag_length);
723 frags[i].dwFlags=0;
724 frags[i].dwLoops=0;
725 rc=waveOutPrepareHeader(wout, &frags[i], sizeof(frags[0]));
726 ok(rc==MMSYSERR_NOERROR,
727 "waveOutPrepareHeader(%s): rc=%s\n",dev_name(device),wave_out_error(rc));
730 if (interactive && rc==MMSYSERR_NOERROR) {
731 trace("Playing %g second %s at %5dx%2dx%d %2d header%s %d loop%s %d bytes %s %s\n",duration,
732 sine ? "440Hz tone" : "silence",pwfx->nSamplesPerSec,
733 pwfx->wBitsPerSample,pwfx->nChannels, headers, headers > 1 ? "s": " ",
734 loops, loops == 1 ? " " : "s", length * (loops + 1),
735 get_format_str(pwfx->wFormatTag),
736 wave_open_flags(flags));
737 if (sine && has_volume && volume == 0)
738 trace("*** Warning the sound is muted, you will not hear the test\n");
740 /* Check that the position is 0 at start */
741 check_position(device, wout, 0, pwfx);
743 rc=waveOutSetVolume(wout,0x20002000);
744 ok(has_volume ? rc==MMSYSERR_NOERROR : rc==MMSYSERR_NOTSUPPORTED,
745 "waveOutSetVolume(%s): rc=%s\n",dev_name(device),wave_out_error(rc));
747 rc=waveOutSetVolume(wout,volume);
748 ok(has_volume ? rc==MMSYSERR_NOERROR : rc==MMSYSERR_NOTSUPPORTED,
749 "waveOutSetVolume(%s): rc=%s\n",dev_name(device),wave_out_error(rc));
751 rc=waveOutWrite(wout, &frags[0], sizeof(frags[0]));
752 ok(rc==MMSYSERR_NOERROR,"waveOutWrite(%s): rc=%s\n",
753 dev_name(device),wave_out_error(rc));
755 ok(frags[0].dwFlags==(WHDR_PREPARED|WHDR_INQUEUE),
756 "WHDR_INQUEUE WHDR_PREPARED expected, got= %s\n",
757 wave_header_flags(frags[0].dwFlags));
759 rc=waveOutWrite(wout, &frags[0], sizeof(frags[0]));
760 ok(rc==WAVERR_STILLPLAYING,
761 "waveOutWrite(%s): WAVE_STILLPLAYING expected, got %s\n",
762 dev_name(device),wave_out_error(rc));
764 ok(frags[0].dwFlags==(WHDR_PREPARED|WHDR_INQUEUE),
765 "WHDR_INQUEUE WHDR_PREPARED expected, got %s\n",
766 wave_header_flags(frags[0].dwFlags));
768 if (headers == 1 && loops == 0 && pause) {
769 paused = duration / 2;
770 Sleep(paused * 1000);
771 rc=waveOutPause(wout);
772 ok(rc==MMSYSERR_NOERROR,"waveOutPause(%s): rc=%s\n",
773 dev_name(device),wave_out_error(rc));
774 trace("pausing for %g seconds\n", paused);
775 Sleep(paused * 1000);
776 rc=waveOutRestart(wout);
777 ok(rc==MMSYSERR_NOERROR,"waveOutRestart(%s): rc=%s\n",
778 dev_name(device),wave_out_error(rc));
781 for (j = 0; j <= loops; j++) {
782 for (i = 0; i < headers; i++) {
783 /* don't do last one */
784 if (!((j == loops) && (i == (headers - 1)))) {
785 if (j > 0)
786 frags[(i+1) % headers].dwFlags = WHDR_PREPARED;
787 rc=waveOutWrite(wout, &frags[(i+1) % headers], sizeof(frags[0]));
788 ok(rc==MMSYSERR_NOERROR,"waveOutWrite(%s, header[%d]): rc=%s\n",
789 dev_name(device),(i+1)%headers,wave_out_error(rc));
791 rc=WaitForSingleObject(hevent,8000);
792 ok(rc==WAIT_OBJECT_0, "missing WOM_DONE notification\n");
796 for (i = 0; i < headers; i++) {
797 ok(frags[i].dwFlags==(WHDR_DONE|WHDR_PREPARED) ||
798 broken((flags & CALLBACK_TYPEMASK)==CALLBACK_EVENT &&
799 frags[i].dwFlags==(WHDR_DONE|WHDR_PREPARED|0x1000)), /* < NT4 */
800 "(%02d) WHDR_DONE WHDR_PREPARED expected, got %s\n",
801 i, wave_header_flags(frags[i].dwFlags));
803 check_position(device, wout, length * (loops + 1), pwfx);
806 for (i = 0; i < headers; i++) {
807 rc=waveOutUnprepareHeader(wout, &frags[i], sizeof(frags[0]));
808 ok(rc==MMSYSERR_NOERROR,
809 "waveOutUnprepareHeader(%s): rc=%s\n",dev_name(device),
810 wave_out_error(rc));
812 rc=waveOutClose(wout);
813 ok(rc==MMSYSERR_NOERROR,"waveOutClose(%s): rc=%s\n",dev_name(device),
814 wave_out_error(rc));
815 if (rc==WAVERR_STILLPLAYING) {
816 /* waveOutReset ought to return all buffers s.t. waveOutClose succeeds */
817 rc=waveOutReset(wout);
818 ok(rc==MMSYSERR_NOERROR,"waveOutReset(%s): rc=%s\n",dev_name(device),
819 wave_out_error(rc));
821 for (i = 0; i < headers; i++) {
822 rc=waveOutUnprepareHeader(wout, &frags[i], sizeof(frags[0]));
823 ok(rc==MMSYSERR_NOERROR,
824 "waveOutUnprepareHeader(%s): rc=%s\n",dev_name(device),
825 wave_out_error(rc));
827 rc=waveOutClose(wout);
828 ok(rc==MMSYSERR_NOERROR,"waveOutClose(%s): rc=%s\n",dev_name(device),
829 wave_out_error(rc));
831 rc=WaitForSingleObject(hevent,1500);
832 ok(rc==WAIT_OBJECT_0, "missing WOM_CLOSE notification\n");
834 HeapFree(GetProcessHeap(), 0, buffer);
835 EXIT:
836 if ((flags & CALLBACK_TYPEMASK) == CALLBACK_THREAD) {
837 PostThreadMessage(thread_id, WM_APP, 0, 0);
838 WaitForSingleObject(hevent,10000);
840 CloseHandle(hevent);
841 HeapFree(GetProcessHeap(), 0, frags);
844 static void wave_out_test_device(UINT_PTR device)
846 WAVEOUTCAPSA capsA;
847 WAVEOUTCAPSW capsW;
848 WAVEFORMATEX format;
849 WAVEFORMATEXTENSIBLE wfex;
850 IMAADPCMWAVEFORMAT wfa;
851 HWAVEOUT wout;
852 MMRESULT rc;
853 UINT f;
854 WCHAR * nameW;
855 CHAR * nameA;
856 DWORD size;
857 DWORD dwPageSize;
858 BYTE * twoPages;
859 SYSTEM_INFO sSysInfo;
860 DWORD flOldProtect;
861 BOOL res;
863 GetSystemInfo(&sSysInfo);
864 dwPageSize = sSysInfo.dwPageSize;
866 rc=waveOutGetDevCapsA(device,&capsA,sizeof(capsA));
867 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_BADDEVICEID ||
868 rc==MMSYSERR_NODRIVER,
869 "waveOutGetDevCapsA(%s): failed to get capabilities: rc=%s\n",
870 dev_name(device),wave_out_error(rc));
871 if (rc==MMSYSERR_BADDEVICEID || rc==MMSYSERR_NODRIVER)
872 return;
874 rc=waveOutGetDevCapsW(device,&capsW,sizeof(capsW));
875 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NOTSUPPORTED,
876 "waveOutGetDevCapsW(%s): MMSYSERR_NOERROR or MMSYSERR_NOTSUPPORTED "
877 "expected, got %s\n",dev_name(device),wave_out_error(rc));
879 rc=waveOutGetDevCapsA(device,0,sizeof(capsA));
880 ok(rc==MMSYSERR_INVALPARAM,
881 "waveOutGetDevCapsA(%s): MMSYSERR_INVALPARAM expected, "
882 "got %s\n",dev_name(device),wave_out_error(rc));
884 rc=waveOutGetDevCapsW(device,0,sizeof(capsW));
885 ok(rc==MMSYSERR_INVALPARAM || rc==MMSYSERR_NOTSUPPORTED,
886 "waveOutGetDevCapsW(%s): MMSYSERR_INVALPARAM or MMSYSERR_NOTSUPPORTED "
887 "expected, got %s\n",dev_name(device),wave_out_error(rc));
889 if (0)
891 /* FIXME: this works on windows but crashes wine */
892 rc=waveOutGetDevCapsA(device,(LPWAVEOUTCAPSA)1,sizeof(capsA));
893 ok(rc==MMSYSERR_INVALPARAM,
894 "waveOutGetDevCapsA(%s): MMSYSERR_INVALPARAM expected, got %s\n",
895 dev_name(device),wave_out_error(rc));
897 rc=waveOutGetDevCapsW(device,(LPWAVEOUTCAPSW)1,sizeof(capsW));
898 ok(rc==MMSYSERR_INVALPARAM || rc==MMSYSERR_NOTSUPPORTED,
899 "waveOutGetDevCapsW(%s): MMSYSERR_INVALPARAM or MMSYSERR_NOTSUPPORTED "
900 "expected, got %s\n",dev_name(device),wave_out_error(rc));
903 rc=waveOutGetDevCapsA(device,&capsA,4);
904 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_INVALPARAM,
905 "waveOutGetDevCapsA(%s): MMSYSERR_NOERROR or MMSYSERR_INVALPARAM "
906 "expected, got %s\n", dev_name(device),wave_out_error(rc));
908 rc=waveOutGetDevCapsW(device,&capsW,4);
909 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NOTSUPPORTED ||
910 rc==MMSYSERR_INVALPARAM, /* Vista, W2K8 */
911 "waveOutGetDevCapsW(%s): unexpected return value %s\n",
912 dev_name(device),wave_out_error(rc));
914 rc=waveOutMessage((HWAVEOUT)device, DRV_QUERYMAPPABLE, 0, 0);
915 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NOTSUPPORTED,
916 "DRV_QUERYMAPPABLE(%s): unexpected return value %s\n",
917 dev_name(device),wave_out_error(rc));
919 nameA=NULL;
920 rc=waveOutMessage((HWAVEOUT)device, DRV_QUERYDEVICEINTERFACESIZE,
921 (DWORD_PTR)&size, 0);
922 ok(rc==MMSYSERR_NOERROR || broken(rc==MMSYSERR_INVALPARAM ||
923 rc==MMSYSERR_NOTSUPPORTED),
924 "waveOutMessage(%s): failed to get interface size, rc=%s\n",
925 dev_name(device),wave_out_error(rc));
926 if (rc==MMSYSERR_NOERROR) {
927 nameW = HeapAlloc(GetProcessHeap(), 0, size);
928 rc=waveOutMessage((HWAVEOUT)device, DRV_QUERYDEVICEINTERFACE,
929 (DWORD_PTR)nameW, size);
930 ok(rc==MMSYSERR_NOERROR,"waveOutMessage(%s): failed to get interface "
931 "name, rc=%s\n",dev_name(device),wave_out_error(rc));
932 ok(lstrlenW(nameW)+1==size/sizeof(WCHAR),"got an incorrect size %d\n",size);
933 if (rc==MMSYSERR_NOERROR) {
934 nameA = HeapAlloc(GetProcessHeap(), 0, size/sizeof(WCHAR));
935 WideCharToMultiByte(CP_ACP, 0, nameW, size/sizeof(WCHAR), nameA,
936 size/sizeof(WCHAR), NULL, NULL);
938 HeapFree(GetProcessHeap(), 0, nameW);
940 else if (rc==MMSYSERR_NOTSUPPORTED) {
941 nameA=HeapAlloc(GetProcessHeap(), 0, sizeof("not supported"));
942 strcpy(nameA, "not supported");
945 rc=waveOutGetDevCapsA(device,&capsA,sizeof(capsA));
946 ok(rc==MMSYSERR_NOERROR,
947 "waveOutGetDevCapsA(%s): MMSYSERR_NOERROR expected, got %s\n",
948 dev_name(device),wave_out_error(rc));
949 if (rc!=MMSYSERR_NOERROR)
950 return;
952 trace(" %s: \"%s\" (%s) %d.%d (%d:%d)\n",dev_name(device),capsA.szPname,
953 (nameA?nameA:"failed"),capsA.vDriverVersion >> 8,
954 capsA.vDriverVersion & 0xff, capsA.wMid,capsA.wPid);
955 trace(" channels=%d formats=%05x support=%04x\n",
956 capsA.wChannels,capsA.dwFormats,capsA.dwSupport);
957 trace(" %s\n",wave_out_caps(capsA.dwSupport));
958 HeapFree(GetProcessHeap(), 0, nameA);
960 if (winetest_interactive && (device != WAVE_MAPPER))
962 trace("Playing a 5 seconds reference tone.\n");
963 trace("All subsequent tones should be identical to this one.\n");
964 trace("Listen for stutter, changes in pitch, volume, etc.\n");
965 format.wFormatTag=WAVE_FORMAT_PCM;
966 format.nChannels=1;
967 format.wBitsPerSample=8;
968 format.nSamplesPerSec=22050;
969 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
970 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
971 format.cbSize=0;
973 wave_out_test_deviceOut(device,5.0,1,0,&format,WAVE_FORMAT_2M08,
974 CALLBACK_EVENT,&capsA,TRUE,TRUE,FALSE);
975 wave_out_test_deviceOut(device,5.0,1,0,&format,WAVE_FORMAT_2M08,
976 CALLBACK_FUNCTION,&capsA,TRUE,TRUE,FALSE);
977 wave_out_test_deviceOut(device,5.0,1,0,&format,WAVE_FORMAT_2M08,
978 CALLBACK_THREAD,&capsA,TRUE,TRUE,FALSE);
980 wave_out_test_deviceOut(device,5.0,10,0,&format,WAVE_FORMAT_2M08,
981 CALLBACK_EVENT,&capsA,TRUE,TRUE,FALSE);
982 wave_out_test_deviceOut(device,5.0,5,1,&format,WAVE_FORMAT_2M08,
983 CALLBACK_EVENT,&capsA,TRUE,TRUE,FALSE);
984 } else {
985 format.wFormatTag=WAVE_FORMAT_PCM;
986 format.nChannels=1;
987 format.wBitsPerSample=8;
988 format.nSamplesPerSec=22050;
989 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
990 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
991 format.cbSize=0;
992 wave_out_test_deviceOut(device,0.6,1,0,&format,WAVE_FORMAT_2M08,
993 CALLBACK_EVENT,&capsA,TRUE,FALSE,FALSE);
994 wave_out_test_deviceOut(device,0.6,1,0,&format,WAVE_FORMAT_2M08,
995 CALLBACK_EVENT,&capsA,TRUE,FALSE,TRUE);
996 wave_out_test_deviceOut(device,0.6,1,0,&format,WAVE_FORMAT_2M08,
997 CALLBACK_FUNCTION,&capsA,TRUE,FALSE,FALSE);
998 wave_out_test_deviceOut(device,0.6,1,0,&format,WAVE_FORMAT_2M08,
999 CALLBACK_FUNCTION,&capsA,TRUE,FALSE,TRUE);
1000 wave_out_test_deviceOut(device,0.6,1,0,&format,WAVE_FORMAT_2M08,
1001 CALLBACK_THREAD,&capsA,TRUE,FALSE,FALSE);
1002 wave_out_test_deviceOut(device,0.6,1,0,&format,WAVE_FORMAT_2M08,
1003 CALLBACK_THREAD,&capsA,TRUE,FALSE,TRUE);
1005 wave_out_test_deviceOut(device,0.8,10,0,&format,WAVE_FORMAT_2M08,
1006 CALLBACK_EVENT,&capsA,TRUE,FALSE,FALSE);
1007 wave_out_test_deviceOut(device,1.0,5,1,&format,WAVE_FORMAT_2M08,
1008 CALLBACK_EVENT,&capsA,TRUE,FALSE,FALSE);
1011 for (f=0;f<NB_WIN_FORMATS;f++) {
1012 format.wFormatTag=WAVE_FORMAT_PCM;
1013 format.nChannels=win_formats[f][3];
1014 format.wBitsPerSample=win_formats[f][2];
1015 format.nSamplesPerSec=win_formats[f][1];
1016 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
1017 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
1018 format.cbSize=0;
1019 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
1020 CALLBACK_EVENT,&capsA,winetest_interactive,
1021 TRUE,FALSE);
1022 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
1023 CALLBACK_FUNCTION,&capsA,winetest_interactive,
1024 TRUE,FALSE);
1025 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
1026 CALLBACK_THREAD,&capsA,winetest_interactive,
1027 TRUE,FALSE);
1029 wave_out_test_deviceOut(device,1.0,10,0,&format,win_formats[f][0],
1030 CALLBACK_EVENT,&capsA,winetest_interactive,
1031 TRUE,FALSE);
1032 wave_out_test_deviceOut(device,1.0,5,1,&format,win_formats[f][0],
1033 CALLBACK_EVENT,&capsA,winetest_interactive,
1034 TRUE,FALSE);
1036 if (winetest_interactive) {
1037 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
1038 CALLBACK_EVENT,&capsA,winetest_interactive,
1039 TRUE,TRUE);
1040 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
1041 CALLBACK_FUNCTION,&capsA,winetest_interactive,
1042 TRUE,TRUE);
1043 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
1044 CALLBACK_THREAD,&capsA,winetest_interactive,
1045 TRUE,TRUE);
1047 wave_out_test_deviceOut(device,1.0,10,0,&format,win_formats[f][0],
1048 CALLBACK_EVENT,&capsA,winetest_interactive,
1049 TRUE,TRUE);
1050 wave_out_test_deviceOut(device,1.0,5,1,&format,win_formats[f][0],
1051 CALLBACK_EVENT,&capsA,winetest_interactive,
1052 TRUE,TRUE);
1054 if (device != WAVE_MAPPER)
1056 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
1057 CALLBACK_EVENT|WAVE_FORMAT_DIRECT,&capsA,
1058 winetest_interactive,TRUE,FALSE);
1059 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
1060 CALLBACK_EVENT|WAVE_MAPPED,&capsA,
1061 winetest_interactive,TRUE,FALSE);
1062 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
1063 CALLBACK_FUNCTION|WAVE_FORMAT_DIRECT,&capsA,
1064 winetest_interactive,TRUE,FALSE);
1065 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
1066 CALLBACK_FUNCTION|WAVE_MAPPED,&capsA,
1067 winetest_interactive,TRUE,FALSE);
1068 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
1069 CALLBACK_THREAD|WAVE_FORMAT_DIRECT,&capsA,
1070 winetest_interactive,TRUE,FALSE);
1071 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
1072 CALLBACK_THREAD|WAVE_MAPPED,&capsA,
1073 winetest_interactive,TRUE,FALSE);
1075 wave_out_test_deviceOut(device,1.0,10,0,&format,win_formats[f][0],
1076 CALLBACK_EVENT|WAVE_FORMAT_DIRECT,&capsA,
1077 winetest_interactive,TRUE,FALSE);
1078 wave_out_test_deviceOut(device,1.0,5,1,&format,win_formats[f][0],
1079 CALLBACK_EVENT|WAVE_FORMAT_DIRECT,&capsA,
1080 winetest_interactive,TRUE,FALSE);
1084 /* Try a PCMWAVEFORMAT aligned next to an unaccessible page for bounds
1085 * checking */
1086 twoPages = VirtualAlloc(NULL, 2 * dwPageSize, MEM_RESERVE | MEM_COMMIT,
1087 PAGE_READWRITE);
1088 ok(twoPages!=NULL,"Failed to allocate 2 pages of memory\n");
1089 if (twoPages) {
1090 res = VirtualProtect(twoPages + dwPageSize, dwPageSize, PAGE_NOACCESS,
1091 &flOldProtect);
1092 ok(res, "Failed to set memory access on second page\n");
1093 if (res) {
1094 LPWAVEFORMATEX pwfx = (LPWAVEFORMATEX)(twoPages + dwPageSize -
1095 sizeof(PCMWAVEFORMAT));
1096 pwfx->wFormatTag=WAVE_FORMAT_PCM;
1097 pwfx->nChannels=1;
1098 pwfx->wBitsPerSample=8;
1099 pwfx->nSamplesPerSec=22050;
1100 pwfx->nBlockAlign=pwfx->nChannels*pwfx->wBitsPerSample/8;
1101 pwfx->nAvgBytesPerSec=pwfx->nSamplesPerSec*pwfx->nBlockAlign;
1102 wave_out_test_deviceOut(device,1.0,1,0,pwfx,WAVE_FORMAT_2M08,
1103 CALLBACK_EVENT,&capsA,winetest_interactive,
1104 TRUE,FALSE);
1105 wave_out_test_deviceOut(device,1.0,10,0,pwfx,WAVE_FORMAT_2M08,
1106 CALLBACK_EVENT,&capsA,winetest_interactive,
1107 TRUE,FALSE);
1108 wave_out_test_deviceOut(device,1.0,5,1,pwfx,WAVE_FORMAT_2M08,
1109 CALLBACK_EVENT,&capsA,winetest_interactive,
1110 TRUE,FALSE);
1111 if (device != WAVE_MAPPER)
1113 wave_out_test_deviceOut(device,1.0,1,0,pwfx,WAVE_FORMAT_2M08,
1114 CALLBACK_EVENT|WAVE_FORMAT_DIRECT,
1115 &capsA,winetest_interactive,TRUE,FALSE);
1116 wave_out_test_deviceOut(device,1.0,1,0,pwfx,WAVE_FORMAT_2M08,
1117 CALLBACK_EVENT|WAVE_MAPPED,&capsA,
1118 winetest_interactive,TRUE,FALSE);
1119 wave_out_test_deviceOut(device,1.0,10,0,pwfx,WAVE_FORMAT_2M08,
1120 CALLBACK_EVENT|WAVE_FORMAT_DIRECT,
1121 &capsA,winetest_interactive,TRUE,FALSE);
1122 wave_out_test_deviceOut(device,1.0,10,0,pwfx,WAVE_FORMAT_2M08,
1123 CALLBACK_EVENT|WAVE_MAPPED,&capsA,
1124 winetest_interactive,TRUE,FALSE);
1125 wave_out_test_deviceOut(device,1.0,5,1,pwfx,WAVE_FORMAT_2M08,
1126 CALLBACK_EVENT|WAVE_FORMAT_DIRECT,
1127 &capsA,winetest_interactive,TRUE,FALSE);
1128 wave_out_test_deviceOut(device,1.0,5,1,pwfx,WAVE_FORMAT_2M08,
1129 CALLBACK_EVENT|WAVE_MAPPED,&capsA,
1130 winetest_interactive,TRUE,FALSE);
1133 VirtualFree(twoPages, 0, MEM_RELEASE);
1136 /* try some non PCM formats */
1137 format.wFormatTag=WAVE_FORMAT_MULAW;
1138 format.nChannels=1;
1139 format.wBitsPerSample=8;
1140 format.nSamplesPerSec=8000;
1141 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
1142 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
1143 format.cbSize=0;
1144 rc=waveOutOpen(&wout,device,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT);
1145 ok(rc==MMSYSERR_NOERROR ||rc==WAVERR_BADFORMAT ||
1146 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
1147 "waveOutOpen(%s): returned %s\n",dev_name(device),wave_out_error(rc));
1148 if (rc==MMSYSERR_NOERROR) {
1149 waveOutClose(wout);
1150 wave_out_test_deviceOut(device,1.0,1,0,&format,0,CALLBACK_EVENT,
1151 &capsA,winetest_interactive,TRUE,FALSE);
1152 wave_out_test_deviceOut(device,1.0,10,0,&format,0,CALLBACK_EVENT,
1153 &capsA,winetest_interactive,TRUE,FALSE);
1154 wave_out_test_deviceOut(device,1.0,5,1,&format,0,CALLBACK_EVENT,
1155 &capsA,winetest_interactive,TRUE,FALSE);
1156 } else
1157 trace("waveOutOpen(%s): WAVE_FORMAT_MULAW not supported\n",
1158 dev_name(device));
1160 wfa.wfx.wFormatTag=WAVE_FORMAT_IMA_ADPCM;
1161 wfa.wfx.nChannels=1;
1162 wfa.wfx.nSamplesPerSec=11025;
1163 wfa.wfx.nAvgBytesPerSec=5588;
1164 wfa.wfx.nBlockAlign=256;
1165 wfa.wfx.wBitsPerSample=4; /* see imaadp32.c */
1166 wfa.wfx.cbSize=2;
1167 wfa.wSamplesPerBlock=505;
1168 rc=waveOutOpen(&wout,device,&wfa.wfx,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT);
1169 ok(rc==MMSYSERR_NOERROR ||rc==WAVERR_BADFORMAT ||
1170 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
1171 "waveOutOpen(%s): returned %s\n",dev_name(device),wave_out_error(rc));
1172 if (rc==MMSYSERR_NOERROR) {
1173 waveOutClose(wout);
1174 /* TODO: teach wave_generate_* ADPCM
1175 wave_out_test_deviceOut(device,1.0,1,0,&wfa.wfx,0,CALLBACK_EVENT,
1176 &capsA,winetest_interactive,TRUE,FALSE);
1177 wave_out_test_deviceOut(device,1.0,10,0,&wfa.wfx,0,CALLBACK_EVENT,
1178 &capsA,winetest_interactive,TRUE,FALSE);
1179 wave_out_test_deviceOut(device,1.0,5,1,&wfa.wfx,0,CALLBACK_EVENT,
1180 &capsA,winetest_interactive,TRUE,FALSE);
1182 } else
1183 trace("waveOutOpen(%s): WAVE_FORMAT_IMA_ADPCM not supported\n",
1184 dev_name(device));
1186 /* test if WAVEFORMATEXTENSIBLE supported */
1187 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
1188 wfex.Format.nChannels=2;
1189 wfex.Format.wBitsPerSample=16;
1190 wfex.Format.nSamplesPerSec=22050;
1191 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
1192 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
1193 wfex.Format.nBlockAlign;
1194 wfex.Format.cbSize=22;
1195 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
1196 wfex.dwChannelMask=SPEAKER_ALL;
1197 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
1198 rc=waveOutOpen(&wout,device,&wfex.Format,0,0,
1199 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
1200 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
1201 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
1202 "waveOutOpen(%s): returned %s\n",dev_name(device),wave_out_error(rc));
1203 if (rc==MMSYSERR_NOERROR) {
1204 waveOutClose(wout);
1205 wave_out_test_deviceOut(device,1.0,1,0,&wfex.Format,WAVE_FORMAT_2M16,
1206 CALLBACK_EVENT,&capsA,winetest_interactive,
1207 TRUE,FALSE);
1208 wave_out_test_deviceOut(device,1.0,10,0,&wfex.Format,WAVE_FORMAT_2M16,
1209 CALLBACK_EVENT,&capsA,winetest_interactive,
1210 TRUE,FALSE);
1211 wave_out_test_deviceOut(device,1.0,5,1,&wfex.Format,WAVE_FORMAT_2M16,
1212 CALLBACK_EVENT,&capsA,winetest_interactive,
1213 TRUE,FALSE);
1214 } else
1215 trace("waveOutOpen(%s): WAVE_FORMAT_EXTENSIBLE not supported\n",
1216 dev_name(device));
1218 /* test if 4 channels supported */
1219 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
1220 wfex.Format.nChannels=4;
1221 wfex.Format.wBitsPerSample=16;
1222 wfex.Format.nSamplesPerSec=22050;
1223 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
1224 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
1225 wfex.Format.nBlockAlign;
1226 wfex.Format.cbSize=22;
1227 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
1228 wfex.dwChannelMask=SPEAKER_ALL;
1229 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
1230 rc=waveOutOpen(&wout,device,&wfex.Format,0,0,
1231 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
1232 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
1233 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
1234 "waveOutOpen(%s): returned %s\n",dev_name(device),wave_out_error(rc));
1235 if (rc==MMSYSERR_NOERROR) {
1236 waveOutClose(wout);
1237 wave_out_test_deviceOut(device,1.0,1,0,&wfex.Format,0,CALLBACK_EVENT,
1238 &capsA,winetest_interactive,TRUE,FALSE);
1239 wave_out_test_deviceOut(device,1.0,10,0,&wfex.Format,0,CALLBACK_EVENT,
1240 &capsA,winetest_interactive,TRUE,FALSE);
1241 wave_out_test_deviceOut(device,1.0,5,1,&wfex.Format,0,CALLBACK_EVENT,
1242 &capsA,winetest_interactive,TRUE,FALSE);
1243 } else
1244 trace("waveOutOpen(%s): 4 channels not supported\n",
1245 dev_name(device));
1247 /* test if 6 channels supported */
1248 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
1249 wfex.Format.nChannels=6;
1250 wfex.Format.wBitsPerSample=16;
1251 wfex.Format.nSamplesPerSec=22050;
1252 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
1253 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
1254 wfex.Format.nBlockAlign;
1255 wfex.Format.cbSize=22;
1256 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
1257 wfex.dwChannelMask=SPEAKER_ALL;
1258 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
1259 rc=waveOutOpen(&wout,device,&wfex.Format,0,0,
1260 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
1261 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
1262 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
1263 "waveOutOpen(%s): returned %s\n",dev_name(device),wave_out_error(rc));
1264 if (rc==MMSYSERR_NOERROR) {
1265 waveOutClose(wout);
1266 wave_out_test_deviceOut(device,1.0,1,0,&wfex.Format,WAVE_FORMAT_2M16,
1267 CALLBACK_EVENT,&capsA,winetest_interactive,
1268 TRUE,FALSE);
1269 wave_out_test_deviceOut(device,1.0,10,0,&wfex.Format,WAVE_FORMAT_2M16,
1270 CALLBACK_EVENT,&capsA,winetest_interactive,
1271 TRUE,FALSE);
1272 wave_out_test_deviceOut(device,1.0,5,1,&wfex.Format,WAVE_FORMAT_2M16,
1273 CALLBACK_EVENT,&capsA,winetest_interactive,
1274 TRUE,FALSE);
1275 } else
1276 trace("waveOutOpen(%s): 6 channels not supported\n",
1277 dev_name(device));
1279 if (0)
1281 /* FIXME: ALSA doesn't like this format */
1282 /* test if 24 bit samples supported */
1283 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
1284 wfex.Format.nChannels=2;
1285 wfex.Format.wBitsPerSample=24;
1286 wfex.Format.nSamplesPerSec=22050;
1287 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
1288 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
1289 wfex.Format.nBlockAlign;
1290 wfex.Format.cbSize=22;
1291 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
1292 wfex.dwChannelMask=SPEAKER_ALL;
1293 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
1294 rc=waveOutOpen(&wout,device,&wfex.Format,0,0,
1295 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
1296 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
1297 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
1298 "waveOutOpen(%s): returned %s\n",dev_name(device),wave_out_error(rc));
1299 if (rc==MMSYSERR_NOERROR) {
1300 waveOutClose(wout);
1301 wave_out_test_deviceOut(device,1.0,1,0,&wfex.Format,WAVE_FORMAT_2M16,
1302 CALLBACK_EVENT,&capsA,winetest_interactive,
1303 TRUE,FALSE);
1304 } else
1305 trace("waveOutOpen(%s): 24 bit samples not supported\n",
1306 dev_name(device));
1309 /* test if 32 bit samples supported */
1310 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
1311 wfex.Format.nChannels=2;
1312 wfex.Format.wBitsPerSample=32;
1313 wfex.Format.nSamplesPerSec=22050;
1314 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
1315 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
1316 wfex.Format.nBlockAlign;
1317 wfex.Format.cbSize=22;
1318 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
1319 wfex.dwChannelMask=SPEAKER_ALL;
1320 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
1321 rc=waveOutOpen(&wout,device,&wfex.Format,0,0,
1322 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
1323 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
1324 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
1325 "waveOutOpen(%s): returned %s\n",dev_name(device),wave_out_error(rc));
1326 if (rc==MMSYSERR_NOERROR) {
1327 waveOutClose(wout);
1328 wave_out_test_deviceOut(device,1.0,1,0,&wfex.Format,WAVE_FORMAT_2M16,
1329 CALLBACK_EVENT,&capsA,winetest_interactive,
1330 TRUE,FALSE);
1331 wave_out_test_deviceOut(device,1.0,10,0,&wfex.Format,WAVE_FORMAT_2M16,
1332 CALLBACK_EVENT,&capsA,winetest_interactive,
1333 TRUE,FALSE);
1334 wave_out_test_deviceOut(device,1.0,5,1,&wfex.Format,WAVE_FORMAT_2M16,
1335 CALLBACK_EVENT,&capsA,winetest_interactive,
1336 TRUE,FALSE);
1337 } else
1338 trace("waveOutOpen(%s): 32 bit samples not supported\n",
1339 dev_name(device));
1341 /* test if 32 bit float samples supported */
1342 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
1343 wfex.Format.nChannels=2;
1344 wfex.Format.wBitsPerSample=32;
1345 wfex.Format.nSamplesPerSec=22050;
1346 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
1347 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
1348 wfex.Format.nBlockAlign;
1349 wfex.Format.cbSize=22;
1350 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
1351 wfex.dwChannelMask=SPEAKER_ALL;
1352 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
1353 rc=waveOutOpen(&wout,device,&wfex.Format,0,0,
1354 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
1355 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
1356 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
1357 "waveOutOpen(%s): returned %s\n",dev_name(device),wave_out_error(rc));
1358 if (rc==MMSYSERR_NOERROR) {
1359 waveOutClose(wout);
1360 wave_out_test_deviceOut(device,1.0,1,0,&wfex.Format,WAVE_FORMAT_2M16,
1361 CALLBACK_EVENT,&capsA,winetest_interactive,
1362 TRUE,FALSE);
1363 wave_out_test_deviceOut(device,1.0,10,0,&wfex.Format,WAVE_FORMAT_2M16,
1364 CALLBACK_EVENT,&capsA,winetest_interactive,
1365 TRUE,FALSE);
1366 wave_out_test_deviceOut(device,1.0,5,1,&wfex.Format,WAVE_FORMAT_2M16,
1367 CALLBACK_EVENT,&capsA,winetest_interactive,
1368 TRUE,FALSE);
1369 } else
1370 trace("waveOutOpen(%s): 32 bit float samples not supported\n",
1371 dev_name(device));
1374 static void wave_out_tests(void)
1376 WAVEOUTCAPSA capsA;
1377 WAVEOUTCAPSW capsW;
1378 WAVEFORMATEX format;
1379 HWAVEOUT wout;
1380 MMRESULT rc;
1381 DWORD preferred, status;
1382 UINT ndev,d;
1384 ndev=waveOutGetNumDevs();
1385 trace("found %d WaveOut devices\n",ndev);
1387 rc = waveOutMessage((HWAVEOUT)WAVE_MAPPER, DRVM_MAPPER_PREFERRED_GET,
1388 (DWORD_PTR)&preferred, (DWORD_PTR)&status);
1389 ok((ndev == 0 && rc == MMSYSERR_NODRIVER) ||
1390 rc == MMSYSERR_NOERROR, "waveOutMessage(DRVM_MAPPER_PREFERRED_GET) failed: %u\n", rc);
1392 ok((ndev == 0 && (preferred == -1 || broken(preferred != -1))) ||
1393 preferred < ndev, "Got invalid preferred device: 0x%x\n", preferred);
1395 rc=waveOutGetDevCapsA(ndev+1,&capsA,sizeof(capsA));
1396 ok(rc==MMSYSERR_BADDEVICEID,
1397 "waveOutGetDevCapsA(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
1398 dev_name(ndev+1),mmsys_error(rc));
1400 rc=waveOutGetDevCapsW(ndev+1,&capsW,sizeof(capsW));
1401 ok(rc==MMSYSERR_BADDEVICEID || rc==MMSYSERR_NOTSUPPORTED,
1402 "waveOutGetDevCapsW(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NOTSUPPORTED "
1403 "expected, got %s\n",dev_name(ndev+1),mmsys_error(rc));
1405 rc=waveOutGetDevCapsA(WAVE_MAPPER,&capsA,sizeof(capsA));
1406 if (ndev>0)
1407 ok(rc==MMSYSERR_NOERROR,
1408 "waveOutGetDevCapsA(%s): MMSYSERR_NOERROR expected, got %s\n",
1409 dev_name(WAVE_MAPPER),mmsys_error(rc));
1410 else
1411 ok(rc==MMSYSERR_BADDEVICEID || rc==MMSYSERR_NODRIVER,
1412 "waveOutGetDevCapsA(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NODRIVER "
1413 "expected, got %s\n",dev_name(WAVE_MAPPER),mmsys_error(rc));
1415 rc=waveOutGetDevCapsW(WAVE_MAPPER,&capsW,sizeof(capsW));
1416 if (ndev>0)
1417 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NOTSUPPORTED,
1418 "waveOutGetDevCapsW(%s): MMSYSERR_NOERROR or MMSYSERR_NOTSUPPORTED "
1419 "expected, got %s\n",dev_name(WAVE_MAPPER),mmsys_error(rc));
1420 else
1421 ok(rc==MMSYSERR_BADDEVICEID || rc==MMSYSERR_NODRIVER ||
1422 rc==MMSYSERR_NOTSUPPORTED,
1423 "waveOutGetDevCapsW(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NODRIVER "
1424 " or MMSYSERR_NOTSUPPORTED expected, got %s\n",
1425 dev_name(WAVE_MAPPER),mmsys_error(rc));
1427 format.wFormatTag=WAVE_FORMAT_PCM;
1428 format.nChannels=2;
1429 format.wBitsPerSample=16;
1430 format.nSamplesPerSec=44100;
1431 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
1432 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
1433 format.cbSize=0;
1434 rc=waveOutOpen(&wout,ndev+1,&format,0,0,CALLBACK_NULL);
1435 ok(rc==MMSYSERR_BADDEVICEID,
1436 "waveOutOpen(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
1437 dev_name(ndev+1),mmsys_error(rc));
1439 for (d=0;d<ndev;d++)
1440 wave_out_test_device(d);
1442 if (ndev>0)
1443 wave_out_test_device(WAVE_MAPPER);
1446 START_TEST(wave)
1448 test_multiple_waveopens();
1449 wave_out_tests();