Check for AL errors after setting all parameters
[dsound-openal.git] / primary.c
blobc9ae5e175915ede580834078018f239680c83543
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 inline DS8Primary *impl_from_IDirectSoundBuffer(IDirectSoundBuffer *iface)
74 return CONTAINING_RECORD(iface, DS8Primary, IDirectSoundBuffer_iface);
77 static inline DS8Primary *impl_from_IDirectSound3DListener(IDirectSound3DListener *iface)
79 return CONTAINING_RECORD(iface, DS8Primary, IDirectSound3DListener_iface);
82 static inline DS8Primary *impl_from_IKsPropertySet(IKsPropertySet *iface)
84 return CONTAINING_RECORD(iface, DS8Primary, IKsPropertySet_iface);
88 static void AL_APIENTRY wrap_DeferUpdates(void)
89 { alcSuspendContext(alcGetCurrentContext()); }
90 static void AL_APIENTRY wrap_ProcessUpdates(void)
91 { alcProcessContext(alcGetCurrentContext()); }
94 static void trigger_elapsed_notifies(DS8Buffer *buf, DWORD lastpos, DWORD curpos)
96 DWORD i;
97 for(i = 0; i < buf->nnotify; ++i)
99 DSBPOSITIONNOTIFY *not = &buf->notify[i];
100 HANDLE event = not->hEventNotify;
101 DWORD ofs = not->dwOffset;
103 if(ofs == (DWORD)DSBPN_OFFSETSTOP)
104 continue;
106 /* Wraparound case */
107 if(curpos < lastpos)
109 if(ofs < curpos || ofs >= lastpos)
110 SetEvent(event);
111 continue;
114 /* Normal case */
115 if(ofs >= lastpos && ofs < curpos)
116 SetEvent(event);
120 static void trigger_stop_notifies(DS8Buffer *buf)
122 DWORD i;
123 for(i = 0; i < buf->nnotify; ++i)
125 DSBPOSITIONNOTIFY *not = &buf->notify[i];
126 if(not->dwOffset == (DWORD)DSBPN_OFFSETSTOP)
127 SetEvent(not->hEventNotify);
131 static DWORD CALLBACK DS8Primary_thread(void *dwUser)
133 DS8Primary *prim = (DS8Primary*)dwUser;
134 DWORD i, active_notifies;
135 MSG msg;
137 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
139 TRACE("Primary buffer (%p) message loop start\n", prim);
140 while(GetMessageA(&msg, NULL, 0, 0))
142 if(msg.message != WM_USER)
143 continue;
145 EnterCriticalSection(prim->crst);
146 setALContext(prim->ctx);
148 for(i = 0;i < prim->nnotifies;)
150 DS8Buffer *buf = prim->notifies[i];
151 IDirectSoundBuffer8 *dsb = &buf->IDirectSoundBuffer8_iface;
152 DWORD status=0, curpos=buf->lastpos;
154 IDirectSoundBuffer8_GetStatus(dsb, &status);
155 IDirectSoundBuffer8_GetCurrentPosition(dsb, &curpos, NULL);
156 if(buf->lastpos != curpos)
158 trigger_elapsed_notifies(buf, buf->lastpos, curpos);
159 buf->lastpos = curpos;
161 if(!(status&DSBSTATUS_PLAYING))
163 /* Remove this buffer from list and put another at the
164 * current position; don't increment i
166 trigger_stop_notifies(buf);
167 prim->notifies[i] = prim->notifies[--prim->nnotifies];
168 continue;
170 i++;
172 active_notifies = i;
174 /* OpenAL doesn't support our lovely buffer extensions
175 * so just make sure enough buffers are queued
177 if(!prim->SupportedExt[SOFT_BUFFER_SAMPLES] &&
178 !prim->SupportedExt[SOFT_BUFFER_SUB_DATA] &&
179 !prim->SupportedExt[EXT_STATIC_BUFFER])
181 for(i = 0;i < prim->nbuffers;++i)
183 DS8Buffer *buf = prim->buffers[i];
184 ALint done = 0, queued = QBUFFERS, state = AL_PLAYING;
185 ALuint which, ofs;
187 if(buf->buffer->numsegs == 1 || !buf->isplaying)
188 continue;
190 alGetSourcei(buf->source, AL_SOURCE_STATE, &state);
191 alGetSourcei(buf->source, AL_BUFFERS_QUEUED, &queued);
192 alGetSourcei(buf->source, AL_BUFFERS_PROCESSED, &done);
194 queued -= done;
195 while(done--)
196 alSourceUnqueueBuffers(buf->source, 1, &which);
197 while(queued < QBUFFERS)
199 which = buf->buffer->buffers[buf->curidx];
200 ofs = buf->curidx*buf->buffer->segsize;
201 if(buf->curidx < buf->buffer->numsegs-1)
202 alBufferData(which, buf->buffer->buf_format,
203 buf->buffer->data + ofs, buf->buffer->segsize,
204 buf->buffer->format.Format.nSamplesPerSec);
205 else
206 alBufferData(which, buf->buffer->buf_format,
207 buf->buffer->data + ofs, buf->buffer->lastsegsize,
208 buf->buffer->format.Format.nSamplesPerSec);
210 alSourceQueueBuffers(buf->source, 1, &which);
211 buf->curidx = (buf->curidx+1)%buf->buffer->numsegs;
212 queued++;
214 if(!buf->curidx && !buf->islooping)
216 buf->isplaying = FALSE;
217 break;
220 if(state != AL_PLAYING)
222 if(!queued)
224 IDirectSoundBuffer8_Stop(&buf->IDirectSoundBuffer8_iface);
225 continue;
227 alSourcePlay(buf->source);
230 checkALError();
232 else if(active_notifies == 0 && prim->timer_id)
234 TRACE("No more notifies, killing timer\n");
235 timeKillEvent(prim->timer_id);
236 prim->timer_id = 0;
237 timeEndPeriod(prim->timer_res);
240 popALContext();
241 LeaveCriticalSection(prim->crst);
243 TRACE("Primary buffer (%p) message loop quit\n", prim);
245 if(prim->timer_id)
247 timeKillEvent(prim->timer_id);
248 prim->timer_id = 0;
249 timeEndPeriod(prim->timer_res);
250 TRACE("Killed timer\n");
253 return 0;
256 static void CALLBACK DS8Primary_timer(UINT timerID, UINT msg, DWORD_PTR dwUser,
257 DWORD_PTR dw1, DWORD_PTR dw2)
259 (void)timerID;
260 (void)msg;
261 (void)dw1;
262 (void)dw2;
263 PostThreadMessageA(dwUser, WM_USER, 0, 0);
266 void DS8Primary_starttimer(DS8Primary *prim)
268 DWORD triggertime, res = DS_TIME_RES;
269 ALint refresh = FAKE_REFRESH_COUNT;
270 TIMECAPS time;
272 if(prim->timer_id)
273 return;
275 timeGetDevCaps(&time, sizeof(TIMECAPS));
277 alcGetIntegerv(prim->parent->device, ALC_REFRESH, 1, &refresh);
278 checkALCError(prim->parent->device);
280 triggertime = 1000 / refresh / 2;
281 if(triggertime < time.wPeriodMin)
282 triggertime = time.wPeriodMin;
283 TRACE("Calling timer every %"LONGFMT"u ms for %i refreshes per second\n", triggertime, refresh);
285 if (res < time.wPeriodMin)
286 res = time.wPeriodMin;
287 if (timeBeginPeriod(res) == TIMERR_NOCANDO)
288 WARN("Could not set minimum resolution, don't expect sound\n");
290 prim->timer_res = res;
291 prim->timer_id = timeSetEvent(triggertime, res, DS8Primary_timer, prim->thread_id, TIME_PERIODIC|TIME_KILL_SYNCHRONOUS);
296 HRESULT DS8Primary_PreInit(DS8Primary *This, DS8Impl *parent)
298 DS3DLISTENER *listener;
299 WAVEFORMATEX *wfx;
300 HRESULT hr;
302 This->IDirectSoundBuffer_iface.lpVtbl = (IDirectSoundBufferVtbl*)&DS8Primary_Vtbl;
303 This->IDirectSound3DListener_iface.lpVtbl = (IDirectSound3DListenerVtbl*)&DS8Primary3D_Vtbl;
304 This->IKsPropertySet_iface.lpVtbl = (IKsPropertySetVtbl*)&DS8PrimaryProp_Vtbl;
306 This->parent = parent;
307 This->crst = &parent->share->crst;
308 This->ctx = parent->share->ctx;
309 This->SupportedExt = parent->share->SupportedExt;
310 This->ExtAL = &parent->share->ExtAL;
311 This->sources = parent->share->sources;
312 This->auxslot = parent->share->auxslot;
314 /* Allocate enough for a WAVEFORMATEXTENSIBLE */
315 wfx = &This->format.Format;
317 wfx->wFormatTag = WAVE_FORMAT_PCM;
318 wfx->nChannels = 2;
319 wfx->wBitsPerSample = 8;
320 wfx->nSamplesPerSec = 22050;
321 wfx->nBlockAlign = wfx->wBitsPerSample * wfx->nChannels / 8;
322 wfx->nAvgBytesPerSec = wfx->nSamplesPerSec * wfx->nBlockAlign;
323 wfx->cbSize = 0;
325 This->stopped = TRUE;
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->SupportedExt[SOFT_DEFERRED_UPDATES])
335 This->DeferUpdates = This->ExtAL->DeferUpdatesSOFT;
336 This->ProcessUpdates = This->ExtAL->ProcessUpdatesSOFT;
338 else
340 This->DeferUpdates = wrap_DeferUpdates;
341 This->ProcessUpdates = wrap_ProcessUpdates;
344 This->eax_prop = EnvironmentDefaults[EAX_ENVIRONMENT_GENERIC];
345 if(This->SupportedExt[EXT_EFX] && This->auxslot != 0)
347 ALint revid = alGetEnumValue("AL_EFFECT_REVERB");
348 if(revid != 0 && revid != -1)
350 This->ExtAL->GenEffects(1, &This->effect);
351 This->ExtAL->Effecti(This->effect, AL_EFFECT_TYPE, AL_EFFECT_REVERB);
352 checkALError();
356 /* Make sure DS3DListener defaults are applied to OpenAL */
357 listener = &This->params;
358 listener->dwSize = sizeof(This->params);
359 listener->vPosition.x = 0.0;
360 listener->vPosition.y = 0.0;
361 listener->vPosition.z = 0.0;
362 listener->vVelocity.x = 0.0;
363 listener->vVelocity.y = 0.0;
364 listener->vVelocity.z = 0.0;
365 listener->vOrientFront.x = 0.0;
366 listener->vOrientFront.y = 0.0;
367 listener->vOrientFront.z = 1.0;
368 listener->vOrientTop.x = 0.0;
369 listener->vOrientTop.y = 1.0;
370 listener->vOrientTop.z = 0.0;
371 listener->flDistanceFactor = DS3D_DEFAULTDISTANCEFACTOR;
372 listener->flRolloffFactor = DS3D_DEFAULTROLLOFFFACTOR;
373 listener->flDopplerFactor = DS3D_DEFAULTDOPPLERFACTOR;
374 hr = IDirectSound3DListener_SetAllParameters(&This->IDirectSound3DListener_iface, listener, DS3D_IMMEDIATE);
375 if(FAILED(hr))
376 ERR("Could not set 3d parameters: %08"LONGFMT"x\n", hr);
378 This->sizenotifies = This->sizebuffers = parent->share->max_sources;
380 hr = DSERR_OUTOFMEMORY;
381 This->buffers = HeapAlloc(GetProcessHeap(), 0, This->sizebuffers*sizeof(*This->buffers));
382 This->notifies = HeapAlloc(GetProcessHeap(), 0, This->sizenotifies*sizeof(*This->notifies));
383 if(!This->buffers || !This->notifies)
384 goto fail;
386 This->thread_hdl = CreateThread(NULL, 0, DS8Primary_thread, This, 0, &This->thread_id);
387 if(This->thread_hdl == NULL)
388 goto fail;
390 return S_OK;
392 fail:
393 DS8Primary_Clear(This);
394 return hr;
397 void DS8Primary_Clear(DS8Primary *This)
399 TRACE("Clearing primary %p\n", This);
401 if(!This->parent)
402 return;
404 if(This->thread_hdl)
406 PostThreadMessageA(This->thread_id, WM_QUIT, 0, 0);
407 if(WaitForSingleObject(This->thread_hdl, 1000) != WAIT_OBJECT_0)
409 /* HACK: Apparently, if the device is initialized (thus the primary
410 * buffer has PreInit called) then immediately deleted (the primary
411 * buffer has Clear called), the WM_QUIT message gets sent before
412 * the thread has a chance to run which apparently prevents it from
413 * receiving the message.
414 * If the wait attempt fails, try sending the message again. */
415 PostThreadMessageA(This->thread_id, WM_QUIT, 0, 0);
416 if(WaitForSingleObject(This->thread_hdl, 1000) != WAIT_OBJECT_0)
417 ERR("Thread wait timed out\n");
419 CloseHandle(This->thread_hdl);
422 setALContext(This->ctx);
423 if(This->effect)
424 This->ExtAL->DeleteEffects(1, &This->effect);
425 popALContext();
426 while(This->nbuffers--)
427 DS8Buffer_Destroy(This->buffers[This->nbuffers]);
429 HeapFree(GetProcessHeap(), 0, This->notifies);
430 HeapFree(GetProcessHeap(), 0, This->buffers);
431 memset(This, 0, sizeof(*This));
434 static HRESULT WINAPI DS8Primary_QueryInterface(IDirectSoundBuffer *iface, REFIID riid, LPVOID *ppv)
436 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
438 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
440 *ppv = NULL;
441 if(IsEqualIID(riid, &IID_IUnknown) ||
442 IsEqualIID(riid, &IID_IDirectSoundBuffer))
443 *ppv = &This->IDirectSoundBuffer_iface;
444 else if(IsEqualIID(riid, &IID_IDirectSound3DListener))
446 if((This->flags&DSBCAPS_CTRL3D))
447 *ppv = &This->IDirectSound3DListener_iface;
449 else
450 FIXME("Unhandled GUID: %s\n", debugstr_guid(riid));
452 if(*ppv)
454 IUnknown_AddRef((IUnknown*)*ppv);
455 return S_OK;
458 return E_NOINTERFACE;
461 static ULONG WINAPI DS8Primary_AddRef(IDirectSoundBuffer *iface)
463 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
464 LONG ret;
466 ret = InterlockedIncrement(&This->ref);
467 if(ret == 1) This->flags = 0;
469 return ret;
472 static ULONG WINAPI DS8Primary_Release(IDirectSoundBuffer *iface)
474 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
475 LONG ret;
477 ret = InterlockedDecrement(&This->ref);
479 return ret;
482 static HRESULT WINAPI DS8Primary_GetCaps(IDirectSoundBuffer *iface, DSBCAPS *caps)
484 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
486 TRACE("(%p)->(%p)\n", iface, caps);
488 if(!caps || caps->dwSize < sizeof(*caps))
490 WARN("Invalid DSBCAPS (%p, %"LONGFMT"u)\n", caps, caps ? caps->dwSize : 0);
491 return DSERR_INVALIDPARAM;
494 caps->dwFlags = This->flags;
495 caps->dwBufferBytes = This->buf_size;
496 caps->dwUnlockTransferRate = 0;
497 caps->dwPlayCpuOverhead = 0;
499 return DS_OK;
502 static HRESULT WINAPI DS8Primary_GetCurrentPosition(IDirectSoundBuffer *iface, DWORD *playpos, DWORD *curpos)
504 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
505 HRESULT hr = DSERR_PRIOLEVELNEEDED;
507 EnterCriticalSection(This->crst);
508 if(This->write_emu)
509 hr = IDirectSoundBuffer8_GetCurrentPosition(This->write_emu, playpos, curpos);
510 LeaveCriticalSection(This->crst);
512 return hr;
515 static HRESULT WINAPI DS8Primary_GetFormat(IDirectSoundBuffer *iface, WAVEFORMATEX *wfx, DWORD allocated, DWORD *written)
517 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
518 HRESULT hr = S_OK;
519 UINT size;
521 if(!wfx && !written)
523 WARN("Cannot report format or format size\n");
524 return DSERR_INVALIDPARAM;
527 EnterCriticalSection(This->crst);
528 size = sizeof(This->format.Format) + This->format.Format.cbSize;
529 if(written)
530 *written = size;
531 if(wfx)
533 if(allocated < size)
534 hr = DSERR_INVALIDPARAM;
535 else
536 memcpy(wfx, &This->format.Format, size);
538 LeaveCriticalSection(This->crst);
540 return hr;
543 static HRESULT WINAPI DS8Primary_GetVolume(IDirectSoundBuffer *iface, LONG *volume)
545 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
546 ALfloat gain;
548 TRACE("(%p)->(%p)\n", iface, volume);
550 if(!volume)
551 return DSERR_INVALIDPARAM;
552 *volume = 0;
554 if(!(This->flags&DSBCAPS_CTRLVOLUME))
555 return DSERR_CONTROLUNAVAIL;
557 setALContext(This->ctx);
558 alGetListenerf(AL_GAIN, &gain);
559 checkALError();
560 popALContext();
562 *volume = clampI(gain_to_mB(gain), DSBVOLUME_MIN, DSBVOLUME_MAX);
563 return DS_OK;
566 static HRESULT WINAPI DS8Primary_GetPan(IDirectSoundBuffer *iface, LONG *pan)
568 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
569 HRESULT hr = DS_OK;
571 WARN("(%p)->(%p): semi-stub\n", iface, pan);
573 if(!pan)
574 return DSERR_INVALIDPARAM;
576 EnterCriticalSection(This->crst);
577 if(This->write_emu)
578 hr = IDirectSoundBuffer8_GetPan(This->write_emu, pan);
579 else if(!(This->flags & DSBCAPS_CTRLPAN))
580 hr = DSERR_CONTROLUNAVAIL;
581 else
582 *pan = 0;
583 LeaveCriticalSection(This->crst);
585 return hr;
588 static HRESULT WINAPI DS8Primary_GetFrequency(IDirectSoundBuffer *iface, DWORD *freq)
590 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
591 HRESULT hr = DS_OK;
593 WARN("(%p)->(%p): semi-stub\n", iface, freq);
595 if(!freq)
596 return DSERR_INVALIDPARAM;
598 if(!(This->flags&DSBCAPS_CTRLFREQUENCY))
599 return DSERR_CONTROLUNAVAIL;
601 EnterCriticalSection(This->crst);
602 *freq = This->format.Format.nSamplesPerSec;
603 LeaveCriticalSection(This->crst);
605 return hr;
608 static HRESULT WINAPI DS8Primary_GetStatus(IDirectSoundBuffer *iface, DWORD *status)
610 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
612 TRACE("(%p)->(%p)\n", iface, status);
614 if(!status)
615 return DSERR_INVALIDPARAM;
617 EnterCriticalSection(This->crst);
618 *status = DSBSTATUS_PLAYING|DSBSTATUS_LOOPING;
619 if((This->flags&DSBCAPS_LOCDEFER))
620 *status |= DSBSTATUS_LOCHARDWARE;
622 if(This->stopped)
624 DWORD i, state;
625 HRESULT hr;
627 for(i = 0;i < This->nbuffers;++i)
629 hr = IDirectSoundBuffer8_GetStatus(&This->buffers[i]->IDirectSoundBuffer8_iface, &state);
630 if(SUCCEEDED(hr) && (state&DSBSTATUS_PLAYING))
631 break;
633 if(i == This->nbuffers)
635 /* Primary stopped and no buffers playing.. */
636 *status = 0;
639 LeaveCriticalSection(This->crst);
641 return DS_OK;
644 static HRESULT WINAPI DS8Primary_Initialize(IDirectSoundBuffer *iface, IDirectSound *ds, const DSBUFFERDESC *desc)
646 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
647 HRESULT hr;
649 TRACE("(%p)->(%p, %p)\n", iface, ds, desc);
651 if(!desc || desc->lpwfxFormat || desc->dwBufferBytes)
653 WARN("Bad DSBDESC for primary buffer\n");
654 return DSERR_INVALIDPARAM;
656 if((desc->dwFlags&DSBCAPS_CTRLFX) ||
657 (desc->dwFlags&DSBCAPS_CTRLPOSITIONNOTIFY) ||
658 (desc->dwFlags&DSBCAPS_LOCSOFTWARE))
660 WARN("Bad dwFlags %08"LONGFMT"x\n", desc->dwFlags);
661 return DSERR_INVALIDPARAM;
664 /* Should be 0 if not initialized */
665 if(This->flags)
666 return DSERR_ALREADYINITIALIZED;
668 hr = DS_OK;
669 if(This->parent->prio_level == DSSCL_WRITEPRIMARY)
671 DSBUFFERDESC emudesc;
672 DS8Buffer *emu;
674 if(This->write_emu)
676 ERR("There shouldn't be a write_emu!\n");
677 IDirectSoundBuffer8_Release(This->write_emu);
678 This->write_emu = NULL;
681 memset(&emudesc, 0, sizeof(emudesc));
682 emudesc.dwSize = sizeof(emudesc);
683 emudesc.dwFlags = DSBCAPS_LOCHARDWARE | (desc->dwFlags&DSBCAPS_CTRLPAN);
684 /* Dont play last incomplete sample */
685 emudesc.dwBufferBytes = This->buf_size - (This->buf_size%This->format.Format.nBlockAlign);
686 emudesc.lpwfxFormat = &This->format.Format;
688 hr = DS8Buffer_Create(&emu, This, NULL);
689 if(SUCCEEDED(hr))
691 This->write_emu = &emu->IDirectSoundBuffer8_iface;
692 hr = IDirectSoundBuffer8_Initialize(This->write_emu, ds, &emudesc);
693 if(FAILED(hr))
695 IDirectSoundBuffer8_Release(This->write_emu);
696 This->write_emu = NULL;
701 if(SUCCEEDED(hr))
702 This->flags = desc->dwFlags | DSBCAPS_LOCHARDWARE;
703 return hr;
706 static HRESULT WINAPI DS8Primary_Lock(IDirectSoundBuffer *iface, DWORD ofs, DWORD bytes, void **ptr1, DWORD *len1, void **ptr2, DWORD *len2, DWORD flags)
708 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
709 HRESULT hr = DSERR_PRIOLEVELNEEDED;
711 TRACE("(%p)->(%"LONGFMT"u, %"LONGFMT"u, %p, %p, %p, %p, %"LONGFMT"u)\n", iface, ofs, bytes, ptr1, len1, ptr2, len2, flags);
713 EnterCriticalSection(This->crst);
714 if(This->write_emu)
715 hr = IDirectSoundBuffer8_Lock(This->write_emu, ofs, bytes, ptr1, len1, ptr2, len2, flags);
716 LeaveCriticalSection(This->crst);
718 return hr;
721 static HRESULT WINAPI DS8Primary_Play(IDirectSoundBuffer *iface, DWORD res1, DWORD res2, DWORD flags)
723 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
724 HRESULT hr;
726 TRACE("(%p)->(%"LONGFMT"u, %"LONGFMT"u, %"LONGFMT"u)\n", iface, res1, res2, flags);
728 if(!(flags & DSBPLAY_LOOPING))
730 WARN("Flags (%08"LONGFMT"x) not set to DSBPLAY_LOOPING\n", flags);
731 return DSERR_INVALIDPARAM;
734 EnterCriticalSection(This->crst);
735 hr = S_OK;
736 if(This->write_emu)
737 hr = IDirectSoundBuffer8_Play(This->write_emu, res1, res2, flags);
738 if(SUCCEEDED(hr))
739 This->stopped = FALSE;
740 LeaveCriticalSection(This->crst);
742 return hr;
745 static HRESULT WINAPI DS8Primary_SetCurrentPosition(IDirectSoundBuffer *iface, DWORD pos)
747 WARN("(%p)->(%"LONGFMT"u)\n", iface, pos);
748 return DSERR_INVALIDCALL;
751 /* Just assume the format is crap, and clean up the damage */
752 static void copy_waveformat(WAVEFORMATEX *wfx, const WAVEFORMATEX *from)
754 if(from->wFormatTag == WAVE_FORMAT_PCM)
756 wfx->cbSize = 0;
757 if(from->wBitsPerSample == 8 ||
758 from->wBitsPerSample == 16 ||
759 from->wBitsPerSample == 24 ||
760 from->wBitsPerSample == 32)
761 wfx->wBitsPerSample = from->wBitsPerSample;
763 else if(from->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
765 WAVEFORMATEXTENSIBLE *wfe = (WAVEFORMATEXTENSIBLE*)wfx;
766 const WAVEFORMATEXTENSIBLE *fromx = (const WAVEFORMATEXTENSIBLE*)from;
767 DWORD size = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
769 /* Fail silently.. */
770 if(from->cbSize < size)
771 return;
772 if(!fromx->Samples.wValidBitsPerSample &&
773 !fromx->Format.wBitsPerSample)
774 return;
776 if(!IsEqualGUID(&wfe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM) &&
777 !IsEqualGUID(&wfe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT))
779 ERR("Unhandled extensible format: %s\n", debugstr_guid(&wfe->SubFormat));
780 return;
783 wfe->Format.wBitsPerSample = from->wBitsPerSample;
784 wfe->Samples.wValidBitsPerSample = fromx->Samples.wValidBitsPerSample;
785 if(!wfe->Samples.wValidBitsPerSample)
786 wfe->Samples.wValidBitsPerSample = wfe->Format.wBitsPerSample;
787 wfe->Format.cbSize = size;
788 wfe->dwChannelMask = fromx->dwChannelMask;
789 wfe->SubFormat = fromx->SubFormat;
791 else
793 ERR("Unhandled format tag %04x\n", from->wFormatTag);
794 return;
797 if(from->nChannels)
798 wfx->nChannels = from->nChannels;
799 wfx->wFormatTag = from->wFormatTag;
800 if(from->nSamplesPerSec >= DSBFREQUENCY_MIN &&
801 from->nSamplesPerSec <= DSBFREQUENCY_MAX)
802 wfx->nSamplesPerSec = from->nSamplesPerSec;
803 wfx->nBlockAlign = wfx->wBitsPerSample * wfx->nChannels / 8;
804 wfx->nAvgBytesPerSec = wfx->nSamplesPerSec * wfx->nBlockAlign;
807 static HRESULT WINAPI DS8Primary_SetFormat(IDirectSoundBuffer *iface, const WAVEFORMATEX *wfx)
809 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
810 HRESULT hr = S_OK;
811 ALCint freq;
813 TRACE("(%p)->(%p)\n", iface, wfx);
815 if(!wfx)
817 WARN("Missing format\n");
818 return DSERR_INVALIDPARAM;
821 EnterCriticalSection(This->crst);
823 if(This->parent->prio_level < DSSCL_PRIORITY)
825 hr = DSERR_PRIOLEVELNEEDED;
826 goto out;
829 TRACE("Requested primary format:\n"
830 " FormatTag = %04x\n"
831 " Channels = %u\n"
832 " SamplesPerSec = %"LONGFMT"u\n"
833 " AvgBytesPerSec = %"LONGFMT"u\n"
834 " BlockAlign = %u\n"
835 " BitsPerSample = %u\n",
836 wfx->wFormatTag, wfx->nChannels,
837 wfx->nSamplesPerSec, wfx->nAvgBytesPerSec,
838 wfx->nBlockAlign, wfx->wBitsPerSample);
840 copy_waveformat(&This->format.Format, wfx);
842 freq = This->format.Format.nSamplesPerSec;
843 alcGetIntegerv(This->parent->device, ALC_FREQUENCY, 1, &freq);
844 checkALCError(This->parent->device);
846 This->format.Format.nSamplesPerSec = freq;
847 This->format.Format.nAvgBytesPerSec = This->format.Format.nBlockAlign *
848 This->format.Format.nSamplesPerSec;
850 if(This->write_emu)
852 DS8Buffer *buf;
853 DSBUFFERDESC desc;
855 memset(&desc, 0, sizeof(desc));
856 desc.dwSize = sizeof(desc);
857 desc.dwFlags = DSBCAPS_LOCHARDWARE|DSBCAPS_CTRLPAN;
858 desc.dwBufferBytes = This->buf_size - (This->buf_size % This->format.Format.nBlockAlign);
859 desc.lpwfxFormat = &This->format.Format;
861 hr = DS8Buffer_Create(&buf, This, NULL);
862 if(FAILED(hr))
863 goto out;
865 hr = IDirectSoundBuffer8_Initialize(&buf->IDirectSoundBuffer8_iface, &This->parent->IDirectSound_iface, &desc);
866 if(FAILED(hr))
867 DS8Buffer_Destroy(buf);
868 else
870 IDirectSoundBuffer8_Release(This->write_emu);
871 This->write_emu = &buf->IDirectSoundBuffer8_iface;
875 out:
876 LeaveCriticalSection(This->crst);
877 return hr;
880 static HRESULT WINAPI DS8Primary_SetVolume(IDirectSoundBuffer *iface, LONG vol)
882 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
884 TRACE("(%p)->(%"LONGFMT"d)\n", iface, vol);
886 if(vol > DSBVOLUME_MAX || vol < DSBVOLUME_MIN)
888 WARN("Invalid volume (%"LONGFMT"d)\n", vol);
889 return DSERR_INVALIDPARAM;
892 if(!(This->flags&DSBCAPS_CTRLVOLUME))
893 return DSERR_CONTROLUNAVAIL;
895 setALContext(This->ctx);
896 alListenerf(AL_GAIN, mB_to_gain(vol));
897 popALContext();
899 return DS_OK;
902 static HRESULT WINAPI DS8Primary_SetPan(IDirectSoundBuffer *iface, LONG pan)
904 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
905 HRESULT hr;
907 TRACE("(%p)->(%"LONGFMT"d)\n", iface, pan);
909 if(pan > DSBPAN_RIGHT || pan < DSBPAN_LEFT)
911 WARN("invalid parameter: pan = %"LONGFMT"d\n", pan);
912 return DSERR_INVALIDPARAM;
915 EnterCriticalSection(This->crst);
916 if(!(This->flags&DSBCAPS_CTRLPAN))
918 WARN("control unavailable\n");
919 hr = DSERR_CONTROLUNAVAIL;
921 else if(This->write_emu)
922 hr = IDirectSoundBuffer8_SetPan(This->write_emu, pan);
923 else
925 FIXME("Not supported\n");
926 hr = E_NOTIMPL;
928 LeaveCriticalSection(This->crst);
930 return hr;
933 static HRESULT WINAPI DS8Primary_SetFrequency(IDirectSoundBuffer *iface, DWORD freq)
935 WARN("(%p)->(%"LONGFMT"u)\n", iface, freq);
936 return DSERR_CONTROLUNAVAIL;
939 static HRESULT WINAPI DS8Primary_Stop(IDirectSoundBuffer *iface)
941 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
942 HRESULT hr = S_OK;
944 TRACE("(%p)->()\n", iface);
946 EnterCriticalSection(This->crst);
947 if(This->write_emu)
948 hr = IDirectSoundBuffer8_Stop(This->write_emu);
949 if(SUCCEEDED(hr))
950 This->stopped = TRUE;
951 LeaveCriticalSection(This->crst);
953 return hr;
956 static HRESULT WINAPI DS8Primary_Unlock(IDirectSoundBuffer *iface, void *ptr1, DWORD len1, void *ptr2, DWORD len2)
958 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
959 HRESULT hr = DSERR_INVALIDCALL;
961 TRACE("(%p)->(%p, %"LONGFMT"u, %p, %"LONGFMT"u)\n", iface, ptr1, len1, ptr2, len2);
963 EnterCriticalSection(This->crst);
964 if(This->write_emu)
965 hr = IDirectSoundBuffer8_Unlock(This->write_emu, ptr1, len1, ptr2, len2);
966 LeaveCriticalSection(This->crst);
968 return hr;
971 static HRESULT WINAPI DS8Primary_Restore(IDirectSoundBuffer *iface)
973 DS8Primary *This = impl_from_IDirectSoundBuffer(iface);
974 HRESULT hr = S_OK;
976 TRACE("(%p)->()\n", iface);
978 EnterCriticalSection(This->crst);
979 if(This->write_emu)
980 hr = IDirectSoundBuffer8_Restore(This->write_emu);
981 LeaveCriticalSection(This->crst);
983 return hr;
986 static const IDirectSoundBufferVtbl DS8Primary_Vtbl =
988 DS8Primary_QueryInterface,
989 DS8Primary_AddRef,
990 DS8Primary_Release,
991 DS8Primary_GetCaps,
992 DS8Primary_GetCurrentPosition,
993 DS8Primary_GetFormat,
994 DS8Primary_GetVolume,
995 DS8Primary_GetPan,
996 DS8Primary_GetFrequency,
997 DS8Primary_GetStatus,
998 DS8Primary_Initialize,
999 DS8Primary_Lock,
1000 DS8Primary_Play,
1001 DS8Primary_SetCurrentPosition,
1002 DS8Primary_SetFormat,
1003 DS8Primary_SetVolume,
1004 DS8Primary_SetPan,
1005 DS8Primary_SetFrequency,
1006 DS8Primary_Stop,
1007 DS8Primary_Unlock,
1008 DS8Primary_Restore
1012 static void DS8Primary_SetParams(DS8Primary *This, const DS3DLISTENER *params, LONG flags)
1014 union PrimaryParamFlags dirty = { flags };
1015 DWORD i;
1017 if(dirty.bit.pos)
1018 alListener3f(AL_POSITION, params->vPosition.x, params->vPosition.y,
1019 -params->vPosition.z);
1020 if(dirty.bit.vel)
1021 alListener3f(AL_VELOCITY, params->vVelocity.x, params->vVelocity.y,
1022 -params->vVelocity.z);
1023 if(dirty.bit.orientation)
1025 ALfloat orient[6] = {
1026 params->vOrientFront.x, params->vOrientFront.y, -params->vOrientFront.z,
1027 params->vOrientTop.x, params->vOrientTop.y, -params->vOrientTop.z
1029 alListenerfv(AL_ORIENTATION, orient);
1031 if(dirty.bit.distancefactor)
1033 alSpeedOfSound(343.3f/params->flDistanceFactor);
1034 if(This->SupportedExt[EXT_EFX])
1035 alListenerf(AL_METERS_PER_UNIT, params->flDistanceFactor);
1037 if(dirty.bit.rollofffactor)
1039 ALfloat rolloff = params->flRolloffFactor;
1040 This->rollofffactor = rolloff;
1041 for(i = 0;i < This->nbuffers;++i)
1043 const DS8Buffer *buf = This->buffers[i];
1044 if(buf->ds3dmode != DS3DMODE_DISABLE)
1045 alSourcef(buf->source, AL_ROLLOFF_FACTOR, rolloff);
1048 if(dirty.bit.dopplerfactor)
1049 alDopplerFactor(params->flDopplerFactor);
1050 if(dirty.bit.effect)
1051 This->ExtAL->AuxiliaryEffectSloti(This->auxslot, AL_EFFECTSLOT_EFFECT, This->effect);
1054 static HRESULT WINAPI DS8Primary3D_QueryInterface(IDirectSound3DListener *iface, REFIID riid, void **ppv)
1056 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1057 return DS8Primary_QueryInterface(&This->IDirectSoundBuffer_iface, riid, ppv);
1060 static ULONG WINAPI DS8Primary3D_AddRef(IDirectSound3DListener *iface)
1062 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1063 LONG ret;
1065 ret = InterlockedIncrement(&This->ds3d_ref);
1066 TRACE("new refcount %"LONGFMT"d\n", ret);
1068 return ret;
1071 static ULONG WINAPI DS8Primary3D_Release(IDirectSound3DListener *iface)
1073 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1074 LONG ret;
1076 ret = InterlockedDecrement(&This->ds3d_ref);
1077 TRACE("new refcount %"LONGFMT"d\n", ret);
1079 return ret;
1083 static HRESULT WINAPI DS8Primary3D_GetAllParameters(IDirectSound3DListener *iface, DS3DLISTENER *listener)
1085 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1087 TRACE("(%p)->(%p)\n", iface, listener);
1089 if(!listener || listener->dwSize < sizeof(*listener))
1091 WARN("Invalid DS3DLISTENER %p %"LONGFMT"u\n", listener, listener ? listener->dwSize : 0);
1092 return DSERR_INVALIDPARAM;
1095 EnterCriticalSection(This->crst);
1096 setALContext(This->ctx);
1097 IDirectSound3DListener_GetPosition(iface, &listener->vPosition);
1098 IDirectSound3DListener_GetVelocity(iface, &listener->vVelocity);
1099 IDirectSound3DListener_GetOrientation(iface, &listener->vOrientFront, &listener->vOrientTop);
1100 IDirectSound3DListener_GetDistanceFactor(iface, &listener->flDistanceFactor);
1101 IDirectSound3DListener_GetRolloffFactor(iface, &listener->flRolloffFactor);
1102 IDirectSound3DListener_GetDopplerFactor(iface, &listener->flDopplerFactor);
1103 popALContext();
1104 LeaveCriticalSection(This->crst);
1106 return DS_OK;
1109 static HRESULT WINAPI DS8Primary3D_GetDistanceFactor(IDirectSound3DListener *iface, D3DVALUE *distancefactor)
1111 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1113 TRACE("(%p)->(%p)\n", iface, distancefactor);
1115 if(!distancefactor)
1117 WARN("Invalid parameter %p\n", distancefactor);
1118 return DSERR_INVALIDPARAM;
1121 setALContext(This->ctx);
1122 *distancefactor = 343.3f/alGetFloat(AL_SPEED_OF_SOUND);
1123 checkALError();
1124 popALContext();
1126 return S_OK;
1129 static HRESULT WINAPI DS8Primary3D_GetDopplerFactor(IDirectSound3DListener *iface, D3DVALUE *dopplerfactor)
1131 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1133 TRACE("(%p)->(%p)\n", iface, dopplerfactor);
1135 if(!dopplerfactor)
1137 WARN("Invalid parameter %p\n", dopplerfactor);
1138 return DSERR_INVALIDPARAM;
1141 setALContext(This->ctx);
1142 *dopplerfactor = alGetFloat(AL_DOPPLER_FACTOR);
1143 checkALError();
1144 popALContext();
1146 return S_OK;
1149 static HRESULT WINAPI DS8Primary3D_GetOrientation(IDirectSound3DListener *iface, D3DVECTOR *front, D3DVECTOR *top)
1151 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1152 ALfloat orient[6];
1154 TRACE("(%p)->(%p, %p)\n", iface, front, top);
1156 if(!front || !top)
1158 WARN("Invalid parameter %p %p\n", front, top);
1159 return DSERR_INVALIDPARAM;
1162 setALContext(This->ctx);
1163 alGetListenerfv(AL_ORIENTATION, orient);
1164 checkALError();
1165 popALContext();
1167 front->x = orient[0];
1168 front->y = orient[1];
1169 front->z = -orient[2];
1170 top->x = orient[3];
1171 top->y = orient[4];
1172 top->z = -orient[5];
1173 return S_OK;
1176 static HRESULT WINAPI DS8Primary3D_GetPosition(IDirectSound3DListener *iface, D3DVECTOR *pos)
1178 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1179 ALfloat alpos[3];
1181 TRACE("(%p)->(%p)\n", iface, pos);
1183 if(!pos)
1185 WARN("Invalid parameter %p\n", pos);
1186 return DSERR_INVALIDPARAM;
1189 setALContext(This->ctx);
1190 alGetListenerfv(AL_POSITION, alpos);
1191 checkALError();
1192 popALContext();
1194 pos->x = alpos[0];
1195 pos->y = alpos[1];
1196 pos->z = -alpos[2];
1197 return S_OK;
1200 static HRESULT WINAPI DS8Primary3D_GetRolloffFactor(IDirectSound3DListener *iface, D3DVALUE *rollofffactor)
1202 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1204 TRACE("(%p)->(%p)\n", iface, rollofffactor);
1206 if(!rollofffactor)
1208 WARN("Invalid parameter %p\n", rollofffactor);
1209 return DSERR_INVALIDPARAM;
1212 EnterCriticalSection(This->crst);
1213 *rollofffactor = This->rollofffactor;
1214 LeaveCriticalSection(This->crst);
1216 return S_OK;
1219 static HRESULT WINAPI DS8Primary3D_GetVelocity(IDirectSound3DListener *iface, D3DVECTOR *velocity)
1221 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1222 ALfloat vel[3];
1224 TRACE("(%p)->(%p)\n", iface, velocity);
1226 if(!velocity)
1228 WARN("Invalid parameter %p\n", velocity);
1229 return DSERR_INVALIDPARAM;
1232 setALContext(This->ctx);
1233 alGetListenerfv(AL_VELOCITY, vel);
1234 checkALError();
1235 popALContext();
1237 velocity->x = vel[0];
1238 velocity->y = vel[1];
1239 velocity->z = -vel[2];
1240 return S_OK;
1243 static HRESULT WINAPI DS8Primary3D_SetAllParameters(IDirectSound3DListener *iface, const DS3DLISTENER *listen, DWORD apply)
1245 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1247 TRACE("(%p)->(%p, %"LONGFMT"u)\n", iface, listen, apply);
1249 if(!listen || listen->dwSize < sizeof(*listen))
1251 WARN("Invalid parameter %p %"LONGFMT"u\n", listen, listen ? listen->dwSize : 0);
1252 return DSERR_INVALIDPARAM;
1255 if(listen->flDistanceFactor > DS3D_MAXDISTANCEFACTOR ||
1256 listen->flDistanceFactor < DS3D_MINDISTANCEFACTOR)
1258 WARN("Invalid distance factor (%f)\n", listen->flDistanceFactor);
1259 return DSERR_INVALIDPARAM;
1262 if(listen->flDopplerFactor > DS3D_MAXDOPPLERFACTOR ||
1263 listen->flDopplerFactor < DS3D_MINDOPPLERFACTOR)
1265 WARN("Invalid doppler factor (%f)\n", listen->flDopplerFactor);
1266 return DSERR_INVALIDPARAM;
1269 if(listen->flRolloffFactor < DS3D_MINROLLOFFFACTOR ||
1270 listen->flRolloffFactor > DS3D_MAXROLLOFFFACTOR)
1272 WARN("Invalid rolloff factor (%f)\n", listen->flRolloffFactor);
1273 return DSERR_INVALIDPARAM;
1276 if(apply == DS3D_DEFERRED)
1278 EnterCriticalSection(This->crst);
1279 This->params = *listen;
1280 This->params.dwSize = sizeof(This->params);
1281 This->dirty.bit.pos = 1;
1282 This->dirty.bit.vel = 1;
1283 This->dirty.bit.orientation = 1;
1284 This->dirty.bit.distancefactor = 1;
1285 This->dirty.bit.rollofffactor = 1;
1286 This->dirty.bit.dopplerfactor = 1;
1287 LeaveCriticalSection(This->crst);
1289 else
1291 union PrimaryParamFlags dirty = { 0l };
1292 dirty.bit.pos = 1;
1293 dirty.bit.vel = 1;
1294 dirty.bit.orientation = 1;
1295 dirty.bit.distancefactor = 1;
1296 dirty.bit.rollofffactor = 1;
1297 dirty.bit.dopplerfactor = 1;
1299 EnterCriticalSection(This->crst);
1300 setALContext(This->ctx);
1301 DS8Primary_SetParams(This, listen, dirty.flags);
1302 checkALError();
1303 popALContext();
1304 LeaveCriticalSection(This->crst);
1307 return S_OK;
1310 static HRESULT WINAPI DS8Primary3D_SetDistanceFactor(IDirectSound3DListener *iface, D3DVALUE factor, DWORD apply)
1312 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1314 TRACE("(%p)->(%f, %"LONGFMT"u)\n", iface, factor, apply);
1316 if(factor < DS3D_MINDISTANCEFACTOR ||
1317 factor > DS3D_MAXDISTANCEFACTOR)
1319 WARN("Invalid parameter %f\n", factor);
1320 return DSERR_INVALIDPARAM;
1323 if(apply == DS3D_DEFERRED)
1325 EnterCriticalSection(This->crst);
1326 This->params.flDistanceFactor = factor;
1327 This->dirty.bit.distancefactor = 1;
1328 LeaveCriticalSection(This->crst);
1330 else
1332 setALContext(This->ctx);
1333 alSpeedOfSound(343.3f/factor);
1334 if(This->SupportedExt[EXT_EFX])
1335 alListenerf(AL_METERS_PER_UNIT, factor);
1336 checkALError();
1337 popALContext();
1340 return S_OK;
1343 static HRESULT WINAPI DS8Primary3D_SetDopplerFactor(IDirectSound3DListener *iface, D3DVALUE factor, DWORD apply)
1345 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1347 TRACE("(%p)->(%f, %"LONGFMT"u)\n", iface, factor, apply);
1349 if(factor < DS3D_MINDOPPLERFACTOR ||
1350 factor > DS3D_MAXDOPPLERFACTOR)
1352 WARN("Invalid parameter %f\n", factor);
1353 return DSERR_INVALIDPARAM;
1356 if(apply == DS3D_DEFERRED)
1358 EnterCriticalSection(This->crst);
1359 This->params.flDopplerFactor = factor;
1360 This->dirty.bit.dopplerfactor = 1;
1361 LeaveCriticalSection(This->crst);
1363 else
1365 setALContext(This->ctx);
1366 alDopplerFactor(factor);
1367 checkALError();
1368 popALContext();
1371 return S_OK;
1374 static HRESULT WINAPI DS8Primary3D_SetOrientation(IDirectSound3DListener *iface, D3DVALUE xFront, D3DVALUE yFront, D3DVALUE zFront, D3DVALUE xTop, D3DVALUE yTop, D3DVALUE zTop, DWORD apply)
1376 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1378 TRACE("(%p)->(%f, %f, %f, %f, %f, %f, %"LONGFMT"u)\n", iface, xFront, yFront, zFront, xTop, yTop, zTop, apply);
1380 if(apply == DS3D_DEFERRED)
1382 EnterCriticalSection(This->crst);
1383 This->params.vOrientFront.x = xFront;
1384 This->params.vOrientFront.y = yFront;
1385 This->params.vOrientFront.z = zFront;
1386 This->params.vOrientTop.x = xTop;
1387 This->params.vOrientTop.y = yTop;
1388 This->params.vOrientTop.z = zTop;
1389 This->dirty.bit.orientation = 1;
1390 LeaveCriticalSection(This->crst);
1392 else
1394 ALfloat orient[6] = {
1395 xFront, yFront, -zFront,
1396 xTop, yTop, -zTop
1398 setALContext(This->ctx);
1399 alListenerfv(AL_ORIENTATION, orient);
1400 checkALError();
1401 popALContext();
1404 return S_OK;
1407 static HRESULT WINAPI DS8Primary3D_SetPosition(IDirectSound3DListener *iface, D3DVALUE x, D3DVALUE y, D3DVALUE z, DWORD apply)
1409 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1411 TRACE("(%p)->(%f, %f, %f, %"LONGFMT"u)\n", iface, x, y, z, apply);
1413 if(apply == DS3D_DEFERRED)
1415 EnterCriticalSection(This->crst);
1416 This->params.vPosition.x = x;
1417 This->params.vPosition.y = y;
1418 This->params.vPosition.z = z;
1419 This->dirty.bit.pos = 1;
1420 LeaveCriticalSection(This->crst);
1422 else
1424 setALContext(This->ctx);
1425 alListener3f(AL_POSITION, x, y, -z);
1426 checkALError();
1427 popALContext();
1430 return S_OK;
1433 static HRESULT WINAPI DS8Primary3D_SetRolloffFactor(IDirectSound3DListener *iface, D3DVALUE factor, DWORD apply)
1435 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1437 TRACE("(%p)->(%f, %"LONGFMT"u)\n", iface, factor, apply);
1439 if(factor < DS3D_MINROLLOFFFACTOR ||
1440 factor > DS3D_MAXROLLOFFFACTOR)
1442 WARN("Invalid parameter %f\n", factor);
1443 return DSERR_INVALIDPARAM;
1446 EnterCriticalSection(This->crst);
1447 if(apply == DS3D_DEFERRED)
1449 This->params.flRolloffFactor = factor;
1450 This->dirty.bit.rollofffactor = 1;
1452 else
1454 DWORD i;
1456 setALContext(This->ctx);
1457 for(i = 0;i < This->nbuffers;++i)
1459 if(This->buffers[i]->ds3dmode != DS3DMODE_DISABLE)
1460 alSourcef(This->buffers[i]->source, AL_ROLLOFF_FACTOR, factor);
1462 checkALError();
1463 popALContext();
1465 This->rollofffactor = factor;
1467 LeaveCriticalSection(This->crst);
1469 return S_OK;
1472 static HRESULT WINAPI DS8Primary3D_SetVelocity(IDirectSound3DListener *iface, D3DVALUE x, D3DVALUE y, D3DVALUE z, DWORD apply)
1474 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1476 TRACE("(%p)->(%f, %f, %f, %"LONGFMT"u)\n", iface, x, y, z, apply);
1478 if(apply == DS3D_DEFERRED)
1480 EnterCriticalSection(This->crst);
1481 This->params.vVelocity.x = x;
1482 This->params.vVelocity.y = y;
1483 This->params.vVelocity.z = z;
1484 This->dirty.bit.vel = 1;
1485 LeaveCriticalSection(This->crst);
1487 else
1489 setALContext(This->ctx);
1490 alListener3f(AL_VELOCITY, x, y, -z);
1491 checkALError();
1492 popALContext();
1495 return S_OK;
1498 static HRESULT WINAPI DS8Primary3D_CommitDeferredSettings(IDirectSound3DListener *iface)
1500 DS8Primary *This = impl_from_IDirectSound3DListener(iface);
1501 LONG flags;
1502 DWORD i;
1504 EnterCriticalSection(This->crst);
1505 setALContext(This->ctx);
1506 This->DeferUpdates();
1508 if((flags=InterlockedExchange(&This->dirty.flags, 0)) != 0)
1510 DS8Primary_SetParams(This, &This->params, flags);
1511 /* checkALError is here for debugging */
1512 checkALError();
1514 TRACE("Dirty flags was: 0x%02x\n", flags);
1516 for(i = 0;i < This->nbuffers;++i)
1518 DS8Buffer *buf = This->buffers[i];
1520 if((flags=InterlockedExchange(&buf->dirty.flags, 0)) != 0)
1521 DS8Buffer_SetParams(buf, &buf->params, flags);
1523 checkALError();
1525 This->ProcessUpdates();
1526 popALContext();
1527 LeaveCriticalSection(This->crst);
1529 return DS_OK;
1532 static const IDirectSound3DListenerVtbl DS8Primary3D_Vtbl =
1534 DS8Primary3D_QueryInterface,
1535 DS8Primary3D_AddRef,
1536 DS8Primary3D_Release,
1537 DS8Primary3D_GetAllParameters,
1538 DS8Primary3D_GetDistanceFactor,
1539 DS8Primary3D_GetDopplerFactor,
1540 DS8Primary3D_GetOrientation,
1541 DS8Primary3D_GetPosition,
1542 DS8Primary3D_GetRolloffFactor,
1543 DS8Primary3D_GetVelocity,
1544 DS8Primary3D_SetAllParameters,
1545 DS8Primary3D_SetDistanceFactor,
1546 DS8Primary3D_SetDopplerFactor,
1547 DS8Primary3D_SetOrientation,
1548 DS8Primary3D_SetPosition,
1549 DS8Primary3D_SetRolloffFactor,
1550 DS8Primary3D_SetVelocity,
1551 DS8Primary3D_CommitDeferredSettings
1554 /* NOTE: Although the app handles listener properties through secondary buffers,
1555 * we pass the requests to the primary buffer though a propertyset interface.
1556 * These methods are not exposed to the app. */
1557 static HRESULT WINAPI DS8PrimaryProp_QueryInterface(IKsPropertySet *iface, REFIID riid, void **ppv)
1559 DS8Primary *This = impl_from_IKsPropertySet(iface);
1560 return DS8Primary_QueryInterface(&This->IDirectSoundBuffer_iface, riid, ppv);
1563 static ULONG WINAPI DS8PrimaryProp_AddRef(IKsPropertySet *iface)
1565 DS8Primary *This = impl_from_IKsPropertySet(iface);
1566 LONG ret;
1568 ret = InterlockedIncrement(&This->prop_ref);
1569 TRACE("new refcount %"LONGFMT"d\n", ret);
1571 return ret;
1574 static ULONG WINAPI DS8PrimaryProp_Release(IKsPropertySet *iface)
1576 DS8Primary *This = impl_from_IKsPropertySet(iface);
1577 LONG ret;
1579 ret = InterlockedDecrement(&This->prop_ref);
1580 TRACE("new refcount %"LONGFMT"d\n", ret);
1582 return ret;
1585 static HRESULT WINAPI DS8PrimaryProp_Get(IKsPropertySet *iface,
1586 REFGUID guidPropSet, ULONG dwPropID,
1587 LPVOID pInstanceData, ULONG cbInstanceData,
1588 LPVOID pPropData, ULONG cbPropData,
1589 PULONG pcbReturned)
1591 DS8Primary *This = impl_from_IKsPropertySet(iface);
1592 HRESULT res = E_PROP_ID_UNSUPPORTED;
1593 (void)pInstanceData;
1594 (void)cbInstanceData;
1596 if(IsEqualIID(guidPropSet, &DSPROPSETID_EAX20_ListenerProperties))
1598 EnterCriticalSection(This->crst);
1600 if(This->effect == 0)
1601 res = E_PROP_ID_UNSUPPORTED;
1602 else switch(dwPropID)
1604 case DSPROPERTY_EAXLISTENER_ALLPARAMETERS:
1605 res = DSERR_INVALIDPARAM;
1606 if(cbPropData >= sizeof(EAXLISTENERPROPERTIES))
1608 union {
1609 void *v;
1610 EAXLISTENERPROPERTIES *props;
1611 } data = { pPropData };
1613 *data.props = This->eax_prop;
1614 *pcbReturned = sizeof(EAXLISTENERPROPERTIES);
1615 res = DS_OK;
1617 break;
1619 case DSPROPERTY_EAXLISTENER_ROOM:
1620 res = DSERR_INVALIDPARAM;
1621 if(cbPropData >= sizeof(LONG))
1623 union {
1624 void *v;
1625 LONG *l;
1626 } data = { pPropData };
1628 *data.l = This->eax_prop.lRoom;
1629 *pcbReturned = sizeof(LONG);
1630 res = DS_OK;
1632 break;
1633 case DSPROPERTY_EAXLISTENER_ROOMHF:
1634 res = DSERR_INVALIDPARAM;
1635 if(cbPropData >= sizeof(LONG))
1637 union {
1638 void *v;
1639 LONG *l;
1640 } data = { pPropData };
1642 *data.l = This->eax_prop.lRoomHF;
1643 *pcbReturned = sizeof(LONG);
1644 res = DS_OK;
1646 break;
1648 case DSPROPERTY_EAXLISTENER_ROOMROLLOFFFACTOR:
1649 res = DSERR_INVALIDPARAM;
1650 if(cbPropData >= sizeof(FLOAT))
1652 union {
1653 void *v;
1654 FLOAT *fl;
1655 } data = { pPropData };
1657 *data.fl = This->eax_prop.flRoomRolloffFactor;
1658 *pcbReturned = sizeof(FLOAT);
1659 res = DS_OK;
1661 break;
1663 case DSPROPERTY_EAXLISTENER_ENVIRONMENT:
1664 res = DSERR_INVALIDPARAM;
1665 if(cbPropData >= sizeof(DWORD))
1667 union {
1668 void *v;
1669 DWORD *dw;
1670 } data = { pPropData };
1672 *data.dw = This->eax_prop.dwEnvironment;
1673 *pcbReturned = sizeof(DWORD);
1674 res = DS_OK;
1676 break;
1678 case DSPROPERTY_EAXLISTENER_ENVIRONMENTSIZE:
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.flEnvironmentSize;
1688 *pcbReturned = sizeof(FLOAT);
1689 res = DS_OK;
1691 break;
1692 case DSPROPERTY_EAXLISTENER_ENVIRONMENTDIFFUSION:
1693 res = DSERR_INVALIDPARAM;
1694 if(cbPropData >= sizeof(FLOAT))
1696 union {
1697 void *v;
1698 FLOAT *fl;
1699 } data = { pPropData };
1701 *data.fl = This->eax_prop.flEnvironmentDiffusion;
1702 *pcbReturned = sizeof(FLOAT);
1703 res = DS_OK;
1705 break;
1707 case DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF:
1708 res = DSERR_INVALIDPARAM;
1709 if(cbPropData >= sizeof(FLOAT))
1711 union {
1712 void *v;
1713 FLOAT *fl;
1714 } data = { pPropData };
1716 *data.fl = This->eax_prop.flAirAbsorptionHF;
1717 *pcbReturned = sizeof(FLOAT);
1718 res = DS_OK;
1720 break;
1722 case DSPROPERTY_EAXLISTENER_FLAGS:
1723 res = DSERR_INVALIDPARAM;
1724 if(cbPropData >= sizeof(DWORD))
1726 union {
1727 void *v;
1728 DWORD *dw;
1729 } data = { pPropData };
1731 *data.dw = This->eax_prop.dwFlags;
1732 *pcbReturned = sizeof(DWORD);
1733 res = DS_OK;
1735 break;
1737 default:
1738 FIXME("Unhandled propid: 0x%08"LONGFMT"x\n", dwPropID);
1739 break;
1742 LeaveCriticalSection(This->crst);
1744 else
1745 FIXME("Unhandled propset: %s\n", debugstr_guid(guidPropSet));
1747 return res;
1750 static HRESULT WINAPI DS8PrimaryProp_Set(IKsPropertySet *iface,
1751 REFGUID guidPropSet, ULONG dwPropID,
1752 LPVOID pInstanceData, ULONG cbInstanceData,
1753 LPVOID pPropData, ULONG cbPropData)
1755 DS8Primary *This = impl_from_IKsPropertySet(iface);
1756 HRESULT res = E_PROP_ID_UNSUPPORTED;
1757 (void)pInstanceData;
1758 (void)cbInstanceData;
1760 if(IsEqualIID(guidPropSet, &DSPROPSETID_EAX20_ListenerProperties))
1762 DWORD propid = dwPropID & ~DSPROPERTY_EAXLISTENER_DEFERRED;
1763 BOOL immediate = !(dwPropID&DSPROPERTY_EAXLISTENER_DEFERRED);
1765 EnterCriticalSection(This->crst);
1766 setALContext(This->ctx);
1768 if(This->effect == 0)
1769 res = E_PROP_ID_UNSUPPORTED;
1770 else switch(propid)
1772 case 0: /* 0 = not setting any property, just apply */
1773 res = DS_OK;
1774 break;
1776 case DSPROPERTY_EAXLISTENER_ALLPARAMETERS:
1777 do_allparams:
1778 res = DSERR_INVALIDPARAM;
1779 if(cbPropData >= sizeof(EAXLISTENERPROPERTIES))
1781 union {
1782 const void *v;
1783 const EAXLISTENERPROPERTIES *props;
1784 } data = { pPropData };
1786 /* FIXME: Need to validate property values... Ignore? Clamp? Error? */
1787 This->eax_prop = *data.props;
1788 This->ExtAL->Effectf(This->effect, AL_REVERB_DENSITY,
1789 (data.props->flEnvironmentSize < 2.0f) ?
1790 (data.props->flEnvironmentSize - 1.0f) : 1.0f);
1791 This->ExtAL->Effectf(This->effect, AL_REVERB_DIFFUSION,
1792 data.props->flEnvironmentDiffusion);
1794 This->ExtAL->Effectf(This->effect, AL_REVERB_GAIN,
1795 mB_to_gain(data.props->lRoom));
1796 This->ExtAL->Effectf(This->effect, AL_REVERB_GAINHF,
1797 mB_to_gain(data.props->lRoomHF));
1799 This->ExtAL->Effectf(This->effect, AL_REVERB_ROOM_ROLLOFF_FACTOR,
1800 data.props->flRoomRolloffFactor);
1802 This->ExtAL->Effectf(This->effect, AL_REVERB_DECAY_TIME,
1803 data.props->flDecayTime);
1804 This->ExtAL->Effectf(This->effect, AL_REVERB_DECAY_HFRATIO,
1805 data.props->flDecayHFRatio);
1807 This->ExtAL->Effectf(This->effect, AL_REVERB_REFLECTIONS_GAIN,
1808 mB_to_gain(data.props->lReflections));
1809 This->ExtAL->Effectf(This->effect, AL_REVERB_REFLECTIONS_DELAY,
1810 data.props->flReflectionsDelay);
1812 This->ExtAL->Effectf(This->effect, AL_REVERB_LATE_REVERB_GAIN,
1813 mB_to_gain(data.props->lReverb));
1814 This->ExtAL->Effectf(This->effect, AL_REVERB_LATE_REVERB_DELAY,
1815 data.props->flReverbDelay);
1817 This->ExtAL->Effectf(This->effect, AL_REVERB_AIR_ABSORPTION_GAINHF,
1818 mB_to_gain(data.props->flAirAbsorptionHF));
1820 This->ExtAL->Effecti(This->effect, AL_REVERB_DECAY_HFLIMIT,
1821 (data.props->dwFlags&EAXLISTENERFLAGS_DECAYHFLIMIT) ?
1822 AL_TRUE : AL_FALSE);
1824 checkALError();
1826 This->dirty.bit.effect = 1;
1827 res = DS_OK;
1829 break;
1831 case DSPROPERTY_EAXLISTENER_ROOM:
1832 res = DSERR_INVALIDPARAM;
1833 if(cbPropData >= sizeof(LONG))
1835 union {
1836 const void *v;
1837 const LONG *l;
1838 } data = { pPropData };
1840 This->eax_prop.lRoom = *data.l;
1841 This->ExtAL->Effectf(This->effect, AL_REVERB_GAIN,
1842 mB_to_gain(This->eax_prop.lRoom));
1843 checkALError();
1845 This->dirty.bit.effect = 1;
1846 res = DS_OK;
1848 break;
1849 case DSPROPERTY_EAXLISTENER_ROOMHF:
1850 res = DSERR_INVALIDPARAM;
1851 if(cbPropData >= sizeof(LONG))
1853 union {
1854 const void *v;
1855 const LONG *l;
1856 } data = { pPropData };
1858 This->eax_prop.lRoomHF = *data.l;
1859 This->ExtAL->Effectf(This->effect, AL_REVERB_GAINHF,
1860 mB_to_gain(This->eax_prop.lRoomHF));
1861 checkALError();
1863 This->dirty.bit.effect = 1;
1864 res = DS_OK;
1866 break;
1868 case DSPROPERTY_EAXLISTENER_ROOMROLLOFFFACTOR:
1869 res = DSERR_INVALIDPARAM;
1870 if(cbPropData >= sizeof(FLOAT))
1872 union {
1873 const void *v;
1874 const FLOAT *fl;
1875 } data = { pPropData };
1877 This->eax_prop.flRoomRolloffFactor = *data.fl;
1878 This->ExtAL->Effectf(This->effect, AL_REVERB_ROOM_ROLLOFF_FACTOR,
1879 This->eax_prop.flRoomRolloffFactor);
1880 checkALError();
1882 This->dirty.bit.effect = 1;
1883 res = DS_OK;
1885 break;
1887 case DSPROPERTY_EAXLISTENER_ENVIRONMENT:
1888 res = DSERR_INVALIDPARAM;
1889 if(cbPropData >= sizeof(DWORD))
1891 union {
1892 const void *v;
1893 const DWORD *dw;
1894 } data = { pPropData };
1896 if(*data.dw < EAX_ENVIRONMENT_COUNT)
1898 /* Get the environment index's default and pass it down to
1899 * ALLPARAMETERS */
1900 propid = DSPROPERTY_EAXLISTENER_ALLPARAMETERS;
1901 pPropData = (void*)&EnvironmentDefaults[*data.dw];
1902 cbPropData = sizeof(EnvironmentDefaults[*data.dw]);
1903 goto do_allparams;
1906 break;
1908 case DSPROPERTY_EAXLISTENER_ENVIRONMENTSIZE:
1909 res = DSERR_INVALIDPARAM;
1910 if(cbPropData >= sizeof(FLOAT))
1912 union {
1913 const void *v;
1914 const FLOAT *fl;
1915 } data = { pPropData };
1917 if(*data.fl >= 1.0f && *data.fl <= 100.0f)
1919 double scale = (*data.fl)/This->eax_prop.flEnvironmentSize;
1921 This->eax_prop.flEnvironmentSize = *data.fl;
1923 if((This->eax_prop.dwFlags&EAXLISTENERFLAGS_DECAYTIMESCALE))
1925 This->eax_prop.flDecayTime *= scale;
1926 This->eax_prop.flDecayTime = clampF(This->eax_prop.flDecayTime, 0.1f, 20.0f);
1928 if((This->eax_prop.dwFlags&EAXLISTENERFLAGS_REFLECTIONSSCALE))
1930 This->eax_prop.lReflections += gain_to_mB(1.0/scale);
1931 This->eax_prop.lReflections = clampI(This->eax_prop.lReflections, -10000, 1000);
1933 if((This->eax_prop.dwFlags&EAXLISTENERFLAGS_REFLECTIONSDELAYSCALE))
1935 This->eax_prop.flReflectionsDelay *= scale;
1936 This->eax_prop.flReflectionsDelay = clampF(This->eax_prop.flReflectionsDelay, 0.0f, 0.3f);
1938 if((This->eax_prop.dwFlags&EAXLISTENERFLAGS_REVERBSCALE))
1940 This->eax_prop.lReverb += gain_to_mB(1.0/scale);
1941 This->eax_prop.lReverb = clampI(This->eax_prop.lReverb, -10000, 2000);
1943 if((This->eax_prop.dwFlags&EAXLISTENERFLAGS_REVERBDELAYSCALE))
1945 This->eax_prop.flReverbDelay *= scale;
1946 This->eax_prop.flReverbDelay = clampF(This->eax_prop.flReverbDelay, 0.0f, 0.1f);
1949 /* Pass the updated environment properties down to ALLPARAMETERS */
1950 propid = DSPROPERTY_EAXLISTENER_ALLPARAMETERS;
1951 pPropData = (void*)&This->eax_prop;
1952 cbPropData = sizeof(This->eax_prop);
1953 goto do_allparams;
1956 break;
1957 case DSPROPERTY_EAXLISTENER_ENVIRONMENTDIFFUSION:
1958 res = DSERR_INVALIDPARAM;
1959 if(cbPropData >= sizeof(FLOAT))
1961 union {
1962 const void *v;
1963 const FLOAT *fl;
1964 } data = { pPropData };
1966 This->eax_prop.flEnvironmentDiffusion = *data.fl;
1967 This->ExtAL->Effectf(This->effect, AL_REVERB_DIFFUSION,
1968 This->eax_prop.flEnvironmentDiffusion);
1969 checkALError();
1971 This->dirty.bit.effect = 1;
1972 res = DS_OK;
1974 break;
1976 case DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF:
1977 res = DSERR_INVALIDPARAM;
1978 if(cbPropData >= sizeof(FLOAT))
1980 union {
1981 const void *v;
1982 const FLOAT *fl;
1983 } data = { pPropData };
1985 This->eax_prop.flAirAbsorptionHF = *data.fl;
1986 This->ExtAL->Effectf(This->effect, AL_REVERB_AIR_ABSORPTION_GAINHF,
1987 mB_to_gain(This->eax_prop.flAirAbsorptionHF));
1988 checkALError();
1990 This->dirty.bit.effect = 1;
1991 res = DS_OK;
1993 break;
1995 case DSPROPERTY_EAXLISTENER_FLAGS:
1996 res = DSERR_INVALIDPARAM;
1997 if(cbPropData >= sizeof(DWORD))
1999 union {
2000 const void *v;
2001 const DWORD *dw;
2002 } data = { pPropData };
2004 This->eax_prop.dwFlags = *data.dw;
2005 This->ExtAL->Effecti(This->effect, AL_REVERB_DECAY_HFLIMIT,
2006 (This->eax_prop.dwFlags&EAXLISTENERFLAGS_DECAYHFLIMIT) ?
2007 AL_TRUE : AL_FALSE);
2008 checkALError();
2010 This->dirty.bit.effect = 1;
2011 res = DS_OK;
2013 break;
2015 default:
2016 FIXME("Unhandled propid: 0x%08"LONGFMT"x\n", propid);
2017 break;
2020 if(res == DS_OK && immediate)
2021 IDirectSound3DListener_CommitDeferredSettings(&This->IDirectSound3DListener_iface);
2023 popALContext();
2024 LeaveCriticalSection(This->crst);
2026 else
2027 FIXME("Unhandled propset: %s\n", debugstr_guid(guidPropSet));
2029 return res;
2032 static HRESULT WINAPI DS8PrimaryProp_QuerySupport(IKsPropertySet *iface,
2033 REFGUID guidPropSet, ULONG dwPropID,
2034 PULONG pTypeSupport)
2036 DS8Primary *This = impl_from_IKsPropertySet(iface);
2037 HRESULT res = E_PROP_ID_UNSUPPORTED;
2039 if(IsEqualIID(guidPropSet, &DSPROPSETID_EAX20_ListenerProperties))
2041 EnterCriticalSection(This->crst);
2043 if(This->effect == 0)
2044 res = E_PROP_ID_UNSUPPORTED;
2045 else if(dwPropID == DSPROPERTY_EAXLISTENER_ALLPARAMETERS ||
2046 dwPropID == DSPROPERTY_EAXLISTENER_ROOM ||
2047 dwPropID == DSPROPERTY_EAXLISTENER_ROOMHF ||
2048 dwPropID == DSPROPERTY_EAXLISTENER_ROOMROLLOFFFACTOR ||
2049 dwPropID == DSPROPERTY_EAXLISTENER_ENVIRONMENT ||
2050 dwPropID == DSPROPERTY_EAXLISTENER_ENVIRONMENTSIZE ||
2051 dwPropID == DSPROPERTY_EAXLISTENER_ENVIRONMENTDIFFUSION ||
2052 dwPropID == DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF ||
2053 dwPropID == DSPROPERTY_EAXLISTENER_FLAGS)
2055 *pTypeSupport = KSPROPERTY_SUPPORT_GET|KSPROPERTY_SUPPORT_SET;
2056 res = DS_OK;
2058 else
2059 FIXME("Unhandled propid: 0x%08"LONGFMT"x\n", dwPropID);
2061 LeaveCriticalSection(This->crst);
2063 else
2064 FIXME("Unhandled propset: %s\n", debugstr_guid(guidPropSet));
2066 return res;
2069 static const IKsPropertySetVtbl DS8PrimaryProp_Vtbl =
2071 DS8PrimaryProp_QueryInterface,
2072 DS8PrimaryProp_AddRef,
2073 DS8PrimaryProp_Release,
2074 DS8PrimaryProp_Get,
2075 DS8PrimaryProp_Set,
2076 DS8PrimaryProp_QuerySupport