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