Changeset 5292 for trunk/src/dsound/OS2SNDBUFFER.CPP
- Timestamp:
- Mar 10, 2001, 7:21:06 AM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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));
Note:
See TracChangeset
for help on using the changeset viewer.