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

Last change on this file since 3925 was 3925, checked in by bird, 25 years ago

Added the CVS keyword Id.

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