Changeset 3555 for trunk/src/dsound/dart.cpp
- Timestamp:
- May 18, 2000, 10:37:10 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/dsound/dart.cpp
r3099 r3555 1 1 /* 2 * Dart Interface.. 3 * 2 4 * Kevin Langman 3 5 * 4 * The Dart functions are here to avoid the conficts with the 5 * the OS/2 mcios2.h, meerror.h, os2medef.h and mmsystem.h 6 * Project Odin Software License can be found in LICENSE.TXT 6 7 * 7 8 */ … … 12 13 #include <os2mewrap.h> 13 14 15 #include <stdio.h> 14 16 #include <stdlib.h> 15 17 #include <string.h> … … 43 45 ULONG rc; 44 46 45 if ((ulFlags == MIX_WRITE_COMPLETE) || 46 ((ulFlags == (MIX_WRITE_COMPLETE | MIX_STREAM_ERROR))&& 47 (ulStatus == ERROR_DEVICE_UNDERRUN))) 47 if( ( (ulFlags == MIX_WRITE_COMPLETE) || 48 ((ulFlags == (MIX_WRITE_COMPLETE | MIX_STREAM_ERROR))&& 49 (ulStatus == ERROR_DEVICE_UNDERRUN)) ) 50 ) 48 51 { 49 52 lLastBuff++; 50 if (lLastBuff == ulNumDartBuffs) 53 if (lLastBuff == ulNumDartBuffs){ 51 54 lLastBuff = 0; 55 } 56 57 if( fIsPlaying == FALSE /*&& lLastBuff == 0*/ ){ 58 mciSendCommand(usDeviceID, MCI_STOP, MCI_WAIT, NULL, 0); 59 return TRUE; 60 } 52 61 53 62 /* Now mix sound from all playing secondary SoundBuffers into the primary buffer */ … … 59 68 /* Send the NEXT Buffer to Dart for playing! */ 60 69 rc = MixSetup_Global->pmixWrite(MixSetup_Global->ulMixHandle, &pMixBuffers[lLastBuff], 1 ); 61 //dprintf(("DSOUND-DART: Playing Next Buffer %d", rc));62 70 } 63 71 … … 104 112 memset(&AmpOpenParms, 0, sizeof(MCI_AMP_OPEN_PARMS)); 105 113 AmpOpenParms.usDeviceID = 0; 106 AmpOpenParms.pszDeviceType = (PSZ)MCI_DEVTYPE_AUDIO_AMPMIX; 114 //AmpOpenParms.pszDeviceType = (PSZ)MCI_DEVTYPE_AUDIO_AMPMIX; 115 AmpOpenParms.pszDeviceType = (PSZ)MAKEULONG(MCI_DEVTYPE_AUDIO_AMPMIX, (USHORT)device); 107 116 108 117 rc = mciSendCommand(0, MCI_OPEN, MCI_WAIT | MCI_OPEN_TYPE_ID, (PVOID)&AmpOpenParms, 0); … … 133 142 /* Create the Audio Buffer */ 134 143 // OK... Since DSound only uses 1 buffer and uses the GetPosition API to 135 // figure out where it can and can't write ,I have emulating this by136 // using 16 1kb buffers and do locking by tracking what buffer is currently137 // playing. This maybe less CPU friendly then other methods but it's the best138 // my little brain could come up with!!144 // figure out where it can and can't write. I have emulating this by 145 // using many smaller buffers and do locking by tracking what buffer that is 146 // currently playing. This maybe less CPU friendly then other methods but 147 // it's the best my little brain could come up with!! 139 148 140 149 MixSetupParms.ulBufferSize = BUFFER_SIZE / ulNumDartBuffs; … … 153 162 154 163 /* Clear the Buffer */ 155 // Todo: I don't know if Dart expects Signed or Unsigned data... This will 156 // ok until I look in to this... Also it may be that Dart uses signed for 157 // 8bit data and unsigned for 16it.. Anyhow the worst that can happen by setting 158 // the buffer to 0 is a click on Dart_Play and a Clink when real sound is written 159 // to the buffer! 164 // Set initial values to 32767 to avoid clicks on start of playback. 160 165 for (device = 0; device < ulNumDartBuffs; device++) { 161 memset(pMixBuffers[device].pBuffer, 0, BUFFER_SIZE/ulNumDartBuffs);166 memset(pMixBuffers[device].pBuffer, 32767, BUFFER_SIZE/ulNumDartBuffs); 162 167 } 163 168 … … 308 313 309 314 /* Clear the Buffer */ 310 // Todo: I don't know if Dart expects Signed or Unsigned data... This will 311 // ok until I look in to this... Also it may be that Dart uses signed for 312 // 8bit data and unsigned for 16it.. Anyhow the worst that can happen by setting 313 // the buffer to 0 is a click on Dart_Play and a Clink when real sound is written 314 // to the buffer! 315 // If the data is 8bit then set values to 127 316 // If the data is 16bit then set values to 32767 317 // Doing this will avoid the clicks at the beging of playback! :) 315 318 for (int i=0; i<ulNumDartBuffs; i++) { 316 memset(pMixBuffers[i].pBuffer, 0, BUFFER_SIZE/ulNumDartBuffs); 317 } 319 memset(pMixBuffers[i].pBuffer, lBPS == 8 ? 127 : 32767, BUFFER_SIZE / ulNumDartBuffs); 320 } 321 322 lLastBuff = 0; /* we have to reset this, the number of buffers probably changed! */ 318 323 319 324 /* If the primary buffer was playing, we have to restart it!! */ … … 347 352 348 353 fIsPlaying = FALSE; 349 // rc = mciSendCommand(usDeviceID, MCI_PAUSE, MCI_WAIT, NULL, 0); 350 rc = mciSendCommand(usDeviceID, MCI_STOP, MCI_WAIT, NULL, 0); 351 if (rc != MCIERR_SUCCESS) { 352 dprintf(("DSOUND-DART: MCI_PAUSE %d", rc)); 353 return DSERR_GENERIC; 354 } 354 355 // The OS2_Dart_Update function is now used to send the MCI_STOP!! 356 // Doing this fixes a bug where after a Dart_Stop call the sound would 357 // continue to loop because the OS2_Dart_Update would send the next 358 // buffer causing Dart to start again.. 359 360 //rc = mciSendCommand(usDeviceID, MCI_STOP, MCI_WAIT, NULL, 0); 361 //if (rc != MCIERR_SUCCESS) { 362 // { FILE *dbf; dbf=fopen("log.log", "a"); fprintf( dbf, "Error in MCI_STOP...\n"); fclose(dbf); } 363 // dprintf(("DSOUND-DART: MCI_PAUSE %d", rc)); 364 // return DSERR_GENERIC; 365 //} 366 367 355 368 return DS_OK; 356 369 }
Note:
See TracChangeset
for help on using the changeset viewer.