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