- Timestamp:
- May 18, 2000, 10:37:10 PM (25 years ago)
- Location:
- trunk/src/dsound
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/dsound/Dart.h
r3099 r3555 2 2 #define INVALID_PARMS 1 3 3 #define OUT_OF_MEMORY 2 4 4 5 5 6 #ifdef DART_DSOUND … … 30 31 #endif 31 32 33 32 34 #define BUFFER_SIZE 32768 33 35 -
trunk/src/dsound/OS2DSOUND.CPP
r3099 r3555 1 /* $Id: OS2DSOUND.CPP,v 1. 6 2000-03-13 12:47:46 sandervlExp $ */1 /* $Id: OS2DSOUND.CPP,v 1.7 2000-05-18 20:37:08 mike Exp $ */ 2 2 3 3 /* … … 17 17 #include <stdlib.h> 18 18 #include <string.h> 19 20 21 22 #include <stdio.h> /****** DEBUGGING ********/ 23 24 19 25 20 26 #define INITGUID … … 61 67 OS2IDirectSound::fDSExists = TRUE; 62 68 69 // Create the primary buffer 70 primary = new OS2PrimBuff(this, /*lpDSBufferDesc*/NULL); 71 if (primary == NULL){ 72 lastError = DSERR_OUTOFMEMORY; 73 return ; 74 } 75 if ( primary->GetLastError() != DS_OK ){ 76 ULONG lastErr = primary->GetLastError(); 77 dprintf(("LastErr = %d\n", lastErr)); 78 delete primary; 79 lastError = lastErr; 80 return; 81 } 82 primary->Vtbl.AddRef(primary); 83 63 84 dprintf(("Sound init OK\n")); 64 85 } … … 150 171 151 172 if (lpDSBufferDesc->dwFlags & DSBCAPS_PRIMARYBUFFER) { 173 174 /* 175 176 // The Primary buffer is now created by the Constructor.. This only 177 // makes sence becuse you can really only have one primary buffer and 178 // you need it before you can to do anything. 179 152 180 OS2PrimBuff *primbuff; 153 181 primbuff = new OS2PrimBuff(me, lpDSBufferDesc); … … 166 194 primbuff->Vtbl.AddRef(primbuff); 167 195 dprintf(("Created PrimBuff... Exiting Create Buffer function\n")); 168 196 */ 197 198 *lplpDirectSoundBuffer = (LPDIRECTSOUNDBUFFER)me->primary; 169 199 return DS_OK; 170 200 } -
trunk/src/dsound/OS2DSOUND.H
r3099 r3555 1 /* $Id: OS2DSOUND.H,v 1. 5 2000-03-13 12:47:46 sandervlExp $ */1 /* $Id: OS2DSOUND.H,v 1.6 2000-05-18 20:37:08 mike Exp $ */ 2 2 3 3 /* … … 18 18 #define THIS_ VOID*This, 19 19 20 // A forward declaration is need here! 21 class OS2PrimBuff; 22 20 23 class OS2IDirectSound 21 24 { … … 33 36 inline HRESULT GetLastError() { return lastError; }; 34 37 inline DWORD GetCoopLevel() { return CoopLevel; }; 38 39 OS2PrimBuff* primary; // Primary Buffer..Created on construct of DSound (KL) 40 // (Public so that the Secondary buffer instances can access this.. Maybe a GetPrimary function would eb better?) 35 41 36 42 private: -
trunk/src/dsound/OS2PrimBuff.cpp
r3100 r3555 12 12 /* NOTES: 13 13 14 1. I have cheaped out and simply send a DSERR_INVALIDCALL return code 15 for many calls. I don't know if DSound does the same or not!! 16 TODO: See if windows returns this in some of the set* functions!!! 17 18 2. The Dart.cpp file is used rather then imbeding code here to avoid 19 problems with using some of the os2 multimedis headders 20 I guess I should use the ODIN version of the API's to avoid 21 the FS reset problem.. This is a TODO! 22 23 3. Here is how the buffers, GetPosition and Lock work: 24 Dart is allocated 16 buffer of 1kb each. These buffers are filled 25 when dart has finished playing one of the buffer, from a 16kb buffer 14 Here is how the buffers, GetPosition and Locking works: 15 Dart is allocated many little buffers. These buffers are filled 16 when dart has finished playing one of the buffer, from a 32kb buffer 26 17 that the Win32 program can write to. The GetPosition function will 27 18 determine what buffer is being played, and return the offset to the 28 end of this buffer. The Lock function will call the GetCurrentPosition 29 function to determine where the end of the currently playing buffer is 30 and allow the Win32 program to lock between that location and 15ms from 31 there (15ms should be past the next buffer). 19 end of this buffer. 20 21 The Lock function will call the GetCurrentPosition function to determine 22 where the end of the currently playing buffer is and allow the Win32 23 program to lock between that location and 15ms from there 24 (15ms should be past the next buffer). 32 25 33 26 */ … … 42 35 #include <dsound.h> 43 36 44 #include "DSound.h"37 //#include "DSound.h" 45 38 #include "OS2DSound.h" 46 39 #include "OS2SndBuffer.h" … … 159 152 return DS_OK; 160 153 } 154 155 // I guess a Notify object should be creaed for the Primary Buffer also.. 156 // Does windows DSound have a notify object for Primary buffer??? 161 157 162 158 return E_NOINTERFACE; … … 528 524 HRESULT __stdcall PrimBufUnlock(THIS_ LPVOID,DWORD,LPVOID,DWORD ) 529 525 { 530 // I don't think we really need any code here.. This may be a handly place to526 // I don't think we really need any code here.. 531 527 532 528 dprintf(("DSOUND-PrimBuff: Unlock")); … … 539 535 HRESULT __stdcall PrimBufRestore(THIS ) 540 536 { 537 // This maybe a good place to re-aquire the device if some other process 538 // has taken the audio focus, but before we do that we need to determine 539 // if we have lost the device and set the falg in the GetStatus method! 540 541 541 dprintf(("DSOUND-PrimBuff: Restore")); 542 542 -
trunk/src/dsound/OS2PrimBuff.h
r3099 r3555 1 1 /* 2 * Direct Sound Primary Buffer Implemetation ofr ODIN2 * Direct Sound Primary Buffer Implemetation for ODIN 3 3 * 4 * Kevin Langman 4 * Kevin Langman (langman@earthling.net) 5 5 * 6 6 * Project Odin Software License can be found in LICENSE.TXT -
trunk/src/dsound/OS2SNDBUFFER.CPP
r3099 r3555 1 /* $Id: OS2SNDBUFFER.CPP,v 1. 7 2000-03-13 12:47:48 sandervlExp $ */1 /* $Id: OS2SNDBUFFER.CPP,v 1.8 2000-05-18 20:37:09 mike Exp $ */ 2 2 3 3 /* … … 75 75 dprintf(("DSOUND-OS2IDirectSoundBuffer::OS2IDirectSoundBuffer (buf=%X)", this)); 76 76 77 // get the primary buffer from the DSound instance. 78 primary = DSound->primary; 79 80 // We can still to the below logic just in case!! Should not be required thow! 77 81 // If the primary SoundBuffer doesn't exist by now, we have to create it! 78 82 if (primary == NULL) { -
trunk/src/dsound/OS2SNDBUFFER.H
r3099 r3555 1 /* $Id: OS2SNDBUFFER.H,v 1. 6 2000-03-13 12:47:48 sandervlExp $ */1 /* $Id: OS2SNDBUFFER.H,v 1.7 2000-05-18 20:37:09 mike Exp $ */ 2 2 3 3 /* … … 21 21 class OS2IDirectSoundNotify; 22 22 class OS2IDirectSound3DBuffer; 23 class OS2IDirectSound; 23 24 24 25 class OS2IDirectSoundBuffer -
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 } -
trunk/src/dsound/dsmixer.cpp
r3099 r3555 183 183 data8b = (unsigned char *) outBuf->lpBuffer; 184 184 for (i = 0; i < tomix * outnch; i++) { 185 if (mixbuf[i] <= -32768) data 16b[outpos] = 0;186 else if (mixbuf[i] >= 32767) data 16b[outpos] = 255;187 else data 16b[outpos] = mixbuf[i] / 256 + 128;185 if (mixbuf[i] <= -32768) data8b[outpos] = 0; 186 else if (mixbuf[i] >= 32767) data8b[outpos] = 255; 187 else data8b[outpos] = mixbuf[i] / 256 + 128; 188 188 outpos++; 189 189 if (outpos >= outlen) outpos = 0;
Note:
See TracChangeset
for help on using the changeset viewer.