Changeset 1744 for trunk/src/dsound/OS2SNDBUFFER.CPP
- Timestamp:
- Nov 14, 1999, 11:12:15 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/dsound/OS2SNDBUFFER.CPP
r1421 r1744 1 /* $Id: OS2SNDBUFFER.CPP,v 1. 4 1999-10-23 23:00:49 sandervlExp $ */1 /* $Id: OS2SNDBUFFER.CPP,v 1.5 1999-11-14 22:12:15 hugh Exp $ */ 2 2 3 3 /* … … 14 14 * Header Files * 15 15 *******************************************************************************/ 16 #define INCL_DOSMISC 16 17 #include <os2win.h> 17 18 #include <stdlib.h> … … 23 24 #include "os2dsound.h" 24 25 #include "os2sndbuffer.h" 25 #include "misc.h" 26 26 #include <misc.h> 27 28 29 extern DWORD GetTickCountOS2(); 30 31 WAVEFORMATEX wfxDefaultPrimaryBuf = { WAVE_FORMAT_PCM, 32 2, 33 22050, 34 44100, 35 2, 36 8, 37 0}; 27 38 28 39 //****************************************************************************** … … 61 72 lpfxFormat= NULL; 62 73 lpBuffer = NULL; 63 74 fPlaying = FALSE; 75 fLoop = FALSE; 76 newWritePos = 0; 77 LastTickCnt = 0; 64 78 memcpy(&bufferdesc, lpDSBufferDesc, sizeof(DSBUFFERDESC)); 65 if(!(bufferdesc.dwFlags & DSBCAPS_PRIMARYBUFFER)) { 66 if(bufferdesc.lpwfxFormat == NULL || bufferdesc.dwBufferBytes == 0) { 67 dprintf(("bufferdesc not valid!")); 68 lastError = DSERR_INVALIDPARAM; 69 return; 70 } 71 lpfxFormat = (WAVEFORMATEX *)malloc(bufferdesc.lpwfxFormat->cbSize + sizeof(WAVEFORMATEX)); 72 memcpy(lpfxFormat, bufferdesc.lpwfxFormat, bufferdesc.lpwfxFormat->cbSize + sizeof(WAVEFORMATEX)); 73 74 lpBuffer = (LPSTR)VirtualAlloc(0, bufferdesc.dwBufferBytes, MEM_COMMIT, PAGE_READWRITE); 75 if(lpBuffer == NULL) { 76 dprintf(("VirtualAlloc failed")); 77 lpBuffer = NULL; 78 lastError = DSERR_OUTOFMEMORY; 79 return; 80 } 81 } 82 else {//todo: primary buffer 79 80 if(bufferdesc.dwFlags & DSBCAPS_PRIMARYBUFFER) 81 { 82 // Primary Buffer 83 // Fake this for now and setup the default values for it 84 //todo: Do the primary buffer right 85 bufferdesc.dwBufferBytes = 4096; 86 bufferdesc.lpwfxFormat = &wfxDefaultPrimaryBuf; 87 88 } 89 90 if(bufferdesc.lpwfxFormat == NULL || bufferdesc.dwBufferBytes == 0) 91 { 92 dprintf(("bufferdesc not valid!")); 93 lastError = DSERR_INVALIDPARAM; 94 return; 95 } 96 97 lpfxFormat = (WAVEFORMATEX *)malloc(bufferdesc.lpwfxFormat->cbSize + sizeof(WAVEFORMATEX)); 98 memcpy( lpfxFormat, 99 bufferdesc.lpwfxFormat, 100 bufferdesc.lpwfxFormat->cbSize + sizeof(WAVEFORMATEX)); 101 102 lpBuffer = (LPSTR)VirtualAlloc( 0, bufferdesc.dwBufferBytes, MEM_COMMIT, PAGE_READWRITE); 103 if(lpBuffer == NULL) 104 { 105 dprintf(("VirtualAlloc failed")); 106 lpBuffer = NULL; 107 lastError = DSERR_OUTOFMEMORY; 108 return; 83 109 } 84 110 } … … 98 124 { 99 125 dprintf(("OS2IDirectSoundBuffer::QueryInterface\n")); 100 if(This == NULL) { 126 if(This == NULL) 127 { 101 128 return DSERR_INVALIDPARAM; 102 129 } … … 118 145 119 146 dprintf(("OS2IDirectSoundBuffer::AddRef %d\n", me->Referenced+1)); 120 if(me == NULL) { 147 if(me == NULL) 148 { 121 149 return 0; 122 150 } … … 129 157 OS2IDirectSoundBuffer *me = (OS2IDirectSoundBuffer *)This; 130 158 131 dprintf((" OS2IDirectSoundBuffer::Release %d\n", me->Referenced-1)); 132 if(me == NULL) { 159 dprintf(("OS2IDirectSoundBuffer::Release %d\n", me->Referenced-1)); 160 if(me == NULL) 161 { 133 162 return 0; 134 163 } 135 if(me->Referenced) { 164 if(me->Referenced) 165 { 136 166 me->Referenced--; 137 if(me->Referenced == 0) { 138 delete me; 139 return(0); 140 } 141 else return me->Referenced; 142 } 143 else return(0); 167 if(me->Referenced == 0) 168 { 169 delete me; 170 return(0); 171 } 172 else 173 return me->Referenced; 174 } 175 else 176 return(0); 144 177 } 145 178 //****************************************************************************** … … 149 182 OS2IDirectSoundBuffer *me = (OS2IDirectSoundBuffer *)This; 150 183 151 dprintf(("SoundBufGetCaps")); 152 if(me == NULL || lpDSCaps == NULL) { 184 dprintf(("OS2IDirectSoundBuffer::SoundBufGetCaps")); 185 if(me == NULL || lpDSCaps == NULL) 186 { 153 187 return DSERR_INVALIDPARAM; 154 188 } … … 162 196 OS2IDirectSoundBuffer *me = (OS2IDirectSoundBuffer *)This; 163 197 164 dprintf(("SoundBufGetCurrentPosition")); 165 if(me == NULL || lpdwCurrentPlayCursor == NULL || lpdwCurrentWriteCursor == NULL) { 166 return DSERR_INVALIDPARAM; 167 } 198 dprintf(("OS2IDirectSoundBuffer::SoundBufGetCurrentPosition")); 199 if( me == NULL || lpdwCurrentPlayCursor == NULL || lpdwCurrentWriteCursor == NULL) 200 { 201 dprintf((" Invalid parameters %d %d %d",me,lpdwCurrentPlayCursor,lpdwCurrentWriteCursor)); 202 return DSERR_INVALIDPARAM; 203 } 204 205 // Simply advance the bufferpointer according to time; 206 if(me->fPlaying) 207 { 208 ULONG CurrentTicks, Ticks, NewPos; 209 CurrentTicks = GetTickCountOS2(); 210 Ticks = CurrentTicks-me->LastTickCnt; 211 dprintf((" Is Playing, Ticks: Last %d Current %d Difference %d",me->LastTickCnt, CurrentTicks,Ticks)); 212 me->LastTickCnt = CurrentTicks; 213 214 NewPos = ((me->frequency*Ticks)/1000)*(me->bufferdesc.lpwfxFormat->wBitsPerSample/8); 215 dprintf((" advance pos by %d bytes",NewPos)); 216 217 if(me->playpos+NewPos >= me->bufferdesc.dwBufferBytes) 218 { 219 if(me->fLoop) 220 { 221 me->playpos = (me->playpos+NewPos) % me->bufferdesc.dwBufferBytes; 222 } 223 else 224 { 225 me->playpos = me->bufferdesc.dwBufferBytes; 226 me->fPlaying = FALSE; 227 } 228 229 } 230 else 231 { 232 me->playpos += NewPos; 233 } 234 me->writepos = me->playpos + 2048; 235 if(me->writepos >= me->bufferdesc.dwBufferBytes) 236 me->writepos = me->writepos % me->bufferdesc.dwBufferBytes; 237 238 } 239 else 240 { 241 dprintf((" Buffer Not playing")); 242 } 243 dprintf((" Buffer %d: PlayPos %d, WritePos %d\n",me, me->playpos,me->writepos)); 168 244 *lpdwCurrentPlayCursor = me->playpos; 169 245 *lpdwCurrentWriteCursor = me->writepos; … … 178 254 int copysize; 179 255 180 dprintf(("SoundBufGetFormat")); 181 if(me == NULL || lpwfxFormat == NULL || ddwSizeAllocated == 0) { 256 dprintf(("OS2IDirectSoundBuffer::SoundBufGetFormat")); 257 if( me == NULL || lpwfxFormat == NULL || ddwSizeAllocated == 0) 258 { 182 259 return DSERR_INVALIDPARAM; 183 260 } … … 185 262 memcpy(lpwfxFormat, me->lpfxFormat, copysize); 186 263 187 if(lpdwSizeWritten) { 264 if(lpdwSizeWritten) 265 { 188 266 *lpdwSizeWritten = copysize; 189 267 } … … 196 274 OS2IDirectSoundBuffer *me = (OS2IDirectSoundBuffer *)This; 197 275 198 dprintf(("SoundBufGetVolume")); 199 if(me == NULL || lplVolume == NULL) { 276 dprintf(("OS2IDirectSoundBuffer::SoundBufGetVolume")); 277 if(me == NULL || lplVolume == NULL) 278 { 200 279 return DSERR_INVALIDPARAM; 201 280 } … … 209 288 OS2IDirectSoundBuffer *me = (OS2IDirectSoundBuffer *)This; 210 289 211 dprintf(("SoundBufGetPan")); 212 if(me == NULL || lplPan == NULL) { 290 dprintf(("OS2IDirectSoundBuffer::SoundBufGetPan")); 291 if(me == NULL || lplPan == NULL) 292 { 213 293 return DSERR_INVALIDPARAM; 214 294 } … … 222 302 OS2IDirectSoundBuffer *me = (OS2IDirectSoundBuffer *)This; 223 303 224 dprintf(("SoundBufGetFrequency")); 225 if(me == NULL || lpdwFrequency == NULL) { 304 dprintf(("OS2IDirectSoundBuffer::SoundBufGetFrequency")); 305 if(me == NULL || lpdwFrequency == NULL) 306 { 226 307 return DSERR_INVALIDPARAM; 227 308 } … … 235 316 OS2IDirectSoundBuffer *me = (OS2IDirectSoundBuffer *)This; 236 317 237 dprintf(("SoundBufGetStatus")); 238 if(me == NULL || lpdwStatus == NULL) { 318 dprintf(("OS2IDirectSoundBuffer::SoundBufGetStatus")); 319 if(me == NULL || lpdwStatus == NULL) 320 { 239 321 return DSERR_INVALIDPARAM; 240 322 } … … 249 331 250 332 dprintf(("SoundBufInitialize")); 251 if(me == NULL) { 333 if(me == NULL) 334 { 252 335 return DSERR_INVALIDPARAM; 253 336 } … … 263 346 OS2IDirectSoundBuffer *me = (OS2IDirectSoundBuffer *)This; 264 347 265 dprintf(("SoundBufLock")); 266 if(me == NULL || !lplpvAudioPtr1 || !lpdwAudioBytes1) { 348 dprintf(("OS2IDirectSoundBuffer::SoundBufLock")); 349 if(me == NULL || !lplpvAudioPtr1 || !lpdwAudioBytes1) 350 { 267 351 return(DSERR_INVALIDPARAM); 268 352 } 269 353 //not sure if this is an error, but it's certainly a smart thing to do (cond. == true) 270 if(dwWriteBytes > me->bufferdesc.dwBufferBytes) { 354 if(dwWriteBytes > me->bufferdesc.dwBufferBytes) 355 { 271 356 dprintf(("SoundBufLock: dwWriteBytes > me->bufferdesc.dwBufferBytes")); 272 357 return(DSERR_INVALIDPARAM); 273 358 } 274 if(dwFlags & DSBLOCK_FROMWRITECURSOR) { 359 if(dwFlags & DSBLOCK_FROMWRITECURSOR) 360 { 275 361 dwWriteCursor = me->writepos; 276 362 } 277 if(dwWriteCursor + dwWriteBytes > me->bufferdesc.dwBufferBytes ) { 363 if(dwWriteCursor + dwWriteBytes > me->bufferdesc.dwBufferBytes ) 364 { 278 365 *(DWORD *)lplpvAudioPtr1 = (DWORD)(me->lpBuffer + dwWriteCursor); 279 366 *lpdwAudioBytes1 = me->bufferdesc.dwBufferBytes - dwWriteCursor; 280 if(lplpvAudioPtr2 && lpdwAudioBytes2) { 367 if(lplpvAudioPtr2 && lpdwAudioBytes2) 368 { 281 369 *(DWORD *)lplpvAudioPtr2 = (DWORD)me->lpBuffer; 282 370 *lpdwAudioBytes2 = dwWriteBytes - *lpdwAudioBytes1; 283 371 } 284 372 } 285 else { 373 else 374 { 286 375 *(DWORD *)lplpvAudioPtr1 = (DWORD)(me->lpBuffer + dwWriteCursor); 287 376 *lpdwAudioBytes1 = dwWriteBytes; 288 if(lplpvAudioPtr2 && lpdwAudioBytes2) { 377 if(lplpvAudioPtr2 && lpdwAudioBytes2) 378 { 289 379 *(DWORD *)lplpvAudioPtr2 = 0; 290 380 *lpdwAudioBytes2 = 0; … … 296 386 //****************************************************************************** 297 387 //****************************************************************************** 298 HRESULT __stdcall SoundBufPlay(THIS_ DWORD,DWORD,DWORD ) 299 { 300 OS2IDirectSoundBuffer *me = (OS2IDirectSoundBuffer *)This; 301 302 dprintf(("SoundBufPlay")); 303 if(me == NULL) { 304 return DSERR_INVALIDPARAM; 305 } 388 HRESULT __stdcall SoundBufPlay(THIS_ DWORD dwRes1,DWORD dwRes2,DWORD dwFlags) 389 { 390 OS2IDirectSoundBuffer *me = (OS2IDirectSoundBuffer *)This; 391 392 dprintf(("OS2IDirectSoundBuffer::SoundBufPlay")); 393 if(me == NULL) 394 { 395 dprintf((" Invalid parms me is NULL\n")); 396 return DSERR_INVALIDPARAM; 397 } 398 me->fPlaying = TRUE; 399 me->fLoop = dwFlags == DSBPLAY_LOOPING; 400 me->LastTickCnt = GetTickCountOS2(); 401 dprintf((" Buffer %d: Start at Tick %d Loop %s",me,me->LastTickCnt,me->fLoop?"YES":"NO")); 306 402 return DS_OK; 307 403 } … … 312 408 OS2IDirectSoundBuffer *me = (OS2IDirectSoundBuffer *)This; 313 409 314 dprintf(("SoundBufSetCurrentPosition")); 315 if(me == NULL) { 410 dprintf(("OS2IDirectSoundBuffer::SoundBufSetCurrentPosition")); 411 if(me == NULL) 412 { 316 413 return DSERR_INVALIDPARAM; 317 414 } … … 327 424 OS2IDirectSoundBuffer *me = (OS2IDirectSoundBuffer *)This; 328 425 329 dprintf(("SoundBufSetFormat")); 330 if(me == NULL) { 426 dprintf(("OS2IDirectSoundBuffer::SoundBufSetFormat")); 427 if(me == NULL) 428 { 331 429 return DSERR_INVALIDPARAM; 332 430 } … … 339 437 OS2IDirectSoundBuffer *me = (OS2IDirectSoundBuffer *)This; 340 438 341 dprintf(("SoundBufSetVolume")); 342 if(me == NULL) { 439 dprintf(("OS2IDirectSoundBuffer::SoundBufSetVolume")); 440 if(me == NULL) 441 { 343 442 return DSERR_INVALIDPARAM; 344 443 } … … 352 451 OS2IDirectSoundBuffer *me = (OS2IDirectSoundBuffer *)This; 353 452 354 dprintf(("SoundBufSetPan")); 355 if(me == NULL) { 453 dprintf(("OS2IDirectSoundBuffer::SoundBufSetPan")); 454 if(me == NULL) 455 { 356 456 return DSERR_INVALIDPARAM; 357 457 } … … 365 465 OS2IDirectSoundBuffer *me = (OS2IDirectSoundBuffer *)This; 366 466 367 dprintf(("SoundBufSetFrequency")); 368 if(me == NULL) { 467 dprintf(("OS2IDirectSoundBuffer::SoundBufSetFrequency")); 468 if(me == NULL) 469 { 369 470 return DSERR_INVALIDPARAM; 370 471 } … … 378 479 OS2IDirectSoundBuffer *me = (OS2IDirectSoundBuffer *)This; 379 480 380 dprintf(("SoundBufStop")); 381 if(me == NULL) { 382 return DSERR_INVALIDPARAM; 481 dprintf(("OS2IDirectSoundBuffer::SoundBufStop")); 482 if(me == NULL) 483 { 484 return DSERR_INVALIDPARAM; 485 } 486 // Simply advance the bufferpointer according to time; 487 if(me->fPlaying) 488 { 489 ULONG CurrentTicks, Ticks, NewPos; 490 CurrentTicks = GetTickCountOS2(); 491 492 Ticks = CurrentTicks - me->LastTickCnt; 493 me->LastTickCnt = CurrentTicks; 494 495 NewPos = ((me->frequency*Ticks)/1000)*(me->bufferdesc.lpwfxFormat->wBitsPerSample>>8); 496 if(me->playpos+NewPos >= me->bufferdesc.dwBufferBytes) 497 { 498 if(me->fLoop) 499 { 500 me->playpos = (me->playpos+NewPos % me->bufferdesc.dwBufferBytes); 501 } 502 else 503 { 504 me->playpos = me->bufferdesc.dwBufferBytes; 505 me->fPlaying = FALSE; 506 } 507 508 } 509 else 510 { 511 me->playpos += NewPos; 512 } 513 me->writepos = me->playpos + 2048; 514 if(me->writepos >= me->bufferdesc.dwBufferBytes) 515 me->writepos = me->writepos % me->bufferdesc.dwBufferBytes; 516 517 me->fPlaying = FALSE; 518 383 519 } 384 520 return DS_OK; … … 390 526 OS2IDirectSoundBuffer *me = (OS2IDirectSoundBuffer *)This; 391 527 392 dprintf(("SoundBufUnlock")); 393 if(me == NULL) { 528 dprintf(("OS2IDirectSoundBuffer::SoundBufUnlock")); 529 if(me == NULL) 530 { 394 531 return DSERR_INVALIDPARAM; 395 532 } … … 402 539 OS2IDirectSoundBuffer *me = (OS2IDirectSoundBuffer *)This; 403 540 404 dprintf(("SoundBufRestore")); 405 if(me == NULL) { 406 return DSERR_INVALIDPARAM; 407 } 408 return DS_OK; 409 } 410 //****************************************************************************** 411 //****************************************************************************** 541 dprintf(("OS2IDirectSoundBuffer::SoundBufRestore")); 542 if(me == NULL) 543 { 544 return DSERR_INVALIDPARAM; 545 } 546 return DS_OK; 547 } 548 //****************************************************************************** 549 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.