1 /* DirectSound COM interface
3 * Copyright 2009 Maarten Lankhorst
5 * Some code taken from the original dsound-openal implementation
6 * Copyright 2007-2009 Chris Robinson
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #define NONAMELESSSTRUCT
29 #define NONAMELESSUNION
39 #include "wine/debug.h"
42 #include "dsound_private.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(dsound
);
56 #include "dsound_private.h"
58 DEFINE_GUID(KSDATAFORMAT_SUBTYPE_PCM
, 0x00000001, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71);
59 DEFINE_GUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
, 0x00000003, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71);
61 #ifndef E_PROP_ID_UNSUPPORTED
62 #define E_PROP_ID_UNSUPPORTED ((HRESULT)0x80070490)
67 static const IDirectSoundBufferVtbl DS8Primary_Vtbl
;
68 static const IDirectSound3DListenerVtbl DS8Primary3D_Vtbl
;
69 static const IKsPropertySetVtbl DS8PrimaryProp_Vtbl
;
71 static void AL_APIENTRY
wrap_DeferUpdates(void)
72 { alcSuspendContext(alcGetCurrentContext()); }
73 static void AL_APIENTRY
wrap_ProcessUpdates(void)
74 { alcProcessContext(alcGetCurrentContext()); }
77 static void trigger_elapsed_notifies(DS8Buffer
*buf
, DWORD lastpos
, DWORD curpos
)
80 for(i
= 0; i
< buf
->nnotify
; ++i
)
82 DSBPOSITIONNOTIFY
*not = &buf
->notify
[i
];
83 HANDLE event
= not->hEventNotify
;
84 DWORD ofs
= not->dwOffset
;
86 if(ofs
== (DWORD
)DSBPN_OFFSETSTOP
)
92 if(ofs
< curpos
|| ofs
>= lastpos
)
98 if(ofs
>= lastpos
&& ofs
< curpos
)
103 static void trigger_stop_notifies(DS8Buffer
*buf
)
106 for(i
= 0; i
< buf
->nnotify
; ++i
)
108 DSBPOSITIONNOTIFY
*not = &buf
->notify
[i
];
109 if(not->dwOffset
== (DWORD
)DSBPN_OFFSETSTOP
)
110 SetEvent(not->hEventNotify
);
114 static DWORD CALLBACK
ThreadProc(void *dwUser
)
116 DS8Primary
*prim
= (DS8Primary
*)dwUser
;
120 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL
);
122 while(GetMessageA(&msg
, NULL
, 0, 0))
124 if(msg
.message
!= WM_USER
)
127 EnterCriticalSection(&prim
->crst
);
128 setALContext(prim
->ctx
);
130 /* OpenAL doesn't support our lovely buffer extensions
131 * so just make sure enough buffers are queued
133 if(!prim
->ExtAL
.BufferSamplesSOFT
&& !prim
->ExtAL
.BufferSubData
&&
134 !prim
->ExtAL
.BufferDataStatic
)
136 for(i
= 0;i
< prim
->nbuffers
;++i
)
138 DS8Buffer
*buf
= prim
->buffers
[i
];
139 ALint done
= 0, queued
= QBUFFERS
, state
= AL_PLAYING
;
142 if(buf
->buffer
->numsegs
== 1 || !buf
->isplaying
)
145 alGetSourcei(buf
->source
, AL_SOURCE_STATE
, &state
);
146 alGetSourcei(buf
->source
, AL_BUFFERS_QUEUED
, &queued
);
147 alGetSourcei(buf
->source
, AL_BUFFERS_PROCESSED
, &done
);
151 alSourceUnqueueBuffers(buf
->source
, 1, &which
);
152 while(queued
< QBUFFERS
)
154 which
= buf
->buffer
->buffers
[buf
->curidx
];
155 ofs
= buf
->curidx
*buf
->buffer
->segsize
;
156 if(buf
->curidx
< buf
->buffer
->numsegs
-1)
157 alBufferData(which
, buf
->buffer
->buf_format
,
158 buf
->buffer
->data
+ ofs
, buf
->buffer
->segsize
,
159 buf
->buffer
->format
.Format
.nSamplesPerSec
);
161 alBufferData(which
, buf
->buffer
->buf_format
,
162 buf
->buffer
->data
+ ofs
, buf
->buffer
->lastsegsize
,
163 buf
->buffer
->format
.Format
.nSamplesPerSec
);
165 alSourceQueueBuffers(buf
->source
, 1, &which
);
166 buf
->curidx
= (buf
->curidx
+1)%buf
->buffer
->numsegs
;
169 if(!buf
->curidx
&& !buf
->islooping
)
171 buf
->isplaying
= FALSE
;
175 if(state
!= AL_PLAYING
)
179 IDirectSoundBuffer8_Stop(&buf
->IDirectSoundBuffer8_iface
);
182 alSourcePlay(buf
->source
);
188 for(i
= 0;i
< prim
->nnotifies
;)
190 DS8Buffer
*buf
= prim
->notifies
[i
];
191 IDirectSoundBuffer8
*dsb
= &buf
->IDirectSoundBuffer8_iface
;
192 DWORD status
=0, curpos
=buf
->lastpos
;
194 IDirectSoundBuffer8_GetStatus(dsb
, &status
);
195 IDirectSoundBuffer8_GetCurrentPosition(dsb
, &curpos
, NULL
);
196 if(buf
->lastpos
!= curpos
)
198 trigger_elapsed_notifies(buf
, buf
->lastpos
, curpos
);
199 buf
->lastpos
= curpos
;
201 if(!(status
&DSBSTATUS_PLAYING
))
203 /* Remove this buffer from list and put another at the
204 * current position; don't increment i
206 trigger_stop_notifies(buf
);
207 prim
->notifies
[i
] = prim
->notifies
[--prim
->nnotifies
];
213 LeaveCriticalSection(&prim
->crst
);
219 HRESULT
DS8Primary_Create(DS8Primary
**ppv
, DS8Impl
*parent
)
221 HRESULT hr
= DSERR_OUTOFMEMORY
;
222 DS8Primary
*This
= NULL
;
223 DS3DLISTENER
*listener
;
229 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*This
));
232 This
->IDirectSoundBuffer_iface
.lpVtbl
= (IDirectSoundBufferVtbl
*)&DS8Primary_Vtbl
;
233 This
->IDirectSound3DListener_iface
.lpVtbl
= (IDirectSound3DListenerVtbl
*)&DS8Primary3D_Vtbl
;
234 This
->IKsPropertySet_iface
.lpVtbl
= (IKsPropertySetVtbl
*)&DS8PrimaryProp_Vtbl
;
236 InitializeCriticalSection(&This
->crst
);
237 This
->crst
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": DS8Primary.crst");
239 /* Allocate enough for a WAVEFORMATEXTENSIBLE */
240 wfx
= &This
->format
.Format
;
243 This
->ctx
= alcCreateContext(parent
->device
, NULL
);
246 ALCenum err
= alcGetError(parent
->device
);
247 ERR("Could not create context (0x%x)!\n", err
);
251 setALContext(This
->ctx
);
252 if(alIsExtensionPresent("AL_EXT_FLOAT32"))
254 TRACE("Found AL_EXT_FLOAT32\n");
255 This
->SupportedExt
[EXT_FLOAT32
] = AL_TRUE
;
257 if(alIsExtensionPresent("AL_EXT_MCFORMATS"))
259 TRACE("Found AL_EXT_MCFORMATS\n");
260 This
->SupportedExt
[EXT_MCFORMATS
] = AL_TRUE
;
262 if(alIsExtensionPresent("AL_EXT_STATIC_BUFFER"))
264 TRACE("Found AL_EXT_STATIC_BUFFER\n");
265 This
->ExtAL
.BufferDataStatic
= alGetProcAddress("alBufferDataStatic");
266 This
->SupportedExt
[EXT_STATIC_BUFFER
] = AL_TRUE
;
268 if(alIsExtensionPresent("AL_SOFTX_buffer_samples"))
270 TRACE("Found AL_SOFTX_buffer_samples\n");
271 This
->ExtAL
.BufferSamplesSOFT
= alGetProcAddress("alBufferSamplesSOFT");
272 This
->ExtAL
.BufferSubSamplesSOFT
= alGetProcAddress("alBufferSubSamplesSOFT");
273 This
->ExtAL
.GetBufferSamplesSOFT
= alGetProcAddress("alGetBufferSamplesSOFT");
274 This
->ExtAL
.IsBufferFormatSupportedSOFT
= alGetProcAddress("alIsBufferFormatSupportedSOFT");
275 This
->SupportedExt
[SOFT_BUFFER_SAMPLES
] = AL_TRUE
;
277 if(alIsExtensionPresent("AL_SOFT_buffer_sub_data"))
279 TRACE("Found AL_SOFT_buffer_sub_data\n");
280 This
->ExtAL
.BufferSubData
= alGetProcAddress("alBufferSubDataSOFT");
281 This
->SupportedExt
[SOFT_BUFFER_SUB_DATA
] = AL_TRUE
;
283 if(alIsExtensionPresent("AL_SOFTX_deferred_updates"))
285 TRACE("Found AL_SOFTX_deferred_updates\n");
286 This
->ExtAL
.DeferUpdates
= alGetProcAddress("alDeferUpdatesSOFT");
287 This
->ExtAL
.ProcessUpdates
= alGetProcAddress("alProcessUpdatesSOFT");
288 This
->SupportedExt
[SOFT_DEFERRED_UPDATES
] = AL_TRUE
;
292 This
->ExtAL
.DeferUpdates
= wrap_DeferUpdates
;
293 This
->ExtAL
.ProcessUpdates
= wrap_ProcessUpdates
;
296 if(alcIsExtensionPresent(parent
->device
, "ALC_EXT_EFX"))
298 #define LOAD_FUNC(x) (This->ExtAL.x = alGetProcAddress("al"#x))
299 LOAD_FUNC(GenEffects
);
300 LOAD_FUNC(DeleteEffects
);
304 LOAD_FUNC(GenAuxiliaryEffectSlots
);
305 LOAD_FUNC(DeleteAuxiliaryEffectSlots
);
306 LOAD_FUNC(AuxiliaryEffectSloti
);
308 This
->SupportedExt
[EXT_EFX
] = AL_TRUE
;
310 This
->ExtAL
.GenEffects(1, &This
->effect
);
311 This
->ExtAL
.Effecti(This
->effect
, AL_EFFECT_TYPE
, AL_EFFECT_REVERB
);
313 This
->ExtAL
.GenAuxiliaryEffectSlots(1, &This
->auxslot
);
315 This
->eax_prop
= EnvironmentDefaults
[EAX_ENVIRONMENT_GENERIC
];
317 wfx
->wFormatTag
= WAVE_FORMAT_PCM
;
319 wfx
->wBitsPerSample
= 8;
320 wfx
->nSamplesPerSec
= 22050;
321 wfx
->nBlockAlign
= wfx
->wBitsPerSample
* wfx
->nChannels
/ 8;
322 wfx
->nAvgBytesPerSec
= wfx
->nSamplesPerSec
* wfx
->nBlockAlign
;
325 This
->stopped
= TRUE
;
326 This
->parent
= parent
;
327 /* Apparently primary buffer size is always 32k,
328 * tested on windows with 192k 24 bits sound @ 6 channels
329 * where it will run out in 60 ms and it isn't pointer aligned
331 This
->buf_size
= 32768;
333 if(!This
->ExtAL
.BufferSubData
&& !This
->ExtAL
.BufferSamplesSOFT
&&
334 !This
->ExtAL
.BufferDataStatic
)
336 ERR("Missing alBufferSubDataSOFT, alBufferSamplesSOFT , and alBufferDataStatic on device '%s', sound playback quality may be degraded\n",
337 alcGetString(parent
->device
, ALC_DEVICE_SPECIFIER
));
338 ERR("Please consider using OpenAL-Soft\n");
341 /* Make sure DS3DListener defaults are applied to OpenAL */
342 listener
= &This
->listen
;
343 listener
->dwSize
= sizeof(*listener
);
344 listener
->vPosition
.x
= 0.0;
345 listener
->vPosition
.y
= 0.0;
346 listener
->vPosition
.z
= 0.0;
347 listener
->vVelocity
.x
= 0.0;
348 listener
->vVelocity
.y
= 0.0;
349 listener
->vVelocity
.z
= 0.0;
350 listener
->vOrientFront
.x
= 0.0;
351 listener
->vOrientFront
.y
= 0.0;
352 listener
->vOrientFront
.z
= 1.0;
353 listener
->vOrientTop
.x
= 0.0;
354 listener
->vOrientTop
.y
= 1.0;
355 listener
->vOrientTop
.z
= 0.0;
356 listener
->flDistanceFactor
= DS3D_DEFAULTDISTANCEFACTOR
;
357 listener
->flRolloffFactor
= DS3D_DEFAULTROLLOFFFACTOR
;
358 listener
->flDopplerFactor
= DS3D_DEFAULTDOPPLERFACTOR
;
359 hr
= IDirectSound3DListener_SetAllParameters(&This
->IDirectSound3DListener_iface
, listener
, DS3D_IMMEDIATE
);
361 ERR("Could not set 3d parameters: %08x\n", hr
);
363 for(nsources
= 0;nsources
< sizeof(srcs
)/sizeof(*srcs
);nsources
++)
365 alGenSources(1, &srcs
[nsources
]);
366 if(alGetError() != AL_NO_ERROR
)
369 alDeleteSources(nsources
, srcs
);
374 This
->max_sources
= nsources
;
375 This
->sizenotifies
= This
->sizebuffers
= This
->sizesources
= nsources
+1;
377 hr
= DSERR_OUTOFMEMORY
;
378 This
->sources
= HeapAlloc(GetProcessHeap(), 0, nsources
*sizeof(*This
->sources
));
379 This
->buffers
= HeapAlloc(GetProcessHeap(), 0, nsources
*sizeof(*This
->buffers
));
380 This
->notifies
= HeapAlloc(GetProcessHeap(), 0, nsources
*sizeof(*This
->notifies
));
381 if(!This
->sources
|| !This
->buffers
|| !This
->notifies
)
384 This
->thread_hdl
= CreateThread(NULL
, 0, ThreadProc
, This
, 0, &This
->thread_id
);
385 if(This
->thread_hdl
== NULL
)
392 DS8Primary_Destroy(This
);
396 void DS8Primary_Destroy(DS8Primary
*This
)
398 TRACE("Destroying primary %p\n", This
);
402 timeKillEvent(This
->timer_id
);
403 timeEndPeriod(This
->timer_res
);
404 TRACE("Killed timer\n");
408 PostThreadMessageA(This
->thread_id
, WM_QUIT
, 0, 0);
409 WaitForSingleObject(This
->thread_hdl
, 1000);
410 CloseHandle(This
->thread_hdl
);
415 /* Calling setALContext is not appropriate here,
416 * since we *have* to unset the context before destroying it
420 EnterCriticalSection(&openal_crst
);
421 old_ctx
= get_context();
422 if(old_ctx
!= This
->ctx
)
423 set_context(This
->ctx
);
427 while(This
->nbuffers
--)
428 DS8Buffer_Destroy(This
->buffers
[This
->nbuffers
]);
431 alDeleteSources(This
->nsources
, This
->sources
);
434 This
->ExtAL
.DeleteEffects(1, &This
->effect
);
436 This
->ExtAL
.DeleteAuxiliaryEffectSlots(1, &This
->auxslot
);
438 HeapFree(GetProcessHeap(), 0, This
->sources
);
439 HeapFree(GetProcessHeap(), 0, This
->notifies
);
440 HeapFree(GetProcessHeap(), 0, This
->buffers
);
442 set_context(old_ctx
);
443 alcDestroyContext(This
->ctx
);
444 LeaveCriticalSection(&openal_crst
);
447 This
->crst
.DebugInfo
->Spare
[0] = 0;
448 DeleteCriticalSection(&This
->crst
);
450 HeapFree(GetProcessHeap(), 0, This
);
453 static inline DS8Primary
*impl_from_IDirectSoundBuffer(IDirectSoundBuffer
*iface
)
455 return CONTAINING_RECORD(iface
, DS8Primary
, IDirectSoundBuffer_iface
);
458 static HRESULT WINAPI
DS8Primary_QueryInterface(IDirectSoundBuffer
*iface
, REFIID riid
, LPVOID
*ppv
)
460 DS8Primary
*This
= impl_from_IDirectSoundBuffer(iface
);
462 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
465 if(IsEqualIID(riid
, &IID_IUnknown
) ||
466 IsEqualIID(riid
, &IID_IDirectSoundBuffer
))
467 *ppv
= &This
->IDirectSoundBuffer_iface
;
468 else if(IsEqualIID(riid
, &IID_IDirectSound3DListener
))
470 if((This
->flags
&DSBCAPS_CTRL3D
))
471 *ppv
= &This
->IDirectSound3DListener_iface
;
474 FIXME("Unhandled GUID: %s\n", debugstr_guid(riid
));
478 IUnknown_AddRef((IUnknown
*)*ppv
);
482 return E_NOINTERFACE
;
485 static ULONG WINAPI
DS8Primary_AddRef(IDirectSoundBuffer
*iface
)
487 DS8Primary
*This
= impl_from_IDirectSoundBuffer(iface
);
490 ret
= InterlockedIncrement(&This
->ref
);
497 static ULONG WINAPI
DS8Primary_Release(IDirectSoundBuffer
*iface
)
499 DS8Primary
*This
= impl_from_IDirectSoundBuffer(iface
);
502 ret
= InterlockedDecrement(&This
->ref
);
507 static HRESULT WINAPI
DS8Primary_GetCaps(IDirectSoundBuffer
*iface
, DSBCAPS
*caps
)
509 DS8Primary
*This
= impl_from_IDirectSoundBuffer(iface
);
511 TRACE("(%p)->(%p)\n", iface
, caps
);
513 if(!caps
|| caps
->dwSize
< sizeof(*caps
))
515 WARN("Invalid DSBCAPS (%p, %u)\n", caps
, caps
? caps
->dwSize
: 0);
516 return DSERR_INVALIDPARAM
;
519 EnterCriticalSection(&This
->crst
);
520 caps
->dwFlags
= This
->flags
;
521 caps
->dwBufferBytes
= This
->buf_size
;
522 caps
->dwUnlockTransferRate
= 0;
523 caps
->dwPlayCpuOverhead
= 0;
524 LeaveCriticalSection(&This
->crst
);
529 static HRESULT WINAPI
DS8Primary_GetCurrentPosition(IDirectSoundBuffer
*iface
, DWORD
*playpos
, DWORD
*curpos
)
531 DS8Primary
*This
= impl_from_IDirectSoundBuffer(iface
);
532 HRESULT hr
= DSERR_PRIOLEVELNEEDED
;
534 EnterCriticalSection(&This
->crst
);
536 hr
= IDirectSoundBuffer8_GetCurrentPosition(This
->write_emu
, playpos
, curpos
);
537 LeaveCriticalSection(&This
->crst
);
542 static HRESULT WINAPI
DS8Primary_GetFormat(IDirectSoundBuffer
*iface
, WAVEFORMATEX
*wfx
, DWORD allocated
, DWORD
*written
)
544 DS8Primary
*This
= impl_from_IDirectSoundBuffer(iface
);
550 WARN("Cannot report format or format size\n");
551 return DSERR_INVALIDPARAM
;
554 EnterCriticalSection(&This
->crst
);
555 size
= sizeof(This
->format
.Format
) + This
->format
.Format
.cbSize
;
561 hr
= DSERR_INVALIDPARAM
;
563 memcpy(wfx
, &This
->format
.Format
, size
);
565 LeaveCriticalSection(&This
->crst
);
570 static HRESULT WINAPI
DS8Primary_GetVolume(IDirectSoundBuffer
*iface
, LONG
*volume
)
572 DS8Primary
*This
= impl_from_IDirectSoundBuffer(iface
);
575 TRACE("(%p)->(%p)\n", iface
, volume
);
578 return DSERR_INVALIDPARAM
;
580 EnterCriticalSection(&This
->crst
);
581 if(!(This
->flags
& DSBCAPS_CTRLVOLUME
))
582 hr
= DSERR_CONTROLUNAVAIL
;
588 setALContext(This
->ctx
);
589 alGetListenerf(AL_GAIN
, &gain
);
593 vol
= gain_to_mB(gain
);
594 vol
= max(vol
, DSBVOLUME_MIN
);
595 *volume
= min(vol
, DSBVOLUME_MAX
);
597 LeaveCriticalSection(&This
->crst
);
602 static HRESULT WINAPI
DS8Primary_GetPan(IDirectSoundBuffer
*iface
, LONG
*pan
)
604 DS8Primary
*This
= impl_from_IDirectSoundBuffer(iface
);
607 WARN("(%p)->(%p): semi-stub\n", iface
, pan
);
610 return DSERR_INVALIDPARAM
;
612 EnterCriticalSection(&This
->crst
);
614 hr
= IDirectSoundBuffer8_GetPan(This
->write_emu
, pan
);
615 else if(!(This
->flags
& DSBCAPS_CTRLPAN
))
616 hr
= DSERR_CONTROLUNAVAIL
;
619 LeaveCriticalSection(&This
->crst
);
624 static HRESULT WINAPI
DS8Primary_GetFrequency(IDirectSoundBuffer
*iface
, DWORD
*freq
)
626 DS8Primary
*This
= impl_from_IDirectSoundBuffer(iface
);
629 WARN("(%p)->(%p): semi-stub\n", iface
, freq
);
632 return DSERR_INVALIDPARAM
;
634 EnterCriticalSection(&This
->crst
);
635 if(!(This
->flags
& DSBCAPS_CTRLFREQUENCY
))
636 hr
= DSERR_CONTROLUNAVAIL
;
638 *freq
= This
->format
.Format
.nSamplesPerSec
;
639 LeaveCriticalSection(&This
->crst
);
644 static HRESULT WINAPI
DS8Primary_GetStatus(IDirectSoundBuffer
*iface
, DWORD
*status
)
646 DS8Primary
*This
= impl_from_IDirectSoundBuffer(iface
);
648 TRACE("(%p)->(%p)\n", iface
, status
);
651 return DSERR_INVALIDPARAM
;
653 EnterCriticalSection(&This
->crst
);
655 *status
= DSBSTATUS_PLAYING
|DSBSTATUS_LOOPING
;
656 if((This
->flags
&DSBCAPS_LOCDEFER
))
657 *status
|= DSBSTATUS_LOCHARDWARE
;
664 for(i
= 0;i
< This
->nbuffers
;++i
)
666 hr
= IDirectSoundBuffer_GetStatus((IDirectSoundBuffer
*)This
->buffers
[i
], &state
);
667 if(SUCCEEDED(hr
) && (state
&DSBSTATUS_PLAYING
))
670 if(i
== This
->nbuffers
)
672 /* Primary stopped and no buffers playing.. */
677 LeaveCriticalSection(&This
->crst
);
682 static HRESULT WINAPI
DS8Primary_Initialize(IDirectSoundBuffer
*iface
, IDirectSound
*ds
, const DSBUFFERDESC
*desc
)
684 DS8Primary
*This
= impl_from_IDirectSoundBuffer(iface
);
687 TRACE("(%p)->(%p, %p)\n", iface
, ds
, desc
);
689 if(!desc
|| desc
->lpwfxFormat
|| desc
->dwBufferBytes
)
691 WARN("Bad DSBDESC for primary buffer\n");
692 return DSERR_INVALIDPARAM
;
694 if((desc
->dwFlags
&DSBCAPS_CTRLFX
) ||
695 (desc
->dwFlags
&DSBCAPS_CTRLPOSITIONNOTIFY
) ||
696 (desc
->dwFlags
&DSBCAPS_LOCSOFTWARE
))
698 WARN("Bad dwFlags %08x\n", desc
->dwFlags
);
699 return DSERR_INVALIDPARAM
;
702 EnterCriticalSection(&This
->crst
);
703 /* Should be 0 if not initialized */
706 hr
= DSERR_ALREADYINITIALIZED
;
710 if(This
->parent
->prio_level
== DSSCL_WRITEPRIMARY
)
712 DSBUFFERDESC emudesc
;
717 ERR("There shouldn't be a write_emu!\n");
718 IDirectSoundBuffer8_Release(This
->write_emu
);
719 This
->write_emu
= NULL
;
722 memset(&emudesc
, 0, sizeof(emudesc
));
723 emudesc
.dwSize
= sizeof(emudesc
);
724 emudesc
.dwFlags
= DSBCAPS_LOCHARDWARE
| (desc
->dwFlags
&DSBCAPS_CTRLPAN
);
725 /* Dont play last incomplete sample */
726 emudesc
.dwBufferBytes
= This
->buf_size
- (This
->buf_size
%This
->format
.Format
.nBlockAlign
);
727 emudesc
.lpwfxFormat
= &This
->format
.Format
;
729 hr
= DS8Buffer_Create(&emu
, This
, NULL
);
732 This
->write_emu
= &emu
->IDirectSoundBuffer8_iface
;
733 hr
= IDirectSoundBuffer8_Initialize(This
->write_emu
, ds
, &emudesc
);
736 IDirectSoundBuffer8_Release(This
->write_emu
);
737 This
->write_emu
= NULL
;
743 This
->flags
= desc
->dwFlags
| DSBCAPS_LOCHARDWARE
;
745 LeaveCriticalSection(&This
->crst
);
749 static HRESULT WINAPI
DS8Primary_Lock(IDirectSoundBuffer
*iface
, DWORD ofs
, DWORD bytes
, void **ptr1
, DWORD
*len1
, void **ptr2
, DWORD
*len2
, DWORD flags
)
751 DS8Primary
*This
= impl_from_IDirectSoundBuffer(iface
);
752 HRESULT hr
= DSERR_PRIOLEVELNEEDED
;
754 TRACE("(%p)->(%u, %u, %p, %p, %p, %p, %u)\n", iface
, ofs
, bytes
, ptr1
, len1
, ptr2
, len2
, flags
);
756 EnterCriticalSection(&This
->crst
);
758 hr
= IDirectSoundBuffer8_Lock(This
->write_emu
, ofs
, bytes
, ptr1
, len1
, ptr2
, len2
, flags
);
759 LeaveCriticalSection(&This
->crst
);
764 static HRESULT WINAPI
DS8Primary_Play(IDirectSoundBuffer
*iface
, DWORD res1
, DWORD res2
, DWORD flags
)
766 DS8Primary
*This
= impl_from_IDirectSoundBuffer(iface
);
769 TRACE("(%p)->(%u, %u, %u)\n", iface
, res1
, res2
, flags
);
771 if(!(flags
& DSBPLAY_LOOPING
))
773 WARN("Flags (%08x) not set to DSBPLAY_LOOPING\n", flags
);
774 return DSERR_INVALIDPARAM
;
777 EnterCriticalSection(&This
->crst
);
780 hr
= IDirectSoundBuffer8_Play(This
->write_emu
, res1
, res2
, flags
);
782 This
->stopped
= FALSE
;
783 LeaveCriticalSection(&This
->crst
);
788 static HRESULT WINAPI
DS8Primary_SetCurrentPosition(IDirectSoundBuffer
*iface
, DWORD pos
)
790 WARN("(%p)->(%u)\n", iface
, pos
);
791 return DSERR_INVALIDCALL
;
794 /* Just assume the format is crap, and clean up the damage */
795 static void copy_waveformat(WAVEFORMATEX
*wfx
, const WAVEFORMATEX
*from
)
797 if(from
->wFormatTag
== WAVE_FORMAT_PCM
)
800 if(from
->wBitsPerSample
== 8 ||
801 from
->wBitsPerSample
== 16 ||
802 from
->wBitsPerSample
== 24 ||
803 from
->wBitsPerSample
== 32)
804 wfx
->wBitsPerSample
= from
->wBitsPerSample
;
806 else if(from
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
808 WAVEFORMATEXTENSIBLE
*wfe
= (WAVEFORMATEXTENSIBLE
*)wfx
;
809 const WAVEFORMATEXTENSIBLE
*fromx
= (const WAVEFORMATEXTENSIBLE
*)from
;
810 DWORD size
= sizeof(WAVEFORMATEXTENSIBLE
) - sizeof(WAVEFORMATEX
);
812 /* Fail silently.. */
813 if(from
->cbSize
< size
)
815 if(!fromx
->Samples
.wValidBitsPerSample
&&
816 !fromx
->Format
.wBitsPerSample
)
819 if(!IsEqualGUID(&wfe
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
) &&
820 !IsEqualGUID(&wfe
->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
))
822 ERR("Unhandled extensible format: %s\n", debugstr_guid(&wfe
->SubFormat
));
826 wfe
->Format
.wBitsPerSample
= from
->wBitsPerSample
;
827 wfe
->Samples
.wValidBitsPerSample
= fromx
->Samples
.wValidBitsPerSample
;
828 if(!wfe
->Samples
.wValidBitsPerSample
)
829 wfe
->Samples
.wValidBitsPerSample
= wfe
->Format
.wBitsPerSample
;
830 wfe
->Format
.cbSize
= size
;
831 wfe
->dwChannelMask
= fromx
->dwChannelMask
;
832 wfe
->SubFormat
= fromx
->SubFormat
;
836 ERR("Unhandled format tag %04x\n", from
->wFormatTag
);
841 wfx
->nChannels
= from
->nChannels
;
842 wfx
->wFormatTag
= from
->wFormatTag
;
843 if(from
->nSamplesPerSec
>= DSBFREQUENCY_MIN
&&
844 from
->nSamplesPerSec
<= DSBFREQUENCY_MAX
)
845 wfx
->nSamplesPerSec
= from
->nSamplesPerSec
;
846 wfx
->nBlockAlign
= wfx
->wBitsPerSample
* wfx
->nChannels
/ 8;
847 wfx
->nAvgBytesPerSec
= wfx
->nSamplesPerSec
* wfx
->nBlockAlign
;
850 static HRESULT WINAPI
DS8Primary_SetFormat(IDirectSoundBuffer
*iface
, const WAVEFORMATEX
*wfx
)
852 DS8Primary
*This
= impl_from_IDirectSoundBuffer(iface
);
856 TRACE("(%p)->(%p)\n", iface
, wfx
);
860 WARN("Missing format\n");
861 return DSERR_INVALIDPARAM
;
864 EnterCriticalSection(&This
->crst
);
866 if(This
->parent
->prio_level
< DSSCL_PRIORITY
)
868 hr
= DSERR_PRIOLEVELNEEDED
;
872 TRACE("Requested primary format:\n"
873 " FormatTag = %04x\n"
875 " SamplesPerSec = %u\n"
876 " AvgBytesPerSec = %u\n"
878 " BitsPerSample = %u\n",
879 wfx
->wFormatTag
, wfx
->nChannels
,
880 wfx
->nSamplesPerSec
, wfx
->nAvgBytesPerSec
,
881 wfx
->nBlockAlign
, wfx
->wBitsPerSample
);
883 copy_waveformat(&This
->format
.Format
, wfx
);
885 freq
= This
->format
.Format
.nSamplesPerSec
;
886 alcGetIntegerv(This
->parent
->device
, ALC_FREQUENCY
, 1, &freq
);
887 getALCError(This
->parent
->device
);
889 This
->format
.Format
.nSamplesPerSec
= freq
;
890 This
->format
.Format
.nAvgBytesPerSec
= This
->format
.Format
.nBlockAlign
*
891 This
->format
.Format
.nSamplesPerSec
;
898 memset(&desc
, 0, sizeof(desc
));
899 desc
.dwSize
= sizeof(desc
);
900 desc
.dwFlags
= DSBCAPS_LOCHARDWARE
|DSBCAPS_CTRLPAN
;
901 desc
.dwBufferBytes
= This
->buf_size
- (This
->buf_size
% This
->format
.Format
.nBlockAlign
);
902 desc
.lpwfxFormat
= &This
->format
.Format
;
904 hr
= DS8Buffer_Create(&buf
, This
, NULL
);
908 hr
= IDirectSoundBuffer8_Initialize(&buf
->IDirectSoundBuffer8_iface
, (IDirectSound
*)&This
->parent
->IDirectSound8_iface
, &desc
);
910 DS8Buffer_Destroy(buf
);
913 IDirectSoundBuffer8_Release(This
->write_emu
);
914 This
->write_emu
= &buf
->IDirectSoundBuffer8_iface
;
919 LeaveCriticalSection(&This
->crst
);
923 static HRESULT WINAPI
DS8Primary_SetVolume(IDirectSoundBuffer
*iface
, LONG vol
)
925 DS8Primary
*This
= impl_from_IDirectSoundBuffer(iface
);
928 TRACE("(%p)->(%d)\n", iface
, vol
);
930 if(vol
> DSBVOLUME_MAX
|| vol
< DSBVOLUME_MIN
)
932 WARN("Invalid volume (%d)\n", vol
);
933 return DSERR_INVALIDPARAM
;
936 EnterCriticalSection(&This
->crst
);
937 if(!(This
->flags
&DSBCAPS_CTRLVOLUME
))
938 hr
= DSERR_CONTROLUNAVAIL
;
941 setALContext(This
->ctx
);
942 alListenerf(AL_GAIN
, mB_to_gain(vol
));
945 LeaveCriticalSection(&This
->crst
);
950 static HRESULT WINAPI
DS8Primary_SetPan(IDirectSoundBuffer
*iface
, LONG pan
)
952 DS8Primary
*This
= impl_from_IDirectSoundBuffer(iface
);
955 TRACE("(%p)->(%d)\n", iface
, pan
);
957 if(pan
> DSBPAN_RIGHT
|| pan
< DSBPAN_LEFT
)
959 WARN("invalid parameter: pan = %d\n", pan
);
960 return DSERR_INVALIDPARAM
;
963 EnterCriticalSection(&This
->crst
);
964 if(!(This
->flags
&DSBCAPS_CTRLPAN
))
966 WARN("control unavailable\n");
967 hr
= DSERR_CONTROLUNAVAIL
;
969 else if(This
->write_emu
)
970 hr
= IDirectSoundBuffer8_SetPan(This
->write_emu
, pan
);
973 FIXME("Not supported\n");
976 LeaveCriticalSection(&This
->crst
);
981 static HRESULT WINAPI
DS8Primary_SetFrequency(IDirectSoundBuffer
*iface
, DWORD freq
)
983 WARN("(%p)->(%u)\n", iface
, freq
);
984 return DSERR_CONTROLUNAVAIL
;
987 static HRESULT WINAPI
DS8Primary_Stop(IDirectSoundBuffer
*iface
)
989 DS8Primary
*This
= impl_from_IDirectSoundBuffer(iface
);
992 TRACE("(%p)->()\n", iface
);
994 EnterCriticalSection(&This
->crst
);
996 hr
= IDirectSoundBuffer8_Stop(This
->write_emu
);
998 This
->stopped
= TRUE
;
999 LeaveCriticalSection(&This
->crst
);
1004 static HRESULT WINAPI
DS8Primary_Unlock(IDirectSoundBuffer
*iface
, void *ptr1
, DWORD len1
, void *ptr2
, DWORD len2
)
1006 DS8Primary
*This
= impl_from_IDirectSoundBuffer(iface
);
1007 HRESULT hr
= DSERR_INVALIDCALL
;
1009 TRACE("(%p)->(%p, %u, %p, %u)\n", iface
, ptr1
, len1
, ptr2
, len2
);
1011 EnterCriticalSection(&This
->crst
);
1013 hr
= IDirectSoundBuffer8_Unlock(This
->write_emu
, ptr1
, len1
, ptr2
, len2
);
1014 LeaveCriticalSection(&This
->crst
);
1019 static HRESULT WINAPI
DS8Primary_Restore(IDirectSoundBuffer
*iface
)
1021 DS8Primary
*This
= impl_from_IDirectSoundBuffer(iface
);
1024 TRACE("(%p)->()\n", iface
);
1026 EnterCriticalSection(&This
->crst
);
1028 hr
= IDirectSoundBuffer8_Restore(This
->write_emu
);
1029 LeaveCriticalSection(&This
->crst
);
1034 static const IDirectSoundBufferVtbl DS8Primary_Vtbl
=
1036 DS8Primary_QueryInterface
,
1040 DS8Primary_GetCurrentPosition
,
1041 DS8Primary_GetFormat
,
1042 DS8Primary_GetVolume
,
1044 DS8Primary_GetFrequency
,
1045 DS8Primary_GetStatus
,
1046 DS8Primary_Initialize
,
1049 DS8Primary_SetCurrentPosition
,
1050 DS8Primary_SetFormat
,
1051 DS8Primary_SetVolume
,
1053 DS8Primary_SetFrequency
,
1059 static inline DS8Primary
*impl_from_IDirectSound3DListener(IDirectSound3DListener
*iface
)
1061 return CONTAINING_RECORD(iface
, DS8Primary
, IDirectSound3DListener_iface
);
1064 static HRESULT WINAPI
DS8Primary3D_QueryInterface(IDirectSound3DListener
*iface
, REFIID riid
, void **ppv
)
1066 DS8Primary
*This
= impl_from_IDirectSound3DListener(iface
);
1067 return IDirectSoundBuffer_QueryInterface((IDirectSoundBuffer
*)This
, riid
, ppv
);
1070 static ULONG WINAPI
DS8Primary3D_AddRef(IDirectSound3DListener
*iface
)
1072 DS8Primary
*This
= impl_from_IDirectSound3DListener(iface
);
1075 ret
= InterlockedIncrement(&This
->ds3d_ref
);
1076 TRACE("new refcount %d\n", ret
);
1082 /* Considering the primary buffer doesn't get destroyed
1083 * it doesn't make sense to destroy ds3d here
1085 static ULONG WINAPI
DS8Primary3D_Release(IDirectSound3DListener
*iface
)
1087 DS8Primary
*This
= impl_from_IDirectSound3DListener(iface
);
1090 ret
= InterlockedDecrement(&This
->ds3d_ref
);
1091 TRACE("new refcount %d\n", ret
);
1097 static HRESULT WINAPI
DS8Primary3D_GetAllParameters(IDirectSound3DListener
*iface
, DS3DLISTENER
*listener
)
1099 DS8Primary
*This
= impl_from_IDirectSound3DListener(iface
);
1102 TRACE("(%p)->(%p)\n", iface
, listener
);
1104 if(!listener
|| listener
->dwSize
< sizeof(*listener
))
1106 WARN("Invalid DS3DLISTENER %p %u\n", listener
, listener
? listener
->dwSize
: 0);
1107 return DSERR_INVALIDPARAM
;
1110 EnterCriticalSection(&This
->crst
);
1111 setALContext(This
->ctx
);
1112 IDirectSound3DListener_GetPosition(iface
, &listener
->vPosition
);
1113 IDirectSound3DListener_GetVelocity(iface
, &listener
->vVelocity
);
1114 IDirectSound3DListener_GetOrientation(iface
, &listener
->vOrientFront
, &listener
->vOrientTop
);
1115 IDirectSound3DListener_GetDistanceFactor(iface
, &listener
->flDistanceFactor
);
1116 IDirectSound3DListener_GetRolloffFactor(iface
, &listener
->flRolloffFactor
);
1117 IDirectSound3DListener_GetRolloffFactor(iface
, &listener
->flDopplerFactor
);
1119 LeaveCriticalSection(&This
->crst
);
1125 static HRESULT WINAPI
DS8Primary3D_GetDistanceFactor(IDirectSound3DListener
*iface
, D3DVALUE
*distancefactor
)
1127 DS8Primary
*This
= impl_from_IDirectSound3DListener(iface
);
1129 TRACE("(%p)->(%p)\n", iface
, distancefactor
);
1133 WARN("Invalid parameter %p\n", distancefactor
);
1134 return DSERR_INVALIDPARAM
;
1137 EnterCriticalSection(&This
->crst
);
1138 setALContext(This
->ctx
);
1140 *distancefactor
= 343.3f
/alGetFloat(AL_SPEED_OF_SOUND
);
1144 LeaveCriticalSection(&This
->crst
);
1149 static HRESULT WINAPI
DS8Primary3D_GetDopplerFactor(IDirectSound3DListener
*iface
, D3DVALUE
*dopplerfactor
)
1151 DS8Primary
*This
= impl_from_IDirectSound3DListener(iface
);
1153 TRACE("(%p)->(%p)\n", iface
, dopplerfactor
);
1157 WARN("Invalid parameter %p\n", dopplerfactor
);
1158 return DSERR_INVALIDPARAM
;
1161 EnterCriticalSection(&This
->crst
);
1162 setALContext(This
->ctx
);
1164 *dopplerfactor
= alGetFloat(AL_DOPPLER_FACTOR
);
1168 LeaveCriticalSection(&This
->crst
);
1173 static HRESULT WINAPI
DS8Primary3D_GetOrientation(IDirectSound3DListener
*iface
, D3DVECTOR
*front
, D3DVECTOR
*top
)
1175 DS8Primary
*This
= impl_from_IDirectSound3DListener(iface
);
1178 TRACE("(%p)->(%p, %p)\n", iface
, front
, top
);
1182 WARN("Invalid parameter %p %p\n", front
, top
);
1183 return DSERR_INVALIDPARAM
;
1186 EnterCriticalSection(&This
->crst
);
1187 setALContext(This
->ctx
);
1189 alGetListenerfv(AL_ORIENTATION
, orient
);
1192 front
->x
= orient
[0];
1193 front
->y
= orient
[1];
1194 front
->z
= -orient
[2];
1197 top
->z
= -orient
[5];
1200 LeaveCriticalSection(&This
->crst
);
1205 static HRESULT WINAPI
DS8Primary3D_GetPosition(IDirectSound3DListener
*iface
, D3DVECTOR
*pos
)
1207 DS8Primary
*This
= impl_from_IDirectSound3DListener(iface
);
1210 TRACE("(%p)->(%p)\n", iface
, pos
);
1214 WARN("Invalid parameter %p\n", pos
);
1215 return DSERR_INVALIDPARAM
;
1218 EnterCriticalSection(&This
->crst
);
1219 setALContext(This
->ctx
);
1221 alGetListenerfv(AL_POSITION
, alpos
);
1229 LeaveCriticalSection(&This
->crst
);
1234 static HRESULT WINAPI
DS8Primary3D_GetRolloffFactor(IDirectSound3DListener
*iface
, D3DVALUE
*rollofffactor
)
1236 DS8Primary
*This
= impl_from_IDirectSound3DListener(iface
);
1238 TRACE("(%p)->(%p)\n", iface
, rollofffactor
);
1242 WARN("Invalid parameter %p\n", rollofffactor
);
1243 return DSERR_INVALIDPARAM
;
1246 EnterCriticalSection(&This
->crst
);
1247 *rollofffactor
= This
->rollofffactor
;
1248 LeaveCriticalSection(&This
->crst
);
1253 static HRESULT WINAPI
DS8Primary3D_GetVelocity(IDirectSound3DListener
*iface
, D3DVECTOR
*velocity
)
1255 DS8Primary
*This
= impl_from_IDirectSound3DListener(iface
);
1258 TRACE("(%p)->(%p)\n", iface
, velocity
);
1262 WARN("Invalid parameter %p\n", velocity
);
1263 return DSERR_INVALIDPARAM
;
1266 EnterCriticalSection(&This
->crst
);
1267 setALContext(This
->ctx
);
1269 alGetListenerfv(AL_VELOCITY
, vel
);
1272 velocity
->x
= vel
[0];
1273 velocity
->y
= vel
[1];
1274 velocity
->z
= -vel
[2];
1277 LeaveCriticalSection(&This
->crst
);
1282 static HRESULT WINAPI
DS8Primary3D_SetAllParameters(IDirectSound3DListener
*iface
, const DS3DLISTENER
*listen
, DWORD apply
)
1284 DS8Primary
*This
= impl_from_IDirectSound3DListener(iface
);
1286 TRACE("(%p)->(%p, %u)\n", iface
, listen
, apply
);
1288 if(!listen
|| listen
->dwSize
< sizeof(*listen
))
1290 WARN("Invalid parameter %p %u\n", listen
, listen
? listen
->dwSize
: 0);
1291 return DSERR_INVALIDPARAM
;
1294 if(listen
->flDistanceFactor
> DS3D_MAXDISTANCEFACTOR
||
1295 listen
->flDistanceFactor
< DS3D_MINDISTANCEFACTOR
)
1297 WARN("Invalid distance factor (%f)\n", listen
->flDistanceFactor
);
1298 return DSERR_INVALIDPARAM
;
1301 if(listen
->flDopplerFactor
> DS3D_MAXDOPPLERFACTOR
||
1302 listen
->flDopplerFactor
< DS3D_MINDOPPLERFACTOR
)
1304 WARN("Invalid doppler factor (%f)\n", listen
->flDopplerFactor
);
1305 return DSERR_INVALIDPARAM
;
1308 if(listen
->flRolloffFactor
< DS3D_MINROLLOFFFACTOR
||
1309 listen
->flRolloffFactor
> DS3D_MAXROLLOFFFACTOR
)
1311 WARN("Invalid rolloff factor (%f)\n", listen
->flRolloffFactor
);
1312 return DSERR_INVALIDPARAM
;
1315 EnterCriticalSection(&This
->crst
);
1316 setALContext(This
->ctx
);
1317 IDirectSound3DListener_SetPosition(iface
, listen
->vPosition
.x
, listen
->vPosition
.y
, listen
->vPosition
.z
, apply
);
1318 IDirectSound3DListener_SetVelocity(iface
, listen
->vVelocity
.x
, listen
->vVelocity
.y
, listen
->vVelocity
.z
, apply
);
1319 IDirectSound3DListener_SetOrientation(iface
, listen
->vOrientFront
.x
, listen
->vOrientFront
.y
, listen
->vOrientFront
.z
,
1320 listen
->vOrientTop
.x
, listen
->vOrientTop
.y
, listen
->vOrientTop
.z
, apply
);
1321 IDirectSound3DListener_SetDistanceFactor(iface
, listen
->flDistanceFactor
, apply
);
1322 IDirectSound3DListener_SetRolloffFactor(iface
, listen
->flRolloffFactor
, apply
);
1323 IDirectSound3DListener_SetDopplerFactor(iface
, listen
->flDopplerFactor
, apply
);
1325 LeaveCriticalSection(&This
->crst
);
1330 static HRESULT WINAPI
DS8Primary3D_SetDistanceFactor(IDirectSound3DListener
*iface
, D3DVALUE factor
, DWORD apply
)
1332 DS8Primary
*This
= impl_from_IDirectSound3DListener(iface
);
1334 TRACE("(%p)->(%f, %u)\n", iface
, factor
, apply
);
1336 if(factor
< DS3D_MINDISTANCEFACTOR
||
1337 factor
> DS3D_MAXDISTANCEFACTOR
)
1339 WARN("Invalid parameter %f\n", factor
);
1340 return DSERR_INVALIDPARAM
;
1343 EnterCriticalSection(&This
->crst
);
1344 if(apply
== DS3D_DEFERRED
)
1346 This
->listen
.flDistanceFactor
= factor
;
1347 This
->dirty
.bit
.distancefactor
= 1;
1351 setALContext(This
->ctx
);
1352 alSpeedOfSound(343.3f
/factor
);
1353 if(This
->SupportedExt
[EXT_EFX
])
1354 alListenerf(AL_METERS_PER_UNIT
, factor
);
1358 LeaveCriticalSection(&This
->crst
);
1363 static HRESULT WINAPI
DS8Primary3D_SetDopplerFactor(IDirectSound3DListener
*iface
, D3DVALUE factor
, DWORD apply
)
1365 DS8Primary
*This
= impl_from_IDirectSound3DListener(iface
);
1367 TRACE("(%p)->(%f, %u)\n", iface
, factor
, apply
);
1369 if(factor
< DS3D_MINDOPPLERFACTOR
||
1370 factor
> DS3D_MAXDOPPLERFACTOR
)
1372 WARN("Invalid parameter %f\n", factor
);
1373 return DSERR_INVALIDPARAM
;
1376 EnterCriticalSection(&This
->crst
);
1377 if(apply
== DS3D_DEFERRED
)
1379 This
->listen
.flDopplerFactor
= factor
;
1380 This
->dirty
.bit
.dopplerfactor
= 1;
1384 setALContext(This
->ctx
);
1385 alDopplerFactor(factor
);
1389 LeaveCriticalSection(&This
->crst
);
1394 static HRESULT WINAPI
DS8Primary3D_SetOrientation(IDirectSound3DListener
*iface
, D3DVALUE xFront
, D3DVALUE yFront
, D3DVALUE zFront
, D3DVALUE xTop
, D3DVALUE yTop
, D3DVALUE zTop
, DWORD apply
)
1396 DS8Primary
*This
= impl_from_IDirectSound3DListener(iface
);
1398 TRACE("(%p)->(%f, %f, %f, %f, %f, %f, %u)\n", iface
, xFront
, yFront
, zFront
, xTop
, yTop
, zTop
, apply
);
1400 EnterCriticalSection(&This
->crst
);
1401 if(apply
== DS3D_DEFERRED
)
1403 This
->listen
.vOrientFront
.x
= xFront
;
1404 This
->listen
.vOrientFront
.y
= yFront
;
1405 This
->listen
.vOrientFront
.z
= zFront
;
1406 This
->listen
.vOrientTop
.x
= xTop
;
1407 This
->listen
.vOrientTop
.y
= yTop
;
1408 This
->listen
.vOrientTop
.z
= zTop
;
1409 This
->dirty
.bit
.orientation
= 1;
1413 ALfloat orient
[6] = {
1414 xFront
, yFront
, -zFront
,
1417 setALContext(This
->ctx
);
1418 alListenerfv(AL_ORIENTATION
, orient
);
1422 LeaveCriticalSection(&This
->crst
);
1427 static HRESULT WINAPI
DS8Primary3D_SetPosition(IDirectSound3DListener
*iface
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD apply
)
1429 DS8Primary
*This
= impl_from_IDirectSound3DListener(iface
);
1431 TRACE("(%p)->(%f, %f, %f, %u)\n", iface
, x
, y
, z
, apply
);
1433 EnterCriticalSection(&This
->crst
);
1434 if(apply
== DS3D_DEFERRED
)
1436 This
->listen
.vPosition
.x
= x
;
1437 This
->listen
.vPosition
.y
= y
;
1438 This
->listen
.vPosition
.z
= z
;
1439 This
->dirty
.bit
.pos
= 1;
1443 setALContext(This
->ctx
);
1444 alListener3f(AL_POSITION
, x
, y
, -z
);
1448 LeaveCriticalSection(&This
->crst
);
1453 static HRESULT WINAPI
DS8Primary3D_SetRolloffFactor(IDirectSound3DListener
*iface
, D3DVALUE factor
, DWORD apply
)
1455 DS8Primary
*This
= impl_from_IDirectSound3DListener(iface
);
1457 TRACE("(%p)->(%f, %u)\n", iface
, factor
, apply
);
1459 if(factor
< DS3D_MINROLLOFFFACTOR
||
1460 factor
> DS3D_MAXROLLOFFFACTOR
)
1462 WARN("Invalid parameter %f\n", factor
);
1463 return DSERR_INVALIDPARAM
;
1466 EnterCriticalSection(&This
->crst
);
1467 if(apply
== DS3D_DEFERRED
)
1469 This
->listen
.flRolloffFactor
= factor
;
1470 This
->dirty
.bit
.rollofffactor
= 1;
1476 setALContext(This
->ctx
);
1477 for(i
= 0;i
< This
->nbuffers
;++i
)
1479 if(This
->buffers
[i
]->ds3dmode
!= DS3DMODE_DISABLE
)
1480 alSourcef(This
->buffers
[i
]->source
, AL_ROLLOFF_FACTOR
, factor
);
1485 This
->rollofffactor
= factor
;
1487 LeaveCriticalSection(&This
->crst
);
1492 static HRESULT WINAPI
DS8Primary3D_SetVelocity(IDirectSound3DListener
*iface
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD apply
)
1494 DS8Primary
*This
= impl_from_IDirectSound3DListener(iface
);
1496 TRACE("(%p)->(%f, %f, %f, %u)\n", iface
, x
, y
, z
, apply
);
1498 EnterCriticalSection(&This
->crst
);
1499 if(apply
== DS3D_DEFERRED
)
1501 This
->listen
.vVelocity
.x
= x
;
1502 This
->listen
.vVelocity
.y
= y
;
1503 This
->listen
.vVelocity
.z
= z
;
1504 This
->dirty
.bit
.vel
= 1;
1508 setALContext(This
->ctx
);
1509 alListener3f(AL_VELOCITY
, x
, y
, -z
);
1513 LeaveCriticalSection(&This
->crst
);
1518 static HRESULT WINAPI
DS8Primary3D_CommitDeferredSettings(IDirectSound3DListener
*iface
)
1520 DS8Primary
*This
= impl_from_IDirectSound3DListener(iface
);
1521 const DS3DLISTENER
*listen
= &This
->listen
;
1524 EnterCriticalSection(&This
->crst
);
1525 setALContext(This
->ctx
);
1526 This
->ExtAL
.DeferUpdates();
1528 if(This
->dirty
.bit
.pos
)
1529 alListener3f(AL_POSITION
, listen
->vPosition
.x
, listen
->vPosition
.y
, -listen
->vPosition
.z
);
1530 if(This
->dirty
.bit
.vel
)
1531 alListener3f(AL_VELOCITY
, listen
->vVelocity
.x
, listen
->vVelocity
.y
, -listen
->vVelocity
.z
);
1532 if(This
->dirty
.bit
.orientation
)
1534 ALfloat orient
[6] = {
1535 listen
->vOrientFront
.x
, listen
->vOrientFront
.y
, -listen
->vOrientFront
.z
,
1536 listen
->vOrientTop
.x
, listen
->vOrientTop
.y
, -listen
->vOrientTop
.z
1538 alListenerfv(AL_ORIENTATION
, orient
);
1540 if(This
->dirty
.bit
.distancefactor
)
1542 alSpeedOfSound(343.3f
/listen
->flDistanceFactor
);
1543 if(This
->SupportedExt
[EXT_EFX
])
1544 alListenerf(AL_METERS_PER_UNIT
, listen
->flDistanceFactor
);
1547 if(This
->dirty
.bit
.rollofffactor
)
1549 ALfloat rolloff
= This
->rollofffactor
;
1550 for(i
= 0;i
< This
->nbuffers
;++i
)
1552 DS8Buffer
*buf
= This
->buffers
[i
];
1553 if(buf
->ds3dmode
!= DS3DMODE_DISABLE
)
1554 alSourcef(buf
->source
, AL_ROLLOFF_FACTOR
, rolloff
);
1558 if(This
->dirty
.bit
.dopplerfactor
)
1559 alDopplerFactor(listen
->flDopplerFactor
);
1561 if(This
->dirty
.bit
.effect
)
1562 This
->ExtAL
.AuxiliaryEffectSloti(This
->auxslot
, AL_EFFECTSLOT_EFFECT
, This
->effect
);
1564 /* getALError is here for debugging */
1567 TRACE("Dirty flags was: 0x%02x\n", This
->dirty
.flags
);
1568 This
->dirty
.flags
= 0;
1570 for(i
= 0;i
< This
->nbuffers
;++i
)
1572 DS8Buffer
*buf
= This
->buffers
[i
];
1574 if(!buf
->dirty
.flags
)
1577 if(buf
->dirty
.bit
.pos
)
1578 alSource3f(buf
->source
, AL_POSITION
,
1579 buf
->ds3dbuffer
.vPosition
.x
,
1580 buf
->ds3dbuffer
.vPosition
.y
,
1581 -buf
->ds3dbuffer
.vPosition
.z
);
1582 if(buf
->dirty
.bit
.vel
)
1583 alSource3f(buf
->source
, AL_VELOCITY
,
1584 buf
->ds3dbuffer
.vVelocity
.x
,
1585 buf
->ds3dbuffer
.vVelocity
.y
,
1586 -buf
->ds3dbuffer
.vVelocity
.z
);
1587 if(buf
->dirty
.bit
.cone_angles
)
1589 alSourcei(buf
->source
, AL_CONE_INNER_ANGLE
,
1590 buf
->ds3dbuffer
.dwInsideConeAngle
);
1591 alSourcei(buf
->source
, AL_CONE_OUTER_ANGLE
,
1592 buf
->ds3dbuffer
.dwOutsideConeAngle
);
1594 if(buf
->dirty
.bit
.cone_orient
)
1595 alSource3f(buf
->source
, AL_DIRECTION
,
1596 buf
->ds3dbuffer
.vConeOrientation
.x
,
1597 buf
->ds3dbuffer
.vConeOrientation
.y
,
1598 -buf
->ds3dbuffer
.vConeOrientation
.z
);
1599 if(buf
->dirty
.bit
.cone_outsidevolume
)
1600 alSourcef(buf
->source
, AL_CONE_OUTER_GAIN
,
1601 mB_to_gain(buf
->ds3dbuffer
.lConeOutsideVolume
));
1602 if(buf
->dirty
.bit
.min_distance
)
1603 alSourcef(buf
->source
, AL_REFERENCE_DISTANCE
, buf
->ds3dbuffer
.flMinDistance
);
1604 if(buf
->dirty
.bit
.max_distance
)
1605 alSourcef(buf
->source
, AL_MAX_DISTANCE
, buf
->ds3dbuffer
.flMaxDistance
);
1606 if(buf
->dirty
.bit
.mode
)
1608 buf
->ds3dmode
= buf
->ds3dbuffer
.dwMode
;
1609 alSourcei(buf
->source
, AL_SOURCE_RELATIVE
,
1610 (buf
->ds3dmode
!=DS3DMODE_NORMAL
) ? AL_TRUE
: AL_FALSE
);
1611 alSourcef(buf
->source
, AL_ROLLOFF_FACTOR
,
1612 (buf
->ds3dmode
==DS3DMODE_DISABLE
) ? 0.0f
: This
->rollofffactor
);
1614 buf
->dirty
.flags
= 0;
1618 This
->ExtAL
.ProcessUpdates();
1620 LeaveCriticalSection(&This
->crst
);
1625 static const IDirectSound3DListenerVtbl DS8Primary3D_Vtbl
=
1627 DS8Primary3D_QueryInterface
,
1628 DS8Primary3D_AddRef
,
1629 DS8Primary3D_Release
,
1630 DS8Primary3D_GetAllParameters
,
1631 DS8Primary3D_GetDistanceFactor
,
1632 DS8Primary3D_GetDopplerFactor
,
1633 DS8Primary3D_GetOrientation
,
1634 DS8Primary3D_GetPosition
,
1635 DS8Primary3D_GetRolloffFactor
,
1636 DS8Primary3D_GetVelocity
,
1637 DS8Primary3D_SetAllParameters
,
1638 DS8Primary3D_SetDistanceFactor
,
1639 DS8Primary3D_SetDopplerFactor
,
1640 DS8Primary3D_SetOrientation
,
1641 DS8Primary3D_SetPosition
,
1642 DS8Primary3D_SetRolloffFactor
,
1643 DS8Primary3D_SetVelocity
,
1644 DS8Primary3D_CommitDeferredSettings
1647 /* NOTE: Although the app handles listener properties through secondary buffers,
1648 * we pass the requests to the primary buffer though a propertyset interface.
1649 * These methods are not exposed to the app. */
1650 static inline DS8Primary
*impl_from_IKsPropertySet(IKsPropertySet
*iface
)
1652 return CONTAINING_RECORD(iface
, DS8Primary
, IKsPropertySet_iface
);
1655 static HRESULT WINAPI
DS8PrimaryProp_QueryInterface(IKsPropertySet
*iface
, REFIID riid
, void **ppv
)
1657 DS8Primary
*This
= impl_from_IKsPropertySet(iface
);
1658 return IDirectSoundBuffer_QueryInterface((IDirectSoundBuffer
*)This
, riid
, ppv
);
1661 static ULONG WINAPI
DS8PrimaryProp_AddRef(IKsPropertySet
*iface
)
1663 DS8Primary
*This
= impl_from_IKsPropertySet(iface
);
1666 ret
= InterlockedIncrement(&This
->prop_ref
);
1667 TRACE("new refcount %d\n", ret
);
1672 static ULONG WINAPI
DS8PrimaryProp_Release(IKsPropertySet
*iface
)
1674 DS8Primary
*This
= impl_from_IKsPropertySet(iface
);
1677 ret
= InterlockedDecrement(&This
->prop_ref
);
1678 TRACE("new refcount %d\n", ret
);
1683 static HRESULT WINAPI
DS8PrimaryProp_Get(IKsPropertySet
*iface
,
1684 REFGUID guidPropSet
, ULONG dwPropID
,
1685 LPVOID pInstanceData
, ULONG cbInstanceData
,
1686 LPVOID pPropData
, ULONG cbPropData
,
1689 DS8Primary
*This
= impl_from_IKsPropertySet(iface
);
1690 HRESULT res
= E_PROP_ID_UNSUPPORTED
;
1692 TRACE("(%p)->(%s, %u, %p, %u, %p, %u, %p)\n", iface
, debugstr_guid(guidPropSet
),
1693 dwPropID
, pInstanceData
, cbInstanceData
, pPropData
, cbPropData
, pcbReturned
);
1695 if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX20_ListenerProperties
))
1697 EnterCriticalSection(&This
->crst
);
1699 if(This
->effect
== 0)
1700 res
= E_PROP_ID_UNSUPPORTED
;
1701 else if(dwPropID
== DSPROPERTY_EAXLISTENER_ALLPARAMETERS
)
1703 res
= DSERR_INVALIDPARAM
;
1704 if(cbPropData
>= sizeof(EAXLISTENERPROPERTIES
))
1708 EAXLISTENERPROPERTIES
*props
;
1709 } data
= { pPropData
};
1711 *data
.props
= This
->eax_prop
;
1712 *pcbReturned
= sizeof(EAXLISTENERPROPERTIES
);
1716 else if(dwPropID
== DSPROPERTY_EAXLISTENER_ROOM
)
1718 res
= DSERR_INVALIDPARAM
;
1719 if(cbPropData
>= sizeof(LONG
))
1724 } data
= { pPropData
};
1726 *data
.l
= This
->eax_prop
.lRoom
;
1727 *pcbReturned
= sizeof(LONG
);
1731 else if(dwPropID
== DSPROPERTY_EAXLISTENER_ROOMHF
)
1733 res
= DSERR_INVALIDPARAM
;
1734 if(cbPropData
>= sizeof(LONG
))
1739 } data
= { pPropData
};
1741 *data
.l
= This
->eax_prop
.lRoomHF
;
1742 *pcbReturned
= sizeof(LONG
);
1746 else if(dwPropID
== DSPROPERTY_EAXLISTENER_ROOMROLLOFFFACTOR
)
1748 res
= DSERR_INVALIDPARAM
;
1749 if(cbPropData
>= sizeof(FLOAT
))
1754 } data
= { pPropData
};
1756 *data
.fl
= This
->eax_prop
.flRoomRolloffFactor
;
1757 *pcbReturned
= sizeof(FLOAT
);
1761 else if(dwPropID
== DSPROPERTY_EAXLISTENER_ENVIRONMENT
)
1763 res
= DSERR_INVALIDPARAM
;
1764 if(cbPropData
>= sizeof(DWORD
))
1769 } data
= { pPropData
};
1771 *data
.dw
= This
->eax_prop
.dwEnvironment
;
1772 *pcbReturned
= sizeof(DWORD
);
1776 else if(dwPropID
== DSPROPERTY_EAXLISTENER_ENVIRONMENTSIZE
)
1778 res
= DSERR_INVALIDPARAM
;
1779 if(cbPropData
>= sizeof(FLOAT
))
1784 } data
= { pPropData
};
1786 *data
.fl
= This
->eax_prop
.flEnvironmentSize
;
1787 *pcbReturned
= sizeof(FLOAT
);
1791 else if(dwPropID
== DSPROPERTY_EAXLISTENER_ENVIRONMENTDIFFUSION
)
1793 res
= DSERR_INVALIDPARAM
;
1794 if(cbPropData
>= sizeof(FLOAT
))
1799 } data
= { pPropData
};
1801 *data
.fl
= This
->eax_prop
.flEnvironmentDiffusion
;
1802 *pcbReturned
= sizeof(FLOAT
);
1806 else if(dwPropID
== DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF
)
1808 res
= DSERR_INVALIDPARAM
;
1809 if(cbPropData
>= sizeof(FLOAT
))
1814 } data
= { pPropData
};
1816 *data
.fl
= This
->eax_prop
.flAirAbsorptionHF
;
1817 *pcbReturned
= sizeof(FLOAT
);
1821 else if(dwPropID
== DSPROPERTY_EAXLISTENER_FLAGS
)
1823 res
= DSERR_INVALIDPARAM
;
1824 if(cbPropData
>= sizeof(DWORD
))
1829 } data
= { pPropData
};
1831 *data
.dw
= This
->eax_prop
.dwFlags
;
1832 *pcbReturned
= sizeof(DWORD
);
1837 FIXME("Unhandled propid: 0x%08x\n", dwPropID
);
1839 LeaveCriticalSection(&This
->crst
);
1842 FIXME("Unhandled propset: %s\n", debugstr_guid(guidPropSet
));
1847 static HRESULT WINAPI
DS8PrimaryProp_Set(IKsPropertySet
*iface
,
1848 REFGUID guidPropSet
, ULONG dwPropID
,
1849 LPVOID pInstanceData
, ULONG cbInstanceData
,
1850 LPVOID pPropData
, ULONG cbPropData
)
1852 DS8Primary
*This
= impl_from_IKsPropertySet(iface
);
1853 HRESULT res
= E_PROP_ID_UNSUPPORTED
;
1855 TRACE("(%p)->(%s, %u, %p, %u, %p, %u)\n", iface
, debugstr_guid(guidPropSet
),
1856 dwPropID
, pInstanceData
, cbInstanceData
, pPropData
, cbPropData
);
1858 if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX20_ListenerProperties
))
1860 DWORD propid
= dwPropID
& ~DSPROPERTY_EAXLISTENER_DEFERRED
;
1861 BOOL immediate
= !(dwPropID
&DSPROPERTY_EAXLISTENER_DEFERRED
);
1863 EnterCriticalSection(&This
->crst
);
1864 setALContext(This
->ctx
);
1866 if(This
->effect
== 0)
1867 res
= E_PROP_ID_UNSUPPORTED
;
1868 else if(propid
== DSPROPERTY_EAXLISTENER_ALLPARAMETERS
)
1871 res
= DSERR_INVALIDPARAM
;
1872 if(cbPropData
>= sizeof(EAXLISTENERPROPERTIES
))
1876 const EAXLISTENERPROPERTIES
*props
;
1877 } data
= { pPropData
};
1879 /* FIXME: Need to validate property values... Ignore? Clamp? Error? */
1880 This
->eax_prop
= *data
.props
;
1881 This
->ExtAL
.Effectf(This
->effect
, AL_REVERB_DENSITY
,
1882 (data
.props
->flEnvironmentSize
< 2.0f
) ?
1883 (data
.props
->flEnvironmentSize
- 1.0f
) : 1.0f
);
1884 This
->ExtAL
.Effectf(This
->effect
, AL_REVERB_DIFFUSION
,
1885 data
.props
->flEnvironmentDiffusion
);
1887 This
->ExtAL
.Effectf(This
->effect
, AL_REVERB_GAIN
,
1888 mB_to_gain(data
.props
->lRoom
));
1889 This
->ExtAL
.Effectf(This
->effect
, AL_REVERB_GAINHF
,
1890 mB_to_gain(data
.props
->lRoomHF
));
1892 This
->ExtAL
.Effectf(This
->effect
, AL_REVERB_ROOM_ROLLOFF_FACTOR
,
1893 data
.props
->flRoomRolloffFactor
);
1895 This
->ExtAL
.Effectf(This
->effect
, AL_REVERB_DECAY_TIME
,
1896 data
.props
->flDecayTime
);
1897 This
->ExtAL
.Effectf(This
->effect
, AL_REVERB_DECAY_HFRATIO
,
1898 data
.props
->flDecayHFRatio
);
1900 This
->ExtAL
.Effectf(This
->effect
, AL_REVERB_REFLECTIONS_GAIN
,
1901 mB_to_gain(data
.props
->lReflections
));
1902 This
->ExtAL
.Effectf(This
->effect
, AL_REVERB_REFLECTIONS_DELAY
,
1903 data
.props
->flReflectionsDelay
);
1905 This
->ExtAL
.Effectf(This
->effect
, AL_REVERB_LATE_REVERB_GAIN
,
1906 mB_to_gain(data
.props
->lReverb
));
1907 This
->ExtAL
.Effectf(This
->effect
, AL_REVERB_LATE_REVERB_DELAY
,
1908 data
.props
->flReverbDelay
);
1910 This
->ExtAL
.Effectf(This
->effect
, AL_REVERB_AIR_ABSORPTION_GAINHF
,
1911 mB_to_gain(data
.props
->flAirAbsorptionHF
));
1913 This
->ExtAL
.Effecti(This
->effect
, AL_REVERB_DECAY_HFLIMIT
,
1914 (data
.props
->dwFlags
&EAXLISTENERFLAGS_DECAYHFLIMIT
) ?
1915 AL_TRUE
: AL_FALSE
);
1919 This
->dirty
.bit
.effect
= 1;
1923 else if(propid
== DSPROPERTY_EAXLISTENER_ROOM
)
1925 res
= DSERR_INVALIDPARAM
;
1926 if(cbPropData
>= sizeof(LONG
))
1931 } data
= { pPropData
};
1933 This
->eax_prop
.lRoom
= *data
.l
;
1934 This
->ExtAL
.Effectf(This
->effect
, AL_REVERB_GAIN
,
1935 mB_to_gain(This
->eax_prop
.lRoom
));
1938 This
->dirty
.bit
.effect
= 1;
1942 else if(propid
== DSPROPERTY_EAXLISTENER_ROOMHF
)
1944 res
= DSERR_INVALIDPARAM
;
1945 if(cbPropData
>= sizeof(LONG
))
1950 } data
= { pPropData
};
1952 This
->eax_prop
.lRoomHF
= *data
.l
;
1953 This
->ExtAL
.Effectf(This
->effect
, AL_REVERB_GAINHF
,
1954 mB_to_gain(This
->eax_prop
.lRoomHF
));
1957 This
->dirty
.bit
.effect
= 1;
1961 else if(propid
== DSPROPERTY_EAXLISTENER_ROOMROLLOFFFACTOR
)
1963 res
= DSERR_INVALIDPARAM
;
1964 if(cbPropData
>= sizeof(FLOAT
))
1969 } data
= { pPropData
};
1971 This
->eax_prop
.flRoomRolloffFactor
= *data
.fl
;
1972 This
->ExtAL
.Effectf(This
->effect
, AL_REVERB_ROOM_ROLLOFF_FACTOR
,
1973 This
->eax_prop
.flRoomRolloffFactor
);
1976 This
->dirty
.bit
.effect
= 1;
1980 else if(propid
== DSPROPERTY_EAXLISTENER_ENVIRONMENT
)
1982 res
= DSERR_INVALIDPARAM
;
1983 if(cbPropData
>= sizeof(DWORD
))
1988 } data
= { pPropData
};
1990 if(*data
.dw
< EAX_ENVIRONMENT_COUNT
)
1992 /* Get the environment index's default and pass it down to
1994 propid
= DSPROPERTY_EAXLISTENER_ALLPARAMETERS
;
1995 pPropData
= (void*)&EnvironmentDefaults
[*data
.dw
];
1996 cbPropData
= sizeof(EnvironmentDefaults
[*data
.dw
]);
2001 else if(propid
== DSPROPERTY_EAXLISTENER_ENVIRONMENTSIZE
)
2003 res
= DSERR_INVALIDPARAM
;
2004 if(cbPropData
>= sizeof(FLOAT
))
2009 } data
= { pPropData
};
2011 if(*data
.fl
>= 1.0f
&& *data
.fl
<= 100.0f
)
2013 double scale
= (*data
.fl
)/This
->eax_prop
.flEnvironmentSize
;
2015 This
->eax_prop
.flEnvironmentSize
= *data
.fl
;
2017 if((This
->eax_prop
.dwFlags
&EAXLISTENERFLAGS_DECAYTIMESCALE
))
2019 This
->eax_prop
.flDecayTime
*= scale
;
2020 This
->eax_prop
.flDecayTime
= clampF(This
->eax_prop
.flDecayTime
, 0.1f
, 20.0f
);
2022 if((This
->eax_prop
.dwFlags
&EAXLISTENERFLAGS_REFLECTIONSSCALE
))
2024 This
->eax_prop
.lReflections
+= gain_to_mB(1.0/scale
);
2025 This
->eax_prop
.lReflections
= clampI(This
->eax_prop
.lReflections
, -10000, 1000);
2027 if((This
->eax_prop
.dwFlags
&EAXLISTENERFLAGS_REFLECTIONSDELAYSCALE
))
2029 This
->eax_prop
.flReflectionsDelay
*= scale
;
2030 This
->eax_prop
.flReflectionsDelay
= clampF(This
->eax_prop
.flReflectionsDelay
, 0.0f
, 0.3f
);
2032 if((This
->eax_prop
.dwFlags
&EAXLISTENERFLAGS_REVERBSCALE
))
2034 This
->eax_prop
.lReverb
+= gain_to_mB(1.0/scale
);
2035 This
->eax_prop
.lReverb
= clampI(This
->eax_prop
.lReverb
, -10000, 2000);
2037 if((This
->eax_prop
.dwFlags
&EAXLISTENERFLAGS_REVERBDELAYSCALE
))
2039 This
->eax_prop
.flReverbDelay
*= scale
;
2040 This
->eax_prop
.flReverbDelay
= clampF(This
->eax_prop
.flReverbDelay
, 0.0f
, 0.1f
);
2043 /* Pass the updated environment properties down to ALLPARAMETERS */
2044 propid
= DSPROPERTY_EAXLISTENER_ALLPARAMETERS
;
2045 pPropData
= (void*)&This
->eax_prop
;
2046 cbPropData
= sizeof(This
->eax_prop
);
2051 else if(propid
== DSPROPERTY_EAXLISTENER_ENVIRONMENTDIFFUSION
)
2053 res
= DSERR_INVALIDPARAM
;
2054 if(cbPropData
>= sizeof(FLOAT
))
2059 } data
= { pPropData
};
2061 This
->eax_prop
.flEnvironmentDiffusion
= *data
.fl
;
2062 This
->ExtAL
.Effectf(This
->effect
, AL_REVERB_DIFFUSION
,
2063 This
->eax_prop
.flEnvironmentDiffusion
);
2066 This
->dirty
.bit
.effect
= 1;
2070 else if(propid
== DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF
)
2072 res
= DSERR_INVALIDPARAM
;
2073 if(cbPropData
>= sizeof(FLOAT
))
2078 } data
= { pPropData
};
2080 This
->eax_prop
.flAirAbsorptionHF
= *data
.fl
;
2081 This
->ExtAL
.Effectf(This
->effect
, AL_REVERB_AIR_ABSORPTION_GAINHF
,
2082 mB_to_gain(This
->eax_prop
.flAirAbsorptionHF
));
2085 This
->dirty
.bit
.effect
= 1;
2089 else if(propid
== DSPROPERTY_EAXLISTENER_FLAGS
)
2091 res
= DSERR_INVALIDPARAM
;
2092 if(cbPropData
>= sizeof(DWORD
))
2097 } data
= { pPropData
};
2099 This
->eax_prop
.dwFlags
= *data
.dw
;
2100 This
->ExtAL
.Effecti(This
->effect
, AL_REVERB_DECAY_HFLIMIT
,
2101 (This
->eax_prop
.dwFlags
&EAXLISTENERFLAGS_DECAYHFLIMIT
) ?
2102 AL_TRUE
: AL_FALSE
);
2105 This
->dirty
.bit
.effect
= 1;
2109 else if(propid
!= 0)
2110 FIXME("Unhandled propid: 0x%08x\n", propid
);
2112 if(res
== DS_OK
&& immediate
)
2113 IDirectSound3DListener_CommitDeferredSettings(&This
->IDirectSound3DListener_iface
);
2116 LeaveCriticalSection(&This
->crst
);
2119 FIXME("Unhandled propset: %s\n", debugstr_guid(guidPropSet
));
2124 static HRESULT WINAPI
DS8PrimaryProp_QuerySupport(IKsPropertySet
*iface
,
2125 REFGUID guidPropSet
, ULONG dwPropID
,
2126 PULONG pTypeSupport
)
2128 DS8Primary
*This
= impl_from_IKsPropertySet(iface
);
2129 HRESULT res
= E_PROP_ID_UNSUPPORTED
;
2131 TRACE("(%p)->(%s, %u, %p)\n", iface
, debugstr_guid(guidPropSet
), dwPropID
, pTypeSupport
);
2133 if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX20_ListenerProperties
))
2135 EnterCriticalSection(&This
->crst
);
2137 if(This
->effect
== 0)
2138 res
= E_PROP_ID_UNSUPPORTED
;
2139 else if(dwPropID
== DSPROPERTY_EAXLISTENER_ALLPARAMETERS
||
2140 dwPropID
== DSPROPERTY_EAXLISTENER_ROOM
||
2141 dwPropID
== DSPROPERTY_EAXLISTENER_ROOMHF
||
2142 dwPropID
== DSPROPERTY_EAXLISTENER_ROOMROLLOFFFACTOR
||
2143 dwPropID
== DSPROPERTY_EAXLISTENER_ENVIRONMENT
||
2144 dwPropID
== DSPROPERTY_EAXLISTENER_ENVIRONMENTSIZE
||
2145 dwPropID
== DSPROPERTY_EAXLISTENER_ENVIRONMENTDIFFUSION
||
2146 dwPropID
== DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF
||
2147 dwPropID
== DSPROPERTY_EAXLISTENER_FLAGS
)
2149 *pTypeSupport
= KSPROPERTY_SUPPORT_GET
|KSPROPERTY_SUPPORT_SET
;
2153 FIXME("Unhandled propid: 0x%08x\n", dwPropID
);
2155 LeaveCriticalSection(&This
->crst
);
2158 FIXME("Unhandled propset: %s\n", debugstr_guid(guidPropSet
));
2163 static const IKsPropertySetVtbl DS8PrimaryProp_Vtbl
=
2165 DS8PrimaryProp_QueryInterface
,
2166 DS8PrimaryProp_AddRef
,
2167 DS8PrimaryProp_Release
,
2170 DS8PrimaryProp_QuerySupport