1 | /* $Id: OS2DSOUND.CPP,v 1.4 1999-10-23 23:00:49 sandervl 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 | /*@Header***********************************************************************
|
---|
13 | * Header Files *
|
---|
14 | *******************************************************************************/
|
---|
15 | #include <os2win.h>
|
---|
16 | #include <stdlib.h>
|
---|
17 | #include <string.h>
|
---|
18 |
|
---|
19 | #define INITGUID
|
---|
20 | #include <dsound.h>
|
---|
21 |
|
---|
22 | #include "os2dsound.h"
|
---|
23 | #include "os2sndbuffer.h"
|
---|
24 | #include "misc.h"
|
---|
25 |
|
---|
26 | //******************************************************************************
|
---|
27 | //******************************************************************************
|
---|
28 | OS2IDirectSound::OS2IDirectSound(const GUID *lpGUID) : Referenced(0),
|
---|
29 | lastError(DS_OK), hwndClient(0)
|
---|
30 | {
|
---|
31 | lpVtbl = &Vtbl;
|
---|
32 | Vtbl.AddRef = SoundAddRef;
|
---|
33 | Vtbl.Release = SoundRelease;
|
---|
34 | Vtbl.QueryInterface = SoundQueryInterface;
|
---|
35 | Vtbl.Compact = SoundCompact;
|
---|
36 | Vtbl.CreateSoundBuffer = SoundCreateSoundBuffer;
|
---|
37 | Vtbl.GetCaps = SoundGetCaps;
|
---|
38 | Vtbl.DuplicateSoundBuffer = SoundDuplicateSoundBuffer;
|
---|
39 | Vtbl.SetCooperativeLevel = SoundSetCooperativeLevel;
|
---|
40 | Vtbl.Compact = SoundCompact;
|
---|
41 | Vtbl.GetSpeakerConfig = SoundGetSpeakerConfig;
|
---|
42 | Vtbl.SetSpeakerConfig = SoundSetSpeakerConfig;
|
---|
43 | Vtbl.Initialize = SoundInitialize;
|
---|
44 |
|
---|
45 | speakerConfig = DSSPEAKER_STEREO;
|
---|
46 | CoopLevel = DSSCL_EXCLUSIVE; //default
|
---|
47 | }
|
---|
48 | //******************************************************************************
|
---|
49 | //******************************************************************************
|
---|
50 | OS2IDirectSound::~OS2IDirectSound()
|
---|
51 | {
|
---|
52 |
|
---|
53 | }
|
---|
54 | //******************************************************************************
|
---|
55 | //******************************************************************************
|
---|
56 | HRESULT WIN32API SoundQueryInterface(THIS, REFIID riid, LPVOID * ppvObj)
|
---|
57 | {
|
---|
58 | dprintf(("OS2IDirectSound::QueryInterface\n"));
|
---|
59 | if(This == NULL) {
|
---|
60 | return DSERR_INVALIDPARAM;
|
---|
61 | }
|
---|
62 | *ppvObj = NULL;
|
---|
63 |
|
---|
64 | if(!IsEqualGUID(riid, CLSID_DirectSound) &&
|
---|
65 | !IsEqualGUID(riid, IID_IDirectSound))
|
---|
66 | return E_NOINTERFACE;
|
---|
67 |
|
---|
68 | *ppvObj = This;
|
---|
69 |
|
---|
70 | SoundAddRef(This);
|
---|
71 | return(DS_OK);
|
---|
72 | }
|
---|
73 | //******************************************************************************
|
---|
74 | //******************************************************************************
|
---|
75 | ULONG WIN32API SoundAddRef(THIS)
|
---|
76 | {
|
---|
77 | OS2IDirectSound *me = (OS2IDirectSound *)This;
|
---|
78 |
|
---|
79 | dprintf(("OS2IDirectSound::AddRef %d\n", me->Referenced+1));
|
---|
80 | return ++me->Referenced;
|
---|
81 | }
|
---|
82 | //******************************************************************************
|
---|
83 | //******************************************************************************
|
---|
84 | ULONG WIN32API SoundRelease(THIS)
|
---|
85 | {
|
---|
86 | OS2IDirectSound *me = (OS2IDirectSound *)This;
|
---|
87 |
|
---|
88 | dprintf(("OS2IDirectSound::Release %d\n", me->Referenced-1));
|
---|
89 | if(me->Referenced) {
|
---|
90 | me->Referenced--;
|
---|
91 | if(me->Referenced == 0) {
|
---|
92 | delete me;
|
---|
93 | return(0);
|
---|
94 | }
|
---|
95 | else return me->Referenced;
|
---|
96 | }
|
---|
97 | else return(0);
|
---|
98 | }
|
---|
99 | //******************************************************************************
|
---|
100 | //******************************************************************************
|
---|
101 | HRESULT WIN32API SoundCompact(THIS)
|
---|
102 | {
|
---|
103 | dprintf(("OS2IDirectSound::Compact\n"));
|
---|
104 | return(DS_OK);
|
---|
105 | }
|
---|
106 | //******************************************************************************
|
---|
107 | //******************************************************************************
|
---|
108 | HRESULT WIN32API SoundCreateSoundBuffer(THIS_
|
---|
109 | LPDSBUFFERDESC lpDSBufferDesc, //new, const
|
---|
110 | LPDIRECTSOUNDBUFFER *lplpDirectSoundBuffer,
|
---|
111 | LPUNKNOWN pUnkOuter)
|
---|
112 | {
|
---|
113 | OS2IDirectSound *me = (OS2IDirectSound *)This;
|
---|
114 | OS2IDirectSoundBuffer *sndbuf;
|
---|
115 |
|
---|
116 | dprintf(("OS2IDirectSound::CreateSoundBuffer\n"));
|
---|
117 | if(me == NULL || lpDSBufferDesc == NULL || lplpDirectSoundBuffer == NULL) {
|
---|
118 | return(DSERR_INVALIDPARAM);
|
---|
119 | }
|
---|
120 | sndbuf = new OS2IDirectSoundBuffer(lpDSBufferDesc);
|
---|
121 | if(sndbuf == NULL) {
|
---|
122 | return(DSERR_OUTOFMEMORY);
|
---|
123 | }
|
---|
124 | if(sndbuf->GetLastError() != DS_OK) {
|
---|
125 | ULONG lastErr = sndbuf->GetLastError();
|
---|
126 | delete sndbuf;
|
---|
127 | return lastErr;
|
---|
128 | }
|
---|
129 | *lplpDirectSoundBuffer = (LPDIRECTSOUNDBUFFER)sndbuf;
|
---|
130 | return(DS_OK);
|
---|
131 | }
|
---|
132 | //******************************************************************************
|
---|
133 | //******************************************************************************
|
---|
134 | HRESULT WIN32API SoundGetCaps(THIS_ LPDSCAPS lpCaps)
|
---|
135 | {
|
---|
136 | dprintf(("OS2IDirectSound::GetCaps\n"));
|
---|
137 | return(DS_OK);
|
---|
138 | }
|
---|
139 | //******************************************************************************
|
---|
140 | //******************************************************************************
|
---|
141 | HRESULT WIN32API SoundDuplicateSoundBuffer(THIS_ LPDIRECTSOUNDBUFFER, LPLPDIRECTSOUNDBUFFER )
|
---|
142 | {
|
---|
143 | dprintf(("OS2IDirectSound::DuplicateSoundBuffer\n"));
|
---|
144 | return(DSERR_OUTOFMEMORY);
|
---|
145 | }
|
---|
146 | //******************************************************************************
|
---|
147 | //******************************************************************************
|
---|
148 | HRESULT WIN32API SoundSetCooperativeLevel(THIS_ HWND hwndClient, DWORD level)
|
---|
149 | {
|
---|
150 | OS2IDirectSound *me = (OS2IDirectSound *)This;
|
---|
151 |
|
---|
152 | dprintf(("OS2IDirectSound::SetCooperativeLevel\n"));
|
---|
153 | if(me == NULL) {
|
---|
154 | return(DSERR_INVALIDPARAM);
|
---|
155 | }
|
---|
156 | me->hwndClient = (HWND)hwndClient;
|
---|
157 | me->CoopLevel = level;
|
---|
158 | return(DS_OK);
|
---|
159 | }
|
---|
160 | //******************************************************************************
|
---|
161 | //******************************************************************************
|
---|
162 | HRESULT WIN32API SoundGetSpeakerConfig(THIS_ LPDWORD lpSpeakerCfg)
|
---|
163 | {
|
---|
164 | OS2IDirectSound *me = (OS2IDirectSound *)This;
|
---|
165 |
|
---|
166 | dprintf(("OS2IDirectSound::GetSpeakerConfig\n"));
|
---|
167 | if(me == NULL) {
|
---|
168 | return(DSERR_INVALIDPARAM);
|
---|
169 | }
|
---|
170 | *lpSpeakerCfg = me->speakerConfig;
|
---|
171 |
|
---|
172 | return(DS_OK);
|
---|
173 | }
|
---|
174 | //******************************************************************************
|
---|
175 | //******************************************************************************
|
---|
176 | HRESULT WIN32API SoundSetSpeakerConfig(THIS_ DWORD speakerCfg)
|
---|
177 | {
|
---|
178 | OS2IDirectSound *me = (OS2IDirectSound *)This;
|
---|
179 |
|
---|
180 | dprintf(("OS2IDirectSound::SetSpeakerConfig %X\n", speakerCfg));
|
---|
181 | if(me == NULL) {
|
---|
182 | return(DSERR_INVALIDPARAM);
|
---|
183 | }
|
---|
184 | me->speakerConfig = speakerCfg;
|
---|
185 | return(DS_OK);
|
---|
186 | }
|
---|
187 | //******************************************************************************
|
---|
188 | //******************************************************************************
|
---|
189 | HRESULT WIN32API SoundInitialize(THIS_ LPGUID)
|
---|
190 | {
|
---|
191 | dprintf(("OS2IDirectSound::Initialize UNSUPPORTED\n"));
|
---|
192 | return(DS_OK);
|
---|
193 | }
|
---|
194 | //******************************************************************************
|
---|
195 | //******************************************************************************
|
---|