3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998 Rob Riggs
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 * FIXME: This file is full of race conditions and unlocked variable access
12 * from two threads. But we usually don't need to bother.
14 * Tested with a Soundblaster clone and a Gravis UltraSound Classic.
17 * - Wing Commander 4/W95:
18 * The intromovie plays without problems. Nearly lipsynchron.
20 * The sound works, but noticeable chunks are left out (from the sound and
21 * the animation). Don't know why yet.
23 * Sound works, but slows down the movieplayer.
27 * The background sound of the startscreen works ;)
28 * - WingCommander Prophecy Demo:
29 * Sound works for the intromovie.
35 #include <sys/types.h>
37 #include <sys/fcntl.h>
41 #include <math.h> /* Insomnia - pow() function */
44 #include "interfaces.h"
52 # include <sys/ioctl.h>
53 # ifdef HAVE_MACHINE_SOUNDCARD_H
54 # include <machine/soundcard.h>
56 # ifdef HAVE_SYS_SOUNDCARD_H
57 # include <sys/soundcard.h>
60 /* #define USE_DSOUND3D 1 */
62 #define DSOUND_BUFLEN (primarybuf->wfx.nAvgBytesPerSec >> 4)
63 #define DSOUND_FREQSHIFT (14)
65 static int audiofd
= -1;
66 static int audioOK
= 0;
68 static LPDIRECTSOUND dsound
= NULL
;
70 static LPDIRECTSOUNDBUFFER primarybuf
= NULL
;
72 static int DSOUND_setformat(LPWAVEFORMATEX wfex
);
73 static void DSOUND_CheckEvent(IDirectSoundBuffer
*dsb
, int len
);
74 static void DSOUND_CloseAudio(void);
78 HRESULT WINAPI
DirectSoundEnumerate32A(LPDSENUMCALLBACK32A enumcb
,LPVOID context
) {
80 enumcb(NULL
,"WINE DirectSound using Open Sound System","sound",context
);
86 static void _dump_DSBCAPS(DWORD xmask
) {
91 #define FE(x) { x, #x },
92 FE(DSBCAPS_PRIMARYBUFFER
)
94 FE(DSBCAPS_LOCHARDWARE
)
95 FE(DSBCAPS_LOCSOFTWARE
)
96 FE(DSBCAPS_CTRLFREQUENCY
)
98 FE(DSBCAPS_CTRLVOLUME
)
99 FE(DSBCAPS_CTRLDEFAULT
)
101 FE(DSBCAPS_STICKYFOCUS
)
102 FE(DSBCAPS_GETCURRENTPOSITION2
)
106 for (i
=0;i
<sizeof(flags
)/sizeof(flags
[0]);i
++)
107 if (flags
[i
].mask
& xmask
)
108 fprintf(stderr
,"%s ",flags
[i
].name
);
111 /*******************************************************************************
112 * IDirectSound3DBuffer
116 static HRESULT WINAPI
IDirectSound3DBuffer_QueryInterface(
117 LPDIRECTSOUND3DBUFFER
this, REFIID riid
, LPVOID
*ppobj
)
121 WINE_StringFromCLSID(riid
,xbuf
);
122 TRACE(dsound
,"(%p,%s,%p)\n",this,xbuf
,ppobj
);
126 static ULONG WINAPI
IDirectSound3DBuffer_AddRef(LPDIRECTSOUND3DBUFFER
this)
132 static ULONG WINAPI
IDirectSound3DBuffer_Release(LPDIRECTSOUND3DBUFFER
this)
137 HeapFree(GetProcessHeap(),0,this->buffer
);
138 HeapFree(GetProcessHeap(),0,this);
143 // IDirectSound3DBuffer methods
144 static HRESULT WINAPI
IDirectSound3DBuffer_GetAllParameters(
145 LPDIRECTSOUND3DBUFFER
this,
146 LPDS3DBUFFER lpDs3dBuffer
)
148 FIXME(dsound
,"stub\n");
152 static HRESULT WINAPI
IDirectSound3DBuffer_GetConeAngles(
153 LPDIRECTSOUND3DBUFFER
this,
154 LPDWORD lpdwInsideConeAngle
,
155 LPDWORD lpdwOutsideConeAngle
)
157 FIXME(dsound
,"stub\n");
161 static HRESULT WINAPI
IDirectSound3DBuffer_GetConeOrientation(
162 LPDIRECTSOUND3DBUFFER
this,
163 LPD3DVECTOR lpvConeOrientation
)
165 FIXME(dsound
,"stub\n");
169 static HRESULT WINAPI
IDirectSound3DBuffer_GetConeOutsideVolume(
170 LPDIRECTSOUND3DBUFFER
this,
171 LPLONG lplConeOutsideVolume
)
173 FIXME(dsound
,"stub\n");
177 static HRESULT WINAPI
IDirectSound3DBuffer_GetMaxDistance(
178 LPDIRECTSOUND3DBUFFER
this,
179 LPD3DVALUE lpfMaxDistance
)
181 FIXME(dsound
,"stub\n");
185 static HRESULT WINAPI
IDirectSound3DBuffer_GetMinDistance(
186 LPDIRECTSOUND3DBUFFER
this,
187 LPD3DVALUE lpfMinDistance
)
189 FIXME(dsound
,"stub\n");
193 static HRESULT WINAPI
IDirectSound3DBuffer_GetMode(
194 LPDIRECTSOUND3DBUFFER
this,
197 FIXME(dsound
,"stub\n");
201 static HRESULT WINAPI
IDirectSound3DBuffer_GetPosition(
202 LPDIRECTSOUND3DBUFFER
this,
203 LPD3DVECTOR lpvPosition
)
205 FIXME(dsound
,"stub\n");
209 static HRESULT WINAPI
IDirectSound3DBuffer_GetVelocity(
210 LPDIRECTSOUND3DBUFFER
this,
211 LPD3DVECTOR lpvVelocity
)
213 FIXME(dsound
,"stub\n");
217 static HRESULT WINAPI
IDirectSound3DBuffer_SetAllParameters(
218 LPDIRECTSOUND3DBUFFER
this,
219 LPCDS3DBUFFER lpcDs3dBuffer
,
222 FIXME(dsound
,"stub\n");
226 static HRESULT WINAPI
IDirectSound3DBuffer_SetConeAngles(
227 LPDIRECTSOUND3DBUFFER
this,
228 DWORD dwInsideConeAngle
,
229 DWORD dwOutsideConeAngle
,
232 FIXME(dsound
,"stub\n");
236 static HRESULT WINAPI
IDirectSound3DBuffer_SetConeOrientation(
237 LPDIRECTSOUND3DBUFFER
this,
238 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
,
241 FIXME(dsound
,"stub\n");
245 static HRESULT WINAPI
IDirectSound3DBuffer_SetConeOutsideVolume(
246 LPDIRECTSOUND3DBUFFER
this,
247 LONG lConeOutsideVolume
,
250 FIXME(dsound
,"stub\n");
254 static HRESULT WINAPI
IDirectSound3DBuffer_SetMaxDistance(
255 LPDIRECTSOUND3DBUFFER
this,
256 D3DVALUE fMaxDistance
,
259 FIXME(dsound
,"stub\n");
263 static HRESULT WINAPI
IDirectSound3DBuffer_SetMinDistance(
264 LPDIRECTSOUND3DBUFFER
this,
265 D3DVALUE fMinDistance
,
268 FIXME(dsound
,"stub\n");
272 static HRESULT WINAPI
IDirectSound3DBuffer_SetMode(
273 LPDIRECTSOUND3DBUFFER
this,
277 TRACE(dsound
, "mode = %lx\n", dwMode
);
278 this->ds3db
.dwMode
= dwMode
;
282 static HRESULT WINAPI
IDirectSound3DBuffer_SetPosition(
283 LPDIRECTSOUND3DBUFFER
this,
284 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
,
287 FIXME(dsound
,"stub\n");
291 static HRESULT WINAPI
IDirectSound3DBuffer_SetVelocity(
292 LPDIRECTSOUND3DBUFFER
this,
293 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
,
296 FIXME(dsound
,"stub\n");
300 IDirectSound3DBuffer_VTable ds3dbvt
= {
302 IDirectSound3DBuffer_QueryInterface
,
303 IDirectSound3DBuffer_AddRef
,
304 IDirectSound3DBuffer_Release
,
305 // IDirectSound3DBuffer methods
306 IDirectSound3DBuffer_GetAllParameters
,
307 IDirectSound3DBuffer_GetConeAngles
,
308 IDirectSound3DBuffer_GetConeOrientation
,
309 IDirectSound3DBuffer_GetConeOutsideVolume
,
310 IDirectSound3DBuffer_GetMaxDistance
,
311 IDirectSound3DBuffer_GetMinDistance
,
312 IDirectSound3DBuffer_GetMode
,
313 IDirectSound3DBuffer_GetPosition
,
314 IDirectSound3DBuffer_GetVelocity
,
315 IDirectSound3DBuffer_SetAllParameters
,
316 IDirectSound3DBuffer_SetConeAngles
,
317 IDirectSound3DBuffer_SetConeOrientation
,
318 IDirectSound3DBuffer_SetConeOutsideVolume
,
319 IDirectSound3DBuffer_SetMaxDistance
,
320 IDirectSound3DBuffer_SetMinDistance
,
321 IDirectSound3DBuffer_SetMode
,
322 IDirectSound3DBuffer_SetPosition
,
323 IDirectSound3DBuffer_SetVelocity
,
327 static int DSOUND_Create3DBuffer(LPDIRECTSOUNDBUFFER dsb
)
329 DWORD i
, temp
, iSize
, oSize
, offset
;
330 LPBYTE bIbuf
, bObuf
, bTbuf
= NULL
;
331 LPWORD wIbuf
, wObuf
, wTbuf
= NULL
;
333 // Inside DirectX says it's stupid but allowed
334 if (dsb
->wfx
.nChannels
== 2) {
336 if (dsb
->wfx
.wBitsPerSample
== 16) {
337 iSize
= dsb
->buflen
/ 4;
338 wTbuf
= malloc(dsb
->buflen
/ 2);
340 return DSERR_OUTOFMEMORY
;
341 for (i
= 0; i
< iSize
; i
++)
342 wTbuf
[i
] = (dsb
->buffer
[i
] + dsb
->buffer
[(i
* 2) + 1]) / 2;
345 iSize
= dsb
->buflen
/ 2;
346 bTbuf
= malloc(dsb
->buflen
/ 2);
348 return DSERR_OUTOFMEMORY
;
349 for (i
= 0; i
< iSize
; i
++)
350 bTbuf
[i
] = (dsb
->buffer
[i
] + dsb
->buffer
[(i
* 2) + 1]) / 2;
354 if (dsb
->wfx
.wBitsPerSample
== 16) {
355 iSize
= dsb
->buflen
/ 2;
356 wIbuf
= (LPWORD
) dsb
->buffer
;
358 bIbuf
= (LPBYTE
) dsb
->buffer
;
363 if (primarybuf
->wfx
.wBitsPerSample
== 16) {
364 wObuf
= (LPWORD
) dsb
->ds3db
->buffer
;
365 oSize
= dsb
->ds3db
->buflen
/ 2;
367 bObuf
= (LPBYTE
) dsb
->ds3db
->buffer
;
368 oSize
= dsb
->ds3db
->buflen
;
371 offset
= primarybuf
->wfx
.nSamplesPerSec
/ 100; // 10ms
372 if (primarybuf
->wfx
.wBitsPerSample
== 16 && dsb
->wfx
.wBitsPerSample
== 16)
373 for (i
= 0; i
< iSize
; i
++) {
376 temp
+= wIbuf
[i
- offset
] >> 9;
378 temp
+= wIbuf
[i
+ iSize
- offset
] >> 9;
380 wObuf
[(i
* 2) + 1] = temp
;
382 else if (primarybuf
->wfx
.wBitsPerSample
== 8 && dsb
->wfx
.wBitsPerSample
== 8)
383 for (i
= 0; i
< iSize
; i
++) {
386 temp
+= bIbuf
[i
- offset
] >> 5;
388 temp
+= bIbuf
[i
+ iSize
- offset
] >> 5;
390 bObuf
[(i
* 2) + 1] = temp
;
401 /*******************************************************************************
402 * IDirectSound3DListener
406 static HRESULT WINAPI
IDirectSound3DListener_QueryInterface(
407 LPDIRECTSOUND3DLISTENER
this, REFIID riid
, LPVOID
*ppobj
)
411 WINE_StringFromCLSID(riid
,xbuf
);
412 TRACE(dsound
,"(%p,%s,%p)\n",this,xbuf
,ppobj
);
416 static ULONG WINAPI
IDirectSound3DListener_AddRef(LPDIRECTSOUND3DLISTENER
this)
422 static ULONG WINAPI
IDirectSound3DListener_Release(LPDIRECTSOUND3DLISTENER
this)
428 // IDirectSound3DListener methods
429 static HRESULT WINAPI
IDirectSound3DListener_GetAllParameter(
430 LPDIRECTSOUND3DLISTENER
this,
431 LPDS3DLISTENER lpDS3DL
)
433 FIXME(dsound
,"stub\n");
437 static HRESULT WINAPI
IDirectSound3DListener_GetDistanceFactor(
438 LPDIRECTSOUND3DLISTENER
this,
439 LPD3DVALUE lpfDistanceFactor
)
441 FIXME(dsound
,"stub\n");
445 static HRESULT WINAPI
IDirectSound3DListener_GetDopplerFactor(
446 LPDIRECTSOUND3DLISTENER
this,
447 LPD3DVALUE lpfDopplerFactor
)
449 FIXME(dsound
,"stub\n");
453 static HRESULT WINAPI
IDirectSound3DListener_GetOrientation(
454 LPDIRECTSOUND3DLISTENER
this,
455 LPD3DVECTOR lpvOrientFront
,
456 LPD3DVECTOR lpvOrientTop
)
458 FIXME(dsound
,"stub\n");
462 static HRESULT WINAPI
IDirectSound3DListener_GetPosition(
463 LPDIRECTSOUND3DLISTENER
this,
464 LPD3DVECTOR lpvPosition
)
466 FIXME(dsound
,"stub\n");
470 static HRESULT WINAPI
IDirectSound3DListener_GetRolloffFactor(
471 LPDIRECTSOUND3DLISTENER
this,
472 LPD3DVALUE lpfRolloffFactor
)
474 FIXME(dsound
,"stub\n");
478 static HRESULT WINAPI
IDirectSound3DListener_GetVelocity(
479 LPDIRECTSOUND3DLISTENER
this,
480 LPD3DVECTOR lpvVelocity
)
482 FIXME(dsound
,"stub\n");
486 static HRESULT WINAPI
IDirectSound3DListener_SetAllParameters(
487 LPDIRECTSOUND3DLISTENER
this,
488 LPCDS3DLISTENER lpcDS3DL
,
491 FIXME(dsound
,"stub\n");
495 static HRESULT WINAPI
IDirectSound3DListener_SetDistanceFactor(
496 LPDIRECTSOUND3DLISTENER
this,
497 D3DVALUE fDistanceFactor
,
500 FIXME(dsound
,"stub\n");
504 static HRESULT WINAPI
IDirectSound3DListener_SetDopplerFactor(
505 LPDIRECTSOUND3DLISTENER
this,
506 D3DVALUE fDopplerFactor
,
509 FIXME(dsound
,"stub\n");
513 static HRESULT WINAPI
IDirectSound3DListener_SetOrientation(
514 LPDIRECTSOUND3DLISTENER
this,
515 D3DVALUE xFront
, D3DVALUE yFront
, D3DVALUE zFront
,
516 D3DVALUE xTop
, D3DVALUE yTop
, D3DVALUE zTop
,
519 FIXME(dsound
,"stub\n");
523 static HRESULT WINAPI
IDirectSound3DListener_SetPosition(
524 LPDIRECTSOUND3DLISTENER
this,
525 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
,
528 FIXME(dsound
,"stub\n");
532 static HRESULT WINAPI
IDirectSound3DListener_SetRolloffFactor(
533 LPDIRECTSOUND3DLISTENER
this,
534 D3DVALUE fRolloffFactor
,
537 FIXME(dsound
,"stub\n");
541 static HRESULT WINAPI
IDirectSound3DListener_SetVelocity(
542 LPDIRECTSOUND3DLISTENER
this,
543 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
,
546 FIXME(dsound
,"stub\n");
550 static HRESULT WINAPI
IDirectSound3DListener_CommitDeferredSettings(
551 LPDIRECTSOUND3DLISTENER
this)
554 FIXME(dsound
,"stub\n");
558 IDirectSound3DListener_VTable ds3dlvt
= {
560 IDirectSound3DListener_QueryInterface
,
561 IDirectSound3DListener_AddRef
,
562 IDirectSound3DListener_Release
,
563 // IDirectSound3DListener methods
564 IDirectSound3DListener_GetAllParameter
,
565 IDirectSound3DListener_GetDistanceFactor
,
566 IDirectSound3DListener_GetDopplerFactor
,
567 IDirectSound3DListener_GetOrientation
,
568 IDirectSound3DListener_GetPosition
,
569 IDirectSound3DListener_GetRolloffFactor
,
570 IDirectSound3DListener_GetVelocity
,
571 IDirectSound3DListener_SetAllParameters
,
572 IDirectSound3DListener_SetDistanceFactor
,
573 IDirectSound3DListener_SetDopplerFactor
,
574 IDirectSound3DListener_SetOrientation
,
575 IDirectSound3DListener_SetPosition
,
576 IDirectSound3DListener_SetRolloffFactor
,
577 IDirectSound3DListener_SetVelocity
,
578 IDirectSound3DListener_CommitDeferredSettings
,
581 /*******************************************************************************
584 static HRESULT WINAPI
IDirectSoundNotify_QueryInterface(
585 LPDIRECTSOUNDNOTIFY
this,REFIID riid
,LPVOID
*ppobj
589 WINE_StringFromCLSID(riid
,xbuf
);
590 TRACE(dsound
,"(%p,%s,%p)\n",this,xbuf
,ppobj
);
594 static ULONG WINAPI
IDirectSoundNotify_AddRef(LPDIRECTSOUNDNOTIFY
this) {
595 return ++(this->ref
);
598 static ULONG WINAPI
IDirectSoundNotify_Release(LPDIRECTSOUNDNOTIFY
this) {
601 this->dsb
->lpvtbl
->fnRelease(this->dsb
);
602 HeapFree(GetProcessHeap(),0,this);
608 static HRESULT WINAPI
IDirectSoundNotify_SetNotificationPositions(
609 LPDIRECTSOUNDNOTIFY
this,DWORD howmuch
,LPCDSBPOSITIONNOTIFY notify
613 if (TRACE_ON(dsound
)) {
614 TRACE(dsound
,"(%p,0x%08lx,%p)\n",this,howmuch
,notify
);
615 for (i
=0;i
<howmuch
;i
++)
616 TRACE(dsound
,"notify at %ld to 0x%08lx\n",
617 notify
[i
].dwOffset
,(DWORD
)notify
[i
].hEventNotify
);
619 this->dsb
->notifies
= HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,this->dsb
->notifies
,(this->dsb
->nrofnotifies
+howmuch
)*sizeof(DSBPOSITIONNOTIFY
));
620 memcpy( this->dsb
->notifies
+this->dsb
->nrofnotifies
,
622 howmuch
*sizeof(DSBPOSITIONNOTIFY
)
624 this->dsb
->nrofnotifies
+=howmuch
;
629 IDirectSoundNotify_VTable dsnvt
= {
630 IDirectSoundNotify_QueryInterface
,
631 IDirectSoundNotify_AddRef
,
632 IDirectSoundNotify_Release
,
633 IDirectSoundNotify_SetNotificationPositions
,
636 /*******************************************************************************
640 // This sets this format for the <em>Primary Buffer Only</em>
641 // See file:///cdrom/sdk52/docs/worddoc/dsound.doc page 120
642 static HRESULT WINAPI
IDirectSoundBuffer_SetFormat(
643 LPDIRECTSOUNDBUFFER
this,LPWAVEFORMATEX wfex
645 LPDIRECTSOUNDBUFFER
*dsb
;
649 EnterCriticalSection(&(primarybuf
->lock
));
651 if (primarybuf
->wfx
.nSamplesPerSec
!= wfex
->nSamplesPerSec
) {
652 dsb
= dsound
->buffers
;
653 for (i
= 0; i
< dsound
->nrofbuffers
; i
++, dsb
++) {
655 EnterCriticalSection(&((*dsb
)->lock
));
657 (*dsb
)->freqAdjust
= ((*dsb
)->freq
<< DSOUND_FREQSHIFT
) /
658 wfex
->nSamplesPerSec
;
660 LeaveCriticalSection(&((*dsb
)->lock
));
665 memcpy(&(primarybuf
->wfx
), wfex
, sizeof(primarybuf
->wfx
));
667 TRACE(dsound
,"(formattag=0x%04x,chans=%d,samplerate=%ld"
668 "bytespersec=%ld,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
669 wfex
->wFormatTag
, wfex
->nChannels
, wfex
->nSamplesPerSec
,
670 wfex
->nAvgBytesPerSec
, wfex
->nBlockAlign
,
671 wfex
->wBitsPerSample
, wfex
->cbSize
);
673 primarybuf
->wfx
.nAvgBytesPerSec
=
674 this->wfx
.nSamplesPerSec
* this->wfx
.nBlockAlign
;
678 LeaveCriticalSection(&(primarybuf
->lock
));
684 static HRESULT WINAPI
IDirectSoundBuffer_SetVolume(
685 LPDIRECTSOUNDBUFFER
this,LONG vol
689 TRACE(dsound
,"(%p,%ld)\n",this,vol
);
691 // I'm not sure if we need this for primary buffer
692 if (!(this->dsbd
.dwFlags
& DSBCAPS_CTRLVOLUME
))
693 return DSERR_CONTROLUNAVAIL
;
695 if ((vol
> DSBVOLUME_MAX
) || (vol
< DSBVOLUME_MIN
))
696 return DSERR_INVALIDPARAM
;
698 // This needs to adjust the soundcard volume when
699 // called for the primary buffer
700 if (this->dsbd
.dwFlags
& DSBCAPS_PRIMARYBUFFER
) {
701 FIXME(dsound
, "Volume control of primary unimplemented.\n");
707 EnterCriticalSection(&(this->lock
));
711 temp
= (double) (this->volume
- (this->pan
> 0 ? this->pan
: 0));
712 this->lVolAdjust
= (ULONG
) (pow(2.0, temp
/ 600.0) * 32768.0);
713 temp
= (double) (this->volume
+ (this->pan
< 0 ? this->pan
: 0));
714 this->rVolAdjust
= (ULONG
) (pow(2.0, temp
/ 600.0) * 32768.0);
716 LeaveCriticalSection(&(this->lock
));
719 TRACE(dsound
, "left = %lx, right = %lx\n", this->lVolAdjust
, this->rVolAdjust
);
724 static HRESULT WINAPI
IDirectSoundBuffer_GetVolume(
725 LPDIRECTSOUNDBUFFER
this,LPLONG vol
727 TRACE(dsound
,"(%p,%p)\n",this,vol
);
732 static HRESULT WINAPI
IDirectSoundBuffer_SetFrequency(
733 LPDIRECTSOUNDBUFFER
this,DWORD freq
735 TRACE(dsound
,"(%p,%ld)\n",this,freq
);
737 // You cannot set the frequency of the primary buffer
738 if (!(this->dsbd
.dwFlags
& DSBCAPS_CTRLFREQUENCY
) ||
739 (this->dsbd
.dwFlags
& DSBCAPS_PRIMARYBUFFER
))
740 return DSERR_CONTROLUNAVAIL
;
742 if ((freq
< DSBFREQUENCY_MIN
) || (freq
> DSBFREQUENCY_MAX
))
743 return DSERR_INVALIDPARAM
;
746 EnterCriticalSection(&(this->lock
));
749 this->freqAdjust
= (freq
<< DSOUND_FREQSHIFT
) / primarybuf
->wfx
.nSamplesPerSec
;
750 this->nAvgBytesPerSec
= freq
* this->wfx
.nBlockAlign
;
752 LeaveCriticalSection(&(this->lock
));
758 static HRESULT WINAPI
IDirectSoundBuffer_Play(
759 LPDIRECTSOUNDBUFFER
this,DWORD reserved1
,DWORD reserved2
,DWORD flags
761 TRACE(dsound
,"(%p,%08lx,%08lx,%08lx)\n",
762 this,reserved1
,reserved2
,flags
764 this->playflags
= flags
;
769 static HRESULT WINAPI
IDirectSoundBuffer_Stop(LPDIRECTSOUNDBUFFER
this)
771 TRACE(dsound
,"(%p)\n",this);
774 EnterCriticalSection(&(this->lock
));
777 DSOUND_CheckEvent(this, 0);
779 LeaveCriticalSection(&(this->lock
));
785 static DWORD WINAPI
IDirectSoundBuffer_AddRef(LPDIRECTSOUNDBUFFER
this) {
786 // TRACE(dsound,"(%p) ref was %ld\n",this, this->ref);
788 return ++(this->ref
);
790 static DWORD WINAPI
IDirectSoundBuffer_Release(LPDIRECTSOUNDBUFFER
this) {
793 // TRACE(dsound,"(%p) ref was %ld\n",this, this->ref);
798 for (i
=0;i
<this->dsound
->nrofbuffers
;i
++)
799 if (this->dsound
->buffers
[i
] == this)
801 if (i
< this->dsound
->nrofbuffers
) {
802 /* Put the last buffer of the list in the (now empty) position */
803 this->dsound
->buffers
[i
] = this->dsound
->buffers
[this->dsound
->nrofbuffers
- 1];
804 this->dsound
->buffers
= HeapReAlloc(GetProcessHeap(),0,this->dsound
->buffers
,sizeof(LPDIRECTSOUNDBUFFER
)*this->dsound
->nrofbuffers
);
805 this->dsound
->nrofbuffers
--;
806 this->dsound
->lpvtbl
->fnRelease(this->dsound
);
809 DeleteCriticalSection(&(this->lock
));
811 if (this->ds3db
&& this->ds3db
->lpvtbl
)
812 this->ds3db
->lpvtbl
->fnRelease(this->ds3db
);
814 HeapFree(GetProcessHeap(),0,this->buffer
);
815 HeapFree(GetProcessHeap(),0,this);
817 if (this == primarybuf
)
823 static HRESULT WINAPI
IDirectSoundBuffer_GetCurrentPosition(
824 LPDIRECTSOUNDBUFFER
this,LPDWORD playpos
,LPDWORD writepos
826 TRACE(dsound
,"(%p,%p,%p)\n",this,playpos
,writepos
);
827 if (playpos
) *playpos
= this->playpos
;
828 if (writepos
) *writepos
= this->writepos
;
832 static HRESULT WINAPI
IDirectSoundBuffer_GetStatus(
833 LPDIRECTSOUNDBUFFER
this,LPDWORD status
835 TRACE(dsound
,"(%p,%p)\n",this,status
);
838 *status
|= DSBSTATUS_PLAYING
;
839 if (this->playflags
& DSBPLAY_LOOPING
)
840 *status
|= DSBSTATUS_LOOPING
;
845 static HRESULT WINAPI
IDirectSoundBuffer_GetFormat(
846 LPDIRECTSOUNDBUFFER
this,LPWAVEFORMATEX lpwf
,DWORD wfsize
,LPDWORD wfwritten
848 TRACE(dsound
,"(%p,%p,%ld,%p)\n",this,lpwf
,wfsize
,wfwritten
);
849 if (wfsize
>sizeof(this->wfx
))
850 wfsize
= sizeof(this->wfx
);
851 if (lpwf
) { // NULL is valid
852 memcpy(lpwf
,&(this->wfx
),wfsize
);
857 *wfwritten
= sizeof(this->wfx
);
859 return DSERR_INVALIDPARAM
;
864 static HRESULT WINAPI
IDirectSoundBuffer_Lock(
865 LPDIRECTSOUNDBUFFER
this,DWORD writecursor
,DWORD writebytes
,LPVOID lplpaudioptr1
,LPDWORD audiobytes1
,LPVOID lplpaudioptr2
,LPDWORD audiobytes2
,DWORD flags
868 TRACE(dsound
,"(%p,%ld,%ld,%p,%p,%p,%p,0x%08lx)\n",
878 if (flags
& DSBLOCK_FROMWRITECURSOR
)
879 writecursor
+= this->writepos
;
880 if (flags
& DSBLOCK_ENTIREBUFFER
)
881 writebytes
= this->buflen
;
882 if (writebytes
> this->buflen
)
883 writebytes
= this->buflen
;
885 assert(audiobytes1
!=audiobytes2
);
886 assert(lplpaudioptr1
!=lplpaudioptr2
);
887 if (writecursor
+writebytes
<= this->buflen
) {
888 *(LPBYTE
*)lplpaudioptr1
= this->buffer
+writecursor
;
889 *audiobytes1
= writebytes
;
891 *(LPBYTE
*)lplpaudioptr2
= NULL
;
894 TRACE(dsound
,"->%ld.0\n",writebytes
);
896 *(LPBYTE
*)lplpaudioptr1
= this->buffer
+writecursor
;
897 *audiobytes1
= this->buflen
-writecursor
;
899 *(LPBYTE
*)lplpaudioptr2
= this->buffer
;
901 *audiobytes2
= writebytes
-(this->buflen
-writecursor
);
902 TRACE(dsound
,"->%ld.%ld\n",*audiobytes1
,audiobytes2
?*audiobytes2
:0);
904 // No. See file:///cdrom/sdk52/docs/worddoc/dsound.doc page 21
905 // this->writepos=(writecursor+writebytes)%this->buflen;
909 static HRESULT WINAPI
IDirectSoundBuffer_SetCurrentPosition(
910 LPDIRECTSOUNDBUFFER
this,DWORD newpos
912 TRACE(dsound
,"(%p,%ld)\n",this,newpos
);
915 EnterCriticalSection(&(this->lock
));
917 this->playpos
= newpos
;
919 LeaveCriticalSection(&(this->lock
));
925 static HRESULT WINAPI
IDirectSoundBuffer_SetPan(
926 LPDIRECTSOUNDBUFFER
this,LONG pan
930 TRACE(dsound
,"(%p,%ld)\n",this,pan
);
932 if (!(this) || (pan
> DSBPAN_RIGHT
) || (pan
< DSBPAN_LEFT
))
933 return DSERR_INVALIDPARAM
;
935 // You cannot set the pan of the primary buffer
936 // and you cannot use both pan and 3D controls
937 if (!(this->dsbd
.dwFlags
& DSBCAPS_CTRLPAN
) ||
938 (this->dsbd
.dwFlags
& DSBCAPS_CTRL3D
) ||
939 (this->dsbd
.dwFlags
& DSBCAPS_PRIMARYBUFFER
))
940 return DSERR_CONTROLUNAVAIL
;
943 EnterCriticalSection(&(this->lock
));
947 temp
= (double) (this->volume
- (this->pan
> 0 ? this->pan
: 0));
948 this->lVolAdjust
= (ULONG
) (pow(2.0, temp
/ 600.0) * 32768.0);
949 temp
= (double) (this->volume
+ (this->pan
< 0 ? this->pan
: 0));
950 this->rVolAdjust
= (ULONG
) (pow(2.0, temp
/ 600.0) * 32768.0);
952 LeaveCriticalSection(&(this->lock
));
958 static HRESULT WINAPI
IDirectSoundBuffer_GetPan(
959 LPDIRECTSOUNDBUFFER
this,LPLONG pan
961 TRACE(dsound
,"(%p,%p)\n",this,pan
);
966 static HRESULT WINAPI
IDirectSoundBuffer_Unlock(
967 LPDIRECTSOUNDBUFFER
this,LPVOID p1
,DWORD x1
,LPVOID p2
,DWORD x2
969 TRACE(dsound
,"(%p,%p,%ld,%p,%ld):stub\n", this,p1
,x1
,p2
,x2
);
971 // This is highly experimental and liable to break things
972 if (this->dsbd
.dwFlags
& DSBCAPS_CTRL3D
)
973 DSOUND_Create3DBuffer(this);
978 static HRESULT WINAPI
IDirectSoundBuffer_GetFrequency(
979 LPDIRECTSOUNDBUFFER
this,LPDWORD freq
981 TRACE(dsound
,"(%p,%p)\n",this,freq
);
986 static HRESULT WINAPI
IDirectSoundBuffer_Initialize(
987 LPDIRECTSOUNDBUFFER
this,LPDIRECTSOUND dsound
,LPDSBUFFERDESC dbsd
989 FIXME(dsound
,"(%p,%p,%p):stub\n",this,dsound
,dbsd
);
990 printf("Re-Init!!!\n");
991 return DSERR_ALREADYINITIALIZED
;
994 static HRESULT WINAPI
IDirectSoundBuffer_GetCaps(
995 LPDIRECTSOUNDBUFFER
this,LPDSBCAPS caps
997 TRACE(dsound
,"(%p)->(%p)\n",this,caps
);
999 caps
->dwSize
= sizeof(*caps
);
1000 caps
->dwFlags
= this->dsbd
.dwFlags
| DSBCAPS_LOCSOFTWARE
;
1001 caps
->dwBufferBytes
= this->dsbd
.dwBufferBytes
;
1002 /* This value represents the speed of the "unlock" command.
1003 As unlock is quite fast (it does not do anything), I put
1004 4096 ko/s = 4 Mo / s */
1005 caps
->dwUnlockTransferRate
= 4096;
1006 caps
->dwPlayCpuOverhead
= 0;
1011 static HRESULT WINAPI
IDirectSoundBuffer_QueryInterface(
1012 LPDIRECTSOUNDBUFFER
this,REFIID riid
,LPVOID
*ppobj
1016 WINE_StringFromCLSID(riid
,xbuf
);
1017 TRACE(dsound
,"(%p,%s,%p)\n",this,xbuf
,ppobj
);
1019 if (!memcmp(&IID_IDirectSoundNotify
,riid
,sizeof(*riid
))) {
1020 IDirectSoundNotify
*dsn
;
1022 dsn
= (LPDIRECTSOUNDNOTIFY
)HeapAlloc(GetProcessHeap(),0,sizeof(*dsn
));
1025 this->lpvtbl
->fnAddRef(this);
1026 dsn
->lpvtbl
= &dsnvt
;
1027 *ppobj
= (LPVOID
)dsn
;
1031 if (!memcmp(&IID_IDirectSound3DBuffer
,riid
,sizeof(*riid
))) {
1032 *ppobj
= this->ds3db
;
1040 static struct tagLPDIRECTSOUNDBUFFER_VTABLE dsbvt
= {
1041 IDirectSoundBuffer_QueryInterface
,
1042 IDirectSoundBuffer_AddRef
,
1043 IDirectSoundBuffer_Release
,
1044 IDirectSoundBuffer_GetCaps
,
1045 IDirectSoundBuffer_GetCurrentPosition
,
1046 IDirectSoundBuffer_GetFormat
,
1047 IDirectSoundBuffer_GetVolume
,
1048 IDirectSoundBuffer_GetPan
,
1049 IDirectSoundBuffer_GetFrequency
,
1050 IDirectSoundBuffer_GetStatus
,
1051 IDirectSoundBuffer_Initialize
,
1052 IDirectSoundBuffer_Lock
,
1053 IDirectSoundBuffer_Play
,
1054 IDirectSoundBuffer_SetCurrentPosition
,
1055 IDirectSoundBuffer_SetFormat
,
1056 IDirectSoundBuffer_SetVolume
,
1057 IDirectSoundBuffer_SetPan
,
1058 IDirectSoundBuffer_SetFrequency
,
1059 IDirectSoundBuffer_Stop
,
1060 IDirectSoundBuffer_Unlock
1063 /*******************************************************************************
1067 static HRESULT WINAPI
IDirectSound_SetCooperativeLevel(
1068 LPDIRECTSOUND
this,HWND32 hwnd
,DWORD level
1070 FIXME(dsound
,"(%p,%08lx,%ld):stub\n",this,(DWORD
)hwnd
,level
);
1075 static HRESULT WINAPI
IDirectSound_CreateSoundBuffer(
1076 LPDIRECTSOUND
this,LPDSBUFFERDESC dsbd
,LPLPDIRECTSOUNDBUFFER ppdsb
,LPUNKNOWN lpunk
1078 LPWAVEFORMATEX wfex
;
1080 TRACE(dsound
,"(%p,%p,%p,%p)\n",this,dsbd
,ppdsb
,lpunk
);
1082 if ((this == NULL
) || (dsbd
== NULL
) || (ppdsb
== NULL
))
1083 return DSERR_INVALIDPARAM
;
1085 if (TRACE_ON(dsound
)) {
1086 TRACE(dsound
,"(size=%ld)\n",dsbd
->dwSize
);
1087 TRACE(dsound
,"(flags=0x%08lx\n",dsbd
->dwFlags
);
1088 _dump_DSBCAPS(dsbd
->dwFlags
);
1089 TRACE(dsound
,"(bufferbytes=%ld)\n",dsbd
->dwBufferBytes
);
1090 TRACE(dsound
,"(lpwfxFormat=%p)\n",dsbd
->lpwfxFormat
);
1093 wfex
= dsbd
->lpwfxFormat
;
1096 TRACE(dsound
,"(formattag=0x%04x,chans=%d,samplerate=%ld"
1097 "bytespersec=%ld,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
1098 wfex
->wFormatTag
, wfex
->nChannels
, wfex
->nSamplesPerSec
,
1099 wfex
->nAvgBytesPerSec
, wfex
->nBlockAlign
,
1100 wfex
->wBitsPerSample
, wfex
->cbSize
);
1102 if (dsbd
->dwFlags
& DSBCAPS_PRIMARYBUFFER
) {
1104 primarybuf
->lpvtbl
->fnAddRef(primarybuf
);
1105 *ppdsb
= primarybuf
;
1107 } // Else create primarybuf
1110 *ppdsb
= (LPDIRECTSOUNDBUFFER
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirectSoundBuffer
));
1112 return DSERR_OUTOFMEMORY
;
1115 TRACE(dsound
, "Created buffer at %p\n", *ppdsb
);
1117 if (dsbd
->dwFlags
& DSBCAPS_PRIMARYBUFFER
) {
1118 (*ppdsb
)->buflen
= dsound
->wfx
.nAvgBytesPerSec
;
1119 (*ppdsb
)->freq
= dsound
->wfx
.nSamplesPerSec
;
1121 (*ppdsb
)->buflen
= dsbd
->dwBufferBytes
;
1122 (*ppdsb
)->freq
= dsbd
->lpwfxFormat
->nSamplesPerSec
;
1124 (*ppdsb
)->buffer
= (LPBYTE
)HeapAlloc(GetProcessHeap(),0,(*ppdsb
)->buflen
);
1125 if ((*ppdsb
)->buffer
== NULL
) {
1126 HeapFree(GetProcessHeap(),0,(*ppdsb
));
1128 return DSERR_OUTOFMEMORY
;
1130 (*ppdsb
)->playpos
= 0;
1131 (*ppdsb
)->writepos
= 0;
1132 (*ppdsb
)->lpvtbl
= &dsbvt
;
1133 (*ppdsb
)->dsound
= this;
1134 (*ppdsb
)->playing
= 0;
1135 (*ppdsb
)->lVolAdjust
= (1 << 15);
1136 (*ppdsb
)->rVolAdjust
= (1 << 15);
1138 if (!(dsbd
->dwFlags
& DSBCAPS_PRIMARYBUFFER
)) {
1139 (*ppdsb
)->freqAdjust
= ((*ppdsb
)->freq
<< DSOUND_FREQSHIFT
) /
1140 primarybuf
->wfx
.nSamplesPerSec
;
1141 (*ppdsb
)->nAvgBytesPerSec
= (*ppdsb
)->freq
*
1142 dsbd
->lpwfxFormat
->nBlockAlign
;
1145 memcpy(&((*ppdsb
)->dsbd
),dsbd
,sizeof(*dsbd
));
1147 /* register buffer */
1148 if (!(dsbd
->dwFlags
& DSBCAPS_PRIMARYBUFFER
)) {
1149 this->buffers
= (LPDIRECTSOUNDBUFFER
*)HeapReAlloc(GetProcessHeap(),0,this->buffers
,sizeof(LPDIRECTSOUNDBUFFER
)*(this->nrofbuffers
+1));
1150 this->buffers
[this->nrofbuffers
] = *ppdsb
;
1151 this->nrofbuffers
++;
1152 this->lpvtbl
->fnAddRef(this);
1155 if (dsbd
->lpwfxFormat
)
1156 memcpy(&((*ppdsb
)->wfx
), dsbd
->lpwfxFormat
, sizeof((*ppdsb
)->wfx
));
1158 InitializeCriticalSection(&((*ppdsb
)->lock
));
1161 if (dsbd
->dwFlags
& DSBCAPS_CTRL3D
) {
1162 IDirectSound3DBuffer
*ds3db
;
1164 ds3db
= (LPDIRECTSOUND3DBUFFER
)HeapAlloc(GetProcessHeap(),
1167 ds3db
->dsb
= (*ppdsb
);
1168 ds3db
->lpvtbl
= &ds3dbvt
;
1169 (*ppdsb
)->ds3db
= ds3db
;
1170 ds3db
->ds3db
.dwSize
= sizeof(DS3DBUFFER
);
1171 ds3db
->ds3db
.vPosition
.x
= 0.0;
1172 ds3db
->ds3db
.vPosition
.y
= 0.0;
1173 ds3db
->ds3db
.vPosition
.z
= 0.0;
1174 ds3db
->ds3db
.vVelocity
.x
= 0.0;
1175 ds3db
->ds3db
.vVelocity
.y
= 0.0;
1176 ds3db
->ds3db
.vVelocity
.z
= 0.0;
1177 ds3db
->ds3db
.dwInsideConeAngle
= DS3D_DEFAULTCONEANGLE
;
1178 ds3db
->ds3db
.dwOutsideConeAngle
= DS3D_DEFAULTCONEANGLE
;
1179 ds3db
->ds3db
.vConeOrientation
.x
= 0.0;
1180 ds3db
->ds3db
.vConeOrientation
.y
= 0.0;
1181 ds3db
->ds3db
.vConeOrientation
.z
= 0.0;
1182 ds3db
->ds3db
.lConeOutsideVolume
= DS3D_DEFAULTCONEOUTSIDEVOLUME
;
1183 ds3db
->ds3db
.flMinDistance
= DS3D_DEFAULTMINDISTANCE
;
1184 ds3db
->ds3db
.flMaxDistance
= DS3D_DEFAULTMAXDISTANCE
;
1185 ds3db
->ds3db
.dwMode
= DS3DMODE_NORMAL
;
1186 ds3db
->buflen
= ((*ppdsb
)->buflen
* primarybuf
->wfx
.nBlockAlign
) /
1187 (*ppdsb
)->wfx
.nBlockAlign
;
1188 ds3db
->buffer
= HeapAlloc(GetProcessHeap(), 0, ds3db
->buflen
);
1189 if (ds3db
->buffer
== NULL
) {
1191 ds3db
->ds3db
.dwMode
= DS3DMODE_DISABLE
;
1198 static HRESULT WINAPI
IDirectSound_DuplicateSoundBuffer(
1199 LPDIRECTSOUND
this,LPDIRECTSOUNDBUFFER pdsb
,LPLPDIRECTSOUNDBUFFER ppdsb
1201 TRACE(dsound
,"(%p,%p,%p)\n",this,pdsb
,ppdsb
);
1203 *ppdsb
= (LPDIRECTSOUNDBUFFER
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirectSoundBuffer
));
1206 (*ppdsb
)->buffer
= (LPBYTE
)HeapAlloc(GetProcessHeap(),0,pdsb
->buflen
);
1207 memcpy((*ppdsb
)->buffer
,pdsb
->buffer
,pdsb
->buflen
);
1208 (*ppdsb
)->buflen
= pdsb
->buflen
;
1209 (*ppdsb
)->playpos
= 0;
1210 (*ppdsb
)->writepos
= 0;
1211 (*ppdsb
)->lpvtbl
= &dsbvt
;
1212 (*ppdsb
)->dsound
= this;
1213 memcpy(&((*ppdsb
)->wfx
), &(pdsb
->wfx
), sizeof((*ppdsb
)->wfx
));
1214 /* register buffer */
1215 this->buffers
= (LPDIRECTSOUNDBUFFER
*)HeapReAlloc(GetProcessHeap(),0,this->buffers
,sizeof(LPDIRECTSOUNDBUFFER
)*(this->nrofbuffers
+1));
1216 this->buffers
[this->nrofbuffers
] = *ppdsb
;
1217 this->nrofbuffers
++;
1218 this->lpvtbl
->fnAddRef(this);
1223 static HRESULT WINAPI
IDirectSound_GetCaps(LPDIRECTSOUND
this,LPDSCAPS caps
) {
1224 TRACE(dsound
,"(%p,%p)\n",this,caps
);
1225 TRACE(dsound
,"(flags=0x%08lx)\n",caps
->dwFlags
);
1227 caps
->dwSize
= sizeof(*caps
);
1229 DSCAPS_PRIMARYSTEREO
|
1230 DSCAPS_PRIMARY16BIT
|
1231 DSCAPS_SECONDARYSTEREO
|
1232 DSCAPS_SECONDARY16BIT
|
1233 DSCAPS_CONTINUOUSRATE
;
1234 /* FIXME: query OSS */
1235 caps
->dwMinSecondarySampleRate
= DSBFREQUENCY_MIN
;
1236 caps
->dwMaxSecondarySampleRate
= DSBFREQUENCY_MAX
;
1238 caps
->dwPrimaryBuffers
= 1;
1240 caps
->dwMaxHwMixingAllBuffers
= 0;
1241 caps
->dwMaxHwMixingStaticBuffers
= 0;
1242 caps
->dwMaxHwMixingStreamingBuffers
= 0;
1244 caps
->dwFreeHwMixingAllBuffers
= 0;
1245 caps
->dwFreeHwMixingStaticBuffers
= 0;
1246 caps
->dwFreeHwMixingStreamingBuffers
= 0;
1248 caps
->dwMaxHw3DAllBuffers
= 0;
1249 caps
->dwMaxHw3DStaticBuffers
= 0;
1250 caps
->dwMaxHw3DStreamingBuffers
= 0;
1252 caps
->dwFreeHw3DAllBuffers
= 0;
1253 caps
->dwFreeHw3DStaticBuffers
= 0;
1254 caps
->dwFreeHw3DStreamingBuffers
= 0;
1256 caps
->dwTotalHwMemBytes
= 0;
1258 caps
->dwFreeHwMemBytes
= 0;
1260 caps
->dwMaxContigFreeHwMemBytes
= 0;
1262 caps
->dwUnlockTransferRateHwBuffers
= 4096; // But we have none...
1264 caps
->dwPlayCpuOverheadSwBuffers
= 1; // 1%
1269 static ULONG WINAPI
IDirectSound_AddRef(LPDIRECTSOUND
this) {
1270 return ++(this->ref
);
1273 static ULONG WINAPI
IDirectSound_Release(LPDIRECTSOUND
this) {
1274 TRACE(dsound
,"(%p), ref was %ld\n",this,this->ref
);
1275 if (!--(this->ref
)) {
1276 DSOUND_CloseAudio();
1277 while(IDirectSoundBuffer_Release(primarybuf
)); // Deallocate
1278 FIXME(dsound
, "need to release all buffers!\n");
1279 HeapFree(GetProcessHeap(),0,this);
1286 static HRESULT WINAPI
IDirectSound_SetSpeakerConfig(
1287 LPDIRECTSOUND
this,DWORD config
1289 FIXME(dsound
,"(%p,0x%08lx):stub\n",this,config
);
1293 static HRESULT WINAPI
IDirectSound_QueryInterface(
1294 LPDIRECTSOUND
this,REFIID riid
,LPVOID
*ppobj
1298 if (!memcmp(&IID_IDirectSound3DListener
,riid
,sizeof(*riid
))) {
1300 if (this->listener
) {
1301 *ppobj
= this->listener
;
1304 this->listener
= (LPDIRECTSOUND3DLISTENER
)HeapAlloc(
1305 GetProcessHeap(), 0, sizeof(*(this->listener
)));
1306 this->listener
->ref
= 1;
1307 this->listener
->lpvtbl
= &ds3dlvt
;
1308 this->lpvtbl
->fnAddRef(this);
1309 this->listener
->ds3dl
.dwSize
= sizeof(DS3DLISTENER
);
1310 this->listener
->ds3dl
.vPosition
.x
= 0.0;
1311 this->listener
->ds3dl
.vPosition
.y
= 0.0;
1312 this->listener
->ds3dl
.vPosition
.z
= 0.0;
1313 this->listener
->ds3dl
.vVelocity
.x
= 0.0;
1314 this->listener
->ds3dl
.vVelocity
.y
= 0.0;
1315 this->listener
->ds3dl
.vVelocity
.z
= 0.0;
1316 this->listener
->ds3dl
.vOrientFront
.x
= 0.0;
1317 this->listener
->ds3dl
.vOrientFront
.y
= 0.0;
1318 this->listener
->ds3dl
.vOrientFront
.z
= 1.0;
1319 this->listener
->ds3dl
.vOrientTop
.x
= 0.0;
1320 this->listener
->ds3dl
.vOrientTop
.y
= 1.0;
1321 this->listener
->ds3dl
.vOrientTop
.z
= 0.0;
1322 this->listener
->ds3dl
.flDistanceFactor
= DS3D_DEFAULTDISTANCEFACTOR
;
1323 this->listener
->ds3dl
.flRolloffFactor
= DS3D_DEFAULTROLLOFFFACTOR
;
1324 this->listener
->ds3dl
.flDopplerFactor
= DS3D_DEFAULTDOPPLERFACTOR
;
1325 *ppobj
= (LPVOID
)this->listener
;
1329 WINE_StringFromCLSID(riid
,xbuf
);
1330 TRACE(dsound
,"(%p,%s,%p)\n",this,xbuf
,ppobj
);
1334 static HRESULT WINAPI
IDirectSound_Compact(
1337 TRACE(dsound
, "(%p)\n", this);
1341 static HRESULT WINAPI
IDirectSound_GetSpeakerConfig(
1343 LPDWORD lpdwSpeakerConfig
)
1345 TRACE(dsound
, "(%p, %p)\n", this, lpdwSpeakerConfig
);
1346 *lpdwSpeakerConfig
= DSSPEAKER_STEREO
| DSSPEAKER_GEOMETRY_NARROW
;
1350 static HRESULT WINAPI
IDirectSound_Initialize(
1354 TRACE(dsound
, "(%p, %p)\n", this, lpGuid
);
1358 static struct tagLPDIRECTSOUND_VTABLE dsvt
= {
1359 IDirectSound_QueryInterface
,
1360 IDirectSound_AddRef
,
1361 IDirectSound_Release
,
1362 IDirectSound_CreateSoundBuffer
,
1363 IDirectSound_GetCaps
,
1364 IDirectSound_DuplicateSoundBuffer
,
1365 IDirectSound_SetCooperativeLevel
,
1366 IDirectSound_Compact
,
1367 IDirectSound_GetSpeakerConfig
,
1368 IDirectSound_SetSpeakerConfig
,
1369 IDirectSound_Initialize
1373 DSOUND_setformat(LPWAVEFORMATEX wfex
) {
1374 int xx
,channels
,speed
,format
,nformat
;
1376 // Race condition here... called by DSOUND_thread() and SetFormat()
1378 TRACE(dsound
, "(%p) deferred\n", wfex
);
1381 switch (wfex
->wFormatTag
) {
1383 WARN(dsound
,"unknown WAVE_FORMAT tag %d\n",wfex
->wFormatTag
);
1384 return DSERR_BADFORMAT
;
1385 case WAVE_FORMAT_PCM
:
1388 if (wfex
->wBitsPerSample
==8)
1391 format
= AFMT_S16_LE
;
1393 if (-1==ioctl(audiofd
,SNDCTL_DSP_GETFMTS
,&xx
)) {
1394 perror("ioctl SNDCTL_DSP_GETFMTS");
1397 if ((xx
&format
)!=format
) {/* format unsupported */
1398 FIXME(dsound
,"SNDCTL_DSP_GETFMTS: format not supported\n");
1402 if (-1==ioctl(audiofd
,SNDCTL_DSP_SETFMT
,&nformat
)) {
1403 perror("ioctl SNDCTL_DSP_SETFMT");
1406 if (nformat
!=format
) {/* didn't work */
1407 FIXME(dsound
,"SNDCTL_DSP_GETFMTS: format not set\n");
1411 channels
= wfex
->nChannels
-1;
1412 if (-1==ioctl(audiofd
,SNDCTL_DSP_STEREO
,&channels
)) {
1413 perror("ioctl SNDCTL_DSP_STEREO");
1416 speed
= wfex
->nSamplesPerSec
;
1417 if (-1==ioctl(audiofd
,SNDCTL_DSP_SPEED
,&speed
)) {
1418 perror("ioctl SNDCTL_DSP_SPEED");
1421 TRACE(dsound
,"(freq=%ld,channels=%d,bits=%d)\n",
1422 wfex
->nSamplesPerSec
,wfex
->nChannels
,wfex
->wBitsPerSample
1427 static void DSOUND_CheckEvent(IDirectSoundBuffer
*dsb
, int len
)
1431 LPDSBPOSITIONNOTIFY event
;
1433 if (dsb
->nrofnotifies
== 0)
1436 TRACE(dsound
,"(%p) buflen = %ld, playpos = %ld, len = %d\n",
1437 dsb
, dsb
->buflen
, dsb
->playpos
, len
);
1438 for (i
= 0; i
< dsb
->nrofnotifies
; i
++) {
1439 event
= dsb
->notifies
+ i
;
1440 offset
= event
->dwOffset
;
1441 TRACE(dsound
, "checking %d, position %ld, event = %d\n",
1442 i
, offset
, event
->hEventNotify
);
1443 // DSBPN_OFFSETSTOP has to be the last element. So this is
1444 // OK. [Inside DirectX, p274]
1446 // This also means we can't sort the entries by offset,
1447 // because DSBPN_OFFSETSTOP == -1
1448 if (offset
== DSBPN_OFFSETSTOP
) {
1449 if (dsb
->playing
== 0) {
1450 SetEvent(event
->hEventNotify
);
1451 TRACE(dsound
,"signalled event %d (%d)\n", event
->hEventNotify
, i
);
1456 if ((dsb
->playpos
+ len
) >= dsb
->buflen
) {
1457 if ((offset
< ((dsb
->playpos
+ len
) % dsb
->buflen
)) ||
1458 (offset
>= dsb
->playpos
)) {
1459 TRACE(dsound
,"signalled event %d (%d)\n", event
->hEventNotify
, i
);
1460 SetEvent(event
->hEventNotify
);
1463 if ((offset
>= dsb
->playpos
) && (offset
< (dsb
->playpos
+ len
))) {
1464 TRACE(dsound
,"signalled event %d (%d)\n", event
->hEventNotify
, i
);
1465 SetEvent(event
->hEventNotify
);
1471 // WAV format info can be found at:
1473 // http://www.cwi.nl/ftp/audio/AudioFormats.part2
1474 // ftp://ftp.cwi.nl/pub/audio/RIFF-format
1476 // Import points to remember:
1478 // 8-bit WAV is unsigned
1479 // 16-bit WAV is signed
1481 static inline INT16
cvtU8toS16(BYTE byte
)
1483 INT16 s
= (byte
- 128) << 8;
1488 static inline BYTE
cvtS16toU8(INT16 word
)
1490 BYTE b
= (word
+ 32768) >> 8;
1496 // We should be able to optimize these two inline functions
1497 // so that we aren't doing 8->16->8 conversions when it is
1498 // not necessary. But this is still a WIP. Optimize later.
1499 static inline void get_fields(const IDirectSoundBuffer
*dsb
, BYTE
*buf
, INT32
*fl
, INT32
*fr
)
1501 INT16
*bufs
= (INT16
*) buf
;
1503 // TRACE(dsound, "(%p)", buf);
1504 if ((dsb
->wfx
.wBitsPerSample
== 8) && dsb
->wfx
.nChannels
== 2) {
1505 *fl
= cvtU8toS16(*buf
);
1506 *fr
= cvtU8toS16(*(buf
+ 1));
1510 if ((dsb
->wfx
.wBitsPerSample
== 16) && dsb
->wfx
.nChannels
== 2) {
1516 if ((dsb
->wfx
.wBitsPerSample
== 8) && dsb
->wfx
.nChannels
== 1) {
1517 *fl
= cvtU8toS16(*buf
);
1522 if ((dsb
->wfx
.wBitsPerSample
== 16) && dsb
->wfx
.nChannels
== 1) {
1528 FIXME(dsound
, "get_fields found an unsupported configuration\n");
1532 static inline void set_fields(BYTE
*buf
, INT32 fl
, INT32 fr
)
1534 INT16
*bufs
= (INT16
*) buf
;
1536 if ((primarybuf
->wfx
.wBitsPerSample
== 8) && (primarybuf
->wfx
.nChannels
== 2)) {
1537 *buf
= cvtS16toU8(fl
);
1538 *(buf
+ 1) = cvtS16toU8(fr
);
1542 if ((primarybuf
->wfx
.wBitsPerSample
== 16) && (primarybuf
->wfx
.nChannels
== 2)) {
1548 if ((primarybuf
->wfx
.wBitsPerSample
== 8) && (primarybuf
->wfx
.nChannels
== 1)) {
1549 *buf
= cvtS16toU8((fl
+ fr
) >> 1);
1553 if ((primarybuf
->wfx
.wBitsPerSample
== 16) && (primarybuf
->wfx
.nChannels
== 1)) {
1554 *bufs
= (fl
+ fr
) >> 1;
1557 FIXME(dsound
, "set_fields found an unsupported configuration\n");
1561 // Now with PerfectPitch (tm) technology
1562 static INT32
DSOUND_MixerNorm(IDirectSoundBuffer
*dsb
, BYTE
*buf
, INT32 len
)
1564 INT32 i
, size
, ipos
, ilen
, fieldL
, fieldR
;
1566 INT32 iAdvance
= dsb
->wfx
.nBlockAlign
;
1567 INT32 oAdvance
= primarybuf
->wfx
.nBlockAlign
;
1569 ibp
= dsb
->buffer
+ dsb
->playpos
;
1572 TRACE(dsound
, "(%p, %p, %p), playpos=%8.8lx\n", dsb
, ibp
, obp
, dsb
->playpos
);
1573 // Check for the best case
1574 if ((dsb
->freq
== primarybuf
->wfx
.nSamplesPerSec
) &&
1575 (dsb
->wfx
.wBitsPerSample
== primarybuf
->wfx
.wBitsPerSample
) &&
1576 (dsb
->wfx
.nChannels
== primarybuf
->wfx
.nChannels
)) {
1577 TRACE(dsound
, "(%p) Best case\n", dsb
);
1578 if ((ibp
+ len
) < (BYTE
*)(dsb
->buffer
+ dsb
->buflen
))
1579 memcpy(obp
, ibp
, len
);
1581 memcpy(obp
, ibp
, dsb
->buflen
- dsb
->playpos
);
1582 memcpy(obp
+ (dsb
->buflen
- dsb
->playpos
),
1584 len
- (dsb
->buflen
- dsb
->playpos
));
1589 // Check for same sample rate
1590 if (dsb
->freq
== primarybuf
->wfx
.nSamplesPerSec
) {
1591 TRACE(dsound
, "(%p) Same sample rate %ld = primary %ld\n", dsb
,
1592 dsb
->freq
, primarybuf
->wfx
.nSamplesPerSec
);
1594 for (i
= 0; i
< len
; i
+= oAdvance
) {
1595 get_fields(dsb
, ibp
, &fieldL
, &fieldR
);
1598 set_fields(obp
, fieldL
, fieldR
);
1600 if (ibp
>= (BYTE
*)(dsb
->buffer
+ dsb
->buflen
))
1601 ibp
= dsb
->buffer
; // wrap
1606 // Mix in different sample rates
1608 // New PerfectPitch(tm) Technology (c) 1998 Rob Riggs
1609 // Patent Pending :-]
1611 TRACE(dsound
, "(%p) Adjusting frequency: %ld -> %ld\n",
1612 dsb
, dsb
->freq
, primarybuf
->wfx
.nSamplesPerSec
);
1614 size
= len
/ oAdvance
;
1615 ilen
= ((size
* dsb
->freqAdjust
) >> DSOUND_FREQSHIFT
) * iAdvance
;
1616 for (i
= 0; i
< size
; i
++) {
1618 ipos
= (((i
* dsb
->freqAdjust
) >> DSOUND_FREQSHIFT
) * iAdvance
) + dsb
->playpos
;
1620 if (ipos
>= dsb
->buflen
)
1621 ipos
%= dsb
->buflen
; // wrap
1623 get_fields(dsb
, (dsb
->buffer
+ ipos
), &fieldL
, &fieldR
);
1624 set_fields(obp
, fieldL
, fieldR
);
1630 static void DSOUND_MixerVol(IDirectSoundBuffer
*dsb
, BYTE
*buf
, INT32 len
)
1632 INT32 i
, inc
= primarybuf
->wfx
.wBitsPerSample
>> 3;
1634 INT16
*bps
= (INT16
*) buf
;
1636 TRACE(dsound
, "(%p) left = %lx, right = %lx\n", dsb
,
1637 dsb
->lVolAdjust
, dsb
->rVolAdjust
);
1638 if ((!(dsb
->dsbd
.dwFlags
& DSBCAPS_CTRLPAN
) || (dsb
->pan
== 0)) &&
1639 (!(dsb
->dsbd
.dwFlags
& DSBCAPS_CTRLVOLUME
) || (dsb
->volume
== 0)) &&
1640 !(dsb
->dsbd
.dwFlags
& DSBCAPS_CTRL3D
))
1641 return; // Nothing to do
1643 // If we end up with some bozo coder using panning or 3D sound
1644 // with a mono primary buffer, it could sound very weird using
1645 // this method. Oh well, tough patooties.
1647 for (i
= 0; i
< len
; i
+= inc
) {
1653 // 8-bit WAV is unsigned, but we need to operate
1654 // on signed data for this to work properly
1656 val
= ((val
* (i
& inc
? dsb
->rVolAdjust
: dsb
->lVolAdjust
)) >> 15);
1661 // 16-bit WAV is signed -- much better
1663 val
= ((val
* ((i
& inc
) ? dsb
->rVolAdjust
: dsb
->lVolAdjust
)) >> 15);
1669 FIXME(dsound
, "MixerVol had a nasty error\n");
1675 static void DSOUND_Mixer3D(IDirectSoundBuffer
*dsb
, BYTE
*buf
, INT32 len
)
1678 DWORD buflen
, playpos
;
1680 buflen
= dsb
->ds3db
->buflen
;
1681 playpos
= (dsb
->playpos
* primarybuf
->wfx
.nBlockAlign
) / dsb
->wfx
.nBlockAlign
;
1682 ibp
= dsb
->ds3db
->buffer
+ playpos
;
1685 if (playpos
> buflen
) {
1686 FIXME(dsound
, "Major breakage");
1690 if (len
<= (playpos
+ buflen
))
1691 memcpy(obp
, ibp
, len
);
1693 memcpy(obp
, ibp
, buflen
- playpos
);
1694 memcpy(obp
+ (buflen
- playpos
),
1696 len
- (buflen
- playpos
));
1702 static DWORD
DSOUND_MixInBuffer(IDirectSoundBuffer
*dsb
)
1704 INT32 i
, len
, ilen
, temp
, field
;
1705 INT32 advance
= primarybuf
->wfx
.wBitsPerSample
>> 3;
1706 BYTE
*buf
, *ibuf
, *obuf
;
1707 INT16
*ibufs
, *obufs
;
1709 len
= DSOUND_BUFLEN
; // The most we will use
1710 len
&= ~3; // 4 byte alignment
1711 if (!(dsb
->playflags
& DSBPLAY_LOOPING
)) {
1712 temp
= ((primarybuf
->wfx
.nAvgBytesPerSec
* dsb
->buflen
) /
1713 dsb
->nAvgBytesPerSec
) -
1714 ((primarybuf
->wfx
.nAvgBytesPerSec
* dsb
->playpos
) /
1715 dsb
->nAvgBytesPerSec
);
1716 len
= (len
> temp
) ? temp
: len
;
1719 if ((buf
= ibuf
= (BYTE
*) malloc(len
)) == NULL
)
1722 TRACE(dsound
, "MixInBuffer (%p) len = %d\n", dsb
, len
);
1724 ilen
= DSOUND_MixerNorm(dsb
, ibuf
, len
);
1725 if ((dsb
->dsbd
.dwFlags
& DSBCAPS_CTRLPAN
) ||
1726 (dsb
->dsbd
.dwFlags
& DSBCAPS_CTRLVOLUME
))
1727 DSOUND_MixerVol(dsb
, ibuf
, len
);
1729 TRACE(dsound
, "Mixing buffer - advance = %d\n", advance
);
1730 obuf
= primarybuf
->buffer
+ primarybuf
->playpos
;
1731 for (i
= 0; i
< len
; i
+= advance
) {
1732 obufs
= (INT16
*) obuf
;
1733 ibufs
= (INT16
*) ibuf
;
1734 if (primarybuf
->wfx
.wBitsPerSample
== 8) {
1737 // 8-bit WAV is unsigned
1738 field
= field
> 255 ? 255 : field
;
1743 // 16-bit WAV is signed
1744 field
= field
> 32767 ? 32767 : field
;
1745 field
= field
< -32768 ? -32768 : field
;
1750 if (obuf
>= (BYTE
*)(primarybuf
->buffer
+ primarybuf
->buflen
))
1751 obuf
= primarybuf
->buffer
;
1755 if (dsb
->dsbd
.dwFlags
& DSBCAPS_CTRLPOSITIONNOTIFY
)
1756 DSOUND_CheckEvent(dsb
, ilen
);
1758 dsb
->playpos
+= ilen
;
1759 dsb
->writepos
= dsb
->playpos
+ ilen
;
1761 if (dsb
->playpos
>= dsb
->buflen
) {
1762 if (!(dsb
->playflags
& DSBPLAY_LOOPING
)) {
1766 DSOUND_CheckEvent(dsb
, 0); // For DSBPN_OFFSETSTOP
1768 dsb
->playpos
%= dsb
->buflen
; // wrap
1771 if (dsb
->writepos
>= dsb
->buflen
)
1772 dsb
->writepos
%= dsb
->buflen
;
1777 static DWORD WINAPI
DSOUND_MixPrimary(void)
1779 INT32 i
, len
, maxlen
= 0;
1780 IDirectSoundBuffer
*dsb
;
1782 for (i
= dsound
->nrofbuffers
- 1; i
>= 0; i
--) {
1783 dsb
= dsound
->buffers
[i
];
1785 if (!dsb
|| !(dsb
->lpvtbl
))
1787 dsb
->lpvtbl
->fnAddRef(dsb
);
1788 if (dsb
->buflen
&& dsb
->playing
) {
1789 EnterCriticalSection(&(dsb
->lock
));
1790 len
= DSOUND_MixInBuffer(dsb
);
1791 maxlen
= len
> maxlen
? len
: maxlen
;
1792 LeaveCriticalSection(&(dsb
->lock
));
1794 dsb
->lpvtbl
->fnRelease(dsb
);
1800 static int DSOUND_OpenAudio(void)
1804 if (primarybuf
== NULL
)
1805 return DSERR_OUTOFMEMORY
;
1807 while (audiofd
!= -1)
1809 audiofd
= open("/dev/audio",O_WRONLY
);
1811 perror("open /dev/audio");
1813 return DSERR_NODRIVER
;
1816 audioFragment
=0x0002000c;
1817 if (-1==ioctl(audiofd
,SNDCTL_DSP_SETFRAGMENT
,&audioFragment
))
1818 perror("ioctl SETFRAGMENT");
1821 DSOUND_setformat(&(primarybuf
->wfx
));
1826 static void DSOUND_CloseAudio(void)
1828 audioOK
= 0; // race condition
1831 primarybuf
->playpos
= 0;
1832 primarybuf
->writepos
= DSOUND_BUFLEN
;
1833 memset(primarybuf
->buffer
, 0, primarybuf
->buflen
);
1835 TRACE(dsound
, "Audio stopped\n");
1838 static int DSOUND_WriteAudio(char *buf
, int len
)
1840 int result
, left
= 0;
1842 while (left
< len
) {
1843 result
= write(audiofd
, buf
+ left
, len
- left
);
1854 static DWORD WINAPI
DSOUND_thread(LPVOID arg
)
1856 int maxlen
= DSOUND_BUFLEN
;
1859 TRACE(dsound
,"dsound is at pid %d\n",getpid());
1862 WARN(dsound
,"DSOUND thread giving up.\n");
1866 WARN(dsound
,"DSOUND father died? Giving up.\n");
1869 /* RACE: dsound could be deleted */
1870 dsound
->lpvtbl
->fnAddRef(dsound
);
1871 if (primarybuf
== NULL
) { // Should never happen
1872 /* no soundbuffer yet... wait. */
1874 dsound
->lpvtbl
->fnRelease(dsound
);
1879 EnterCriticalSection(&(primarybuf
->lock
));
1880 len
= DSOUND_MixPrimary();
1881 LeaveCriticalSection(&(primarybuf
->lock
));
1884 if (primarybuf
->playing
)
1885 len
= maxlen
> len
? maxlen
: len
;
1888 EnterCriticalSection(&(primarybuf
->lock
));
1892 if (primarybuf
->playpos
+ len
>= primarybuf
->buflen
) {
1893 if (DSOUND_WriteAudio(
1894 primarybuf
->buffer
+ primarybuf
->playpos
,
1895 primarybuf
->buflen
- primarybuf
->playpos
)
1897 perror("DSOUND_WriteAudio");
1900 memset(primarybuf
->buffer
+ primarybuf
->playpos
, 0,
1901 primarybuf
->buflen
- primarybuf
->playpos
);
1902 if (DSOUND_WriteAudio(primarybuf
->buffer
,
1903 len
- (primarybuf
->buflen
- primarybuf
->playpos
)) != 0) {
1904 perror("DSOUND_WriteAudio");
1907 memset(primarybuf
->buffer
, 0,
1908 len
- (primarybuf
->buflen
- primarybuf
->playpos
));
1910 if (DSOUND_WriteAudio(
1911 primarybuf
->buffer
+ primarybuf
->playpos
,
1913 perror("DSOUND_WriteAudio");
1916 memset(primarybuf
->buffer
+ primarybuf
->playpos
, 0, len
);
1918 primarybuf
->playpos
+= len
;
1919 if (primarybuf
->playpos
>= primarybuf
->buflen
)
1920 primarybuf
->playpos
%= primarybuf
->buflen
;
1921 primarybuf
->writepos
= primarybuf
->playpos
+ maxlen
;
1922 if (primarybuf
->writepos
>= primarybuf
->buflen
)
1923 primarybuf
->writepos
%= primarybuf
->buflen
;
1925 LeaveCriticalSection(&(primarybuf
->lock
));
1928 /* no soundbuffer. close and wait. */
1930 DSOUND_CloseAudio();
1933 dsound
->lpvtbl
->fnRelease(dsound
);
1938 #endif /* HAVE_OSS */
1940 HRESULT WINAPI
DirectSoundCreate(LPGUID lpGUID
,LPDIRECTSOUND
*ppDS
,IUnknown
*pUnkOuter
)
1943 TRACE(dsound
,"(%p,%p,%p)\n",lpGUID
,ppDS
,pUnkOuter
);
1945 TRACE(dsound
,"DirectSoundCreate (%p)\n", ppDS
);
1950 return DSERR_INVALIDPARAM
;
1953 dsound
->lpvtbl
->fnAddRef(dsound
);
1958 *ppDS
= (LPDIRECTSOUND
)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectSound
));
1960 return DSERR_OUTOFMEMORY
;
1963 (*ppDS
)->lpvtbl
= &dsvt
;
1964 (*ppDS
)->buffers
= NULL
;
1965 (*ppDS
)->nrofbuffers
= 0;
1967 (*ppDS
)->wfx
.wFormatTag
= 1;
1968 (*ppDS
)->wfx
.nChannels
= 2;
1969 (*ppDS
)->wfx
.nSamplesPerSec
= 22050;
1970 (*ppDS
)->wfx
.nAvgBytesPerSec
= 44100;
1971 (*ppDS
)->wfx
.nBlockAlign
= 2;
1972 (*ppDS
)->wfx
.wBitsPerSample
= 8;
1979 if (primarybuf
== NULL
) {
1983 dsbd
.dwSize
= sizeof(DSBUFFERDESC
);
1984 dsbd
.dwFlags
= DSBCAPS_PRIMARYBUFFER
;
1985 dsbd
.dwBufferBytes
= 0;
1986 dsbd
.lpwfxFormat
= &(dsound
->wfx
);
1987 hr
= IDirectSound_CreateSoundBuffer(*ppDS
, &dsbd
, &primarybuf
, NULL
);
1988 if (hr
!= DS_OK
) return hr
;
1989 dsound
->primary
= primarybuf
;
1992 hnd
= CreateThread(NULL
,0,DSOUND_thread
,0,0,&xid
);
1996 MessageBox32A(0,"DirectSound needs the Open Sound System Driver, which has not been found by ./configure.","WINE DirectSound",MB_OK
|MB_ICONSTOP
);
1997 return DSERR_NODRIVER
;
2001 /*******************************************************************************
2002 * DirectSound ClassFactory
2004 static HRESULT WINAPI
2005 DSCF_QueryInterface(LPCLASSFACTORY
this,REFIID riid
,LPVOID
*ppobj
) {
2009 WINE_StringFromCLSID(riid
,buf
);
2011 sprintf(buf
,"<guid-0x%04x>",LOWORD(riid
));
2012 FIXME(dsound
,"(%p)->(%s,%p),stub!\n",this,buf
,ppobj
);
2013 return E_NOINTERFACE
;
2017 DSCF_AddRef(LPCLASSFACTORY
this) {
2018 return ++(this->ref
);
2021 static ULONG WINAPI
DSCF_Release(LPCLASSFACTORY
this) {
2022 /* static class, won't be freed */
2023 return --(this->ref
);
2026 static HRESULT WINAPI
DSCF_CreateInstance(
2027 LPCLASSFACTORY
this,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
2031 WINE_StringFromCLSID(riid
,buf
);
2032 TRACE(dsound
,"(%p)->(%p,%s,%p)\n",this,pOuter
,buf
,ppobj
);
2033 if (!memcmp(riid
,&IID_IDirectSound
,sizeof(IID_IDirectSound
))) {
2034 /* FIXME: reuse already created dsound if present? */
2035 return DirectSoundCreate(riid
,(LPDIRECTSOUND
*)ppobj
,pOuter
);
2037 return E_NOINTERFACE
;
2040 static HRESULT WINAPI
DSCF_LockServer(LPCLASSFACTORY
this,BOOL32 dolock
) {
2041 FIXME(dsound
,"(%p)->(%d),stub!\n",this,dolock
);
2045 static IClassFactory_VTable DSCF_VTable
= {
2046 DSCF_QueryInterface
,
2049 DSCF_CreateInstance
,
2052 static IClassFactory DSOUND_CF
= {&DSCF_VTable
, 1 };
2054 /*******************************************************************************
2055 * DllGetClassObject [DSOUND.4]
2056 * Retrieves class object from a DLL object
2059 * Docs say returns STDAPI
2062 * rclsid [I] CLSID for the class object
2063 * riid [I] Reference to identifier of interface for class object
2064 * ppv [O] Address of variable to receive interface pointer for riid
2068 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
2071 DWORD WINAPI
DSOUND_DllGetClassObject(REFCLSID rclsid
,REFIID riid
,LPVOID
*ppv
)
2073 char buf
[80],xbuf
[80];
2076 WINE_StringFromCLSID(rclsid
,xbuf
);
2078 sprintf(xbuf
,"<guid-0x%04x>",LOWORD(rclsid
));
2080 WINE_StringFromCLSID(riid
,buf
);
2082 sprintf(buf
,"<guid-0x%04x>",LOWORD(riid
));
2083 WINE_StringFromCLSID(riid
,xbuf
);
2084 TRACE(dsound
, "(%p,%p,%p)\n", xbuf
, buf
, ppv
);
2085 if (!memcmp(riid
,&IID_IClassFactory
,sizeof(IID_IClassFactory
))) {
2086 *ppv
= (LPVOID
)&DSOUND_CF
;
2087 DSOUND_CF
.lpvtbl
->fnAddRef(&DSOUND_CF
);
2090 FIXME(dsound
, "(%p,%p,%p): no interface found.\n", xbuf
, buf
, ppv
);
2091 return E_NOINTERFACE
;
2095 /*******************************************************************************
2096 * DllCanUnloadNow [DSOUND.3] Determines whether the DLL is in use.
2102 DWORD WINAPI
DllCanUnloadNow(void)
2104 FIXME(dsound
, "(void): stub\n");