1 | /*
|
---|
2 | * DirectSound main class
|
---|
3 | *
|
---|
4 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
5 | *
|
---|
6 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
7 | *
|
---|
8 | */
|
---|
9 |
|
---|
10 | /*@Const************************************************************************
|
---|
11 | * Defined Constants *
|
---|
12 | *******************************************************************************/
|
---|
13 | #define INITGUID
|
---|
14 | #define INCL_DIRECTSOUND_GUID
|
---|
15 | #define WIN32SDK_NOPOSTWRAPPER
|
---|
16 |
|
---|
17 |
|
---|
18 | /*@Header***********************************************************************
|
---|
19 | * Header Files *
|
---|
20 | *******************************************************************************/
|
---|
21 | #include <os2win.h>
|
---|
22 | #include <stdlib.h>
|
---|
23 | #include <string.h>
|
---|
24 |
|
---|
25 | #include "no.h" /* NO* defines for windows.h */
|
---|
26 | #include <w_windows.h>
|
---|
27 | #include <dsound.h>
|
---|
28 | #include <Win32SDKPostWrapper.h>
|
---|
29 |
|
---|
30 | #include "os2dsound.h"
|
---|
31 | #include "os2sndbuffer.h"
|
---|
32 | #include "misc.h"
|
---|
33 |
|
---|
34 |
|
---|
35 | /* KSO Apr 19 1999: INTERFACE set again, since os2sndbuffer changed it. *
|
---|
36 | * (INTERFACE is used in the THIS and THIS_ macros) */
|
---|
37 | #undef INTERFACE
|
---|
38 | #define INTERFACE IDirectSound
|
---|
39 |
|
---|
40 |
|
---|
41 | //******************************************************************************
|
---|
42 | //******************************************************************************
|
---|
43 | OS2IDirectSound::OS2IDirectSound(const GUID *lpGUID) : Referenced(0),
|
---|
44 | lastError(DS_OK), hwndClient(0)
|
---|
45 | {
|
---|
46 | lpVtbl = &Vtbl;
|
---|
47 | Vtbl.AddRef = SoundAddRef;
|
---|
48 | Vtbl.Release = SoundRelease;
|
---|
49 | Vtbl.QueryInterface = SoundQueryInterface;
|
---|
50 | Vtbl.Compact = SoundCompact;
|
---|
51 | Vtbl.CreateSoundBuffer = SoundCreateSoundBuffer;
|
---|
52 | Vtbl.GetCaps = SoundGetCaps;
|
---|
53 | Vtbl.DuplicateSoundBuffer = SoundDuplicateSoundBuffer;
|
---|
54 | Vtbl.SetCooperativeLevel = SoundSetCooperativeLevel;
|
---|
55 | Vtbl.Compact = SoundCompact;
|
---|
56 | Vtbl.GetSpeakerConfig = SoundGetSpeakerConfig;
|
---|
57 | Vtbl.SetSpeakerConfig = SoundSetSpeakerConfig;
|
---|
58 | Vtbl.Initialize = SoundInitialize;
|
---|
59 |
|
---|
60 | speakerConfig = DSSPEAKER_STEREO;
|
---|
61 | CoopLevel = DSSCL_EXCLUSIVE; //default
|
---|
62 | }
|
---|
63 | //******************************************************************************
|
---|
64 | //******************************************************************************
|
---|
65 | OS2IDirectSound::~OS2IDirectSound()
|
---|
66 | {
|
---|
67 |
|
---|
68 | }
|
---|
69 | //******************************************************************************
|
---|
70 | //******************************************************************************
|
---|
71 | HRESULT WIN32API SoundQueryInterface(THIS, REFIID riid, LPVOID FAR * ppvObj)
|
---|
72 | {
|
---|
73 | dprintf(("OS2IDirectSound::QueryInterface\n"));
|
---|
74 | if(This == NULL) {
|
---|
75 | return DSERR_INVALIDPARAM;
|
---|
76 | }
|
---|
77 | *ppvObj = NULL;
|
---|
78 |
|
---|
79 | if(!IsEqualGUID(riid, CLSID_DirectSound) &&
|
---|
80 | !IsEqualGUID(riid, IID_IDirectSound))
|
---|
81 | return E_NOINTERFACE;
|
---|
82 |
|
---|
83 | *ppvObj = This;
|
---|
84 |
|
---|
85 | SoundAddRef(This);
|
---|
86 | return(DS_OK);
|
---|
87 | }
|
---|
88 | //******************************************************************************
|
---|
89 | //******************************************************************************
|
---|
90 | ULONG WIN32API SoundAddRef(THIS)
|
---|
91 | {
|
---|
92 | OS2IDirectSound *me = (OS2IDirectSound *)This;
|
---|
93 |
|
---|
94 | dprintf(("OS2IDirectSound::AddRef %d\n", me->Referenced+1));
|
---|
95 | return ++me->Referenced;
|
---|
96 | }
|
---|
97 | //******************************************************************************
|
---|
98 | //******************************************************************************
|
---|
99 | ULONG WIN32API SoundRelease(THIS)
|
---|
100 | {
|
---|
101 | OS2IDirectSound *me = (OS2IDirectSound *)This;
|
---|
102 |
|
---|
103 | dprintf(("OS2IDirectSound::Release %d\n", me->Referenced-1));
|
---|
104 | if(me->Referenced) {
|
---|
105 | me->Referenced--;
|
---|
106 | if(me->Referenced == 0) {
|
---|
107 | delete me;
|
---|
108 | return(0);
|
---|
109 | }
|
---|
110 | else return me->Referenced;
|
---|
111 | }
|
---|
112 | else return(0);
|
---|
113 | }
|
---|
114 | //******************************************************************************
|
---|
115 | //******************************************************************************
|
---|
116 | HRESULT WIN32API SoundCompact(THIS)
|
---|
117 | {
|
---|
118 | dprintf(("OS2IDirectSound::Compact\n"));
|
---|
119 | return(DS_OK);
|
---|
120 | }
|
---|
121 | //******************************************************************************
|
---|
122 | //******************************************************************************
|
---|
123 | #if 0 //KSO Apr 13 1999: some parameter incompabilities between newer and older SDKs.
|
---|
124 | HRESULT WIN32API SoundCreateSoundBuffer(THIS_
|
---|
125 | LPDSBUFFERDESC lpDSBufferDesc, //old, non const
|
---|
126 | LPLPDIRECTSOUNDBUFFER lplpDirectSoundBuffer,
|
---|
127 | IUnknown FAR *pUnkOuter)
|
---|
128 | #else
|
---|
129 | HRESULT WIN32API SoundCreateSoundBuffer(THIS_
|
---|
130 | LPCDSBUFFERDESC lpDSBufferDesc, //new, const
|
---|
131 | LPDIRECTSOUNDBUFFER *lplpDirectSoundBuffer,
|
---|
132 | LPUNKNOWN pUnkOuter)
|
---|
133 | #endif
|
---|
134 | {
|
---|
135 | OS2IDirectSound *me = (OS2IDirectSound *)This;
|
---|
136 | OS2IDirectSoundBuffer *sndbuf;
|
---|
137 |
|
---|
138 | dprintf(("OS2IDirectSound::CreateSoundBuffer\n"));
|
---|
139 | if(me == NULL || lpDSBufferDesc == NULL || lplpDirectSoundBuffer == NULL) {
|
---|
140 | return(DSERR_INVALIDPARAM);
|
---|
141 | }
|
---|
142 | sndbuf = new OS2IDirectSoundBuffer(lpDSBufferDesc);
|
---|
143 | if(sndbuf == NULL) {
|
---|
144 | return(DSERR_OUTOFMEMORY);
|
---|
145 | }
|
---|
146 | if(sndbuf->GetLastError() != DS_OK) {
|
---|
147 | ULONG lastErr = sndbuf->GetLastError();
|
---|
148 | delete sndbuf;
|
---|
149 | return lastErr;
|
---|
150 | }
|
---|
151 | *lplpDirectSoundBuffer = (LPDIRECTSOUNDBUFFER)sndbuf;
|
---|
152 | return(DS_OK);
|
---|
153 | }
|
---|
154 | //******************************************************************************
|
---|
155 | //******************************************************************************
|
---|
156 | HRESULT WIN32API SoundGetCaps(THIS_ LPDSCAPS lpCaps)
|
---|
157 | {
|
---|
158 | dprintf(("OS2IDirectSound::GetCaps\n"));
|
---|
159 | return(DS_OK);
|
---|
160 | }
|
---|
161 | //******************************************************************************
|
---|
162 | //******************************************************************************
|
---|
163 | HRESULT WIN32API SoundDuplicateSoundBuffer(THIS_ LPDIRECTSOUNDBUFFER, LPLPDIRECTSOUNDBUFFER )
|
---|
164 | {
|
---|
165 | dprintf(("OS2IDirectSound::DuplicateSoundBuffer\n"));
|
---|
166 | return(DSERR_OUTOFMEMORY);
|
---|
167 | }
|
---|
168 | //******************************************************************************
|
---|
169 | //******************************************************************************
|
---|
170 | HRESULT WIN32API SoundSetCooperativeLevel(THIS_ W32_HWND hwndClient, DWORD level)
|
---|
171 | {
|
---|
172 | OS2IDirectSound *me = (OS2IDirectSound *)This;
|
---|
173 |
|
---|
174 | dprintf(("OS2IDirectSound::SetCooperativeLevel\n"));
|
---|
175 | if(me == NULL) {
|
---|
176 | return(DSERR_INVALIDPARAM);
|
---|
177 | }
|
---|
178 | me->hwndClient = (HWND)hwndClient;
|
---|
179 | me->CoopLevel = level;
|
---|
180 | return(DS_OK);
|
---|
181 | }
|
---|
182 | //******************************************************************************
|
---|
183 | //******************************************************************************
|
---|
184 | HRESULT WIN32API SoundGetSpeakerConfig(THIS_ LPDWORD lpSpeakerCfg)
|
---|
185 | {
|
---|
186 | OS2IDirectSound *me = (OS2IDirectSound *)This;
|
---|
187 |
|
---|
188 | dprintf(("OS2IDirectSound::GetSpeakerConfig\n"));
|
---|
189 | if(me == NULL) {
|
---|
190 | return(DSERR_INVALIDPARAM);
|
---|
191 | }
|
---|
192 | *lpSpeakerCfg = me->speakerConfig;
|
---|
193 |
|
---|
194 | return(DS_OK);
|
---|
195 | }
|
---|
196 | //******************************************************************************
|
---|
197 | //******************************************************************************
|
---|
198 | HRESULT WIN32API SoundSetSpeakerConfig(THIS_ DWORD speakerCfg)
|
---|
199 | {
|
---|
200 | OS2IDirectSound *me = (OS2IDirectSound *)This;
|
---|
201 |
|
---|
202 | dprintf(("OS2IDirectSound::SetSpeakerConfig %X\n", speakerCfg));
|
---|
203 | if(me == NULL) {
|
---|
204 | return(DSERR_INVALIDPARAM);
|
---|
205 | }
|
---|
206 | me->speakerConfig = speakerCfg;
|
---|
207 | return(DS_OK);
|
---|
208 | }
|
---|
209 | //******************************************************************************
|
---|
210 | //******************************************************************************
|
---|
211 | #if 0 //KSO Apr 13 1999: parameter declaration has changed in later SDKs
|
---|
212 | HRESULT WIN32API SoundInitialize(THIS_ const GUID * )
|
---|
213 | #else
|
---|
214 | HRESULT WIN32API SoundInitialize(THIS_ LPGUID)
|
---|
215 | #endif
|
---|
216 | {
|
---|
217 | dprintf(("OS2IDirectSound::Initialize UNSUPPORTED\n"));
|
---|
218 | return(DS_OK);
|
---|
219 | }
|
---|
220 | //******************************************************************************
|
---|
221 | //******************************************************************************
|
---|