1 /* DirectSound COM interface
3 * Copyright 2009 Maarten Lankhorst
5 * Some code taken from the original dsound-openal implementation
6 * Copyright 2007-2009 Chris Robinson
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #define NONAMELESSSTRUCT
29 #define NONAMELESSUNION
39 #include "wine/debug.h"
42 #include "dsound_private.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(dsound
);
56 #include "dsound_private.h"
58 DEFINE_GUID(CLSID_DirectSoundPrivate
,0x11ab3ec0,0x25ec,0x11d1,0xa4,0xd8,0x00,0xc0,0x4f,0xc2,0x8a,0xca);
60 DEFINE_GUID(DSPROPSETID_DirectSoundDevice
,0x84624f82,0x25ec,0x11d1,0xa4,0xd8,0x00,0xc0,0x4f,0xc2,0x8a,0xca);
62 DEFINE_GUID(KSDATAFORMAT_SUBTYPE_PCM
, 0x00000001, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71);
63 DEFINE_GUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
, 0x00000003, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71);
65 #ifndef E_PROP_ID_UNSUPPORTED
66 #define E_PROP_ID_UNSUPPORTED ((HRESULT)0x80070490)
71 #ifndef WAVE_FORMAT_IEEE_FLOAT
72 #define WAVE_FORMAT_IEEE_FLOAT 3
75 /* TODO: when bufferlost is set, return from all calls except initialize with
78 static const IDirectSoundBuffer8Vtbl DS8Buffer_Vtbl
;
79 static const IDirectSoundBufferVtbl DSBuffer_Vtbl
;
80 static const IDirectSound3DBufferVtbl DS8Buffer3d_Vtbl
;
81 static const IDirectSoundNotifyVtbl DS8BufferNot_Vtbl
;
82 static const IKsPropertySetVtbl DS8BufferProp_Vtbl
;
85 static inline DS8Buffer
*impl_from_IDirectSoundBuffer8(IDirectSoundBuffer8
*iface
)
87 return CONTAINING_RECORD(iface
, DS8Buffer
, IDirectSoundBuffer8_iface
);
90 static inline DS8Buffer
*impl_from_IDirectSoundBuffer(IDirectSoundBuffer
*iface
)
92 return CONTAINING_RECORD(iface
, DS8Buffer
, IDirectSoundBuffer_iface
);
95 static inline DS8Buffer
*impl_from_IDirectSound3DBuffer(IDirectSound3DBuffer
*iface
)
97 return CONTAINING_RECORD(iface
, DS8Buffer
, IDirectSound3DBuffer_iface
);
100 static inline DS8Buffer
*impl_from_IDirectSoundNotify(IDirectSoundNotify
*iface
)
102 return CONTAINING_RECORD(iface
, DS8Buffer
, IDirectSoundNotify_iface
);
105 static inline DS8Buffer
*impl_from_IKsPropertySet(IKsPropertySet
*iface
)
107 return CONTAINING_RECORD(iface
, DS8Buffer
, IKsPropertySet_iface
);
111 /* Should be called with critsect held and context set.. */
112 static void DS8Buffer_addnotify(DS8Buffer
*buf
)
117 list
= buf
->primary
->notifies
;
118 for(i
= 0; i
< buf
->primary
->nnotifies
; ++i
)
122 ERR("Buffer %p already in notification list\n", buf
);
126 if(buf
->primary
->nnotifies
== buf
->primary
->sizenotifies
)
128 list
= HeapReAlloc(GetProcessHeap(), 0, list
, (buf
->primary
->nnotifies
+ 1) * sizeof(*list
));
131 buf
->primary
->sizenotifies
++;
133 list
[buf
->primary
->nnotifies
++] = buf
;
134 buf
->primary
->notifies
= list
;
138 static const char *get_fmtstr_PCM(const DS8Primary
*prim
, const WAVEFORMATEX
*format
, WAVEFORMATEXTENSIBLE
*out
)
140 out
->Format
= *format
;
141 out
->Format
.cbSize
= 0;
143 if(out
->Format
.nChannels
!= 1 && out
->Format
.nChannels
!= 2 &&
144 !prim
->SupportedExt
[EXT_MCFORMATS
])
146 WARN("Multi-channel not available\n");
150 if(format
->wBitsPerSample
== 8)
152 switch(format
->nChannels
)
154 case 1: return "AL_FORMAT_MONO8";
155 case 2: return "AL_FORMAT_STEREO8";
156 case 4: return "AL_FORMAT_QUAD8";
157 case 6: return "AL_FORMAT_51CHN8";
158 case 7: return "AL_FORMAT_61CHN8";
159 case 8: return "AL_FORMAT_71CHN8";
162 else if(format
->wBitsPerSample
== 16)
164 switch(format
->nChannels
)
166 case 1: return "AL_FORMAT_MONO16";
167 case 2: return "AL_FORMAT_STEREO16";
168 case 4: return "AL_FORMAT_QUAD16";
169 case 6: return "AL_FORMAT_51CHN16";
170 case 7: return "AL_FORMAT_61CHN16";
171 case 8: return "AL_FORMAT_71CHN16";
175 FIXME("Could not get OpenAL format (%d-bit, %d channels)\n",
176 format
->wBitsPerSample
, format
->nChannels
);
179 static ALenum
get_fmt_PCM(const WAVEFORMATEX
*format
, WAVEFORMATEXTENSIBLE
*out
, ALenum
*in_chans
, ALenum
*in_type
)
181 out
->Format
= *format
;
182 out
->Format
.cbSize
= 0;
184 if(format
->wBitsPerSample
== 8)
186 *in_type
= AL_UNSIGNED_BYTE
;
187 switch(format
->nChannels
)
189 case 1: *in_chans
= AL_MONO
;
191 case 2: *in_chans
= AL_STEREO
;
193 case 4: *in_chans
= AL_QUAD
;
195 case 6: *in_chans
= AL_5POINT1
;
197 case 7: *in_chans
= AL_6POINT1
;
199 case 8: *in_chans
= AL_7POINT1
;
203 else if(format
->wBitsPerSample
== 16)
206 switch(format
->nChannels
)
208 case 1: *in_chans
= AL_MONO
;
210 case 2: *in_chans
= AL_STEREO
;
212 case 4: *in_chans
= AL_QUAD
;
214 case 6: *in_chans
= AL_5POINT1
;
215 return AL_5POINT1_16
;
216 case 7: *in_chans
= AL_6POINT1
;
217 return AL_6POINT1_16
;
218 case 8: *in_chans
= AL_7POINT1
;
219 return AL_7POINT1_16
;
222 #if 0 /* Will cause incorrect byte offsets */
223 else if(format
->wBitsPerSample
== 24)
226 switch(format
->nChannels
)
228 case 1: *in_chans
= AL_MONO
;
230 case 2: *in_chans
= AL_STEREO
;
232 case 4: *in_chans
= AL_QUAD
;
234 case 6: *in_chans
= AL_5POINT1
;
235 return AL_5POINT1_32F
;
236 case 7: *in_chans
= AL_6POINT1
;
237 return AL_6POINT1_32F
;
238 case 8: *in_chans
= AL_7POINT1
;
239 return AL_7POINT1_32F
;
243 else if(format
->wBitsPerSample
== 32)
246 switch(format
->nChannels
)
248 case 1: *in_chans
= AL_MONO
;
250 case 2: *in_chans
= AL_STEREO
;
252 case 4: *in_chans
= AL_QUAD
;
254 case 6: *in_chans
= AL_5POINT1
;
255 return AL_5POINT1_32F
;
256 case 7: *in_chans
= AL_6POINT1
;
257 return AL_6POINT1_32F
;
258 case 8: *in_chans
= AL_7POINT1
;
259 return AL_7POINT1_32F
;
263 FIXME("Could not get OpenAL format (%d-bit, %d channels)\n",
264 format
->wBitsPerSample
, format
->nChannels
);
268 static const char *get_fmtstr_FLOAT(const DS8Primary
*prim
, const WAVEFORMATEX
*format
, WAVEFORMATEXTENSIBLE
*out
)
270 out
->Format
= *format
;
271 out
->Format
.cbSize
= 0;
273 if(out
->Format
.nChannels
!= 1 && out
->Format
.nChannels
!= 2 &&
274 !prim
->SupportedExt
[EXT_MCFORMATS
])
276 WARN("Multi-channel not available\n");
280 if(format
->wBitsPerSample
== 32 && prim
->SupportedExt
[EXT_FLOAT32
])
282 switch(format
->nChannels
)
284 case 1: return "AL_FORMAT_MONO_FLOAT32";
285 case 2: return "AL_FORMAT_STEREO_FLOAT32";
286 case 4: return "AL_FORMAT_QUAD32";
287 case 6: return "AL_FORMAT_51CHN32";
288 case 7: return "AL_FORMAT_61CHN32";
289 case 8: return "AL_FORMAT_71CHN32";
293 FIXME("Could not get OpenAL format (%d-bit, %d channels)\n",
294 format
->wBitsPerSample
, format
->nChannels
);
297 static ALenum
get_fmt_FLOAT(const WAVEFORMATEX
*format
, WAVEFORMATEXTENSIBLE
*out
, ALenum
*in_chans
, ALenum
*in_type
)
299 out
->Format
= *format
;
300 out
->Format
.cbSize
= 0;
302 if(format
->wBitsPerSample
== 32)
305 switch(format
->nChannels
)
307 case 1: *in_chans
= AL_MONO
;
309 case 2: *in_chans
= AL_STEREO
;
311 case 4: *in_chans
= AL_QUAD
;
313 case 6: *in_chans
= AL_5POINT1
;
314 return AL_5POINT1_32F
;
315 case 7: *in_chans
= AL_6POINT1
;
316 return AL_6POINT1_32F
;
317 case 8: *in_chans
= AL_7POINT1
;
318 return AL_7POINT1_32F
;
321 #if 0 /* Will cause incorrect byte offsets */
322 else if(format
->wBitsPerSample
== 64)
324 *in_type
= AL_DOUBLE
;
325 switch(format
->nChannels
)
327 case 1: *in_chans
= AL_MONO
;
329 case 2: *in_chans
= AL_STEREO
;
331 case 4: *in_chans
= AL_QUAD
;
333 case 6: *in_chans
= AL_5POINT1
;
334 return AL_5POINT1_32F
;
335 case 7: *in_chans
= AL_6POINT1
;
336 return AL_6POINT1_32F
;
337 case 8: *in_chans
= AL_7POINT1
;
338 return AL_7POINT1_32F
;
343 FIXME("Could not get OpenAL format (%d-bit, %d channels)\n",
344 format
->wBitsPerSample
, format
->nChannels
);
348 /* Speaker configs */
349 #define MONO SPEAKER_FRONT_CENTER
350 #define STEREO (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT)
351 #define REAR (SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT)
352 #define QUAD (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT)
353 #define X5DOT1 (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER|SPEAKER_LOW_FREQUENCY|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT)
354 #define X6DOT1 (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER|SPEAKER_LOW_FREQUENCY|SPEAKER_BACK_CENTER|SPEAKER_SIDE_LEFT|SPEAKER_SIDE_RIGHT)
355 #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)
357 static const char *get_fmtstr_EXT(const DS8Primary
*prim
, const WAVEFORMATEX
*format
, WAVEFORMATEXTENSIBLE
*out
)
359 *out
= *CONTAINING_RECORD(format
, const WAVEFORMATEXTENSIBLE
, Format
);
360 out
->Format
.cbSize
= sizeof(*out
) - sizeof(out
->Format
);
362 if(!out
->Samples
.wValidBitsPerSample
)
363 out
->Samples
.wValidBitsPerSample
= out
->Format
.wBitsPerSample
;
364 else if(out
->Samples
.wValidBitsPerSample
!= out
->Format
.wBitsPerSample
)
366 FIXME("Padded samples not supported (%u of %u)\n", out
->Samples
.wValidBitsPerSample
, out
->Format
.wBitsPerSample
);
370 if(out
->dwChannelMask
!= MONO
&& out
->dwChannelMask
!= STEREO
&&
371 !prim
->SupportedExt
[EXT_MCFORMATS
])
373 WARN("Multi-channel not available\n");
377 if(IsEqualGUID(&out
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
))
379 if(out
->Samples
.wValidBitsPerSample
== 8)
381 switch(out
->dwChannelMask
)
383 case MONO
: return "AL_FORMAT_MONO8";
384 case STEREO
: return "AL_FORMAT_STEREO8";
385 case REAR
: return "AL_FORMAT_REAR8";
386 case QUAD
: return "AL_FORMAT_QUAD8";
387 case X5DOT1
: return "AL_FORMAT_51CHN8";
388 case X6DOT1
: return "AL_FORMAT_61CHN8";
389 case X7DOT1
: return "AL_FORMAT_71CHN8";
392 else if(out
->Samples
.wValidBitsPerSample
== 16)
394 switch(out
->dwChannelMask
)
396 case MONO
: return "AL_FORMAT_MONO16";
397 case STEREO
: return "AL_FORMAT_STEREO16";
398 case REAR
: return "AL_FORMAT_REAR16";
399 case QUAD
: return "AL_FORMAT_QUAD16";
400 case X5DOT1
: return "AL_FORMAT_51CHN16";
401 case X6DOT1
: return "AL_FORMAT_61CHN16";
402 case X7DOT1
: return "AL_FORMAT_71CHN16";
406 FIXME("Could not get OpenAL PCM format (%d-bit, channelmask %#"LONGFMT
"x)\n",
407 out
->Samples
.wValidBitsPerSample
, out
->dwChannelMask
);
410 else if(IsEqualGUID(&out
->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
) &&
411 prim
->SupportedExt
[EXT_FLOAT32
])
413 if(out
->Samples
.wValidBitsPerSample
== 32)
415 switch(out
->dwChannelMask
)
417 case MONO
: return "AL_FORMAT_MONO_FLOAT32";
418 case STEREO
: return "AL_FORMAT_STEREO_FLOAT32";
419 case REAR
: return "AL_FORMAT_REAR32";
420 case QUAD
: return "AL_FORMAT_QUAD32";
421 case X5DOT1
: return "AL_FORMAT_51CHN32";
422 case X6DOT1
: return "AL_FORMAT_61CHN32";
423 case X7DOT1
: return "AL_FORMAT_71CHN32";
428 WARN("Invalid float bits: %u\n", out
->Samples
.wValidBitsPerSample
);
432 FIXME("Could not get OpenAL float format (%d-bit, channelmask %#"LONGFMT
"x)\n",
433 out
->Samples
.wValidBitsPerSample
, out
->dwChannelMask
);
436 else if(!IsEqualGUID(&out
->SubFormat
, &GUID_NULL
))
437 ERR("Unhandled extensible format: %s\n", debugstr_guid(&out
->SubFormat
));
440 static ALenum
get_fmt_EXT(const WAVEFORMATEX
*format
, WAVEFORMATEXTENSIBLE
*out
, ALenum
*in_chans
, ALenum
*in_type
)
442 *out
= *CONTAINING_RECORD(format
, const WAVEFORMATEXTENSIBLE
, Format
);
443 out
->Format
.cbSize
= sizeof(*out
) - sizeof(out
->Format
);
445 if(!out
->Samples
.wValidBitsPerSample
)
446 out
->Samples
.wValidBitsPerSample
= out
->Format
.wBitsPerSample
;
447 else if(out
->Samples
.wValidBitsPerSample
!= out
->Format
.wBitsPerSample
)
449 FIXME("Padded samples not supported (%u of %u)\n", out
->Samples
.wValidBitsPerSample
, out
->Format
.wBitsPerSample
);
453 if(IsEqualGUID(&out
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
))
455 if(out
->Samples
.wValidBitsPerSample
== 8)
457 *in_type
= AL_UNSIGNED_BYTE
;
458 switch(out
->dwChannelMask
)
460 case MONO
: *in_chans
= AL_MONO
;
462 case STEREO
: *in_chans
= AL_STEREO
;
464 case REAR
: *in_chans
= AL_REAR
;
466 case QUAD
: *in_chans
= AL_QUAD
;
468 case X5DOT1
: *in_chans
= AL_5POINT1
;
470 case X6DOT1
: *in_chans
= AL_6POINT1
;
472 case X7DOT1
: *in_chans
= AL_7POINT1
;
476 else if(out
->Samples
.wValidBitsPerSample
== 16)
479 switch(out
->dwChannelMask
)
481 case MONO
: *in_chans
= AL_MONO
;
483 case STEREO
: *in_chans
= AL_STEREO
;
485 case REAR
: *in_chans
= AL_REAR
;
487 case QUAD
: *in_chans
= AL_QUAD
;
489 case X5DOT1
: *in_chans
= AL_5POINT1
;
490 return AL_5POINT1_16
;
491 case X6DOT1
: *in_chans
= AL_6POINT1
;
492 return AL_6POINT1_16
;
493 case X7DOT1
: *in_chans
= AL_7POINT1
;
494 return AL_7POINT1_16
;
498 else if(out
->Samples
.wValidBitsPerSample
== 24)
501 switch(out
->dwChannelMask
)
503 case MONO
: *in_chans
= AL_MONO
;
505 case STEREO
: *in_chans
= AL_STEREO
;
507 case REAR
: *in_chans
= AL_REAR
;
509 case QUAD
: *in_chans
= AL_QUAD
;
511 case X5DOT1
: *in_chans
= AL_5POINT1
;
512 return AL_5POINT1_32F
;
513 case X6DOT1
: *in_chans
= AL_6POINT1
;
514 return AL_6POINT1_32F
;
515 case X7DOT1
: *in_chans
= AL_7POINT1
;
516 return AL_7POINT1_32F
;
520 else if(out
->Samples
.wValidBitsPerSample
== 32)
523 switch(out
->dwChannelMask
)
525 case MONO
: *in_chans
= AL_MONO
;
527 case STEREO
: *in_chans
= AL_STEREO
;
529 case REAR
: *in_chans
= AL_REAR
;
531 case QUAD
: *in_chans
= AL_QUAD
;
533 case X5DOT1
: *in_chans
= AL_5POINT1
;
534 return AL_5POINT1_32F
;
535 case X6DOT1
: *in_chans
= AL_6POINT1
;
536 return AL_6POINT1_32F
;
537 case X7DOT1
: *in_chans
= AL_7POINT1
;
538 return AL_7POINT1_32F
;
542 FIXME("Could not get OpenAL PCM format (%d-bit, channelmask %#"LONGFMT
"x)\n",
543 out
->Samples
.wValidBitsPerSample
, out
->dwChannelMask
);
546 else if(IsEqualGUID(&out
->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
))
548 if(out
->Samples
.wValidBitsPerSample
== 32)
551 switch(out
->dwChannelMask
)
553 case MONO
: *in_chans
= AL_MONO
;
555 case STEREO
: *in_chans
= AL_STEREO
;
557 case REAR
: *in_chans
= AL_REAR
;
559 case QUAD
: *in_chans
= AL_QUAD
;
561 case X5DOT1
: *in_chans
= AL_5POINT1
;
562 return AL_5POINT1_32F
;
563 case X6DOT1
: *in_chans
= AL_6POINT1
;
564 return AL_6POINT1_32F
;
565 case X7DOT1
: *in_chans
= AL_7POINT1
;
566 return AL_7POINT1_32F
;
570 else if(out
->Samples
.wValidBitsPerSample
== 64)
572 *in_type
= AL_DOUBLE
;
573 switch(out
->dwChannelMask
)
575 case MONO
: *in_chans
= AL_MONO
;
577 case STEREO
: *in_chans
= AL_STEREO
;
579 case REAR
: *in_chans
= AL_REAR
;
581 case QUAD
: *in_chans
= AL_QUAD
;
583 case X5DOT1
: *in_chans
= AL_5POINT1
;
584 return AL_5POINT1_32F
;
585 case X6DOT1
: *in_chans
= AL_6POINT1
;
586 return AL_6POINT1_32F
;
587 case X7DOT1
: *in_chans
= AL_7POINT1
;
588 return AL_7POINT1_32F
;
594 WARN("Invalid float bits: %u\n", out
->Samples
.wValidBitsPerSample
);
598 FIXME("Could not get OpenAL float format (%d-bit, channelmask %#"LONGFMT
"x)\n",
599 out
->Samples
.wValidBitsPerSample
, out
->dwChannelMask
);
602 else if(!IsEqualGUID(&out
->SubFormat
, &GUID_NULL
))
603 ERR("Unhandled extensible format: %s\n", debugstr_guid(&out
->SubFormat
));
607 static void DS8Data_Release(DS8Data
*This
);
608 static HRESULT
DS8Data_Create(DS8Data
**ppv
, const DSBUFFERDESC
*desc
, DS8Primary
*prim
)
610 HRESULT hr
= DSERR_INVALIDPARAM
;
611 const WAVEFORMATEX
*format
;
614 format
= desc
->lpwfxFormat
;
615 TRACE("Requested buffer format:\n"
616 " FormatTag = 0x%04x\n"
618 " SamplesPerSec = %"LONGFMT
"u\n"
619 " AvgBytesPerSec = %"LONGFMT
"u\n"
621 " BitsPerSample = %d\n",
622 format
->wFormatTag
, format
->nChannels
,
623 format
->nSamplesPerSec
, format
->nAvgBytesPerSec
,
624 format
->nBlockAlign
, format
->wBitsPerSample
);
626 if(format
->nBlockAlign
== 0)
628 WARN("Invalid BlockAlign specified\n");
629 return DSERR_INVALIDPARAM
;
632 /* Generate a new buffer. Supporting the DSBCAPS_LOC* flags properly
633 * will need the EAX-RAM extension. Currently, we just tell the app it
634 * gets what it wanted. */
635 pBuffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*pBuffer
));
637 return E_OUTOFMEMORY
;
640 pBuffer
->dsbflags
= desc
->dwFlags
;
641 if((pBuffer
->dsbflags
&(DSBCAPS_LOCSOFTWARE
|DSBCAPS_LOCHARDWARE
)) == (DSBCAPS_LOCSOFTWARE
|DSBCAPS_LOCHARDWARE
))
643 WARN("Hardware and software location requested\n");
646 if(!(pBuffer
->dsbflags
&(DSBCAPS_LOCSOFTWARE
|DSBCAPS_LOCHARDWARE
|DSBCAPS_LOCDEFER
)))
647 pBuffer
->dsbflags
|= DSBCAPS_LOCHARDWARE
;
649 pBuffer
->buf_size
= desc
->dwBufferBytes
+ format
->nBlockAlign
- 1;
650 pBuffer
->buf_size
-= pBuffer
->buf_size
%format
->nBlockAlign
;
652 hr
= DSERR_BUFFERTOOSMALL
;
653 if(pBuffer
->buf_size
< DSBSIZE_MIN
)
656 hr
= DSERR_INVALIDPARAM
;
657 if(pBuffer
->buf_size
> DSBSIZE_MAX
)
660 pBuffer
->numsegs
= 1;
661 pBuffer
->segsize
= pBuffer
->buf_size
;
662 pBuffer
->lastsegsize
= pBuffer
->buf_size
;
664 if(!prim
->SupportedExt
[SOFT_BUFFER_SAMPLES
])
666 const char *fmt_str
= NULL
;
668 if(!(pBuffer
->dsbflags
&DSBCAPS_STATIC
) &&
669 !prim
->SupportedExt
[SOFT_BUFFER_SUB_DATA
] &&
670 !prim
->SupportedExt
[EXT_STATIC_BUFFER
])
672 ALCint refresh
= FAKE_REFRESH_COUNT
;
675 alcGetIntegerv(prim
->parent
->device
, ALC_REFRESH
, 1, &refresh
);
676 checkALCError(prim
->parent
->device
);
678 newSize
= format
->nAvgBytesPerSec
/refresh
+ format
->nBlockAlign
- 1;
679 newSize
-= newSize
%format
->nBlockAlign
;
681 /* Make sure enough buffers are available */
682 if(newSize
> pBuffer
->buf_size
/(QBUFFERS
+2))
683 ERR("Buffer segments too large to stream (%u for %u)!\n",
684 newSize
, pBuffer
->buf_size
);
687 pBuffer
->numsegs
= pBuffer
->buf_size
/newSize
;
688 pBuffer
->segsize
= newSize
;
689 pBuffer
->lastsegsize
= pBuffer
->buf_size
- (newSize
*(pBuffer
->numsegs
-1));
690 TRACE("New streaming buffer (%u chunks, %u : %u sizes)\n",
691 pBuffer
->numsegs
, pBuffer
->segsize
, pBuffer
->lastsegsize
);
695 if(format
->wFormatTag
== WAVE_FORMAT_PCM
)
696 fmt_str
= get_fmtstr_PCM(prim
, format
, &pBuffer
->format
);
697 else if(format
->wFormatTag
== WAVE_FORMAT_IEEE_FLOAT
)
698 fmt_str
= get_fmtstr_FLOAT(prim
, format
, &pBuffer
->format
);
699 else if(format
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
701 const WAVEFORMATEXTENSIBLE
*wfe
;
703 hr
= DSERR_CONTROLUNAVAIL
;
704 if(format
->cbSize
!= sizeof(WAVEFORMATEXTENSIBLE
)-sizeof(WAVEFORMATEX
) &&
705 format
->cbSize
!= sizeof(WAVEFORMATEXTENSIBLE
))
708 wfe
= CONTAINING_RECORD(format
, const WAVEFORMATEXTENSIBLE
, Format
);
709 TRACE("Extensible values:\n"
711 " ChannelMask = 0x%"LONGFMT
"x\n"
713 wfe
->Samples
.wReserved
, wfe
->dwChannelMask
,
714 debugstr_guid(&wfe
->SubFormat
));
716 fmt_str
= get_fmtstr_EXT(prim
, format
, &pBuffer
->format
);
719 ERR("Unhandled formattag 0x%04x\n", format
->wFormatTag
);
721 hr
= DSERR_INVALIDCALL
;
725 pBuffer
->buf_format
= alGetEnumValue(fmt_str
);
726 if(alGetError() != AL_NO_ERROR
|| pBuffer
->buf_format
== 0 ||
727 pBuffer
->buf_format
== -1)
729 WARN("Could not get OpenAL format from %s\n", fmt_str
);
735 if(format
->wFormatTag
== WAVE_FORMAT_PCM
)
736 pBuffer
->buf_format
= get_fmt_PCM(format
, &pBuffer
->format
, &pBuffer
->in_chans
, &pBuffer
->in_type
);
737 else if(format
->wFormatTag
== WAVE_FORMAT_IEEE_FLOAT
)
738 pBuffer
->buf_format
= get_fmt_FLOAT(format
, &pBuffer
->format
, &pBuffer
->in_chans
, &pBuffer
->in_type
);
739 else if(format
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
741 const WAVEFORMATEXTENSIBLE
*wfe
;
743 hr
= DSERR_CONTROLUNAVAIL
;
744 if(format
->cbSize
!= sizeof(WAVEFORMATEXTENSIBLE
)-sizeof(WAVEFORMATEX
) &&
745 format
->cbSize
!= sizeof(WAVEFORMATEXTENSIBLE
))
748 wfe
= CONTAINING_RECORD(format
, const WAVEFORMATEXTENSIBLE
, Format
);
749 TRACE("Extensible values:\n"
751 " ChannelMask = 0x%"LONGFMT
"x\n"
753 wfe
->Samples
.wReserved
, wfe
->dwChannelMask
,
754 debugstr_guid(&wfe
->SubFormat
));
756 pBuffer
->buf_format
= get_fmt_EXT(format
, &pBuffer
->format
, &pBuffer
->in_chans
, &pBuffer
->in_type
);
759 ERR("Unhandled formattag 0x%04x\n", format
->wFormatTag
);
761 hr
= DSERR_INVALIDCALL
;
762 if(prim
->ExtAL
->IsBufferFormatSupportedSOFT(pBuffer
->buf_format
) == AL_FALSE
)
764 WARN("Unsupported OpenAL format: 0x%x\n", pBuffer
->buf_format
);
770 pBuffer
->buffers
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*pBuffer
->buffers
)*pBuffer
->numsegs
);
771 pBuffer
->data
= HeapAlloc(GetProcessHeap(), 0, pBuffer
->buf_size
);
772 if(!pBuffer
->buffers
|| !pBuffer
->data
)
775 alGenBuffers(pBuffer
->numsegs
, pBuffer
->buffers
);
782 DS8Data_Release(pBuffer
);
786 static void DS8Data_AddRef(DS8Data
*data
)
788 InterlockedIncrement(&data
->ref
);
791 /* This function is always called with the device lock held */
792 static void DS8Data_Release(DS8Data
*This
)
794 if(InterlockedDecrement(&This
->ref
)) return;
796 TRACE("Deleting %p\n", This
);
797 if (This
->buffers
&& This
->buffers
[0])
799 alDeleteBuffers(This
->numsegs
, This
->buffers
);
802 HeapFree(GetProcessHeap(), 0, This
->buffers
);
803 HeapFree(GetProcessHeap(), 0, This
->data
);
804 HeapFree(GetProcessHeap(), 0, This
);
807 HRESULT
DS8Buffer_Create(DS8Buffer
**ppv
, DS8Primary
*prim
, IDirectSoundBuffer
*orig
)
813 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*This
));
814 if(!This
) return DSERR_OUTOFMEMORY
;
816 This
->IDirectSoundBuffer8_iface
.lpVtbl
= (IDirectSoundBuffer8Vtbl
*)&DS8Buffer_Vtbl
;
817 This
->IDirectSoundBuffer_iface
.lpVtbl
= (IDirectSoundBufferVtbl
*)&DSBuffer_Vtbl
;
818 This
->IDirectSound3DBuffer_iface
.lpVtbl
= (IDirectSound3DBufferVtbl
*)&DS8Buffer3d_Vtbl
;
819 This
->IDirectSoundNotify_iface
.lpVtbl
= (IDirectSoundNotifyVtbl
*)&DS8BufferNot_Vtbl
;
820 This
->IKsPropertySet_iface
.lpVtbl
= (IKsPropertySetVtbl
*)&DS8BufferProp_Vtbl
;
822 This
->primary
= prim
;
823 This
->ctx
= prim
->ctx
;
824 This
->ExtAL
= prim
->ExtAL
;
825 This
->crst
= prim
->crst
;
826 This
->ref
= This
->all_ref
= 1;
830 DS8Buffer
*org
= impl_from_IDirectSoundBuffer(orig
);
831 hr
= DSERR_BUFFERLOST
;
834 DS8Data_AddRef(org
->buffer
);
835 This
->buffer
= org
->buffer
;
838 /* Append to buffer list */
839 if(prim
->nbuffers
== prim
->sizebuffers
)
843 hr
= DSERR_OUTOFMEMORY
;
844 bufs
= HeapReAlloc(GetProcessHeap(), 0, prim
->buffers
, sizeof(*bufs
)*(prim
->nbuffers
+1));
847 prim
->buffers
= bufs
;
850 prim
->buffers
[prim
->nbuffers
++] = This
;
852 /* Disable until initialized.. */
853 This
->ds3dmode
= DS3DMODE_DISABLE
;
859 DS8Buffer_Destroy(This
);
863 void DS8Buffer_Destroy(DS8Buffer
*This
)
865 DS8Primary
*prim
= This
->primary
;
868 TRACE("Destroying %p\n", This
);
870 EnterCriticalSection(prim
->crst
);
871 /* Remove from list, if in list */
872 for(idx
= 0;idx
< prim
->nnotifies
;++idx
)
874 if(This
== prim
->notifies
[idx
])
876 prim
->notifies
[idx
] = prim
->notifies
[--prim
->nnotifies
];
880 for(idx
= 0;idx
< prim
->nbuffers
;++idx
)
882 if(prim
->buffers
[idx
] == This
)
884 prim
->buffers
[idx
] = prim
->buffers
[--prim
->nbuffers
];
889 setALContext(This
->ctx
);
892 alSourceStop(This
->source
);
893 alSourcei(This
->source
, AL_BUFFER
, 0);
896 prim
->sources
[prim
->parent
->share
->nsources
++] = This
->source
;
899 LeaveCriticalSection(prim
->crst
);
902 DS8Data_Release(This
->buffer
);
906 HeapFree(GetProcessHeap(), 0, This
->notify
);
907 HeapFree(GetProcessHeap(), 0, This
);
911 static HRESULT WINAPI
DS8Buffer_QueryInterface(IDirectSoundBuffer8
*iface
, REFIID riid
, void **ppv
)
913 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
915 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
918 if(IsEqualIID(riid
, &IID_IUnknown
))
919 *ppv
= &This
->IDirectSoundBuffer8_iface
;
920 else if(IsEqualIID(riid
, &IID_IDirectSoundBuffer
))
921 *ppv
= &This
->IDirectSoundBuffer_iface
;
922 else if(IsEqualIID(riid
, &IID_IDirectSoundBuffer8
))
924 if(This
->primary
->parent
->is_8
)
925 *ppv
= &This
->IDirectSoundBuffer8_iface
;
927 else if(IsEqualIID(riid
, &IID_IDirectSound3DBuffer
))
929 if((This
->buffer
->dsbflags
&DSBCAPS_CTRL3D
))
930 *ppv
= &This
->IDirectSound3DBuffer_iface
;
932 else if(IsEqualIID(riid
, &IID_IDirectSoundNotify
))
934 if((This
->buffer
->dsbflags
&DSBCAPS_CTRLPOSITIONNOTIFY
))
935 *ppv
= &This
->IDirectSoundNotify_iface
;
937 else if(IsEqualIID(riid
, &IID_IKsPropertySet
))
938 *ppv
= &This
->IKsPropertySet_iface
;
940 FIXME("Unhandled GUID: %s\n", debugstr_guid(riid
));
944 IUnknown_AddRef((IUnknown
*)*ppv
);
948 return E_NOINTERFACE
;
951 static ULONG WINAPI
DS8Buffer_AddRef(IDirectSoundBuffer8
*iface
)
953 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
956 InterlockedIncrement(&This
->all_ref
);
957 ret
= InterlockedIncrement(&This
->ref
);
958 TRACE("new refcount %"LONGFMT
"d\n", ret
);
963 static ULONG WINAPI
DS8Buffer_Release(IDirectSoundBuffer8
*iface
)
965 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
968 ret
= InterlockedDecrement(&This
->ref
);
969 TRACE("new refcount %"LONGFMT
"d\n", ret
);
970 if(InterlockedDecrement(&This
->all_ref
) == 0)
971 DS8Buffer_Destroy(This
);
976 static HRESULT WINAPI
DS8Buffer_GetCaps(IDirectSoundBuffer8
*iface
, DSBCAPS
*caps
)
978 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
980 TRACE("(%p)->(%p)\n", iface
, caps
);
982 if(!caps
|| caps
->dwSize
< sizeof(*caps
))
984 WARN("Invalid DSBCAPS (%p, %"LONGFMT
"u)\n", caps
, (caps
? caps
->dwSize
: 0));
985 return DSERR_INVALIDPARAM
;
988 caps
->dwFlags
= This
->buffer
->dsbflags
;
989 caps
->dwBufferBytes
= This
->buffer
->buf_size
;
990 caps
->dwUnlockTransferRate
= 4096;
991 caps
->dwPlayCpuOverhead
= 0;
995 static HRESULT WINAPI
DS8Buffer_GetCurrentPosition(IDirectSoundBuffer8
*iface
, DWORD
*playpos
, DWORD
*curpos
)
997 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
998 WAVEFORMATEX
*format
= &This
->buffer
->format
.Format
;
999 UINT writecursor
, pos
;
1001 TRACE("(%p)->(%p, %p)\n", iface
, playpos
, curpos
);
1003 if(This
->buffer
->numsegs
> 1)
1005 ALint queued
= QBUFFERS
;
1007 EnterCriticalSection(This
->crst
);
1009 setALContext(This
->ctx
);
1010 alGetSourcei(This
->source
, AL_BUFFERS_QUEUED
, &queued
);
1014 pos
= (This
->curidx
+This
->buffer
->numsegs
-queued
)%This
->buffer
->numsegs
;
1015 pos
*= This
->buffer
->segsize
;
1016 writecursor
= This
->curidx
* This
->buffer
->segsize
;
1018 LeaveCriticalSection(This
->crst
);
1020 else if(This
->primary
->SupportedExt
[SOFT_BUFFER_SUB_DATA
] ||
1021 This
->primary
->SupportedExt
[SOFT_BUFFER_SAMPLES
])
1023 ALint rwpos
[2] = { 0, 0 };
1025 setALContext(This
->ctx
);
1026 alGetSourceiv(This
->source
, AL_BYTE_RW_OFFSETS_SOFT
, rwpos
);
1031 writecursor
= rwpos
[1];
1038 setALContext(This
->ctx
);
1039 alGetSourcei(This
->source
, AL_BYTE_OFFSET
, &ofs
);
1040 alGetSourcei(This
->source
, AL_SOURCE_STATE
, &status
);
1045 if(status
== AL_PLAYING
)
1047 writecursor
= format
->nSamplesPerSec
/ 100;
1048 writecursor
*= format
->nBlockAlign
;
1052 writecursor
= (writecursor
+ pos
) % This
->buffer
->buf_size
;
1054 TRACE("%p Play pos = %u, write pos = %u\n", This
, pos
, writecursor
);
1055 if(pos
>= This
->buffer
->buf_size
)
1057 ERR("playpos >= buf_size\n");
1058 pos
%= This
->buffer
->buf_size
;
1060 if(writecursor
>= This
->buffer
->buf_size
)
1062 ERR("writepos >= buf_size\n");
1063 writecursor
%= This
->buffer
->buf_size
;
1066 if(playpos
) *playpos
= pos
;
1067 if(curpos
) *curpos
= writecursor
;
1072 static HRESULT WINAPI
DS8Buffer_GetFormat(IDirectSoundBuffer8
*iface
, WAVEFORMATEX
*wfx
, DWORD allocated
, DWORD
*written
)
1074 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1078 TRACE("(%p)->(%p, %"LONGFMT
"u, %p)\n", iface
, wfx
, allocated
, written
);
1080 if(!wfx
&& !written
)
1082 WARN("Cannot report format or format size\n");
1083 return DSERR_INVALIDPARAM
;
1086 size
= sizeof(This
->buffer
->format
.Format
) + This
->buffer
->format
.Format
.cbSize
;
1089 if(allocated
< size
)
1090 hr
= DSERR_INVALIDPARAM
;
1092 memcpy(wfx
, &This
->buffer
->format
.Format
, size
);
1100 static HRESULT WINAPI
DS8Buffer_GetVolume(IDirectSoundBuffer8
*iface
, LONG
*vol
)
1102 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1105 TRACE("(%p)->(%p)\n", iface
, vol
);
1109 WARN("Invalid pointer\n");
1110 return DSERR_INVALIDPARAM
;
1113 hr
= DSERR_CONTROLUNAVAIL
;
1114 if(!(This
->buffer
->dsbflags
&DSBCAPS_CTRLVOLUME
))
1115 WARN("Volume control not set\n");
1118 ALfloat gain
= 1.0f
;
1120 setALContext(This
->ctx
);
1121 alGetSourcef(This
->source
, AL_GAIN
, &gain
);
1125 *vol
= clampI(gain_to_mB(gain
), DSBVOLUME_MIN
, DSBVOLUME_MAX
);
1132 static HRESULT WINAPI
DS8Buffer_GetPan(IDirectSoundBuffer8
*iface
, LONG
*pan
)
1134 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1137 TRACE("(%p)->(%p)\n", iface
, pan
);
1141 WARN("Invalid pointer\n");
1142 return DSERR_INVALIDPARAM
;
1145 hr
= DSERR_CONTROLUNAVAIL
;
1146 if(!(This
->buffer
->dsbflags
&DSBCAPS_CTRLPAN
))
1147 WARN("Panning control not set\n");
1152 setALContext(This
->ctx
);
1153 alGetSourcefv(This
->source
, AL_POSITION
, pos
);
1157 *pan
= clampI(((pos
[0]+1.0) * (DSBPAN_RIGHT
-DSBPAN_LEFT
) / 2.0 + 0.5) + DSBPAN_LEFT
, DSBPAN_LEFT
, DSBPAN_RIGHT
);
1164 static HRESULT WINAPI
DS8Buffer_GetFrequency(IDirectSoundBuffer8
*iface
, DWORD
*freq
)
1166 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1169 TRACE("(%p)->(%p)\n", iface
, freq
);
1173 WARN("Invalid pointer\n");
1174 return DSERR_INVALIDPARAM
;
1177 hr
= DSERR_CONTROLUNAVAIL
;
1178 if(!(This
->buffer
->dsbflags
&DSBCAPS_CTRLFREQUENCY
))
1179 WARN("Frequency control not set\n");
1182 ALfloat pitch
= 1.0f
;
1184 setALContext(This
->ctx
);
1185 alGetSourcefv(This
->source
, AL_PITCH
, &pitch
);
1189 *freq
= (DWORD
)(This
->buffer
->format
.Format
.nSamplesPerSec
* pitch
);
1196 static HRESULT WINAPI
DS8Buffer_GetStatus(IDirectSoundBuffer8
*iface
, DWORD
*status
)
1198 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1199 ALint state
, looping
;
1201 TRACE("(%p)->(%p)\n", iface
, status
);
1205 WARN("Invalid pointer\n");
1206 return DSERR_INVALIDPARAM
;
1209 if(This
->buffer
->numsegs
== 1)
1211 setALContext(This
->ctx
);
1212 alGetSourcei(This
->source
, AL_SOURCE_STATE
, &state
);
1213 alGetSourcei(This
->source
, AL_LOOPING
, &looping
);
1219 EnterCriticalSection(This
->crst
);
1221 setALContext(This
->ctx
);
1222 alGetSourcei(This
->source
, AL_SOURCE_STATE
, &state
);
1226 if(state
!= AL_PLAYING
)
1227 state
= This
->isplaying
? AL_PLAYING
: AL_PAUSED
;
1228 looping
= This
->islooping
;
1230 LeaveCriticalSection(This
->crst
);
1234 if((This
->buffer
->dsbflags
&DSBCAPS_LOCDEFER
))
1236 if((This
->buffer
->dsbflags
&DSBCAPS_LOCSOFTWARE
))
1237 *status
|= DSBSTATUS_LOCSOFTWARE
;
1238 else if((This
->buffer
->dsbflags
&DSBCAPS_LOCHARDWARE
))
1239 *status
|= DSBSTATUS_LOCHARDWARE
;
1241 if(state
== AL_PLAYING
)
1242 *status
|= DSBSTATUS_PLAYING
| (looping
? DSBSTATUS_LOOPING
: 0);
1247 static HRESULT WINAPI
DS8Buffer_Initialize(IDirectSoundBuffer8
*iface
, IDirectSound
*ds
, const DSBUFFERDESC
*desc
)
1249 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1250 DS3DBUFFER
*ds3dbuffer
;
1253 TRACE("(%p)->(%p, %p)\n", iface
, ds
, desc
);
1255 EnterCriticalSection(This
->crst
);
1256 setALContext(This
->ctx
);
1258 hr
= DSERR_ALREADYINITIALIZED
;
1264 hr
= DSERR_INVALIDPARAM
;
1267 WARN("Missing DSound buffer description\n");
1270 if(!desc
->lpwfxFormat
)
1272 WARN("Missing buffer format (%p)\n", This
);
1275 if((desc
->dwFlags
&DSBCAPS_CTRL3D
) && desc
->lpwfxFormat
->nChannels
!= 1)
1277 if(This
->primary
->parent
->is_8
)
1279 /* DirectSoundBuffer8 objects aren't allowed non-mono 3D
1281 WARN("Can't create multi-channel 3D buffers\n");
1284 ERR("Multi-channel 3D sounds are not spatialized\n");
1287 hr
= DS8Data_Create(&This
->buffer
, desc
, This
->primary
);
1292 DS8Data
*buf
= This
->buffer
;
1294 if(buf
->format
.Format
.wBitsPerSample
== 8)
1295 memset(buf
->data
, 0x80, buf
->buf_size
);
1297 memset(buf
->data
, 0x00, buf
->buf_size
);
1299 if(This
->primary
->SupportedExt
[EXT_STATIC_BUFFER
])
1300 This
->ExtAL
->BufferDataStatic(buf
->buffers
[0], buf
->buf_format
,
1301 buf
->data
, buf
->buf_size
,
1302 buf
->format
.Format
.nSamplesPerSec
);
1303 else if(This
->primary
->SupportedExt
[SOFT_BUFFER_SAMPLES
])
1304 This
->ExtAL
->BufferSamplesSOFT(buf
->buffers
[0],
1305 buf
->format
.Format
.nSamplesPerSec
, buf
->buf_format
,
1306 buf
->buf_size
/buf
->format
.Format
.nBlockAlign
,
1307 buf
->in_chans
, buf
->in_type
, buf
->data
);
1308 else if(This
->primary
->SupportedExt
[SOFT_BUFFER_SUB_DATA
])
1309 alBufferData(buf
->buffers
[0], buf
->buf_format
,
1310 buf
->data
, buf
->buf_size
,
1311 buf
->format
.Format
.nSamplesPerSec
);
1317 if(This
->primary
->parent
->share
->nsources
)
1319 This
->source
= This
->primary
->sources
[--(This
->primary
->parent
->share
->nsources
)];
1320 alSourcef(This
->source
, AL_GAIN
, 1.0f
);
1321 alSourcef(This
->source
, AL_PITCH
, 1.0f
);
1327 ds3dbuffer
= &This
->params
;
1328 ds3dbuffer
->dwSize
= sizeof(This
->params
);
1329 ds3dbuffer
->vPosition
.x
= 0.0;
1330 ds3dbuffer
->vPosition
.y
= 0.0;
1331 ds3dbuffer
->vPosition
.z
= 0.0;
1332 ds3dbuffer
->vVelocity
.x
= 0.0;
1333 ds3dbuffer
->vVelocity
.y
= 0.0;
1334 ds3dbuffer
->vVelocity
.z
= 0.0;
1335 ds3dbuffer
->dwInsideConeAngle
= DS3D_DEFAULTCONEANGLE
;
1336 ds3dbuffer
->dwOutsideConeAngle
= DS3D_DEFAULTCONEANGLE
;
1337 ds3dbuffer
->vConeOrientation
.x
= 0.0;
1338 ds3dbuffer
->vConeOrientation
.y
= 0.0;
1339 ds3dbuffer
->vConeOrientation
.z
= 1.0;
1340 ds3dbuffer
->lConeOutsideVolume
= DS3D_DEFAULTCONEOUTSIDEVOLUME
;
1341 ds3dbuffer
->flMinDistance
= DS3D_DEFAULTMINDISTANCE
;
1342 ds3dbuffer
->flMaxDistance
= DS3D_DEFAULTMAXDISTANCE
;
1343 ds3dbuffer
->dwMode
= DS3DMODE_NORMAL
;
1345 if((This
->buffer
->dsbflags
&DSBCAPS_CTRL3D
))
1347 if(This
->primary
->auxslot
!= 0)
1349 alSource3i(This
->source
, AL_AUXILIARY_SEND_FILTER
, This
->primary
->auxslot
, 0, AL_FILTER_NULL
);
1353 hr
= IDirectSound3DBuffer_SetAllParameters(&This
->IDirectSound3DBuffer_iface
, ds3dbuffer
, DS3D_IMMEDIATE
);
1356 ERR("SetAllParameters failed\n");
1362 ALuint source
= This
->source
;
1364 if(This
->primary
->auxslot
!= 0)
1366 /* Simple hack to make reverb affect non-3D sounds too */
1367 alSource3i(source
, AL_AUXILIARY_SEND_FILTER
, This
->primary
->auxslot
, 0, AL_FILTER_NULL
);
1368 /*alSource3i(source, AL_AUXILIARY_SEND_FILTER, 0, 0, AL_FILTER_NULL);*/
1371 /* Non-3D sources aren't distance attenuated */
1372 This
->ds3dmode
= DS3DMODE_DISABLE
;
1373 alSource3f(source
, AL_POSITION
, 0.0f
, 1.0f
, 0.0f
);
1374 alSource3f(source
, AL_VELOCITY
, 0.0f
, 0.0f
, 0.0f
);
1375 alSource3f(source
, AL_DIRECTION
, 0.0f
, 0.0f
, 0.0f
);
1376 alSourcef(source
, AL_CONE_OUTER_GAIN
, 1.0f
);
1377 alSourcef(source
, AL_REFERENCE_DISTANCE
, 1.0f
);
1378 alSourcef(source
, AL_MAX_DISTANCE
, 1000.0f
);
1379 alSourcef(source
, AL_ROLLOFF_FACTOR
, 0.0f
);
1380 alSourcei(source
, AL_CONE_INNER_ANGLE
, 360);
1381 alSourcei(source
, AL_CONE_OUTER_ANGLE
, 360);
1382 alSourcei(source
, AL_SOURCE_RELATIVE
, AL_TRUE
);
1389 LeaveCriticalSection(This
->crst
);
1394 static HRESULT WINAPI
DS8Buffer_Lock(IDirectSoundBuffer8
*iface
, DWORD ofs
, DWORD bytes
, void **ptr1
, DWORD
*len1
, void **ptr2
, DWORD
*len2
, DWORD flags
)
1396 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1399 TRACE("(%p)->(%"LONGFMT
"u, %"LONGFMT
"u, %p, %p, %p, %p, 0x%"LONGFMT
"x)\n", This
, ofs
, bytes
, ptr1
, len1
, ptr2
, len2
, flags
);
1403 WARN("Invalid pointer/len %p %p\n", ptr1
, len1
);
1404 return DSERR_INVALIDPARAM
;
1409 if(ptr2
) *ptr2
= NULL
;
1412 if((flags
&DSBLOCK_FROMWRITECURSOR
))
1413 DS8Buffer_GetCurrentPosition(iface
, NULL
, &ofs
);
1414 else if(ofs
>= This
->buffer
->buf_size
)
1416 WARN("Invalid ofs %"LONGFMT
"u\n", ofs
);
1417 return DSERR_INVALIDPARAM
;
1419 if((flags
&DSBLOCK_ENTIREBUFFER
))
1420 bytes
= This
->buffer
->buf_size
;
1421 else if(bytes
> This
->buffer
->buf_size
)
1423 WARN("Invalid size %"LONGFMT
"u\n", bytes
);
1424 return DSERR_INVALIDPARAM
;
1427 if(InterlockedExchange(&This
->buffer
->locked
, TRUE
) == TRUE
)
1429 WARN("Already locked\n");
1430 return DSERR_INVALIDPARAM
;
1433 *ptr1
= This
->buffer
->data
+ ofs
;
1434 if(ofs
+bytes
>= This
->buffer
->buf_size
)
1436 *len1
= This
->buffer
->buf_size
- ofs
;
1437 remain
= bytes
- *len1
;
1445 if(ptr2
&& len2
&& remain
)
1447 *ptr2
= This
->buffer
->data
;
1454 static HRESULT WINAPI
DS8Buffer_Play(IDirectSoundBuffer8
*iface
, DWORD res1
, DWORD prio
, DWORD flags
)
1456 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1457 ALint type
, state
= AL_STOPPED
;
1460 TRACE("(%p)->(%"LONGFMT
"u, %"LONGFMT
"u, %"LONGFMT
"u)\n", iface
, res1
, prio
, flags
);
1462 EnterCriticalSection(This
->crst
);
1463 setALContext(This
->ctx
);
1465 hr
= DSERR_BUFFERLOST
;
1466 if(This
->bufferlost
)
1468 WARN("Buffer %p lost\n", This
);
1472 if((This
->buffer
->dsbflags
&DSBCAPS_LOCDEFER
))
1474 if(!(This
->buffer
->dsbflags
&(DSBCAPS_LOCHARDWARE
|DSBCAPS_LOCSOFTWARE
)))
1476 if(flags
& DSBPLAY_LOCSOFTWARE
)
1477 This
->buffer
->dsbflags
|= DSBCAPS_LOCSOFTWARE
;
1479 This
->buffer
->dsbflags
|= DSBCAPS_LOCHARDWARE
;
1484 ERR("Invalid priority set for non-deferred buffer %p, %"LONGFMT
"u!\n", This
->buffer
, prio
);
1485 hr
= DSERR_INVALIDPARAM
;
1489 alGetSourcei(This
->source
, AL_SOURCE_STATE
, &state
);
1490 if(This
->buffer
->numsegs
> 1)
1492 This
->islooping
= !!(flags
&DSBPLAY_LOOPING
);
1493 if(state
!= AL_PLAYING
&& This
->isplaying
)
1498 alGetSourcei(This
->source
, AL_SOURCE_TYPE
, &type
);
1499 alSourcei(This
->source
, AL_LOOPING
, (flags
&DSBPLAY_LOOPING
) ? AL_TRUE
: AL_FALSE
);
1504 if(state
== AL_PLAYING
)
1507 /* alSourceQueueBuffers will implicitly set type to streaming */
1508 if(This
->buffer
->numsegs
== 1)
1510 if(type
!= AL_STATIC
)
1511 alSourcei(This
->source
, AL_BUFFER
, This
->buffer
->buffers
[0]);
1512 alSourcePlay(This
->source
);
1514 if(alGetError() != AL_NO_ERROR
)
1516 ERR("Couldn't start source\n");
1517 This
->curidx
= (This
->buffer
->numsegs
-1+This
->curidx
)%This
->buffer
->numsegs
;
1518 alSourcei(This
->source
, AL_BUFFER
, 0);
1523 This
->isplaying
= TRUE
;
1527 DS8Buffer_addnotify(This
);
1528 DS8Primary_starttimer(This
->primary
);
1530 else if(This
->buffer
->numsegs
> 1)
1531 DS8Primary_starttimer(This
->primary
);
1535 LeaveCriticalSection(This
->crst
);
1539 static HRESULT WINAPI
DS8Buffer_SetCurrentPosition(IDirectSoundBuffer8
*iface
, DWORD pos
)
1541 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1543 TRACE("(%p)->(%"LONGFMT
"u)\n", iface
, pos
);
1545 if(pos
>= This
->buffer
->buf_size
)
1546 return DSERR_INVALIDPARAM
;
1548 EnterCriticalSection(This
->crst
);
1550 if(This
->buffer
->numsegs
> 1)
1552 DS8Data
*buf
= This
->buffer
;
1553 This
->curidx
= pos
/buf
->segsize
;
1554 if(This
->curidx
>= buf
->numsegs
)
1555 This
->curidx
= buf
->numsegs
- 1;
1558 setALContext(This
->ctx
);
1559 /* Perform a flush, so the next timer update will restart at the
1560 * proper position */
1561 alSourceStop(This
->source
);
1562 alSourcei(This
->source
, AL_BUFFER
, 0);
1569 setALContext(This
->ctx
);
1570 alSourcei(This
->source
, AL_BYTE_OFFSET
, pos
);
1573 This
->lastpos
= pos
;
1575 LeaveCriticalSection(This
->crst
);
1579 static HRESULT WINAPI
DS8Buffer_SetFormat(IDirectSoundBuffer8
*iface
, const WAVEFORMATEX
*wfx
)
1581 /* This call only works on primary buffers */
1582 WARN("(%p)->(%p)\n", iface
, wfx
);
1583 return DSERR_INVALIDCALL
;
1586 static HRESULT WINAPI
DS8Buffer_SetVolume(IDirectSoundBuffer8
*iface
, LONG vol
)
1588 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1591 TRACE("(%p)->(%"LONGFMT
"d)\n", iface
, vol
);
1593 if(vol
> DSBVOLUME_MAX
|| vol
< DSBVOLUME_MIN
)
1595 WARN("Invalid volume (%"LONGFMT
"d)\n", vol
);
1596 return DSERR_INVALIDPARAM
;
1599 if(!(This
->buffer
->dsbflags
&DSBCAPS_CTRLVOLUME
))
1600 hr
= DSERR_CONTROLUNAVAIL
;
1603 ALfloat fvol
= mB_to_gain(vol
);
1604 setALContext(This
->ctx
);
1605 alSourcef(This
->source
, AL_GAIN
, fvol
);
1612 static HRESULT WINAPI
DS8Buffer_SetPan(IDirectSoundBuffer8
*iface
, LONG pan
)
1614 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1617 TRACE("(%p)->(%"LONGFMT
"d)\n", iface
, pan
);
1619 if(pan
> DSBPAN_RIGHT
|| pan
< DSBPAN_LEFT
)
1621 WARN("invalid parameter: pan = %"LONGFMT
"d\n", pan
);
1622 return DSERR_INVALIDPARAM
;
1625 if(!(This
->buffer
->dsbflags
&DSBCAPS_CTRLPAN
))
1626 hr
= DSERR_CONTROLUNAVAIL
;
1630 pos
[0] = (pan
-DSBPAN_LEFT
) * 2.0 / (ALfloat
)(DSBPAN_RIGHT
-DSBPAN_LEFT
) - 1.0;
1631 /* NOTE: Strict movement along the X plane can cause the sound to jump
1632 * between left and right sharply. Using a curved path helps smooth it
1634 pos
[1] = sqrt(1.0 - pos
[0]*pos
[0]);
1637 setALContext(This
->ctx
);
1638 alSourcefv(This
->source
, AL_POSITION
, pos
);
1642 if(pan
!= 0 && This
->buffer
->format
.Format
.nChannels
> 1)
1643 FIXME("Panning for multi-channel buffers is not supported\n");
1649 static HRESULT WINAPI
DS8Buffer_SetFrequency(IDirectSoundBuffer8
*iface
, DWORD freq
)
1651 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1654 TRACE("(%p)->(%"LONGFMT
"u)\n", iface
, freq
);
1656 if(freq
< DSBFREQUENCY_MIN
|| freq
> DSBFREQUENCY_MAX
)
1658 WARN("invalid parameter: freq = %"LONGFMT
"u\n", freq
);
1659 return DSERR_INVALIDPARAM
;
1662 if(!(This
->buffer
->dsbflags
&DSBCAPS_CTRLFREQUENCY
))
1663 hr
= DSERR_CONTROLUNAVAIL
;
1666 ALfloat pitch
= 1.0f
;
1667 if(freq
!= DSBFREQUENCY_ORIGINAL
)
1668 pitch
= freq
/ (ALfloat
)This
->buffer
->format
.Format
.nSamplesPerSec
;
1670 setALContext(This
->ctx
);
1671 alSourcef(This
->source
, AL_PITCH
, pitch
);
1679 static HRESULT WINAPI
DS8Buffer_Stop(IDirectSoundBuffer8
*iface
)
1681 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1684 TRACE("(%p)->()\n", iface
);
1686 EnterCriticalSection(This
->crst
);
1687 setALContext(This
->ctx
);
1689 alSourcePause(This
->source
);
1691 /* Mac OS X doesn't immediately report state change
1692 * if Play() is immediately called after Stop, this can be fatal,
1693 * the buffer would never be restarted
1697 alGetSourcei(This
->source
, AL_SOURCE_STATE
, &state
);
1698 if(state
!= AL_PLAYING
)
1703 This
->isplaying
= FALSE
;
1706 LeaveCriticalSection(This
->crst
);
1711 static HRESULT WINAPI
DS8Buffer_Unlock(IDirectSoundBuffer8
*iface
, void *ptr1
, DWORD len1
, void *ptr2
, DWORD len2
)
1713 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1714 DS8Data
*buf
= This
->buffer
;
1715 DWORD bufsize
= buf
->buf_size
;
1716 DWORD_PTR ofs1
, ofs2
;
1717 DWORD_PTR boundary
= (DWORD_PTR
)buf
->data
;
1720 TRACE("(%p)->(%p, %"LONGFMT
"u, %p, %"LONGFMT
"u)\n", iface
, ptr1
, len1
, ptr2
, len2
);
1722 if(InterlockedExchange(&This
->buffer
->locked
, FALSE
) == FALSE
)
1724 WARN("Not locked\n");
1725 return DSERR_INVALIDPARAM
;
1728 hr
= DSERR_INVALIDPARAM
;
1729 /* Make sure offset is between boundary and boundary + bufsize */
1730 ofs1
= (DWORD_PTR
)ptr1
;
1731 ofs2
= (DWORD_PTR
)ptr2
;
1734 if(ofs2
&& ofs2
!= boundary
)
1738 if(bufsize
-ofs1
< len1
|| len2
> ofs1
)
1746 if(This
->primary
->SupportedExt
[EXT_STATIC_BUFFER
])
1749 setALContext(This
->ctx
);
1750 if(This
->primary
->SupportedExt
[SOFT_BUFFER_SAMPLES
])
1752 const WAVEFORMATEX
*format
= &buf
->format
.Format
;
1754 ptr1
= (BYTE
*)ptr1
- (ofs1
%format
->nBlockAlign
);
1755 ofs1
/= format
->nBlockAlign
;
1756 len1
/= format
->nBlockAlign
;
1758 This
->ExtAL
->BufferSubSamplesSOFT(buf
->buffers
[0], ofs1
, len1
,
1759 buf
->in_chans
, buf
->in_type
, ptr1
);
1760 ptr2
= (BYTE
*)ptr2
- (ofs2
%format
->nBlockAlign
);
1761 ofs2
/= format
->nBlockAlign
;
1762 len2
/= format
->nBlockAlign
;
1764 This
->ExtAL
->BufferSubSamplesSOFT(buf
->buffers
[0], ofs2
, len2
,
1765 buf
->in_chans
, buf
->in_type
, ptr2
);
1768 else if(This
->primary
->SupportedExt
[SOFT_BUFFER_SUB_DATA
])
1770 const WAVEFORMATEX
*format
= &buf
->format
.Format
;
1772 len1
-= len1
%format
->nBlockAlign
;
1774 This
->ExtAL
->BufferSubData(buf
->buffers
[0], buf
->buf_format
, ptr1
,
1776 len2
-= len2
%format
->nBlockAlign
;
1778 This
->ExtAL
->BufferSubData(buf
->buffers
[0], buf
->buf_format
, ptr2
,
1784 alBufferData(buf
->buffers
[0], buf
->buf_format
,
1785 buf
->data
, buf
->buf_size
,
1786 buf
->format
.Format
.nSamplesPerSec
);
1793 WARN("Invalid parameters (0x%lx,%"LONGFMT
"u) (%p,%"LONGFMT
"u,%p,%"LONGFMT
"u)\n", boundary
, bufsize
, ptr1
, len1
, ptr2
, len2
);
1797 static HRESULT WINAPI
DS8Buffer_Restore(IDirectSoundBuffer8
*iface
)
1799 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1802 TRACE("(%p)->()\n", iface
);
1804 EnterCriticalSection(This
->crst
);
1805 if(This
->primary
->parent
->prio_level
< DSSCL_WRITEPRIMARY
||
1806 iface
== This
->primary
->write_emu
)
1808 This
->bufferlost
= 0;
1812 hr
= DSERR_BUFFERLOST
;
1813 LeaveCriticalSection(This
->crst
);
1818 static HRESULT WINAPI
DS8Buffer_SetFX(IDirectSoundBuffer8
*iface
, DWORD fxcount
, DSEFFECTDESC
*desc
, DWORD
*rescodes
)
1820 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1823 TRACE("(%p)->(%"LONGFMT
"u, %p, %p)\n", This
, fxcount
, desc
, rescodes
);
1825 if(!(This
->buffer
->dsbflags
&DSBCAPS_CTRLFX
))
1827 WARN("FX control not set\n");
1828 return DSERR_CONTROLUNAVAIL
;
1833 if(desc
|| rescodes
)
1835 WARN("Non-NULL desc and/or result pointer specified with no effects.\n");
1836 return DSERR_INVALIDPARAM
;
1839 /* No effects; we can handle that */
1843 if(!desc
|| !rescodes
)
1845 WARN("NULL desc and/or result pointer specified.\n");
1846 return DSERR_INVALIDPARAM
;
1849 /* We don't (currently) handle DSound effects */
1850 for(i
= 0;i
< fxcount
;++i
)
1852 FIXME("Cannot handle effect: %s\n", debugstr_guid(&desc
[i
].guidDSFXClass
));
1853 rescodes
[i
] = DSFXR_FAILED
;
1856 return DS_INCOMPLETE
;
1859 static HRESULT WINAPI
DS8Buffer_AcquireResources(IDirectSoundBuffer8
*iface
, DWORD flags
, DWORD fxcount
, DWORD
*rescodes
)
1861 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1863 TRACE("(%p)->(%"LONGFMT
"u, %"LONGFMT
"u, %p)\n", This
, flags
, fxcount
, rescodes
);
1865 /* effects aren't supported at the moment.. */
1866 if(fxcount
!= 0 || rescodes
)
1868 WARN("Non-zero effect count and/or result pointer specified with no effects.\n");
1869 return DSERR_INVALIDPARAM
;
1872 EnterCriticalSection(This
->crst
);
1873 if((This
->buffer
->dsbflags
&DSBCAPS_LOCDEFER
))
1875 This
->buffer
->dsbflags
&= ~(DSBCAPS_LOCSOFTWARE
|DSBCAPS_LOCHARDWARE
);
1876 if((flags
&DSBPLAY_LOCSOFTWARE
))
1877 This
->buffer
->dsbflags
|= DSBCAPS_LOCSOFTWARE
;
1879 This
->buffer
->dsbflags
|= DSBCAPS_LOCHARDWARE
;
1881 LeaveCriticalSection(This
->crst
);
1886 static HRESULT WINAPI
DS8Buffer_GetObjectInPath(IDirectSoundBuffer8
*iface
, REFGUID guid
, DWORD idx
, REFGUID rguidiface
, void **ppv
)
1888 FIXME("(%p)->(%s, %"LONGFMT
"u, %s, %p) : stub!\n", iface
, debugstr_guid(guid
), idx
, debugstr_guid(rguidiface
), ppv
);
1892 static const IDirectSoundBuffer8Vtbl DS8Buffer_Vtbl
= {
1893 DS8Buffer_QueryInterface
,
1897 DS8Buffer_GetCurrentPosition
,
1898 DS8Buffer_GetFormat
,
1899 DS8Buffer_GetVolume
,
1901 DS8Buffer_GetFrequency
,
1902 DS8Buffer_GetStatus
,
1903 DS8Buffer_Initialize
,
1906 DS8Buffer_SetCurrentPosition
,
1907 DS8Buffer_SetFormat
,
1908 DS8Buffer_SetVolume
,
1910 DS8Buffer_SetFrequency
,
1915 DS8Buffer_AcquireResources
,
1916 DS8Buffer_GetObjectInPath
1920 static HRESULT WINAPI
DSBuffer_QueryInterface(IDirectSoundBuffer
*iface
, REFIID riid
, void **ppv
)
1922 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1923 return DS8Buffer_QueryInterface(&This
->IDirectSoundBuffer8_iface
, riid
, ppv
);
1926 static ULONG WINAPI
DSBuffer_AddRef(IDirectSoundBuffer
*iface
)
1928 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1929 return DS8Buffer_AddRef(&This
->IDirectSoundBuffer8_iface
);
1932 static ULONG WINAPI
DSBuffer_Release(IDirectSoundBuffer
*iface
)
1934 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1935 return DS8Buffer_Release(&This
->IDirectSoundBuffer8_iface
);
1938 static HRESULT WINAPI
DSBuffer_GetCaps(IDirectSoundBuffer
*iface
, DSBCAPS
*caps
)
1940 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1941 return DS8Buffer_GetCaps(&This
->IDirectSoundBuffer8_iface
, caps
);
1944 static HRESULT WINAPI
DSBuffer_GetCurrentPosition(IDirectSoundBuffer
*iface
, DWORD
*playpos
, DWORD
*curpos
)
1946 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1947 return DS8Buffer_GetCurrentPosition(&This
->IDirectSoundBuffer8_iface
, playpos
, curpos
);
1950 static HRESULT WINAPI
DSBuffer_GetFormat(IDirectSoundBuffer
*iface
, WAVEFORMATEX
*wfx
, DWORD allocated
, DWORD
*written
)
1952 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1953 return DS8Buffer_GetFormat(&This
->IDirectSoundBuffer8_iface
, wfx
, allocated
, written
);
1956 static HRESULT WINAPI
DSBuffer_GetVolume(IDirectSoundBuffer
*iface
, LONG
*vol
)
1958 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1959 return DS8Buffer_GetVolume(&This
->IDirectSoundBuffer8_iface
, vol
);
1962 static HRESULT WINAPI
DSBuffer_GetPan(IDirectSoundBuffer
*iface
, LONG
*pan
)
1964 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1965 return DS8Buffer_GetPan(&This
->IDirectSoundBuffer8_iface
, pan
);
1968 static HRESULT WINAPI
DSBuffer_GetFrequency(IDirectSoundBuffer
*iface
, DWORD
*freq
)
1970 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1971 return DS8Buffer_GetFrequency(&This
->IDirectSoundBuffer8_iface
, freq
);
1974 static HRESULT WINAPI
DSBuffer_GetStatus(IDirectSoundBuffer
*iface
, DWORD
*status
)
1976 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1977 return DS8Buffer_GetStatus(&This
->IDirectSoundBuffer8_iface
, status
);
1980 static HRESULT WINAPI
DSBuffer_Initialize(IDirectSoundBuffer
*iface
, IDirectSound
*ds
, const DSBUFFERDESC
*desc
)
1982 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1983 return DS8Buffer_Initialize(&This
->IDirectSoundBuffer8_iface
, ds
, desc
);
1986 static HRESULT WINAPI
DSBuffer_Lock(IDirectSoundBuffer
*iface
, DWORD ofs
, DWORD bytes
, void **ptr1
, DWORD
*len1
, void **ptr2
, DWORD
*len2
, DWORD flags
)
1988 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1989 return DS8Buffer_Lock(&This
->IDirectSoundBuffer8_iface
, ofs
, bytes
, ptr1
, len1
, ptr2
, len2
, flags
);
1992 static HRESULT WINAPI
DSBuffer_Play(IDirectSoundBuffer
*iface
, DWORD res1
, DWORD prio
, DWORD flags
)
1994 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1995 return DS8Buffer_Play(&This
->IDirectSoundBuffer8_iface
, res1
, prio
, flags
);
1998 static HRESULT WINAPI
DSBuffer_SetCurrentPosition(IDirectSoundBuffer
*iface
, DWORD pos
)
2000 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
2001 return DS8Buffer_SetCurrentPosition(&This
->IDirectSoundBuffer8_iface
, pos
);
2004 static HRESULT WINAPI
DSBuffer_SetFormat(IDirectSoundBuffer
*iface
, const WAVEFORMATEX
*wfx
)
2006 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
2007 return DS8Buffer_SetFormat(&This
->IDirectSoundBuffer8_iface
, wfx
);
2010 static HRESULT WINAPI
DSBuffer_SetVolume(IDirectSoundBuffer
*iface
, LONG vol
)
2012 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
2013 return DS8Buffer_SetVolume(&This
->IDirectSoundBuffer8_iface
, vol
);
2016 static HRESULT WINAPI
DSBuffer_SetPan(IDirectSoundBuffer
*iface
, LONG pan
)
2018 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
2019 return DS8Buffer_SetPan(&This
->IDirectSoundBuffer8_iface
, pan
);
2022 static HRESULT WINAPI
DSBuffer_SetFrequency(IDirectSoundBuffer
*iface
, DWORD freq
)
2024 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
2025 return DS8Buffer_SetFrequency(&This
->IDirectSoundBuffer8_iface
, freq
);
2028 static HRESULT WINAPI
DSBuffer_Stop(IDirectSoundBuffer
*iface
)
2030 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
2031 return DS8Buffer_Stop(&This
->IDirectSoundBuffer8_iface
);
2034 static HRESULT WINAPI
DSBuffer_Unlock(IDirectSoundBuffer
*iface
, void *ptr1
, DWORD len1
, void *ptr2
, DWORD len2
)
2036 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
2037 return DS8Buffer_Unlock(&This
->IDirectSoundBuffer8_iface
, ptr1
, len1
, ptr2
, len2
);
2040 static HRESULT WINAPI
DSBuffer_Restore(IDirectSoundBuffer
*iface
)
2042 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
2043 return DS8Buffer_Restore(&This
->IDirectSoundBuffer8_iface
);
2046 static const IDirectSoundBufferVtbl DSBuffer_Vtbl
= {
2047 DSBuffer_QueryInterface
,
2051 DSBuffer_GetCurrentPosition
,
2055 DSBuffer_GetFrequency
,
2057 DSBuffer_Initialize
,
2060 DSBuffer_SetCurrentPosition
,
2064 DSBuffer_SetFrequency
,
2071 void DS8Buffer_SetParams(DS8Buffer
*This
, const DS3DBUFFER
*params
, LONG flags
)
2073 const ALuint source
= This
->source
;
2074 union BufferParamFlags dirty
= { flags
};
2077 alSource3f(source
, AL_POSITION
, params
->vPosition
.x
, params
->vPosition
.y
,
2078 -params
->vPosition
.z
);
2080 alSource3f(source
, AL_VELOCITY
, params
->vVelocity
.x
, params
->vVelocity
.y
,
2081 -params
->vVelocity
.z
);
2082 if(dirty
.bit
.cone_angles
)
2084 alSourcei(source
, AL_CONE_INNER_ANGLE
, params
->dwInsideConeAngle
);
2085 alSourcei(source
, AL_CONE_OUTER_ANGLE
, params
->dwOutsideConeAngle
);
2087 if(dirty
.bit
.cone_orient
)
2088 alSource3f(source
, AL_DIRECTION
, params
->vConeOrientation
.x
,
2089 params
->vConeOrientation
.y
,
2090 -params
->vConeOrientation
.z
);
2091 if(dirty
.bit
.cone_outsidevolume
)
2092 alSourcef(source
, AL_CONE_OUTER_GAIN
, mB_to_gain(params
->lConeOutsideVolume
));
2093 if(dirty
.bit
.min_distance
)
2094 alSourcef(source
, AL_REFERENCE_DISTANCE
, params
->flMinDistance
);
2095 if(dirty
.bit
.max_distance
)
2096 alSourcef(source
, AL_MAX_DISTANCE
, params
->flMaxDistance
);
2099 This
->ds3dmode
= params
->dwMode
;
2100 alSourcei(source
, AL_SOURCE_RELATIVE
, (params
->dwMode
!=DS3DMODE_NORMAL
) ?
2101 AL_TRUE
: AL_FALSE
);
2102 alSourcef(source
, AL_ROLLOFF_FACTOR
, (params
->dwMode
==DS3DMODE_DISABLE
) ?
2103 0.0f
: This
->primary
->rollofffactor
);
2107 static HRESULT WINAPI
DS8Buffer3D_QueryInterface(IDirectSound3DBuffer
*iface
, REFIID riid
, void **ppv
)
2109 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2110 return IDirectSoundBuffer8_QueryInterface(&This
->IDirectSoundBuffer8_iface
, riid
, ppv
);
2113 static ULONG WINAPI
DS8Buffer3D_AddRef(IDirectSound3DBuffer
*iface
)
2115 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2118 InterlockedIncrement(&This
->all_ref
);
2119 ret
= InterlockedIncrement(&This
->ds3d_ref
);
2120 TRACE("new refcount %"LONGFMT
"d\n", ret
);
2125 static ULONG WINAPI
DS8Buffer3D_Release(IDirectSound3DBuffer
*iface
)
2127 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2130 ret
= InterlockedDecrement(&This
->ds3d_ref
);
2131 TRACE("new refcount %"LONGFMT
"d\n", ret
);
2132 if(InterlockedDecrement(&This
->all_ref
) == 0)
2133 DS8Buffer_Destroy(This
);
2138 static HRESULT WINAPI
DS8Buffer3D_GetAllParameters(IDirectSound3DBuffer
*iface
, DS3DBUFFER
*ds3dbuffer
)
2140 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2142 TRACE("(%p)->(%p)\n", iface
, ds3dbuffer
);
2144 if(!ds3dbuffer
|| ds3dbuffer
->dwSize
< sizeof(*ds3dbuffer
))
2146 WARN("Invalid parameters %p %"LONGFMT
"u\n", ds3dbuffer
, ds3dbuffer
? ds3dbuffer
->dwSize
: 0);
2147 return DSERR_INVALIDPARAM
;
2150 EnterCriticalSection(This
->crst
);
2151 setALContext(This
->ctx
);
2153 IDirectSound3DBuffer_GetPosition(iface
, &ds3dbuffer
->vPosition
);
2154 IDirectSound3DBuffer_GetVelocity(iface
, &ds3dbuffer
->vVelocity
);
2155 IDirectSound3DBuffer_GetConeAngles(iface
, &ds3dbuffer
->dwInsideConeAngle
, &ds3dbuffer
->dwOutsideConeAngle
);
2156 IDirectSound3DBuffer_GetConeOrientation(iface
, &ds3dbuffer
->vConeOrientation
);
2157 IDirectSound3DBuffer_GetConeOutsideVolume(iface
, &ds3dbuffer
->lConeOutsideVolume
);
2158 IDirectSound3DBuffer_GetMinDistance(iface
, &ds3dbuffer
->flMinDistance
);
2159 IDirectSound3DBuffer_GetMaxDistance(iface
, &ds3dbuffer
->flMaxDistance
);
2160 IDirectSound3DBuffer_GetMode(iface
, &ds3dbuffer
->dwMode
);
2163 LeaveCriticalSection(This
->crst
);
2168 static HRESULT WINAPI
DS8Buffer3D_GetConeAngles(IDirectSound3DBuffer
*iface
, DWORD
*pdwInsideConeAngle
, DWORD
*pdwOutsideConeAngle
)
2170 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2171 ALint inangle
, outangle
;
2173 TRACE("(%p)->(%p, %p)\n", This
, pdwInsideConeAngle
, pdwOutsideConeAngle
);
2174 if(!pdwInsideConeAngle
|| !pdwOutsideConeAngle
)
2176 WARN("Invalid pointers (%p, %p)\n", pdwInsideConeAngle
, pdwOutsideConeAngle
);
2177 return DSERR_INVALIDPARAM
;
2180 EnterCriticalSection(This
->crst
);
2181 setALContext(This
->ctx
);
2183 alGetSourcei(This
->source
, AL_CONE_INNER_ANGLE
, &inangle
);
2184 alGetSourcei(This
->source
, AL_CONE_OUTER_ANGLE
, &outangle
);
2188 LeaveCriticalSection(This
->crst
);
2190 *pdwInsideConeAngle
= inangle
;
2191 *pdwOutsideConeAngle
= outangle
;
2195 static HRESULT WINAPI
DS8Buffer3D_GetConeOrientation(IDirectSound3DBuffer
*iface
, D3DVECTOR
*orient
)
2197 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2200 TRACE("(%p)->(%p)\n", This
, orient
);
2203 WARN("Invalid pointer\n");
2204 return DSERR_INVALIDPARAM
;
2207 setALContext(This
->ctx
);
2208 alGetSourcefv(This
->source
, AL_DIRECTION
, dir
);
2214 orient
->z
= -dir
[2];
2218 static HRESULT WINAPI
DS8Buffer3D_GetConeOutsideVolume(IDirectSound3DBuffer
*iface
, LONG
*vol
)
2220 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2223 TRACE("(%p)->(%p)\n", This
, vol
);
2226 WARN("Invalid pointer\n");
2227 return DSERR_INVALIDPARAM
;
2230 setALContext(This
->ctx
);
2231 alGetSourcef(This
->source
, AL_CONE_OUTER_GAIN
, &gain
);
2235 *vol
= clampI(gain_to_mB(gain
), DSBVOLUME_MIN
, DSBVOLUME_MAX
);
2239 static HRESULT WINAPI
DS8Buffer3D_GetMaxDistance(IDirectSound3DBuffer
*iface
, D3DVALUE
*maxdist
)
2241 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2244 TRACE("(%p)->(%p)\n", This
, maxdist
);
2247 WARN("Invalid pointer\n");
2248 return DSERR_INVALIDPARAM
;
2251 setALContext(This
->ctx
);
2252 alGetSourcef(This
->source
, AL_MAX_DISTANCE
, &dist
);
2260 static HRESULT WINAPI
DS8Buffer3D_GetMinDistance(IDirectSound3DBuffer
*iface
, D3DVALUE
*mindist
)
2262 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2265 TRACE("(%p)->(%p)\n", This
, mindist
);
2268 WARN("Invalid pointer\n");
2269 return DSERR_INVALIDPARAM
;
2272 setALContext(This
->ctx
);
2273 alGetSourcef(This
->source
, AL_REFERENCE_DISTANCE
, &dist
);
2281 static HRESULT WINAPI
DS8Buffer3D_GetMode(IDirectSound3DBuffer
*iface
, DWORD
*mode
)
2283 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2285 TRACE("(%p)->(%p)\n", This
, mode
);
2288 WARN("Invalid pointer\n");
2289 return DSERR_INVALIDPARAM
;
2292 EnterCriticalSection(This
->crst
);
2293 *mode
= This
->ds3dmode
;
2294 LeaveCriticalSection(This
->crst
);
2299 static HRESULT WINAPI
DS8Buffer3D_GetPosition(IDirectSound3DBuffer
*iface
, D3DVECTOR
*pos
)
2301 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2304 TRACE("(%p)->(%p)\n", This
, pos
);
2307 WARN("Invalid pointer\n");
2308 return DSERR_INVALIDPARAM
;
2311 setALContext(This
->ctx
);
2312 alGetSourcefv(This
->source
, AL_POSITION
, alpos
);
2322 static HRESULT WINAPI
DS8Buffer3D_GetVelocity(IDirectSound3DBuffer
*iface
, D3DVECTOR
*vel
)
2324 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2327 TRACE("(%p)->(%p)\n", This
, vel
);
2330 WARN("Invalid pointer\n");
2331 return DSERR_INVALIDPARAM
;
2334 setALContext(This
->ctx
);
2335 alGetSourcefv(This
->source
, AL_VELOCITY
, alvel
);
2345 static HRESULT WINAPI
DS8Buffer3D_SetAllParameters(IDirectSound3DBuffer
*iface
, const DS3DBUFFER
*ds3dbuffer
, DWORD apply
)
2347 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2348 TRACE("(%p)->(%p, %"LONGFMT
"u)\n", This
, ds3dbuffer
, apply
);
2350 if(!ds3dbuffer
|| ds3dbuffer
->dwSize
< sizeof(*ds3dbuffer
))
2352 WARN("Invalid DS3DBUFFER (%p, %"LONGFMT
"u)\n", ds3dbuffer
, ds3dbuffer
? ds3dbuffer
->dwSize
: 0);
2353 return DSERR_INVALIDPARAM
;
2356 if(ds3dbuffer
->dwInsideConeAngle
> DS3D_MAXCONEANGLE
||
2357 ds3dbuffer
->dwOutsideConeAngle
> DS3D_MAXCONEANGLE
)
2359 WARN("Invalid cone angles (%"LONGFMT
"u, %"LONGFMT
"u)\n",
2360 ds3dbuffer
->dwInsideConeAngle
, ds3dbuffer
->dwOutsideConeAngle
);
2361 return DSERR_INVALIDPARAM
;
2364 if(ds3dbuffer
->lConeOutsideVolume
> DSBVOLUME_MAX
||
2365 ds3dbuffer
->lConeOutsideVolume
< DSBVOLUME_MIN
)
2367 WARN("Invalid cone outside volume (%"LONGFMT
"d)\n", ds3dbuffer
->lConeOutsideVolume
);
2368 return DSERR_INVALIDPARAM
;
2371 if(ds3dbuffer
->flMaxDistance
< 0.0f
)
2373 WARN("Invalid max distance (%f)\n", ds3dbuffer
->flMaxDistance
);
2374 return DSERR_INVALIDPARAM
;
2377 if(ds3dbuffer
->flMinDistance
< 0.0f
)
2379 WARN("Invalid min distance (%f)\n", ds3dbuffer
->flMinDistance
);
2380 return DSERR_INVALIDPARAM
;
2383 if(ds3dbuffer
->dwMode
!= DS3DMODE_NORMAL
&&
2384 ds3dbuffer
->dwMode
!= DS3DMODE_HEADRELATIVE
&&
2385 ds3dbuffer
->dwMode
!= DS3DMODE_DISABLE
)
2387 WARN("Invalid mode (%"LONGFMT
"u)\n", ds3dbuffer
->dwMode
);
2388 return DSERR_INVALIDPARAM
;
2391 if(apply
== DS3D_DEFERRED
)
2393 EnterCriticalSection(This
->crst
);
2394 This
->params
= *ds3dbuffer
;
2395 This
->params
.dwSize
= sizeof(This
->params
);
2396 This
->dirty
.bit
.pos
= 1;
2397 This
->dirty
.bit
.vel
= 1;
2398 This
->dirty
.bit
.cone_angles
= 1;
2399 This
->dirty
.bit
.cone_orient
= 1;
2400 This
->dirty
.bit
.cone_outsidevolume
= 1;
2401 This
->dirty
.bit
.min_distance
= 1;
2402 This
->dirty
.bit
.max_distance
= 1;
2403 This
->dirty
.bit
.mode
= 1;
2404 LeaveCriticalSection(This
->crst
);
2408 union BufferParamFlags dirty
= { 0 };
2411 dirty
.bit
.cone_angles
= 1;
2412 dirty
.bit
.cone_orient
= 1;
2413 dirty
.bit
.cone_outsidevolume
= 1;
2414 dirty
.bit
.min_distance
= 1;
2415 dirty
.bit
.max_distance
= 1;
2418 EnterCriticalSection(This
->crst
);
2419 setALContext(This
->ctx
);
2420 DS8Buffer_SetParams(This
, ds3dbuffer
, dirty
.flags
);
2423 LeaveCriticalSection(This
->crst
);
2429 static HRESULT WINAPI
DS8Buffer3D_SetConeAngles(IDirectSound3DBuffer
*iface
, DWORD dwInsideConeAngle
, DWORD dwOutsideConeAngle
, DWORD apply
)
2431 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2433 TRACE("(%p)->(%"LONGFMT
"u, %"LONGFMT
"u, %"LONGFMT
"u)\n", This
, dwInsideConeAngle
, dwOutsideConeAngle
, apply
);
2434 if(dwInsideConeAngle
> DS3D_MAXCONEANGLE
||
2435 dwOutsideConeAngle
> DS3D_MAXCONEANGLE
)
2437 WARN("Invalid cone angles (%"LONGFMT
"u, %"LONGFMT
"u)\n", dwInsideConeAngle
, dwOutsideConeAngle
);
2438 return DSERR_INVALIDPARAM
;
2441 EnterCriticalSection(This
->crst
);
2442 if(apply
== DS3D_DEFERRED
)
2444 This
->params
.dwInsideConeAngle
= dwInsideConeAngle
;
2445 This
->params
.dwOutsideConeAngle
= dwOutsideConeAngle
;
2446 This
->dirty
.bit
.cone_angles
= 1;
2450 setALContext(This
->ctx
);
2451 alSourcei(This
->source
, AL_CONE_INNER_ANGLE
, dwInsideConeAngle
);
2452 alSourcei(This
->source
, AL_CONE_OUTER_ANGLE
, dwOutsideConeAngle
);
2456 LeaveCriticalSection(This
->crst
);
2461 static HRESULT WINAPI
DS8Buffer3D_SetConeOrientation(IDirectSound3DBuffer
*iface
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD apply
)
2463 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2465 TRACE("(%p)->(%f, %f, %f, %"LONGFMT
"u)\n", This
, x
, y
, z
, apply
);
2467 if(apply
== DS3D_DEFERRED
)
2469 EnterCriticalSection(This
->crst
);
2470 This
->params
.vConeOrientation
.x
= x
;
2471 This
->params
.vConeOrientation
.y
= y
;
2472 This
->params
.vConeOrientation
.z
= z
;
2473 This
->dirty
.bit
.cone_orient
= 1;
2474 LeaveCriticalSection(This
->crst
);
2478 setALContext(This
->ctx
);
2479 alSource3f(This
->source
, AL_DIRECTION
, x
, y
, -z
);
2487 static HRESULT WINAPI
DS8Buffer3D_SetConeOutsideVolume(IDirectSound3DBuffer
*iface
, LONG vol
, DWORD apply
)
2489 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2491 TRACE("(%p)->(%"LONGFMT
"d, %"LONGFMT
"u)\n", This
, vol
, apply
);
2492 if(vol
< DSBVOLUME_MIN
|| vol
> DSBVOLUME_MAX
)
2494 WARN("Invalid volume (%"LONGFMT
"d)\n", vol
);
2495 return DSERR_INVALIDPARAM
;
2498 if(apply
== DS3D_DEFERRED
)
2500 EnterCriticalSection(This
->crst
);
2501 This
->params
.lConeOutsideVolume
= vol
;
2502 This
->dirty
.bit
.cone_outsidevolume
= 1;
2503 LeaveCriticalSection(This
->crst
);
2507 setALContext(This
->ctx
);
2508 alSourcef(This
->source
, AL_CONE_OUTER_GAIN
, mB_to_gain(vol
));
2516 static HRESULT WINAPI
DS8Buffer3D_SetMaxDistance(IDirectSound3DBuffer
*iface
, D3DVALUE maxdist
, DWORD apply
)
2518 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2520 TRACE("(%p)->(%f, %"LONGFMT
"u)\n", This
, maxdist
, apply
);
2523 WARN("Invalid max distance (%f)\n", maxdist
);
2524 return DSERR_INVALIDPARAM
;
2527 if(apply
== DS3D_DEFERRED
)
2529 EnterCriticalSection(This
->crst
);
2530 This
->params
.flMaxDistance
= maxdist
;
2531 This
->dirty
.bit
.max_distance
= 1;
2532 LeaveCriticalSection(This
->crst
);
2536 setALContext(This
->ctx
);
2537 alSourcef(This
->source
, AL_MAX_DISTANCE
, maxdist
);
2545 static HRESULT WINAPI
DS8Buffer3D_SetMinDistance(IDirectSound3DBuffer
*iface
, D3DVALUE mindist
, DWORD apply
)
2547 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2549 TRACE("(%p)->(%f, %"LONGFMT
"u)\n", This
, mindist
, apply
);
2552 WARN("Invalid min distance (%f)\n", mindist
);
2553 return DSERR_INVALIDPARAM
;
2556 if(apply
== DS3D_DEFERRED
)
2558 EnterCriticalSection(This
->crst
);
2559 This
->params
.flMinDistance
= mindist
;
2560 This
->dirty
.bit
.min_distance
= 1;
2561 LeaveCriticalSection(This
->crst
);
2565 setALContext(This
->ctx
);
2566 alSourcef(This
->source
, AL_REFERENCE_DISTANCE
, mindist
);
2574 static HRESULT WINAPI
DS8Buffer3D_SetMode(IDirectSound3DBuffer
*iface
, DWORD mode
, DWORD apply
)
2576 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2578 TRACE("(%p)->(%"LONGFMT
"u, %"LONGFMT
"u)\n", This
, mode
, apply
);
2579 if(mode
!= DS3DMODE_NORMAL
&& mode
!= DS3DMODE_HEADRELATIVE
&&
2580 mode
!= DS3DMODE_DISABLE
)
2582 WARN("Invalid mode (%"LONGFMT
"u)\n", mode
);
2583 return DSERR_INVALIDPARAM
;
2586 EnterCriticalSection(This
->crst
);
2587 if(apply
== DS3D_DEFERRED
)
2589 This
->params
.dwMode
= mode
;
2590 This
->dirty
.bit
.mode
= 1;
2594 setALContext(This
->ctx
);
2595 alSourcei(This
->source
, AL_SOURCE_RELATIVE
,
2596 (mode
!= DS3DMODE_NORMAL
) ? AL_TRUE
: AL_FALSE
);
2597 alSourcef(This
->source
, AL_ROLLOFF_FACTOR
,
2598 (mode
== DS3DMODE_DISABLE
) ? 0.0f
: This
->primary
->rollofffactor
);
2599 This
->ds3dmode
= mode
;
2603 LeaveCriticalSection(This
->crst
);
2608 static HRESULT WINAPI
DS8Buffer3D_SetPosition(IDirectSound3DBuffer
*iface
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD apply
)
2610 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2612 TRACE("(%p)->(%f, %f, %f, %"LONGFMT
"u)\n", This
, x
, y
, z
, apply
);
2614 if(apply
== DS3D_DEFERRED
)
2616 EnterCriticalSection(This
->crst
);
2617 This
->params
.vPosition
.x
= x
;
2618 This
->params
.vPosition
.y
= y
;
2619 This
->params
.vPosition
.z
= z
;
2620 This
->dirty
.bit
.pos
= 1;
2621 LeaveCriticalSection(This
->crst
);
2625 setALContext(This
->ctx
);
2626 alSource3f(This
->source
, AL_POSITION
, x
, y
, -z
);
2634 static HRESULT WINAPI
DS8Buffer3D_SetVelocity(IDirectSound3DBuffer
*iface
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD apply
)
2636 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2638 TRACE("(%p)->(%f, %f, %f, %"LONGFMT
"u)\n", This
, x
, y
, z
, apply
);
2640 if(apply
== DS3D_DEFERRED
)
2642 EnterCriticalSection(This
->crst
);
2643 This
->params
.vVelocity
.x
= x
;
2644 This
->params
.vVelocity
.y
= y
;
2645 This
->params
.vVelocity
.z
= z
;
2646 This
->dirty
.bit
.vel
= 1;
2647 LeaveCriticalSection(This
->crst
);
2651 setALContext(This
->ctx
);
2652 alSource3f(This
->source
, AL_VELOCITY
, x
, y
, -z
);
2660 static const IDirectSound3DBufferVtbl DS8Buffer3d_Vtbl
=
2662 DS8Buffer3D_QueryInterface
,
2664 DS8Buffer3D_Release
,
2665 DS8Buffer3D_GetAllParameters
,
2666 DS8Buffer3D_GetConeAngles
,
2667 DS8Buffer3D_GetConeOrientation
,
2668 DS8Buffer3D_GetConeOutsideVolume
,
2669 DS8Buffer3D_GetMaxDistance
,
2670 DS8Buffer3D_GetMinDistance
,
2671 DS8Buffer3D_GetMode
,
2672 DS8Buffer3D_GetPosition
,
2673 DS8Buffer3D_GetVelocity
,
2674 DS8Buffer3D_SetAllParameters
,
2675 DS8Buffer3D_SetConeAngles
,
2676 DS8Buffer3D_SetConeOrientation
,
2677 DS8Buffer3D_SetConeOutsideVolume
,
2678 DS8Buffer3D_SetMaxDistance
,
2679 DS8Buffer3D_SetMinDistance
,
2680 DS8Buffer3D_SetMode
,
2681 DS8Buffer3D_SetPosition
,
2682 DS8Buffer3D_SetVelocity
2686 static HRESULT WINAPI
DS8BufferNot_QueryInterface(IDirectSoundNotify
*iface
, REFIID riid
, void **ppv
)
2688 DS8Buffer
*This
= impl_from_IDirectSoundNotify(iface
);
2689 return IDirectSoundBuffer8_QueryInterface(&This
->IDirectSoundBuffer8_iface
, riid
, ppv
);
2692 static ULONG WINAPI
DS8BufferNot_AddRef(IDirectSoundNotify
*iface
)
2694 DS8Buffer
*This
= impl_from_IDirectSoundNotify(iface
);
2697 InterlockedIncrement(&This
->all_ref
);
2698 ret
= InterlockedIncrement(&This
->not_ref
);
2699 TRACE("new refcount %"LONGFMT
"d\n", ret
);
2704 static ULONG WINAPI
DS8BufferNot_Release(IDirectSoundNotify
*iface
)
2706 DS8Buffer
*This
= impl_from_IDirectSoundNotify(iface
);
2709 ret
= InterlockedDecrement(&This
->not_ref
);
2710 TRACE("new refcount %"LONGFMT
"d\n", ret
);
2711 if(InterlockedDecrement(&This
->all_ref
) == 0)
2712 DS8Buffer_Destroy(This
);
2717 static HRESULT WINAPI
DS8BufferNot_SetNotificationPositions(IDirectSoundNotify
*iface
, DWORD count
, const DSBPOSITIONNOTIFY
*notifications
)
2719 DS8Buffer
*This
= impl_from_IDirectSoundNotify(iface
);
2720 DSBPOSITIONNOTIFY
*nots
;
2724 EnterCriticalSection(This
->crst
);
2725 hr
= DSERR_INVALIDPARAM
;
2726 if(count
&& !notifications
)
2729 hr
= IDirectSoundBuffer8_GetStatus(&This
->IDirectSoundBuffer8_iface
, &state
);
2733 hr
= DSERR_INVALIDCALL
;
2734 if((state
&DSBSTATUS_PLAYING
))
2739 HeapFree(GetProcessHeap(), 0, This
->notify
);
2748 hr
= DSERR_INVALIDPARAM
;
2749 for(i
= 0;i
< count
;++i
)
2751 if(notifications
[i
].dwOffset
>= This
->buffer
->buf_size
&&
2752 notifications
[i
].dwOffset
!= (DWORD
)DSBPN_OFFSETSTOP
)
2757 nots
= HeapAlloc(GetProcessHeap(), 0, count
*sizeof(*nots
));
2760 memcpy(nots
, notifications
, count
*sizeof(*nots
));
2762 HeapFree(GetProcessHeap(), 0, This
->notify
);
2763 This
->notify
= nots
;
2764 This
->nnotify
= count
;
2770 LeaveCriticalSection(This
->crst
);
2774 static const IDirectSoundNotifyVtbl DS8BufferNot_Vtbl
=
2776 DS8BufferNot_QueryInterface
,
2777 DS8BufferNot_AddRef
,
2778 DS8BufferNot_Release
,
2779 DS8BufferNot_SetNotificationPositions
2783 static HRESULT WINAPI
DS8BufferProp_QueryInterface(IKsPropertySet
*iface
, REFIID riid
, void **ppv
)
2785 DS8Buffer
*This
= impl_from_IKsPropertySet(iface
);
2786 return IDirectSoundBuffer8_QueryInterface(&This
->IDirectSoundBuffer8_iface
, riid
, ppv
);
2789 static ULONG WINAPI
DS8BufferProp_AddRef(IKsPropertySet
*iface
)
2791 DS8Buffer
*This
= impl_from_IKsPropertySet(iface
);
2794 InterlockedIncrement(&This
->all_ref
);
2795 ret
= InterlockedIncrement(&This
->prop_ref
);
2796 TRACE("new refcount %"LONGFMT
"d\n", ret
);
2801 static ULONG WINAPI
DS8BufferProp_Release(IKsPropertySet
*iface
)
2803 DS8Buffer
*This
= impl_from_IKsPropertySet(iface
);
2806 ret
= InterlockedDecrement(&This
->prop_ref
);
2807 TRACE("new refcount %"LONGFMT
"d\n", ret
);
2808 if(InterlockedDecrement(&This
->all_ref
) == 0)
2809 DS8Buffer_Destroy(This
);
2814 /* NOTE: Due to some apparent quirks in DSound, the listener properties are
2815 handled through secondary buffers. */
2816 static HRESULT WINAPI
DS8BufferProp_Get(IKsPropertySet
*iface
,
2817 REFGUID guidPropSet
, ULONG dwPropID
,
2818 LPVOID pInstanceData
, ULONG cbInstanceData
,
2819 LPVOID pPropData
, ULONG cbPropData
,
2822 DS8Buffer
*This
= impl_from_IKsPropertySet(iface
);
2823 HRESULT hr
= E_PROP_ID_UNSUPPORTED
;
2825 TRACE("(%p)->(%s, %"LONGFMT
"u, %p, %"LONGFMT
"u, %p, %"LONGFMT
"u, %p)\n", iface
, debugstr_guid(guidPropSet
),
2826 dwPropID
, pInstanceData
, cbInstanceData
, pPropData
, cbPropData
, pcbReturned
);
2833 if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX20_BufferProperties
))
2839 /* Not a known buffer/source property. Pass it to the listener */
2840 hr
= IKsPropertySet_Get(&This
->primary
->IKsPropertySet_iface
, guidPropSet
,
2841 dwPropID
, pInstanceData
, cbInstanceData
, pPropData
, cbPropData
,
2848 static HRESULT WINAPI
DS8BufferProp_Set(IKsPropertySet
*iface
,
2849 REFGUID guidPropSet
, ULONG dwPropID
,
2850 LPVOID pInstanceData
, ULONG cbInstanceData
,
2851 LPVOID pPropData
, ULONG cbPropData
)
2853 DS8Buffer
*This
= impl_from_IKsPropertySet(iface
);
2854 HRESULT hr
= E_PROP_ID_UNSUPPORTED
;
2856 TRACE("(%p)->(%s, %"LONGFMT
"u, %p, %"LONGFMT
"u, %p, %"LONGFMT
"u)\n", iface
, debugstr_guid(guidPropSet
),
2857 dwPropID
, pInstanceData
, cbInstanceData
, pPropData
, cbPropData
);
2860 if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX20_BufferProperties
))
2866 /* Not a known buffer/source property. Pass it to the listener */
2867 hr
= IKsPropertySet_Set(&This
->primary
->IKsPropertySet_iface
, guidPropSet
,
2868 dwPropID
, pInstanceData
, cbInstanceData
, pPropData
,
2875 static HRESULT WINAPI
DS8BufferProp_QuerySupport(IKsPropertySet
*iface
,
2876 REFGUID guidPropSet
, ULONG dwPropID
,
2877 PULONG pTypeSupport
)
2879 DS8Buffer
*This
= impl_from_IKsPropertySet(iface
);
2880 HRESULT hr
= E_PROP_ID_UNSUPPORTED
;
2882 TRACE("(%p)->(%s, %"LONGFMT
"u, %p)\n", iface
, debugstr_guid(guidPropSet
), dwPropID
, pTypeSupport
);
2889 if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX20_BufferProperties
))
2895 /* Not a known buffer/source property. Pass it to the listener */
2896 hr
= IKsPropertySet_QuerySupport(&This
->primary
->IKsPropertySet_iface
,
2897 guidPropSet
, dwPropID
, pTypeSupport
);
2903 static const IKsPropertySetVtbl DS8BufferProp_Vtbl
=
2905 DS8BufferProp_QueryInterface
,
2906 DS8BufferProp_AddRef
,
2907 DS8BufferProp_Release
,
2910 DS8BufferProp_QuerySupport