Authors: Chris Morgan <cmorgan@wpi.edu>, James Abbatiello <abbejy@wpi.edu>
[wine/multimedia.git] / multimedia / dsound.c
blob71d9d5cc6b5e90456d4a9ae6cb212c906d258c43
1 /* DirectSound
2 *
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998 Rob Riggs
5 */
6 /*
7 * Note: This file requires multithread ability. It is not possible to
8 * implement the stuff in a single thread anyway. And most DirectX apps
9 * require threading themselves.
11 * Most thread locking is complete. There may be a few race
12 * conditions still lurking.
14 * Tested with a Soundblaster clone, a Gravis UltraSound Classic,
15 * and a Turtle Beach Tropez+.
17 * TODO:
18 * Implement DirectSoundCapture API
19 * Implement SetCooperativeLevel properly (need to address focus issues)
20 * Use wavetable synth for static buffers if available
21 * Implement DirectSound3DBuffers (stubs in place)
22 * Use hardware 3D support if available (OSS support may be needed first)
23 * Add support for APIs other than OSS: ALSA (http://alsa.jcu.cz/)
24 * and esound (http://www.gnome.org), for instance
26 * FIXME: Status needs updating.
28 * Status:
29 * - Wing Commander 4/W95:
30 * The intromovie plays without problems. Nearly lipsynchron.
31 * - DiscWorld 2
32 * The sound works, but noticeable chunks are left out (from the sound and
33 * the animation). Don't know why yet.
34 * - Diablo:
35 * Sound works, but slows down the movieplayer.
36 * - XvT:
37 * Doesn't sound yet.
38 * - Monkey Island 3:
39 * The background sound of the startscreen works ;)
40 * - WingCommander Prophecy Demo:
41 * Sound works for the intromovie.
42 * - Total Annihilation (1998/12/04):
43 * Sound plays perfectly in the game, but the Smacker movies
44 * (http://www.smacker.com/) play silently.
45 * - A-10 Cuba! Demo (1998/12/04):
46 * Sound works properly (for some people).
47 * - dsstream.exe, from DirectX 5.2 SDK (1998/12/04):
48 * Works properly, but requires "-dll -winmm".
49 * - dsshow.exe, from DirectX 5.2 SDK (1998/12/04):
50 * Initializes the DLL properly with CoCreateInstance(), but the
51 * FileOpen dialog box is broken - could not test properly
54 #include "config.h"
55 #include <assert.h>
56 #include <errno.h>
57 #include <sys/types.h>
58 #include <sys/time.h>
59 #include <sys/fcntl.h>
60 #include <unistd.h>
61 #include <stdlib.h>
62 #include <string.h>
63 #include <math.h> /* Insomnia - pow() function */
64 #include "dsound.h"
65 #include "winuser.h"
66 #include "winerror.h"
67 #include "multimedia.h"
68 #include "wine/obj_base.h"
69 #include "thread.h"
70 #include "debug.h"
72 DEFAULT_DEBUG_CHANNEL(dsound)
75 /*****************************************************************************
76 * Predeclare the interface implementation structures
78 typedef struct IDirectSoundImpl IDirectSoundImpl;
79 typedef struct IDirectSoundBufferImpl IDirectSoundBufferImpl;
80 typedef struct IDirectSoundNotifyImpl IDirectSoundNotifyImpl;
81 typedef struct IDirectSound3DListenerImpl IDirectSound3DListenerImpl;
82 typedef struct IDirectSound3DBufferImpl IDirectSound3DBufferImpl;
84 /*****************************************************************************
85 * IDirectSound implementation structure
87 struct IDirectSoundImpl
89 /* IUnknown fields */
90 ICOM_VTABLE(IDirectSound)* lpvtbl;
91 DWORD ref;
92 /* IDirectSoundImpl fields */
93 DWORD priolevel;
94 int nrofbuffers;
95 IDirectSoundBufferImpl** buffers;
96 IDirectSoundBufferImpl* primary;
97 IDirectSound3DListenerImpl* listener;
98 WAVEFORMATEX wfx; /* current main waveformat */
101 /*****************************************************************************
102 * IDirectSoundBuffer implementation structure
104 struct IDirectSoundBufferImpl
106 /* IUnknown fields */
107 ICOM_VTABLE(IDirectSoundBuffer)* lpvtbl;
108 DWORD ref;
109 /* IDirectSoundBufferImpl fields */
110 WAVEFORMATEX wfx;
111 LPBYTE buffer;
112 IDirectSound3DBufferImpl* ds3db;
113 DWORD playflags,playing;
114 DWORD playpos,writepos,buflen;
115 DWORD nAvgBytesPerSec;
116 DWORD freq;
117 ULONG freqAdjust;
118 LONG volume,pan;
119 LONG lVolAdjust,rVolAdjust;
120 IDirectSoundBufferImpl* parent; /* for duplicates */
121 IDirectSoundImpl* dsound;
122 DSBUFFERDESC dsbd;
123 LPDSBPOSITIONNOTIFY notifies;
124 int nrofnotifies;
125 CRITICAL_SECTION lock;
128 /*****************************************************************************
129 * IDirectSoundNotify implementation structure
131 struct IDirectSoundNotifyImpl
133 /* IUnknown fields */
134 ICOM_VTABLE(IDirectSoundNotify)* lpvtbl;
135 DWORD ref;
136 /* IDirectSoundNotifyImpl fields */
137 IDirectSoundBufferImpl* dsb;
140 /*****************************************************************************
141 * IDirectSound3DListener implementation structure
143 struct IDirectSound3DListenerImpl
145 /* IUnknown fields */
146 ICOM_VTABLE(IDirectSound3DListener)* lpvtbl;
147 DWORD ref;
148 /* IDirectSound3DListenerImpl fields */
149 IDirectSoundBufferImpl* dsb;
150 DS3DLISTENER ds3dl;
151 CRITICAL_SECTION lock;
154 /*****************************************************************************
155 * IDirectSound3DBuffer implementation structure
157 struct IDirectSound3DBufferImpl
159 /* IUnknown fields */
160 ICOM_VTABLE(IDirectSound3DBuffer)* lpvtbl;
161 DWORD ref;
162 /* IDirectSound3DBufferImpl fields */
163 IDirectSoundBufferImpl* dsb;
164 DS3DBUFFER ds3db;
165 LPBYTE buffer;
166 DWORD buflen;
167 CRITICAL_SECTION lock;
171 #ifdef HAVE_OSS
172 # include <sys/ioctl.h>
173 # ifdef HAVE_MACHINE_SOUNDCARD_H
174 # include <machine/soundcard.h>
175 # endif
176 # ifdef HAVE_SYS_SOUNDCARD_H
177 # include <sys/soundcard.h>
178 # endif
180 /* #define USE_DSOUND3D 1 */
182 #define DSOUND_FRAGLEN (primarybuf->wfx.nAvgBytesPerSec >> 4)
183 #define DSOUND_FREQSHIFT (14)
185 static int audiofd = -1;
186 static int audioOK = 0;
188 static IDirectSoundImpl* dsound = NULL;
190 static IDirectSoundBufferImpl* primarybuf = NULL;
192 static int DSOUND_setformat(LPWAVEFORMATEX wfex);
193 static void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len);
194 static void DSOUND_CloseAudio(void);
196 #endif
199 HRESULT WINAPI DirectSoundEnumerateA(
200 LPDSENUMCALLBACKA enumcb,
201 LPVOID context)
203 TRACE(dsound, "enumcb = %p, context = %p\n", enumcb, context);
205 #ifdef HAVE_OSS
206 if (enumcb != NULL)
207 enumcb(NULL,"WINE DirectSound using Open Sound System",
208 "sound",context);
209 #endif
211 return 0;
214 #ifdef HAVE_OSS
215 static void _dump_DSBCAPS(DWORD xmask) {
216 struct {
217 DWORD mask;
218 char *name;
219 } flags[] = {
220 #define FE(x) { x, #x },
221 FE(DSBCAPS_PRIMARYBUFFER)
222 FE(DSBCAPS_STATIC)
223 FE(DSBCAPS_LOCHARDWARE)
224 FE(DSBCAPS_LOCSOFTWARE)
225 FE(DSBCAPS_CTRLFREQUENCY)
226 FE(DSBCAPS_CTRLPAN)
227 FE(DSBCAPS_CTRLVOLUME)
228 FE(DSBCAPS_CTRLDEFAULT)
229 FE(DSBCAPS_CTRLALL)
230 FE(DSBCAPS_STICKYFOCUS)
231 FE(DSBCAPS_GETCURRENTPOSITION2)
233 int i;
235 for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
236 if (flags[i].mask & xmask)
237 fprintf(stderr,"%s ",flags[i].name);
240 /*******************************************************************************
241 * IDirectSound3DBuffer
244 /* IUnknown methods */
245 static HRESULT WINAPI IDirectSound3DBufferImpl_QueryInterface(
246 LPDIRECTSOUND3DBUFFER iface, REFIID riid, LPVOID *ppobj)
248 ICOM_THIS(IDirectSound3DBufferImpl,iface);
249 char xbuf[50];
251 WINE_StringFromCLSID(riid,xbuf);
252 TRACE(dsound,"(%p,%s,%p)\n",This,xbuf,ppobj);
253 return E_FAIL;
256 static ULONG WINAPI IDirectSound3DBufferImpl_AddRef(LPDIRECTSOUND3DBUFFER iface)
258 ICOM_THIS(IDirectSound3DBufferImpl,iface);
259 This->ref++;
260 return This->ref;
263 static ULONG WINAPI IDirectSound3DBufferImpl_Release(LPDIRECTSOUND3DBUFFER iface)
265 ICOM_THIS(IDirectSound3DBufferImpl,iface);
266 if(--This->ref)
267 return This->ref;
269 HeapFree(GetProcessHeap(),0,This->buffer);
270 HeapFree(GetProcessHeap(),0,This);
272 return 0;
275 /* IDirectSound3DBuffer methods */
276 static HRESULT WINAPI IDirectSound3DBufferImpl_GetAllParameters(
277 LPDIRECTSOUND3DBUFFER iface,
278 LPDS3DBUFFER lpDs3dBuffer)
280 FIXME(dsound,"stub\n");
281 return DS_OK;
284 static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeAngles(
285 LPDIRECTSOUND3DBUFFER iface,
286 LPDWORD lpdwInsideConeAngle,
287 LPDWORD lpdwOutsideConeAngle)
289 FIXME(dsound,"stub\n");
290 return DS_OK;
293 static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeOrientation(
294 LPDIRECTSOUND3DBUFFER iface,
295 LPD3DVECTOR lpvConeOrientation)
297 FIXME(dsound,"stub\n");
298 return DS_OK;
301 static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeOutsideVolume(
302 LPDIRECTSOUND3DBUFFER iface,
303 LPLONG lplConeOutsideVolume)
305 FIXME(dsound,"stub\n");
306 return DS_OK;
309 static HRESULT WINAPI IDirectSound3DBufferImpl_GetMaxDistance(
310 LPDIRECTSOUND3DBUFFER iface,
311 LPD3DVALUE lpfMaxDistance)
313 FIXME(dsound,"stub\n");
314 return DS_OK;
317 static HRESULT WINAPI IDirectSound3DBufferImpl_GetMinDistance(
318 LPDIRECTSOUND3DBUFFER iface,
319 LPD3DVALUE lpfMinDistance)
321 FIXME(dsound,"stub\n");
322 return DS_OK;
325 static HRESULT WINAPI IDirectSound3DBufferImpl_GetMode(
326 LPDIRECTSOUND3DBUFFER iface,
327 LPDWORD lpdwMode)
329 FIXME(dsound,"stub\n");
330 return DS_OK;
333 static HRESULT WINAPI IDirectSound3DBufferImpl_GetPosition(
334 LPDIRECTSOUND3DBUFFER iface,
335 LPD3DVECTOR lpvPosition)
337 FIXME(dsound,"stub\n");
338 return DS_OK;
341 static HRESULT WINAPI IDirectSound3DBufferImpl_GetVelocity(
342 LPDIRECTSOUND3DBUFFER iface,
343 LPD3DVECTOR lpvVelocity)
345 FIXME(dsound,"stub\n");
346 return DS_OK;
349 static HRESULT WINAPI IDirectSound3DBufferImpl_SetAllParameters(
350 LPDIRECTSOUND3DBUFFER iface,
351 LPCDS3DBUFFER lpcDs3dBuffer,
352 DWORD dwApply)
354 FIXME(dsound,"stub\n");
355 return DS_OK;
358 static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeAngles(
359 LPDIRECTSOUND3DBUFFER iface,
360 DWORD dwInsideConeAngle,
361 DWORD dwOutsideConeAngle,
362 DWORD dwApply)
364 FIXME(dsound,"stub\n");
365 return DS_OK;
368 static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeOrientation(
369 LPDIRECTSOUND3DBUFFER iface,
370 D3DVALUE x, D3DVALUE y, D3DVALUE z,
371 DWORD dwApply)
373 FIXME(dsound,"stub\n");
374 return DS_OK;
377 static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeOutsideVolume(
378 LPDIRECTSOUND3DBUFFER iface,
379 LONG lConeOutsideVolume,
380 DWORD dwApply)
382 FIXME(dsound,"stub\n");
383 return DS_OK;
386 static HRESULT WINAPI IDirectSound3DBufferImpl_SetMaxDistance(
387 LPDIRECTSOUND3DBUFFER iface,
388 D3DVALUE fMaxDistance,
389 DWORD dwApply)
391 FIXME(dsound,"stub\n");
392 return DS_OK;
395 static HRESULT WINAPI IDirectSound3DBufferImpl_SetMinDistance(
396 LPDIRECTSOUND3DBUFFER iface,
397 D3DVALUE fMinDistance,
398 DWORD dwApply)
400 FIXME(dsound,"stub\n");
401 return DS_OK;
404 static HRESULT WINAPI IDirectSound3DBufferImpl_SetMode(
405 LPDIRECTSOUND3DBUFFER iface,
406 DWORD dwMode,
407 DWORD dwApply)
409 ICOM_THIS(IDirectSound3DBufferImpl,iface);
410 TRACE(dsound, "mode = %lx\n", dwMode);
411 This->ds3db.dwMode = dwMode;
412 return DS_OK;
415 static HRESULT WINAPI IDirectSound3DBufferImpl_SetPosition(
416 LPDIRECTSOUND3DBUFFER iface,
417 D3DVALUE x, D3DVALUE y, D3DVALUE z,
418 DWORD dwApply)
420 FIXME(dsound,"stub\n");
421 return DS_OK;
424 static HRESULT WINAPI IDirectSound3DBufferImpl_SetVelocity(
425 LPDIRECTSOUND3DBUFFER iface,
426 D3DVALUE x, D3DVALUE y, D3DVALUE z,
427 DWORD dwApply)
429 FIXME(dsound,"stub\n");
430 return DS_OK;
433 ICOM_VTABLE(IDirectSound3DBuffer) ds3dbvt = {
434 /* IUnknown methods */
435 IDirectSound3DBufferImpl_QueryInterface,
436 IDirectSound3DBufferImpl_AddRef,
437 IDirectSound3DBufferImpl_Release,
438 /* IDirectSound3DBuffer methods */
439 IDirectSound3DBufferImpl_GetAllParameters,
440 IDirectSound3DBufferImpl_GetConeAngles,
441 IDirectSound3DBufferImpl_GetConeOrientation,
442 IDirectSound3DBufferImpl_GetConeOutsideVolume,
443 IDirectSound3DBufferImpl_GetMaxDistance,
444 IDirectSound3DBufferImpl_GetMinDistance,
445 IDirectSound3DBufferImpl_GetMode,
446 IDirectSound3DBufferImpl_GetPosition,
447 IDirectSound3DBufferImpl_GetVelocity,
448 IDirectSound3DBufferImpl_SetAllParameters,
449 IDirectSound3DBufferImpl_SetConeAngles,
450 IDirectSound3DBufferImpl_SetConeOrientation,
451 IDirectSound3DBufferImpl_SetConeOutsideVolume,
452 IDirectSound3DBufferImpl_SetMaxDistance,
453 IDirectSound3DBufferImpl_SetMinDistance,
454 IDirectSound3DBufferImpl_SetMode,
455 IDirectSound3DBufferImpl_SetPosition,
456 IDirectSound3DBufferImpl_SetVelocity,
459 #ifdef USE_DSOUND3D
460 static int DSOUND_Create3DBuffer(IDirectSoundBufferImpl* dsb)
462 DWORD i, temp, iSize, oSize, offset;
463 LPBYTE bIbuf, bObuf, bTbuf = NULL;
464 LPWORD wIbuf, wObuf, wTbuf = NULL;
466 /* Inside DirectX says it's stupid but allowed */
467 if (dsb->wfx.nChannels == 2) {
468 /* Convert to mono */
469 if (dsb->wfx.wBitsPerSample == 16) {
470 iSize = dsb->buflen / 4;
471 wTbuf = malloc(dsb->buflen / 2);
472 if (wTbuf == NULL)
473 return DSERR_OUTOFMEMORY;
474 for (i = 0; i < iSize; i++)
475 wTbuf[i] = (dsb->buffer[i] + dsb->buffer[(i * 2) + 1]) / 2;
476 wIbuf = wTbuf;
477 } else {
478 iSize = dsb->buflen / 2;
479 bTbuf = malloc(dsb->buflen / 2);
480 if (bTbuf == NULL)
481 return DSERR_OUTOFMEMORY;
482 for (i = 0; i < iSize; i++)
483 bTbuf[i] = (dsb->buffer[i] + dsb->buffer[(i * 2) + 1]) / 2;
484 bIbuf = bTbuf;
486 } else {
487 if (dsb->wfx.wBitsPerSample == 16) {
488 iSize = dsb->buflen / 2;
489 wIbuf = (LPWORD) dsb->buffer;
490 } else {
491 bIbuf = (LPBYTE) dsb->buffer;
492 iSize = dsb->buflen;
496 if (primarybuf->wfx.wBitsPerSample == 16) {
497 wObuf = (LPWORD) dsb->ds3db->buffer;
498 oSize = dsb->ds3db->buflen / 2;
499 } else {
500 bObuf = (LPBYTE) dsb->ds3db->buffer;
501 oSize = dsb->ds3db->buflen;
504 offset = primarybuf->wfx.nSamplesPerSec / 100; /* 10ms */
505 if (primarybuf->wfx.wBitsPerSample == 16 && dsb->wfx.wBitsPerSample == 16)
506 for (i = 0; i < iSize; i++) {
507 temp = wIbuf[i];
508 if (i >= offset)
509 temp += wIbuf[i - offset] >> 9;
510 else
511 temp += wIbuf[i + iSize - offset] >> 9;
512 wObuf[i * 2] = temp;
513 wObuf[(i * 2) + 1] = temp;
515 else if (primarybuf->wfx.wBitsPerSample == 8 && dsb->wfx.wBitsPerSample == 8)
516 for (i = 0; i < iSize; i++) {
517 temp = bIbuf[i];
518 if (i >= offset)
519 temp += bIbuf[i - offset] >> 5;
520 else
521 temp += bIbuf[i + iSize - offset] >> 5;
522 bObuf[i * 2] = temp;
523 bObuf[(i * 2) + 1] = temp;
526 if (wTbuf)
527 free(wTbuf);
528 if (bTbuf)
529 free(bTbuf);
531 return DS_OK;
533 #endif
534 /*******************************************************************************
535 * IDirectSound3DListener
538 /* IUnknown methods */
539 static HRESULT WINAPI IDirectSound3DListenerImpl_QueryInterface(
540 LPDIRECTSOUND3DLISTENER iface, REFIID riid, LPVOID *ppobj)
542 ICOM_THIS(IDirectSound3DListenerImpl,iface);
543 char xbuf[50];
545 WINE_StringFromCLSID(riid,xbuf);
546 TRACE(dsound,"(%p,%s,%p)\n",This,xbuf,ppobj);
547 return E_FAIL;
550 static ULONG WINAPI IDirectSound3DListenerImpl_AddRef(LPDIRECTSOUND3DLISTENER iface)
552 ICOM_THIS(IDirectSound3DListenerImpl,iface);
553 This->ref++;
554 return This->ref;
557 static ULONG WINAPI IDirectSound3DListenerImpl_Release(LPDIRECTSOUND3DLISTENER iface)
559 ICOM_THIS(IDirectSound3DListenerImpl,iface);
560 This->ref--;
561 return This->ref;
564 /* IDirectSound3DListener methods */
565 static HRESULT WINAPI IDirectSound3DListenerImpl_GetAllParameter(
566 LPDIRECTSOUND3DLISTENER iface,
567 LPDS3DLISTENER lpDS3DL)
569 FIXME(dsound,"stub\n");
570 return DS_OK;
573 static HRESULT WINAPI IDirectSound3DListenerImpl_GetDistanceFactor(
574 LPDIRECTSOUND3DLISTENER iface,
575 LPD3DVALUE lpfDistanceFactor)
577 FIXME(dsound,"stub\n");
578 return DS_OK;
581 static HRESULT WINAPI IDirectSound3DListenerImpl_GetDopplerFactor(
582 LPDIRECTSOUND3DLISTENER iface,
583 LPD3DVALUE lpfDopplerFactor)
585 FIXME(dsound,"stub\n");
586 return DS_OK;
589 static HRESULT WINAPI IDirectSound3DListenerImpl_GetOrientation(
590 LPDIRECTSOUND3DLISTENER iface,
591 LPD3DVECTOR lpvOrientFront,
592 LPD3DVECTOR lpvOrientTop)
594 FIXME(dsound,"stub\n");
595 return DS_OK;
598 static HRESULT WINAPI IDirectSound3DListenerImpl_GetPosition(
599 LPDIRECTSOUND3DLISTENER iface,
600 LPD3DVECTOR lpvPosition)
602 FIXME(dsound,"stub\n");
603 return DS_OK;
606 static HRESULT WINAPI IDirectSound3DListenerImpl_GetRolloffFactor(
607 LPDIRECTSOUND3DLISTENER iface,
608 LPD3DVALUE lpfRolloffFactor)
610 FIXME(dsound,"stub\n");
611 return DS_OK;
614 static HRESULT WINAPI IDirectSound3DListenerImpl_GetVelocity(
615 LPDIRECTSOUND3DLISTENER iface,
616 LPD3DVECTOR lpvVelocity)
618 FIXME(dsound,"stub\n");
619 return DS_OK;
622 static HRESULT WINAPI IDirectSound3DListenerImpl_SetAllParameters(
623 LPDIRECTSOUND3DLISTENER iface,
624 LPCDS3DLISTENER lpcDS3DL,
625 DWORD dwApply)
627 FIXME(dsound,"stub\n");
628 return DS_OK;
631 static HRESULT WINAPI IDirectSound3DListenerImpl_SetDistanceFactor(
632 LPDIRECTSOUND3DLISTENER iface,
633 D3DVALUE fDistanceFactor,
634 DWORD dwApply)
636 FIXME(dsound,"stub\n");
637 return DS_OK;
640 static HRESULT WINAPI IDirectSound3DListenerImpl_SetDopplerFactor(
641 LPDIRECTSOUND3DLISTENER iface,
642 D3DVALUE fDopplerFactor,
643 DWORD dwApply)
645 FIXME(dsound,"stub\n");
646 return DS_OK;
649 static HRESULT WINAPI IDirectSound3DListenerImpl_SetOrientation(
650 LPDIRECTSOUND3DLISTENER iface,
651 D3DVALUE xFront, D3DVALUE yFront, D3DVALUE zFront,
652 D3DVALUE xTop, D3DVALUE yTop, D3DVALUE zTop,
653 DWORD dwApply)
655 FIXME(dsound,"stub\n");
656 return DS_OK;
659 static HRESULT WINAPI IDirectSound3DListenerImpl_SetPosition(
660 LPDIRECTSOUND3DLISTENER iface,
661 D3DVALUE x, D3DVALUE y, D3DVALUE z,
662 DWORD dwApply)
664 FIXME(dsound,"stub\n");
665 return DS_OK;
668 static HRESULT WINAPI IDirectSound3DListenerImpl_SetRolloffFactor(
669 LPDIRECTSOUND3DLISTENER iface,
670 D3DVALUE fRolloffFactor,
671 DWORD dwApply)
673 FIXME(dsound,"stub\n");
674 return DS_OK;
677 static HRESULT WINAPI IDirectSound3DListenerImpl_SetVelocity(
678 LPDIRECTSOUND3DLISTENER iface,
679 D3DVALUE x, D3DVALUE y, D3DVALUE z,
680 DWORD dwApply)
682 FIXME(dsound,"stub\n");
683 return DS_OK;
686 static HRESULT WINAPI IDirectSound3DListenerImpl_CommitDeferredSettings(
687 LPDIRECTSOUND3DLISTENER iface)
690 FIXME(dsound,"stub\n");
691 return DS_OK;
694 ICOM_VTABLE(IDirectSound3DListener) ds3dlvt = {
695 /* IUnknown methods */
696 IDirectSound3DListenerImpl_QueryInterface,
697 IDirectSound3DListenerImpl_AddRef,
698 IDirectSound3DListenerImpl_Release,
699 /* IDirectSound3DListener methods */
700 IDirectSound3DListenerImpl_GetAllParameter,
701 IDirectSound3DListenerImpl_GetDistanceFactor,
702 IDirectSound3DListenerImpl_GetDopplerFactor,
703 IDirectSound3DListenerImpl_GetOrientation,
704 IDirectSound3DListenerImpl_GetPosition,
705 IDirectSound3DListenerImpl_GetRolloffFactor,
706 IDirectSound3DListenerImpl_GetVelocity,
707 IDirectSound3DListenerImpl_SetAllParameters,
708 IDirectSound3DListenerImpl_SetDistanceFactor,
709 IDirectSound3DListenerImpl_SetDopplerFactor,
710 IDirectSound3DListenerImpl_SetOrientation,
711 IDirectSound3DListenerImpl_SetPosition,
712 IDirectSound3DListenerImpl_SetRolloffFactor,
713 IDirectSound3DListenerImpl_SetVelocity,
714 IDirectSound3DListenerImpl_CommitDeferredSettings,
717 /*******************************************************************************
718 * IDirectSoundNotify
720 static HRESULT WINAPI IDirectSoundNotifyImpl_QueryInterface(
721 LPDIRECTSOUNDNOTIFY iface,REFIID riid,LPVOID *ppobj
723 ICOM_THIS(IDirectSoundNotifyImpl,iface);
724 char xbuf[50];
726 WINE_StringFromCLSID(riid,xbuf);
727 TRACE(dsound,"(%p,%s,%p)\n",This,xbuf,ppobj);
728 return E_FAIL;
731 static ULONG WINAPI IDirectSoundNotifyImpl_AddRef(LPDIRECTSOUNDNOTIFY iface) {
732 ICOM_THIS(IDirectSoundNotifyImpl,iface);
733 return ++(This->ref);
736 static ULONG WINAPI IDirectSoundNotifyImpl_Release(LPDIRECTSOUNDNOTIFY iface) {
737 ICOM_THIS(IDirectSoundNotifyImpl,iface);
738 This->ref--;
739 if (!This->ref) {
740 IDirectSoundNotify_Release((LPDIRECTSOUNDBUFFER)This->dsb);
741 HeapFree(GetProcessHeap(),0,This);
742 return 0;
744 return This->ref;
747 static HRESULT WINAPI IDirectSoundNotifyImpl_SetNotificationPositions(
748 LPDIRECTSOUNDNOTIFY iface,DWORD howmuch,LPCDSBPOSITIONNOTIFY notify
750 ICOM_THIS(IDirectSoundNotifyImpl,iface);
751 int i;
753 if (TRACE_ON(dsound)) {
754 TRACE(dsound,"(%p,0x%08lx,%p)\n",This,howmuch,notify);
755 for (i=0;i<howmuch;i++)
756 TRACE(dsound,"notify at %ld to 0x%08lx\n",
757 notify[i].dwOffset,(DWORD)notify[i].hEventNotify);
759 This->dsb->notifies = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,This->dsb->notifies,(This->dsb->nrofnotifies+howmuch)*sizeof(DSBPOSITIONNOTIFY));
760 memcpy( This->dsb->notifies+This->dsb->nrofnotifies,
761 notify,
762 howmuch*sizeof(DSBPOSITIONNOTIFY)
764 This->dsb->nrofnotifies+=howmuch;
766 return 0;
769 ICOM_VTABLE(IDirectSoundNotify) dsnvt = {
770 IDirectSoundNotifyImpl_QueryInterface,
771 IDirectSoundNotifyImpl_AddRef,
772 IDirectSoundNotifyImpl_Release,
773 IDirectSoundNotifyImpl_SetNotificationPositions,
776 /*******************************************************************************
777 * IDirectSoundBuffer
780 /* This sets this format for the <em>Primary Buffer Only</em> */
781 /* See file:///cdrom/sdk52/docs/worddoc/dsound.doc page 120 */
782 static HRESULT WINAPI IDirectSoundBufferImpl_SetFormat(
783 LPDIRECTSOUNDBUFFER iface,LPWAVEFORMATEX wfex
785 ICOM_THIS(IDirectSoundBufferImpl,iface);
786 IDirectSoundBufferImpl** dsb;
787 int i;
789 /* Let's be pedantic! */
790 if ((wfex == NULL) ||
791 (wfex->wFormatTag != WAVE_FORMAT_PCM) ||
792 (wfex->nChannels < 1) || (wfex->nChannels > 2) ||
793 (wfex->nSamplesPerSec < 1) ||
794 (wfex->nBlockAlign < 1) || (wfex->nChannels > 4) ||
795 ((wfex->wBitsPerSample != 8) && (wfex->wBitsPerSample != 16))) {
796 TRACE(dsound, "failed pedantic check!\n");
797 return DSERR_INVALIDPARAM;
800 /* **** */
801 EnterCriticalSection(&(primarybuf->lock));
803 if (primarybuf->wfx.nSamplesPerSec != wfex->nSamplesPerSec) {
804 dsb = dsound->buffers;
805 for (i = 0; i < dsound->nrofbuffers; i++, dsb++) {
806 /* **** */
807 EnterCriticalSection(&((*dsb)->lock));
809 (*dsb)->freqAdjust = ((*dsb)->freq << DSOUND_FREQSHIFT) /
810 wfex->nSamplesPerSec;
812 LeaveCriticalSection(&((*dsb)->lock));
813 /* **** */
817 memcpy(&(primarybuf->wfx), wfex, sizeof(primarybuf->wfx));
819 TRACE(dsound,"(formattag=0x%04x,chans=%d,samplerate=%ld"
820 "bytespersec=%ld,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
821 wfex->wFormatTag, wfex->nChannels, wfex->nSamplesPerSec,
822 wfex->nAvgBytesPerSec, wfex->nBlockAlign,
823 wfex->wBitsPerSample, wfex->cbSize);
825 primarybuf->wfx.nAvgBytesPerSec =
826 This->wfx.nSamplesPerSec * This->wfx.nBlockAlign;
828 DSOUND_CloseAudio();
830 LeaveCriticalSection(&(primarybuf->lock));
831 /* **** */
833 return DS_OK;
836 static HRESULT WINAPI IDirectSoundBufferImpl_SetVolume(
837 LPDIRECTSOUNDBUFFER iface,LONG vol
839 ICOM_THIS(IDirectSoundBufferImpl,iface);
840 double temp;
842 TRACE(dsound,"(%p,%ld)\n",This,vol);
844 /* I'm not sure if we need this for primary buffer */
845 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME))
846 return DSERR_CONTROLUNAVAIL;
848 if ((vol > DSBVOLUME_MAX) || (vol < DSBVOLUME_MIN))
849 return DSERR_INVALIDPARAM;
851 /* This needs to adjust the soundcard volume when */
852 /* called for the primary buffer */
853 if (This->dsbd.dwFlags & DSBCAPS_PRIMARYBUFFER) {
854 FIXME(dsound, "Volume control of primary unimplemented.\n");
855 This->volume = vol;
856 return DS_OK;
859 /* **** */
860 EnterCriticalSection(&(This->lock));
862 This->volume = vol;
864 temp = (double) (This->volume - (This->pan > 0 ? This->pan : 0));
865 This->lVolAdjust = (ULONG) (pow(2.0, temp / 600.0) * 32768.0);
866 temp = (double) (This->volume + (This->pan < 0 ? This->pan : 0));
867 This->rVolAdjust = (ULONG) (pow(2.0, temp / 600.0) * 32768.0);
869 LeaveCriticalSection(&(This->lock));
870 /* **** */
872 TRACE(dsound, "left = %lx, right = %lx\n", This->lVolAdjust, This->rVolAdjust);
874 return DS_OK;
877 static HRESULT WINAPI IDirectSoundBufferImpl_GetVolume(
878 LPDIRECTSOUNDBUFFER iface,LPLONG vol
880 ICOM_THIS(IDirectSoundBufferImpl,iface);
881 TRACE(dsound,"(%p,%p)\n",This,vol);
883 if (vol == NULL)
884 return DSERR_INVALIDPARAM;
886 *vol = This->volume;
887 return DS_OK;
890 static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(
891 LPDIRECTSOUNDBUFFER iface,DWORD freq
893 ICOM_THIS(IDirectSoundBufferImpl,iface);
894 TRACE(dsound,"(%p,%ld)\n",This,freq);
896 /* You cannot set the frequency of the primary buffer */
897 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLFREQUENCY) ||
898 (This->dsbd.dwFlags & DSBCAPS_PRIMARYBUFFER))
899 return DSERR_CONTROLUNAVAIL;
901 if ((freq < DSBFREQUENCY_MIN) || (freq > DSBFREQUENCY_MAX))
902 return DSERR_INVALIDPARAM;
904 /* **** */
905 EnterCriticalSection(&(This->lock));
907 This->freq = freq;
908 This->freqAdjust = (freq << DSOUND_FREQSHIFT) / primarybuf->wfx.nSamplesPerSec;
909 This->nAvgBytesPerSec = freq * This->wfx.nBlockAlign;
911 LeaveCriticalSection(&(This->lock));
912 /* **** */
914 return DS_OK;
917 static HRESULT WINAPI IDirectSoundBufferImpl_Play(
918 LPDIRECTSOUNDBUFFER iface,DWORD reserved1,DWORD reserved2,DWORD flags
920 ICOM_THIS(IDirectSoundBufferImpl,iface);
921 TRACE(dsound,"(%p,%08lx,%08lx,%08lx)\n",
922 This,reserved1,reserved2,flags
924 This->playflags = flags;
925 This->playing = 1;
926 return DS_OK;
929 static HRESULT WINAPI IDirectSoundBufferImpl_Stop(LPDIRECTSOUNDBUFFER iface)
931 ICOM_THIS(IDirectSoundBufferImpl,iface);
932 TRACE(dsound,"(%p)\n",This);
934 /* **** */
935 EnterCriticalSection(&(This->lock));
937 This->playing = 0;
938 DSOUND_CheckEvent(This, 0);
940 LeaveCriticalSection(&(This->lock));
941 /* **** */
943 return DS_OK;
946 static DWORD WINAPI IDirectSoundBufferImpl_AddRef(LPDIRECTSOUNDBUFFER iface) {
947 ICOM_THIS(IDirectSoundBufferImpl,iface);
948 /* TRACE(dsound,"(%p) ref was %ld\n",This, This->ref); */
950 return ++(This->ref);
952 static DWORD WINAPI IDirectSoundBufferImpl_Release(LPDIRECTSOUNDBUFFER iface) {
953 ICOM_THIS(IDirectSoundBufferImpl,iface);
954 int i;
956 /* TRACE(dsound,"(%p) ref was %ld\n",This, This->ref); */
958 if (--This->ref)
959 return This->ref;
961 for (i=0;i<This->dsound->nrofbuffers;i++)
962 if (This->dsound->buffers[i] == This)
963 break;
964 if (i < This->dsound->nrofbuffers) {
965 /* Put the last buffer of the list in the (now empty) position */
966 This->dsound->buffers[i] = This->dsound->buffers[This->dsound->nrofbuffers - 1];
967 This->dsound->buffers = HeapReAlloc(GetProcessHeap(),0,This->dsound->buffers,sizeof(LPDIRECTSOUNDBUFFER)*This->dsound->nrofbuffers);
968 This->dsound->nrofbuffers--;
969 IDirectSound_Release((LPDIRECTSOUND)This->dsound);
972 DeleteCriticalSection(&(This->lock));
974 if (This->ds3db && This->ds3db->lpvtbl)
975 IDirectSound3DBuffer_Release((LPDIRECTSOUND3DBUFFER)This->ds3db);
977 if (This->parent)
978 /* this is a duplicate buffer */
979 IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER)This->parent);
980 else
981 /* this is a toplevel buffer */
982 HeapFree(GetProcessHeap(),0,This->buffer);
984 HeapFree(GetProcessHeap(),0,This);
986 if (This == primarybuf)
987 primarybuf = NULL;
989 return DS_OK;
992 static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(
993 LPDIRECTSOUNDBUFFER iface,LPDWORD playpos,LPDWORD writepos
995 ICOM_THIS(IDirectSoundBufferImpl,iface);
996 TRACE(dsound,"(%p,%p,%p)\n",This,playpos,writepos);
997 if (playpos) *playpos = This->playpos;
998 if (writepos) *writepos = This->writepos;
999 TRACE(dsound, "playpos = %ld, writepos = %ld\n", *playpos, *writepos);
1000 return DS_OK;
1003 static HRESULT WINAPI IDirectSoundBufferImpl_GetStatus(
1004 LPDIRECTSOUNDBUFFER iface,LPDWORD status
1006 ICOM_THIS(IDirectSoundBufferImpl,iface);
1007 TRACE(dsound,"(%p,%p)\n",This,status);
1009 if (status == NULL)
1010 return DSERR_INVALIDPARAM;
1012 *status = 0;
1013 if (This->playing)
1014 *status |= DSBSTATUS_PLAYING;
1015 if (This->playflags & DSBPLAY_LOOPING)
1016 *status |= DSBSTATUS_LOOPING;
1018 return DS_OK;
1022 static HRESULT WINAPI IDirectSoundBufferImpl_GetFormat(
1023 LPDIRECTSOUNDBUFFER iface,LPWAVEFORMATEX lpwf,DWORD wfsize,LPDWORD wfwritten
1025 ICOM_THIS(IDirectSoundBufferImpl,iface);
1026 TRACE(dsound,"(%p,%p,%ld,%p)\n",This,lpwf,wfsize,wfwritten);
1028 if (wfsize>sizeof(This->wfx))
1029 wfsize = sizeof(This->wfx);
1030 if (lpwf) { /* NULL is valid */
1031 memcpy(lpwf,&(This->wfx),wfsize);
1032 if (wfwritten)
1033 *wfwritten = wfsize;
1034 } else
1035 if (wfwritten)
1036 *wfwritten = sizeof(This->wfx);
1037 else
1038 return DSERR_INVALIDPARAM;
1040 return DS_OK;
1043 static HRESULT WINAPI IDirectSoundBufferImpl_Lock(
1044 LPDIRECTSOUNDBUFFER iface,DWORD writecursor,DWORD writebytes,LPVOID lplpaudioptr1,LPDWORD audiobytes1,LPVOID lplpaudioptr2,LPDWORD audiobytes2,DWORD flags
1046 ICOM_THIS(IDirectSoundBufferImpl,iface);
1048 TRACE(dsound,"(%p,%ld,%ld,%p,%p,%p,%p,0x%08lx)\n",
1049 This,
1050 writecursor,
1051 writebytes,
1052 lplpaudioptr1,
1053 audiobytes1,
1054 lplpaudioptr2,
1055 audiobytes2,
1056 flags
1058 if (flags & DSBLOCK_FROMWRITECURSOR)
1059 writecursor += This->writepos;
1060 if (flags & DSBLOCK_ENTIREBUFFER)
1061 writebytes = This->buflen;
1062 if (writebytes > This->buflen)
1063 writebytes = This->buflen;
1065 assert(audiobytes1!=audiobytes2);
1066 assert(lplpaudioptr1!=lplpaudioptr2);
1067 if (writecursor+writebytes <= This->buflen) {
1068 *(LPBYTE*)lplpaudioptr1 = This->buffer+writecursor;
1069 *audiobytes1 = writebytes;
1070 if (lplpaudioptr2)
1071 *(LPBYTE*)lplpaudioptr2 = NULL;
1072 if (audiobytes2)
1073 *audiobytes2 = 0;
1074 TRACE(dsound,"->%ld.0\n",writebytes);
1075 } else {
1076 *(LPBYTE*)lplpaudioptr1 = This->buffer+writecursor;
1077 *audiobytes1 = This->buflen-writecursor;
1078 if (lplpaudioptr2)
1079 *(LPBYTE*)lplpaudioptr2 = This->buffer;
1080 if (audiobytes2)
1081 *audiobytes2 = writebytes-(This->buflen-writecursor);
1082 TRACE(dsound,"->%ld.%ld\n",*audiobytes1,audiobytes2?*audiobytes2:0);
1084 /* No. See file:///cdrom/sdk52/docs/worddoc/dsound.doc page 21 */
1085 /* This->writepos=(writecursor+writebytes)%This->buflen; */
1086 return DS_OK;
1089 static HRESULT WINAPI IDirectSoundBufferImpl_SetCurrentPosition(
1090 LPDIRECTSOUNDBUFFER iface,DWORD newpos
1092 ICOM_THIS(IDirectSoundBufferImpl,iface);
1093 TRACE(dsound,"(%p,%ld)\n",This,newpos);
1095 /* **** */
1096 EnterCriticalSection(&(This->lock));
1098 This->playpos = newpos;
1100 LeaveCriticalSection(&(This->lock));
1101 /* **** */
1103 return 0;
1106 static HRESULT WINAPI IDirectSoundBufferImpl_SetPan(
1107 LPDIRECTSOUNDBUFFER iface,LONG pan
1109 ICOM_THIS(IDirectSoundBufferImpl,iface);
1110 double temp;
1112 TRACE(dsound,"(%p,%ld)\n",This,pan);
1114 if ((pan > DSBPAN_RIGHT) || (pan < DSBPAN_LEFT))
1115 return DSERR_INVALIDPARAM;
1117 /* You cannot set the pan of the primary buffer */
1118 /* and you cannot use both pan and 3D controls */
1119 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN) ||
1120 (This->dsbd.dwFlags & DSBCAPS_CTRL3D) ||
1121 (This->dsbd.dwFlags & DSBCAPS_PRIMARYBUFFER))
1122 return DSERR_CONTROLUNAVAIL;
1124 /* **** */
1125 EnterCriticalSection(&(This->lock));
1127 This->pan = pan;
1129 temp = (double) (This->volume - (This->pan > 0 ? This->pan : 0));
1130 This->lVolAdjust = (ULONG) (pow(2.0, temp / 600.0) * 32768.0);
1131 temp = (double) (This->volume + (This->pan < 0 ? This->pan : 0));
1132 This->rVolAdjust = (ULONG) (pow(2.0, temp / 600.0) * 32768.0);
1134 LeaveCriticalSection(&(This->lock));
1135 /* **** */
1137 return DS_OK;
1140 static HRESULT WINAPI IDirectSoundBufferImpl_GetPan(
1141 LPDIRECTSOUNDBUFFER iface,LPLONG pan
1143 ICOM_THIS(IDirectSoundBufferImpl,iface);
1144 TRACE(dsound,"(%p,%p)\n",This,pan);
1146 if (pan == NULL)
1147 return DSERR_INVALIDPARAM;
1149 *pan = This->pan;
1151 return DS_OK;
1154 static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(
1155 LPDIRECTSOUNDBUFFER iface,LPVOID p1,DWORD x1,LPVOID p2,DWORD x2
1157 ICOM_THIS(IDirectSoundBufferImpl,iface);
1158 TRACE(dsound,"(%p,%p,%ld,%p,%ld):stub\n", This,p1,x1,p2,x2);
1160 /* There is really nothing to do here. Should someone */
1161 /* choose to implement static buffers in hardware (by */
1162 /* using a wave table synth, for example) this is where */
1163 /* you'd want to do the loading. For software buffers, */
1164 /* which is what we currently use, we need do nothing. */
1166 #if 0
1167 /* It's also the place to pre-process 3D buffers... */
1169 /* This is highly experimental and liable to break things */
1170 if (This->dsbd.dwFlags & DSBCAPS_CTRL3D)
1171 DSOUND_Create3DBuffer(This);
1172 #endif
1174 return DS_OK;
1177 static HRESULT WINAPI IDirectSoundBufferImpl_GetFrequency(
1178 LPDIRECTSOUNDBUFFER iface,LPDWORD freq
1180 ICOM_THIS(IDirectSoundBufferImpl,iface);
1181 TRACE(dsound,"(%p,%p)\n",This,freq);
1183 if (freq == NULL)
1184 return DSERR_INVALIDPARAM;
1186 *freq = This->freq;
1188 return DS_OK;
1191 static HRESULT WINAPI IDirectSoundBufferImpl_Initialize(
1192 LPDIRECTSOUNDBUFFER iface,LPDIRECTSOUND dsound,LPDSBUFFERDESC dbsd
1194 ICOM_THIS(IDirectSoundBufferImpl,iface);
1195 FIXME(dsound,"(%p,%p,%p):stub\n",This,dsound,dbsd);
1196 printf("Re-Init!!!\n");
1197 return DSERR_ALREADYINITIALIZED;
1200 static HRESULT WINAPI IDirectSoundBufferImpl_GetCaps(
1201 LPDIRECTSOUNDBUFFER iface,LPDSBCAPS caps
1203 ICOM_THIS(IDirectSoundBufferImpl,iface);
1204 TRACE(dsound,"(%p)->(%p)\n",This,caps);
1206 if (caps == NULL)
1207 return DSERR_INVALIDPARAM;
1209 /* I think we should check this value, not set it. See */
1210 /* Inside DirectX, p215. That should apply here, too. */
1211 caps->dwSize = sizeof(*caps);
1213 caps->dwFlags = This->dsbd.dwFlags | DSBCAPS_LOCSOFTWARE;
1214 caps->dwBufferBytes = This->dsbd.dwBufferBytes;
1215 /* This value represents the speed of the "unlock" command.
1216 As unlock is quite fast (it does not do anything), I put
1217 4096 ko/s = 4 Mo / s */
1218 caps->dwUnlockTransferRate = 4096;
1219 caps->dwPlayCpuOverhead = 0;
1221 return DS_OK;
1224 static HRESULT WINAPI IDirectSoundBufferImpl_QueryInterface(
1225 LPDIRECTSOUNDBUFFER iface,REFIID riid,LPVOID *ppobj
1227 ICOM_THIS(IDirectSoundBufferImpl,iface);
1228 char xbuf[50];
1230 WINE_StringFromCLSID(riid,xbuf);
1231 TRACE(dsound,"(%p,%s,%p)\n",This,xbuf,ppobj);
1233 if (!memcmp(&IID_IDirectSoundNotify,riid,sizeof(*riid))) {
1234 IDirectSoundNotifyImpl *dsn;
1236 dsn = (IDirectSoundNotifyImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(*dsn));
1237 dsn->ref = 1;
1238 dsn->dsb = This;
1239 IDirectSoundBuffer_AddRef(iface);
1240 dsn->lpvtbl = &dsnvt;
1241 *ppobj = (LPVOID)dsn;
1242 return 0;
1245 if (!memcmp(&IID_IDirectSound3DBuffer,riid,sizeof(*riid))) {
1246 *ppobj = This->ds3db;
1247 if (*ppobj)
1248 return DS_OK;
1251 return E_FAIL;
1254 static ICOM_VTABLE(IDirectSoundBuffer) dsbvt = {
1255 IDirectSoundBufferImpl_QueryInterface,
1256 IDirectSoundBufferImpl_AddRef,
1257 IDirectSoundBufferImpl_Release,
1258 IDirectSoundBufferImpl_GetCaps,
1259 IDirectSoundBufferImpl_GetCurrentPosition,
1260 IDirectSoundBufferImpl_GetFormat,
1261 IDirectSoundBufferImpl_GetVolume,
1262 IDirectSoundBufferImpl_GetPan,
1263 IDirectSoundBufferImpl_GetFrequency,
1264 IDirectSoundBufferImpl_GetStatus,
1265 IDirectSoundBufferImpl_Initialize,
1266 IDirectSoundBufferImpl_Lock,
1267 IDirectSoundBufferImpl_Play,
1268 IDirectSoundBufferImpl_SetCurrentPosition,
1269 IDirectSoundBufferImpl_SetFormat,
1270 IDirectSoundBufferImpl_SetVolume,
1271 IDirectSoundBufferImpl_SetPan,
1272 IDirectSoundBufferImpl_SetFrequency,
1273 IDirectSoundBufferImpl_Stop,
1274 IDirectSoundBufferImpl_Unlock
1277 /*******************************************************************************
1278 * IDirectSound
1281 static HRESULT WINAPI IDirectSoundImpl_SetCooperativeLevel(
1282 LPDIRECTSOUND iface,HWND hwnd,DWORD level
1284 ICOM_THIS(IDirectSoundImpl,iface);
1285 FIXME(dsound,"(%p,%08lx,%ld):stub\n",This,(DWORD)hwnd,level);
1286 return 0;
1289 static HRESULT WINAPI IDirectSoundImpl_CreateSoundBuffer(
1290 LPDIRECTSOUND iface,LPDSBUFFERDESC dsbd,LPLPDIRECTSOUNDBUFFER ppdsb,LPUNKNOWN lpunk
1292 ICOM_THIS(IDirectSoundImpl,iface);
1293 IDirectSoundBufferImpl** ippdsb=(IDirectSoundBufferImpl**)ppdsb;
1294 LPWAVEFORMATEX wfex;
1296 TRACE(dsound,"(%p,%p,%p,%p)\n",This,dsbd,ippdsb,lpunk);
1298 if ((This == NULL) || (dsbd == NULL) || (ippdsb == NULL))
1299 return DSERR_INVALIDPARAM;
1301 if (TRACE_ON(dsound)) {
1302 TRACE(dsound,"(size=%ld)\n",dsbd->dwSize);
1303 TRACE(dsound,"(flags=0x%08lx\n",dsbd->dwFlags);
1304 _dump_DSBCAPS(dsbd->dwFlags);
1305 TRACE(dsound,"(bufferbytes=%ld)\n",dsbd->dwBufferBytes);
1306 TRACE(dsound,"(lpwfxFormat=%p)\n",dsbd->lpwfxFormat);
1309 wfex = dsbd->lpwfxFormat;
1311 if (wfex)
1312 TRACE(dsound,"(formattag=0x%04x,chans=%d,samplerate=%ld"
1313 "bytespersec=%ld,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
1314 wfex->wFormatTag, wfex->nChannels, wfex->nSamplesPerSec,
1315 wfex->nAvgBytesPerSec, wfex->nBlockAlign,
1316 wfex->wBitsPerSample, wfex->cbSize);
1318 if (dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER) {
1319 if (primarybuf) {
1320 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER)primarybuf);
1321 *ippdsb = primarybuf;
1322 return DS_OK;
1323 } /* Else create primarybuf */
1326 *ippdsb = (IDirectSoundBufferImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectSoundBufferImpl));
1327 if (*ippdsb == NULL)
1328 return DSERR_OUTOFMEMORY;
1329 (*ippdsb)->ref = 1;
1331 TRACE(dsound, "Created buffer at %p\n", *ippdsb);
1333 if (dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER) {
1334 (*ippdsb)->buflen = dsound->wfx.nAvgBytesPerSec;
1335 (*ippdsb)->freq = dsound->wfx.nSamplesPerSec;
1336 } else {
1337 (*ippdsb)->buflen = dsbd->dwBufferBytes;
1338 (*ippdsb)->freq = dsbd->lpwfxFormat->nSamplesPerSec;
1340 (*ippdsb)->buffer = (LPBYTE)HeapAlloc(GetProcessHeap(),0,(*ippdsb)->buflen);
1341 if ((*ippdsb)->buffer == NULL) {
1342 HeapFree(GetProcessHeap(),0,(*ippdsb));
1343 *ippdsb = NULL;
1344 return DSERR_OUTOFMEMORY;
1346 /* It's not necessary to initialize values to zero since */
1347 /* we allocated this structure with HEAP_ZERO_MEMORY... */
1348 (*ippdsb)->playpos = 0;
1349 (*ippdsb)->writepos = 0;
1350 (*ippdsb)->parent = NULL;
1351 (*ippdsb)->lpvtbl = &dsbvt;
1352 (*ippdsb)->dsound = This;
1353 (*ippdsb)->playing = 0;
1354 (*ippdsb)->lVolAdjust = (1 << 15);
1355 (*ippdsb)->rVolAdjust = (1 << 15);
1357 if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER)) {
1358 (*ippdsb)->freqAdjust = ((*ippdsb)->freq << DSOUND_FREQSHIFT) /
1359 primarybuf->wfx.nSamplesPerSec;
1360 (*ippdsb)->nAvgBytesPerSec = (*ippdsb)->freq *
1361 dsbd->lpwfxFormat->nBlockAlign;
1364 memcpy(&((*ippdsb)->dsbd),dsbd,sizeof(*dsbd));
1366 /* register buffer */
1367 if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER)) {
1368 This->buffers = (IDirectSoundBufferImpl**)HeapReAlloc(GetProcessHeap(),0,This->buffers,sizeof(IDirectSoundBufferImpl*)*(This->nrofbuffers+1));
1369 This->buffers[This->nrofbuffers] = *ippdsb;
1370 This->nrofbuffers++;
1372 IDirectSound_AddRef(iface);
1374 if (dsbd->lpwfxFormat)
1375 memcpy(&((*ippdsb)->wfx), dsbd->lpwfxFormat, sizeof((*ippdsb)->wfx));
1377 InitializeCriticalSection(&((*ippdsb)->lock));
1379 #if USE_DSOUND3D
1380 if (dsbd->dwFlags & DSBCAPS_CTRL3D) {
1381 IDirectSound3DBufferImpl *ds3db;
1383 ds3db = (IDirectSound3DBufferImpl*)HeapAlloc(GetProcessHeap(),
1384 0,sizeof(*ds3db));
1385 ds3db->ref = 1;
1386 ds3db->dsb = (*ippdsb);
1387 ds3db->lpvtbl = &ds3dbvt;
1388 (*ippdsb)->ds3db = ds3db;
1389 ds3db->ds3db.dwSize = sizeof(DS3DBUFFER);
1390 ds3db->ds3db.vPosition.x.x = 0.0;
1391 ds3db->ds3db.vPosition.y.y = 0.0;
1392 ds3db->ds3db.vPosition.z.z = 0.0;
1393 ds3db->ds3db.vVelocity.x.x = 0.0;
1394 ds3db->ds3db.vVelocity.y.y = 0.0;
1395 ds3db->ds3db.vVelocity.z.z = 0.0;
1396 ds3db->ds3db.dwInsideConeAngle = DS3D_DEFAULTCONEANGLE;
1397 ds3db->ds3db.dwOutsideConeAngle = DS3D_DEFAULTCONEANGLE;
1398 ds3db->ds3db.vConeOrientation.x.x = 0.0;
1399 ds3db->ds3db.vConeOrientation.y.y = 0.0;
1400 ds3db->ds3db.vConeOrientation.z.z = 0.0;
1401 ds3db->ds3db.lConeOutsideVolume = DS3D_DEFAULTCONEOUTSIDEVOLUME;
1402 ds3db->ds3db.flMinDistance = DS3D_DEFAULTMINDISTANCE;
1403 ds3db->ds3db.flMaxDistance = DS3D_DEFAULTMAXDISTANCE;
1404 ds3db->ds3db.dwMode = DS3DMODE_NORMAL;
1405 ds3db->buflen = ((*ippdsb)->buflen * primarybuf->wfx.nBlockAlign) /
1406 (*ippdsb)->wfx.nBlockAlign;
1407 ds3db->buffer = HeapAlloc(GetProcessHeap(), 0, ds3db->buflen);
1408 if (ds3db->buffer == NULL) {
1409 ds3db->buflen = 0;
1410 ds3db->ds3db.dwMode = DS3DMODE_DISABLE;
1413 #endif
1414 return DS_OK;
1417 static HRESULT WINAPI IDirectSoundImpl_DuplicateSoundBuffer(
1418 LPDIRECTSOUND iface,LPDIRECTSOUNDBUFFER pdsb,LPLPDIRECTSOUNDBUFFER ppdsb
1420 ICOM_THIS(IDirectSoundImpl,iface);
1421 IDirectSoundBufferImpl* ipdsb=(IDirectSoundBufferImpl*)pdsb;
1422 IDirectSoundBufferImpl** ippdsb=(IDirectSoundBufferImpl**)ppdsb;
1423 TRACE(dsound,"(%p,%p,%p)\n",This,ipdsb,ippdsb);
1425 *ippdsb = (IDirectSoundBufferImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectSoundBufferImpl));
1427 IDirectSoundBuffer_AddRef(pdsb);
1428 memcpy(*ippdsb, ipdsb, sizeof(IDirectSoundBufferImpl));
1429 (*ippdsb)->ref = 1;
1430 (*ippdsb)->playpos = 0;
1431 (*ippdsb)->writepos = 0;
1432 (*ippdsb)->dsound = This;
1433 (*ippdsb)->parent = ipdsb;
1434 memcpy(&((*ippdsb)->wfx), &(ipdsb->wfx), sizeof((*ippdsb)->wfx));
1435 /* register buffer */
1436 This->buffers = (IDirectSoundBufferImpl**)HeapReAlloc(GetProcessHeap(),0,This->buffers,sizeof(IDirectSoundBufferImpl**)*(This->nrofbuffers+1));
1437 This->buffers[This->nrofbuffers] = *ippdsb;
1438 This->nrofbuffers++;
1439 IDirectSound_AddRef(iface);
1440 return 0;
1444 static HRESULT WINAPI IDirectSoundImpl_GetCaps(LPDIRECTSOUND iface,LPDSCAPS caps) {
1445 ICOM_THIS(IDirectSoundImpl,iface);
1446 TRACE(dsound,"(%p,%p)\n",This,caps);
1447 TRACE(dsound,"(flags=0x%08lx)\n",caps->dwFlags);
1449 if (caps == NULL)
1450 return DSERR_INVALIDPARAM;
1452 /* We should check this value, not set it. See Inside DirectX, p215. */
1453 caps->dwSize = sizeof(*caps);
1455 caps->dwFlags =
1456 DSCAPS_PRIMARYSTEREO |
1457 DSCAPS_PRIMARY16BIT |
1458 DSCAPS_SECONDARYSTEREO |
1459 DSCAPS_SECONDARY16BIT |
1460 DSCAPS_CONTINUOUSRATE;
1461 /* FIXME: query OSS */
1462 caps->dwMinSecondarySampleRate = DSBFREQUENCY_MIN;
1463 caps->dwMaxSecondarySampleRate = DSBFREQUENCY_MAX;
1465 caps->dwPrimaryBuffers = 1;
1467 caps->dwMaxHwMixingAllBuffers = 0;
1468 caps->dwMaxHwMixingStaticBuffers = 0;
1469 caps->dwMaxHwMixingStreamingBuffers = 0;
1471 caps->dwFreeHwMixingAllBuffers = 0;
1472 caps->dwFreeHwMixingStaticBuffers = 0;
1473 caps->dwFreeHwMixingStreamingBuffers = 0;
1475 caps->dwMaxHw3DAllBuffers = 0;
1476 caps->dwMaxHw3DStaticBuffers = 0;
1477 caps->dwMaxHw3DStreamingBuffers = 0;
1479 caps->dwFreeHw3DAllBuffers = 0;
1480 caps->dwFreeHw3DStaticBuffers = 0;
1481 caps->dwFreeHw3DStreamingBuffers = 0;
1483 caps->dwTotalHwMemBytes = 0;
1485 caps->dwFreeHwMemBytes = 0;
1487 caps->dwMaxContigFreeHwMemBytes = 0;
1489 caps->dwUnlockTransferRateHwBuffers = 4096; /* But we have none... */
1491 caps->dwPlayCpuOverheadSwBuffers = 1; /* 1% */
1493 return 0;
1496 static ULONG WINAPI IDirectSoundImpl_AddRef(LPDIRECTSOUND iface) {
1497 ICOM_THIS(IDirectSoundImpl,iface);
1498 return ++(This->ref);
1501 static ULONG WINAPI IDirectSoundImpl_Release(LPDIRECTSOUND iface) {
1502 ICOM_THIS(IDirectSoundImpl,iface);
1503 TRACE(dsound,"(%p), ref was %ld\n",This,This->ref);
1504 if (!--(This->ref)) {
1505 DSOUND_CloseAudio();
1506 while(IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER)primarybuf)); /* Deallocate */
1507 FIXME(dsound, "need to release all buffers!\n");
1508 HeapFree(GetProcessHeap(),0,This);
1509 dsound = NULL;
1510 return 0;
1512 return This->ref;
1515 static HRESULT WINAPI IDirectSoundImpl_SetSpeakerConfig(
1516 LPDIRECTSOUND iface,DWORD config
1518 ICOM_THIS(IDirectSoundImpl,iface);
1519 FIXME(dsound,"(%p,0x%08lx):stub\n",This,config);
1520 return 0;
1523 static HRESULT WINAPI IDirectSoundImpl_QueryInterface(
1524 LPDIRECTSOUND iface,REFIID riid,LPVOID *ppobj
1526 ICOM_THIS(IDirectSoundImpl,iface);
1527 char xbuf[50];
1529 if (!memcmp(&IID_IDirectSound3DListener,riid,sizeof(*riid))) {
1531 if (This->listener) {
1532 *ppobj = This->listener;
1533 return DS_OK;
1535 This->listener = (IDirectSound3DListenerImpl*)HeapAlloc(
1536 GetProcessHeap(), 0, sizeof(*(This->listener)));
1537 This->listener->ref = 1;
1538 This->listener->lpvtbl = &ds3dlvt;
1539 IDirectSound_AddRef(iface);
1540 This->listener->ds3dl.dwSize = sizeof(DS3DLISTENER);
1541 This->listener->ds3dl.vPosition.x.x = 0.0;
1542 This->listener->ds3dl.vPosition.y.y = 0.0;
1543 This->listener->ds3dl.vPosition.z.z = 0.0;
1544 This->listener->ds3dl.vVelocity.x.x = 0.0;
1545 This->listener->ds3dl.vVelocity.y.y = 0.0;
1546 This->listener->ds3dl.vVelocity.z.z = 0.0;
1547 This->listener->ds3dl.vOrientFront.x.x = 0.0;
1548 This->listener->ds3dl.vOrientFront.y.y = 0.0;
1549 This->listener->ds3dl.vOrientFront.z.z = 1.0;
1550 This->listener->ds3dl.vOrientTop.x.x = 0.0;
1551 This->listener->ds3dl.vOrientTop.y.y = 1.0;
1552 This->listener->ds3dl.vOrientTop.z.z = 0.0;
1553 This->listener->ds3dl.flDistanceFactor = DS3D_DEFAULTDISTANCEFACTOR;
1554 This->listener->ds3dl.flRolloffFactor = DS3D_DEFAULTROLLOFFFACTOR;
1555 This->listener->ds3dl.flDopplerFactor = DS3D_DEFAULTDOPPLERFACTOR;
1556 *ppobj = (LPVOID)This->listener;
1557 return DS_OK;
1560 WINE_StringFromCLSID(riid,xbuf);
1561 TRACE(dsound,"(%p,%s,%p)\n",This,xbuf,ppobj);
1562 return E_FAIL;
1565 static HRESULT WINAPI IDirectSoundImpl_Compact(
1566 LPDIRECTSOUND iface)
1568 ICOM_THIS(IDirectSoundImpl,iface);
1569 TRACE(dsound, "(%p)\n", This);
1570 return DS_OK;
1573 static HRESULT WINAPI IDirectSoundImpl_GetSpeakerConfig(
1574 LPDIRECTSOUND iface,
1575 LPDWORD lpdwSpeakerConfig)
1577 ICOM_THIS(IDirectSoundImpl,iface);
1578 TRACE(dsound, "(%p, %p)\n", This, lpdwSpeakerConfig);
1579 *lpdwSpeakerConfig = DSSPEAKER_STEREO | (DSSPEAKER_GEOMETRY_NARROW << 16);
1580 return DS_OK;
1583 static HRESULT WINAPI IDirectSoundImpl_Initialize(
1584 LPDIRECTSOUND iface,
1585 LPGUID lpGuid)
1587 ICOM_THIS(IDirectSoundImpl,iface);
1588 TRACE(dsound, "(%p, %p)\n", This, lpGuid);
1589 return DS_OK;
1592 static ICOM_VTABLE(IDirectSound) dsvt = {
1593 IDirectSoundImpl_QueryInterface,
1594 IDirectSoundImpl_AddRef,
1595 IDirectSoundImpl_Release,
1596 IDirectSoundImpl_CreateSoundBuffer,
1597 IDirectSoundImpl_GetCaps,
1598 IDirectSoundImpl_DuplicateSoundBuffer,
1599 IDirectSoundImpl_SetCooperativeLevel,
1600 IDirectSoundImpl_Compact,
1601 IDirectSoundImpl_GetSpeakerConfig,
1602 IDirectSoundImpl_SetSpeakerConfig,
1603 IDirectSoundImpl_Initialize
1607 /* See http://www.opensound.com/pguide/audio.html for more details */
1609 static int
1610 DSOUND_setformat(LPWAVEFORMATEX wfex) {
1611 int xx,channels,speed,format,nformat;
1613 if (!audioOK) {
1614 TRACE(dsound, "(%p) deferred\n", wfex);
1615 return 0;
1617 switch (wfex->wFormatTag) {
1618 default:
1619 WARN(dsound,"unknown WAVE_FORMAT tag %d\n",wfex->wFormatTag);
1620 return DSERR_BADFORMAT;
1621 case WAVE_FORMAT_PCM:
1622 break;
1624 if (wfex->wBitsPerSample==8)
1625 format = AFMT_U8;
1626 else
1627 format = AFMT_S16_LE;
1629 if (-1==ioctl(audiofd,SNDCTL_DSP_GETFMTS,&xx)) {
1630 perror("ioctl SNDCTL_DSP_GETFMTS");
1631 return -1;
1633 if ((xx&format)!=format) {/* format unsupported */
1634 FIXME(dsound,"SNDCTL_DSP_GETFMTS: format not supported\n");
1635 return -1;
1637 nformat = format;
1638 if (-1==ioctl(audiofd,SNDCTL_DSP_SETFMT,&nformat)) {
1639 perror("ioctl SNDCTL_DSP_SETFMT");
1640 return -1;
1642 if (nformat!=format) {/* didn't work */
1643 FIXME(dsound,"SNDCTL_DSP_GETFMTS: format not set\n");
1644 return -1;
1647 channels = wfex->nChannels-1;
1648 if (-1==ioctl(audiofd,SNDCTL_DSP_STEREO,&channels)) {
1649 perror("ioctl SNDCTL_DSP_STEREO");
1650 return -1;
1652 speed = wfex->nSamplesPerSec;
1653 if (-1==ioctl(audiofd,SNDCTL_DSP_SPEED,&speed)) {
1654 perror("ioctl SNDCTL_DSP_SPEED");
1655 return -1;
1657 TRACE(dsound,"(freq=%ld,channels=%d,bits=%d)\n",
1658 wfex->nSamplesPerSec,wfex->nChannels,wfex->wBitsPerSample
1660 return 0;
1663 static void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len)
1665 int i;
1666 DWORD offset;
1667 LPDSBPOSITIONNOTIFY event;
1669 if (dsb->nrofnotifies == 0)
1670 return;
1672 TRACE(dsound,"(%p) buflen = %ld, playpos = %ld, len = %d\n",
1673 dsb, dsb->buflen, dsb->playpos, len);
1674 for (i = 0; i < dsb->nrofnotifies ; i++) {
1675 event = dsb->notifies + i;
1676 offset = event->dwOffset;
1677 TRACE(dsound, "checking %d, position %ld, event = %d\n",
1678 i, offset, event->hEventNotify);
1679 /* DSBPN_OFFSETSTOP has to be the last element. So this is */
1680 /* OK. [Inside DirectX, p274] */
1681 /* */
1682 /* This also means we can't sort the entries by offset, */
1683 /* because DSBPN_OFFSETSTOP == -1 */
1684 if (offset == DSBPN_OFFSETSTOP) {
1685 if (dsb->playing == 0) {
1686 SetEvent(event->hEventNotify);
1687 TRACE(dsound,"signalled event %d (%d)\n", event->hEventNotify, i);
1688 return;
1689 } else
1690 return;
1692 if ((dsb->playpos + len) >= dsb->buflen) {
1693 if ((offset < ((dsb->playpos + len) % dsb->buflen)) ||
1694 (offset >= dsb->playpos)) {
1695 TRACE(dsound,"signalled event %d (%d)\n", event->hEventNotify, i);
1696 SetEvent(event->hEventNotify);
1698 } else {
1699 if ((offset >= dsb->playpos) && (offset < (dsb->playpos + len))) {
1700 TRACE(dsound,"signalled event %d (%d)\n", event->hEventNotify, i);
1701 SetEvent(event->hEventNotify);
1707 /* WAV format info can be found at: */
1708 /* */
1709 /* http://www.cwi.nl/ftp/audio/AudioFormats.part2 */
1710 /* ftp://ftp.cwi.nl/pub/audio/RIFF-format */
1711 /* */
1712 /* Import points to remember: */
1713 /* */
1714 /* 8-bit WAV is unsigned */
1715 /* 16-bit WAV is signed */
1717 static __inline__ INT16 cvtU8toS16(BYTE byte)
1719 INT16 s = (byte - 128) << 8;
1721 return s;
1724 static __inline__ BYTE cvtS16toU8(INT16 word)
1726 BYTE b = (word + 32768) >> 8;
1728 return b;
1732 /* We should be able to optimize these two inline functions */
1733 /* so that we aren't doing 8->16->8 conversions when it is */
1734 /* not necessary. But this is still a WIP. Optimize later. */
1735 static __inline__ void get_fields(const IDirectSoundBufferImpl *dsb, BYTE *buf, INT *fl, INT *fr)
1737 INT16 *bufs = (INT16 *) buf;
1739 /* TRACE(dsound, "(%p)", buf); */
1740 if ((dsb->wfx.wBitsPerSample == 8) && dsb->wfx.nChannels == 2) {
1741 *fl = cvtU8toS16(*buf);
1742 *fr = cvtU8toS16(*(buf + 1));
1743 return;
1746 if ((dsb->wfx.wBitsPerSample == 16) && dsb->wfx.nChannels == 2) {
1747 *fl = *bufs;
1748 *fr = *(bufs + 1);
1749 return;
1752 if ((dsb->wfx.wBitsPerSample == 8) && dsb->wfx.nChannels == 1) {
1753 *fl = cvtU8toS16(*buf);
1754 *fr = *fl;
1755 return;
1758 if ((dsb->wfx.wBitsPerSample == 16) && dsb->wfx.nChannels == 1) {
1759 *fl = *bufs;
1760 *fr = *bufs;
1761 return;
1764 FIXME(dsound, "get_fields found an unsupported configuration\n");
1765 return;
1768 static __inline__ void set_fields(BYTE *buf, INT fl, INT fr)
1770 INT16 *bufs = (INT16 *) buf;
1772 if ((primarybuf->wfx.wBitsPerSample == 8) && (primarybuf->wfx.nChannels == 2)) {
1773 *buf = cvtS16toU8(fl);
1774 *(buf + 1) = cvtS16toU8(fr);
1775 return;
1778 if ((primarybuf->wfx.wBitsPerSample == 16) && (primarybuf->wfx.nChannels == 2)) {
1779 *bufs = fl;
1780 *(bufs + 1) = fr;
1781 return;
1784 if ((primarybuf->wfx.wBitsPerSample == 8) && (primarybuf->wfx.nChannels == 1)) {
1785 *buf = cvtS16toU8((fl + fr) >> 1);
1786 return;
1789 if ((primarybuf->wfx.wBitsPerSample == 16) && (primarybuf->wfx.nChannels == 1)) {
1790 *bufs = (fl + fr) >> 1;
1791 return;
1793 FIXME(dsound, "set_fields found an unsupported configuration\n");
1794 return;
1797 /* Now with PerfectPitch (tm) technology */
1798 static INT DSOUND_MixerNorm(IDirectSoundBufferImpl *dsb, BYTE *buf, INT len)
1800 INT i, size, ipos, ilen, fieldL, fieldR;
1801 BYTE *ibp, *obp;
1802 INT iAdvance = dsb->wfx.nBlockAlign;
1803 INT oAdvance = primarybuf->wfx.nBlockAlign;
1805 ibp = dsb->buffer + dsb->playpos;
1806 obp = buf;
1808 TRACE(dsound, "(%p, %p, %p), playpos=%8.8lx\n", dsb, ibp, obp, dsb->playpos);
1809 /* Check for the best case */
1810 if ((dsb->freq == primarybuf->wfx.nSamplesPerSec) &&
1811 (dsb->wfx.wBitsPerSample == primarybuf->wfx.wBitsPerSample) &&
1812 (dsb->wfx.nChannels == primarybuf->wfx.nChannels)) {
1813 TRACE(dsound, "(%p) Best case\n", dsb);
1814 if ((ibp + len) < (BYTE *)(dsb->buffer + dsb->buflen))
1815 memcpy(obp, ibp, len);
1816 else { /* wrap */
1817 memcpy(obp, ibp, dsb->buflen - dsb->playpos);
1818 memcpy(obp + (dsb->buflen - dsb->playpos),
1819 dsb->buffer,
1820 len - (dsb->buflen - dsb->playpos));
1822 return len;
1825 /* Check for same sample rate */
1826 if (dsb->freq == primarybuf->wfx.nSamplesPerSec) {
1827 TRACE(dsound, "(%p) Same sample rate %ld = primary %ld\n", dsb,
1828 dsb->freq, primarybuf->wfx.nSamplesPerSec);
1829 ilen = 0;
1830 for (i = 0; i < len; i += oAdvance) {
1831 get_fields(dsb, ibp, &fieldL, &fieldR);
1832 ibp += iAdvance;
1833 ilen += iAdvance;
1834 set_fields(obp, fieldL, fieldR);
1835 obp += oAdvance;
1836 if (ibp >= (BYTE *)(dsb->buffer + dsb->buflen))
1837 ibp = dsb->buffer; /* wrap */
1839 return (ilen);
1842 /* Mix in different sample rates */
1843 /* */
1844 /* New PerfectPitch(tm) Technology (c) 1998 Rob Riggs */
1845 /* Patent Pending :-] */
1847 TRACE(dsound, "(%p) Adjusting frequency: %ld -> %ld\n",
1848 dsb, dsb->freq, primarybuf->wfx.nSamplesPerSec);
1850 size = len / oAdvance;
1851 ilen = ((size * dsb->freqAdjust) >> DSOUND_FREQSHIFT) * iAdvance;
1852 for (i = 0; i < size; i++) {
1854 ipos = (((i * dsb->freqAdjust) >> DSOUND_FREQSHIFT) * iAdvance) + dsb->playpos;
1856 if (ipos >= dsb->buflen)
1857 ipos %= dsb->buflen; /* wrap */
1859 get_fields(dsb, (dsb->buffer + ipos), &fieldL, &fieldR);
1860 set_fields(obp, fieldL, fieldR);
1861 obp += oAdvance;
1863 return ilen;
1866 static void DSOUND_MixerVol(IDirectSoundBufferImpl *dsb, BYTE *buf, INT len)
1868 INT i, inc = primarybuf->wfx.wBitsPerSample >> 3;
1869 BYTE *bpc = buf;
1870 INT16 *bps = (INT16 *) buf;
1872 TRACE(dsound, "(%p) left = %lx, right = %lx\n", dsb,
1873 dsb->lVolAdjust, dsb->rVolAdjust);
1874 if ((!(dsb->dsbd.dwFlags & DSBCAPS_CTRLPAN) || (dsb->pan == 0)) &&
1875 (!(dsb->dsbd.dwFlags & DSBCAPS_CTRLVOLUME) || (dsb->volume == 0)) &&
1876 !(dsb->dsbd.dwFlags & DSBCAPS_CTRL3D))
1877 return; /* Nothing to do */
1879 /* If we end up with some bozo coder using panning or 3D sound */
1880 /* with a mono primary buffer, it could sound very weird using */
1881 /* this method. Oh well, tough patooties. */
1883 for (i = 0; i < len; i += inc) {
1884 INT val;
1886 switch (inc) {
1888 case 1:
1889 /* 8-bit WAV is unsigned, but we need to operate */
1890 /* on signed data for this to work properly */
1891 val = *bpc - 128;
1892 val = ((val * (i & inc ? dsb->rVolAdjust : dsb->lVolAdjust)) >> 15);
1893 *bpc = val + 128;
1894 bpc++;
1895 break;
1896 case 2:
1897 /* 16-bit WAV is signed -- much better */
1898 val = *bps;
1899 val = ((val * ((i & inc) ? dsb->rVolAdjust : dsb->lVolAdjust)) >> 15);
1900 *bps = val;
1901 bps++;
1902 break;
1903 default:
1904 /* Very ugly! */
1905 FIXME(dsound, "MixerVol had a nasty error\n");
1910 #ifdef USE_DSOUND3D
1911 static void DSOUND_Mixer3D(IDirectSoundBufferImpl *dsb, BYTE *buf, INT len)
1913 BYTE *ibp, *obp;
1914 DWORD buflen, playpos;
1916 buflen = dsb->ds3db->buflen;
1917 playpos = (dsb->playpos * primarybuf->wfx.nBlockAlign) / dsb->wfx.nBlockAlign;
1918 ibp = dsb->ds3db->buffer + playpos;
1919 obp = buf;
1921 if (playpos > buflen) {
1922 FIXME(dsound, "Major breakage");
1923 return;
1926 if (len <= (playpos + buflen))
1927 memcpy(obp, ibp, len);
1928 else { /* wrap */
1929 memcpy(obp, ibp, buflen - playpos);
1930 memcpy(obp + (buflen - playpos),
1931 dsb->buffer,
1932 len - (buflen - playpos));
1934 return;
1936 #endif
1938 static DWORD DSOUND_MixInBuffer(IDirectSoundBufferImpl *dsb)
1940 INT i, len, ilen, temp, field;
1941 INT advance = primarybuf->wfx.wBitsPerSample >> 3;
1942 BYTE *buf, *ibuf, *obuf;
1943 INT16 *ibufs, *obufs;
1945 len = DSOUND_FRAGLEN; /* The most we will use */
1946 if (!(dsb->playflags & DSBPLAY_LOOPING)) {
1947 temp = MulDiv(primarybuf->wfx.nAvgBytesPerSec, dsb->buflen,
1948 dsb->nAvgBytesPerSec) -
1949 MulDiv(primarybuf->wfx.nAvgBytesPerSec, dsb->playpos,
1950 dsb->nAvgBytesPerSec);
1951 len = (len > temp) ? temp : len;
1953 len &= ~3; /* 4 byte alignment */
1955 if (len == 0) {
1956 /* This should only happen if we aren't looping and temp < 4 */
1958 /* We skip the remainder, so check for possible events */
1959 DSOUND_CheckEvent(dsb, dsb->buflen - dsb->playpos);
1960 /* Stop */
1961 dsb->playing = 0;
1962 dsb->writepos = 0;
1963 dsb->playpos = 0;
1964 /* Check for DSBPN_OFFSETSTOP */
1965 DSOUND_CheckEvent(dsb, 0);
1966 return 0;
1969 /* Been seeing segfaults in malloc() for some reason... */
1970 TRACE(dsound, "allocating buffer (size = %d)\n", len);
1971 if ((buf = ibuf = (BYTE *) malloc(len)) == NULL)
1972 return 0;
1974 TRACE(dsound, "MixInBuffer (%p) len = %d\n", dsb, len);
1976 ilen = DSOUND_MixerNorm(dsb, ibuf, len);
1977 if ((dsb->dsbd.dwFlags & DSBCAPS_CTRLPAN) ||
1978 (dsb->dsbd.dwFlags & DSBCAPS_CTRLVOLUME))
1979 DSOUND_MixerVol(dsb, ibuf, len);
1981 obuf = primarybuf->buffer + primarybuf->playpos;
1982 for (i = 0; i < len; i += advance) {
1983 obufs = (INT16 *) obuf;
1984 ibufs = (INT16 *) ibuf;
1985 if (primarybuf->wfx.wBitsPerSample == 8) {
1986 /* 8-bit WAV is unsigned */
1987 field = (*ibuf - 128);
1988 field += (*obuf - 128);
1989 field = field > 127 ? 127 : field;
1990 field = field < -128 ? -128 : field;
1991 *obuf = field + 128;
1992 } else {
1993 /* 16-bit WAV is signed */
1994 field = *ibufs;
1995 field += *obufs;
1996 field = field > 32767 ? 32767 : field;
1997 field = field < -32768 ? -32768 : field;
1998 *obufs = field;
2000 ibuf += advance;
2001 obuf += advance;
2002 if (obuf >= (BYTE *)(primarybuf->buffer + primarybuf->buflen))
2003 obuf = primarybuf->buffer;
2005 free(buf);
2007 if (dsb->dsbd.dwFlags & DSBCAPS_CTRLPOSITIONNOTIFY)
2008 DSOUND_CheckEvent(dsb, ilen);
2010 dsb->playpos += ilen;
2011 dsb->writepos = dsb->playpos + ilen;
2013 if (dsb->playpos >= dsb->buflen) {
2014 if (!(dsb->playflags & DSBPLAY_LOOPING)) {
2015 dsb->playing = 0;
2016 dsb->writepos = 0;
2017 dsb->playpos = 0;
2018 DSOUND_CheckEvent(dsb, 0); /* For DSBPN_OFFSETSTOP */
2019 } else
2020 dsb->playpos %= dsb->buflen; /* wrap */
2023 if (dsb->writepos >= dsb->buflen)
2024 dsb->writepos %= dsb->buflen;
2026 return len;
2029 static DWORD WINAPI DSOUND_MixPrimary(void)
2031 INT i, len, maxlen = 0;
2032 IDirectSoundBufferImpl *dsb;
2034 for (i = dsound->nrofbuffers - 1; i >= 0; i--) {
2035 dsb = dsound->buffers[i];
2037 if (!dsb || !(dsb->lpvtbl))
2038 continue;
2039 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER)dsb);
2040 if (dsb->buflen && dsb->playing) {
2041 EnterCriticalSection(&(dsb->lock));
2042 len = DSOUND_MixInBuffer(dsb);
2043 maxlen = len > maxlen ? len : maxlen;
2044 LeaveCriticalSection(&(dsb->lock));
2046 IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER)dsb);
2049 return maxlen;
2052 static int DSOUND_OpenAudio(void)
2054 int audioFragment;
2056 if (primarybuf == NULL)
2057 return DSERR_OUTOFMEMORY;
2059 while (audiofd != -1)
2060 sleep(5);
2061 audiofd = open("/dev/audio",O_WRONLY);
2062 if (audiofd==-1) {
2063 /* Don't worry if sound is busy at the moment */
2064 if (errno != EBUSY)
2065 perror("open /dev/audio");
2066 return audiofd; /* -1 */
2069 /* We should probably do something here if SETFRAGMENT fails... */
2070 audioFragment=0x0002000c;
2071 if (-1==ioctl(audiofd,SNDCTL_DSP_SETFRAGMENT,&audioFragment))
2072 perror("ioctl SETFRAGMENT");
2074 audioOK = 1;
2075 DSOUND_setformat(&(primarybuf->wfx));
2077 return 0;
2080 static void DSOUND_CloseAudio(void)
2082 int neutral;
2084 neutral = primarybuf->wfx.wBitsPerSample == 8 ? 128 : 0;
2085 audioOK = 0; /* race condition */
2086 Sleep(5);
2087 /* It's possible we've been called with audio closed */
2088 /* from SetFormat()... this is just to force a call */
2089 /* to OpenAudio() to reset the hardware properly */
2090 if (audiofd != -1)
2091 close(audiofd);
2092 primarybuf->playpos = 0;
2093 primarybuf->writepos = DSOUND_FRAGLEN;
2094 memset(primarybuf->buffer, neutral, primarybuf->buflen);
2095 audiofd = -1;
2096 TRACE(dsound, "Audio stopped\n");
2099 static int DSOUND_WriteAudio(char *buf, int len)
2101 int result, left = 0;
2103 while (left < len) {
2104 result = write(audiofd, buf + left, len - left);
2105 if (result == -1) {
2106 if (errno == EINTR)
2107 continue;
2108 else
2109 return result;
2111 left += result;
2113 return 0;
2116 static void DSOUND_OutputPrimary(int len)
2118 int neutral, flen1, flen2;
2119 char *frag1, *frag2;
2121 /* This is a bad place for this. We need to clear the */
2122 /* buffer with a neutral value, for unsigned 8-bit WAVE */
2123 /* that's 128, for signed 16-bit it's 0 */
2124 neutral = primarybuf->wfx.wBitsPerSample == 8 ? 128 : 0;
2126 /* **** */
2127 EnterCriticalSection(&(primarybuf->lock));
2129 /* Write out the */
2130 if ((audioOK == 1) || (DSOUND_OpenAudio() == 0)) {
2131 if (primarybuf->playpos + len >= primarybuf->buflen) {
2132 frag1 = primarybuf->buffer + primarybuf->playpos;
2133 flen1 = primarybuf->buflen - primarybuf->playpos;
2134 frag2 = primarybuf->buffer;
2135 flen2 = len - (primarybuf->buflen - primarybuf->playpos);
2136 if (DSOUND_WriteAudio(frag1, flen1) != 0) {
2137 perror("DSOUND_WriteAudio");
2138 LeaveCriticalSection(&(primarybuf->lock));
2139 ExitThread(0);
2141 memset(frag1, neutral, flen1);
2142 if (DSOUND_WriteAudio(frag2, flen2) != 0) {
2143 perror("DSOUND_WriteAudio");
2144 LeaveCriticalSection(&(primarybuf->lock));
2145 ExitThread(0);
2147 memset(frag2, neutral, flen2);
2148 } else {
2149 frag1 = primarybuf->buffer + primarybuf->playpos;
2150 flen1 = len;
2151 if (DSOUND_WriteAudio(frag1, flen1) != 0) {
2152 perror("DSOUND_WriteAudio");
2153 LeaveCriticalSection(&(primarybuf->lock));
2154 ExitThread(0);
2156 memset(frag1, neutral, flen1);
2158 } else {
2159 /* Can't play audio at the moment -- we need to sleep */
2160 /* to make up for the time we'd be blocked in write() */
2161 /* to /dev/audio */
2162 Sleep(60);
2164 primarybuf->playpos += len;
2165 if (primarybuf->playpos >= primarybuf->buflen)
2166 primarybuf->playpos %= primarybuf->buflen;
2167 primarybuf->writepos = primarybuf->playpos + DSOUND_FRAGLEN;
2168 if (primarybuf->writepos >= primarybuf->buflen)
2169 primarybuf->writepos %= primarybuf->buflen;
2171 LeaveCriticalSection(&(primarybuf->lock));
2172 /* **** */
2175 static DWORD WINAPI DSOUND_thread(LPVOID arg)
2177 int len;
2179 TRACE(dsound,"dsound is at pid %d\n",getpid());
2180 while (1) {
2181 if (!dsound) {
2182 WARN(dsound,"DSOUND thread giving up.\n");
2183 ExitThread(0);
2185 if (getppid()==1) {
2186 WARN(dsound,"DSOUND father died? Giving up.\n");
2187 ExitThread(0);
2189 /* RACE: dsound could be deleted */
2190 IDirectSound_AddRef((LPDIRECTSOUND)dsound);
2191 if (primarybuf == NULL) {
2192 /* Should never happen */
2193 WARN(dsound, "Lost the primary buffer!\n");
2194 IDirectSound_Release((LPDIRECTSOUND)dsound);
2195 ExitThread(0);
2198 /* **** */
2199 EnterCriticalSection(&(primarybuf->lock));
2200 len = DSOUND_MixPrimary();
2201 LeaveCriticalSection(&(primarybuf->lock));
2202 /* **** */
2204 if (primarybuf->playing)
2205 len = DSOUND_FRAGLEN > len ? DSOUND_FRAGLEN : len;
2206 if (len) {
2207 /* This does all the work */
2208 DSOUND_OutputPrimary(len);
2209 } else {
2210 /* no buffers playing -- close and wait */
2211 if (audioOK)
2212 DSOUND_CloseAudio();
2213 Sleep(100);
2215 IDirectSound_Release((LPDIRECTSOUND)dsound);
2217 ExitThread(0);
2220 #endif /* HAVE_OSS */
2222 HRESULT WINAPI DirectSoundCreate(REFGUID lpGUID,LPDIRECTSOUND *ppDS,IUnknown *pUnkOuter )
2224 IDirectSoundImpl** ippDS=(IDirectSoundImpl**)ppDS;
2225 if (lpGUID)
2226 TRACE(dsound,"(%p,%p,%p)\n",lpGUID,ippDS,pUnkOuter);
2227 else
2228 TRACE(dsound,"DirectSoundCreate (%p)\n", ippDS);
2230 #ifdef HAVE_OSS
2232 if (ippDS == NULL)
2233 return DSERR_INVALIDPARAM;
2235 if (primarybuf) {
2236 IDirectSound_AddRef((LPDIRECTSOUND)dsound);
2237 *ippDS = dsound;
2238 return DS_OK;
2241 /* Check that we actually have audio capabilities */
2242 /* If we do, whether it's busy or not, we continue */
2243 /* otherwise we return with DSERR_NODRIVER */
2245 audiofd = open("/dev/audio",O_WRONLY);
2246 if (audiofd == -1) {
2247 if (errno == ENODEV) {
2248 MSG("No sound hardware found.\n");
2249 return DSERR_NODRIVER;
2250 } else if (errno == EBUSY) {
2251 MSG("Sound device busy, will keep trying.\n");
2252 } else {
2253 MSG("Unexpected error while checking for sound support.\n");
2254 return DSERR_GENERIC;
2256 } else {
2257 close(audiofd);
2258 audiofd = -1;
2261 *ippDS = (IDirectSoundImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectSoundImpl));
2262 if (*ippDS == NULL)
2263 return DSERR_OUTOFMEMORY;
2265 (*ippDS)->ref = 1;
2266 (*ippDS)->lpvtbl = &dsvt;
2267 (*ippDS)->buffers = NULL;
2268 (*ippDS)->nrofbuffers = 0;
2270 (*ippDS)->wfx.wFormatTag = 1;
2271 (*ippDS)->wfx.nChannels = 2;
2272 (*ippDS)->wfx.nSamplesPerSec = 22050;
2273 (*ippDS)->wfx.nAvgBytesPerSec = 44100;
2274 (*ippDS)->wfx.nBlockAlign = 2;
2275 (*ippDS)->wfx.wBitsPerSample = 8;
2277 if (!dsound) {
2278 HANDLE hnd;
2279 DWORD xid;
2281 dsound = (*ippDS);
2282 if (primarybuf == NULL) {
2283 DSBUFFERDESC dsbd;
2284 HRESULT hr;
2286 dsbd.dwSize = sizeof(DSBUFFERDESC);
2287 dsbd.dwFlags = DSBCAPS_PRIMARYBUFFER;
2288 dsbd.dwBufferBytes = 0;
2289 dsbd.lpwfxFormat = &(dsound->wfx);
2290 hr = IDirectSound_CreateSoundBuffer(*ppDS, &dsbd, (LPDIRECTSOUNDBUFFER*)&primarybuf, NULL);
2291 if (hr != DS_OK)
2292 return hr;
2293 dsound->primary = primarybuf;
2295 memset(primarybuf->buffer, 128, primarybuf->buflen);
2296 hnd = CreateThread(NULL,0,DSOUND_thread,0,0,&xid);
2298 return DS_OK;
2299 #else
2300 MessageBoxA(0,"DirectSound needs the Open Sound System Driver, which has not been found by ./configure.","WINE DirectSound",MB_OK|MB_ICONSTOP);
2301 return DSERR_NODRIVER;
2302 #endif
2305 /*******************************************************************************
2306 * DirectSound ClassFactory
2308 typedef struct
2310 /* IUnknown fields */
2311 ICOM_VTABLE(IClassFactory)* lpvtbl;
2312 DWORD ref;
2313 } IClassFactoryImpl;
2315 static HRESULT WINAPI
2316 DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
2317 ICOM_THIS(IClassFactoryImpl,iface);
2318 char buf[80];
2320 if (HIWORD(riid))
2321 WINE_StringFromCLSID(riid,buf);
2322 else
2323 sprintf(buf,"<guid-0x%04x>",LOWORD(riid));
2324 FIXME(dsound,"(%p)->(%s,%p),stub!\n",This,buf,ppobj);
2325 return E_NOINTERFACE;
2328 static ULONG WINAPI
2329 DSCF_AddRef(LPCLASSFACTORY iface) {
2330 ICOM_THIS(IClassFactoryImpl,iface);
2331 return ++(This->ref);
2334 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface) {
2335 ICOM_THIS(IClassFactoryImpl,iface);
2336 /* static class, won't be freed */
2337 return --(This->ref);
2340 static HRESULT WINAPI DSCF_CreateInstance(
2341 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
2343 ICOM_THIS(IClassFactoryImpl,iface);
2344 char buf[80];
2346 WINE_StringFromCLSID(riid,buf);
2347 TRACE(dsound,"(%p)->(%p,%s,%p)\n",This,pOuter,buf,ppobj);
2348 if (!memcmp(riid,&IID_IDirectSound,sizeof(IID_IDirectSound))) {
2349 /* FIXME: reuse already created dsound if present? */
2350 return DirectSoundCreate(riid,(LPDIRECTSOUND*)ppobj,pOuter);
2352 return E_NOINTERFACE;
2355 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
2356 ICOM_THIS(IClassFactoryImpl,iface);
2357 FIXME(dsound,"(%p)->(%d),stub!\n",This,dolock);
2358 return S_OK;
2361 static ICOM_VTABLE(IClassFactory) DSCF_Vtbl = {
2362 DSCF_QueryInterface,
2363 DSCF_AddRef,
2364 DSCF_Release,
2365 DSCF_CreateInstance,
2366 DSCF_LockServer
2368 static IClassFactoryImpl DSOUND_CF = {&DSCF_Vtbl, 1 };
2370 /*******************************************************************************
2371 * DllGetClassObject [DSOUND.4]
2372 * Retrieves class object from a DLL object
2374 * NOTES
2375 * Docs say returns STDAPI
2377 * PARAMS
2378 * rclsid [I] CLSID for the class object
2379 * riid [I] Reference to identifier of interface for class object
2380 * ppv [O] Address of variable to receive interface pointer for riid
2382 * RETURNS
2383 * Success: S_OK
2384 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
2385 * E_UNEXPECTED
2387 DWORD WINAPI DSOUND_DllGetClassObject(REFCLSID rclsid,REFIID riid,LPVOID *ppv)
2389 char buf[80],xbuf[80];
2391 if (HIWORD(rclsid))
2392 WINE_StringFromCLSID(rclsid,xbuf);
2393 else
2394 sprintf(xbuf,"<guid-0x%04x>",LOWORD(rclsid));
2395 if (HIWORD(riid))
2396 WINE_StringFromCLSID(riid,buf);
2397 else
2398 sprintf(buf,"<guid-0x%04x>",LOWORD(riid));
2399 WINE_StringFromCLSID(riid,xbuf);
2400 TRACE(dsound, "(%p,%p,%p)\n", xbuf, buf, ppv);
2401 if (!memcmp(riid,&IID_IClassFactory,sizeof(IID_IClassFactory))) {
2402 *ppv = (LPVOID)&DSOUND_CF;
2403 IClassFactory_AddRef((IClassFactory*)*ppv);
2404 return S_OK;
2406 FIXME(dsound, "(%p,%p,%p): no interface found.\n", xbuf, buf, ppv);
2407 return E_NOINTERFACE;
2411 /*******************************************************************************
2412 * DllCanUnloadNow [DSOUND.3] Determines whether the DLL is in use.
2414 * RETURNS
2415 * Success: S_OK
2416 * Failure: S_FALSE
2418 DWORD WINAPI DSOUND_DllCanUnloadNow(void)
2420 FIXME(dsound, "(void): stub\n");
2421 return S_FALSE;