source: trunk/src/dsound/OS2DSOUND.CPP@ 1744

Last change on this file since 1744 was 1744, checked in by hugh, 26 years ago

Implemented fake soundcard
The Bufferpos will be advanced based on the elapsed time
since start playing

File size: 6.7 KB
Line 
1/* $Id: OS2DSOUND.CPP,v 1.5 1999-11-14 22:12:15 hugh 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//******************************************************************************
28OS2IDirectSound::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//******************************************************************************
50OS2IDirectSound::~OS2IDirectSound()
51{
52
53}
54//******************************************************************************
55//******************************************************************************
56HRESULT WIN32API SoundQueryInterface(THIS, REFIID riid, LPVOID * ppvObj)
57{
58 dprintf(("OS2IDirectSound::QueryInterface\n"));
59 if(This == NULL)
60 {
61 return DSERR_INVALIDPARAM;
62 }
63 *ppvObj = NULL;
64
65 if(!IsEqualGUID(riid, CLSID_DirectSound) &&
66 !IsEqualGUID(riid, IID_IDirectSound))
67 return E_NOINTERFACE;
68
69 *ppvObj = This;
70
71 SoundAddRef(This);
72 return(DS_OK);
73}
74//******************************************************************************
75//******************************************************************************
76ULONG WIN32API SoundAddRef(THIS)
77{
78 OS2IDirectSound *me = (OS2IDirectSound *)This;
79
80 dprintf(("OS2IDirectSound::AddRef %d\n", me->Referenced+1));
81 return ++me->Referenced;
82}
83//******************************************************************************
84//******************************************************************************
85ULONG WIN32API SoundRelease(THIS)
86{
87 OS2IDirectSound *me = (OS2IDirectSound *)This;
88
89 dprintf(("OS2IDirectSound::Release %d\n", me->Referenced-1));
90 if(me->Referenced) {
91 me->Referenced--;
92 if(me->Referenced == 0) {
93 delete me;
94 return(0);
95 }
96 else return me->Referenced;
97 }
98 else return(0);
99}
100//******************************************************************************
101//******************************************************************************
102HRESULT WIN32API SoundCompact(THIS)
103{
104 dprintf(("OS2IDirectSound::Compact\n"));
105 return(DS_OK);
106}
107//******************************************************************************
108//******************************************************************************
109HRESULT WIN32API SoundCreateSoundBuffer(THIS_
110 LPDSBUFFERDESC lpDSBufferDesc, //new, const
111 LPDIRECTSOUNDBUFFER *lplpDirectSoundBuffer,
112 LPUNKNOWN pUnkOuter)
113{
114 OS2IDirectSound *me = (OS2IDirectSound *)This;
115 OS2IDirectSoundBuffer *sndbuf;
116
117 dprintf(("OS2IDirectSound::CreateSoundBuffer\n"));
118 if(me == NULL || lpDSBufferDesc == NULL || lplpDirectSoundBuffer == NULL)
119 {
120 return(DSERR_INVALIDPARAM);
121 }
122
123 sndbuf = new OS2IDirectSoundBuffer(lpDSBufferDesc);
124 if(sndbuf == NULL)
125 {
126 return(DSERR_OUTOFMEMORY);
127 }
128 if(sndbuf->GetLastError() != DS_OK)
129 {
130 ULONG lastErr = sndbuf->GetLastError();
131 delete sndbuf;
132 return lastErr;
133 }
134 *lplpDirectSoundBuffer = (LPDIRECTSOUNDBUFFER)sndbuf;
135 return(DS_OK);
136}
137//******************************************************************************
138//******************************************************************************
139HRESULT WIN32API SoundGetCaps(THIS_ LPDSCAPS lpCaps)
140{
141 dprintf(("OS2IDirectSound::GetCaps\n"));
142 return(DS_OK);
143}
144//******************************************************************************
145//******************************************************************************
146HRESULT WIN32API SoundDuplicateSoundBuffer(THIS_ LPDIRECTSOUNDBUFFER, LPLPDIRECTSOUNDBUFFER )
147{
148 dprintf(("OS2IDirectSound::DuplicateSoundBuffer\n"));
149 return(DSERR_OUTOFMEMORY);
150}
151//******************************************************************************
152//******************************************************************************
153HRESULT WIN32API SoundSetCooperativeLevel(THIS_ HWND hwndClient, DWORD level)
154{
155 OS2IDirectSound *me = (OS2IDirectSound *)This;
156
157 dprintf(("OS2IDirectSound::SetCooperativeLevel\n"));
158 if(me == NULL) {
159 return(DSERR_INVALIDPARAM);
160 }
161 me->hwndClient = (HWND)hwndClient;
162 me->CoopLevel = level;
163 return(DS_OK);
164}
165//******************************************************************************
166//******************************************************************************
167HRESULT WIN32API SoundGetSpeakerConfig(THIS_ LPDWORD lpSpeakerCfg)
168{
169 OS2IDirectSound *me = (OS2IDirectSound *)This;
170
171 dprintf(("OS2IDirectSound::GetSpeakerConfig\n"));
172 if(me == NULL) {
173 return(DSERR_INVALIDPARAM);
174 }
175 *lpSpeakerCfg = me->speakerConfig;
176
177 return(DS_OK);
178}
179//******************************************************************************
180//******************************************************************************
181HRESULT WIN32API SoundSetSpeakerConfig(THIS_ DWORD speakerCfg)
182{
183 OS2IDirectSound *me = (OS2IDirectSound *)This;
184
185 dprintf(("OS2IDirectSound::SetSpeakerConfig %X\n", speakerCfg));
186 if(me == NULL) {
187 return(DSERR_INVALIDPARAM);
188 }
189 me->speakerConfig = speakerCfg;
190 return(DS_OK);
191}
192//******************************************************************************
193//******************************************************************************
194HRESULT WIN32API SoundInitialize(THIS_ LPGUID)
195{
196 dprintf(("OS2IDirectSound::Initialize UNSUPPORTED\n"));
197 return(DS_OK);
198}
199//******************************************************************************
200//******************************************************************************
Note: See TracBrowser for help on using the repository browser.