1 | /* $Id: OS2DSOUND.CPP,v 1.1 2000-03-06 13:11:38 mike Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * DirectSound main class
|
---|
5 | *
|
---|
6 | * Copyright 1998 Sander van Leeuwen
|
---|
7 | * Copyright 2000 Michal Necasek
|
---|
8 | *
|
---|
9 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
10 | *
|
---|
11 | */
|
---|
12 |
|
---|
13 | /*@Header***********************************************************************
|
---|
14 | * Header Files *
|
---|
15 | *******************************************************************************/
|
---|
16 | #include <os2win.h>
|
---|
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 "os2notify.h"
|
---|
27 | #include <misc.h>
|
---|
28 |
|
---|
29 | // TODO: primary buffer should probably created right away when creating the DSound
|
---|
30 | // object
|
---|
31 | // TODO: handle cooperative levels properly!!
|
---|
32 |
|
---|
33 | // this flag is set if the OS2IDirectObject exists
|
---|
34 | BOOL OS2IDirectSound::fDSExists = FALSE;
|
---|
35 |
|
---|
36 | //******************************************************************************
|
---|
37 | //******************************************************************************
|
---|
38 | OS2IDirectSound::OS2IDirectSound(const GUID *lpGUID) : Referenced(0),
|
---|
39 | lastError(DS_OK), hwndClient(0)
|
---|
40 | {
|
---|
41 | lpVtbl = &Vtbl;
|
---|
42 | Vtbl.AddRef = SoundAddRef;
|
---|
43 | Vtbl.Release = SoundRelease;
|
---|
44 | Vtbl.QueryInterface = SoundQueryInterface;
|
---|
45 | Vtbl.Compact = SoundCompact;
|
---|
46 | Vtbl.CreateSoundBuffer = SoundCreateSoundBuffer;
|
---|
47 | Vtbl.GetCaps = SoundGetCaps;
|
---|
48 | Vtbl.DuplicateSoundBuffer = SoundDuplicateSoundBuffer;
|
---|
49 | Vtbl.SetCooperativeLevel = SoundSetCooperativeLevel;
|
---|
50 | Vtbl.Compact = SoundCompact;
|
---|
51 | Vtbl.GetSpeakerConfig = SoundGetSpeakerConfig;
|
---|
52 | Vtbl.SetSpeakerConfig = SoundSetSpeakerConfig;
|
---|
53 | Vtbl.Initialize = SoundInitialize;
|
---|
54 |
|
---|
55 | dprintf(("DSOUND-OS2IDirectSound::OS2IDirectSound\n"));
|
---|
56 |
|
---|
57 | speakerConfig = DSSPEAKER_STEREO;
|
---|
58 | CoopLevel = DSSCL_EXCLUSIVE; //default
|
---|
59 |
|
---|
60 | OS2IDirectSound::fDSExists = TRUE;
|
---|
61 |
|
---|
62 | dprintf(("Sound init OK\n"));
|
---|
63 | }
|
---|
64 | //******************************************************************************
|
---|
65 | //******************************************************************************
|
---|
66 | OS2IDirectSound::~OS2IDirectSound()
|
---|
67 | {
|
---|
68 | // TODO: Close all SoundBuffers here
|
---|
69 | OS2IDirectSoundBuffer::DestroyAllBuffers();
|
---|
70 | OS2IDirectSound::fDSExists = FALSE;
|
---|
71 | }
|
---|
72 | //******************************************************************************
|
---|
73 | //******************************************************************************
|
---|
74 | HRESULT WIN32API SoundQueryInterface(THIS, REFIID riid, LPVOID * ppvObj)
|
---|
75 | {
|
---|
76 | dprintf(("DSOUND-OS2IDirectSound::QueryInterface\n"));
|
---|
77 | if (This == NULL) {
|
---|
78 | return DSERR_INVALIDPARAM;
|
---|
79 | }
|
---|
80 | *ppvObj = NULL;
|
---|
81 |
|
---|
82 | if (!IsEqualGUID(riid, CLSID_DirectSound) &&
|
---|
83 | !IsEqualGUID(riid, IID_IDirectSound))
|
---|
84 | return E_NOINTERFACE;
|
---|
85 |
|
---|
86 | *ppvObj = This;
|
---|
87 |
|
---|
88 | SoundAddRef(This);
|
---|
89 | return DS_OK;
|
---|
90 | }
|
---|
91 |
|
---|
92 | //******************************************************************************
|
---|
93 | //******************************************************************************
|
---|
94 | ULONG WIN32API SoundAddRef(THIS)
|
---|
95 | {
|
---|
96 | OS2IDirectSound *me = (OS2IDirectSound *)This;
|
---|
97 |
|
---|
98 | dprintf(("DSOUND-OS2IDirectSound::AddRef %d\n", me->Referenced+1));
|
---|
99 | return ++me->Referenced;
|
---|
100 | }
|
---|
101 |
|
---|
102 | //******************************************************************************
|
---|
103 | //******************************************************************************
|
---|
104 | ULONG WIN32API SoundRelease(THIS)
|
---|
105 | {
|
---|
106 | OS2IDirectSound *me = (OS2IDirectSound *)This;
|
---|
107 |
|
---|
108 | dprintf(("DSOUND-OS2IDirectSound::Release %d\n", me->Referenced-1));
|
---|
109 | if (me->Referenced) {
|
---|
110 | me->Referenced--;
|
---|
111 | if (me->Referenced == 0) {
|
---|
112 | delete me;
|
---|
113 | return 0;
|
---|
114 | }
|
---|
115 | else
|
---|
116 | return me->Referenced;
|
---|
117 | }
|
---|
118 | else
|
---|
119 | return 0;
|
---|
120 | }
|
---|
121 |
|
---|
122 | //******************************************************************************
|
---|
123 | //******************************************************************************
|
---|
124 | HRESULT WIN32API SoundCompact(THIS)
|
---|
125 | {
|
---|
126 | dprintf(("DSOUND-OS2IDirectSound::Compact\n"));
|
---|
127 | return DS_OK;
|
---|
128 | }
|
---|
129 |
|
---|
130 | //******************************************************************************
|
---|
131 | //******************************************************************************
|
---|
132 | HRESULT WIN32API SoundCreateSoundBuffer(THIS_
|
---|
133 | LPDSBUFFERDESC lpDSBufferDesc, //new, const
|
---|
134 | LPDIRECTSOUNDBUFFER *lplpDirectSoundBuffer,
|
---|
135 | LPUNKNOWN pUnkOuter)
|
---|
136 | {
|
---|
137 | OS2IDirectSound *me = (OS2IDirectSound *)This;
|
---|
138 | OS2IDirectSoundBuffer *sndbuf;
|
---|
139 |
|
---|
140 | dprintf(("DSOUND-OS2IDirectSound::CreateSoundBuffer\n"));
|
---|
141 | if (me == NULL || lpDSBufferDesc == NULL || lplpDirectSoundBuffer == NULL) {
|
---|
142 | return DSERR_INVALIDPARAM;
|
---|
143 | }
|
---|
144 |
|
---|
145 | if ((lpDSBufferDesc->dwFlags & DSBCAPS_PRIMARYBUFFER) && (lpDSBufferDesc->lpwfxFormat != NULL)) {
|
---|
146 | // Primary buffers must be created without format info!
|
---|
147 | return DSERR_INVALIDPARAM;
|
---|
148 | }
|
---|
149 |
|
---|
150 | if (lpDSBufferDesc->dwFlags & DSBCAPS_PRIMARYBUFFER) {
|
---|
151 | OS2PrimBuff *primbuff;
|
---|
152 | primbuff = new OS2PrimBuff(me, lpDSBufferDesc);
|
---|
153 |
|
---|
154 | if (primbuff == NULL)
|
---|
155 | return DSERR_OUTOFMEMORY;
|
---|
156 |
|
---|
157 | if ( primbuff->GetLastError() != DS_OK ){
|
---|
158 | ULONG lastErr = primbuff->GetLastError();
|
---|
159 |
|
---|
160 | dprintf(("LastErr = %d\n", lastErr));
|
---|
161 | delete primbuff;
|
---|
162 | return lastErr;
|
---|
163 | }
|
---|
164 | *lplpDirectSoundBuffer = (LPDIRECTSOUNDBUFFER)primbuff;
|
---|
165 | primbuff->Vtbl.AddRef(primbuff);
|
---|
166 | dprintf(("Created PrimBuff... Exiting Create Buffer function\n"));
|
---|
167 |
|
---|
168 | return DS_OK;
|
---|
169 | }
|
---|
170 |
|
---|
171 | sndbuf = new OS2IDirectSoundBuffer(me, lpDSBufferDesc);
|
---|
172 | if (sndbuf == NULL) {
|
---|
173 | return DSERR_OUTOFMEMORY;
|
---|
174 | }
|
---|
175 | if(sndbuf->GetLastError() != DS_OK) {
|
---|
176 | ULONG lastErr = sndbuf->GetLastError();
|
---|
177 | delete sndbuf;
|
---|
178 | return lastErr;
|
---|
179 | }
|
---|
180 | sndbuf->Vtbl.AddRef(sndbuf);
|
---|
181 |
|
---|
182 | *lplpDirectSoundBuffer = (LPDIRECTSOUNDBUFFER)sndbuf;
|
---|
183 |
|
---|
184 | return DS_OK;
|
---|
185 | }
|
---|
186 |
|
---|
187 | //******************************************************************************
|
---|
188 | //******************************************************************************
|
---|
189 | HRESULT WIN32API SoundGetCaps(THIS_ LPDSCAPS lpCaps)
|
---|
190 | {
|
---|
191 | dprintf(("DSOUND-OS2IDirectSound::GetCaps\n"));
|
---|
192 |
|
---|
193 | if (lpCaps == NULL)
|
---|
194 | return DSERR_INVALIDPARAM;
|
---|
195 |
|
---|
196 | lpCaps->dwSize = sizeof(DSCAPS);
|
---|
197 | lpCaps->dwFlags = DSCAPS_SECONDARY8BIT | DSCAPS_SECONDARY16BIT |
|
---|
198 | DSCAPS_SECONDARYMONO | DSCAPS_SECONDARYSTEREO |
|
---|
199 | DSCAPS_PRIMARY8BIT | DSCAPS_PRIMARY16BIT |
|
---|
200 | /* DSCAPS_PRIMARYMONO |*/ DSCAPS_PRIMARYSTEREO;
|
---|
201 | lpCaps->dwMinSecondarySampleRate = 100;
|
---|
202 | lpCaps->dwMaxSecondarySampleRate = 100000;
|
---|
203 | lpCaps->dwPrimaryBuffers = 1;
|
---|
204 | lpCaps->dwMaxHwMixingAllBuffers = 0; // no HW support, no HW buffers...
|
---|
205 | lpCaps->dwMaxHwMixingStaticBuffers = 0;
|
---|
206 | lpCaps->dwMaxHwMixingStreamingBuffers = 0;
|
---|
207 | lpCaps->dwFreeHwMixingAllBuffers = 0;
|
---|
208 | lpCaps->dwFreeHwMixingStaticBuffers = 0;
|
---|
209 | lpCaps->dwFreeHwMixingStreamingBuffers = 0;
|
---|
210 | lpCaps->dwMaxHw3DAllBuffers = 0;
|
---|
211 | lpCaps->dwMaxHw3DStaticBuffers = 0;
|
---|
212 | lpCaps->dwMaxHw3DStreamingBuffers = 0;
|
---|
213 | lpCaps->dwFreeHw3DAllBuffers = 0;
|
---|
214 | lpCaps->dwFreeHw3DStaticBuffers = 0;
|
---|
215 | lpCaps->dwFreeHw3DStreamingBuffers = 0;
|
---|
216 | lpCaps->dwTotalHwMemBytes = 0;
|
---|
217 | lpCaps->dwFreeHwMemBytes = 0;
|
---|
218 | lpCaps->dwMaxContigFreeHwMemBytes = 0;
|
---|
219 | lpCaps->dwUnlockTransferRateHwBuffers = 0; // no transfer needed
|
---|
220 | lpCaps->dwPlayCpuOverheadSwBuffers = 0; // we lie here...
|
---|
221 | lpCaps->dwReserved1 = 0;
|
---|
222 | lpCaps->dwReserved2 = 0;
|
---|
223 |
|
---|
224 | return DS_OK;
|
---|
225 | }
|
---|
226 |
|
---|
227 | //******************************************************************************
|
---|
228 | //******************************************************************************
|
---|
229 | HRESULT WIN32API SoundDuplicateSoundBuffer(THIS_ LPDIRECTSOUNDBUFFER, LPLPDIRECTSOUNDBUFFER )
|
---|
230 | {
|
---|
231 | dprintf(("DSOUND-OS2IDirectSound::DuplicateSoundBuffer\n"));
|
---|
232 | return DSERR_OUTOFMEMORY;
|
---|
233 | }
|
---|
234 |
|
---|
235 | //******************************************************************************
|
---|
236 | //******************************************************************************
|
---|
237 | HRESULT WIN32API SoundSetCooperativeLevel(THIS_ HWND hwndClient, DWORD level)
|
---|
238 | {
|
---|
239 | OS2IDirectSound *me = (OS2IDirectSound *)This;
|
---|
240 |
|
---|
241 | dprintf(("DSOUND-OS2IDirectSound::SetCooperativeLevel (to %d)\n", level));
|
---|
242 | if (me == NULL) {
|
---|
243 | return DSERR_INVALIDPARAM;
|
---|
244 | }
|
---|
245 | me->hwndClient = (HWND)hwndClient;
|
---|
246 | me->CoopLevel = level;
|
---|
247 | return DS_OK;
|
---|
248 | }
|
---|
249 | //******************************************************************************
|
---|
250 | //******************************************************************************
|
---|
251 | HRESULT WIN32API SoundGetSpeakerConfig(THIS_ LPDWORD lpSpeakerCfg)
|
---|
252 | {
|
---|
253 | OS2IDirectSound *me = (OS2IDirectSound *)This;
|
---|
254 |
|
---|
255 | dprintf(("DSOUND-OS2IDirectSound::GetSpeakerConfig\n"));
|
---|
256 | if (me == NULL) {
|
---|
257 | return(DSERR_INVALIDPARAM);
|
---|
258 | }
|
---|
259 | *lpSpeakerCfg = me->speakerConfig;
|
---|
260 |
|
---|
261 | return DS_OK;
|
---|
262 | }
|
---|
263 |
|
---|
264 | //******************************************************************************
|
---|
265 | //******************************************************************************
|
---|
266 | HRESULT WIN32API SoundSetSpeakerConfig(THIS_ DWORD speakerCfg)
|
---|
267 | {
|
---|
268 | OS2IDirectSound *me = (OS2IDirectSound *)This;
|
---|
269 |
|
---|
270 | dprintf(("DSOUND-OS2IDirectSound::SetSpeakerConfig %X\n", speakerCfg));
|
---|
271 | if (me == NULL) {
|
---|
272 | return DSERR_INVALIDPARAM;
|
---|
273 | }
|
---|
274 | me->speakerConfig = speakerCfg;
|
---|
275 | return DS_OK;
|
---|
276 | }
|
---|
277 |
|
---|
278 | //******************************************************************************
|
---|
279 | //******************************************************************************
|
---|
280 | HRESULT WIN32API SoundInitialize(THIS_ LPGUID)
|
---|
281 | {
|
---|
282 | dprintf(("DSOUND-OS2IDirectSound::Initialize NOP\n"));
|
---|
283 | return DS_OK;
|
---|
284 | }
|
---|
285 | //******************************************************************************
|
---|
286 | //******************************************************************************
|
---|