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
31 #include <devpropdef.h>
33 #include "dsound_private.h"
37 #define DS_INCOMPLETE ((HRESULT)0x08780020)
40 #ifndef WAVE_FORMAT_IEEE_FLOAT
41 #define WAVE_FORMAT_IEEE_FLOAT 3
45 /* TODO: when bufferlost is set, return from all calls except initialize with
48 static const IDirectSoundBuffer8Vtbl DSBuffer_Vtbl
;
49 static const IDirectSound3DBufferVtbl DSBuffer3d_Vtbl
;
50 static const IDirectSoundNotifyVtbl DSBufferNot_Vtbl
;
51 static const IKsPropertySetVtbl DSBufferProp_Vtbl
;
54 static inline DSBuffer
*impl_from_IDirectSoundBuffer8(IDirectSoundBuffer8
*iface
)
56 return CONTAINING_RECORD(iface
, DSBuffer
, IDirectSoundBuffer8_iface
);
59 static inline DSBuffer
*impl_from_IDirectSoundBuffer(IDirectSoundBuffer
*iface
)
61 return CONTAINING_RECORD(iface
, DSBuffer
, IDirectSoundBuffer8_iface
);
64 static inline DSBuffer
*impl_from_IDirectSound3DBuffer(IDirectSound3DBuffer
*iface
)
66 return CONTAINING_RECORD(iface
, DSBuffer
, IDirectSound3DBuffer_iface
);
69 static inline DSBuffer
*impl_from_IDirectSoundNotify(IDirectSoundNotify
*iface
)
71 return CONTAINING_RECORD(iface
, DSBuffer
, IDirectSoundNotify_iface
);
74 static inline DSBuffer
*impl_from_IKsPropertySet(IKsPropertySet
*iface
)
76 return CONTAINING_RECORD(iface
, DSBuffer
, IKsPropertySet_iface
);
80 /* Should be called with critsect held and context set.. */
81 static void DSBuffer_addnotify(DSBuffer
*buf
)
83 DSPrimary
*prim
= buf
->primary
;
87 list
= prim
->notifies
;
88 for(i
= 0; i
< prim
->nnotifies
; ++i
)
92 ERR("Buffer %p already in notification list\n", buf
);
96 if(prim
->nnotifies
== prim
->sizenotifies
)
98 list
= HeapReAlloc(GetProcessHeap(), 0, list
, (prim
->nnotifies
+ 1) * sizeof(*list
));
100 prim
->sizenotifies
++;
102 list
[prim
->nnotifies
++] = buf
;
103 prim
->notifies
= list
;
107 static const char *get_fmtstr_PCM(const DSPrimary
*prim
, const WAVEFORMATEX
*format
, WAVEFORMATEXTENSIBLE
*out
)
109 out
->Format
= *format
;
110 out
->Format
.cbSize
= 0;
112 if(out
->Format
.nChannels
!= 1 && out
->Format
.nChannels
!= 2 &&
113 !HAS_EXTENSION(prim
->share
, EXT_MCFORMATS
))
115 WARN("Multi-channel not available\n");
119 if(format
->wBitsPerSample
== 8)
121 switch(format
->nChannels
)
123 case 1: return "AL_FORMAT_MONO8";
124 case 2: return "AL_FORMAT_STEREO8";
125 case 4: return "AL_FORMAT_QUAD8";
126 case 6: return "AL_FORMAT_51CHN8";
127 case 7: return "AL_FORMAT_61CHN8";
128 case 8: return "AL_FORMAT_71CHN8";
131 else if(format
->wBitsPerSample
== 16)
133 switch(format
->nChannels
)
135 case 1: return "AL_FORMAT_MONO16";
136 case 2: return "AL_FORMAT_STEREO16";
137 case 4: return "AL_FORMAT_QUAD16";
138 case 6: return "AL_FORMAT_51CHN16";
139 case 7: return "AL_FORMAT_61CHN16";
140 case 8: return "AL_FORMAT_71CHN16";
144 FIXME("Could not get OpenAL format (%d-bit, %d channels)\n",
145 format
->wBitsPerSample
, format
->nChannels
);
149 static const char *get_fmtstr_FLOAT(const DSPrimary
*prim
, const WAVEFORMATEX
*format
, WAVEFORMATEXTENSIBLE
*out
)
151 out
->Format
= *format
;
152 out
->Format
.cbSize
= 0;
154 if(out
->Format
.nChannels
!= 1 && out
->Format
.nChannels
!= 2 &&
155 !HAS_EXTENSION(prim
->share
, EXT_MCFORMATS
))
157 WARN("Multi-channel not available\n");
161 if(format
->wBitsPerSample
== 32 && HAS_EXTENSION(prim
->share
, EXT_FLOAT32
))
163 switch(format
->nChannels
)
165 case 1: return "AL_FORMAT_MONO_FLOAT32";
166 case 2: return "AL_FORMAT_STEREO_FLOAT32";
167 case 4: return "AL_FORMAT_QUAD32";
168 case 6: return "AL_FORMAT_51CHN32";
169 case 7: return "AL_FORMAT_61CHN32";
170 case 8: return "AL_FORMAT_71CHN32";
174 FIXME("Could not get OpenAL format (%d-bit, %d channels)\n",
175 format
->wBitsPerSample
, format
->nChannels
);
179 /* Speaker configs */
180 #define MONO SPEAKER_FRONT_CENTER
181 #define STEREO (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT)
182 #define REAR (SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT)
183 #define QUAD (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT)
184 #define X5DOT1 (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER|SPEAKER_LOW_FREQUENCY|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT)
185 #define X6DOT1 (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER|SPEAKER_LOW_FREQUENCY|SPEAKER_BACK_CENTER|SPEAKER_SIDE_LEFT|SPEAKER_SIDE_RIGHT)
186 #define X7DOT1 (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER|SPEAKER_LOW_FREQUENCY|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT|SPEAKER_SIDE_LEFT|SPEAKER_SIDE_RIGHT)
188 static const char *get_fmtstr_EXT(const DSPrimary
*prim
, const WAVEFORMATEX
*format
, WAVEFORMATEXTENSIBLE
*out
)
190 *out
= *CONTAINING_RECORD(format
, const WAVEFORMATEXTENSIBLE
, Format
);
191 out
->Format
.cbSize
= sizeof(*out
) - sizeof(out
->Format
);
193 if(!out
->Samples
.wValidBitsPerSample
)
194 out
->Samples
.wValidBitsPerSample
= out
->Format
.wBitsPerSample
;
195 else if(out
->Samples
.wValidBitsPerSample
> out
->Format
.wBitsPerSample
)
197 WARN("Invalid ValidBitsPerSample (%u > %u)\n", out
->Samples
.wValidBitsPerSample
, out
->Format
.wBitsPerSample
);
200 else if(out
->Samples
.wValidBitsPerSample
< out
->Format
.wBitsPerSample
)
202 FIXME("Padded samples not supported (%u of %u)\n", out
->Samples
.wValidBitsPerSample
, out
->Format
.wBitsPerSample
);
206 if(out
->dwChannelMask
!= MONO
&& out
->dwChannelMask
!= STEREO
&&
207 !HAS_EXTENSION(prim
->share
, EXT_MCFORMATS
))
209 WARN("Multi-channel not available\n");
213 if(IsEqualGUID(&out
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
))
215 if(out
->Samples
.wValidBitsPerSample
== 8)
217 switch(out
->dwChannelMask
)
219 case MONO
: return "AL_FORMAT_MONO8";
220 case STEREO
: return "AL_FORMAT_STEREO8";
221 case REAR
: return "AL_FORMAT_REAR8";
222 case QUAD
: return "AL_FORMAT_QUAD8";
223 case X5DOT1
: return "AL_FORMAT_51CHN8";
224 case X6DOT1
: return "AL_FORMAT_61CHN8";
225 case X7DOT1
: return "AL_FORMAT_71CHN8";
228 else if(out
->Samples
.wValidBitsPerSample
== 16)
230 switch(out
->dwChannelMask
)
232 case MONO
: return "AL_FORMAT_MONO16";
233 case STEREO
: return "AL_FORMAT_STEREO16";
234 case REAR
: return "AL_FORMAT_REAR16";
235 case QUAD
: return "AL_FORMAT_QUAD16";
236 case X5DOT1
: return "AL_FORMAT_51CHN16";
237 case X6DOT1
: return "AL_FORMAT_61CHN16";
238 case X7DOT1
: return "AL_FORMAT_71CHN16";
242 FIXME("Could not get OpenAL PCM format (%d-bit, channelmask %#lx)\n",
243 out
->Samples
.wValidBitsPerSample
, out
->dwChannelMask
);
246 else if(IsEqualGUID(&out
->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
) &&
247 HAS_EXTENSION(prim
->share
, EXT_FLOAT32
))
249 if(out
->Samples
.wValidBitsPerSample
== 32)
251 switch(out
->dwChannelMask
)
253 case MONO
: return "AL_FORMAT_MONO_FLOAT32";
254 case STEREO
: return "AL_FORMAT_STEREO_FLOAT32";
255 case REAR
: return "AL_FORMAT_REAR32";
256 case QUAD
: return "AL_FORMAT_QUAD32";
257 case X5DOT1
: return "AL_FORMAT_51CHN32";
258 case X6DOT1
: return "AL_FORMAT_61CHN32";
259 case X7DOT1
: return "AL_FORMAT_71CHN32";
264 WARN("Invalid float bits: %u\n", out
->Samples
.wValidBitsPerSample
);
268 FIXME("Could not get OpenAL float format (%d-bit, channelmask %#lx)\n",
269 out
->Samples
.wValidBitsPerSample
, out
->dwChannelMask
);
272 else if(!IsEqualGUID(&out
->SubFormat
, &GUID_NULL
))
273 ERR("Unhandled extensible format: %s\n", debugstr_guid(&out
->SubFormat
));
277 static void DSData_Release(DSData
*This
);
278 static HRESULT
DSData_Create(DSData
**ppv
, const DSBUFFERDESC
*desc
, DSPrimary
*prim
)
280 HRESULT hr
= DSERR_INVALIDPARAM
;
281 const WAVEFORMATEX
*format
;
282 const char *fmt_str
= NULL
;
286 format
= desc
->lpwfxFormat
;
287 TRACE("Requested buffer format:\n"
288 " FormatTag = 0x%04x\n"
290 " SamplesPerSec = %lu\n"
291 " AvgBytesPerSec = %lu\n"
293 " BitsPerSample = %d\n",
294 format
->wFormatTag
, format
->nChannels
,
295 format
->nSamplesPerSec
, format
->nAvgBytesPerSec
,
296 format
->nBlockAlign
, format
->wBitsPerSample
);
298 if(format
->nChannels
<= 0)
300 WARN("Invalid Channels %d\n", format
->nChannels
);
301 return DSERR_INVALIDPARAM
;
303 if(format
->nSamplesPerSec
< DSBFREQUENCY_MIN
|| format
->nSamplesPerSec
> DSBFREQUENCY_MAX
)
305 WARN("Invalid SamplesPerSec %lu\n", format
->nSamplesPerSec
);
306 return DSERR_INVALIDPARAM
;
308 if(format
->nBlockAlign
<= 0)
310 WARN("Invalid BlockAlign %d\n", format
->nBlockAlign
);
311 return DSERR_INVALIDPARAM
;
313 if(format
->wBitsPerSample
== 0 || (format
->wBitsPerSample
%8) != 0)
315 WARN("Invalid BitsPerSample %d\n", format
->wBitsPerSample
);
316 return DSERR_INVALIDPARAM
;
318 if(format
->nBlockAlign
!= format
->nChannels
*format
->wBitsPerSample
/8)
320 WARN("Invalid BlockAlign %d (expected %u = %u*%u/8)\n",
321 format
->nBlockAlign
, format
->nChannels
*format
->wBitsPerSample
/8,
322 format
->nChannels
, format
->wBitsPerSample
);
323 return DSERR_INVALIDPARAM
;
325 if(format
->nAvgBytesPerSec
!= format
->nBlockAlign
*format
->nSamplesPerSec
)
327 WARN("Invalid AvgBytesPerSec %lu (expected %lu = %lu*%u)\n",
328 format
->nAvgBytesPerSec
, format
->nSamplesPerSec
*format
->nBlockAlign
,
329 format
->nSamplesPerSec
, format
->nBlockAlign
);
330 return DSERR_INVALIDPARAM
;
333 if((desc
->dwFlags
&(DSBCAPS_LOCSOFTWARE
|DSBCAPS_LOCHARDWARE
)) == (DSBCAPS_LOCSOFTWARE
|DSBCAPS_LOCHARDWARE
))
335 WARN("Hardware and software location requested\n");
336 return DSERR_INVALIDPARAM
;
339 buf_size
= desc
->dwBufferBytes
+ format
->nBlockAlign
- 1;
340 buf_size
-= buf_size
%format
->nBlockAlign
;
341 if(buf_size
< DSBSIZE_MIN
) return DSERR_BUFFERTOOSMALL
;
342 if(buf_size
> DSBSIZE_MAX
) return DSERR_INVALIDPARAM
;
344 /* Generate a new buffer. Supporting the DSBCAPS_LOC* flags properly
345 * will need the EAX-RAM extension. Currently, we just tell the app it
346 * gets what it wanted. */
347 if(!HAS_EXTENSION(prim
->share
, SOFTX_MAP_BUFFER
))
348 pBuffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*pBuffer
)+buf_size
);
350 pBuffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*pBuffer
));
351 if(!pBuffer
) return E_OUTOFMEMORY
;
353 pBuffer
->primary
= prim
;
355 pBuffer
->dsbflags
= desc
->dwFlags
;
356 pBuffer
->buf_size
= buf_size
;
358 if(format
->wFormatTag
== WAVE_FORMAT_PCM
)
359 fmt_str
= get_fmtstr_PCM(prim
, format
, &pBuffer
->format
);
360 else if(format
->wFormatTag
== WAVE_FORMAT_IEEE_FLOAT
)
361 fmt_str
= get_fmtstr_FLOAT(prim
, format
, &pBuffer
->format
);
362 else if(format
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
364 const WAVEFORMATEXTENSIBLE
*wfe
;
366 if(format
->cbSize
!= sizeof(WAVEFORMATEXTENSIBLE
)-sizeof(WAVEFORMATEX
) &&
367 format
->cbSize
!= sizeof(WAVEFORMATEXTENSIBLE
))
370 wfe
= CONTAINING_RECORD(format
, const WAVEFORMATEXTENSIBLE
, Format
);
371 TRACE("Extensible values:\n"
373 " ChannelMask = 0x%lx\n"
375 wfe
->Samples
.wReserved
, wfe
->dwChannelMask
,
376 debugstr_guid(&wfe
->SubFormat
));
378 fmt_str
= get_fmtstr_EXT(prim
, format
, &pBuffer
->format
);
381 ERR("Unhandled formattag 0x%04x\n", format
->wFormatTag
);
382 if(!fmt_str
) goto fail
;
385 pBuffer
->buf_format
= alGetEnumValue(fmt_str
);
386 if(alGetError() != AL_NO_ERROR
|| pBuffer
->buf_format
== 0 ||
387 pBuffer
->buf_format
== -1)
389 WARN("Could not get OpenAL format from %s\n", fmt_str
);
394 if(!HAS_EXTENSION(prim
->share
, SOFTX_MAP_BUFFER
))
396 pBuffer
->data
= (BYTE
*)(pBuffer
+1);
398 alGenBuffers(1, &pBuffer
->bid
);
403 const ALbitfieldSOFT map_bits
= AL_MAP_READ_BIT_SOFT
| AL_MAP_WRITE_BIT_SOFT
|
404 AL_MAP_PERSISTENT_BIT_SOFT
;
405 alGenBuffers(1, &pBuffer
->bid
);
406 alBufferStorageSOFT(pBuffer
->bid
, pBuffer
->buf_format
, NULL
, pBuffer
->buf_size
,
407 pBuffer
->format
.Format
.nSamplesPerSec
, map_bits
);
408 pBuffer
->data
= alMapBufferSOFT(pBuffer
->bid
, 0, pBuffer
->buf_size
, map_bits
);
411 if(!pBuffer
->data
) goto fail
;
418 DSData_Release(pBuffer
);
422 static void DSData_AddRef(DSData
*data
)
424 InterlockedIncrement(&data
->ref
);
427 /* This function is always called with the device lock held */
428 static void DSData_Release(DSData
*This
)
430 if(InterlockedDecrement(&This
->ref
)) return;
432 TRACE("Deleting %p\n", This
);
435 DSPrimary
*prim
= This
->primary
;
436 if(HAS_EXTENSION(prim
->share
, SOFTX_MAP_BUFFER
))
437 alUnmapBufferSOFT(This
->bid
);
438 alDeleteBuffers(1, &This
->bid
);
441 HeapFree(GetProcessHeap(), 0, This
);
445 HRESULT
DSBuffer_Create(DSBuffer
**ppv
, DSPrimary
*prim
, IDirectSoundBuffer
*orig
)
447 DSBuffer
*This
= NULL
;
451 EnterCriticalSection(&prim
->share
->crst
);
452 for(i
= 0;i
< prim
->NumBufferGroups
;++i
)
454 if(prim
->BufferGroups
[i
].FreeBuffers
)
456 int idx
= CTZ64(prim
->BufferGroups
[i
].FreeBuffers
);
457 This
= prim
->BufferGroups
[i
].Buffers
+ idx
;
458 memset(This
, 0, sizeof(*This
));
459 prim
->BufferGroups
[i
].FreeBuffers
&= ~(U64(1) << idx
);
465 struct DSBufferGroup
*grp
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
466 (prim
->NumBufferGroups
+1)*sizeof(prim
->BufferGroups
[0]));
469 for(i
= 0;i
< prim
->NumBufferGroups
;i
++)
470 grp
[i
] = prim
->BufferGroups
[i
];
471 grp
[i
].FreeBuffers
= ~U64(0);
472 grp
[i
].Buffers
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
473 64*sizeof(grp
[0].Buffers
[0]));
476 HeapFree(GetProcessHeap(), 0, grp
);
481 HeapFree(GetProcessHeap(), 0, prim
->BufferGroups
);
482 prim
->BufferGroups
= grp
;
483 prim
->NumBufferGroups
++;
485 This
= prim
->BufferGroups
[i
].Buffers
+ 0;
486 memset(This
, 0, sizeof(*This
));
487 prim
->BufferGroups
[i
].FreeBuffers
&= ~(U64(1) << 0);
491 LeaveCriticalSection(&prim
->share
->crst
);
494 WARN("Out of memory allocating buffers\n");
495 return DSERR_OUTOFMEMORY
;
498 This
->IDirectSoundBuffer8_iface
.lpVtbl
= &DSBuffer_Vtbl
;
499 This
->IDirectSound3DBuffer_iface
.lpVtbl
= &DSBuffer3d_Vtbl
;
500 This
->IDirectSoundNotify_iface
.lpVtbl
= &DSBufferNot_Vtbl
;
501 This
->IKsPropertySet_iface
.lpVtbl
= &DSBufferProp_Vtbl
;
503 This
->share
= prim
->share
;
504 This
->primary
= prim
;
505 This
->ctx
= prim
->ctx
;
507 This
->current
.vol
= 0;
508 This
->current
.pan
= 0;
509 This
->current
.frequency
= 0;
510 This
->current
.ds3d
.dwSize
= sizeof(This
->current
.ds3d
);
511 This
->current
.ds3d
.vPosition
.x
= 0.0f
;
512 This
->current
.ds3d
.vPosition
.y
= 0.0f
;
513 This
->current
.ds3d
.vPosition
.z
= 0.0f
;
514 This
->current
.ds3d
.vVelocity
.x
= 0.0f
;
515 This
->current
.ds3d
.vVelocity
.y
= 0.0f
;
516 This
->current
.ds3d
.vVelocity
.z
= 0.0f
;
517 This
->current
.ds3d
.dwInsideConeAngle
= DS3D_DEFAULTCONEANGLE
;
518 This
->current
.ds3d
.dwOutsideConeAngle
= DS3D_DEFAULTCONEANGLE
;
519 This
->current
.ds3d
.vConeOrientation
.x
= 0.0f
;
520 This
->current
.ds3d
.vConeOrientation
.y
= 0.0f
;
521 This
->current
.ds3d
.vConeOrientation
.z
= 1.0f
;
522 This
->current
.ds3d
.lConeOutsideVolume
= DS3D_DEFAULTCONEOUTSIDEVOLUME
;
523 This
->current
.ds3d
.flMinDistance
= DS3D_DEFAULTMINDISTANCE
;
524 This
->current
.ds3d
.flMaxDistance
= DS3D_DEFAULTMAXDISTANCE
;
525 This
->current
.ds3d
.dwMode
= DS3DMODE_NORMAL
;
526 This
->current
.eax
.lDirect
= 0;
527 This
->current
.eax
.lDirectHF
= 0;
528 This
->current
.eax
.lRoom
= 0;
529 This
->current
.eax
.lRoomHF
= 0;
530 This
->current
.eax
.lObstruction
= 0;
531 This
->current
.eax
.flObstructionLFRatio
= 0.0f
;
532 This
->current
.eax
.lOcclusion
= 0;
533 This
->current
.eax
.flOcclusionLFRatio
= 0.25f
;
534 This
->current
.eax
.flOcclusionRoomRatio
= 1.5f
;
535 This
->current
.eax
.flOcclusionDirectRatio
= 1.0f
;
536 This
->current
.eax
.lExclusion
= 0;
537 This
->current
.eax
.flExclusionLFRatio
= 1.0f
;
538 This
->current
.eax
.lOutsideVolumeHF
= 0;
539 This
->current
.eax
.flDopplerFactor
= 1.0f
;
540 This
->current
.eax
.flRolloffFactor
= 0.0f
;
541 This
->current
.eax
.flRoomRolloffFactor
= 0.0f
;
542 This
->current
.eax
.flAirAbsorptionFactor
= 0.0f
;
543 This
->current
.eax
.dwFlags
= EAXSOURCEFLAGS_DIRECTHFAUTO
| EAXSOURCEFLAGS_ROOMAUTO
|
544 EAXSOURCEFLAGS_ROOMHFAUTO
;
545 This
->current
.fxslot_targets
[0] = FXSLOT_TARGET_PRIMARY
;
546 for(i
= 1;i
< EAX_MAX_ACTIVE_FXSLOTS
;++i
)
547 This
->current
.fxslot_targets
[i
] = FXSLOT_TARGET_NULL
;
548 for(i
= 0;i
< EAX_MAX_FXSLOTS
;++i
)
550 This
->current
.send
[i
].lSend
= 0;
551 This
->current
.send
[i
].lSendHF
= 0;
552 This
->current
.send
[i
].lOcclusion
= 0;
553 This
->current
.send
[i
].flOcclusionLFRatio
= 0.25f
;
554 This
->current
.send
[i
].flOcclusionRoomRatio
= 1.5f
;
555 This
->current
.send
[i
].flOcclusionDirectRatio
= 1.0f
;
556 This
->current
.send
[i
].lExclusion
= 0;
557 This
->current
.send
[i
].flExclusionLFRatio
= 1.0f
;
559 This
->current
.eax1_reverbmix
= 1.0f
;
563 DSBuffer
*org
= impl_from_IDirectSoundBuffer(orig
);
564 DSData
*data
= org
->buffer
;
568 DSBuffer_Destroy(This
);
569 return DSERR_BUFFERLOST
;
574 /* According to MSDN, volume isn't copied. */
575 if((data
->dsbflags
&DSBCAPS_CTRLPAN
))
576 This
->current
.pan
= org
->current
.pan
;
577 if((data
->dsbflags
&DSBCAPS_CTRLFREQUENCY
))
578 This
->current
.frequency
= org
->current
.frequency
;
579 if((data
->dsbflags
&DSBCAPS_CTRL3D
))
580 This
->current
.ds3d
= org
->current
.ds3d
;
583 This
->deferred
.ds3d
= This
->current
.ds3d
;
584 This
->deferred
.eax
= This
->current
.eax
;
585 for(i
= 0;i
< EAX_MAX_ACTIVE_FXSLOTS
;++i
)
586 This
->deferred
.fxslot_targets
[i
] = This
->current
.fxslot_targets
[i
];
587 for(i
= 0;i
< EAX_MAX_FXSLOTS
;++i
)
588 This
->deferred
.send
[i
] = This
->current
.send
[i
];
589 This
->deferred
.eax1_reverbmix
= This
->current
.eax1_reverbmix
;
595 void DSBuffer_Destroy(DSBuffer
*This
)
597 DSPrimary
*prim
= This
->primary
;
601 TRACE("Destroying %p\n", This
);
603 EnterCriticalSection(&prim
->share
->crst
);
604 /* Remove from list, if in list */
605 for(i
= 0;i
< prim
->nnotifies
;++i
)
607 if(This
== prim
->notifies
[i
])
609 prim
->notifies
[i
] = prim
->notifies
[--prim
->nnotifies
];
614 setALContext(This
->ctx
);
617 DeviceShare
*share
= This
->share
;
619 alSourceRewind(This
->source
);
620 alSourcei(This
->source
, AL_BUFFER
, 0);
623 if(This
->loc_status
== DSBSTATUS_LOCHARDWARE
)
624 share
->sources
.ids
[share
->sources
.availhw_num
++] = This
->source
;
627 DWORD base
= share
->sources
.maxhw_alloc
;
628 share
->sources
.ids
[base
+ share
->sources
.availsw_num
++] = This
->source
;
632 if(This
->stream_bids
[0])
633 alDeleteBuffers(QBUFFERS
, This
->stream_bids
);
635 alDeleteFilters(1+EAX_MAX_FXSLOTS
, This
->filter
);
638 DSData_Release(This
->buffer
);
642 HeapFree(GetProcessHeap(), 0, This
->notify
);
644 for(i
= 0;i
< prim
->NumBufferGroups
;++i
)
646 DWORD_PTR idx
= This
- prim
->BufferGroups
[i
].Buffers
;
649 prim
->BufferGroups
[i
].FreeBuffers
|= U64(1) << idx
;
654 LeaveCriticalSection(&prim
->share
->crst
);
657 HRESULT
DSBuffer_GetInterface(DSBuffer
*buf
, REFIID riid
, void **ppv
)
660 if(IsEqualIID(riid
, &IID_IDirectSoundBuffer
))
661 *ppv
= &buf
->IDirectSoundBuffer8_iface
;
662 else if(IsEqualIID(riid
, &IID_IDirectSoundBuffer8
))
664 if(buf
->primary
->parent
->is_8
)
665 *ppv
= &buf
->IDirectSoundBuffer8_iface
;
667 else if(IsEqualIID(riid
, &IID_IDirectSound3DBuffer
))
669 if((buf
->buffer
->dsbflags
&DSBCAPS_CTRL3D
))
670 *ppv
= &buf
->IDirectSound3DBuffer_iface
;
672 else if(IsEqualIID(riid
, &IID_IDirectSoundNotify
))
674 if((buf
->buffer
->dsbflags
&DSBCAPS_CTRLPOSITIONNOTIFY
))
675 *ppv
= &buf
->IDirectSoundNotify_iface
;
677 else if(IsEqualIID(riid
, &IID_IKsPropertySet
))
678 *ppv
= &buf
->IKsPropertySet_iface
;
679 else if(IsEqualIID(riid
, &IID_IUnknown
))
680 *ppv
= &buf
->IDirectSoundBuffer8_iface
;
682 FIXME("Unhandled GUID: %s\n", debugstr_guid(riid
));
686 IUnknown_AddRef((IUnknown
*)*ppv
);
690 return E_NOINTERFACE
;
693 static HRESULT
DSBuffer_SetLoc(DSBuffer
*buf
, DWORD loc_status
)
695 DeviceShare
*share
= buf
->share
;
696 DSData
*data
= buf
->buffer
;
699 if((loc_status
&& buf
->loc_status
== loc_status
) || (!loc_status
&& buf
->loc_status
))
702 /* If we have a source, we're changing location, so return the source we
703 * have to get a new one.
707 alSourceRewind(buf
->source
);
708 alSourcei(buf
->source
, AL_BUFFER
, 0);
711 if(buf
->loc_status
== DSBSTATUS_LOCHARDWARE
)
712 share
->sources
.ids
[share
->sources
.availhw_num
++] = buf
->source
;
715 DWORD base
= share
->sources
.maxhw_alloc
;
716 share
->sources
.ids
[base
+ share
->sources
.availsw_num
++] = buf
->source
;
724 if(share
->sources
.availhw_num
)
725 loc_status
= DSBSTATUS_LOCHARDWARE
;
726 else if(share
->sources
.availsw_num
)
727 loc_status
= DSBSTATUS_LOCSOFTWARE
;
730 if((loc_status
== DSBSTATUS_LOCHARDWARE
&& !share
->sources
.availhw_num
) ||
731 (loc_status
== DSBSTATUS_LOCSOFTWARE
&& !share
->sources
.availsw_num
) ||
734 ERR("Out of %s sources\n",
735 (loc_status
== DSBSTATUS_LOCHARDWARE
) ? "hardware" :
736 (loc_status
== DSBSTATUS_LOCSOFTWARE
) ? "software" : "any"
738 return DSERR_ALLOCATED
;
741 if(loc_status
== DSBSTATUS_LOCHARDWARE
)
742 buf
->source
= share
->sources
.ids
[--(share
->sources
.availhw_num
)];
745 DWORD base
= share
->sources
.maxhw_alloc
;
746 buf
->source
= share
->sources
.ids
[base
+ --(share
->sources
.availsw_num
)];
748 alSourcef(buf
->source
, AL_GAIN
, mB_to_gain((float)buf
->current
.vol
));
749 alSourcef(buf
->source
, AL_PITCH
,
750 buf
->current
.frequency
? (float)buf
->current
.frequency
/data
->format
.Format
.nSamplesPerSec
754 /* TODO: Don't set EAX parameters or connect to effect slots for software
755 * buffers. Need to check if EAX buffer properties are still tracked, or if
756 * they're lost/reset when leaving hardware.
758 * Alternatively, we can just allow it and say software processing supports
759 * EAX too. Depends if apps may get upset over that.
762 if((data
->dsbflags
&DSBCAPS_CTRL3D
))
764 const DSPrimary
*prim
= buf
->primary
;
765 const ALuint source
= buf
->source
;
766 const DS3DBUFFER
*params
= &buf
->current
.ds3d
;
767 const EAXSOURCEPROPERTIES
*eax_params
= &buf
->current
.eax
;
769 alSource3f(source
, AL_POSITION
, params
->vPosition
.x
, params
->vPosition
.y
,
770 -params
->vPosition
.z
);
771 alSource3f(source
, AL_VELOCITY
, params
->vVelocity
.x
, params
->vVelocity
.y
,
772 -params
->vVelocity
.z
);
773 alSourcei(source
, AL_CONE_INNER_ANGLE
, params
->dwInsideConeAngle
);
774 alSourcei(source
, AL_CONE_OUTER_ANGLE
, params
->dwOutsideConeAngle
);
775 alSource3f(source
, AL_DIRECTION
, params
->vConeOrientation
.x
,
776 params
->vConeOrientation
.y
,
777 -params
->vConeOrientation
.z
);
778 alSourcef(source
, AL_CONE_OUTER_GAIN
, mB_to_gain((float)params
->lConeOutsideVolume
));
779 alSourcef(source
, AL_REFERENCE_DISTANCE
, params
->flMinDistance
);
780 alSourcef(source
, AL_MAX_DISTANCE
, params
->flMaxDistance
);
781 if(HAS_EXTENSION(share
, SOFT_SOURCE_SPATIALIZE
))
782 alSourcei(source
, AL_SOURCE_SPATIALIZE_SOFT
,
783 (params
->dwMode
==DS3DMODE_DISABLE
) ? AL_FALSE
: AL_TRUE
785 alSourcei(source
, AL_SOURCE_RELATIVE
,
786 (params
->dwMode
!=DS3DMODE_NORMAL
) ? AL_TRUE
: AL_FALSE
789 alSourcef(source
, AL_ROLLOFF_FACTOR
,
790 prim
->current
.ds3d
.flRolloffFactor
+ eax_params
->flRolloffFactor
);
791 alSourcef(source
, AL_DOPPLER_FACTOR
, eax_params
->flDopplerFactor
);
792 if(HAS_EXTENSION(share
, EXT_EFX
))
794 alSourcei(source
, AL_DIRECT_FILTER
, buf
->filter
[0]);
795 for(i
= 0;i
< share
->num_sends
;++i
)
797 DWORD target
= buf
->current
.fxslot_targets
[i
];
798 ALuint filter
=0, slot
=0;
799 if(target
< FXSLOT_TARGET_NULL
)
801 ALint idx
= (target
== FXSLOT_TARGET_PRIMARY
) ?
802 prim
->primary_idx
: (ALint
)target
;
805 slot
= prim
->auxslot
[idx
];
806 filter
= buf
->filter
[1+idx
];
809 alSource3i(source
, AL_AUXILIARY_SEND_FILTER
, slot
, i
, filter
);
811 alSourcef(source
, AL_ROOM_ROLLOFF_FACTOR
, eax_params
->flRoomRolloffFactor
);
812 alSourcef(source
, AL_CONE_OUTER_GAINHF
, mB_to_gain((float)eax_params
->lOutsideVolumeHF
));
813 alSourcef(source
, AL_AIR_ABSORPTION_FACTOR
,
814 clampF(prim
->current
.ctx
.flAirAbsorptionHF
/ -5.0f
*
815 eax_params
->flAirAbsorptionFactor
, 0.0f
, 10.0f
)
817 alSourcei(source
, AL_DIRECT_FILTER_GAINHF_AUTO
,
818 (eax_params
->dwFlags
&EAXSOURCEFLAGS_DIRECTHFAUTO
) ? AL_TRUE
: AL_FALSE
);
819 alSourcei(source
, AL_AUXILIARY_SEND_FILTER_GAIN_AUTO
,
820 (eax_params
->dwFlags
&EAXSOURCEFLAGS_ROOMAUTO
) ? AL_TRUE
: AL_FALSE
);
821 alSourcei(source
, AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO
,
822 (eax_params
->dwFlags
&EAXSOURCEFLAGS_ROOMHFAUTO
) ? AL_TRUE
: AL_FALSE
);
828 const ALuint source
= buf
->source
;
829 const ALfloat x
= (ALfloat
)(buf
->current
.pan
-DSBPAN_LEFT
)/(DSBPAN_RIGHT
-DSBPAN_LEFT
) -
832 alSource3f(source
, AL_POSITION
, x
, 0.0f
, -sqrtf(1.0f
- x
*x
));
833 alSource3f(source
, AL_VELOCITY
, 0.0f
, 0.0f
, 0.0f
);
834 alSource3f(source
, AL_DIRECTION
, 0.0f
, 0.0f
, 0.0f
);
835 alSourcef(source
, AL_CONE_OUTER_GAIN
, 1.0f
);
836 alSourcef(source
, AL_REFERENCE_DISTANCE
, 1.0f
);
837 alSourcef(source
, AL_MAX_DISTANCE
, 1000.0f
);
838 alSourcef(source
, AL_ROLLOFF_FACTOR
, 0.0f
);
839 alSourcef(source
, AL_DOPPLER_FACTOR
, 0.0f
);
840 alSourcei(source
, AL_CONE_INNER_ANGLE
, 360);
841 alSourcei(source
, AL_CONE_OUTER_ANGLE
, 360);
842 alSourcei(source
, AL_SOURCE_RELATIVE
, AL_TRUE
);
843 if(HAS_EXTENSION(share
, EXT_EFX
))
845 alSourcef(source
, AL_ROOM_ROLLOFF_FACTOR
, 0.0f
);
846 alSourcef(source
, AL_CONE_OUTER_GAINHF
, 1.0f
);
847 alSourcef(source
, AL_AIR_ABSORPTION_FACTOR
, 0.0f
);
848 alSourcei(source
, AL_DIRECT_FILTER_GAINHF_AUTO
, AL_TRUE
);
849 alSourcei(source
, AL_AUXILIARY_SEND_FILTER_GAIN_AUTO
, AL_TRUE
);
850 alSourcei(source
, AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO
, AL_TRUE
);
851 alSourcei(source
, AL_DIRECT_FILTER
, AL_FILTER_NULL
);
852 for(i
= 0;i
< share
->num_sends
;++i
)
853 alSource3i(source
, AL_AUXILIARY_SEND_FILTER
, 0, i
, AL_FILTER_NULL
);
855 if(HAS_EXTENSION(share
, SOFT_SOURCE_SPATIALIZE
))
857 /* Set to auto so panning works for mono, and multi-channel works
860 alSourcei(source
, AL_SOURCE_SPATIALIZE_SOFT
, AL_AUTO_SOFT
);
865 buf
->loc_status
= loc_status
;
870 static HRESULT WINAPI
DSBuffer_QueryInterface(IDirectSoundBuffer8
*iface
, REFIID riid
, void **ppv
)
872 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
873 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
874 return DSBuffer_GetInterface(This
, riid
, ppv
);
877 static ULONG WINAPI
DSBuffer_AddRef(IDirectSoundBuffer8
*iface
)
879 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
882 InterlockedIncrement(&This
->all_ref
);
883 ret
= InterlockedIncrement(&This
->ref
);
884 TRACE("(%p) ref %lu\n", iface
, ret
);
889 static ULONG WINAPI
DSBuffer_Release(IDirectSoundBuffer8
*iface
)
891 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
894 ret
= InterlockedDecrement(&This
->ref
);
895 TRACE("(%p) ref %lu\n", iface
, ret
);
896 if(InterlockedDecrement(&This
->all_ref
) == 0)
897 DSBuffer_Destroy(This
);
902 static HRESULT WINAPI
DSBuffer_GetCaps(IDirectSoundBuffer8
*iface
, DSBCAPS
*caps
)
904 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
907 TRACE("(%p)->(%p)\n", iface
, caps
);
909 if(!caps
|| caps
->dwSize
< sizeof(*caps
))
911 WARN("Invalid DSBCAPS (%p, %lu)\n", caps
, (caps
? caps
->dwSize
: 0));
912 return DSERR_INVALIDPARAM
;
916 caps
->dwFlags
= data
->dsbflags
;
917 if(!(data
->dsbflags
&DSBCAPS_LOCDEFER
))
919 if(This
->loc_status
== DSBSTATUS_LOCHARDWARE
)
920 caps
->dwFlags
|= DSBCAPS_LOCHARDWARE
;
921 else if(This
->loc_status
== DSBSTATUS_LOCSOFTWARE
)
922 caps
->dwFlags
|= DSBCAPS_LOCSOFTWARE
;
924 caps
->dwBufferBytes
= data
->buf_size
;
925 caps
->dwUnlockTransferRate
= 4096;
926 caps
->dwPlayCpuOverhead
= 0;
931 HRESULT WINAPI
DSBuffer_GetCurrentPosition(IDirectSoundBuffer8
*iface
, DWORD
*playpos
, DWORD
*curpos
)
933 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
934 ALsizei writecursor
, pos
;
937 TRACE("(%p)->(%p, %p)\n", iface
, playpos
, curpos
);
940 if(This
->segsize
!= 0)
942 ALint queued
= QBUFFERS
;
943 ALint status
= AL_INITIAL
;
946 EnterCriticalSection(&This
->share
->crst
);
948 if(LIKELY(This
->source
))
950 setALContext(This
->ctx
);
951 alGetSourcei(This
->source
, AL_BUFFERS_QUEUED
, &queued
);
952 alGetSourcei(This
->source
, AL_BYTE_OFFSET
, &ofs
);
953 alGetSourcei(This
->source
, AL_SOURCE_STATE
, &status
);
958 if(status
== AL_STOPPED
)
959 pos
= This
->segsize
*queued
+ This
->queue_base
;
961 pos
= ofs
+ This
->queue_base
;
962 if(pos
>= data
->buf_size
)
965 pos
%= data
->buf_size
;
966 else if(This
->isplaying
)
968 pos
= data
->buf_size
;
969 alSourceStop(This
->source
);
970 alSourcei(This
->source
, AL_BUFFER
, 0);
972 This
->isplaying
= FALSE
;
976 writecursor
= (This
->segsize
*QBUFFERS
+ pos
) % data
->buf_size
;
978 writecursor
= pos
% data
->buf_size
;
980 LeaveCriticalSection(&This
->share
->crst
);
984 const WAVEFORMATEX
*format
= &data
->format
.Format
;
985 ALint status
= AL_INITIAL
;
988 if(LIKELY(This
->source
))
990 setALContext(This
->ctx
);
991 alGetSourcei(This
->source
, AL_BYTE_OFFSET
, &ofs
);
992 alGetSourcei(This
->source
, AL_SOURCE_STATE
, &status
);
997 if(status
== AL_PLAYING
)
1000 writecursor
= format
->nSamplesPerSec
/ This
->primary
->refresh
;
1001 writecursor
*= format
->nBlockAlign
;
1005 /* AL_STOPPED means the source naturally reached its end, where
1006 * DirectSound's position should be at the end (OpenAL reports 0
1007 * for stopped sources). The Stop method correlates to pausing,
1008 * which would put the source into an AL_PAUSED state and correctly
1009 * hold its current position. AL_INITIAL means the buffer hasn't
1010 * been played since last changing location.
1014 case AL_STOPPED
: pos
= data
->buf_size
; break;
1015 case AL_PAUSED
: pos
= ofs
; break;
1016 case AL_INITIAL
: pos
= This
->lastpos
; break;
1021 writecursor
= (writecursor
+ pos
) % data
->buf_size
;
1023 TRACE("%p Play pos = %u, write pos = %u\n", This
, pos
, writecursor
);
1025 if(pos
> data
->buf_size
)
1027 ERR("playpos > buf_size\n");
1028 pos
%= data
->buf_size
;
1030 if(writecursor
>= data
->buf_size
)
1032 ERR("writepos >= buf_size\n");
1033 writecursor
%= data
->buf_size
;
1036 if(playpos
) *playpos
= pos
;
1037 if(curpos
) *curpos
= writecursor
;
1042 static HRESULT WINAPI
DSBuffer_GetFormat(IDirectSoundBuffer8
*iface
, WAVEFORMATEX
*wfx
, DWORD allocated
, DWORD
*written
)
1044 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1048 TRACE("(%p)->(%p, %lu, %p)\n", iface
, wfx
, allocated
, written
);
1050 if(!wfx
&& !written
)
1052 WARN("Cannot report format or format size\n");
1053 return DSERR_INVALIDPARAM
;
1056 size
= sizeof(This
->buffer
->format
.Format
) + This
->buffer
->format
.Format
.cbSize
;
1059 if(allocated
< size
)
1060 hr
= DSERR_INVALIDPARAM
;
1062 memcpy(wfx
, &This
->buffer
->format
.Format
, size
);
1070 static HRESULT WINAPI
DSBuffer_GetVolume(IDirectSoundBuffer8
*iface
, LONG
*vol
)
1072 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1075 TRACE("(%p)->(%p)\n", iface
, vol
);
1079 WARN("Invalid pointer\n");
1080 return DSERR_INVALIDPARAM
;
1083 hr
= DSERR_CONTROLUNAVAIL
;
1084 if(!(This
->buffer
->dsbflags
&DSBCAPS_CTRLVOLUME
))
1085 WARN("Volume control not set\n");
1088 *vol
= This
->current
.vol
;
1095 static HRESULT WINAPI
DSBuffer_GetPan(IDirectSoundBuffer8
*iface
, LONG
*pan
)
1097 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1100 TRACE("(%p)->(%p)\n", iface
, pan
);
1104 WARN("Invalid pointer\n");
1105 return DSERR_INVALIDPARAM
;
1108 hr
= DSERR_CONTROLUNAVAIL
;
1109 if(!(This
->buffer
->dsbflags
&DSBCAPS_CTRLPAN
))
1110 WARN("Panning control not set\n");
1113 *pan
= This
->current
.pan
;
1120 static HRESULT WINAPI
DSBuffer_GetFrequency(IDirectSoundBuffer8
*iface
, DWORD
*freq
)
1122 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1125 TRACE("(%p)->(%p)\n", iface
, freq
);
1129 WARN("Invalid pointer\n");
1130 return DSERR_INVALIDPARAM
;
1133 hr
= DSERR_CONTROLUNAVAIL
;
1134 if(!(This
->buffer
->dsbflags
&DSBCAPS_CTRLFREQUENCY
))
1135 WARN("Frequency control not set\n");
1138 *freq
= This
->current
.frequency
;
1145 HRESULT WINAPI
DSBuffer_GetStatus(IDirectSoundBuffer8
*iface
, DWORD
*status
)
1147 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1148 ALint state
, looping
;
1150 TRACE("(%p)->(%p)\n", iface
, status
);
1154 WARN("Invalid pointer\n");
1155 return DSERR_INVALIDPARAM
;
1159 if(This
->segsize
== 0)
1163 if(LIKELY(This
->source
))
1165 setALContext(This
->ctx
);
1166 alGetSourcei(This
->source
, AL_SOURCE_STATE
, &state
);
1167 alGetSourcei(This
->source
, AL_LOOPING
, &looping
);
1174 EnterCriticalSection(&This
->share
->crst
);
1175 state
= This
->isplaying
? AL_PLAYING
: AL_PAUSED
;
1176 looping
= This
->islooping
;
1177 LeaveCriticalSection(&This
->share
->crst
);
1180 if((This
->buffer
->dsbflags
&DSBCAPS_LOCDEFER
))
1181 *status
|= This
->loc_status
;
1182 if(state
== AL_PLAYING
)
1183 *status
|= DSBSTATUS_PLAYING
| (looping
? DSBSTATUS_LOOPING
: 0);
1185 TRACE("%p status = 0x%08lx\n", This
, *status
);
1189 HRESULT WINAPI
DSBuffer_Initialize(IDirectSoundBuffer8
*iface
, IDirectSound
*ds
, const DSBUFFERDESC
*desc
)
1191 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1196 TRACE("(%p)->(%p, %p)\n", iface
, ds
, desc
);
1198 EnterCriticalSection(&This
->share
->crst
);
1199 setALContext(This
->ctx
);
1201 hr
= DSERR_ALREADYINITIALIZED
;
1202 if(This
->init_done
) goto out
;
1204 prim
= This
->primary
;
1207 hr
= DSERR_INVALIDPARAM
;
1210 WARN("Missing DSound buffer description\n");
1213 if(!desc
->lpwfxFormat
)
1215 WARN("Missing buffer format (%p)\n", This
);
1218 if((desc
->dwFlags
&DSBCAPS_CTRL3D
) && desc
->lpwfxFormat
->nChannels
!= 1)
1220 if(prim
->parent
->is_8
)
1222 /* DirectSoundBuffer8 objects aren't allowed non-mono 3D
1224 WARN("Can't create multi-channel 3D buffers\n");
1229 static int once
= 0;
1231 ERR("Multi-channel 3D sounds are not spatialized\n");
1234 if((desc
->dwFlags
&DSBCAPS_CTRLPAN
) && desc
->lpwfxFormat
->nChannels
!= 1)
1236 static int once
= 0;
1238 ERR("Panning for multi-channel buffers is not supported\n");
1241 hr
= DSData_Create(&This
->buffer
, desc
, prim
);
1242 if(FAILED(hr
)) goto out
;
1244 data
= This
->buffer
;
1245 if(data
->format
.Format
.wBitsPerSample
== 8)
1246 memset(data
->data
, 0x80, data
->buf_size
);
1248 memset(data
->data
, 0x00, data
->buf_size
);
1251 data
= This
->buffer
;
1252 if(!(data
->dsbflags
&DSBCAPS_STATIC
) && !HAS_EXTENSION(This
->share
, SOFTX_MAP_BUFFER
))
1254 This
->segsize
= (data
->format
.Format
.nAvgBytesPerSec
+prim
->refresh
-1) / prim
->refresh
;
1255 This
->segsize
= clampI(This
->segsize
, data
->format
.Format
.nBlockAlign
, 2048);
1256 This
->segsize
+= data
->format
.Format
.nBlockAlign
- 1;
1257 This
->segsize
-= This
->segsize
%data
->format
.Format
.nBlockAlign
;
1259 alGenBuffers(QBUFFERS
, This
->stream_bids
);
1262 if(!(data
->dsbflags
&DSBCAPS_CTRL3D
))
1264 /* Non-3D sources aren't distance attenuated. */
1265 This
->current
.ds3d
.dwMode
= DS3DMODE_DISABLE
;
1269 if(HAS_EXTENSION(This
->share
, EXT_EFX
))
1273 alGenFilters(1+EAX_MAX_FXSLOTS
, This
->filter
);
1274 alFilteri(This
->filter
[0], AL_FILTER_TYPE
, AL_FILTER_LOWPASS
);
1275 for(i
= 0;i
< EAX_MAX_FXSLOTS
;++i
)
1276 alFilteri(This
->filter
[1+i
], AL_FILTER_TYPE
, AL_FILTER_LOWPASS
);
1277 if(UNLIKELY(alGetError() != AL_NO_ERROR
))
1279 alDeleteFilters(1+EAX_MAX_FXSLOTS
, This
->filter
);
1280 This
->filter
[0] = 0;
1281 for(i
= 0;i
< EAX_MAX_FXSLOTS
;++i
)
1282 This
->filter
[1+i
] = 0;
1286 if(!This
->current
.frequency
)
1287 This
->current
.frequency
= data
->format
.Format
.nSamplesPerSec
;
1288 This
->filter_mBLimit
= prim
->filter_mBLimit
;
1291 if(!(data
->dsbflags
&DSBCAPS_LOCDEFER
))
1294 if((data
->dsbflags
&DSBCAPS_LOCHARDWARE
)) loc
= DSBSTATUS_LOCHARDWARE
;
1295 else if((data
->dsbflags
&DSBCAPS_LOCSOFTWARE
)) loc
= DSBSTATUS_LOCSOFTWARE
;
1296 hr
= DSBuffer_SetLoc(This
, loc
);
1299 This
->init_done
= SUCCEEDED(hr
);
1302 LeaveCriticalSection(&This
->share
->crst
);
1307 static HRESULT WINAPI
DSBuffer_Lock(IDirectSoundBuffer8
*iface
, DWORD ofs
, DWORD bytes
, void **ptr1
, DWORD
*len1
, void **ptr2
, DWORD
*len2
, DWORD flags
)
1309 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1312 TRACE("(%p)->(%lu, %lu, %p, %p, %p, %p, 0x%lx)\n", This
, ofs
, bytes
, ptr1
, len1
, ptr2
, len2
, flags
);
1316 WARN("Invalid pointer/len %p %p\n", ptr1
, len1
);
1317 return DSERR_INVALIDPARAM
;
1322 if(ptr2
) *ptr2
= NULL
;
1325 if((flags
&DSBLOCK_FROMWRITECURSOR
))
1326 DSBuffer_GetCurrentPosition(iface
, NULL
, &ofs
);
1327 else if(ofs
>= (DWORD
)This
->buffer
->buf_size
)
1329 WARN("Invalid ofs %lu\n", ofs
);
1330 return DSERR_INVALIDPARAM
;
1332 if((flags
&DSBLOCK_ENTIREBUFFER
))
1333 bytes
= This
->buffer
->buf_size
;
1334 else if(bytes
> (DWORD
)This
->buffer
->buf_size
)
1336 WARN("Invalid size %lu\n", bytes
);
1337 return DSERR_INVALIDPARAM
;
1340 if(InterlockedExchange(&This
->buffer
->locked
, TRUE
) == TRUE
)
1342 WARN("Already locked\n");
1343 return DSERR_INVALIDPARAM
;
1346 *ptr1
= This
->buffer
->data
+ ofs
;
1347 if(bytes
>= (DWORD
)This
->buffer
->buf_size
-ofs
)
1349 *len1
= This
->buffer
->buf_size
- ofs
;
1350 remain
= bytes
- *len1
;
1358 if(ptr2
&& len2
&& remain
)
1360 *ptr2
= This
->buffer
->data
;
1367 static HRESULT WINAPI
DSBuffer_Play(IDirectSoundBuffer8
*iface
, DWORD res1
, DWORD prio
, DWORD flags
)
1369 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1370 ALint state
= AL_STOPPED
;
1374 TRACE("(%p)->(%lu, %lu, %lu)\n", iface
, res1
, prio
, flags
);
1376 EnterCriticalSection(&This
->share
->crst
);
1377 setALContext(This
->ctx
);
1379 hr
= DSERR_BUFFERLOST
;
1380 if(This
->bufferlost
)
1382 WARN("Buffer %p lost\n", This
);
1386 data
= This
->buffer
;
1387 if((data
->dsbflags
&DSBCAPS_LOCDEFER
))
1391 hr
= DSERR_INVALIDPARAM
;
1392 if((flags
&(DSBPLAY_LOCSOFTWARE
|DSBPLAY_LOCHARDWARE
)) == (DSBPLAY_LOCSOFTWARE
|DSBPLAY_LOCHARDWARE
))
1394 WARN("Both hardware and software specified\n");
1398 if((flags
&DSBPLAY_LOCHARDWARE
)) loc
= DSBSTATUS_LOCHARDWARE
;
1399 else if((flags
&DSBPLAY_LOCSOFTWARE
)) loc
= DSBSTATUS_LOCSOFTWARE
;
1401 if(loc
&& This
->loc_status
&& loc
!= This
->loc_status
)
1403 if(This
->segsize
!= 0)
1410 alGetSourcei(This
->source
, AL_SOURCE_STATE
, &state
);
1414 if(state
== AL_PLAYING
)
1416 ERR("Attemping to change location on playing buffer\n");
1421 hr
= DSBuffer_SetLoc(This
, loc
);
1422 if(FAILED(hr
)) goto out
;
1426 ERR("Invalid priority set for non-deferred buffer %p, %lu!\n", This
->buffer
, prio
);
1427 hr
= DSERR_INVALIDPARAM
;
1431 if(This
->segsize
!= 0)
1433 This
->islooping
= !!(flags
&DSBPLAY_LOOPING
);
1434 if(This
->isplaying
) state
= AL_PLAYING
;
1438 alSourcei(This
->source
, AL_LOOPING
, (flags
&DSBPLAY_LOOPING
) ? AL_TRUE
: AL_FALSE
);
1439 alGetSourcei(This
->source
, AL_SOURCE_STATE
, &state
);
1444 if(state
== AL_PLAYING
)
1447 if(This
->segsize
== 0)
1449 if(state
== AL_INITIAL
)
1451 alSourcei(This
->source
, AL_BUFFER
, data
->bid
);
1452 alSourcei(This
->source
, AL_BYTE_OFFSET
, This
->lastpos
% data
->buf_size
);
1454 alSourcePlay(This
->source
);
1458 alSourceRewind(This
->source
);
1459 alSourcei(This
->source
, AL_BUFFER
, 0);
1460 This
->queue_base
= This
->data_offset
% data
->buf_size
;
1463 if(alGetError() != AL_NO_ERROR
)
1465 ERR("Couldn't start source\n");
1469 This
->isplaying
= TRUE
;
1472 DSBuffer_addnotify(This
);
1476 LeaveCriticalSection(&This
->share
->crst
);
1480 static HRESULT WINAPI
DSBuffer_SetCurrentPosition(IDirectSoundBuffer8
*iface
, DWORD pos
)
1482 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1485 TRACE("(%p)->(%lu)\n", iface
, pos
);
1487 data
= This
->buffer
;
1488 if(pos
>= (DWORD
)data
->buf_size
)
1489 return DSERR_INVALIDPARAM
;
1490 pos
-= pos
%data
->format
.Format
.nBlockAlign
;
1492 EnterCriticalSection(&This
->share
->crst
);
1494 if(This
->segsize
!= 0)
1498 setALContext(This
->ctx
);
1499 /* Perform a flush, so the next timer update will restart at the
1500 * proper position */
1501 alSourceRewind(This
->source
);
1502 alSourcei(This
->source
, AL_BUFFER
, 0);
1506 This
->queue_base
= This
->data_offset
= pos
;
1511 if(LIKELY(This
->source
))
1513 setALContext(This
->ctx
);
1514 alSourcei(This
->source
, AL_BYTE_OFFSET
, pos
);
1519 This
->lastpos
= pos
;
1521 LeaveCriticalSection(&This
->share
->crst
);
1525 static HRESULT WINAPI
DSBuffer_SetFormat(IDirectSoundBuffer8
*iface
, const WAVEFORMATEX
*wfx
)
1527 /* This call only works on primary buffers */
1528 WARN("(%p)->(%p)\n", iface
, wfx
);
1529 return DSERR_INVALIDCALL
;
1532 static HRESULT WINAPI
DSBuffer_SetVolume(IDirectSoundBuffer8
*iface
, LONG vol
)
1534 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1537 TRACE("(%p)->(%ld)\n", iface
, vol
);
1539 if(vol
> DSBVOLUME_MAX
|| vol
< DSBVOLUME_MIN
)
1541 WARN("Invalid volume (%ld)\n", vol
);
1542 return DSERR_INVALIDPARAM
;
1545 if(!(This
->buffer
->dsbflags
&DSBCAPS_CTRLVOLUME
))
1546 hr
= DSERR_CONTROLUNAVAIL
;
1549 This
->current
.vol
= vol
;
1550 if(LIKELY(This
->source
))
1552 setALContext(This
->ctx
);
1553 alSourcef(This
->source
, AL_GAIN
, mB_to_gain((float)vol
));
1561 static HRESULT WINAPI
DSBuffer_SetPan(IDirectSoundBuffer8
*iface
, LONG pan
)
1563 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1566 TRACE("(%p)->(%ld)\n", iface
, pan
);
1568 if(pan
> DSBPAN_RIGHT
|| pan
< DSBPAN_LEFT
)
1570 WARN("invalid parameter: pan = %ld\n", pan
);
1571 return DSERR_INVALIDPARAM
;
1574 if(!(This
->buffer
->dsbflags
&DSBCAPS_CTRLPAN
))
1575 hr
= DSERR_CONTROLUNAVAIL
;
1578 This
->current
.pan
= pan
;
1579 if(LIKELY(This
->source
&& !(This
->buffer
->dsbflags
&DSBCAPS_CTRL3D
)))
1582 pos
[0] = (ALfloat
)(pan
-DSBPAN_LEFT
)/(ALfloat
)(DSBPAN_RIGHT
-DSBPAN_LEFT
) - 0.5f
;
1584 /* NOTE: Strict movement along the X plane can cause the sound to
1585 * jump between left and right sharply. Using a curved path helps
1588 pos
[2] = -sqrtf(1.0f
- pos
[0]*pos
[0]);
1590 setALContext(This
->ctx
);
1591 alSourcefv(This
->source
, AL_POSITION
, pos
);
1600 static HRESULT WINAPI
DSBuffer_SetFrequency(IDirectSoundBuffer8
*iface
, DWORD freq
)
1602 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1606 TRACE("(%p)->(%lu)\n", iface
, freq
);
1608 if(freq
!= 0 && (freq
< DSBFREQUENCY_MIN
|| freq
> DSBFREQUENCY_MAX
))
1610 WARN("invalid parameter: freq = %lu\n", freq
);
1611 return DSERR_INVALIDPARAM
;
1614 data
= This
->buffer
;
1615 if(!(data
->dsbflags
&DSBCAPS_CTRLFREQUENCY
))
1616 hr
= DSERR_CONTROLUNAVAIL
;
1619 This
->current
.frequency
= freq
? freq
: data
->format
.Format
.nSamplesPerSec
;
1620 if(LIKELY(This
->source
))
1622 setALContext(This
->ctx
);
1623 alSourcef(This
->source
, AL_PITCH
,
1624 This
->current
.frequency
/ (ALfloat
)data
->format
.Format
.nSamplesPerSec
1634 static HRESULT WINAPI
DSBuffer_Stop(IDirectSoundBuffer8
*iface
)
1636 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1638 TRACE("(%p)->()\n", iface
);
1640 EnterCriticalSection(&This
->share
->crst
);
1641 if(LIKELY(This
->source
))
1643 const ALuint source
= This
->source
;
1646 setALContext(This
->ctx
);
1647 alSourcePause(source
);
1648 alGetSourcei(source
, AL_BYTE_OFFSET
, &ofs
);
1649 alGetSourcei(source
, AL_SOURCE_STATE
, &state
);
1652 This
->isplaying
= FALSE
;
1654 DSPrimary_triggernots(This
->primary
);
1655 /* Ensure the notification's last tracked position is updated, as well
1656 * as the queue offsets for streaming sources.
1658 if(This
->segsize
== 0)
1659 This
->lastpos
= (state
== AL_STOPPED
) ? This
->buffer
->buf_size
: ofs
;
1662 DSData
*data
= This
->buffer
;
1665 alGetSourcei(This
->source
, AL_BUFFERS_PROCESSED
, &done
);
1666 This
->queue_base
+= This
->segsize
*done
+ ofs
;
1667 if(This
->queue_base
>= data
->buf_size
)
1670 This
->queue_base
%= data
->buf_size
;
1672 This
->queue_base
= data
->buf_size
;
1674 This
->lastpos
= This
->queue_base
;
1676 alSourceRewind(This
->source
);
1677 alSourcei(This
->source
, AL_BUFFER
, 0);
1681 This
->data_offset
= This
->lastpos
% data
->buf_size
;
1683 This
->islooping
= FALSE
;
1686 LeaveCriticalSection(&This
->share
->crst
);
1691 static HRESULT WINAPI
DSBuffer_Unlock(IDirectSoundBuffer8
*iface
, void *ptr1
, DWORD len1
, void *ptr2
, DWORD len2
)
1693 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1694 DSData
*buf
= This
->buffer
;
1695 DWORD bufsize
= buf
->buf_size
;
1696 DWORD_PTR ofs1
, ofs2
;
1697 DWORD_PTR boundary
= (DWORD_PTR
)buf
->data
;
1700 TRACE("(%p)->(%p, %lu, %p, %lu)\n", iface
, ptr1
, len1
, ptr2
, len2
);
1702 if(InterlockedExchange(&buf
->locked
, FALSE
) == FALSE
)
1704 WARN("Not locked\n");
1705 return DSERR_INVALIDPARAM
;
1708 hr
= DSERR_INVALIDPARAM
;
1709 /* Make sure offset is between boundary and boundary + bufsize */
1710 ofs1
= (DWORD_PTR
)ptr1
;
1711 ofs2
= (DWORD_PTR
)ptr2
;
1712 if(ofs1
< boundary
|| (ofs2
&& ofs2
!= boundary
))
1716 if(bufsize
-ofs1
< len1
|| len2
> ofs1
)
1725 if(HAS_EXTENSION(This
->share
, SOFTX_MAP_BUFFER
))
1727 setALContext(This
->ctx
);
1728 alFlushMappedBufferSOFT(buf
->bid
, 0, buf
->buf_size
);
1732 else if(This
->segsize
== 0)
1734 setALContext(This
->ctx
);
1735 alBufferData(buf
->bid
, buf
->buf_format
, buf
->data
, buf
->buf_size
,
1736 buf
->format
.Format
.nSamplesPerSec
);
1743 WARN("Invalid parameters (0x%lx,%lu) (%p,%lu,%p,%lu)\n", boundary
, bufsize
, ptr1
, len1
, ptr2
, len2
);
1747 static HRESULT WINAPI
DSBuffer_Restore(IDirectSoundBuffer8
*iface
)
1749 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1752 TRACE("(%p)->()\n", iface
);
1754 EnterCriticalSection(&This
->share
->crst
);
1755 if(This
->primary
->parent
->prio_level
< DSSCL_WRITEPRIMARY
||
1756 (IDirectSoundBuffer
*)&This
->IDirectSoundBuffer8_iface
== This
->primary
->write_emu
)
1758 This
->bufferlost
= 0;
1762 hr
= DSERR_BUFFERLOST
;
1763 LeaveCriticalSection(&This
->share
->crst
);
1768 static HRESULT WINAPI
DSBuffer_SetFX(IDirectSoundBuffer8
*iface
, DWORD fxcount
, DSEFFECTDESC
*desc
, DWORD
*rescodes
)
1770 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1771 ALenum state
= AL_INITIAL
;
1776 TRACE("(%p)->(%lu, %p, %p)\n", This
, fxcount
, desc
, rescodes
);
1778 data
= This
->buffer
;
1779 if(!(data
->dsbflags
&DSBCAPS_CTRLFX
))
1781 WARN("FX control not set\n");
1782 return DSERR_CONTROLUNAVAIL
;
1787 WARN("Buffer is locked\n");
1788 return DSERR_INVALIDCALL
;
1791 EnterCriticalSection(&This
->share
->crst
);
1793 setALContext(This
->ctx
);
1794 if(LIKELY(This
->source
))
1796 alGetSourcei(This
->source
, AL_SOURCE_STATE
, &state
);
1800 if(This
->segsize
!= 0 && state
!= AL_PLAYING
)
1801 state
= This
->isplaying
? AL_PLAYING
: AL_PAUSED
;
1802 if(state
== AL_PLAYING
)
1804 WARN("Buffer is playing\n");
1805 hr
= DSERR_INVALIDCALL
;
1809 hr
= DSERR_INVALIDPARAM
;
1812 if(desc
|| rescodes
)
1814 WARN("Non-NULL desc and/or result pointer specified with no effects.\n");
1818 /* No effects; we can handle that */
1823 if(!desc
|| !rescodes
)
1825 WARN("NULL desc and/or result pointer specified.\n");
1829 /* We don't (currently) handle DSound effects */
1830 for(i
= 0;i
< fxcount
;++i
)
1832 FIXME("Cannot handle effect: %s\n", debugstr_guid(&desc
[i
].guidDSFXClass
));
1833 rescodes
[i
] = DSFXR_FAILED
;
1838 LeaveCriticalSection(&This
->share
->crst
);
1843 static HRESULT WINAPI
DSBuffer_AcquireResources(IDirectSoundBuffer8
*iface
, DWORD flags
, DWORD fxcount
, DWORD
*rescodes
)
1845 DSBuffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1848 TRACE("(%p)->(%lu, %lu, %p)\n", This
, flags
, fxcount
, rescodes
);
1850 /* effects aren't supported at the moment.. */
1851 if(fxcount
!= 0 || rescodes
)
1853 WARN("Non-zero effect count and/or result pointer specified with no effects.\n");
1854 return DSERR_INVALIDPARAM
;
1857 EnterCriticalSection(&This
->share
->crst
);
1858 setALContext(This
->ctx
);
1861 if((This
->buffer
->dsbflags
&DSBCAPS_LOCDEFER
))
1865 hr
= DSERR_INVALIDPARAM
;
1866 if((flags
&(DSBPLAY_LOCSOFTWARE
|DSBPLAY_LOCHARDWARE
)) == (DSBPLAY_LOCSOFTWARE
|DSBPLAY_LOCHARDWARE
))
1868 WARN("Both hardware and software specified\n");
1872 if((flags
&DSBPLAY_LOCHARDWARE
)) loc
= DSBSTATUS_LOCHARDWARE
;
1873 else if((flags
&DSBPLAY_LOCSOFTWARE
)) loc
= DSBSTATUS_LOCSOFTWARE
;
1875 if(loc
&& This
->loc_status
&& loc
!= This
->loc_status
)
1877 ALint state
= AL_INITIAL
;
1879 if(This
->segsize
!= 0)
1886 alGetSourcei(This
->source
, AL_SOURCE_STATE
, &state
);
1890 if(state
== AL_PLAYING
)
1892 ERR("Attemping to change location on playing buffer\n");
1897 hr
= DSBuffer_SetLoc(This
, loc
);
1902 LeaveCriticalSection(&This
->share
->crst
);
1906 static HRESULT WINAPI
DSBuffer_GetObjectInPath(IDirectSoundBuffer8
*iface
, REFGUID guid
, DWORD idx
, REFGUID rguidiface
, void **ppv
)
1908 FIXME("(%p)->(%s, %lu, %s, %p) : stub!\n", iface
, debugstr_guid(guid
), idx
, debugstr_guid(rguidiface
), ppv
);
1912 static const IDirectSoundBuffer8Vtbl DSBuffer_Vtbl
= {
1913 DSBuffer_QueryInterface
,
1917 DSBuffer_GetCurrentPosition
,
1921 DSBuffer_GetFrequency
,
1923 DSBuffer_Initialize
,
1926 DSBuffer_SetCurrentPosition
,
1930 DSBuffer_SetFrequency
,
1935 DSBuffer_AcquireResources
,
1936 DSBuffer_GetObjectInPath
1940 void DSBuffer_SetParams(DSBuffer
*This
, const DS3DBUFFER
*params
, LONG flags
)
1942 DSPrimary
*prim
= This
->primary
;
1943 const ALuint source
= This
->source
;
1944 union BufferParamFlags dirty
= { flags
};
1947 /* Copy deferred parameters first. */
1949 This
->current
.ds3d
.vPosition
= params
->vPosition
;
1951 This
->current
.ds3d
.vVelocity
= params
->vVelocity
;
1952 if(dirty
.bit
.cone_angles
)
1954 This
->current
.ds3d
.dwInsideConeAngle
= params
->dwInsideConeAngle
;
1955 This
->current
.ds3d
.dwOutsideConeAngle
= params
->dwOutsideConeAngle
;
1957 if(dirty
.bit
.cone_orient
)
1958 This
->current
.ds3d
.vConeOrientation
= params
->vConeOrientation
;
1959 if(dirty
.bit
.cone_outsidevolume
)
1960 This
->current
.ds3d
.lConeOutsideVolume
= params
->lConeOutsideVolume
;
1961 if(dirty
.bit
.min_distance
)
1962 This
->current
.ds3d
.flMinDistance
= params
->flMinDistance
;
1963 if(dirty
.bit
.max_distance
)
1964 This
->current
.ds3d
.flMaxDistance
= params
->flMaxDistance
;
1966 This
->current
.ds3d
.dwMode
= params
->dwMode
;
1967 /* Always copy EAX params (they're always set deferred first, then applied
1968 * when committing all params).
1970 This
->current
.eax
= This
->deferred
.eax
;
1971 for(i
= 0;i
< EAX_MAX_ACTIVE_FXSLOTS
;++i
)
1972 This
->current
.fxslot_targets
[i
] = This
->deferred
.fxslot_targets
[i
];
1973 for(i
= 0;i
< EAX_MAX_FXSLOTS
;++i
)
1974 This
->current
.send
[i
] = This
->deferred
.send
[i
];
1975 This
->current
.eax1_reverbmix
= This
->deferred
.eax1_reverbmix
;
1977 /* Now apply what's changed to OpenAL. */
1978 if(UNLIKELY(!source
)) return;
1981 alSource3f(source
, AL_POSITION
, params
->vPosition
.x
, params
->vPosition
.y
,
1982 -params
->vPosition
.z
);
1984 alSource3f(source
, AL_VELOCITY
, params
->vVelocity
.x
, params
->vVelocity
.y
,
1985 -params
->vVelocity
.z
);
1986 if(dirty
.bit
.cone_angles
)
1988 alSourcei(source
, AL_CONE_INNER_ANGLE
, params
->dwInsideConeAngle
);
1989 alSourcei(source
, AL_CONE_OUTER_ANGLE
, params
->dwOutsideConeAngle
);
1991 if(dirty
.bit
.cone_orient
)
1992 alSource3f(source
, AL_DIRECTION
, params
->vConeOrientation
.x
,
1993 params
->vConeOrientation
.y
,
1994 -params
->vConeOrientation
.z
);
1995 if(dirty
.bit
.cone_outsidevolume
)
1996 alSourcef(source
, AL_CONE_OUTER_GAIN
, mB_to_gain((float)params
->lConeOutsideVolume
));
1997 if(dirty
.bit
.min_distance
)
1998 alSourcef(source
, AL_REFERENCE_DISTANCE
, params
->flMinDistance
);
1999 if(dirty
.bit
.max_distance
)
2000 alSourcef(source
, AL_MAX_DISTANCE
, params
->flMaxDistance
);
2003 if(HAS_EXTENSION(This
->share
, SOFT_SOURCE_SPATIALIZE
))
2004 alSourcei(source
, AL_SOURCE_SPATIALIZE_SOFT
,
2005 (params
->dwMode
==DS3DMODE_DISABLE
) ? AL_FALSE
: AL_TRUE
2007 alSourcei(source
, AL_SOURCE_RELATIVE
,
2008 (params
->dwMode
!=DS3DMODE_NORMAL
) ? AL_TRUE
: AL_FALSE
2012 if(dirty
.bit
.dry_filter
)
2013 alSourcei(source
, AL_DIRECT_FILTER
, This
->filter
[0]);
2014 if(dirty
.bit
.send_filters
)
2016 for(i
= 0;i
< EAX_MAX_ACTIVE_FXSLOTS
;++i
)
2018 DWORD target
= This
->current
.fxslot_targets
[i
];
2019 ALuint filter
=0, slot
=0;
2020 if(target
< FXSLOT_TARGET_NULL
)
2022 ALint idx
= (target
== FXSLOT_TARGET_PRIMARY
) ?
2023 prim
->primary_idx
: (ALint
)target
;
2026 slot
= prim
->auxslot
[idx
];
2027 filter
= This
->filter
[1+idx
];
2030 alSource3i(source
, AL_AUXILIARY_SEND_FILTER
, slot
, i
, filter
);
2033 if(dirty
.bit
.doppler
)
2034 alSourcef(source
, AL_DOPPLER_FACTOR
, This
->current
.eax
.flDopplerFactor
);
2035 if(dirty
.bit
.rolloff
)
2036 alSourcef(source
, AL_ROLLOFF_FACTOR
, This
->current
.eax
.flRolloffFactor
+
2037 prim
->current
.ds3d
.flRolloffFactor
);
2038 if(dirty
.bit
.room_rolloff
)
2039 alSourcef(source
, AL_ROOM_ROLLOFF_FACTOR
, This
->current
.eax
.flRoomRolloffFactor
);
2040 if(dirty
.bit
.cone_outsidevolumehf
)
2041 alSourcef(source
, AL_CONE_OUTER_GAINHF
, mB_to_gain((float)This
->current
.eax
.lOutsideVolumeHF
));
2042 if(dirty
.bit
.air_absorb
)
2043 alSourcef(source
, AL_AIR_ABSORPTION_FACTOR
, This
->current
.eax
.flAirAbsorptionFactor
*
2044 prim
->current
.ctx
.flAirAbsorptionHF
/ -5.0f
);
2047 alSourcei(source
, AL_DIRECT_FILTER_GAINHF_AUTO
,
2048 (This
->current
.eax
.dwFlags
&EAXSOURCEFLAGS_DIRECTHFAUTO
) ? AL_TRUE
: AL_FALSE
);
2049 alSourcei(source
, AL_AUXILIARY_SEND_FILTER_GAIN_AUTO
,
2050 (This
->current
.eax
.dwFlags
&EAXSOURCEFLAGS_ROOMAUTO
) ? AL_TRUE
: AL_FALSE
);
2051 alSourcei(source
, AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO
,
2052 (This
->current
.eax
.dwFlags
&EAXSOURCEFLAGS_ROOMHFAUTO
) ? AL_TRUE
: AL_FALSE
);
2056 static HRESULT WINAPI
DSBuffer3D_QueryInterface(IDirectSound3DBuffer
*iface
, REFIID riid
, void **ppv
)
2058 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2059 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2060 return DSBuffer_GetInterface(This
, riid
, ppv
);
2063 static ULONG WINAPI
DSBuffer3D_AddRef(IDirectSound3DBuffer
*iface
)
2065 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2068 InterlockedIncrement(&This
->all_ref
);
2069 ret
= InterlockedIncrement(&This
->ds3d_ref
);
2070 TRACE("(%p) ref %lu\n", iface
, ret
);
2075 static ULONG WINAPI
DSBuffer3D_Release(IDirectSound3DBuffer
*iface
)
2077 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2080 ret
= InterlockedDecrement(&This
->ds3d_ref
);
2081 TRACE("(%p) ref %lu\n", iface
, ret
);
2082 if(InterlockedDecrement(&This
->all_ref
) == 0)
2083 DSBuffer_Destroy(This
);
2088 static HRESULT WINAPI
DSBuffer3D_GetConeAngles(IDirectSound3DBuffer
*iface
, DWORD
*pdwInsideConeAngle
, DWORD
*pdwOutsideConeAngle
)
2090 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2092 TRACE("(%p)->(%p, %p)\n", This
, pdwInsideConeAngle
, pdwOutsideConeAngle
);
2093 if(!pdwInsideConeAngle
|| !pdwOutsideConeAngle
)
2095 WARN("Invalid pointers (%p, %p)\n", pdwInsideConeAngle
, pdwOutsideConeAngle
);
2096 return DSERR_INVALIDPARAM
;
2099 EnterCriticalSection(&This
->share
->crst
);
2100 *pdwInsideConeAngle
= This
->current
.ds3d
.dwInsideConeAngle
;
2101 *pdwOutsideConeAngle
= This
->current
.ds3d
.dwOutsideConeAngle
;
2102 LeaveCriticalSection(&This
->share
->crst
);
2107 static HRESULT WINAPI
DSBuffer3D_GetConeOrientation(IDirectSound3DBuffer
*iface
, D3DVECTOR
*orient
)
2109 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2111 TRACE("(%p)->(%p)\n", This
, orient
);
2114 WARN("Invalid pointer\n");
2115 return DSERR_INVALIDPARAM
;
2118 EnterCriticalSection(&This
->share
->crst
);
2119 *orient
= This
->current
.ds3d
.vConeOrientation
;
2120 LeaveCriticalSection(&This
->share
->crst
);
2125 static HRESULT WINAPI
DSBuffer3D_GetConeOutsideVolume(IDirectSound3DBuffer
*iface
, LONG
*vol
)
2127 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2129 TRACE("(%p)->(%p)\n", This
, vol
);
2132 WARN("Invalid pointer\n");
2133 return DSERR_INVALIDPARAM
;
2136 *vol
= This
->current
.ds3d
.lConeOutsideVolume
;
2140 static HRESULT WINAPI
DSBuffer3D_GetMaxDistance(IDirectSound3DBuffer
*iface
, D3DVALUE
*maxdist
)
2142 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2144 TRACE("(%p)->(%p)\n", This
, maxdist
);
2147 WARN("Invalid pointer\n");
2148 return DSERR_INVALIDPARAM
;
2151 *maxdist
= This
->current
.ds3d
.flMaxDistance
;
2155 static HRESULT WINAPI
DSBuffer3D_GetMinDistance(IDirectSound3DBuffer
*iface
, D3DVALUE
*mindist
)
2157 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2159 TRACE("(%p)->(%p)\n", This
, mindist
);
2162 WARN("Invalid pointer\n");
2163 return DSERR_INVALIDPARAM
;
2166 *mindist
= This
->current
.ds3d
.flMinDistance
;
2170 static HRESULT WINAPI
DSBuffer3D_GetMode(IDirectSound3DBuffer
*iface
, DWORD
*mode
)
2172 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2174 TRACE("(%p)->(%p)\n", This
, mode
);
2177 WARN("Invalid pointer\n");
2178 return DSERR_INVALIDPARAM
;
2181 *mode
= This
->current
.ds3d
.dwMode
;
2185 static HRESULT WINAPI
DSBuffer3D_GetPosition(IDirectSound3DBuffer
*iface
, D3DVECTOR
*pos
)
2187 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2189 TRACE("(%p)->(%p)\n", This
, pos
);
2192 WARN("Invalid pointer\n");
2193 return DSERR_INVALIDPARAM
;
2196 EnterCriticalSection(&This
->share
->crst
);
2197 *pos
= This
->current
.ds3d
.vPosition
;
2198 LeaveCriticalSection(&This
->share
->crst
);
2203 static HRESULT WINAPI
DSBuffer3D_GetVelocity(IDirectSound3DBuffer
*iface
, D3DVECTOR
*vel
)
2205 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2207 TRACE("(%p)->(%p)\n", This
, vel
);
2210 WARN("Invalid pointer\n");
2211 return DSERR_INVALIDPARAM
;
2214 EnterCriticalSection(&This
->share
->crst
);
2215 *vel
= This
->current
.ds3d
.vVelocity
;
2216 LeaveCriticalSection(&This
->share
->crst
);
2221 static HRESULT WINAPI
DSBuffer3D_GetAllParameters(IDirectSound3DBuffer
*iface
, DS3DBUFFER
*ds3dbuffer
)
2223 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2225 TRACE("(%p)->(%p)\n", iface
, ds3dbuffer
);
2227 if(!ds3dbuffer
|| ds3dbuffer
->dwSize
< sizeof(*ds3dbuffer
))
2229 WARN("Invalid parameters %p %lu\n", ds3dbuffer
, ds3dbuffer
? ds3dbuffer
->dwSize
: 0);
2230 return DSERR_INVALIDPARAM
;
2233 EnterCriticalSection(&This
->share
->crst
);
2234 ds3dbuffer
->vPosition
= This
->current
.ds3d
.vPosition
;
2235 ds3dbuffer
->vVelocity
= This
->current
.ds3d
.vVelocity
;
2236 ds3dbuffer
->dwInsideConeAngle
= This
->current
.ds3d
.dwInsideConeAngle
;
2237 ds3dbuffer
->dwOutsideConeAngle
= This
->current
.ds3d
.dwOutsideConeAngle
;
2238 ds3dbuffer
->vConeOrientation
= This
->current
.ds3d
.vConeOrientation
;
2239 ds3dbuffer
->lConeOutsideVolume
= This
->current
.ds3d
.lConeOutsideVolume
;
2240 ds3dbuffer
->flMinDistance
= This
->current
.ds3d
.flMinDistance
;
2241 ds3dbuffer
->flMaxDistance
= This
->current
.ds3d
.flMaxDistance
;
2242 ds3dbuffer
->dwMode
= This
->current
.ds3d
.dwMode
;
2243 LeaveCriticalSection(&This
->share
->crst
);
2248 static HRESULT WINAPI
DSBuffer3D_SetConeAngles(IDirectSound3DBuffer
*iface
, DWORD dwInsideConeAngle
, DWORD dwOutsideConeAngle
, DWORD apply
)
2250 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2252 TRACE("(%p)->(%lu, %lu, %lu)\n", This
, dwInsideConeAngle
, dwOutsideConeAngle
, apply
);
2253 if(dwInsideConeAngle
> DS3D_MAXCONEANGLE
|| dwOutsideConeAngle
> DS3D_MAXCONEANGLE
)
2255 WARN("Invalid cone angles (%lu, %lu)\n", dwInsideConeAngle
, dwOutsideConeAngle
);
2256 return DSERR_INVALIDPARAM
;
2259 EnterCriticalSection(&This
->share
->crst
);
2260 if(apply
== DS3D_DEFERRED
)
2262 This
->deferred
.ds3d
.dwInsideConeAngle
= dwInsideConeAngle
;
2263 This
->deferred
.ds3d
.dwOutsideConeAngle
= dwOutsideConeAngle
;
2264 This
->dirty
.bit
.cone_angles
= 1;
2268 setALContext(This
->ctx
);
2269 This
->current
.ds3d
.dwInsideConeAngle
= dwInsideConeAngle
;
2270 This
->current
.ds3d
.dwOutsideConeAngle
= dwOutsideConeAngle
;
2271 if(LIKELY(This
->source
))
2273 alSourcei(This
->source
, AL_CONE_INNER_ANGLE
, dwInsideConeAngle
);
2274 alSourcei(This
->source
, AL_CONE_OUTER_ANGLE
, dwOutsideConeAngle
);
2279 LeaveCriticalSection(&This
->share
->crst
);
2284 static HRESULT WINAPI
DSBuffer3D_SetConeOrientation(IDirectSound3DBuffer
*iface
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD apply
)
2286 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2288 TRACE("(%p)->(%f, %f, %f, %lu)\n", This
, x
, y
, z
, apply
);
2290 EnterCriticalSection(&This
->share
->crst
);
2291 if(apply
== DS3D_DEFERRED
)
2293 This
->deferred
.ds3d
.vConeOrientation
.x
= x
;
2294 This
->deferred
.ds3d
.vConeOrientation
.y
= y
;
2295 This
->deferred
.ds3d
.vConeOrientation
.z
= z
;
2296 This
->dirty
.bit
.cone_orient
= 1;
2300 setALContext(This
->ctx
);
2301 This
->current
.ds3d
.vConeOrientation
.x
= x
;
2302 This
->current
.ds3d
.vConeOrientation
.y
= y
;
2303 This
->current
.ds3d
.vConeOrientation
.z
= z
;
2304 if(LIKELY(This
->source
))
2306 alSource3f(This
->source
, AL_DIRECTION
, x
, y
, -z
);
2311 LeaveCriticalSection(&This
->share
->crst
);
2316 static HRESULT WINAPI
DSBuffer3D_SetConeOutsideVolume(IDirectSound3DBuffer
*iface
, LONG vol
, DWORD apply
)
2318 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2320 TRACE("(%p)->(%ld, %lu)\n", This
, vol
, apply
);
2321 if(vol
< DSBVOLUME_MIN
|| vol
> DSBVOLUME_MAX
)
2323 WARN("Invalid volume (%ld)\n", vol
);
2324 return DSERR_INVALIDPARAM
;
2327 EnterCriticalSection(&This
->share
->crst
);
2328 if(apply
== DS3D_DEFERRED
)
2330 This
->deferred
.ds3d
.lConeOutsideVolume
= vol
;
2331 This
->dirty
.bit
.cone_outsidevolume
= 1;
2335 setALContext(This
->ctx
);
2336 This
->current
.ds3d
.lConeOutsideVolume
= vol
;
2337 if(LIKELY(This
->source
))
2339 alSourcef(This
->source
, AL_CONE_OUTER_GAIN
, mB_to_gain((float)vol
));
2344 LeaveCriticalSection(&This
->share
->crst
);
2349 static HRESULT WINAPI
DSBuffer3D_SetMaxDistance(IDirectSound3DBuffer
*iface
, D3DVALUE maxdist
, DWORD apply
)
2351 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2353 TRACE("(%p)->(%f, %lu)\n", This
, maxdist
, apply
);
2356 WARN("Invalid max distance (%f)\n", maxdist
);
2357 return DSERR_INVALIDPARAM
;
2360 EnterCriticalSection(&This
->share
->crst
);
2361 if(apply
== DS3D_DEFERRED
)
2363 This
->deferred
.ds3d
.flMaxDistance
= maxdist
;
2364 This
->dirty
.bit
.max_distance
= 1;
2368 setALContext(This
->ctx
);
2369 This
->current
.ds3d
.flMaxDistance
= maxdist
;
2370 if(LIKELY(This
->source
))
2372 alSourcef(This
->source
, AL_MAX_DISTANCE
, maxdist
);
2377 LeaveCriticalSection(&This
->share
->crst
);
2382 static HRESULT WINAPI
DSBuffer3D_SetMinDistance(IDirectSound3DBuffer
*iface
, D3DVALUE mindist
, DWORD apply
)
2384 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2386 TRACE("(%p)->(%f, %lu)\n", This
, mindist
, apply
);
2389 WARN("Invalid min distance (%f)\n", mindist
);
2390 return DSERR_INVALIDPARAM
;
2393 EnterCriticalSection(&This
->share
->crst
);
2394 if(apply
== DS3D_DEFERRED
)
2396 This
->deferred
.ds3d
.flMinDistance
= mindist
;
2397 This
->dirty
.bit
.min_distance
= 1;
2401 setALContext(This
->ctx
);
2402 This
->current
.ds3d
.flMinDistance
= mindist
;
2403 if(LIKELY(This
->source
))
2405 alSourcef(This
->source
, AL_REFERENCE_DISTANCE
, mindist
);
2410 LeaveCriticalSection(&This
->share
->crst
);
2415 static HRESULT WINAPI
DSBuffer3D_SetMode(IDirectSound3DBuffer
*iface
, DWORD mode
, DWORD apply
)
2417 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2419 TRACE("(%p)->(%lu, %lu)\n", This
, mode
, apply
);
2420 if(mode
!= DS3DMODE_NORMAL
&& mode
!= DS3DMODE_HEADRELATIVE
&&
2421 mode
!= DS3DMODE_DISABLE
)
2423 WARN("Invalid mode (%lu)\n", mode
);
2424 return DSERR_INVALIDPARAM
;
2427 EnterCriticalSection(&This
->share
->crst
);
2428 if(apply
== DS3D_DEFERRED
)
2430 This
->deferred
.ds3d
.dwMode
= mode
;
2431 This
->dirty
.bit
.mode
= 1;
2435 setALContext(This
->ctx
);
2436 This
->current
.ds3d
.dwMode
= mode
;
2437 if(LIKELY(This
->source
))
2439 if(HAS_EXTENSION(This
->share
, SOFT_SOURCE_SPATIALIZE
))
2440 alSourcei(This
->source
, AL_SOURCE_SPATIALIZE_SOFT
,
2441 (mode
==DS3DMODE_DISABLE
) ? AL_FALSE
: AL_TRUE
);
2442 alSourcei(This
->source
, AL_SOURCE_RELATIVE
,
2443 (mode
!= DS3DMODE_NORMAL
) ? AL_TRUE
: AL_FALSE
);
2448 LeaveCriticalSection(&This
->share
->crst
);
2453 static HRESULT WINAPI
DSBuffer3D_SetPosition(IDirectSound3DBuffer
*iface
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD apply
)
2455 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2457 TRACE("(%p)->(%f, %f, %f, %lu)\n", This
, x
, y
, z
, apply
);
2459 EnterCriticalSection(&This
->share
->crst
);
2460 if(apply
== DS3D_DEFERRED
)
2462 This
->deferred
.ds3d
.vPosition
.x
= x
;
2463 This
->deferred
.ds3d
.vPosition
.y
= y
;
2464 This
->deferred
.ds3d
.vPosition
.z
= z
;
2465 This
->dirty
.bit
.pos
= 1;
2469 setALContext(This
->ctx
);
2470 This
->current
.ds3d
.vPosition
.x
= x
;
2471 This
->current
.ds3d
.vPosition
.y
= y
;
2472 This
->current
.ds3d
.vPosition
.z
= z
;
2473 if(LIKELY(This
->source
))
2475 alSource3f(This
->source
, AL_POSITION
, x
, y
, -z
);
2480 LeaveCriticalSection(&This
->share
->crst
);
2485 static HRESULT WINAPI
DSBuffer3D_SetVelocity(IDirectSound3DBuffer
*iface
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD apply
)
2487 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2489 TRACE("(%p)->(%f, %f, %f, %lu)\n", This
, x
, y
, z
, apply
);
2491 EnterCriticalSection(&This
->share
->crst
);
2492 if(apply
== DS3D_DEFERRED
)
2494 This
->deferred
.ds3d
.vVelocity
.x
= x
;
2495 This
->deferred
.ds3d
.vVelocity
.y
= y
;
2496 This
->deferred
.ds3d
.vVelocity
.z
= z
;
2497 This
->dirty
.bit
.vel
= 1;
2501 setALContext(This
->ctx
);
2502 This
->current
.ds3d
.vVelocity
.x
= x
;
2503 This
->current
.ds3d
.vVelocity
.y
= y
;
2504 This
->current
.ds3d
.vVelocity
.z
= z
;
2505 if(LIKELY(This
->source
))
2507 alSource3f(This
->source
, AL_VELOCITY
, x
, y
, -z
);
2512 LeaveCriticalSection(&This
->share
->crst
);
2517 static HRESULT WINAPI
DSBuffer3D_SetAllParameters(IDirectSound3DBuffer
*iface
, const DS3DBUFFER
*ds3dbuffer
, DWORD apply
)
2519 DSBuffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2520 TRACE("(%p)->(%p, %lu)\n", This
, ds3dbuffer
, apply
);
2522 if(!ds3dbuffer
|| ds3dbuffer
->dwSize
< sizeof(*ds3dbuffer
))
2524 WARN("Invalid DS3DBUFFER (%p, %lu)\n", ds3dbuffer
, ds3dbuffer
? ds3dbuffer
->dwSize
: 0);
2525 return DSERR_INVALIDPARAM
;
2528 if(ds3dbuffer
->dwInsideConeAngle
> DS3D_MAXCONEANGLE
||
2529 ds3dbuffer
->dwOutsideConeAngle
> DS3D_MAXCONEANGLE
)
2531 WARN("Invalid cone angles (%lu, %lu)\n",
2532 ds3dbuffer
->dwInsideConeAngle
, ds3dbuffer
->dwOutsideConeAngle
);
2533 return DSERR_INVALIDPARAM
;
2536 if(ds3dbuffer
->lConeOutsideVolume
> DSBVOLUME_MAX
||
2537 ds3dbuffer
->lConeOutsideVolume
< DSBVOLUME_MIN
)
2539 WARN("Invalid cone outside volume (%ld)\n", ds3dbuffer
->lConeOutsideVolume
);
2540 return DSERR_INVALIDPARAM
;
2543 if(ds3dbuffer
->flMaxDistance
< 0.0f
)
2545 WARN("Invalid max distance (%f)\n", ds3dbuffer
->flMaxDistance
);
2546 return DSERR_INVALIDPARAM
;
2549 if(ds3dbuffer
->flMinDistance
< 0.0f
)
2551 WARN("Invalid min distance (%f)\n", ds3dbuffer
->flMinDistance
);
2552 return DSERR_INVALIDPARAM
;
2555 if(ds3dbuffer
->dwMode
!= DS3DMODE_NORMAL
&&
2556 ds3dbuffer
->dwMode
!= DS3DMODE_HEADRELATIVE
&&
2557 ds3dbuffer
->dwMode
!= DS3DMODE_DISABLE
)
2559 WARN("Invalid mode (%lu)\n", ds3dbuffer
->dwMode
);
2560 return DSERR_INVALIDPARAM
;
2563 if(apply
== DS3D_DEFERRED
)
2565 EnterCriticalSection(&This
->share
->crst
);
2566 This
->deferred
.ds3d
= *ds3dbuffer
;
2567 This
->deferred
.ds3d
.dwSize
= sizeof(This
->deferred
.ds3d
);
2568 This
->dirty
.bit
.pos
= 1;
2569 This
->dirty
.bit
.vel
= 1;
2570 This
->dirty
.bit
.cone_angles
= 1;
2571 This
->dirty
.bit
.cone_orient
= 1;
2572 This
->dirty
.bit
.cone_outsidevolume
= 1;
2573 This
->dirty
.bit
.min_distance
= 1;
2574 This
->dirty
.bit
.max_distance
= 1;
2575 This
->dirty
.bit
.mode
= 1;
2576 LeaveCriticalSection(&This
->share
->crst
);
2580 union BufferParamFlags dirty
= { 0 };
2583 dirty
.bit
.cone_angles
= 1;
2584 dirty
.bit
.cone_orient
= 1;
2585 dirty
.bit
.cone_outsidevolume
= 1;
2586 dirty
.bit
.min_distance
= 1;
2587 dirty
.bit
.max_distance
= 1;
2590 EnterCriticalSection(&This
->share
->crst
);
2591 setALContext(This
->ctx
);
2592 DSBuffer_SetParams(This
, ds3dbuffer
, dirty
.flags
);
2595 LeaveCriticalSection(&This
->share
->crst
);
2601 static const IDirectSound3DBufferVtbl DSBuffer3d_Vtbl
=
2603 DSBuffer3D_QueryInterface
,
2606 DSBuffer3D_GetAllParameters
,
2607 DSBuffer3D_GetConeAngles
,
2608 DSBuffer3D_GetConeOrientation
,
2609 DSBuffer3D_GetConeOutsideVolume
,
2610 DSBuffer3D_GetMaxDistance
,
2611 DSBuffer3D_GetMinDistance
,
2613 DSBuffer3D_GetPosition
,
2614 DSBuffer3D_GetVelocity
,
2615 DSBuffer3D_SetAllParameters
,
2616 DSBuffer3D_SetConeAngles
,
2617 DSBuffer3D_SetConeOrientation
,
2618 DSBuffer3D_SetConeOutsideVolume
,
2619 DSBuffer3D_SetMaxDistance
,
2620 DSBuffer3D_SetMinDistance
,
2622 DSBuffer3D_SetPosition
,
2623 DSBuffer3D_SetVelocity
2627 static HRESULT WINAPI
DSBufferNot_QueryInterface(IDirectSoundNotify
*iface
, REFIID riid
, void **ppv
)
2629 DSBuffer
*This
= impl_from_IDirectSoundNotify(iface
);
2630 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2631 return DSBuffer_GetInterface(This
, riid
, ppv
);
2634 static ULONG WINAPI
DSBufferNot_AddRef(IDirectSoundNotify
*iface
)
2636 DSBuffer
*This
= impl_from_IDirectSoundNotify(iface
);
2639 InterlockedIncrement(&This
->all_ref
);
2640 ret
= InterlockedIncrement(&This
->not_ref
);
2641 TRACE("(%p) ref %lu\n", iface
, ret
);
2646 static ULONG WINAPI
DSBufferNot_Release(IDirectSoundNotify
*iface
)
2648 DSBuffer
*This
= impl_from_IDirectSoundNotify(iface
);
2651 ret
= InterlockedDecrement(&This
->not_ref
);
2652 TRACE("(%p) ref %lu\n", iface
, ret
);
2653 if(InterlockedDecrement(&This
->all_ref
) == 0)
2654 DSBuffer_Destroy(This
);
2659 static HRESULT WINAPI
DSBufferNot_SetNotificationPositions(IDirectSoundNotify
*iface
, DWORD count
, const DSBPOSITIONNOTIFY
*notifications
)
2661 DSBuffer
*This
= impl_from_IDirectSoundNotify(iface
);
2662 DSBPOSITIONNOTIFY
*nots
;
2666 TRACE("(%p)->(%lu, %p))\n", iface
, count
, notifications
);
2668 EnterCriticalSection(&This
->share
->crst
);
2669 hr
= DSERR_INVALIDPARAM
;
2670 if(count
&& !notifications
)
2673 hr
= DSBuffer_GetStatus(&This
->IDirectSoundBuffer8_iface
, &state
);
2674 if(FAILED(hr
)) goto out
;
2676 hr
= DSERR_INVALIDCALL
;
2677 if((state
&DSBSTATUS_PLAYING
))
2682 HeapFree(GetProcessHeap(), 0, This
->notify
);
2691 hr
= DSERR_INVALIDPARAM
;
2692 for(i
= 0;i
< count
;++i
)
2694 if(notifications
[i
].dwOffset
>= (DWORD
)This
->buffer
->buf_size
&&
2695 notifications
[i
].dwOffset
!= (DWORD
)DSBPN_OFFSETSTOP
)
2700 nots
= HeapAlloc(GetProcessHeap(), 0, count
*sizeof(*nots
));
2702 memcpy(nots
, notifications
, count
*sizeof(*nots
));
2704 HeapFree(GetProcessHeap(), 0, This
->notify
);
2705 This
->notify
= nots
;
2706 This
->nnotify
= count
;
2712 LeaveCriticalSection(&This
->share
->crst
);
2716 static const IDirectSoundNotifyVtbl DSBufferNot_Vtbl
=
2718 DSBufferNot_QueryInterface
,
2720 DSBufferNot_Release
,
2721 DSBufferNot_SetNotificationPositions
2725 static const char *debug_bufferprop(const GUID
*guid
)
2727 #define HANDLE_ID(id) if(IsEqualGUID(guid, &(id))) return #id
2728 HANDLE_ID(EAXPROPERTYID_EAX40_Source
);
2729 HANDLE_ID(DSPROPSETID_EAX30_BufferProperties
);
2730 HANDLE_ID(DSPROPSETID_EAX20_BufferProperties
);
2731 HANDLE_ID(EAXPROPERTYID_EAX40_FXSlot0
);
2732 HANDLE_ID(EAXPROPERTYID_EAX40_FXSlot1
);
2733 HANDLE_ID(EAXPROPERTYID_EAX40_FXSlot2
);
2734 HANDLE_ID(EAXPROPERTYID_EAX40_FXSlot3
);
2735 HANDLE_ID(DSPROPSETID_EAX30_ListenerProperties
);
2736 HANDLE_ID(DSPROPSETID_EAX20_ListenerProperties
);
2737 HANDLE_ID(EAXPROPERTYID_EAX40_Context
);
2738 HANDLE_ID(DSPROPSETID_EAX10_BufferProperties
);
2739 HANDLE_ID(DSPROPSETID_EAX10_ListenerProperties
);
2740 HANDLE_ID(DSPROPSETID_VoiceManager
);
2741 HANDLE_ID(DSPROPSETID_ZOOMFX_BufferProperties
);
2742 HANDLE_ID(DSPROPSETID_I3DL2_ListenerProperties
);
2743 HANDLE_ID(DSPROPSETID_I3DL2_BufferProperties
);
2745 return debugstr_guid(guid
);
2748 static HRESULT WINAPI
DSBufferProp_QueryInterface(IKsPropertySet
*iface
, REFIID riid
, void **ppv
)
2750 DSBuffer
*This
= impl_from_IKsPropertySet(iface
);
2751 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
2752 return DSBuffer_GetInterface(This
, riid
, ppv
);
2755 static ULONG WINAPI
DSBufferProp_AddRef(IKsPropertySet
*iface
)
2757 DSBuffer
*This
= impl_from_IKsPropertySet(iface
);
2760 InterlockedIncrement(&This
->all_ref
);
2761 ret
= InterlockedIncrement(&This
->prop_ref
);
2762 TRACE("(%p) ref %lu\n", iface
, ret
);
2767 static ULONG WINAPI
DSBufferProp_Release(IKsPropertySet
*iface
)
2769 DSBuffer
*This
= impl_from_IKsPropertySet(iface
);
2772 ret
= InterlockedDecrement(&This
->prop_ref
);
2773 TRACE("(%p) ref %lu\n", iface
, ret
);
2774 if(InterlockedDecrement(&This
->all_ref
) == 0)
2775 DSBuffer_Destroy(This
);
2780 /* NOTE: Due to some apparent quirks in DSound, the listener properties are
2781 handled through secondary buffers. */
2782 static HRESULT WINAPI
DSBufferProp_Get(IKsPropertySet
*iface
,
2783 REFGUID guidPropSet
, ULONG dwPropID
,
2784 LPVOID pInstanceData
, ULONG cbInstanceData
,
2785 LPVOID pPropData
, ULONG cbPropData
,
2788 DSBuffer
*This
= impl_from_IKsPropertySet(iface
);
2789 HRESULT hr
= E_PROP_ID_UNSUPPORTED
;
2791 TRACE("(%p)->(%s, 0x%lx, %p, %lu, %p, %lu, %p)\n", iface
, debug_bufferprop(guidPropSet
),
2792 dwPropID
, pInstanceData
, cbInstanceData
, pPropData
, cbPropData
, pcbReturned
);
2798 if(cbPropData
> 0 && !pPropData
)
2800 WARN("pPropData is NULL with cbPropData > 0\n");
2804 EnterCriticalSection(&This
->share
->crst
);
2805 if(IsEqualIID(guidPropSet
, &EAXPROPERTYID_EAX40_Source
))
2806 hr
= EAX4Source_Get(This
, dwPropID
, pPropData
, cbPropData
, pcbReturned
);
2807 else if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX30_BufferProperties
))
2808 hr
= EAX3Buffer_Get(This
, dwPropID
, pPropData
, cbPropData
, pcbReturned
);
2809 else if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX20_BufferProperties
))
2810 hr
= EAX2Buffer_Get(This
, dwPropID
, pPropData
, cbPropData
, pcbReturned
);
2811 else if(IsEqualIID(guidPropSet
, &EAXPROPERTYID_EAX40_FXSlot0
))
2812 hr
= EAX4Slot_Get(This
->primary
, 0, dwPropID
, pPropData
, cbPropData
, pcbReturned
);
2813 else if(IsEqualIID(guidPropSet
, &EAXPROPERTYID_EAX40_FXSlot1
))
2814 hr
= EAX4Slot_Get(This
->primary
, 1, dwPropID
, pPropData
, cbPropData
, pcbReturned
);
2815 else if(IsEqualIID(guidPropSet
, &EAXPROPERTYID_EAX40_FXSlot2
))
2816 hr
= EAX4Slot_Get(This
->primary
, 2, dwPropID
, pPropData
, cbPropData
, pcbReturned
);
2817 else if(IsEqualIID(guidPropSet
, &EAXPROPERTYID_EAX40_FXSlot3
))
2818 hr
= EAX4Slot_Get(This
->primary
, 3, dwPropID
, pPropData
, cbPropData
, pcbReturned
);
2819 else if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX30_ListenerProperties
))
2820 hr
= EAX3_Get(This
->primary
, dwPropID
, pPropData
, cbPropData
, pcbReturned
);
2821 else if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX20_ListenerProperties
))
2822 hr
= EAX2_Get(This
->primary
, dwPropID
, pPropData
, cbPropData
, pcbReturned
);
2823 else if(IsEqualIID(guidPropSet
, &EAXPROPERTYID_EAX40_Context
))
2824 hr
= EAX4Context_Get(This
->primary
, dwPropID
, pPropData
, cbPropData
, pcbReturned
);
2825 else if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX10_BufferProperties
))
2826 hr
= EAX1Buffer_Get(This
, dwPropID
, pPropData
, cbPropData
, pcbReturned
);
2827 else if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX10_ListenerProperties
))
2828 hr
= EAX1_Get(This
->primary
, dwPropID
, pPropData
, cbPropData
, pcbReturned
);
2830 FIXME("Unhandled propset: %s\n", debug_bufferprop(guidPropSet
));
2831 LeaveCriticalSection(&This
->share
->crst
);
2836 static HRESULT WINAPI
DSBufferProp_Set(IKsPropertySet
*iface
,
2837 REFGUID guidPropSet
, ULONG dwPropID
,
2838 LPVOID pInstanceData
, ULONG cbInstanceData
,
2839 LPVOID pPropData
, ULONG cbPropData
)
2841 DSBuffer
*This
= impl_from_IKsPropertySet(iface
);
2842 HRESULT hr
= E_PROP_ID_UNSUPPORTED
;
2845 TRACE("(%p)->(%s, 0x%lx, %p, %lu, %p, %lu)\n", iface
, debug_bufferprop(guidPropSet
),
2846 dwPropID
, pInstanceData
, cbInstanceData
, pPropData
, cbPropData
);
2848 if(cbPropData
> 0 && !pPropData
)
2850 WARN("pPropData is NULL with cbPropData > 0\n");
2854 EnterCriticalSection(&This
->share
->crst
);
2855 if(IsEqualIID(guidPropSet
, &EAXPROPERTYID_EAX40_Source
))
2857 DWORD propid
= dwPropID
& ~EAXSOURCE_PARAMETER_DEFERRED
;
2858 BOOL immediate
= !(dwPropID
&EAXSOURCE_PARAMETER_DEFERRED
);
2860 setALContext(This
->ctx
);
2861 hr
= EAX4Source_Set(This
, propid
, pPropData
, cbPropData
);
2862 if(hr
== DS_OK
&& immediate
)
2864 DSPrimary
*prim
= This
->primary
;
2865 DSPrimary3D_CommitDeferredSettings(&prim
->IDirectSound3DListener_iface
);
2869 else if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX30_BufferProperties
))
2871 DWORD propid
= dwPropID
& ~DSPROPERTY_EAX30BUFFER_DEFERRED
;
2872 BOOL immediate
= !(dwPropID
&DSPROPERTY_EAX30BUFFER_DEFERRED
);
2874 setALContext(This
->ctx
);
2875 hr
= EAX3Buffer_Set(This
, propid
, pPropData
, cbPropData
);
2876 if(hr
== DS_OK
&& immediate
)
2878 DSPrimary
*prim
= This
->primary
;
2879 DSPrimary3D_CommitDeferredSettings(&prim
->IDirectSound3DListener_iface
);
2883 else if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX20_BufferProperties
))
2885 DWORD propid
= dwPropID
& ~DSPROPERTY_EAX20BUFFER_DEFERRED
;
2886 BOOL immediate
= !(dwPropID
&DSPROPERTY_EAX20BUFFER_DEFERRED
);
2888 setALContext(This
->ctx
);
2889 hr
= EAX2Buffer_Set(This
, propid
, pPropData
, cbPropData
);
2890 if(hr
== DS_OK
&& immediate
)
2892 DSPrimary
*prim
= This
->primary
;
2893 DSPrimary3D_CommitDeferredSettings(&prim
->IDirectSound3DListener_iface
);
2897 else if(((idx
=0),IsEqualIID(guidPropSet
, &EAXPROPERTYID_EAX40_FXSlot0
)) ||
2898 ((idx
=1),IsEqualIID(guidPropSet
, &EAXPROPERTYID_EAX40_FXSlot1
)) ||
2899 ((idx
=2),IsEqualIID(guidPropSet
, &EAXPROPERTYID_EAX40_FXSlot2
)) ||
2900 ((idx
=3),IsEqualIID(guidPropSet
, &EAXPROPERTYID_EAX40_FXSlot3
)))
2902 DSPrimary
*prim
= This
->primary
;
2903 DWORD propid
= dwPropID
& ~EAXFXSLOT_PARAMETER_DEFERRED
;
2904 BOOL immediate
= !(dwPropID
&EAXFXSLOT_PARAMETER_DEFERRED
);
2906 setALContext(prim
->ctx
);
2907 hr
= EAX4Slot_Set(prim
, idx
, propid
, pPropData
, cbPropData
);
2908 if(hr
== DS_OK
&& immediate
)
2909 DSPrimary3D_CommitDeferredSettings(&prim
->IDirectSound3DListener_iface
);
2912 else if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX30_ListenerProperties
))
2914 DSPrimary
*prim
= This
->primary
;
2915 DWORD propid
= dwPropID
& ~DSPROPERTY_EAX30LISTENER_DEFERRED
;
2916 BOOL immediate
= !(dwPropID
&DSPROPERTY_EAX30LISTENER_DEFERRED
);
2918 setALContext(prim
->ctx
);
2919 hr
= EAX3_Set(prim
, propid
, pPropData
, cbPropData
);
2920 if(hr
== DS_OK
&& immediate
)
2921 DSPrimary3D_CommitDeferredSettings(&prim
->IDirectSound3DListener_iface
);
2924 else if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX20_ListenerProperties
))
2926 DSPrimary
*prim
= This
->primary
;
2927 DWORD propid
= dwPropID
& ~DSPROPERTY_EAX20LISTENER_DEFERRED
;
2928 BOOL immediate
= !(dwPropID
&DSPROPERTY_EAX20LISTENER_DEFERRED
);
2930 setALContext(prim
->ctx
);
2931 hr
= EAX2_Set(prim
, propid
, pPropData
, cbPropData
);
2932 if(hr
== DS_OK
&& immediate
)
2933 DSPrimary3D_CommitDeferredSettings(&prim
->IDirectSound3DListener_iface
);
2936 else if(IsEqualIID(guidPropSet
, &EAXPROPERTYID_EAX40_Context
))
2938 DSPrimary
*prim
= This
->primary
;
2939 DWORD propid
= dwPropID
& ~EAXCONTEXT_PARAMETER_DEFERRED
;
2940 BOOL immediate
= !(dwPropID
&EAXCONTEXT_PARAMETER_DEFERRED
);
2942 setALContext(prim
->ctx
);
2943 hr
= EAX4Context_Set(prim
, propid
, pPropData
, cbPropData
);
2944 if(hr
== DS_OK
&& immediate
)
2945 DSPrimary3D_CommitDeferredSettings(&prim
->IDirectSound3DListener_iface
);
2948 else if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX10_BufferProperties
))
2950 DWORD propid
= dwPropID
& ~DSPROPERTY_EAX20BUFFER_DEFERRED
;
2951 BOOL immediate
= !(dwPropID
&DSPROPERTY_EAX20BUFFER_DEFERRED
);
2953 setALContext(This
->ctx
);
2954 hr
= EAX1Buffer_Set(This
, propid
, pPropData
, cbPropData
);
2955 if(hr
== DS_OK
&& immediate
)
2957 DSPrimary
*prim
= This
->primary
;
2958 DSPrimary3D_CommitDeferredSettings(&prim
->IDirectSound3DListener_iface
);
2962 else if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX10_ListenerProperties
))
2964 DSPrimary
*prim
= This
->primary
;
2965 DWORD propid
= dwPropID
& ~DSPROPERTY_EAX20LISTENER_DEFERRED
;
2966 BOOL immediate
= !(dwPropID
&DSPROPERTY_EAX20LISTENER_DEFERRED
);
2968 setALContext(prim
->ctx
);
2969 hr
= EAX1_Set(prim
, propid
, pPropData
, cbPropData
);
2970 if(hr
== DS_OK
&& immediate
)
2971 DSPrimary3D_CommitDeferredSettings(&prim
->IDirectSound3DListener_iface
);
2975 FIXME("Unhandled propset: %s\n", debug_bufferprop(guidPropSet
));
2976 LeaveCriticalSection(&This
->share
->crst
);
2981 static HRESULT WINAPI
DSBufferProp_QuerySupport(IKsPropertySet
*iface
,
2982 REFGUID guidPropSet
, ULONG dwPropID
,
2983 ULONG
*pTypeSupport
)
2985 DSBuffer
*This
= impl_from_IKsPropertySet(iface
);
2986 HRESULT hr
= E_PROP_ID_UNSUPPORTED
;
2988 TRACE("(%p)->(%s, 0x%lx, %p)\n", iface
, debug_bufferprop(guidPropSet
), dwPropID
,
2995 EnterCriticalSection(&This
->share
->crst
);
2996 if(IsEqualIID(guidPropSet
, &EAXPROPERTYID_EAX40_Source
))
2997 hr
= EAX4Source_Query(This
, dwPropID
, pTypeSupport
);
2998 else if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX30_BufferProperties
))
2999 hr
= EAX3Buffer_Query(This
, dwPropID
, pTypeSupport
);
3000 else if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX20_BufferProperties
))
3001 hr
= EAX2Buffer_Query(This
, dwPropID
, pTypeSupport
);
3002 else if(IsEqualIID(guidPropSet
, &EAXPROPERTYID_EAX40_FXSlot0
))
3003 hr
= EAX4Slot_Query(This
->primary
, 0, dwPropID
, pTypeSupport
);
3004 else if(IsEqualIID(guidPropSet
, &EAXPROPERTYID_EAX40_FXSlot1
))
3005 hr
= EAX4Slot_Query(This
->primary
, 1, dwPropID
, pTypeSupport
);
3006 else if(IsEqualIID(guidPropSet
, &EAXPROPERTYID_EAX40_FXSlot2
))
3007 hr
= EAX4Slot_Query(This
->primary
, 2, dwPropID
, pTypeSupport
);
3008 else if(IsEqualIID(guidPropSet
, &EAXPROPERTYID_EAX40_FXSlot3
))
3009 hr
= EAX4Slot_Query(This
->primary
, 3, dwPropID
, pTypeSupport
);
3010 else if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX30_ListenerProperties
))
3011 hr
= EAX3_Query(This
->primary
, dwPropID
, pTypeSupport
);
3012 else if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX20_ListenerProperties
))
3013 hr
= EAX2_Query(This
->primary
, dwPropID
, pTypeSupport
);
3014 else if(IsEqualIID(guidPropSet
, &EAXPROPERTYID_EAX40_Context
))
3015 hr
= EAX4Context_Query(This
->primary
, dwPropID
, pTypeSupport
);
3016 else if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX10_ListenerProperties
))
3017 hr
= EAX1_Query(This
->primary
, dwPropID
, pTypeSupport
);
3018 else if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX10_BufferProperties
))
3019 hr
= EAX1Buffer_Query(This
, dwPropID
, pTypeSupport
);
3021 FIXME("Unhandled propset: %s (propid: %lu)\n", debug_bufferprop(guidPropSet
), dwPropID
);
3022 LeaveCriticalSection(&This
->share
->crst
);
3027 static const IKsPropertySetVtbl DSBufferProp_Vtbl
=
3029 DSBufferProp_QueryInterface
,
3030 DSBufferProp_AddRef
,
3031 DSBufferProp_Release
,
3034 DSBufferProp_QuerySupport