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 EnterCriticalSection(This
->crst
);
1004 setALContext(This
->ctx
);
1006 if(This
->buffer
->numsegs
> 1)
1008 ALint queued
= QBUFFERS
;
1009 alGetSourcei(This
->source
, AL_BUFFERS_QUEUED
, &queued
);
1012 pos
= (This
->curidx
+This
->buffer
->numsegs
-queued
)%This
->buffer
->numsegs
;
1013 pos
*= This
->buffer
->segsize
;
1014 writecursor
= This
->curidx
* This
->buffer
->segsize
;
1016 else if(This
->primary
->SupportedExt
[SOFT_BUFFER_SUB_DATA
] ||
1017 This
->primary
->SupportedExt
[SOFT_BUFFER_SAMPLES
])
1019 ALint rwpos
[2] = { 0, 0 };
1021 alGetSourceiv(This
->source
, AL_BYTE_RW_OFFSETS_SOFT
, rwpos
);
1025 writecursor
= rwpos
[1];
1032 alGetSourcei(This
->source
, AL_BYTE_OFFSET
, &ofs
);
1033 alGetSourcei(This
->source
, AL_SOURCE_STATE
, &status
);
1037 if(status
== AL_PLAYING
)
1039 writecursor
= format
->nSamplesPerSec
/ 100;
1040 writecursor
*= format
->nBlockAlign
;
1044 writecursor
= (writecursor
+ pos
) % This
->buffer
->buf_size
;
1046 TRACE("%p Play pos = %u, write pos = %u\n", This
, pos
, writecursor
);
1047 if(pos
>= This
->buffer
->buf_size
)
1049 ERR("playpos >= buf_size\n");
1050 pos
%= This
->buffer
->buf_size
;
1052 if(writecursor
>= This
->buffer
->buf_size
)
1054 ERR("writepos >= buf_size\n");
1055 writecursor
%= This
->buffer
->buf_size
;
1058 if(playpos
) *playpos
= pos
;
1059 if(curpos
) *curpos
= writecursor
;
1062 LeaveCriticalSection(This
->crst
);
1067 static HRESULT WINAPI
DS8Buffer_GetFormat(IDirectSoundBuffer8
*iface
, WAVEFORMATEX
*wfx
, DWORD allocated
, DWORD
*written
)
1069 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1073 TRACE("(%p)->(%p, %"LONGFMT
"u, %p)\n", iface
, wfx
, allocated
, written
);
1075 if(!wfx
&& !written
)
1077 WARN("Cannot report format or format size\n");
1078 return DSERR_INVALIDPARAM
;
1081 size
= sizeof(This
->buffer
->format
.Format
) + This
->buffer
->format
.Format
.cbSize
;
1084 if(allocated
< size
)
1085 hr
= DSERR_INVALIDPARAM
;
1087 memcpy(wfx
, &This
->buffer
->format
.Format
, size
);
1095 static HRESULT WINAPI
DS8Buffer_GetVolume(IDirectSoundBuffer8
*iface
, LONG
*vol
)
1097 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1100 TRACE("(%p)->(%p)\n", iface
, vol
);
1104 WARN("Invalid pointer\n");
1105 return DSERR_INVALIDPARAM
;
1108 hr
= DSERR_CONTROLUNAVAIL
;
1109 if(!(This
->buffer
->dsbflags
&DSBCAPS_CTRLVOLUME
))
1110 WARN("Volume control not set\n");
1113 ALfloat gain
= 1.0f
;
1115 setALContext(This
->ctx
);
1116 alGetSourcef(This
->source
, AL_GAIN
, &gain
);
1120 *vol
= clampI(gain_to_mB(gain
), DSBVOLUME_MIN
, DSBVOLUME_MAX
);
1127 static HRESULT WINAPI
DS8Buffer_GetPan(IDirectSoundBuffer8
*iface
, LONG
*pan
)
1129 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1132 TRACE("(%p)->(%p)\n", iface
, pan
);
1136 WARN("Invalid pointer\n");
1137 return DSERR_INVALIDPARAM
;
1140 hr
= DSERR_CONTROLUNAVAIL
;
1141 if(!(This
->buffer
->dsbflags
&DSBCAPS_CTRLPAN
))
1142 WARN("Panning control not set\n");
1147 setALContext(This
->ctx
);
1148 alGetSourcefv(This
->source
, AL_POSITION
, pos
);
1152 *pan
= clampI(((pos
[0]+1.0) * (DSBPAN_RIGHT
-DSBPAN_LEFT
) / 2.0 + 0.5) + DSBPAN_LEFT
, DSBPAN_LEFT
, DSBPAN_RIGHT
);
1159 static HRESULT WINAPI
DS8Buffer_GetFrequency(IDirectSoundBuffer8
*iface
, DWORD
*freq
)
1161 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1164 TRACE("(%p)->(%p)\n", iface
, freq
);
1168 WARN("Invalid pointer\n");
1169 return DSERR_INVALIDPARAM
;
1172 hr
= DSERR_CONTROLUNAVAIL
;
1173 if(!(This
->buffer
->dsbflags
&DSBCAPS_CTRLFREQUENCY
))
1174 WARN("Frequency control not set\n");
1177 ALfloat pitch
= 1.0f
;
1179 setALContext(This
->ctx
);
1180 alGetSourcefv(This
->source
, AL_PITCH
, &pitch
);
1184 *freq
= (DWORD
)(This
->buffer
->format
.Format
.nSamplesPerSec
* pitch
);
1191 static HRESULT WINAPI
DS8Buffer_GetStatus(IDirectSoundBuffer8
*iface
, DWORD
*status
)
1193 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1194 ALint state
, looping
;
1196 TRACE("(%p)->(%p)\n", iface
, status
);
1200 WARN("Invalid pointer\n");
1201 return DSERR_INVALIDPARAM
;
1204 EnterCriticalSection(This
->crst
);
1206 setALContext(This
->ctx
);
1207 alGetSourcei(This
->source
, AL_SOURCE_STATE
, &state
);
1208 looping
= This
->islooping
;
1209 if(This
->buffer
->numsegs
== 1)
1210 alGetSourcei(This
->source
, AL_LOOPING
, &looping
);
1211 else if(state
!= AL_PLAYING
)
1212 state
= This
->isplaying
? AL_PLAYING
: AL_PAUSED
;
1216 LeaveCriticalSection(This
->crst
);
1219 if((This
->buffer
->dsbflags
&DSBCAPS_LOCDEFER
))
1221 if((This
->buffer
->dsbflags
&DSBCAPS_LOCSOFTWARE
))
1222 *status
|= DSBSTATUS_LOCSOFTWARE
;
1223 else if((This
->buffer
->dsbflags
&DSBCAPS_LOCHARDWARE
))
1224 *status
|= DSBSTATUS_LOCHARDWARE
;
1226 if(state
== AL_PLAYING
)
1227 *status
|= DSBSTATUS_PLAYING
| (looping
? DSBSTATUS_LOOPING
: 0);
1232 static HRESULT WINAPI
DS8Buffer_Initialize(IDirectSoundBuffer8
*iface
, IDirectSound
*ds
, const DSBUFFERDESC
*desc
)
1234 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1235 DS3DBUFFER
*ds3dbuffer
;
1238 TRACE("(%p)->(%p, %p)\n", iface
, ds
, desc
);
1240 EnterCriticalSection(This
->crst
);
1241 setALContext(This
->ctx
);
1243 hr
= DSERR_ALREADYINITIALIZED
;
1249 hr
= DSERR_INVALIDPARAM
;
1252 WARN("Missing DSound buffer description\n");
1255 if(!desc
->lpwfxFormat
)
1257 WARN("Missing buffer format (%p)\n", This
);
1260 if((desc
->dwFlags
&DSBCAPS_CTRL3D
) && desc
->lpwfxFormat
->nChannels
!= 1)
1262 if(This
->primary
->parent
->is_8
)
1264 /* DirectSoundBuffer8 objects aren't allowed non-mono 3D
1266 WARN("Can't create multi-channel 3D buffers\n");
1269 ERR("Multi-channel 3D sounds are not spatialized\n");
1272 hr
= DS8Data_Create(&This
->buffer
, desc
, This
->primary
);
1277 DS8Data
*buf
= This
->buffer
;
1279 if(buf
->format
.Format
.wBitsPerSample
== 8)
1280 memset(buf
->data
, 0x80, buf
->buf_size
);
1282 memset(buf
->data
, 0x00, buf
->buf_size
);
1284 if(This
->primary
->SupportedExt
[EXT_STATIC_BUFFER
])
1285 This
->ExtAL
->BufferDataStatic(buf
->buffers
[0], buf
->buf_format
,
1286 buf
->data
, buf
->buf_size
,
1287 buf
->format
.Format
.nSamplesPerSec
);
1288 else if(This
->primary
->SupportedExt
[SOFT_BUFFER_SAMPLES
])
1289 This
->ExtAL
->BufferSamplesSOFT(buf
->buffers
[0],
1290 buf
->format
.Format
.nSamplesPerSec
, buf
->buf_format
,
1291 buf
->buf_size
/buf
->format
.Format
.nBlockAlign
,
1292 buf
->in_chans
, buf
->in_type
, buf
->data
);
1293 else if(This
->primary
->SupportedExt
[SOFT_BUFFER_SUB_DATA
])
1294 alBufferData(buf
->buffers
[0], buf
->buf_format
,
1295 buf
->data
, buf
->buf_size
,
1296 buf
->format
.Format
.nSamplesPerSec
);
1302 if(This
->primary
->parent
->share
->nsources
)
1304 This
->source
= This
->primary
->sources
[--(This
->primary
->parent
->share
->nsources
)];
1305 alSourcef(This
->source
, AL_GAIN
, 1.0f
);
1306 alSourcef(This
->source
, AL_PITCH
, 1.0f
);
1312 ds3dbuffer
= &This
->ds3dbuffer
;
1313 ds3dbuffer
->dwSize
= sizeof(*ds3dbuffer
);
1314 ds3dbuffer
->vPosition
.x
= 0.0;
1315 ds3dbuffer
->vPosition
.y
= 0.0;
1316 ds3dbuffer
->vPosition
.z
= 0.0;
1317 ds3dbuffer
->vVelocity
.x
= 0.0;
1318 ds3dbuffer
->vVelocity
.y
= 0.0;
1319 ds3dbuffer
->vVelocity
.z
= 0.0;
1320 ds3dbuffer
->dwInsideConeAngle
= DS3D_DEFAULTCONEANGLE
;
1321 ds3dbuffer
->dwOutsideConeAngle
= DS3D_DEFAULTCONEANGLE
;
1322 ds3dbuffer
->vConeOrientation
.x
= 0.0;
1323 ds3dbuffer
->vConeOrientation
.y
= 0.0;
1324 ds3dbuffer
->vConeOrientation
.z
= 1.0;
1325 ds3dbuffer
->lConeOutsideVolume
= DS3D_DEFAULTCONEOUTSIDEVOLUME
;
1326 ds3dbuffer
->flMinDistance
= DS3D_DEFAULTMINDISTANCE
;
1327 ds3dbuffer
->flMaxDistance
= DS3D_DEFAULTMAXDISTANCE
;
1328 ds3dbuffer
->dwMode
= DS3DMODE_NORMAL
;
1330 if((This
->buffer
->dsbflags
&DSBCAPS_CTRL3D
))
1332 if(This
->primary
->auxslot
!= 0)
1334 alSource3i(This
->source
, AL_AUXILIARY_SEND_FILTER
, This
->primary
->auxslot
, 0, AL_FILTER_NULL
);
1338 hr
= IDirectSound3DBuffer_SetAllParameters(&This
->IDirectSound3DBuffer_iface
, ds3dbuffer
, DS3D_IMMEDIATE
);
1341 ERR("SetAllParameters failed\n");
1347 ALuint source
= This
->source
;
1349 if(This
->primary
->auxslot
!= 0)
1351 /* Simple hack to make reverb affect non-3D sounds too */
1352 alSource3i(source
, AL_AUXILIARY_SEND_FILTER
, This
->primary
->auxslot
, 0, AL_FILTER_NULL
);
1353 /*alSource3i(source, AL_AUXILIARY_SEND_FILTER, 0, 0, AL_FILTER_NULL);*/
1356 /* Non-3D sources aren't distance attenuated */
1357 This
->ds3dmode
= DS3DMODE_DISABLE
;
1358 alSource3f(source
, AL_POSITION
, 0.0f
, 1.0f
, 0.0f
);
1359 alSource3f(source
, AL_VELOCITY
, 0.0f
, 0.0f
, 0.0f
);
1360 alSource3f(source
, AL_DIRECTION
, 0.0f
, 0.0f
, 0.0f
);
1361 alSourcef(source
, AL_CONE_OUTER_GAIN
, 1.0f
);
1362 alSourcef(source
, AL_REFERENCE_DISTANCE
, 1.0f
);
1363 alSourcef(source
, AL_MAX_DISTANCE
, 1000.0f
);
1364 alSourcef(source
, AL_ROLLOFF_FACTOR
, 0.0f
);
1365 alSourcei(source
, AL_CONE_INNER_ANGLE
, 360);
1366 alSourcei(source
, AL_CONE_OUTER_ANGLE
, 360);
1367 alSourcei(source
, AL_SOURCE_RELATIVE
, AL_TRUE
);
1374 LeaveCriticalSection(This
->crst
);
1379 static HRESULT WINAPI
DS8Buffer_Lock(IDirectSoundBuffer8
*iface
, DWORD ofs
, DWORD bytes
, void **ptr1
, DWORD
*len1
, void **ptr2
, DWORD
*len2
, DWORD flags
)
1381 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1384 TRACE("(%p)->(%"LONGFMT
"u, %"LONGFMT
"u, %p, %p, %p, %p, 0x%"LONGFMT
"x)\n", This
, ofs
, bytes
, ptr1
, len1
, ptr2
, len2
, flags
);
1388 WARN("Invalid pointer/len %p %p\n", ptr1
, len1
);
1389 return DSERR_INVALIDPARAM
;
1394 if(ptr2
) *ptr2
= NULL
;
1397 if((flags
&DSBLOCK_FROMWRITECURSOR
))
1398 DS8Buffer_GetCurrentPosition(iface
, NULL
, &ofs
);
1399 else if(ofs
>= This
->buffer
->buf_size
)
1401 WARN("Invalid ofs %"LONGFMT
"u\n", ofs
);
1402 return DSERR_INVALIDPARAM
;
1404 if((flags
&DSBLOCK_ENTIREBUFFER
))
1405 bytes
= This
->buffer
->buf_size
;
1406 else if(bytes
> This
->buffer
->buf_size
)
1408 WARN("Invalid size %"LONGFMT
"u\n", bytes
);
1409 return DSERR_INVALIDPARAM
;
1412 if(InterlockedExchange(&This
->buffer
->locked
, TRUE
) == TRUE
)
1414 WARN("Already locked\n");
1415 return DSERR_INVALIDPARAM
;
1418 *ptr1
= This
->buffer
->data
+ ofs
;
1419 if(ofs
+bytes
>= This
->buffer
->buf_size
)
1421 *len1
= This
->buffer
->buf_size
- ofs
;
1422 remain
= bytes
- *len1
;
1430 if(ptr2
&& len2
&& remain
)
1432 *ptr2
= This
->buffer
->data
;
1439 static HRESULT WINAPI
DS8Buffer_Play(IDirectSoundBuffer8
*iface
, DWORD res1
, DWORD prio
, DWORD flags
)
1441 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1442 ALint type
, state
= AL_STOPPED
;
1445 TRACE("(%p)->(%"LONGFMT
"u, %"LONGFMT
"u, %"LONGFMT
"u\n", iface
, res1
, prio
, flags
);
1447 EnterCriticalSection(This
->crst
);
1448 setALContext(This
->ctx
);
1450 hr
= DSERR_BUFFERLOST
;
1451 if(This
->bufferlost
)
1453 WARN("Buffer %p lost\n", This
);
1457 if((This
->buffer
->dsbflags
&DSBCAPS_LOCDEFER
))
1459 if(!(This
->buffer
->dsbflags
&(DSBCAPS_LOCHARDWARE
|DSBCAPS_LOCSOFTWARE
)))
1461 if(flags
& DSBPLAY_LOCSOFTWARE
)
1462 This
->buffer
->dsbflags
|= DSBCAPS_LOCSOFTWARE
;
1464 This
->buffer
->dsbflags
|= DSBCAPS_LOCHARDWARE
;
1469 ERR("Invalid priority set for non-deferred buffer %p, %"LONGFMT
"u!\n", This
->buffer
, prio
);
1470 hr
= DSERR_INVALIDPARAM
;
1474 alGetSourcei(This
->source
, AL_SOURCE_STATE
, &state
);
1475 if(This
->buffer
->numsegs
> 1)
1477 This
->islooping
= !!(flags
&DSBPLAY_LOOPING
);
1478 if(state
!= AL_PLAYING
&& This
->isplaying
)
1483 alGetSourcei(This
->source
, AL_SOURCE_TYPE
, &type
);
1484 alSourcei(This
->source
, AL_LOOPING
, (flags
&DSBPLAY_LOOPING
) ? AL_TRUE
: AL_FALSE
);
1489 if(state
== AL_PLAYING
)
1492 /* alSourceQueueBuffers will implicitly set type to streaming */
1493 if(This
->buffer
->numsegs
== 1)
1495 if(type
!= AL_STATIC
)
1496 alSourcei(This
->source
, AL_BUFFER
, This
->buffer
->buffers
[0]);
1497 alSourcePlay(This
->source
);
1499 if(alGetError() != AL_NO_ERROR
)
1501 ERR("Couldn't start source\n");
1502 This
->curidx
= (This
->buffer
->numsegs
-1+This
->curidx
)%This
->buffer
->numsegs
;
1503 alSourcei(This
->source
, AL_BUFFER
, 0);
1508 This
->isplaying
= TRUE
;
1512 DS8Buffer_addnotify(This
);
1513 DS8Primary_starttimer(This
->primary
);
1515 else if(This
->buffer
->numsegs
> 1)
1516 DS8Primary_starttimer(This
->primary
);
1520 LeaveCriticalSection(This
->crst
);
1524 static HRESULT WINAPI
DS8Buffer_SetCurrentPosition(IDirectSoundBuffer8
*iface
, DWORD pos
)
1526 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1528 TRACE("(%p)->(%"LONGFMT
"u)\n", iface
, pos
);
1530 if(pos
>= This
->buffer
->buf_size
)
1531 return DSERR_INVALIDPARAM
;
1533 EnterCriticalSection(This
->crst
);
1535 if(This
->buffer
->numsegs
> 1)
1537 DS8Data
*buf
= This
->buffer
;
1538 This
->curidx
= pos
/buf
->segsize
;
1539 if(This
->curidx
>= buf
->numsegs
)
1540 This
->curidx
= buf
->numsegs
- 1;
1543 setALContext(This
->ctx
);
1544 /* Perform a flush, so the next timer update will restart at the
1545 * proper position */
1546 alSourceStop(This
->source
);
1547 alSourcei(This
->source
, AL_BUFFER
, 0);
1554 setALContext(This
->ctx
);
1555 alSourcei(This
->source
, AL_BYTE_OFFSET
, pos
);
1558 This
->lastpos
= pos
;
1560 LeaveCriticalSection(This
->crst
);
1564 static HRESULT WINAPI
DS8Buffer_SetFormat(IDirectSoundBuffer8
*iface
, const WAVEFORMATEX
*wfx
)
1566 /* This call only works on primary buffers */
1567 WARN("(%p)->(%p)\n", iface
, wfx
);
1568 return DSERR_INVALIDCALL
;
1571 static HRESULT WINAPI
DS8Buffer_SetVolume(IDirectSoundBuffer8
*iface
, LONG vol
)
1573 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1576 TRACE("(%p)->(%"LONGFMT
"d)\n", iface
, vol
);
1578 if(vol
> DSBVOLUME_MAX
|| vol
< DSBVOLUME_MIN
)
1580 WARN("Invalid volume (%"LONGFMT
"d)\n", vol
);
1581 return DSERR_INVALIDPARAM
;
1584 if(!(This
->buffer
->dsbflags
&DSBCAPS_CTRLVOLUME
))
1585 hr
= DSERR_CONTROLUNAVAIL
;
1588 ALfloat fvol
= mB_to_gain(vol
);
1589 setALContext(This
->ctx
);
1590 alSourcef(This
->source
, AL_GAIN
, fvol
);
1597 static HRESULT WINAPI
DS8Buffer_SetPan(IDirectSoundBuffer8
*iface
, LONG pan
)
1599 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1602 TRACE("(%p)->(%"LONGFMT
"d)\n", iface
, pan
);
1604 if(pan
> DSBPAN_RIGHT
|| pan
< DSBPAN_LEFT
)
1606 WARN("invalid parameter: pan = %"LONGFMT
"d\n", pan
);
1607 return DSERR_INVALIDPARAM
;
1610 if(!(This
->buffer
->dsbflags
&DSBCAPS_CTRLPAN
))
1611 hr
= DSERR_CONTROLUNAVAIL
;
1615 pos
[0] = (pan
-DSBPAN_LEFT
) * 2.0 / (ALfloat
)(DSBPAN_RIGHT
-DSBPAN_LEFT
) - 1.0;
1616 /* NOTE: Strict movement along the X plane can cause the sound to jump
1617 * between left and right sharply. Using a curved path helps smooth it
1619 pos
[1] = sqrt(1.0 - pos
[0]*pos
[0]);
1622 setALContext(This
->ctx
);
1623 alSourcefv(This
->source
, AL_POSITION
, pos
);
1627 if(pan
!= 0 && This
->buffer
->format
.Format
.nChannels
> 1)
1628 FIXME("Panning for multi-channel buffers is not supported\n");
1634 static HRESULT WINAPI
DS8Buffer_SetFrequency(IDirectSoundBuffer8
*iface
, DWORD freq
)
1636 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1639 TRACE("(%p)->(%"LONGFMT
"u)\n", iface
, freq
);
1641 if(freq
< DSBFREQUENCY_MIN
|| freq
> DSBFREQUENCY_MAX
)
1643 WARN("invalid parameter: freq = %"LONGFMT
"u\n", freq
);
1644 return DSERR_INVALIDPARAM
;
1647 if(!(This
->buffer
->dsbflags
&DSBCAPS_CTRLFREQUENCY
))
1648 hr
= DSERR_CONTROLUNAVAIL
;
1651 ALfloat pitch
= 1.0f
;
1652 if(freq
!= DSBFREQUENCY_ORIGINAL
)
1653 pitch
= freq
/ (ALfloat
)This
->buffer
->format
.Format
.nSamplesPerSec
;
1655 setALContext(This
->ctx
);
1656 alSourcef(This
->source
, AL_PITCH
, pitch
);
1664 static HRESULT WINAPI
DS8Buffer_Stop(IDirectSoundBuffer8
*iface
)
1666 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1669 TRACE("(%p)->()\n", iface
);
1671 EnterCriticalSection(This
->crst
);
1672 setALContext(This
->ctx
);
1674 alSourcePause(This
->source
);
1676 /* Mac OS X doesn't immediately report state change
1677 * if Play() is immediately called after Stop, this can be fatal,
1678 * the buffer would never be restarted
1682 alGetSourcei(This
->source
, AL_SOURCE_STATE
, &state
);
1683 if(state
!= AL_PLAYING
)
1688 This
->isplaying
= FALSE
;
1691 LeaveCriticalSection(This
->crst
);
1696 static HRESULT WINAPI
DS8Buffer_Unlock(IDirectSoundBuffer8
*iface
, void *ptr1
, DWORD len1
, void *ptr2
, DWORD len2
)
1698 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1699 DS8Data
*buf
= This
->buffer
;
1700 DWORD bufsize
= buf
->buf_size
;
1701 DWORD_PTR ofs1
, ofs2
;
1702 DWORD_PTR boundary
= (DWORD_PTR
)buf
->data
;
1705 TRACE("(%p)->(%p, %"LONGFMT
"u, %p, %"LONGFMT
"u)\n", iface
, ptr1
, len1
, ptr2
, len2
);
1707 if(InterlockedExchange(&This
->buffer
->locked
, FALSE
) == FALSE
)
1709 WARN("Not locked\n");
1710 return DSERR_INVALIDPARAM
;
1713 hr
= DSERR_INVALIDPARAM
;
1714 /* Make sure offset is between boundary and boundary + bufsize */
1715 ofs1
= (DWORD_PTR
)ptr1
;
1716 ofs2
= (DWORD_PTR
)ptr2
;
1719 if(ofs2
&& ofs2
!= boundary
)
1723 if(bufsize
-ofs1
< len1
|| len2
> ofs1
)
1731 if(This
->primary
->SupportedExt
[EXT_STATIC_BUFFER
])
1734 setALContext(This
->ctx
);
1735 if(This
->primary
->SupportedExt
[SOFT_BUFFER_SAMPLES
])
1737 const WAVEFORMATEX
*format
= &buf
->format
.Format
;
1739 ptr1
= (BYTE
*)ptr1
- (ofs1
%format
->nBlockAlign
);
1740 ofs1
/= format
->nBlockAlign
;
1741 len1
/= format
->nBlockAlign
;
1743 This
->ExtAL
->BufferSubSamplesSOFT(buf
->buffers
[0], ofs1
, len1
,
1744 buf
->in_chans
, buf
->in_type
, ptr1
);
1745 ptr2
= (BYTE
*)ptr2
- (ofs2
%format
->nBlockAlign
);
1746 ofs2
/= format
->nBlockAlign
;
1747 len2
/= format
->nBlockAlign
;
1749 This
->ExtAL
->BufferSubSamplesSOFT(buf
->buffers
[0], ofs2
, len2
,
1750 buf
->in_chans
, buf
->in_type
, ptr2
);
1753 else if(This
->primary
->SupportedExt
[SOFT_BUFFER_SUB_DATA
])
1755 const WAVEFORMATEX
*format
= &buf
->format
.Format
;
1757 len1
-= len1
%format
->nBlockAlign
;
1759 This
->ExtAL
->BufferSubData(buf
->buffers
[0], buf
->buf_format
, ptr1
,
1761 len2
-= len2
%format
->nBlockAlign
;
1763 This
->ExtAL
->BufferSubData(buf
->buffers
[0], buf
->buf_format
, ptr2
,
1769 alBufferData(buf
->buffers
[0], buf
->buf_format
,
1770 buf
->data
, buf
->buf_size
,
1771 buf
->format
.Format
.nSamplesPerSec
);
1778 WARN("Invalid parameters (0x%lx,%"LONGFMT
"u) (%p,%"LONGFMT
"u,%p,%"LONGFMT
"u)\n", boundary
, bufsize
, ptr1
, len1
, ptr2
, len2
);
1782 static HRESULT WINAPI
DS8Buffer_Restore(IDirectSoundBuffer8
*iface
)
1784 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1787 TRACE("(%p)->()\n", iface
);
1789 EnterCriticalSection(This
->crst
);
1790 if(This
->primary
->parent
->prio_level
< DSSCL_WRITEPRIMARY
||
1791 iface
== This
->primary
->write_emu
)
1793 This
->bufferlost
= 0;
1797 hr
= DSERR_BUFFERLOST
;
1798 LeaveCriticalSection(This
->crst
);
1803 static HRESULT WINAPI
DS8Buffer_SetFX(IDirectSoundBuffer8
*iface
, DWORD fxcount
, DSEFFECTDESC
*desc
, DWORD
*rescodes
)
1805 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1808 TRACE("(%p)->(%"LONGFMT
"u, %p, %p)\n", This
, fxcount
, desc
, rescodes
);
1810 if(!(This
->buffer
->dsbflags
&DSBCAPS_CTRLFX
))
1812 WARN("FX control not set\n");
1813 return DSERR_CONTROLUNAVAIL
;
1818 if(desc
|| rescodes
)
1820 WARN("Non-NULL desc and/or result pointer specified with no effects.\n");
1821 return DSERR_INVALIDPARAM
;
1824 /* No effects; we can handle that */
1828 if(!desc
|| !rescodes
)
1830 WARN("NULL desc and/or result pointer specified.\n");
1831 return DSERR_INVALIDPARAM
;
1834 /* We don't (currently) handle DSound effects */
1835 for(i
= 0;i
< fxcount
;++i
)
1837 FIXME("Cannot handle effect: %s\n", debugstr_guid(&desc
[i
].guidDSFXClass
));
1838 rescodes
[i
] = DSFXR_FAILED
;
1841 return DS_INCOMPLETE
;
1844 static HRESULT WINAPI
DS8Buffer_AcquireResources(IDirectSoundBuffer8
*iface
, DWORD flags
, DWORD fxcount
, DWORD
*rescodes
)
1846 DS8Buffer
*This
= impl_from_IDirectSoundBuffer8(iface
);
1848 TRACE("(%p)->(%"LONGFMT
"u, %"LONGFMT
"u, %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
->crst
);
1858 if((This
->buffer
->dsbflags
&DSBCAPS_LOCDEFER
))
1860 This
->buffer
->dsbflags
&= ~(DSBCAPS_LOCSOFTWARE
|DSBCAPS_LOCHARDWARE
);
1861 if((flags
&DSBPLAY_LOCSOFTWARE
))
1862 This
->buffer
->dsbflags
|= DSBCAPS_LOCSOFTWARE
;
1864 This
->buffer
->dsbflags
|= DSBCAPS_LOCHARDWARE
;
1866 LeaveCriticalSection(This
->crst
);
1871 static HRESULT WINAPI
DS8Buffer_GetObjectInPath(IDirectSoundBuffer8
*iface
, REFGUID guid
, DWORD idx
, REFGUID rguidiface
, void **ppv
)
1873 FIXME("(%p)->(%s, %"LONGFMT
"u, %s, %p) : stub!\n", iface
, debugstr_guid(guid
), idx
, debugstr_guid(rguidiface
), ppv
);
1877 static const IDirectSoundBuffer8Vtbl DS8Buffer_Vtbl
= {
1878 DS8Buffer_QueryInterface
,
1882 DS8Buffer_GetCurrentPosition
,
1883 DS8Buffer_GetFormat
,
1884 DS8Buffer_GetVolume
,
1886 DS8Buffer_GetFrequency
,
1887 DS8Buffer_GetStatus
,
1888 DS8Buffer_Initialize
,
1891 DS8Buffer_SetCurrentPosition
,
1892 DS8Buffer_SetFormat
,
1893 DS8Buffer_SetVolume
,
1895 DS8Buffer_SetFrequency
,
1900 DS8Buffer_AcquireResources
,
1901 DS8Buffer_GetObjectInPath
1905 static HRESULT WINAPI
DSBuffer_QueryInterface(IDirectSoundBuffer
*iface
, REFIID riid
, void **ppv
)
1907 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1908 return DS8Buffer_QueryInterface(&This
->IDirectSoundBuffer8_iface
, riid
, ppv
);
1911 static ULONG WINAPI
DSBuffer_AddRef(IDirectSoundBuffer
*iface
)
1913 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1914 return DS8Buffer_AddRef(&This
->IDirectSoundBuffer8_iface
);
1917 static ULONG WINAPI
DSBuffer_Release(IDirectSoundBuffer
*iface
)
1919 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1920 return DS8Buffer_Release(&This
->IDirectSoundBuffer8_iface
);
1923 static HRESULT WINAPI
DSBuffer_GetCaps(IDirectSoundBuffer
*iface
, DSBCAPS
*caps
)
1925 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1926 return DS8Buffer_GetCaps(&This
->IDirectSoundBuffer8_iface
, caps
);
1929 static HRESULT WINAPI
DSBuffer_GetCurrentPosition(IDirectSoundBuffer
*iface
, DWORD
*playpos
, DWORD
*curpos
)
1931 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1932 return DS8Buffer_GetCurrentPosition(&This
->IDirectSoundBuffer8_iface
, playpos
, curpos
);
1935 static HRESULT WINAPI
DSBuffer_GetFormat(IDirectSoundBuffer
*iface
, WAVEFORMATEX
*wfx
, DWORD allocated
, DWORD
*written
)
1937 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1938 return DS8Buffer_GetFormat(&This
->IDirectSoundBuffer8_iface
, wfx
, allocated
, written
);
1941 static HRESULT WINAPI
DSBuffer_GetVolume(IDirectSoundBuffer
*iface
, LONG
*vol
)
1943 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1944 return DS8Buffer_GetVolume(&This
->IDirectSoundBuffer8_iface
, vol
);
1947 static HRESULT WINAPI
DSBuffer_GetPan(IDirectSoundBuffer
*iface
, LONG
*pan
)
1949 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1950 return DS8Buffer_GetPan(&This
->IDirectSoundBuffer8_iface
, pan
);
1953 static HRESULT WINAPI
DSBuffer_GetFrequency(IDirectSoundBuffer
*iface
, DWORD
*freq
)
1955 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1956 return DS8Buffer_GetFrequency(&This
->IDirectSoundBuffer8_iface
, freq
);
1959 static HRESULT WINAPI
DSBuffer_GetStatus(IDirectSoundBuffer
*iface
, DWORD
*status
)
1961 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1962 return DS8Buffer_GetStatus(&This
->IDirectSoundBuffer8_iface
, status
);
1965 static HRESULT WINAPI
DSBuffer_Initialize(IDirectSoundBuffer
*iface
, IDirectSound
*ds
, const DSBUFFERDESC
*desc
)
1967 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1968 return DS8Buffer_Initialize(&This
->IDirectSoundBuffer8_iface
, ds
, desc
);
1971 static HRESULT WINAPI
DSBuffer_Lock(IDirectSoundBuffer
*iface
, DWORD ofs
, DWORD bytes
, void **ptr1
, DWORD
*len1
, void **ptr2
, DWORD
*len2
, DWORD flags
)
1973 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1974 return DS8Buffer_Lock(&This
->IDirectSoundBuffer8_iface
, ofs
, bytes
, ptr1
, len1
, ptr2
, len2
, flags
);
1977 static HRESULT WINAPI
DSBuffer_Play(IDirectSoundBuffer
*iface
, DWORD res1
, DWORD prio
, DWORD flags
)
1979 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1980 return DS8Buffer_Play(&This
->IDirectSoundBuffer8_iface
, res1
, prio
, flags
);
1983 static HRESULT WINAPI
DSBuffer_SetCurrentPosition(IDirectSoundBuffer
*iface
, DWORD pos
)
1985 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1986 return DS8Buffer_SetCurrentPosition(&This
->IDirectSoundBuffer8_iface
, pos
);
1989 static HRESULT WINAPI
DSBuffer_SetFormat(IDirectSoundBuffer
*iface
, const WAVEFORMATEX
*wfx
)
1991 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1992 return DS8Buffer_SetFormat(&This
->IDirectSoundBuffer8_iface
, wfx
);
1995 static HRESULT WINAPI
DSBuffer_SetVolume(IDirectSoundBuffer
*iface
, LONG vol
)
1997 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
1998 return DS8Buffer_SetVolume(&This
->IDirectSoundBuffer8_iface
, vol
);
2001 static HRESULT WINAPI
DSBuffer_SetPan(IDirectSoundBuffer
*iface
, LONG pan
)
2003 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
2004 return DS8Buffer_SetPan(&This
->IDirectSoundBuffer8_iface
, pan
);
2007 static HRESULT WINAPI
DSBuffer_SetFrequency(IDirectSoundBuffer
*iface
, DWORD freq
)
2009 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
2010 return DS8Buffer_SetFrequency(&This
->IDirectSoundBuffer8_iface
, freq
);
2013 static HRESULT WINAPI
DSBuffer_Stop(IDirectSoundBuffer
*iface
)
2015 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
2016 return DS8Buffer_Stop(&This
->IDirectSoundBuffer8_iface
);
2019 static HRESULT WINAPI
DSBuffer_Unlock(IDirectSoundBuffer
*iface
, void *ptr1
, DWORD len1
, void *ptr2
, DWORD len2
)
2021 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
2022 return DS8Buffer_Unlock(&This
->IDirectSoundBuffer8_iface
, ptr1
, len1
, ptr2
, len2
);
2025 static HRESULT WINAPI
DSBuffer_Restore(IDirectSoundBuffer
*iface
)
2027 DS8Buffer
*This
= impl_from_IDirectSoundBuffer(iface
);
2028 return DS8Buffer_Restore(&This
->IDirectSoundBuffer8_iface
);
2031 static const IDirectSoundBufferVtbl DSBuffer_Vtbl
= {
2032 DSBuffer_QueryInterface
,
2036 DSBuffer_GetCurrentPosition
,
2040 DSBuffer_GetFrequency
,
2042 DSBuffer_Initialize
,
2045 DSBuffer_SetCurrentPosition
,
2049 DSBuffer_SetFrequency
,
2056 static HRESULT WINAPI
DS8Buffer3D_QueryInterface(IDirectSound3DBuffer
*iface
, REFIID riid
, void **ppv
)
2058 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2059 return IDirectSoundBuffer8_QueryInterface(&This
->IDirectSoundBuffer8_iface
, riid
, ppv
);
2062 static ULONG WINAPI
DS8Buffer3D_AddRef(IDirectSound3DBuffer
*iface
)
2064 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2067 InterlockedIncrement(&This
->all_ref
);
2068 ret
= InterlockedIncrement(&This
->ds3d_ref
);
2069 TRACE("new refcount %"LONGFMT
"d\n", ret
);
2074 static ULONG WINAPI
DS8Buffer3D_Release(IDirectSound3DBuffer
*iface
)
2076 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2079 ret
= InterlockedDecrement(&This
->ds3d_ref
);
2080 TRACE("new refcount %"LONGFMT
"d\n", ret
);
2081 if(InterlockedDecrement(&This
->all_ref
) == 0)
2082 DS8Buffer_Destroy(This
);
2087 static HRESULT WINAPI
DS8Buffer3D_GetAllParameters(IDirectSound3DBuffer
*iface
, DS3DBUFFER
*ds3dbuffer
)
2089 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2093 TRACE("%p\n", This
);
2095 if(!ds3dbuffer
|| ds3dbuffer
->dwSize
< sizeof(*ds3dbuffer
))
2097 WARN("Invalid parameters %p %"LONGFMT
"u\n", ds3dbuffer
, ds3dbuffer
? ds3dbuffer
->dwSize
: 0);
2098 return DSERR_INVALIDPARAM
;
2100 ds3dbuf
.dwSize
= sizeof(ds3dbuf
);
2102 EnterCriticalSection(This
->crst
);
2103 setALContext(This
->ctx
);
2105 hr
= IDirectSound3DBuffer_GetPosition(iface
, &ds3dbuf
.vPosition
);
2107 hr
= IDirectSound3DBuffer_GetVelocity(iface
, &ds3dbuf
.vVelocity
);
2109 hr
= IDirectSound3DBuffer_GetConeAngles(iface
, &ds3dbuf
.dwInsideConeAngle
, &ds3dbuf
.dwOutsideConeAngle
);
2111 hr
= IDirectSound3DBuffer_GetConeOrientation(iface
, &ds3dbuf
.vConeOrientation
);
2113 hr
= IDirectSound3DBuffer_GetConeOutsideVolume(iface
, &ds3dbuf
.lConeOutsideVolume
);
2115 hr
= IDirectSound3DBuffer_GetMinDistance(iface
, &ds3dbuf
.flMinDistance
);
2117 hr
= IDirectSound3DBuffer_GetMaxDistance(iface
, &ds3dbuf
.flMaxDistance
);
2119 hr
= IDirectSound3DBuffer_GetMode(iface
, &ds3dbuf
.dwMode
);
2121 memcpy(ds3dbuffer
, &ds3dbuf
, sizeof(ds3dbuf
));
2124 LeaveCriticalSection(This
->crst
);
2129 static HRESULT WINAPI
DS8Buffer3D_GetConeAngles(IDirectSound3DBuffer
*iface
, DWORD
*pdwInsideConeAngle
, DWORD
*pdwOutsideConeAngle
)
2131 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2132 ALint inangle
, outangle
;
2134 TRACE("(%p)->(%p, %p)\n", This
, pdwInsideConeAngle
, pdwOutsideConeAngle
);
2135 if(!pdwInsideConeAngle
|| !pdwOutsideConeAngle
)
2137 WARN("Invalid pointers (%p, %p)\n", pdwInsideConeAngle
, pdwOutsideConeAngle
);
2138 return DSERR_INVALIDPARAM
;
2141 EnterCriticalSection(This
->crst
);
2142 setALContext(This
->ctx
);
2144 alGetSourcei(This
->source
, AL_CONE_INNER_ANGLE
, &inangle
);
2145 alGetSourcei(This
->source
, AL_CONE_OUTER_ANGLE
, &outangle
);
2149 LeaveCriticalSection(This
->crst
);
2151 *pdwInsideConeAngle
= inangle
;
2152 *pdwOutsideConeAngle
= outangle
;
2156 static HRESULT WINAPI
DS8Buffer3D_GetConeOrientation(IDirectSound3DBuffer
*iface
, D3DVECTOR
*orient
)
2158 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2161 TRACE("(%p)->(%p)\n", This
, orient
);
2164 WARN("Invalid pointer\n");
2165 return DSERR_INVALIDPARAM
;
2168 setALContext(This
->ctx
);
2169 alGetSourcefv(This
->source
, AL_DIRECTION
, dir
);
2175 orient
->z
= -dir
[2];
2179 static HRESULT WINAPI
DS8Buffer3D_GetConeOutsideVolume(IDirectSound3DBuffer
*iface
, LONG
*vol
)
2181 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2184 TRACE("(%p)->(%p)\n", This
, vol
);
2187 WARN("Invalid pointer\n");
2188 return DSERR_INVALIDPARAM
;
2191 setALContext(This
->ctx
);
2192 alGetSourcef(This
->source
, AL_CONE_OUTER_GAIN
, &gain
);
2196 *vol
= clampI(gain_to_mB(gain
), DSBVOLUME_MIN
, DSBVOLUME_MAX
);
2200 static HRESULT WINAPI
DS8Buffer3D_GetMaxDistance(IDirectSound3DBuffer
*iface
, D3DVALUE
*maxdist
)
2202 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2205 TRACE("(%p)->(%p)\n", This
, maxdist
);
2208 WARN("Invalid pointer\n");
2209 return DSERR_INVALIDPARAM
;
2212 setALContext(This
->ctx
);
2213 alGetSourcef(This
->source
, AL_MAX_DISTANCE
, &dist
);
2221 static HRESULT WINAPI
DS8Buffer3D_GetMinDistance(IDirectSound3DBuffer
*iface
, D3DVALUE
*mindist
)
2223 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2226 TRACE("(%p)->(%p)\n", This
, mindist
);
2229 WARN("Invalid pointer\n");
2230 return DSERR_INVALIDPARAM
;
2233 setALContext(This
->ctx
);
2234 alGetSourcef(This
->source
, AL_REFERENCE_DISTANCE
, &dist
);
2242 static HRESULT WINAPI
DS8Buffer3D_GetMode(IDirectSound3DBuffer
*iface
, DWORD
*mode
)
2244 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2246 TRACE("(%p)->(%p)\n", This
, mode
);
2249 WARN("Invalid pointer\n");
2250 return DSERR_INVALIDPARAM
;
2253 EnterCriticalSection(This
->crst
);
2254 *mode
= This
->ds3dmode
;
2255 LeaveCriticalSection(This
->crst
);
2260 static HRESULT WINAPI
DS8Buffer3D_GetPosition(IDirectSound3DBuffer
*iface
, D3DVECTOR
*pos
)
2262 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2265 TRACE("(%p)->(%p)\n", This
, pos
);
2268 WARN("Invalid pointer\n");
2269 return DSERR_INVALIDPARAM
;
2272 setALContext(This
->ctx
);
2273 alGetSourcefv(This
->source
, AL_POSITION
, alpos
);
2283 static HRESULT WINAPI
DS8Buffer3D_GetVelocity(IDirectSound3DBuffer
*iface
, D3DVECTOR
*vel
)
2285 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2288 TRACE("(%p)->(%p)\n", This
, vel
);
2291 WARN("Invalid pointer\n");
2292 return DSERR_INVALIDPARAM
;
2295 setALContext(This
->ctx
);
2296 alGetSourcefv(This
->source
, AL_VELOCITY
, alvel
);
2306 static HRESULT WINAPI
DS8Buffer3D_SetAllParameters(IDirectSound3DBuffer
*iface
, const DS3DBUFFER
*ds3dbuffer
, DWORD apply
)
2308 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2309 TRACE("(%p)->(%p, %"LONGFMT
"u)\n", This
, ds3dbuffer
, apply
);
2311 if(!ds3dbuffer
|| ds3dbuffer
->dwSize
< sizeof(*ds3dbuffer
))
2313 WARN("Invalid DS3DBUFFER (%p, %"LONGFMT
"u)\n", ds3dbuffer
, ds3dbuffer
? ds3dbuffer
->dwSize
: 0);
2314 return DSERR_INVALIDPARAM
;
2317 if(ds3dbuffer
->dwInsideConeAngle
> DS3D_MAXCONEANGLE
||
2318 ds3dbuffer
->dwOutsideConeAngle
> DS3D_MAXCONEANGLE
)
2320 WARN("Invalid cone angles (%"LONGFMT
"u, %"LONGFMT
"u)\n", ds3dbuffer
->dwInsideConeAngle
,
2321 ds3dbuffer
->dwOutsideConeAngle
);
2322 return DSERR_INVALIDPARAM
;
2325 if(ds3dbuffer
->lConeOutsideVolume
> DSBVOLUME_MAX
||
2326 ds3dbuffer
->lConeOutsideVolume
< DSBVOLUME_MIN
)
2328 WARN("Invalid cone outside volume (%"LONGFMT
"d)\n", ds3dbuffer
->lConeOutsideVolume
);
2329 return DSERR_INVALIDPARAM
;
2332 if(ds3dbuffer
->flMaxDistance
< 0.0f
)
2334 WARN("Invalid max distance (%f)\n", ds3dbuffer
->flMaxDistance
);
2335 return DSERR_INVALIDPARAM
;
2338 if(ds3dbuffer
->flMinDistance
< 0.0f
)
2340 WARN("Invalid min distance (%f)\n", ds3dbuffer
->flMinDistance
);
2341 return DSERR_INVALIDPARAM
;
2344 if(ds3dbuffer
->dwMode
!= DS3DMODE_NORMAL
&&
2345 ds3dbuffer
->dwMode
!= DS3DMODE_HEADRELATIVE
&&
2346 ds3dbuffer
->dwMode
!= DS3DMODE_DISABLE
)
2348 WARN("Invalid mode (%"LONGFMT
"u)\n", ds3dbuffer
->dwMode
);
2349 return DSERR_INVALIDPARAM
;
2352 EnterCriticalSection(This
->crst
);
2353 setALContext(This
->ctx
);
2354 IDirectSound3DBuffer_SetPosition(iface
, ds3dbuffer
->vPosition
.x
, ds3dbuffer
->vPosition
.y
, ds3dbuffer
->vPosition
.z
, apply
);
2355 IDirectSound3DBuffer_SetVelocity(iface
, ds3dbuffer
->vVelocity
.x
, ds3dbuffer
->vVelocity
.y
, ds3dbuffer
->vVelocity
.z
, apply
);
2356 IDirectSound3DBuffer_SetConeAngles(iface
, ds3dbuffer
->dwInsideConeAngle
, ds3dbuffer
->dwOutsideConeAngle
, apply
);
2357 IDirectSound3DBuffer_SetConeOrientation(iface
, ds3dbuffer
->vConeOrientation
.x
, ds3dbuffer
->vConeOrientation
.y
, ds3dbuffer
->vConeOrientation
.z
, apply
);
2358 IDirectSound3DBuffer_SetConeOutsideVolume(iface
, ds3dbuffer
->lConeOutsideVolume
, apply
);
2359 IDirectSound3DBuffer_SetMinDistance(iface
, ds3dbuffer
->flMinDistance
, apply
);
2360 IDirectSound3DBuffer_SetMaxDistance(iface
, ds3dbuffer
->flMaxDistance
, apply
);
2361 IDirectSound3DBuffer_SetMode(iface
, ds3dbuffer
->dwMode
, apply
);
2363 LeaveCriticalSection(This
->crst
);
2368 static HRESULT WINAPI
DS8Buffer3D_SetConeAngles(IDirectSound3DBuffer
*iface
, DWORD dwInsideConeAngle
, DWORD dwOutsideConeAngle
, DWORD apply
)
2370 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2372 TRACE("(%p)->(%"LONGFMT
"u, %"LONGFMT
"u, %"LONGFMT
"u)\n", This
, dwInsideConeAngle
, dwOutsideConeAngle
, apply
);
2373 if(dwInsideConeAngle
> DS3D_MAXCONEANGLE
||
2374 dwOutsideConeAngle
> DS3D_MAXCONEANGLE
)
2376 WARN("Invalid cone angles (%"LONGFMT
"u, %"LONGFMT
"u)\n", dwInsideConeAngle
, dwOutsideConeAngle
);
2377 return DSERR_INVALIDPARAM
;
2380 EnterCriticalSection(This
->crst
);
2381 if(apply
== DS3D_DEFERRED
)
2383 This
->ds3dbuffer
.dwInsideConeAngle
= dwInsideConeAngle
;
2384 This
->ds3dbuffer
.dwOutsideConeAngle
= dwOutsideConeAngle
;
2385 This
->dirty
.bit
.cone_angles
= 1;
2389 setALContext(This
->ctx
);
2390 alSourcei(This
->source
, AL_CONE_INNER_ANGLE
, dwInsideConeAngle
);
2391 alSourcei(This
->source
, AL_CONE_OUTER_ANGLE
, dwOutsideConeAngle
);
2395 LeaveCriticalSection(This
->crst
);
2400 static HRESULT WINAPI
DS8Buffer3D_SetConeOrientation(IDirectSound3DBuffer
*iface
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD apply
)
2402 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2404 TRACE("(%p)->(%f, %f, %f, %"LONGFMT
"u)\n", This
, x
, y
, z
, apply
);
2406 if(apply
== DS3D_DEFERRED
)
2408 EnterCriticalSection(This
->crst
);
2409 This
->ds3dbuffer
.vConeOrientation
.x
= x
;
2410 This
->ds3dbuffer
.vConeOrientation
.y
= y
;
2411 This
->ds3dbuffer
.vConeOrientation
.z
= z
;
2412 This
->dirty
.bit
.cone_orient
= 1;
2413 LeaveCriticalSection(This
->crst
);
2417 setALContext(This
->ctx
);
2418 alSource3f(This
->source
, AL_DIRECTION
, x
, y
, -z
);
2426 static HRESULT WINAPI
DS8Buffer3D_SetConeOutsideVolume(IDirectSound3DBuffer
*iface
, LONG vol
, DWORD apply
)
2428 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2430 TRACE("(%p)->(%"LONGFMT
"d, %"LONGFMT
"u)\n", This
, vol
, apply
);
2431 if(vol
< DSBVOLUME_MIN
|| vol
> DSBVOLUME_MAX
)
2433 WARN("Invalid volume (%"LONGFMT
"d)\n", vol
);
2434 return DSERR_INVALIDPARAM
;
2437 if(apply
== DS3D_DEFERRED
)
2439 EnterCriticalSection(This
->crst
);
2440 This
->ds3dbuffer
.lConeOutsideVolume
= vol
;
2441 This
->dirty
.bit
.cone_outsidevolume
= 1;
2442 LeaveCriticalSection(This
->crst
);
2446 setALContext(This
->ctx
);
2447 alSourcef(This
->source
, AL_CONE_OUTER_GAIN
, mB_to_gain(vol
));
2455 static HRESULT WINAPI
DS8Buffer3D_SetMaxDistance(IDirectSound3DBuffer
*iface
, D3DVALUE maxdist
, DWORD apply
)
2457 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2459 TRACE("(%p)->(%f, %"LONGFMT
"u)\n", This
, maxdist
, apply
);
2462 WARN("Invalid max distance (%f)\n", maxdist
);
2463 return DSERR_INVALIDPARAM
;
2466 if(apply
== DS3D_DEFERRED
)
2468 EnterCriticalSection(This
->crst
);
2469 This
->ds3dbuffer
.flMaxDistance
= maxdist
;
2470 This
->dirty
.bit
.max_distance
= 1;
2471 LeaveCriticalSection(This
->crst
);
2475 setALContext(This
->ctx
);
2476 alSourcef(This
->source
, AL_MAX_DISTANCE
, maxdist
);
2484 static HRESULT WINAPI
DS8Buffer3D_SetMinDistance(IDirectSound3DBuffer
*iface
, D3DVALUE mindist
, DWORD apply
)
2486 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2488 TRACE("(%p)->(%f, %"LONGFMT
"u)\n", This
, mindist
, apply
);
2491 WARN("Invalid min distance (%f)\n", mindist
);
2492 return DSERR_INVALIDPARAM
;
2495 if(apply
== DS3D_DEFERRED
)
2497 EnterCriticalSection(This
->crst
);
2498 This
->ds3dbuffer
.flMinDistance
= mindist
;
2499 This
->dirty
.bit
.min_distance
= 1;
2500 LeaveCriticalSection(This
->crst
);
2504 setALContext(This
->ctx
);
2505 alSourcef(This
->source
, AL_REFERENCE_DISTANCE
, mindist
);
2513 static HRESULT WINAPI
DS8Buffer3D_SetMode(IDirectSound3DBuffer
*iface
, DWORD mode
, DWORD apply
)
2515 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2517 TRACE("(%p)->(%"LONGFMT
"u, %"LONGFMT
"u)\n", This
, mode
, apply
);
2518 if(mode
!= DS3DMODE_NORMAL
&& mode
!= DS3DMODE_HEADRELATIVE
&&
2519 mode
!= DS3DMODE_DISABLE
)
2521 WARN("Invalid mode (%"LONGFMT
"u)\n", mode
);
2522 return DSERR_INVALIDPARAM
;
2525 EnterCriticalSection(This
->crst
);
2526 if(apply
== DS3D_DEFERRED
)
2528 This
->ds3dbuffer
.dwMode
= mode
;
2529 This
->dirty
.bit
.mode
= 1;
2533 setALContext(This
->ctx
);
2534 alSourcei(This
->source
, AL_SOURCE_RELATIVE
,
2535 (mode
!= DS3DMODE_NORMAL
) ? AL_TRUE
: AL_FALSE
);
2536 alSourcef(This
->source
, AL_ROLLOFF_FACTOR
,
2537 (mode
== DS3DMODE_DISABLE
) ? 0.0f
: This
->primary
->rollofffactor
);
2538 This
->ds3dmode
= mode
;
2542 LeaveCriticalSection(This
->crst
);
2547 static HRESULT WINAPI
DS8Buffer3D_SetPosition(IDirectSound3DBuffer
*iface
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD apply
)
2549 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2551 TRACE("(%p)->(%f, %f, %f, %"LONGFMT
"u)\n", This
, x
, y
, z
, apply
);
2553 if(apply
== DS3D_DEFERRED
)
2555 EnterCriticalSection(This
->crst
);
2556 This
->ds3dbuffer
.vPosition
.x
= x
;
2557 This
->ds3dbuffer
.vPosition
.y
= y
;
2558 This
->ds3dbuffer
.vPosition
.z
= z
;
2559 This
->dirty
.bit
.pos
= 1;
2560 LeaveCriticalSection(This
->crst
);
2564 setALContext(This
->ctx
);
2565 alSource3f(This
->source
, AL_POSITION
, x
, y
, -z
);
2573 static HRESULT WINAPI
DS8Buffer3D_SetVelocity(IDirectSound3DBuffer
*iface
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD apply
)
2575 DS8Buffer
*This
= impl_from_IDirectSound3DBuffer(iface
);
2577 TRACE("(%p)->(%f, %f, %f, %"LONGFMT
"u)\n", This
, x
, y
, z
, apply
);
2579 if(apply
== DS3D_DEFERRED
)
2581 EnterCriticalSection(This
->crst
);
2582 This
->ds3dbuffer
.vVelocity
.x
= x
;
2583 This
->ds3dbuffer
.vVelocity
.y
= y
;
2584 This
->ds3dbuffer
.vVelocity
.z
= z
;
2585 This
->dirty
.bit
.vel
= 1;
2586 LeaveCriticalSection(This
->crst
);
2590 setALContext(This
->ctx
);
2591 alSource3f(This
->source
, AL_VELOCITY
, x
, y
, -z
);
2599 static const IDirectSound3DBufferVtbl DS8Buffer3d_Vtbl
=
2601 DS8Buffer3D_QueryInterface
,
2603 DS8Buffer3D_Release
,
2604 DS8Buffer3D_GetAllParameters
,
2605 DS8Buffer3D_GetConeAngles
,
2606 DS8Buffer3D_GetConeOrientation
,
2607 DS8Buffer3D_GetConeOutsideVolume
,
2608 DS8Buffer3D_GetMaxDistance
,
2609 DS8Buffer3D_GetMinDistance
,
2610 DS8Buffer3D_GetMode
,
2611 DS8Buffer3D_GetPosition
,
2612 DS8Buffer3D_GetVelocity
,
2613 DS8Buffer3D_SetAllParameters
,
2614 DS8Buffer3D_SetConeAngles
,
2615 DS8Buffer3D_SetConeOrientation
,
2616 DS8Buffer3D_SetConeOutsideVolume
,
2617 DS8Buffer3D_SetMaxDistance
,
2618 DS8Buffer3D_SetMinDistance
,
2619 DS8Buffer3D_SetMode
,
2620 DS8Buffer3D_SetPosition
,
2621 DS8Buffer3D_SetVelocity
2625 static HRESULT WINAPI
DS8BufferNot_QueryInterface(IDirectSoundNotify
*iface
, REFIID riid
, void **ppv
)
2627 DS8Buffer
*This
= impl_from_IDirectSoundNotify(iface
);
2628 return IDirectSoundBuffer8_QueryInterface(&This
->IDirectSoundBuffer8_iface
, riid
, ppv
);
2631 static ULONG WINAPI
DS8BufferNot_AddRef(IDirectSoundNotify
*iface
)
2633 DS8Buffer
*This
= impl_from_IDirectSoundNotify(iface
);
2636 InterlockedIncrement(&This
->all_ref
);
2637 ret
= InterlockedIncrement(&This
->not_ref
);
2638 TRACE("new refcount %"LONGFMT
"d\n", ret
);
2643 static ULONG WINAPI
DS8BufferNot_Release(IDirectSoundNotify
*iface
)
2645 DS8Buffer
*This
= impl_from_IDirectSoundNotify(iface
);
2648 ret
= InterlockedDecrement(&This
->not_ref
);
2649 TRACE("new refcount %"LONGFMT
"d\n", ret
);
2650 if(InterlockedDecrement(&This
->all_ref
) == 0)
2651 DS8Buffer_Destroy(This
);
2656 static HRESULT WINAPI
DS8BufferNot_SetNotificationPositions(IDirectSoundNotify
*iface
, DWORD count
, const DSBPOSITIONNOTIFY
*notifications
)
2658 DS8Buffer
*This
= impl_from_IDirectSoundNotify(iface
);
2659 DSBPOSITIONNOTIFY
*nots
;
2663 EnterCriticalSection(This
->crst
);
2664 hr
= DSERR_INVALIDPARAM
;
2665 if(count
&& !notifications
)
2668 hr
= IDirectSoundBuffer8_GetStatus(&This
->IDirectSoundBuffer8_iface
, &state
);
2672 hr
= DSERR_INVALIDCALL
;
2673 if((state
&DSBSTATUS_PLAYING
))
2678 HeapFree(GetProcessHeap(), 0, This
->notify
);
2687 hr
= DSERR_INVALIDPARAM
;
2688 for(i
= 0;i
< count
;++i
)
2690 if(notifications
[i
].dwOffset
>= This
->buffer
->buf_size
&&
2691 notifications
[i
].dwOffset
!= (DWORD
)DSBPN_OFFSETSTOP
)
2696 nots
= HeapAlloc(GetProcessHeap(), 0, count
*sizeof(*nots
));
2699 memcpy(nots
, notifications
, count
*sizeof(*nots
));
2701 HeapFree(GetProcessHeap(), 0, This
->notify
);
2702 This
->notify
= nots
;
2703 This
->nnotify
= count
;
2709 LeaveCriticalSection(This
->crst
);
2713 static const IDirectSoundNotifyVtbl DS8BufferNot_Vtbl
=
2715 DS8BufferNot_QueryInterface
,
2716 DS8BufferNot_AddRef
,
2717 DS8BufferNot_Release
,
2718 DS8BufferNot_SetNotificationPositions
2722 static HRESULT WINAPI
DS8BufferProp_QueryInterface(IKsPropertySet
*iface
, REFIID riid
, void **ppv
)
2724 DS8Buffer
*This
= impl_from_IKsPropertySet(iface
);
2725 return IDirectSoundBuffer8_QueryInterface(&This
->IDirectSoundBuffer8_iface
, riid
, ppv
);
2728 static ULONG WINAPI
DS8BufferProp_AddRef(IKsPropertySet
*iface
)
2730 DS8Buffer
*This
= impl_from_IKsPropertySet(iface
);
2733 InterlockedIncrement(&This
->all_ref
);
2734 ret
= InterlockedIncrement(&This
->prop_ref
);
2735 TRACE("new refcount %"LONGFMT
"d\n", ret
);
2740 static ULONG WINAPI
DS8BufferProp_Release(IKsPropertySet
*iface
)
2742 DS8Buffer
*This
= impl_from_IKsPropertySet(iface
);
2745 ret
= InterlockedDecrement(&This
->prop_ref
);
2746 TRACE("new refcount %"LONGFMT
"d\n", ret
);
2747 if(InterlockedDecrement(&This
->all_ref
) == 0)
2748 DS8Buffer_Destroy(This
);
2753 /* NOTE: Due to some apparent quirks in DSound, the listener properties are
2754 handled through secondary buffers. */
2755 static HRESULT WINAPI
DS8BufferProp_Get(IKsPropertySet
*iface
,
2756 REFGUID guidPropSet
, ULONG dwPropID
,
2757 LPVOID pInstanceData
, ULONG cbInstanceData
,
2758 LPVOID pPropData
, ULONG cbPropData
,
2761 DS8Buffer
*This
= impl_from_IKsPropertySet(iface
);
2762 HRESULT hr
= E_PROP_ID_UNSUPPORTED
;
2764 TRACE("(%p)->(%s, %"LONGFMT
"u, %p, %"LONGFMT
"u, %p, %"LONGFMT
"u, %p)\n", iface
, debugstr_guid(guidPropSet
),
2765 dwPropID
, pInstanceData
, cbInstanceData
, pPropData
, cbPropData
, pcbReturned
);
2772 if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX20_BufferProperties
))
2778 /* Not a known buffer/source property. Pass it to the listener */
2779 hr
= IKsPropertySet_Get(&This
->primary
->IKsPropertySet_iface
, guidPropSet
,
2780 dwPropID
, pInstanceData
, cbInstanceData
, pPropData
, cbPropData
,
2787 static HRESULT WINAPI
DS8BufferProp_Set(IKsPropertySet
*iface
,
2788 REFGUID guidPropSet
, ULONG dwPropID
,
2789 LPVOID pInstanceData
, ULONG cbInstanceData
,
2790 LPVOID pPropData
, ULONG cbPropData
)
2792 DS8Buffer
*This
= impl_from_IKsPropertySet(iface
);
2793 HRESULT hr
= E_PROP_ID_UNSUPPORTED
;
2795 TRACE("(%p)->(%s, %"LONGFMT
"u, %p, %"LONGFMT
"u, %p, %"LONGFMT
"u)\n", iface
, debugstr_guid(guidPropSet
),
2796 dwPropID
, pInstanceData
, cbInstanceData
, pPropData
, cbPropData
);
2799 if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX20_BufferProperties
))
2805 /* Not a known buffer/source property. Pass it to the listener */
2806 hr
= IKsPropertySet_Set(&This
->primary
->IKsPropertySet_iface
, guidPropSet
,
2807 dwPropID
, pInstanceData
, cbInstanceData
, pPropData
,
2814 static HRESULT WINAPI
DS8BufferProp_QuerySupport(IKsPropertySet
*iface
,
2815 REFGUID guidPropSet
, ULONG dwPropID
,
2816 PULONG pTypeSupport
)
2818 DS8Buffer
*This
= impl_from_IKsPropertySet(iface
);
2819 HRESULT hr
= E_PROP_ID_UNSUPPORTED
;
2821 TRACE("(%p)->(%s, %"LONGFMT
"u, %p)\n", iface
, debugstr_guid(guidPropSet
), dwPropID
, pTypeSupport
);
2828 if(IsEqualIID(guidPropSet
, &DSPROPSETID_EAX20_BufferProperties
))
2834 /* Not a known buffer/source property. Pass it to the listener */
2835 hr
= IKsPropertySet_QuerySupport(&This
->primary
->IKsPropertySet_iface
,
2836 guidPropSet
, dwPropID
, pTypeSupport
);
2842 static const IKsPropertySetVtbl DS8BufferProp_Vtbl
=
2844 DS8BufferProp_QueryInterface
,
2845 DS8BufferProp_AddRef
,
2846 DS8BufferProp_Release
,
2849 DS8BufferProp_QuerySupport