Remove some unnecessary locks
[dsound-openal.git] / primary.c
blob91432b310fcdb03ff537cfb036d3d157d22d979e
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
23 #include <stdarg.h>
25 #ifdef __WINESRC__
27 #define COBJMACROS
28 #define NONAMELESSSTRUCT
29 #define NONAMELESSUNION
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winuser.h"
33 #include "winnls.h"
34 #include "winreg.h"
35 #include "vfwmsgs.h"
36 #include "mmsystem.h"
37 #include "winternl.h"
38 #include "mmddk.h"
39 #include "wine/debug.h"
40 #include "dsound.h"
42 #include "dsound_private.h"
44 #include "mmreg.h"
45 #include "ks.h"
46 #include "ksmedia.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
50 #else
52 #define WINVER 0x0600
53 #include <windows.h>
54 #include <dsound.h>
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)
63 #endif
65 #endif
67 static const IDirectSoundBufferVtbl DS8Primary_Vtbl;
68 static const IDirectSound3DListenerVtbl DS8Primary3D_Vtbl;
69 static const IKsPropertySetVtbl DS8PrimaryProp_Vtbl;
72 static void AL_APIENTRY wrap_DeferUpdates(void)
73 { alcSuspendContext(alcGetCurrentContext()); }
74 static void AL_APIENTRY wrap_ProcessUpdates(void)
75 { alcProcessContext(alcGetCurrentContext()); }
78 static void trigger_elapsed_notifies(DS8Buffer *buf, DWORD lastpos, DWORD curpos)
80 DWORD i;
81 for(i = 0; i < buf->nnotify; ++i)
83 DSBPOSITIONNOTIFY *not = &buf->notify[i];
84 HANDLE event = not->hEventNotify;
85 DWORD ofs = not->dwOffset;
87 if(ofs == (DWORD)DSBPN_OFFSETSTOP)
88 continue;
90 /* Wraparound case */
91 if(curpos < lastpos)
93 if(ofs < curpos || ofs >= lastpos)
94 SetEvent(event);
95 continue;
98 /* Normal case */
99 if(ofs >= lastpos && ofs < curpos)
100 SetEvent(event);
104 static void trigger_stop_notifies(DS8Buffer *buf)
106 DWORD i;
107 for(i = 0; i < buf->nnotify; ++i)
109 DSBPOSITIONNOTIFY *not = &buf->notify[i];
110 if(not->dwOffset == (DWORD)DSBPN_OFFSETSTOP)
111 SetEvent(not->hEventNotify);
115 static DWORD CALLBACK ThreadProc(void *dwUser)
117 DS8Primary *prim = (DS8Primary*)dwUser;
118 DWORD i;
119 MSG msg;
121 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
123 while(GetMessageA(&msg, NULL, 0, 0))
125 if(msg.message != WM_USER)
126 continue;
128 EnterCriticalSection(prim->crst);
129 setALContext(prim->ctx);
131 /* OpenAL doesn't support our lovely buffer extensions
132 * so just make sure enough buffers are queued
134 if(!prim->SupportedExt[SOFT_BUFFER_SAMPLES] &&
135 !prim->SupportedExt[SOFT_BUFFER_SUB_DATA] &&
136 !prim->SupportedExt[EXT_STATIC_BUFFER])
138 for(i = 0;i < prim->nbuffers;++i)
140 DS8Buffer *buf = prim->buffers[i];
141 ALint done = 0, queued = QBUFFERS, state = AL_PLAYING;
142 ALuint which, ofs;
144 if(buf->buffer->numsegs == 1 || !buf->isplaying)
145 continue;
147 alGetSourcei(buf->source, AL_SOURCE_STATE, &state);
148 alGetSourcei(buf->source, AL_BUFFERS_QUEUED, &queued);
149 alGetSourcei(buf->source, AL_BUFFERS_PROCESSED, &done);
151 queued -= done;
152 while(done--)
153 alSourceUnqueueBuffers(buf->source, 1, &which);
154 while(queued < QBUFFERS)
156 which = buf->buffer->buffers[buf->curidx];
157 ofs = buf->curidx*buf->buffer->segsize;
158 if(buf->curidx < buf->buffer->numsegs-1)
159 alBufferData(which, buf->buffer->buf_format,
160 buf->buffer->data + ofs, buf->buffer->segsize,
161 buf->buffer->format.Format.nSamplesPerSec);
162 else
163 alBufferData(which, buf->buffer->buf_format,
164 buf->buffer->data + ofs, buf->buffer->lastsegsize,
165 buf->buffer->format.Format.nSamplesPerSec);
167 alSourceQueueBuffers(buf->source, 1, &which);
168 buf->curidx = (buf->curidx+1)%buf->buffer->numsegs;
169 queued++;
171 if(!buf->curidx && !buf->islooping)
173 buf->isplaying = FALSE;
174 break;
177 if(state != AL_PLAYING)
179 if(!queued)
181 IDirectSoundBuffer8_Stop(&buf->IDirectSoundBuffer8_iface);
182 continue;
184 alSourcePlay(buf->source);
187 checkALError();
190 for(i = 0;i < prim->nnotifies;)
192 DS8Buffer *buf = prim->notifies[i];
193 IDirectSoundBuffer8 *dsb = &buf->IDirectSoundBuffer8_iface;
194 DWORD status=0, curpos=buf->lastpos;
196 IDirectSoundBuffer8_GetStatus(dsb, &status);
197 IDirectSoundBuffer8_GetCurrentPosition(dsb, &curpos, NULL);
198 if(buf->lastpos != curpos)
200 trigger_elapsed_notifies(buf, buf->lastpos, curpos);
201 buf->lastpos = curpos;
203 if(!(status&DSBSTATUS_PLAYING))
205 /* Remove this buffer from list and put another at the
206 * current position; don't increment i
208 trigger_stop_notifies(buf);
209 prim->notifies[i] = prim->notifies[--prim->nnotifies];
210 continue;
212 i++;
214 popALContext();
215 LeaveCriticalSection(prim->crst);
217 return 0;
221 HRESULT DS8Primary_PreInit(DS8Primary *This, DS8Impl *parent)
223 DS3DLISTENER *listener;
224 WAVEFORMATEX *wfx;
225 HRESULT hr;
227 This->IDirectSoundBuffer_iface.lpVtbl = (IDirectSoundBufferVtbl*)&DS8Primary_Vtbl;
228 This->IDirectSound3DListener_iface.lpVtbl = (IDirectSound3DListenerVtbl*)&DS8Primary3D_Vtbl;
229 This->IKsPropertySet_iface.lpVtbl = (IKsPropertySetVtbl*)&DS8PrimaryProp_Vtbl;
231 This->parent = parent;
232 This->crst = &parent->share->crst;
233 This->ctx = parent->share->ctx;
234 This->SupportedExt = parent->share->SupportedExt;
235 This->ExtAL = &parent->share->ExtAL;
236 This->sources = parent->share->sources;
237 This->auxslot = parent->share->auxslot;
239 /* Allocate enough for a WAVEFORMATEXTENSIBLE */
240 wfx = &This->format.Format;
242 wfx->wFormatTag = WAVE_FORMAT_PCM;
243 wfx->nChannels = 2;
244 wfx->wBitsPerSample = 8;
245 wfx->nSamplesPerSec = 22050;
246 wfx->nBlockAlign = wfx->wBitsPerSample * wfx->nChannels / 8;
247 wfx->nAvgBytesPerSec = wfx->nSamplesPerSec * wfx->nBlockAlign;
248 wfx->cbSize = 0;
250 This->stopped = TRUE;
252 /* Apparently primary buffer size is always 32k,
253 * tested on windows with 192k 24 bits sound @ 6 channels
254 * where it will run out in 60 ms and it isn't pointer aligned
256 This->buf_size = 32768;
258 if(This->SupportedExt[SOFT_DEFERRED_UPDATES])
260 This->DeferUpdates = This->ExtAL->DeferUpdatesSOFT;
261 This->ProcessUpdates = This->ExtAL->ProcessUpdatesSOFT;
263 else
265 This->DeferUpdates = wrap_DeferUpdates;
266 This->ProcessUpdates = wrap_ProcessUpdates;
269 This->eax_prop = EnvironmentDefaults[EAX_ENVIRONMENT_GENERIC];
270 if(This->SupportedExt[EXT_EFX] && This->auxslot != 0)
272 ALint revid = alGetEnumValue("AL_EFFECT_REVERB");
273 if(revid != 0 && revid != -1)
275 This->ExtAL->GenEffects(1, &This->effect);
276 This->ExtAL->Effecti(This->effect, AL_EFFECT_TYPE, AL_EFFECT_REVERB);
277 checkALError();
281 /* Make sure DS3DListener defaults are applied to OpenAL */
282 listener = &This->listen;
283 listener->dwSize = sizeof(*listener);
284 listener->vPosition.x = 0.0;
285 listener->vPosition.y = 0.0;
286 listener->vPosition.z = 0.0;
287 listener->vVelocity.x = 0.0;
288 listener->vVelocity.y = 0.0;
289 listener->vVelocity.z = 0.0;
290 listener->vOrientFront.x = 0.0;
291 listener->vOrientFront.y = 0.0;
292 listener->vOrientFront.z = 1.0;
293 listener->vOrientTop.x = 0.0;
294 listener->vOrientTop.y = 1.0;
295 listener->vOrientTop.z = 0.0;
296 listener->flDistanceFactor = DS3D_DEFAULTDISTANCEFACTOR;
297 listener->flRolloffFactor = DS3D_DEFAULTROLLOFFFACTOR;
298 listener->flDopplerFactor = DS3D_DEFAULTDOPPLERFACTOR;
299 hr = IDirectSound3DListener_SetAllParameters(&This->IDirectSound3DListener_iface, listener, DS3D_IMMEDIATE);
300 if(FAILED(hr))
301 ERR("Could not set 3d parameters: %08"LONGFMT"x\n", hr);
303 This->sizenotifies = This->sizebuffers = parent->share->max_sources;
305 hr = DSERR_OUTOFMEMORY;
306 This->buffers = HeapAlloc(GetProcessHeap(), 0, This->sizebuffers*sizeof(*This->buffers));
307 This->notifies = HeapAlloc(GetProcessHeap(), 0, This->sizenotifies*sizeof(*This->notifies));
308 if(!This->buffers || !This->notifies)
309 goto fail;
311 This->thread_hdl = CreateThread(NULL, 0, ThreadProc, This, 0, &This->thread_id);
312 if(This->thread_hdl == NULL)
313 goto fail;
315 return S_OK;
317 fail:
318 DS8Primary_Clear(This);
319 return hr;
322 void DS8Primary_Clear(DS8Primary *This)
324 TRACE("Clearing primary %p\n", This);
326 if(!This->parent)
327 return;
329 if(This->timer_id)
331 timeKillEvent(This->timer_id);
332 timeEndPeriod(This->timer_res);
333 TRACE("Killed timer\n");
335 if(This->thread_hdl)
337 PostThreadMessageA(This->thread_id, WM_QUIT, 0, 0);
338 if(WaitForSingleObject(This->thread_hdl, 1000) != WAIT_OBJECT_0)
339 ERR("Thread wait timed out");
340 CloseHandle(This->thread_hdl);
343 setALContext(This->ctx);
344 if(This->effect)
345 This->ExtAL->DeleteEffects(1, &This->effect);
346 popALContext();
347 while(This->nbuffers--)
348 DS8Buffer_Destroy(This->buffers[This->nbuffers]);
350 HeapFree(GetProcessHeap(), 0, This->notifies);
351 HeapFree(GetProcessHeap(), 0, This->buffers);
352 memset(This, 0, sizeof(*This));
355 static inline DS8Primary *impl_from_IDirectSoundBuffer(IDirectSoundBuffer *iface)
357 return CONTAINING_RECORD(iface, DS8Primary, IDirectSoundBuffer_iface);
360 static HRESULT WINAPI DS8Primary_QueryInterface(IDirectSoundBuffer *iface, REFIID riid, LPVOID *ppv)
362 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
364 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
366 *ppv = NULL;
367 if(IsEqualIID(riid, &IID_IUnknown) ||
368 IsEqualIID(riid, &IID_IDirectSoundBuffer))
369 *ppv = &This->IDirectSoundBuffer_iface;
370 else if(IsEqualIID(riid, &IID_IDirectSound3DListener))
372 if((This->flags&DSBCAPS_CTRL3D))
373 *ppv = &This->IDirectSound3DListener_iface;
375 else
376 FIXME("Unhandled GUID: %s\n", debugstr_guid(riid));
378 if(*ppv)
380 IUnknown_AddRef((IUnknown*)*ppv);
381 return S_OK;
384 return E_NOINTERFACE;
387 static ULONG WINAPI DS8Primary_AddRef(IDirectSoundBuffer *iface)
389 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
390 LONG ret;
392 ret = InterlockedIncrement(&This->ref);
393 if(ret == 1) This->flags = 0;
395 return ret;
398 static ULONG WINAPI DS8Primary_Release(IDirectSoundBuffer *iface)
400 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
401 LONG ret;
403 ret = InterlockedDecrement(&This->ref);
405 return ret;
408 static HRESULT WINAPI DS8Primary_GetCaps(IDirectSoundBuffer *iface, DSBCAPS *caps)
410 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
412 TRACE("(%p)->(%p)\n", iface, caps);
414 if(!caps || caps->dwSize < sizeof(*caps))
416 WARN("Invalid DSBCAPS (%p, %"LONGFMT"u)\n", caps, caps ? caps->dwSize : 0);
417 return DSERR_INVALIDPARAM;
420 EnterCriticalSection(This->crst);
421 caps->dwFlags = This->flags;
422 caps->dwBufferBytes = This->buf_size;
423 caps->dwUnlockTransferRate = 0;
424 caps->dwPlayCpuOverhead = 0;
425 LeaveCriticalSection(This->crst);
427 return DS_OK;
430 static HRESULT WINAPI DS8Primary_GetCurrentPosition(IDirectSoundBuffer *iface, DWORD *playpos, DWORD *curpos)
432 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
433 HRESULT hr = DSERR_PRIOLEVELNEEDED;
435 EnterCriticalSection(This->crst);
436 if(This->write_emu)
437 hr = IDirectSoundBuffer8_GetCurrentPosition(This->write_emu, playpos, curpos);
438 LeaveCriticalSection(This->crst);
440 return hr;
443 static HRESULT WINAPI DS8Primary_GetFormat(IDirectSoundBuffer *iface, WAVEFORMATEX *wfx, DWORD allocated, DWORD *written)
445 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
446 HRESULT hr = S_OK;
447 UINT size;
449 if(!wfx && !written)
451 WARN("Cannot report format or format size\n");
452 return DSERR_INVALIDPARAM;
455 EnterCriticalSection(This->crst);
456 size = sizeof(This->format.Format) + This->format.Format.cbSize;
457 if(written)
458 *written = size;
459 if(wfx)
461 if(allocated < size)
462 hr = DSERR_INVALIDPARAM;
463 else
464 memcpy(wfx, &This->format.Format, size);
466 LeaveCriticalSection(This->crst);
468 return hr;
471 static HRESULT WINAPI DS8Primary_GetVolume(IDirectSoundBuffer *iface, LONG *volume)
473 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
474 HRESULT hr = S_OK;
476 TRACE("(%p)->(%p)\n", iface, volume);
478 if(!volume)
479 return DSERR_INVALIDPARAM;
481 EnterCriticalSection(This->crst);
482 if(!(This->flags & DSBCAPS_CTRLVOLUME))
483 hr = DSERR_CONTROLUNAVAIL;
484 else
486 ALfloat gain;
488 setALContext(This->ctx);
489 alGetListenerf(AL_GAIN, &gain);
490 checkALError();
491 popALContext();
493 *volume = clampI(gain_to_mB(gain), DSBVOLUME_MIN, DSBVOLUME_MAX);
495 LeaveCriticalSection(This->crst);
497 return hr;
500 static HRESULT WINAPI DS8Primary_GetPan(IDirectSoundBuffer *iface, LONG *pan)
502 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
503 HRESULT hr = S_OK;
505 WARN("(%p)->(%p): semi-stub\n", iface, pan);
507 if(!pan)
508 return DSERR_INVALIDPARAM;
510 EnterCriticalSection(This->crst);
511 if(This->write_emu)
512 hr = IDirectSoundBuffer8_GetPan(This->write_emu, pan);
513 else if(!(This->flags & DSBCAPS_CTRLPAN))
514 hr = DSERR_CONTROLUNAVAIL;
515 else
516 *pan = 0;
517 LeaveCriticalSection(This->crst);
519 return hr;
522 static HRESULT WINAPI DS8Primary_GetFrequency(IDirectSoundBuffer *iface, DWORD *freq)
524 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
525 HRESULT hr = S_OK;
527 WARN("(%p)->(%p): semi-stub\n", iface, freq);
529 if(!freq)
530 return DSERR_INVALIDPARAM;
532 EnterCriticalSection(This->crst);
533 if(!(This->flags & DSBCAPS_CTRLFREQUENCY))
534 hr = DSERR_CONTROLUNAVAIL;
535 else
536 *freq = This->format.Format.nSamplesPerSec;
537 LeaveCriticalSection(This->crst);
539 return hr;
542 static HRESULT WINAPI DS8Primary_GetStatus(IDirectSoundBuffer *iface, DWORD *status)
544 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
546 TRACE("(%p)->(%p)\n", iface, status);
548 if(!status)
549 return DSERR_INVALIDPARAM;
551 EnterCriticalSection(This->crst);
553 *status = DSBSTATUS_PLAYING|DSBSTATUS_LOOPING;
554 if((This->flags&DSBCAPS_LOCDEFER))
555 *status |= DSBSTATUS_LOCHARDWARE;
557 if(This->stopped)
559 DWORD i, state;
560 HRESULT hr;
562 for(i = 0;i < This->nbuffers;++i)
564 hr = IDirectSoundBuffer8_GetStatus(&This->buffers[i]->IDirectSoundBuffer8_iface, &state);
565 if(SUCCEEDED(hr) && (state&DSBSTATUS_PLAYING))
566 break;
568 if(i == This->nbuffers)
570 /* Primary stopped and no buffers playing.. */
571 *status = 0;
575 LeaveCriticalSection(This->crst);
577 return S_OK;
580 static HRESULT WINAPI DS8Primary_Initialize(IDirectSoundBuffer *iface, IDirectSound *ds, const DSBUFFERDESC *desc)
582 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
583 HRESULT hr = S_OK;
585 TRACE("(%p)->(%p, %p)\n", iface, ds, desc);
587 if(!desc || desc->lpwfxFormat || desc->dwBufferBytes)
589 WARN("Bad DSBDESC for primary buffer\n");
590 return DSERR_INVALIDPARAM;
592 if((desc->dwFlags&DSBCAPS_CTRLFX) ||
593 (desc->dwFlags&DSBCAPS_CTRLPOSITIONNOTIFY) ||
594 (desc->dwFlags&DSBCAPS_LOCSOFTWARE))
596 WARN("Bad dwFlags %08"LONGFMT"x\n", desc->dwFlags);
597 return DSERR_INVALIDPARAM;
600 EnterCriticalSection(This->crst);
601 /* Should be 0 if not initialized */
602 if(This->flags)
604 hr = DSERR_ALREADYINITIALIZED;
605 goto out;
608 if(This->parent->prio_level == DSSCL_WRITEPRIMARY)
610 DSBUFFERDESC emudesc;
611 DS8Buffer *emu;
613 if(This->write_emu)
615 ERR("There shouldn't be a write_emu!\n");
616 IDirectSoundBuffer8_Release(This->write_emu);
617 This->write_emu = NULL;
620 memset(&emudesc, 0, sizeof(emudesc));
621 emudesc.dwSize = sizeof(emudesc);
622 emudesc.dwFlags = DSBCAPS_LOCHARDWARE | (desc->dwFlags&DSBCAPS_CTRLPAN);
623 /* Dont play last incomplete sample */
624 emudesc.dwBufferBytes = This->buf_size - (This->buf_size%This->format.Format.nBlockAlign);
625 emudesc.lpwfxFormat = &This->format.Format;
627 hr = DS8Buffer_Create(&emu, This, NULL);
628 if(SUCCEEDED(hr))
630 This->write_emu = &emu->IDirectSoundBuffer8_iface;
631 hr = IDirectSoundBuffer8_Initialize(This->write_emu, ds, &emudesc);
632 if(FAILED(hr))
634 IDirectSoundBuffer8_Release(This->write_emu);
635 This->write_emu = NULL;
640 if(SUCCEEDED(hr))
641 This->flags = desc->dwFlags | DSBCAPS_LOCHARDWARE;
642 out:
643 LeaveCriticalSection(This->crst);
644 return hr;
647 static HRESULT WINAPI DS8Primary_Lock(IDirectSoundBuffer *iface, DWORD ofs, DWORD bytes, void **ptr1, DWORD *len1, void **ptr2, DWORD *len2, DWORD flags)
649 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
650 HRESULT hr = DSERR_PRIOLEVELNEEDED;
652 TRACE("(%p)->(%"LONGFMT"u, %"LONGFMT"u, %p, %p, %p, %p, %"LONGFMT"u)\n", iface, ofs, bytes, ptr1, len1, ptr2, len2, flags);
654 EnterCriticalSection(This->crst);
655 if(This->write_emu)
656 hr = IDirectSoundBuffer8_Lock(This->write_emu, ofs, bytes, ptr1, len1, ptr2, len2, flags);
657 LeaveCriticalSection(This->crst);
659 return hr;
662 static HRESULT WINAPI DS8Primary_Play(IDirectSoundBuffer *iface, DWORD res1, DWORD res2, DWORD flags)
664 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
665 HRESULT hr;
667 TRACE("(%p)->(%"LONGFMT"u, %"LONGFMT"u, %"LONGFMT"u)\n", iface, res1, res2, flags);
669 if(!(flags & DSBPLAY_LOOPING))
671 WARN("Flags (%08"LONGFMT"x) not set to DSBPLAY_LOOPING\n", flags);
672 return DSERR_INVALIDPARAM;
675 EnterCriticalSection(This->crst);
676 hr = S_OK;
677 if(This->write_emu)
678 hr = IDirectSoundBuffer8_Play(This->write_emu, res1, res2, flags);
679 if(SUCCEEDED(hr))
680 This->stopped = FALSE;
681 LeaveCriticalSection(This->crst);
683 return hr;
686 static HRESULT WINAPI DS8Primary_SetCurrentPosition(IDirectSoundBuffer *iface, DWORD pos)
688 WARN("(%p)->(%"LONGFMT"u)\n", iface, pos);
689 return DSERR_INVALIDCALL;
692 /* Just assume the format is crap, and clean up the damage */
693 static void copy_waveformat(WAVEFORMATEX *wfx, const WAVEFORMATEX *from)
695 if(from->wFormatTag == WAVE_FORMAT_PCM)
697 wfx->cbSize = 0;
698 if(from->wBitsPerSample == 8 ||
699 from->wBitsPerSample == 16 ||
700 from->wBitsPerSample == 24 ||
701 from->wBitsPerSample == 32)
702 wfx->wBitsPerSample = from->wBitsPerSample;
704 else if(from->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
706 WAVEFORMATEXTENSIBLE *wfe = (WAVEFORMATEXTENSIBLE*)wfx;
707 const WAVEFORMATEXTENSIBLE *fromx = (const WAVEFORMATEXTENSIBLE*)from;
708 DWORD size = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
710 /* Fail silently.. */
711 if(from->cbSize < size)
712 return;
713 if(!fromx->Samples.wValidBitsPerSample &&
714 !fromx->Format.wBitsPerSample)
715 return;
717 if(!IsEqualGUID(&wfe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM) &&
718 !IsEqualGUID(&wfe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT))
720 ERR("Unhandled extensible format: %s\n", debugstr_guid(&wfe->SubFormat));
721 return;
724 wfe->Format.wBitsPerSample = from->wBitsPerSample;
725 wfe->Samples.wValidBitsPerSample = fromx->Samples.wValidBitsPerSample;
726 if(!wfe->Samples.wValidBitsPerSample)
727 wfe->Samples.wValidBitsPerSample = wfe->Format.wBitsPerSample;
728 wfe->Format.cbSize = size;
729 wfe->dwChannelMask = fromx->dwChannelMask;
730 wfe->SubFormat = fromx->SubFormat;
732 else
734 ERR("Unhandled format tag %04x\n", from->wFormatTag);
735 return;
738 if(from->nChannels)
739 wfx->nChannels = from->nChannels;
740 wfx->wFormatTag = from->wFormatTag;
741 if(from->nSamplesPerSec >= DSBFREQUENCY_MIN &&
742 from->nSamplesPerSec <= DSBFREQUENCY_MAX)
743 wfx->nSamplesPerSec = from->nSamplesPerSec;
744 wfx->nBlockAlign = wfx->wBitsPerSample * wfx->nChannels / 8;
745 wfx->nAvgBytesPerSec = wfx->nSamplesPerSec * wfx->nBlockAlign;
748 static HRESULT WINAPI DS8Primary_SetFormat(IDirectSoundBuffer *iface, const WAVEFORMATEX *wfx)
750 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
751 HRESULT hr = S_OK;
752 ALCint freq;
754 TRACE("(%p)->(%p)\n", iface, wfx);
756 if(!wfx)
758 WARN("Missing format\n");
759 return DSERR_INVALIDPARAM;
762 EnterCriticalSection(This->crst);
764 if(This->parent->prio_level < DSSCL_PRIORITY)
766 hr = DSERR_PRIOLEVELNEEDED;
767 goto out;
770 TRACE("Requested primary format:\n"
771 " FormatTag = %04x\n"
772 " Channels = %u\n"
773 " SamplesPerSec = %"LONGFMT"u\n"
774 " AvgBytesPerSec = %"LONGFMT"u\n"
775 " BlockAlign = %u\n"
776 " BitsPerSample = %u\n",
777 wfx->wFormatTag, wfx->nChannels,
778 wfx->nSamplesPerSec, wfx->nAvgBytesPerSec,
779 wfx->nBlockAlign, wfx->wBitsPerSample);
781 copy_waveformat(&This->format.Format, wfx);
783 freq = This->format.Format.nSamplesPerSec;
784 alcGetIntegerv(This->parent->device, ALC_FREQUENCY, 1, &freq);
785 checkALCError(This->parent->device);
787 This->format.Format.nSamplesPerSec = freq;
788 This->format.Format.nAvgBytesPerSec = This->format.Format.nBlockAlign *
789 This->format.Format.nSamplesPerSec;
791 if(This->write_emu)
793 DS8Buffer *buf;
794 DSBUFFERDESC desc;
796 memset(&desc, 0, sizeof(desc));
797 desc.dwSize = sizeof(desc);
798 desc.dwFlags = DSBCAPS_LOCHARDWARE|DSBCAPS_CTRLPAN;
799 desc.dwBufferBytes = This->buf_size - (This->buf_size % This->format.Format.nBlockAlign);
800 desc.lpwfxFormat = &This->format.Format;
802 hr = DS8Buffer_Create(&buf, This, NULL);
803 if(FAILED(hr))
804 goto out;
806 hr = IDirectSoundBuffer8_Initialize(&buf->IDirectSoundBuffer8_iface, &This->parent->IDirectSound_iface, &desc);
807 if(FAILED(hr))
808 DS8Buffer_Destroy(buf);
809 else
811 IDirectSoundBuffer8_Release(This->write_emu);
812 This->write_emu = &buf->IDirectSoundBuffer8_iface;
816 out:
817 LeaveCriticalSection(This->crst);
818 return hr;
821 static HRESULT WINAPI DS8Primary_SetVolume(IDirectSoundBuffer *iface, LONG vol)
823 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
824 HRESULT hr = S_OK;
826 TRACE("(%p)->(%"LONGFMT"d)\n", iface, vol);
828 if(vol > DSBVOLUME_MAX || vol < DSBVOLUME_MIN)
830 WARN("Invalid volume (%"LONGFMT"d)\n", vol);
831 return DSERR_INVALIDPARAM;
834 EnterCriticalSection(This->crst);
835 if(!(This->flags&DSBCAPS_CTRLVOLUME))
836 hr = DSERR_CONTROLUNAVAIL;
837 if(SUCCEEDED(hr))
839 setALContext(This->ctx);
840 alListenerf(AL_GAIN, mB_to_gain(vol));
841 popALContext();
843 LeaveCriticalSection(This->crst);
845 return hr;
848 static HRESULT WINAPI DS8Primary_SetPan(IDirectSoundBuffer *iface, LONG pan)
850 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
851 HRESULT hr;
853 TRACE("(%p)->(%"LONGFMT"d)\n", iface, pan);
855 if(pan > DSBPAN_RIGHT || pan < DSBPAN_LEFT)
857 WARN("invalid parameter: pan = %"LONGFMT"d\n", pan);
858 return DSERR_INVALIDPARAM;
861 EnterCriticalSection(This->crst);
862 if(!(This->flags&DSBCAPS_CTRLPAN))
864 WARN("control unavailable\n");
865 hr = DSERR_CONTROLUNAVAIL;
867 else if(This->write_emu)
868 hr = IDirectSoundBuffer8_SetPan(This->write_emu, pan);
869 else
871 FIXME("Not supported\n");
872 hr = E_NOTIMPL;
874 LeaveCriticalSection(This->crst);
876 return hr;
879 static HRESULT WINAPI DS8Primary_SetFrequency(IDirectSoundBuffer *iface, DWORD freq)
881 WARN("(%p)->(%"LONGFMT"u)\n", iface, freq);
882 return DSERR_CONTROLUNAVAIL;
885 static HRESULT WINAPI DS8Primary_Stop(IDirectSoundBuffer *iface)
887 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
888 HRESULT hr = S_OK;
890 TRACE("(%p)->()\n", iface);
892 EnterCriticalSection(This->crst);
893 if(This->write_emu)
894 hr = IDirectSoundBuffer8_Stop(This->write_emu);
895 if(SUCCEEDED(hr))
896 This->stopped = TRUE;
897 LeaveCriticalSection(This->crst);
899 return hr;
902 static HRESULT WINAPI DS8Primary_Unlock(IDirectSoundBuffer *iface, void *ptr1, DWORD len1, void *ptr2, DWORD len2)
904 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
905 HRESULT hr = DSERR_INVALIDCALL;
907 TRACE("(%p)->(%p, %"LONGFMT"u, %p, %"LONGFMT"u)\n", iface, ptr1, len1, ptr2, len2);
909 EnterCriticalSection(This->crst);
910 if(This->write_emu)
911 hr = IDirectSoundBuffer8_Unlock(This->write_emu, ptr1, len1, ptr2, len2);
912 LeaveCriticalSection(This->crst);
914 return hr;
917 static HRESULT WINAPI DS8Primary_Restore(IDirectSoundBuffer *iface)
919 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
920 HRESULT hr = S_OK;
922 TRACE("(%p)->()\n", iface);
924 EnterCriticalSection(This->crst);
925 if(This->write_emu)
926 hr = IDirectSoundBuffer8_Restore(This->write_emu);
927 LeaveCriticalSection(This->crst);
929 return hr;
932 static const IDirectSoundBufferVtbl DS8Primary_Vtbl =
934 DS8Primary_QueryInterface,
935 DS8Primary_AddRef,
936 DS8Primary_Release,
937 DS8Primary_GetCaps,
938 DS8Primary_GetCurrentPosition,
939 DS8Primary_GetFormat,
940 DS8Primary_GetVolume,
941 DS8Primary_GetPan,
942 DS8Primary_GetFrequency,
943 DS8Primary_GetStatus,
944 DS8Primary_Initialize,
945 DS8Primary_Lock,
946 DS8Primary_Play,
947 DS8Primary_SetCurrentPosition,
948 DS8Primary_SetFormat,
949 DS8Primary_SetVolume,
950 DS8Primary_SetPan,
951 DS8Primary_SetFrequency,
952 DS8Primary_Stop,
953 DS8Primary_Unlock,
954 DS8Primary_Restore
957 static inline DS8Primary *impl_from_IDirectSound3DListener(IDirectSound3DListener *iface)
959 return CONTAINING_RECORD(iface, DS8Primary, IDirectSound3DListener_iface);
962 static HRESULT WINAPI DS8Primary3D_QueryInterface(IDirectSound3DListener *iface, REFIID riid, void **ppv)
964 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
965 return DS8Primary_QueryInterface(&This->IDirectSoundBuffer_iface, riid, ppv);
968 static ULONG WINAPI DS8Primary3D_AddRef(IDirectSound3DListener *iface)
970 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
971 LONG ret;
973 ret = InterlockedIncrement(&This->ds3d_ref);
974 TRACE("new refcount %"LONGFMT"d\n", ret);
976 return ret;
980 /* Considering the primary buffer doesn't get destroyed
981 * it doesn't make sense to destroy ds3d here
983 static ULONG WINAPI DS8Primary3D_Release(IDirectSound3DListener *iface)
985 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
986 LONG ret;
988 ret = InterlockedDecrement(&This->ds3d_ref);
989 TRACE("new refcount %"LONGFMT"d\n", ret);
991 return ret;
995 static HRESULT WINAPI DS8Primary3D_GetAllParameters(IDirectSound3DListener *iface, DS3DLISTENER *listener)
997 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
999 TRACE("(%p)->(%p)\n", iface, listener);
1001 if(!listener || listener->dwSize < sizeof(*listener))
1003 WARN("Invalid DS3DLISTENER %p %"LONGFMT"u\n", listener, listener ? listener->dwSize : 0);
1004 return DSERR_INVALIDPARAM;
1007 EnterCriticalSection(This->crst);
1008 setALContext(This->ctx);
1009 IDirectSound3DListener_GetPosition(iface, &listener->vPosition);
1010 IDirectSound3DListener_GetVelocity(iface, &listener->vVelocity);
1011 IDirectSound3DListener_GetOrientation(iface, &listener->vOrientFront, &listener->vOrientTop);
1012 IDirectSound3DListener_GetDistanceFactor(iface, &listener->flDistanceFactor);
1013 IDirectSound3DListener_GetRolloffFactor(iface, &listener->flRolloffFactor);
1014 IDirectSound3DListener_GetRolloffFactor(iface, &listener->flDopplerFactor);
1015 popALContext();
1016 LeaveCriticalSection(This->crst);
1018 return DS_OK;
1021 static HRESULT WINAPI DS8Primary3D_GetDistanceFactor(IDirectSound3DListener *iface, D3DVALUE *distancefactor)
1023 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1025 TRACE("(%p)->(%p)\n", iface, distancefactor);
1027 if(!distancefactor)
1029 WARN("Invalid parameter %p\n", distancefactor);
1030 return DSERR_INVALIDPARAM;
1033 setALContext(This->ctx);
1034 *distancefactor = 343.3f/alGetFloat(AL_SPEED_OF_SOUND);
1035 checkALError();
1036 popALContext();
1038 return S_OK;
1041 static HRESULT WINAPI DS8Primary3D_GetDopplerFactor(IDirectSound3DListener *iface, D3DVALUE *dopplerfactor)
1043 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1045 TRACE("(%p)->(%p)\n", iface, dopplerfactor);
1047 if(!dopplerfactor)
1049 WARN("Invalid parameter %p\n", dopplerfactor);
1050 return DSERR_INVALIDPARAM;
1053 setALContext(This->ctx);
1054 *dopplerfactor = alGetFloat(AL_DOPPLER_FACTOR);
1055 checkALError();
1056 popALContext();
1058 return S_OK;
1061 static HRESULT WINAPI DS8Primary3D_GetOrientation(IDirectSound3DListener *iface, D3DVECTOR *front, D3DVECTOR *top)
1063 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1064 ALfloat orient[6];
1066 TRACE("(%p)->(%p, %p)\n", iface, front, top);
1068 if(!front || !top)
1070 WARN("Invalid parameter %p %p\n", front, top);
1071 return DSERR_INVALIDPARAM;
1074 setALContext(This->ctx);
1075 alGetListenerfv(AL_ORIENTATION, orient);
1076 checkALError();
1077 popALContext();
1079 front->x = orient[0];
1080 front->y = orient[1];
1081 front->z = -orient[2];
1082 top->x = orient[3];
1083 top->y = orient[4];
1084 top->z = -orient[5];
1085 return S_OK;
1088 static HRESULT WINAPI DS8Primary3D_GetPosition(IDirectSound3DListener *iface, D3DVECTOR *pos)
1090 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1091 ALfloat alpos[3];
1093 TRACE("(%p)->(%p)\n", iface, pos);
1095 if(!pos)
1097 WARN("Invalid parameter %p\n", pos);
1098 return DSERR_INVALIDPARAM;
1101 setALContext(This->ctx);
1102 alGetListenerfv(AL_POSITION, alpos);
1103 checkALError();
1104 popALContext();
1106 pos->x = alpos[0];
1107 pos->y = alpos[1];
1108 pos->z = -alpos[2];
1109 return S_OK;
1112 static HRESULT WINAPI DS8Primary3D_GetRolloffFactor(IDirectSound3DListener *iface, D3DVALUE *rollofffactor)
1114 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1116 TRACE("(%p)->(%p)\n", iface, rollofffactor);
1118 if(!rollofffactor)
1120 WARN("Invalid parameter %p\n", rollofffactor);
1121 return DSERR_INVALIDPARAM;
1124 EnterCriticalSection(This->crst);
1125 *rollofffactor = This->rollofffactor;
1126 LeaveCriticalSection(This->crst);
1128 return S_OK;
1131 static HRESULT WINAPI DS8Primary3D_GetVelocity(IDirectSound3DListener *iface, D3DVECTOR *velocity)
1133 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1134 ALfloat vel[3];
1136 TRACE("(%p)->(%p)\n", iface, velocity);
1138 if(!velocity)
1140 WARN("Invalid parameter %p\n", velocity);
1141 return DSERR_INVALIDPARAM;
1144 setALContext(This->ctx);
1145 alGetListenerfv(AL_VELOCITY, vel);
1146 checkALError();
1147 popALContext();
1149 velocity->x = vel[0];
1150 velocity->y = vel[1];
1151 velocity->z = -vel[2];
1152 return S_OK;
1155 static HRESULT WINAPI DS8Primary3D_SetAllParameters(IDirectSound3DListener *iface, const DS3DLISTENER *listen, DWORD apply)
1157 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1159 TRACE("(%p)->(%p, %"LONGFMT"u)\n", iface, listen, apply);
1161 if(!listen || listen->dwSize < sizeof(*listen))
1163 WARN("Invalid parameter %p %"LONGFMT"u\n", listen, listen ? listen->dwSize : 0);
1164 return DSERR_INVALIDPARAM;
1167 if(listen->flDistanceFactor > DS3D_MAXDISTANCEFACTOR ||
1168 listen->flDistanceFactor < DS3D_MINDISTANCEFACTOR)
1170 WARN("Invalid distance factor (%f)\n", listen->flDistanceFactor);
1171 return DSERR_INVALIDPARAM;
1174 if(listen->flDopplerFactor > DS3D_MAXDOPPLERFACTOR ||
1175 listen->flDopplerFactor < DS3D_MINDOPPLERFACTOR)
1177 WARN("Invalid doppler factor (%f)\n", listen->flDopplerFactor);
1178 return DSERR_INVALIDPARAM;
1181 if(listen->flRolloffFactor < DS3D_MINROLLOFFFACTOR ||
1182 listen->flRolloffFactor > DS3D_MAXROLLOFFFACTOR)
1184 WARN("Invalid rolloff factor (%f)\n", listen->flRolloffFactor);
1185 return DSERR_INVALIDPARAM;
1188 EnterCriticalSection(This->crst);
1189 setALContext(This->ctx);
1190 IDirectSound3DListener_SetPosition(iface, listen->vPosition.x, listen->vPosition.y, listen->vPosition.z, apply);
1191 IDirectSound3DListener_SetVelocity(iface, listen->vVelocity.x, listen->vVelocity.y, listen->vVelocity.z, apply);
1192 IDirectSound3DListener_SetOrientation(iface, listen->vOrientFront.x, listen->vOrientFront.y, listen->vOrientFront.z,
1193 listen->vOrientTop.x, listen->vOrientTop.y, listen->vOrientTop.z, apply);
1194 IDirectSound3DListener_SetDistanceFactor(iface, listen->flDistanceFactor, apply);
1195 IDirectSound3DListener_SetRolloffFactor(iface, listen->flRolloffFactor, apply);
1196 IDirectSound3DListener_SetDopplerFactor(iface, listen->flDopplerFactor, apply);
1197 popALContext();
1198 LeaveCriticalSection(This->crst);
1200 return S_OK;
1203 static HRESULT WINAPI DS8Primary3D_SetDistanceFactor(IDirectSound3DListener *iface, D3DVALUE factor, DWORD apply)
1205 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1207 TRACE("(%p)->(%f, %"LONGFMT"u)\n", iface, factor, apply);
1209 if(factor < DS3D_MINDISTANCEFACTOR ||
1210 factor > DS3D_MAXDISTANCEFACTOR)
1212 WARN("Invalid parameter %f\n", factor);
1213 return DSERR_INVALIDPARAM;
1216 if(apply == DS3D_DEFERRED)
1218 EnterCriticalSection(This->crst);
1219 This->listen.flDistanceFactor = factor;
1220 This->dirty.bit.distancefactor = 1;
1221 LeaveCriticalSection(This->crst);
1223 else
1225 setALContext(This->ctx);
1226 alSpeedOfSound(343.3f/factor);
1227 if(This->SupportedExt[EXT_EFX])
1228 alListenerf(AL_METERS_PER_UNIT, factor);
1229 checkALError();
1230 popALContext();
1233 return S_OK;
1236 static HRESULT WINAPI DS8Primary3D_SetDopplerFactor(IDirectSound3DListener *iface, D3DVALUE factor, DWORD apply)
1238 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1240 TRACE("(%p)->(%f, %"LONGFMT"u)\n", iface, factor, apply);
1242 if(factor < DS3D_MINDOPPLERFACTOR ||
1243 factor > DS3D_MAXDOPPLERFACTOR)
1245 WARN("Invalid parameter %f\n", factor);
1246 return DSERR_INVALIDPARAM;
1249 if(apply == DS3D_DEFERRED)
1251 EnterCriticalSection(This->crst);
1252 This->listen.flDopplerFactor = factor;
1253 This->dirty.bit.dopplerfactor = 1;
1254 LeaveCriticalSection(This->crst);
1256 else
1258 setALContext(This->ctx);
1259 alDopplerFactor(factor);
1260 checkALError();
1261 popALContext();
1264 return S_OK;
1267 static HRESULT WINAPI DS8Primary3D_SetOrientation(IDirectSound3DListener *iface, D3DVALUE xFront, D3DVALUE yFront, D3DVALUE zFront, D3DVALUE xTop, D3DVALUE yTop, D3DVALUE zTop, DWORD apply)
1269 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1271 TRACE("(%p)->(%f, %f, %f, %f, %f, %f, %"LONGFMT"u)\n", iface, xFront, yFront, zFront, xTop, yTop, zTop, apply);
1273 if(apply == DS3D_DEFERRED)
1275 EnterCriticalSection(This->crst);
1276 This->listen.vOrientFront.x = xFront;
1277 This->listen.vOrientFront.y = yFront;
1278 This->listen.vOrientFront.z = zFront;
1279 This->listen.vOrientTop.x = xTop;
1280 This->listen.vOrientTop.y = yTop;
1281 This->listen.vOrientTop.z = zTop;
1282 This->dirty.bit.orientation = 1;
1283 LeaveCriticalSection(This->crst);
1285 else
1287 ALfloat orient[6] = {
1288 xFront, yFront, -zFront,
1289 xTop, yTop, -zTop
1291 setALContext(This->ctx);
1292 alListenerfv(AL_ORIENTATION, orient);
1293 checkALError();
1294 popALContext();
1297 return S_OK;
1300 static HRESULT WINAPI DS8Primary3D_SetPosition(IDirectSound3DListener *iface, D3DVALUE x, D3DVALUE y, D3DVALUE z, DWORD apply)
1302 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1304 TRACE("(%p)->(%f, %f, %f, %"LONGFMT"u)\n", iface, x, y, z, apply);
1306 if(apply == DS3D_DEFERRED)
1308 EnterCriticalSection(This->crst);
1309 This->listen.vPosition.x = x;
1310 This->listen.vPosition.y = y;
1311 This->listen.vPosition.z = z;
1312 This->dirty.bit.pos = 1;
1313 LeaveCriticalSection(This->crst);
1315 else
1317 setALContext(This->ctx);
1318 alListener3f(AL_POSITION, x, y, -z);
1319 checkALError();
1320 popALContext();
1323 return S_OK;
1326 static HRESULT WINAPI DS8Primary3D_SetRolloffFactor(IDirectSound3DListener *iface, D3DVALUE factor, DWORD apply)
1328 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1330 TRACE("(%p)->(%f, %"LONGFMT"u)\n", iface, factor, apply);
1332 if(factor < DS3D_MINROLLOFFFACTOR ||
1333 factor > DS3D_MAXROLLOFFFACTOR)
1335 WARN("Invalid parameter %f\n", factor);
1336 return DSERR_INVALIDPARAM;
1339 EnterCriticalSection(This->crst);
1340 if(apply == DS3D_DEFERRED)
1342 This->listen.flRolloffFactor = factor;
1343 This->dirty.bit.rollofffactor = 1;
1345 else
1347 DWORD i;
1349 setALContext(This->ctx);
1350 for(i = 0;i < This->nbuffers;++i)
1352 if(This->buffers[i]->ds3dmode != DS3DMODE_DISABLE)
1353 alSourcef(This->buffers[i]->source, AL_ROLLOFF_FACTOR, factor);
1355 checkALError();
1356 popALContext();
1358 This->rollofffactor = factor;
1360 LeaveCriticalSection(This->crst);
1362 return S_OK;
1365 static HRESULT WINAPI DS8Primary3D_SetVelocity(IDirectSound3DListener *iface, D3DVALUE x, D3DVALUE y, D3DVALUE z, DWORD apply)
1367 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1369 TRACE("(%p)->(%f, %f, %f, %"LONGFMT"u)\n", iface, x, y, z, apply);
1371 if(apply == DS3D_DEFERRED)
1373 EnterCriticalSection(This->crst);
1374 This->listen.vVelocity.x = x;
1375 This->listen.vVelocity.y = y;
1376 This->listen.vVelocity.z = z;
1377 This->dirty.bit.vel = 1;
1378 LeaveCriticalSection(This->crst);
1380 else
1382 setALContext(This->ctx);
1383 alListener3f(AL_VELOCITY, x, y, -z);
1384 checkALError();
1385 popALContext();
1388 return S_OK;
1391 static HRESULT WINAPI DS8Primary3D_CommitDeferredSettings(IDirectSound3DListener *iface)
1393 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1394 const DS3DLISTENER *listen = &This->listen;
1395 DWORD i;
1397 EnterCriticalSection(This->crst);
1398 setALContext(This->ctx);
1399 This->DeferUpdates();
1401 if(This->dirty.bit.pos)
1402 alListener3f(AL_POSITION, listen->vPosition.x, listen->vPosition.y, -listen->vPosition.z);
1403 if(This->dirty.bit.vel)
1404 alListener3f(AL_VELOCITY, listen->vVelocity.x, listen->vVelocity.y, -listen->vVelocity.z);
1405 if(This->dirty.bit.orientation)
1407 ALfloat orient[6] = {
1408 listen->vOrientFront.x, listen->vOrientFront.y, -listen->vOrientFront.z,
1409 listen->vOrientTop.x, listen->vOrientTop.y, -listen->vOrientTop.z
1411 alListenerfv(AL_ORIENTATION, orient);
1413 if(This->dirty.bit.distancefactor)
1415 alSpeedOfSound(343.3f/listen->flDistanceFactor);
1416 if(This->SupportedExt[EXT_EFX])
1417 alListenerf(AL_METERS_PER_UNIT, listen->flDistanceFactor);
1420 if(This->dirty.bit.rollofffactor)
1422 ALfloat rolloff = This->rollofffactor;
1423 for(i = 0;i < This->nbuffers;++i)
1425 DS8Buffer *buf = This->buffers[i];
1426 if(buf->ds3dmode != DS3DMODE_DISABLE)
1427 alSourcef(buf->source, AL_ROLLOFF_FACTOR, rolloff);
1431 if(This->dirty.bit.dopplerfactor)
1432 alDopplerFactor(listen->flDopplerFactor);
1434 if(This->dirty.bit.effect)
1435 This->ExtAL->AuxiliaryEffectSloti(This->auxslot, AL_EFFECTSLOT_EFFECT, This->effect);
1437 /* checkALError is here for debugging */
1438 checkALError();
1440 TRACE("Dirty flags was: 0x%02x\n", This->dirty.flags);
1441 This->dirty.flags = 0;
1443 for(i = 0;i < This->nbuffers;++i)
1445 DS8Buffer *buf = This->buffers[i];
1447 if(!buf->dirty.flags)
1448 continue;
1450 if(buf->dirty.bit.pos)
1451 alSource3f(buf->source, AL_POSITION,
1452 buf->ds3dbuffer.vPosition.x,
1453 buf->ds3dbuffer.vPosition.y,
1454 -buf->ds3dbuffer.vPosition.z);
1455 if(buf->dirty.bit.vel)
1456 alSource3f(buf->source, AL_VELOCITY,
1457 buf->ds3dbuffer.vVelocity.x,
1458 buf->ds3dbuffer.vVelocity.y,
1459 -buf->ds3dbuffer.vVelocity.z);
1460 if(buf->dirty.bit.cone_angles)
1462 alSourcei(buf->source, AL_CONE_INNER_ANGLE,
1463 buf->ds3dbuffer.dwInsideConeAngle);
1464 alSourcei(buf->source, AL_CONE_OUTER_ANGLE,
1465 buf->ds3dbuffer.dwOutsideConeAngle);
1467 if(buf->dirty.bit.cone_orient)
1468 alSource3f(buf->source, AL_DIRECTION,
1469 buf->ds3dbuffer.vConeOrientation.x,
1470 buf->ds3dbuffer.vConeOrientation.y,
1471 -buf->ds3dbuffer.vConeOrientation.z);
1472 if(buf->dirty.bit.cone_outsidevolume)
1473 alSourcef(buf->source, AL_CONE_OUTER_GAIN,
1474 mB_to_gain(buf->ds3dbuffer.lConeOutsideVolume));
1475 if(buf->dirty.bit.min_distance)
1476 alSourcef(buf->source, AL_REFERENCE_DISTANCE, buf->ds3dbuffer.flMinDistance);
1477 if(buf->dirty.bit.max_distance)
1478 alSourcef(buf->source, AL_MAX_DISTANCE, buf->ds3dbuffer.flMaxDistance);
1479 if(buf->dirty.bit.mode)
1481 buf->ds3dmode = buf->ds3dbuffer.dwMode;
1482 alSourcei(buf->source, AL_SOURCE_RELATIVE,
1483 (buf->ds3dmode!=DS3DMODE_NORMAL) ? AL_TRUE : AL_FALSE);
1484 alSourcef(buf->source, AL_ROLLOFF_FACTOR,
1485 (buf->ds3dmode==DS3DMODE_DISABLE) ? 0.0f : This->rollofffactor);
1487 buf->dirty.flags = 0;
1489 checkALError();
1491 This->ProcessUpdates();
1492 popALContext();
1493 LeaveCriticalSection(This->crst);
1495 return S_OK;
1498 static const IDirectSound3DListenerVtbl DS8Primary3D_Vtbl =
1500 DS8Primary3D_QueryInterface,
1501 DS8Primary3D_AddRef,
1502 DS8Primary3D_Release,
1503 DS8Primary3D_GetAllParameters,
1504 DS8Primary3D_GetDistanceFactor,
1505 DS8Primary3D_GetDopplerFactor,
1506 DS8Primary3D_GetOrientation,
1507 DS8Primary3D_GetPosition,
1508 DS8Primary3D_GetRolloffFactor,
1509 DS8Primary3D_GetVelocity,
1510 DS8Primary3D_SetAllParameters,
1511 DS8Primary3D_SetDistanceFactor,
1512 DS8Primary3D_SetDopplerFactor,
1513 DS8Primary3D_SetOrientation,
1514 DS8Primary3D_SetPosition,
1515 DS8Primary3D_SetRolloffFactor,
1516 DS8Primary3D_SetVelocity,
1517 DS8Primary3D_CommitDeferredSettings
1520 /* NOTE: Although the app handles listener properties through secondary buffers,
1521 * we pass the requests to the primary buffer though a propertyset interface.
1522 * These methods are not exposed to the app. */
1523 static inline DS8Primary *impl_from_IKsPropertySet(IKsPropertySet *iface)
1525 return CONTAINING_RECORD(iface, DS8Primary, IKsPropertySet_iface);
1528 static HRESULT WINAPI DS8PrimaryProp_QueryInterface(IKsPropertySet *iface, REFIID riid, void **ppv)
1530 DS8Primary *This = impl_from_IKsPropertySet(iface);
1531 return DS8Primary_QueryInterface(&This->IDirectSoundBuffer_iface, riid, ppv);
1534 static ULONG WINAPI DS8PrimaryProp_AddRef(IKsPropertySet *iface)
1536 DS8Primary *This = impl_from_IKsPropertySet(iface);
1537 LONG ret;
1539 ret = InterlockedIncrement(&This->prop_ref);
1540 TRACE("new refcount %"LONGFMT"d\n", ret);
1542 return ret;
1545 static ULONG WINAPI DS8PrimaryProp_Release(IKsPropertySet *iface)
1547 DS8Primary *This = impl_from_IKsPropertySet(iface);
1548 LONG ret;
1550 ret = InterlockedDecrement(&This->prop_ref);
1551 TRACE("new refcount %"LONGFMT"d\n", ret);
1553 return ret;
1556 static HRESULT WINAPI DS8PrimaryProp_Get(IKsPropertySet *iface,
1557 REFGUID guidPropSet, ULONG dwPropID,
1558 LPVOID pInstanceData, ULONG cbInstanceData,
1559 LPVOID pPropData, ULONG cbPropData,
1560 PULONG pcbReturned)
1562 DS8Primary *This = impl_from_IKsPropertySet(iface);
1563 HRESULT res = E_PROP_ID_UNSUPPORTED;
1564 (void)pInstanceData;
1565 (void)cbInstanceData;
1567 if(IsEqualIID(guidPropSet, &DSPROPSETID_EAX20_ListenerProperties))
1569 EnterCriticalSection(This->crst);
1571 if(This->effect == 0)
1572 res = E_PROP_ID_UNSUPPORTED;
1573 else switch(dwPropID)
1575 case DSPROPERTY_EAXLISTENER_ALLPARAMETERS:
1576 res = DSERR_INVALIDPARAM;
1577 if(cbPropData >= sizeof(EAXLISTENERPROPERTIES))
1579 union {
1580 void *v;
1581 EAXLISTENERPROPERTIES *props;
1582 } data = { pPropData };
1584 *data.props = This->eax_prop;
1585 *pcbReturned = sizeof(EAXLISTENERPROPERTIES);
1586 res = DS_OK;
1588 break;
1590 case DSPROPERTY_EAXLISTENER_ROOM:
1591 res = DSERR_INVALIDPARAM;
1592 if(cbPropData >= sizeof(LONG))
1594 union {
1595 void *v;
1596 LONG *l;
1597 } data = { pPropData };
1599 *data.l = This->eax_prop.lRoom;
1600 *pcbReturned = sizeof(LONG);
1601 res = DS_OK;
1603 break;
1604 case DSPROPERTY_EAXLISTENER_ROOMHF:
1605 res = DSERR_INVALIDPARAM;
1606 if(cbPropData >= sizeof(LONG))
1608 union {
1609 void *v;
1610 LONG *l;
1611 } data = { pPropData };
1613 *data.l = This->eax_prop.lRoomHF;
1614 *pcbReturned = sizeof(LONG);
1615 res = DS_OK;
1617 break;
1619 case DSPROPERTY_EAXLISTENER_ROOMROLLOFFFACTOR:
1620 res = DSERR_INVALIDPARAM;
1621 if(cbPropData >= sizeof(FLOAT))
1623 union {
1624 void *v;
1625 FLOAT *fl;
1626 } data = { pPropData };
1628 *data.fl = This->eax_prop.flRoomRolloffFactor;
1629 *pcbReturned = sizeof(FLOAT);
1630 res = DS_OK;
1632 break;
1634 case DSPROPERTY_EAXLISTENER_ENVIRONMENT:
1635 res = DSERR_INVALIDPARAM;
1636 if(cbPropData >= sizeof(DWORD))
1638 union {
1639 void *v;
1640 DWORD *dw;
1641 } data = { pPropData };
1643 *data.dw = This->eax_prop.dwEnvironment;
1644 *pcbReturned = sizeof(DWORD);
1645 res = DS_OK;
1647 break;
1649 case DSPROPERTY_EAXLISTENER_ENVIRONMENTSIZE:
1650 res = DSERR_INVALIDPARAM;
1651 if(cbPropData >= sizeof(FLOAT))
1653 union {
1654 void *v;
1655 FLOAT *fl;
1656 } data = { pPropData };
1658 *data.fl = This->eax_prop.flEnvironmentSize;
1659 *pcbReturned = sizeof(FLOAT);
1660 res = DS_OK;
1662 break;
1663 case DSPROPERTY_EAXLISTENER_ENVIRONMENTDIFFUSION:
1664 res = DSERR_INVALIDPARAM;
1665 if(cbPropData >= sizeof(FLOAT))
1667 union {
1668 void *v;
1669 FLOAT *fl;
1670 } data = { pPropData };
1672 *data.fl = This->eax_prop.flEnvironmentDiffusion;
1673 *pcbReturned = sizeof(FLOAT);
1674 res = DS_OK;
1676 break;
1678 case DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF:
1679 res = DSERR_INVALIDPARAM;
1680 if(cbPropData >= sizeof(FLOAT))
1682 union {
1683 void *v;
1684 FLOAT *fl;
1685 } data = { pPropData };
1687 *data.fl = This->eax_prop.flAirAbsorptionHF;
1688 *pcbReturned = sizeof(FLOAT);
1689 res = DS_OK;
1691 break;
1693 case DSPROPERTY_EAXLISTENER_FLAGS:
1694 res = DSERR_INVALIDPARAM;
1695 if(cbPropData >= sizeof(DWORD))
1697 union {
1698 void *v;
1699 DWORD *dw;
1700 } data = { pPropData };
1702 *data.dw = This->eax_prop.dwFlags;
1703 *pcbReturned = sizeof(DWORD);
1704 res = DS_OK;
1706 break;
1708 default:
1709 FIXME("Unhandled propid: 0x%08"LONGFMT"x\n", dwPropID);
1710 break;
1713 LeaveCriticalSection(This->crst);
1715 else
1716 FIXME("Unhandled propset: %s\n", debugstr_guid(guidPropSet));
1718 return res;
1721 static HRESULT WINAPI DS8PrimaryProp_Set(IKsPropertySet *iface,
1722 REFGUID guidPropSet, ULONG dwPropID,
1723 LPVOID pInstanceData, ULONG cbInstanceData,
1724 LPVOID pPropData, ULONG cbPropData)
1726 DS8Primary *This = impl_from_IKsPropertySet(iface);
1727 HRESULT res = E_PROP_ID_UNSUPPORTED;
1728 (void)pInstanceData;
1729 (void)cbInstanceData;
1731 if(IsEqualIID(guidPropSet, &DSPROPSETID_EAX20_ListenerProperties))
1733 DWORD propid = dwPropID & ~DSPROPERTY_EAXLISTENER_DEFERRED;
1734 BOOL immediate = !(dwPropID&DSPROPERTY_EAXLISTENER_DEFERRED);
1736 EnterCriticalSection(This->crst);
1737 setALContext(This->ctx);
1739 if(This->effect == 0)
1740 res = E_PROP_ID_UNSUPPORTED;
1741 else switch(propid)
1743 case 0: /* 0 = not setting any property, just apply */
1744 res = DS_OK;
1745 break;
1747 case DSPROPERTY_EAXLISTENER_ALLPARAMETERS:
1748 do_allparams:
1749 res = DSERR_INVALIDPARAM;
1750 if(cbPropData >= sizeof(EAXLISTENERPROPERTIES))
1752 union {
1753 const void *v;
1754 const EAXLISTENERPROPERTIES *props;
1755 } data = { pPropData };
1757 /* FIXME: Need to validate property values... Ignore? Clamp? Error? */
1758 This->eax_prop = *data.props;
1759 This->ExtAL->Effectf(This->effect, AL_REVERB_DENSITY,
1760 (data.props->flEnvironmentSize < 2.0f) ?
1761 (data.props->flEnvironmentSize - 1.0f) : 1.0f);
1762 This->ExtAL->Effectf(This->effect, AL_REVERB_DIFFUSION,
1763 data.props->flEnvironmentDiffusion);
1765 This->ExtAL->Effectf(This->effect, AL_REVERB_GAIN,
1766 mB_to_gain(data.props->lRoom));
1767 This->ExtAL->Effectf(This->effect, AL_REVERB_GAINHF,
1768 mB_to_gain(data.props->lRoomHF));
1770 This->ExtAL->Effectf(This->effect, AL_REVERB_ROOM_ROLLOFF_FACTOR,
1771 data.props->flRoomRolloffFactor);
1773 This->ExtAL->Effectf(This->effect, AL_REVERB_DECAY_TIME,
1774 data.props->flDecayTime);
1775 This->ExtAL->Effectf(This->effect, AL_REVERB_DECAY_HFRATIO,
1776 data.props->flDecayHFRatio);
1778 This->ExtAL->Effectf(This->effect, AL_REVERB_REFLECTIONS_GAIN,
1779 mB_to_gain(data.props->lReflections));
1780 This->ExtAL->Effectf(This->effect, AL_REVERB_REFLECTIONS_DELAY,
1781 data.props->flReflectionsDelay);
1783 This->ExtAL->Effectf(This->effect, AL_REVERB_LATE_REVERB_GAIN,
1784 mB_to_gain(data.props->lReverb));
1785 This->ExtAL->Effectf(This->effect, AL_REVERB_LATE_REVERB_DELAY,
1786 data.props->flReverbDelay);
1788 This->ExtAL->Effectf(This->effect, AL_REVERB_AIR_ABSORPTION_GAINHF,
1789 mB_to_gain(data.props->flAirAbsorptionHF));
1791 This->ExtAL->Effecti(This->effect, AL_REVERB_DECAY_HFLIMIT,
1792 (data.props->dwFlags&EAXLISTENERFLAGS_DECAYHFLIMIT) ?
1793 AL_TRUE : AL_FALSE);
1795 checkALError();
1797 This->dirty.bit.effect = 1;
1798 res = DS_OK;
1800 break;
1802 case DSPROPERTY_EAXLISTENER_ROOM:
1803 res = DSERR_INVALIDPARAM;
1804 if(cbPropData >= sizeof(LONG))
1806 union {
1807 const void *v;
1808 const LONG *l;
1809 } data = { pPropData };
1811 This->eax_prop.lRoom = *data.l;
1812 This->ExtAL->Effectf(This->effect, AL_REVERB_GAIN,
1813 mB_to_gain(This->eax_prop.lRoom));
1814 checkALError();
1816 This->dirty.bit.effect = 1;
1817 res = DS_OK;
1819 break;
1820 case DSPROPERTY_EAXLISTENER_ROOMHF:
1821 res = DSERR_INVALIDPARAM;
1822 if(cbPropData >= sizeof(LONG))
1824 union {
1825 const void *v;
1826 const LONG *l;
1827 } data = { pPropData };
1829 This->eax_prop.lRoomHF = *data.l;
1830 This->ExtAL->Effectf(This->effect, AL_REVERB_GAINHF,
1831 mB_to_gain(This->eax_prop.lRoomHF));
1832 checkALError();
1834 This->dirty.bit.effect = 1;
1835 res = DS_OK;
1837 break;
1839 case DSPROPERTY_EAXLISTENER_ROOMROLLOFFFACTOR:
1840 res = DSERR_INVALIDPARAM;
1841 if(cbPropData >= sizeof(FLOAT))
1843 union {
1844 const void *v;
1845 const FLOAT *fl;
1846 } data = { pPropData };
1848 This->eax_prop.flRoomRolloffFactor = *data.fl;
1849 This->ExtAL->Effectf(This->effect, AL_REVERB_ROOM_ROLLOFF_FACTOR,
1850 This->eax_prop.flRoomRolloffFactor);
1851 checkALError();
1853 This->dirty.bit.effect = 1;
1854 res = DS_OK;
1856 break;
1858 case DSPROPERTY_EAXLISTENER_ENVIRONMENT:
1859 res = DSERR_INVALIDPARAM;
1860 if(cbPropData >= sizeof(DWORD))
1862 union {
1863 const void *v;
1864 const DWORD *dw;
1865 } data = { pPropData };
1867 if(*data.dw < EAX_ENVIRONMENT_COUNT)
1869 /* Get the environment index's default and pass it down to
1870 * ALLPARAMETERS */
1871 propid = DSPROPERTY_EAXLISTENER_ALLPARAMETERS;
1872 pPropData = (void*)&EnvironmentDefaults[*data.dw];
1873 cbPropData = sizeof(EnvironmentDefaults[*data.dw]);
1874 goto do_allparams;
1877 break;
1879 case DSPROPERTY_EAXLISTENER_ENVIRONMENTSIZE:
1880 res = DSERR_INVALIDPARAM;
1881 if(cbPropData >= sizeof(FLOAT))
1883 union {
1884 const void *v;
1885 const FLOAT *fl;
1886 } data = { pPropData };
1888 if(*data.fl >= 1.0f && *data.fl <= 100.0f)
1890 double scale = (*data.fl)/This->eax_prop.flEnvironmentSize;
1892 This->eax_prop.flEnvironmentSize = *data.fl;
1894 if((This->eax_prop.dwFlags&EAXLISTENERFLAGS_DECAYTIMESCALE))
1896 This->eax_prop.flDecayTime *= scale;
1897 This->eax_prop.flDecayTime = clampF(This->eax_prop.flDecayTime, 0.1f, 20.0f);
1899 if((This->eax_prop.dwFlags&EAXLISTENERFLAGS_REFLECTIONSSCALE))
1901 This->eax_prop.lReflections += gain_to_mB(1.0/scale);
1902 This->eax_prop.lReflections = clampI(This->eax_prop.lReflections, -10000, 1000);
1904 if((This->eax_prop.dwFlags&EAXLISTENERFLAGS_REFLECTIONSDELAYSCALE))
1906 This->eax_prop.flReflectionsDelay *= scale;
1907 This->eax_prop.flReflectionsDelay = clampF(This->eax_prop.flReflectionsDelay, 0.0f, 0.3f);
1909 if((This->eax_prop.dwFlags&EAXLISTENERFLAGS_REVERBSCALE))
1911 This->eax_prop.lReverb += gain_to_mB(1.0/scale);
1912 This->eax_prop.lReverb = clampI(This->eax_prop.lReverb, -10000, 2000);
1914 if((This->eax_prop.dwFlags&EAXLISTENERFLAGS_REVERBDELAYSCALE))
1916 This->eax_prop.flReverbDelay *= scale;
1917 This->eax_prop.flReverbDelay = clampF(This->eax_prop.flReverbDelay, 0.0f, 0.1f);
1920 /* Pass the updated environment properties down to ALLPARAMETERS */
1921 propid = DSPROPERTY_EAXLISTENER_ALLPARAMETERS;
1922 pPropData = (void*)&This->eax_prop;
1923 cbPropData = sizeof(This->eax_prop);
1924 goto do_allparams;
1927 break;
1928 case DSPROPERTY_EAXLISTENER_ENVIRONMENTDIFFUSION:
1929 res = DSERR_INVALIDPARAM;
1930 if(cbPropData >= sizeof(FLOAT))
1932 union {
1933 const void *v;
1934 const FLOAT *fl;
1935 } data = { pPropData };
1937 This->eax_prop.flEnvironmentDiffusion = *data.fl;
1938 This->ExtAL->Effectf(This->effect, AL_REVERB_DIFFUSION,
1939 This->eax_prop.flEnvironmentDiffusion);
1940 checkALError();
1942 This->dirty.bit.effect = 1;
1943 res = DS_OK;
1945 break;
1947 case DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF:
1948 res = DSERR_INVALIDPARAM;
1949 if(cbPropData >= sizeof(FLOAT))
1951 union {
1952 const void *v;
1953 const FLOAT *fl;
1954 } data = { pPropData };
1956 This->eax_prop.flAirAbsorptionHF = *data.fl;
1957 This->ExtAL->Effectf(This->effect, AL_REVERB_AIR_ABSORPTION_GAINHF,
1958 mB_to_gain(This->eax_prop.flAirAbsorptionHF));
1959 checkALError();
1961 This->dirty.bit.effect = 1;
1962 res = DS_OK;
1964 break;
1966 case DSPROPERTY_EAXLISTENER_FLAGS:
1967 res = DSERR_INVALIDPARAM;
1968 if(cbPropData >= sizeof(DWORD))
1970 union {
1971 const void *v;
1972 const DWORD *dw;
1973 } data = { pPropData };
1975 This->eax_prop.dwFlags = *data.dw;
1976 This->ExtAL->Effecti(This->effect, AL_REVERB_DECAY_HFLIMIT,
1977 (This->eax_prop.dwFlags&EAXLISTENERFLAGS_DECAYHFLIMIT) ?
1978 AL_TRUE : AL_FALSE);
1979 checkALError();
1981 This->dirty.bit.effect = 1;
1982 res = DS_OK;
1984 break;
1986 default:
1987 FIXME("Unhandled propid: 0x%08"LONGFMT"x\n", propid);
1988 break;
1991 if(res == DS_OK && immediate)
1992 IDirectSound3DListener_CommitDeferredSettings(&This->IDirectSound3DListener_iface);
1994 popALContext();
1995 LeaveCriticalSection(This->crst);
1997 else
1998 FIXME("Unhandled propset: %s\n", debugstr_guid(guidPropSet));
2000 return res;
2003 static HRESULT WINAPI DS8PrimaryProp_QuerySupport(IKsPropertySet *iface,
2004 REFGUID guidPropSet, ULONG dwPropID,
2005 PULONG pTypeSupport)
2007 DS8Primary *This = impl_from_IKsPropertySet(iface);
2008 HRESULT res = E_PROP_ID_UNSUPPORTED;
2010 if(IsEqualIID(guidPropSet, &DSPROPSETID_EAX20_ListenerProperties))
2012 EnterCriticalSection(This->crst);
2014 if(This->effect == 0)
2015 res = E_PROP_ID_UNSUPPORTED;
2016 else if(dwPropID == DSPROPERTY_EAXLISTENER_ALLPARAMETERS ||
2017 dwPropID == DSPROPERTY_EAXLISTENER_ROOM ||
2018 dwPropID == DSPROPERTY_EAXLISTENER_ROOMHF ||
2019 dwPropID == DSPROPERTY_EAXLISTENER_ROOMROLLOFFFACTOR ||
2020 dwPropID == DSPROPERTY_EAXLISTENER_ENVIRONMENT ||
2021 dwPropID == DSPROPERTY_EAXLISTENER_ENVIRONMENTSIZE ||
2022 dwPropID == DSPROPERTY_EAXLISTENER_ENVIRONMENTDIFFUSION ||
2023 dwPropID == DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF ||
2024 dwPropID == DSPROPERTY_EAXLISTENER_FLAGS)
2026 *pTypeSupport = KSPROPERTY_SUPPORT_GET|KSPROPERTY_SUPPORT_SET;
2027 res = DS_OK;
2029 else
2030 FIXME("Unhandled propid: 0x%08"LONGFMT"x\n", dwPropID);
2032 LeaveCriticalSection(This->crst);
2034 else
2035 FIXME("Unhandled propset: %s\n", debugstr_guid(guidPropSet));
2037 return res;
2040 static const IKsPropertySetVtbl DS8PrimaryProp_Vtbl =
2042 DS8PrimaryProp_QueryInterface,
2043 DS8PrimaryProp_AddRef,
2044 DS8PrimaryProp_Release,
2045 DS8PrimaryProp_Get,
2046 DS8PrimaryProp_Set,
2047 DS8PrimaryProp_QuerySupport