source: trunk/src/dsound/OS23DBuffer.cpp@ 3099

Last change on this file since 3099 was 3099, checked in by sandervl, 25 years ago

replaced dsound by new version

File size: 15.7 KB
Line 
1/*
2 * DirectSound OS2IDirectSound3DBuffer class
3 *
4 * Copyright 2000 Michal Necasek
5 *
6 * Project Odin Software License can be found in LICENSE.TXT
7 *
8 */
9
10
11/*@Header***********************************************************************
12* Header Files *
13*******************************************************************************/
14#define INCL_DOSMISC
15#include <os2win.h>
16
17#include <stdlib.h>
18#include <string.h>
19
20#define INITGUID
21#include <dsound.h>
22
23#include "OS2DSound.h"
24#include "OS2SndBuffer.h"
25#include "OS2PrimBuff.h"
26#include "OS23DBuffer.h"
27#include <misc.h>
28
29// Note: the DSound headers are inconsistent; some require THIS to be VOID*, some
30// require it to be a pointer to the appropriate interface.
31
32#undef THIS
33#define THIS IDirectSound3DBuffer*This
34
35#undef THIS_
36#define THIS_ IDirectSound3DBuffer*This,
37
38//******************************************************************************
39//******************************************************************************
40OS2IDirectSound3DBuffer::OS2IDirectSound3DBuffer(OS2IDirectSoundBuffer *parentBuffer)
41{
42 lpVtbl = &Vtbl;
43 Vtbl.AddRef = Sound3DBufferAddRef;
44 Vtbl.Release = Sound3DBufferRelease;
45 Vtbl.QueryInterface = Sound3DBufferQueryInterface;
46 Vtbl.GetAllParameters = Sound3DBufferGetAllParameters;
47 Vtbl.SetAllParameters = Sound3DBufferSetAllParameters;
48 Vtbl.GetMaxDistance = Sound3DBufferGetMaxDistance;
49 Vtbl.SetMaxDistance = Sound3DBufferSetMaxDistance;
50 Vtbl.GetMinDistance = Sound3DBufferGetMinDistance;
51 Vtbl.SetMinDistance = Sound3DBufferSetMinDistance;
52 Vtbl.GetMode = Sound3DBufferGetMode;
53 Vtbl.SetMode = Sound3DBufferSetMode;
54 Vtbl.GetPosition = Sound3DBufferGetPosition;
55 Vtbl.SetPosition = Sound3DBufferSetPosition;
56 Vtbl.GetConeAngles = Sound3DBufferGetConeAngles;
57 Vtbl.SetConeAngles = Sound3DBufferSetConeAngles;
58 Vtbl.GetConeOrientation = Sound3DBufferGetConeOrientation;
59 Vtbl.SetConeOrientation = Sound3DBufferSetConeOrientation;
60 Vtbl.GetConeOutsideVolume = Sound3DBufferGetConeOutsideVolume;
61 Vtbl.SetConeOutsideVolume = Sound3DBufferSetConeOutsideVolume;
62 Vtbl.GetVelocity = Sound3DBufferGetVelocity;
63 Vtbl.SetVelocity = Sound3DBufferSetVelocity;
64
65
66 dprintf(("DSOUND-OS2IDirectSound3DBuffer::OS2IDirectSound3DBuffer (this=%X)", this));
67
68 lpSoundBuffer = parentBuffer;
69 Referenced = 0;
70
71 memset(&data3D, 0, sizeof(DS3DBUFFER));
72 data3D.dwSize = sizeof(DS3DBUFFER);
73
74 // add a reference to the parent primary SoundBuffer to make sure it won't suddenly disappear
75 lpSoundBuffer->Vtbl.AddRef(lpSoundBuffer);
76 // set pointer to ourselves in parent SoundBuffer
77 lpSoundBuffer->Set3DBuffer(this);
78}
79
80//******************************************************************************
81//******************************************************************************
82OS2IDirectSound3DBuffer::~OS2IDirectSound3DBuffer()
83{
84 dprintf(("DSOUND-OS2IDirectSound3DBuffer::~OS2IDirectSound3DBuffer (this=%X)", this));
85 lpSoundBuffer->Set3DBuffer(NULL);
86 lpSoundBuffer->Vtbl.Release(lpSoundBuffer);
87}
88
89//******************************************************************************
90//******************************************************************************
91HRESULT __stdcall Sound3DBufferQueryInterface(THIS, REFIID riid, LPVOID * ppvObj)
92{
93 dprintf(("DSOUND-OS2IDirectSound3DBuffer::QueryInterface"));
94 if (This == NULL) {
95 return DSERR_INVALIDPARAM;
96 }
97 *ppvObj = NULL;
98
99 if (!IsEqualGUID(riid, IID_IDirectSound3DBuffer))
100 return E_NOINTERFACE;
101
102 *ppvObj = This;
103
104 Sound3DBufferAddRef(This);
105 return DS_OK;
106}
107
108//******************************************************************************
109//******************************************************************************
110ULONG __stdcall Sound3DBufferAddRef(THIS)
111{
112 OS2IDirectSound3DBuffer *me = (OS2IDirectSound3DBuffer *)This;
113
114 dprintf(("DSOUND-OS2IDirectSound3DBuffer::AddRef (this=%X) %d", me, me->Referenced+1));
115 if (me == NULL) {
116 return 0;
117 }
118 return ++me->Referenced;
119}
120
121//******************************************************************************
122//******************************************************************************
123ULONG __stdcall Sound3DBufferRelease(THIS)
124{
125 OS2IDirectSound3DBuffer *me = (OS2IDirectSound3DBuffer *)This;
126
127 dprintf(("DSOUND-OS2IDirectSound3DBuffer::Release (this=%X) %d", me, me->Referenced-1));
128 if (me == NULL) {
129 return 0;
130 }
131 if (me->Referenced) {
132 me->Referenced--;
133 if (me->Referenced == 0) {
134 delete me;
135 return DS_OK;
136 }
137 else
138 return me->Referenced;
139 }
140 else
141 return DS_OK;
142}
143
144//******************************************************************************
145//******************************************************************************
146void RecalcNow(OS2IDirectSound3DBuffer *me)
147{
148 dprintf(("DSOUND-3DBuffer: RecalcNow (this=%X)", me));
149
150 // helper function - recalculate all 3D parameters
151}
152
153//******************************************************************************
154//******************************************************************************
155HRESULT __stdcall Sound3DBufferGetAllParameters(THIS, LPDS3DBUFFER lpDs3dBuffer)
156{
157 OS2IDirectSound3DBuffer *me = (OS2IDirectSound3DBuffer *)This;
158
159 dprintf(("DSOUND-OS2IDirectSound3DBuffer::Sound3DBufferGetAllParameters (this=%X)", me));
160 if (me == NULL || lpDs3dBuffer == NULL) {
161 return DSERR_INVALIDPARAM;
162 }
163
164 *lpDs3dBuffer = me->data3D;
165
166 return DS_OK;
167}
168
169//******************************************************************************
170//******************************************************************************
171HRESULT __stdcall Sound3DBufferSetAllParameters(THIS, LPCDS3DBUFFER lpcDs3dBuffer, DWORD dwApply)
172{
173 OS2IDirectSound3DBuffer *me = (OS2IDirectSound3DBuffer *)This;
174
175 dprintf(("DSOUND-OS2IDirectSound3DBuffer::Sound3DBufferSetAllParameters (this=%X)", me));
176 if (me == NULL || lpcDs3dBuffer == NULL) {
177 return DSERR_INVALIDPARAM;
178 }
179
180 me->data3D = *lpcDs3dBuffer;
181
182 if (dwApply == DS3D_IMMEDIATE) {
183 RecalcNow(me);
184 }
185
186 return DS_OK;
187}
188
189//******************************************************************************
190//******************************************************************************
191HRESULT __stdcall Sound3DBufferGetMaxDistance(THIS, LPD3DVALUE lpflMaxDistance)
192{
193 OS2IDirectSound3DBuffer *me = (OS2IDirectSound3DBuffer *)This;
194
195 dprintf(("DSOUND-OS2IDirectSound3DBuffer::Sound3DBufferGetMaxDistance (this=%X)", me));
196 if (me == NULL || lpflMaxDistance == NULL) {
197 return DSERR_INVALIDPARAM;
198 }
199
200 *lpflMaxDistance = me->data3D.flMaxDistance;
201
202 return DS_OK;
203}
204
205//******************************************************************************
206//******************************************************************************
207HRESULT __stdcall Sound3DBufferSetMaxDistance(THIS, D3DVALUE flMaxDistance, DWORD dwApply)
208{
209 OS2IDirectSound3DBuffer *me = (OS2IDirectSound3DBuffer *)This;
210
211 dprintf(("DSOUND-OS2IDirectSound3DBuffer::Sound3DBufferSetMaxDistance (this=%X)", me));
212 if (me == NULL) {
213 return DSERR_INVALIDPARAM;
214 }
215
216 me->data3D.flMaxDistance = flMaxDistance;
217
218 if (dwApply == DS3D_IMMEDIATE) {
219 RecalcNow(me);
220 }
221
222 return DS_OK;
223}
224
225//******************************************************************************
226//******************************************************************************
227HRESULT __stdcall Sound3DBufferGetMinDistance(THIS, LPD3DVALUE lpflMinDistance)
228{
229 OS2IDirectSound3DBuffer *me = (OS2IDirectSound3DBuffer *)This;
230
231 dprintf(("DSOUND-OS2IDirectSound3DBuffer::Sound3DBufferGetMinDistance (this=%X)", me));
232 if (me == NULL || lpflMinDistance == NULL) {
233 return DSERR_INVALIDPARAM;
234 }
235
236 *lpflMinDistance = me->data3D.flMinDistance;
237
238 return DS_OK;
239}
240
241//******************************************************************************
242//******************************************************************************
243HRESULT __stdcall Sound3DBufferSetMinDistance(THIS, D3DVALUE flMinDistance, DWORD dwApply)
244{
245 OS2IDirectSound3DBuffer *me = (OS2IDirectSound3DBuffer *)This;
246
247 dprintf(("DSOUND-OS2IDirectSound3DBuffer::Sound3DBufferSetMinDistance (this=%X)", me));
248 if (me == NULL) {
249 return DSERR_INVALIDPARAM;
250 }
251
252 me->data3D.flMinDistance = flMinDistance;
253
254 if (dwApply == DS3D_IMMEDIATE) {
255 RecalcNow(me);
256 }
257
258 return DS_OK;
259}
260
261//******************************************************************************
262//******************************************************************************
263HRESULT __stdcall Sound3DBufferGetMode(THIS, LPDWORD lpdwMode)
264{
265 OS2IDirectSound3DBuffer *me = (OS2IDirectSound3DBuffer *)This;
266
267 dprintf(("DSOUND-OS2IDirectSound3DBuffer::Sound3DBufferGetMode (this=%X)", me));
268 if (me == NULL || lpdwMode == NULL) {
269 return DSERR_INVALIDPARAM;
270 }
271
272 *lpdwMode = me->data3D.dwMode;
273
274 return DS_OK;
275}
276
277//******************************************************************************
278//******************************************************************************
279HRESULT __stdcall Sound3DBufferSetMode(THIS, DWORD dwMode, DWORD dwApply)
280{
281 OS2IDirectSound3DBuffer *me = (OS2IDirectSound3DBuffer *)This;
282
283 dprintf(("DSOUND-OS2IDirectSound3DBuffer::Sound3DBufferSetMode (this=%X)", me));
284 if (me == NULL) {
285 return DSERR_INVALIDPARAM;
286 }
287
288 me->data3D.dwMode = dwMode;
289
290 if (dwApply == DS3D_IMMEDIATE) {
291 RecalcNow(me);
292 }
293
294 return DS_OK;
295}
296
297//******************************************************************************
298//******************************************************************************
299HRESULT __stdcall Sound3DBufferGetPosition(THIS, LPD3DVECTOR lpvPosition)
300{
301 OS2IDirectSound3DBuffer *me = (OS2IDirectSound3DBuffer *)This;
302
303 dprintf(("DSOUND-OS2IDirectSound3DBuffer::Sound3DBufferGetPosition (this=%X)", me));
304 if (me == NULL || lpvPosition == NULL) {
305 return DSERR_INVALIDPARAM;
306 }
307
308 *lpvPosition = me->data3D.vPosition;
309
310 return DS_OK;
311}
312
313//******************************************************************************
314//******************************************************************************
315HRESULT __stdcall Sound3DBufferSetPosition(THIS, D3DVALUE x, D3DVALUE y, D3DVALUE z, DWORD dwApply)
316{
317 OS2IDirectSound3DBuffer *me = (OS2IDirectSound3DBuffer *)This;
318
319 dprintf(("DSOUND-OS2IDirectSound3DBuffer::Sound3DBufferSetPosition (this=%X)", me));
320 if (me == NULL) {
321 return DSERR_INVALIDPARAM;
322 }
323
324 me->data3D.vPosition.x.x = x;
325 me->data3D.vPosition.y.y = y;
326 me->data3D.vPosition.z.z = z;
327
328 if (dwApply == DS3D_IMMEDIATE) {
329 RecalcNow(me);
330 }
331
332 return DS_OK;
333}
334
335//******************************************************************************
336//******************************************************************************
337HRESULT __stdcall Sound3DBufferGetVelocity(THIS, LPD3DVECTOR lpvVelocity)
338{
339 OS2IDirectSound3DBuffer *me = (OS2IDirectSound3DBuffer *)This;
340
341 dprintf(("DSOUND-OS2IDirectSound3DBuffer::Sound3DBufferGetVelocity (this=%X)", me));
342 if (me == NULL || lpvVelocity == NULL) {
343 return DSERR_INVALIDPARAM;
344 }
345
346 *lpvVelocity = me->data3D.vVelocity;
347
348 return DS_OK;
349}
350
351//******************************************************************************
352//******************************************************************************
353HRESULT __stdcall Sound3DBufferSetVelocity(THIS, D3DVALUE x, D3DVALUE y, D3DVALUE z, DWORD dwApply)
354{
355 OS2IDirectSound3DBuffer *me = (OS2IDirectSound3DBuffer *)This;
356
357 dprintf(("DSOUND-OS2IDirectSound3DBuffer::Sound3DBufferSetVelocity (this=%X)", me));
358 if (me == NULL) {
359 return DSERR_INVALIDPARAM;
360 }
361
362 me->data3D.vVelocity.x.x = x;
363 me->data3D.vVelocity.y.y = y;
364 me->data3D.vVelocity.z.z = z;
365
366 if (dwApply == DS3D_IMMEDIATE) {
367 RecalcNow(me);
368 }
369
370 return DS_OK;
371}
372
373//******************************************************************************
374//******************************************************************************
375HRESULT __stdcall Sound3DBufferGetConeOrientation(THIS, LPD3DVECTOR lpvConeOrientation)
376{
377 OS2IDirectSound3DBuffer *me = (OS2IDirectSound3DBuffer *)This;
378
379 dprintf(("DSOUND-OS2IDirectSound3DBuffer::Sound3DBufferGetConeOrientation (this=%X)", me));
380 if (me == NULL || lpvConeOrientation == NULL) {
381 return DSERR_INVALIDPARAM;
382 }
383
384 *lpvConeOrientation = me->data3D.vConeOrientation;
385
386 return DS_OK;
387}
388
389//******************************************************************************
390//******************************************************************************
391HRESULT __stdcall Sound3DBufferSetConeOrientation(THIS, D3DVALUE x, D3DVALUE y, D3DVALUE z, DWORD dwApply)
392{
393 OS2IDirectSound3DBuffer *me = (OS2IDirectSound3DBuffer *)This;
394
395 dprintf(("DSOUND-OS2IDirectSound3DBuffer::Sound3DBufferSetConeOrientation (this=%X)", me));
396 if (me == NULL) {
397 return DSERR_INVALIDPARAM;
398 }
399
400 me->data3D.vConeOrientation.x.x = x;
401 me->data3D.vConeOrientation.y.y = y;
402 me->data3D.vConeOrientation.z.z = z;
403
404 if (dwApply == DS3D_IMMEDIATE) {
405 RecalcNow(me);
406 }
407
408 return DS_OK;
409}
410
411//******************************************************************************
412//******************************************************************************
413HRESULT __stdcall Sound3DBufferGetConeAngles(THIS, LPDWORD lpdwInsideConeAngle, LPDWORD lpdwOutsideConeAngle)
414{
415 OS2IDirectSound3DBuffer *me = (OS2IDirectSound3DBuffer *)This;
416
417 dprintf(("DSOUND-OS2IDirectSound3DBuffer::Sound3DBufferGetConeOrientation (this=%X)", me));
418 if (me == NULL || lpdwInsideConeAngle == NULL || lpdwOutsideConeAngle == NULL) {
419 return DSERR_INVALIDPARAM;
420 }
421
422 *lpdwInsideConeAngle = me->data3D.dwInsideConeAngle;
423 *lpdwOutsideConeAngle = me->data3D.dwOutsideConeAngle;
424
425 return DS_OK;
426}
427
428//******************************************************************************
429//******************************************************************************
430HRESULT __stdcall Sound3DBufferSetConeAngles(THIS, DWORD dwInsideConeAngle, DWORD dwOutsideConeAngle, DWORD dwApply)
431{
432 OS2IDirectSound3DBuffer *me = (OS2IDirectSound3DBuffer *)This;
433
434 dprintf(("DSOUND-OS2IDirectSound3DBuffer::Sound3DBufferSetConeOrientation (this=%X)", me));
435 if (me == NULL) {
436 return DSERR_INVALIDPARAM;
437 }
438
439 me->data3D.dwInsideConeAngle = dwInsideConeAngle;
440 me->data3D.dwOutsideConeAngle = dwOutsideConeAngle;
441
442 if (dwApply == DS3D_IMMEDIATE) {
443 RecalcNow(me);
444 }
445
446 return DS_OK;
447}
448
449//******************************************************************************
450//******************************************************************************
451HRESULT __stdcall Sound3DBufferGetConeOutsideVolume(THIS, LPLONG lplConeOutsideVolume)
452{
453 OS2IDirectSound3DBuffer *me = (OS2IDirectSound3DBuffer *)This;
454
455 dprintf(("DSOUND-OS2IDirectSound3DBuffer::Sound3DBufferGetConeOrientation (this=%X)", me));
456 if (me == NULL || lplConeOutsideVolume == NULL) {
457 return DSERR_INVALIDPARAM;
458 }
459
460 *lplConeOutsideVolume = me->data3D.lConeOutsideVolume;
461
462 return DS_OK;
463}
464
465//******************************************************************************
466//******************************************************************************
467HRESULT __stdcall Sound3DBufferSetConeOutsideVolume(THIS, LONG lConeOutsideVolume, DWORD dwApply)
468{
469 OS2IDirectSound3DBuffer *me = (OS2IDirectSound3DBuffer *)This;
470
471 dprintf(("DSOUND-OS2IDirectSound3DBuffer::Sound3DBufferSetConeOrientation (this=%X)", me));
472 if (me == NULL) {
473 return DSERR_INVALIDPARAM;
474 }
475
476 me->data3D.lConeOutsideVolume = lConeOutsideVolume;
477
478 if (dwApply == DS3D_IMMEDIATE) {
479 RecalcNow(me);
480 }
481
482 return DS_OK;
483}
484
Note: See TracBrowser for help on using the repository browser.