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