Ignore:
Timestamp:
May 18, 2000, 10:37:10 PM (25 years ago)
Author:
mike
Message:

Updated and slightly fixed DSOUND

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/dsound/dart.cpp

    r3099 r3555  
    11/*
     2 *  Dart Interface..
     3 *
    24 *  Kevin Langman
    35 *
    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
    67 *
    78 */
     
    1213#include <os2mewrap.h>
    1314
     15#include <stdio.h>
    1416#include <stdlib.h>
    1517#include <string.h>
     
    4345   ULONG           rc;
    4446
    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     )
    4851   {
    4952      lLastBuff++;
    50       if (lLastBuff == ulNumDartBuffs)
     53      if (lLastBuff == ulNumDartBuffs){
    5154         lLastBuff = 0;
     55      }
     56
     57      if( fIsPlaying == FALSE /*&& lLastBuff == 0*/ ){
     58         mciSendCommand(usDeviceID, MCI_STOP, MCI_WAIT, NULL, 0);
     59         return TRUE;
     60      }
    5261
    5362      /* Now mix sound from all playing secondary SoundBuffers into the primary buffer */
     
    5968      /* Send the NEXT Buffer to Dart for playing! */
    6069      rc = MixSetup_Global->pmixWrite(MixSetup_Global->ulMixHandle, &pMixBuffers[lLastBuff], 1 );
    61       //dprintf(("DSOUND-DART: Playing Next Buffer %d", rc));
    6270   }
    6371
     
    104112   memset(&AmpOpenParms, 0, sizeof(MCI_AMP_OPEN_PARMS));
    105113   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);
    107116
    108117   rc = mciSendCommand(0, MCI_OPEN, MCI_WAIT | MCI_OPEN_TYPE_ID, (PVOID)&AmpOpenParms, 0);
     
    133142   /* Create the Audio Buffer */
    134143   // 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 by
    136    // using 16 1kb buffers and do locking by tracking what buffer is currently
    137    // playing. This maybe less CPU friendly then other methods but it's the best
    138    // 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!!
    139148
    140149   MixSetupParms.ulBufferSize = BUFFER_SIZE / ulNumDartBuffs;
     
    153162
    154163   /* 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.
    160165   for (device = 0; device < ulNumDartBuffs; device++) {
    161       memset(pMixBuffers[device].pBuffer, 0, BUFFER_SIZE/ulNumDartBuffs);
     166      memset(pMixBuffers[device].pBuffer, 32767, BUFFER_SIZE/ulNumDartBuffs);
    162167   }
    163168
     
    308313
    309314   /* 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! :)
    315318   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! */
    318323
    319324   /* If the primary buffer was playing, we have to restart it!! */
     
    347352
    348353   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
    355368   return DS_OK;
    356369}
Note: See TracChangeset for help on using the changeset viewer.