- Timestamp:
- Mar 10, 2001, 7:21:06 AM (24 years ago)
- Location:
- trunk/src/dsound
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/dsound/OS2DSOUND.CPP
r3555 r5292 1 /* $Id: OS2DSOUND.CPP,v 1. 7 2000-05-18 20:37:08mike Exp $ */1 /* $Id: OS2DSOUND.CPP,v 1.8 2001-03-10 06:21:06 mike Exp $ */ 2 2 3 3 /* … … 5 5 * 6 6 * Copyright 1998 Sander van Leeuwen 7 * Copyright 2000 Michal Necasek 7 * Copyright 2000 Kevin Langman 8 * Copyright 2001 Michal Necasek 8 9 * 9 10 * Project Odin Software License can be found in LICENSE.TXT … … 18 19 #include <string.h> 19 20 20 21 22 21 #include <stdio.h> /****** DEBUGGING ********/ 23 24 25 22 26 23 #define INITGUID … … 34 31 #include <misc.h> 35 32 36 // TODO: primary buffer should probably created right away when creating the DSound37 // object38 33 // TODO: handle cooperative levels properly!! 39 34 … … 60 55 Vtbl.Initialize = SoundInitialize; 61 56 62 dprintf(("DSOUND-OS2IDirectSound::OS2IDirectSound \n"));57 dprintf(("DSOUND-OS2IDirectSound::OS2IDirectSound")); 63 58 64 59 speakerConfig = DSSPEAKER_STEREO; … … 75 70 if ( primary->GetLastError() != DS_OK ){ 76 71 ULONG lastErr = primary->GetLastError(); 77 dprintf(("LastErr = %d \n", lastErr));72 dprintf(("LastErr = %d", lastErr)); 78 73 delete primary; 79 74 lastError = lastErr; … … 82 77 primary->Vtbl.AddRef(primary); 83 78 84 dprintf(("Sound init OK\n")); 85 } 79 dprintf(("Sound init OK")); 80 } 81 86 82 //****************************************************************************** 87 83 //****************************************************************************** … … 92 88 OS2IDirectSound::fDSExists = FALSE; 93 89 } 90 94 91 //****************************************************************************** 95 92 //****************************************************************************** 96 93 HRESULT WIN32API SoundQueryInterface(THIS, REFIID riid, LPVOID * ppvObj) 97 94 { 98 dprintf(("DSOUND-OS2IDirectSound::QueryInterface \n"));95 dprintf(("DSOUND-OS2IDirectSound::QueryInterface")); 99 96 if (This == NULL) { 100 97 return DSERR_INVALIDPARAM; … … 118 115 OS2IDirectSound *me = (OS2IDirectSound *)This; 119 116 120 dprintf(("DSOUND-OS2IDirectSound::AddRef %d \n", me->Referenced+1));117 dprintf(("DSOUND-OS2IDirectSound::AddRef %d", me->Referenced+1)); 121 118 return ++me->Referenced; 122 119 } … … 128 125 OS2IDirectSound *me = (OS2IDirectSound *)This; 129 126 130 dprintf(("DSOUND-OS2IDirectSound::Release %d \n", me->Referenced-1));127 dprintf(("DSOUND-OS2IDirectSound::Release %d", me->Referenced-1)); 131 128 if (me->Referenced) { 132 129 me->Referenced--; … … 146 143 HRESULT WIN32API SoundCompact(THIS) 147 144 { 148 dprintf(("DSOUND-OS2IDirectSound::Compact \n"));145 dprintf(("DSOUND-OS2IDirectSound::Compact - NOP")); 149 146 return DS_OK; 150 147 } … … 160 157 OS2IDirectSoundBuffer *sndbuf; 161 158 162 dprintf(("DSOUND-OS2IDirectSound::CreateSoundBuffer \n"));159 dprintf(("DSOUND-OS2IDirectSound::CreateSoundBuffer")); 163 160 if (me == NULL || lpDSBufferDesc == NULL || lplpDirectSoundBuffer == NULL) { 164 161 return DSERR_INVALIDPARAM; … … 171 168 172 169 if (lpDSBufferDesc->dwFlags & DSBCAPS_PRIMARYBUFFER) { 173 174 /*175 176 // The Primary buffer is now created by the Constructor.. This only177 // makes sence becuse you can really only have one primary buffer and178 // you need it before you can to do anything.179 180 OS2PrimBuff *primbuff;181 primbuff = new OS2PrimBuff(me, lpDSBufferDesc);182 183 if (primbuff == NULL)184 return DSERR_OUTOFMEMORY;185 186 if ( primbuff->GetLastError() != DS_OK ){187 ULONG lastErr = primbuff->GetLastError();188 189 dprintf(("LastErr = %d\n", lastErr));190 delete primbuff;191 return lastErr;192 }193 *lplpDirectSoundBuffer = (LPDIRECTSOUNDBUFFER)primbuff;194 primbuff->Vtbl.AddRef(primbuff);195 dprintf(("Created PrimBuff... Exiting Create Buffer function\n"));196 */197 198 170 *lplpDirectSoundBuffer = (LPDIRECTSOUNDBUFFER)me->primary; 199 171 return DS_OK; … … 204 176 return DSERR_OUTOFMEMORY; 205 177 } 206 if (sndbuf->GetLastError() != DS_OK) {178 if (sndbuf->GetLastError() != DS_OK) { 207 179 ULONG lastErr = sndbuf->GetLastError(); 208 180 delete sndbuf; … … 220 192 HRESULT WIN32API SoundGetCaps(THIS_ LPDSCAPS lpCaps) 221 193 { 222 dprintf(("DSOUND-OS2IDirectSound::GetCaps \n"));194 dprintf(("DSOUND-OS2IDirectSound::GetCaps")); 223 195 224 196 if (lpCaps == NULL) … … 258 230 //****************************************************************************** 259 231 //****************************************************************************** 260 HRESULT WIN32API SoundDuplicateSoundBuffer(THIS_ LPDIRECTSOUNDBUFFER, LPLPDIRECTSOUNDBUFFER ) 261 { 262 dprintf(("DSOUND-OS2IDirectSound::DuplicateSoundBuffer\n")); 263 return DSERR_OUTOFMEMORY; 232 HRESULT WIN32API SoundDuplicateSoundBuffer(THIS_ LPDIRECTSOUNDBUFFER lpBuf, LPLPDIRECTSOUNDBUFFER lplpDirectSoundBuffer) 233 { 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 } 253 tgtBuf->Vtbl.AddRef(tgtBuf); 254 255 *lplpDirectSoundBuffer = (LPDIRECTSOUNDBUFFER)tgtBuf; 256 257 return DS_OK; 264 258 } 265 259 … … 270 264 OS2IDirectSound *me = (OS2IDirectSound *)This; 271 265 272 dprintf(("DSOUND-OS2IDirectSound::SetCooperativeLevel (to %d) \n", level));266 dprintf(("DSOUND-OS2IDirectSound::SetCooperativeLevel (to %d)", level)); 273 267 if (me == NULL) { 274 268 return DSERR_INVALIDPARAM; … … 278 272 return DS_OK; 279 273 } 274 280 275 //****************************************************************************** 281 276 //****************************************************************************** … … 284 279 OS2IDirectSound *me = (OS2IDirectSound *)This; 285 280 286 dprintf(("DSOUND-OS2IDirectSound::GetSpeakerConfig \n"));281 dprintf(("DSOUND-OS2IDirectSound::GetSpeakerConfig")); 287 282 if (me == NULL) { 288 283 return(DSERR_INVALIDPARAM); … … 299 294 OS2IDirectSound *me = (OS2IDirectSound *)This; 300 295 301 dprintf(("DSOUND-OS2IDirectSound::SetSpeakerConfig %X \n", speakerCfg));296 dprintf(("DSOUND-OS2IDirectSound::SetSpeakerConfig %X", speakerCfg)); 302 297 if (me == NULL) { 303 298 return DSERR_INVALIDPARAM; … … 311 306 HRESULT WIN32API SoundInitialize(THIS_ LPGUID) 312 307 { 313 dprintf(("DSOUND-OS2IDirectSound::Initialize NOP \n"));314 return DS_OK; 315 } 316 //****************************************************************************** 317 //****************************************************************************** 308 dprintf(("DSOUND-OS2IDirectSound::Initialize NOP")); 309 return DS_OK; 310 } 311 //****************************************************************************** 312 //****************************************************************************** -
trunk/src/dsound/OS2SNDBUFFER.CPP
r5285 r5292 1 /* $Id: OS2SNDBUFFER.CPP,v 1. 9 2001-03-06 20:11:16 mike Exp $ */1 /* $Id: OS2SNDBUFFER.CPP,v 1.10 2001-03-10 06:21:06 mike Exp $ */ 2 2 3 3 /* … … 5 5 * 6 6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl) 7 * Copyright 200 0Michal Necasek7 * Copyright 2001 Michal Necasek 8 8 * 9 9 * Project Odin Software License can be found in LICENSE.TXT … … 50 50 : Referenced(0), lastError(DS_OK) 51 51 { 52 //This is the "normal" constructor 52 53 lpVtbl = &Vtbl; 53 54 Vtbl.AddRef = SoundBufAddRef; … … 110 111 DSpan = 0; 111 112 lpfxFormat= NULL; 112 lpBuffer = NULL;113 113 fPlaying = FALSE; 114 114 fLoop = FALSE; … … 135 135 dprintf((" Buffer format: %dHz, %dbit, %d channels", lpfxFormat->nSamplesPerSec, lpfxFormat->wBitsPerSample, lpfxFormat->nChannels)); 136 136 137 lp Buffer = (LPSTR)VirtualAlloc(0, bufferdesc.dwBufferBytes, MEM_COMMIT, PAGE_READWRITE);138 if (lp Buffer == NULL) {137 lpSndBuffer = (SOUNDBUF*)VirtualAlloc(0, bufferdesc.dwBufferBytes + sizeof(DWORD), MEM_COMMIT, PAGE_READWRITE); 138 if (lpSndBuffer == NULL) { 139 139 dprintf(("VirtualAlloc failed")); 140 lp Buffer = NULL;140 lpSndBuffer = NULL; 141 141 lastError = DSERR_OUTOFMEMORY; 142 142 return; 143 143 } 144 lpBuffer = &(lpSndBuffer->pData[0]); 145 lpSndBuffer->dwReferences = 1; 146 147 next = dsbroot; 148 dsbroot = this; 149 } 150 151 //****************************************************************************** 152 //****************************************************************************** 153 OS2IDirectSoundBuffer::OS2IDirectSoundBuffer(OS2IDirectSound *DSound, OS2IDirectSoundBuffer *srcBuf) 154 : Referenced(0), lastError(DS_OK) 155 { 156 //This is the constructor used for duplicating sound buffers 157 lpVtbl = &Vtbl; 158 Vtbl.AddRef = SoundBufAddRef; 159 Vtbl.Release = SoundBufRelease; 160 Vtbl.QueryInterface = SoundBufQueryInterface; 161 Vtbl.GetCaps = SoundBufGetCaps; 162 Vtbl.GetFormat = SoundBufGetFormat; 163 Vtbl.GetVolume = SoundBufGetVolume; 164 Vtbl.GetStatus = SoundBufGetStatus; 165 Vtbl.GetCurrentPosition = SoundBufGetCurrentPosition; 166 Vtbl.GetPan = SoundBufGetPan; 167 Vtbl.GetFrequency = SoundBufGetFrequency; 168 Vtbl.Initialize = SoundBufInitialize; 169 Vtbl.Restore = SoundBufRestore; 170 Vtbl.SetFormat = SoundBufSetFormat; 171 Vtbl.SetVolume = SoundBufSetVolume; 172 Vtbl.SetCurrentPosition = SoundBufSetCurrentPosition; 173 Vtbl.SetPan = SoundBufSetPan; 174 Vtbl.SetFrequency = SoundBufSetFrequency; 175 Vtbl.Lock = SoundBufLock; 176 Vtbl.Unlock = SoundBufUnlock; 177 Vtbl.Stop = SoundBufStop; 178 Vtbl.Play = SoundBufPlay; 179 180 dprintf(("DSOUND-OS2IDirectSoundBuffer::OS2IDirectSoundBuffer/Duplicate (buf=%X)", this)); 181 182 if (srcBuf->fPrimary) { 183 dprintf(("Error: Cannot duplicate primary sound buffer!")); 184 lpBuffer = NULL; 185 lastError = DSERR_INVALIDPARAM; 186 return; 187 } 188 189 // get the primary buffer from the DSound instance. 190 primary = DSound->primary; 191 192 // No need to check if primary exists - it has to (this can't be the first 193 // secondary buffer being created) 194 195 // Add a reference to the primary buffer for _every_ secondary buffer; this makes 196 // sure that as long as a secondary buffer exists the primary buffer won't get 197 // destroyed; moreover if the user didn't create a primary buffer himself/herself, 198 // it will automatically get created and destroyed with the last secondary buffer 199 primary->Vtbl.AddRef(primary); 200 201 parentDS = DSound; 202 writepos = 0; 203 playpos = 0; 204 status = 0; 205 fLocked = FALSE; 206 fPrimary = FALSE; 207 volume = srcBuf->volume; 208 DSvolume = srcBuf->DSvolume; 209 pan = srcBuf->pan; 210 DSpan = srcBuf->DSpan; 211 lpBuffer = srcBuf->lpBuffer; 212 fPlaying = FALSE; 213 fLoop = srcBuf->fLoop; 214 notify = NULL; 215 memcpy(&bufferdesc, &(srcBuf->bufferdesc), sizeof(DSBUFFERDESC)); 216 217 // Note: this cannot be a primary buffer - those take a different route 218 219 // frequency has to be set according to the bufer format 220 frequency = srcBuf->frequency; 221 222 lpfxFormat = (WAVEFORMATEX *)malloc(sizeof(WAVEFORMATEX)); 223 memcpy(lpfxFormat,srcBuf->lpfxFormat, 224 sizeof(WAVEFORMATEX)); 225 226 dprintf((" Buffer format: %dHz, %dbit, %d channels", lpfxFormat->nSamplesPerSec, lpfxFormat->wBitsPerSample, lpfxFormat->nChannels)); 227 228 // Increment reference count for the buffer memory 229 lpSndBuffer = srcBuf->lpSndBuffer; 230 lpSndBuffer->dwReferences++; 144 231 145 232 next = dsbroot; … … 157 244 dprintf(("DSOUND-OS2IDirectSoundBuffer::~OS2IDirectSoundBuffer (buf=%X)", this)); 158 245 159 // free allocted memory 160 if (lpBuffer) 161 VirtualFree(lpBuffer, 0, MEM_RELEASE); 246 // free allocted memory - unless it's shared by a duplicated buffer 247 if (lpSndBuffer) { 248 lpSndBuffer->dwReferences--; 249 if (lpSndBuffer->dwReferences == 0) 250 VirtualFree(lpSndBuffer, 0, MEM_RELEASE); 251 } 162 252 163 253 if (lpfxFormat) … … 328 418 return DSERR_INVALIDPARAM; 329 419 } 330 copysize = MIN(ddwSizeAllocated, (me->lpfxFormat->cbSize + sizeof(WAVEFORMATEX)));420 copysize = min(ddwSizeAllocated, (me->lpfxFormat->cbSize + sizeof(WAVEFORMATEX))); 331 421 memcpy(lpwfxFormat, me->lpfxFormat, copysize); 332 422 … … 457 547 { 458 548 OS2IDirectSoundBuffer *me = (OS2IDirectSoundBuffer *)This; 549 550 ULONG ulBytesToPlay; 459 551 460 552 dprintf(("DSOUND-OS2IDirectSoundBuffer::SoundBufPlay (buf=%X)", me)); -
trunk/src/dsound/OS2SNDBUFFER.H
r3555 r5292 1 /* $Id: OS2SNDBUFFER.H,v 1. 7 2000-05-18 20:37:09mike Exp $ */1 /* $Id: OS2SNDBUFFER.H,v 1.8 2001-03-10 06:21:06 mike Exp $ */ 2 2 3 3 /* … … 18 18 #define THIS_ VOID*This, 19 19 20 // simple structure to handle duplicated buffers - the first DWORD of 21 // a sound buffer contains the buffer's usage count (to prevent freeing 22 // of buffers still in use) 23 typedef struct _SOUNDBUF { 24 DWORD dwReferences; 25 char pData[1]; 26 } SOUNDBUF; 27 20 28 // a forward declaration of some classes is needed here! 21 29 class OS2IDirectSoundNotify; … … 31 39 32 40 OS2IDirectSoundBuffer(OS2IDirectSound *DSound, const DSBUFFERDESC *lpDSBufferDesc); 41 OS2IDirectSoundBuffer(OS2IDirectSound *DSound, OS2IDirectSoundBuffer *srcBuf); 33 42 OS2IDirectSoundBuffer() {}; 34 43 ~OS2IDirectSoundBuffer(); … … 39 48 inline HRESULT GetLastError() { return lastError; }; 40 49 inline void SetNotify(OS2IDirectSoundNotify *_notify) { 41 50 notify = _notify; }; 42 51 inline void Set3DBuffer(OS2IDirectSound3DBuffer *_buffer3D) { 43 52 buffer3D = _buffer3D; }; 44 53 private: 45 54 … … 61 70 LONG frac; // saved mixer position overflow 62 71 63 char *lpBuffer; // sound data 72 SOUNDBUF *lpSndBuffer; // sound data + reference count 73 char *lpBuffer; // actual sound data 64 74 65 75 OS2IDirectSoundNotify* notify; // pointer to the associated Notify object (if exists)
Note:
See TracChangeset
for help on using the changeset viewer.