Changeset 3555 for trunk/src


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

Updated and slightly fixed DSOUND

Location:
trunk/src/dsound
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/dsound/Dart.h

    r3099 r3555  
    22#define INVALID_PARMS 1
    33#define OUT_OF_MEMORY 2
     4
    45
    56#ifdef DART_DSOUND
     
    3031#endif
    3132
     33
    3234#define BUFFER_SIZE 32768
    3335
  • trunk/src/dsound/OS2DSOUND.CPP

    r3099 r3555  
    1 /* $Id: OS2DSOUND.CPP,v 1.6 2000-03-13 12:47:46 sandervl Exp $ */
     1/* $Id: OS2DSOUND.CPP,v 1.7 2000-05-18 20:37:08 mike Exp $ */
    22
    33/*
     
    1717#include <stdlib.h>
    1818#include <string.h>
     19
     20
     21
     22#include <stdio.h> /****** DEBUGGING ********/
     23
     24
    1925
    2026#define INITGUID
     
    6167   OS2IDirectSound::fDSExists = TRUE;
    6268
     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
    6384   dprintf(("Sound init OK\n"));
    6485}
     
    150171
    151172   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
    152180      OS2PrimBuff *primbuff;
    153181      primbuff = new OS2PrimBuff(me, lpDSBufferDesc);
     
    166194      primbuff->Vtbl.AddRef(primbuff);
    167195      dprintf(("Created PrimBuff... Exiting Create Buffer function\n"));
    168 
     196*/
     197
     198      *lplpDirectSoundBuffer = (LPDIRECTSOUNDBUFFER)me->primary;
    169199      return DS_OK;
    170200   }
  • trunk/src/dsound/OS2DSOUND.H

    r3099 r3555  
    1 /* $Id: OS2DSOUND.H,v 1.5 2000-03-13 12:47:46 sandervl Exp $ */
     1/* $Id: OS2DSOUND.H,v 1.6 2000-05-18 20:37:08 mike Exp $ */
    22
    33/*
     
    1818#define THIS_ VOID*This,
    1919
     20// A forward declaration is need here!
     21class OS2PrimBuff;
     22
    2023class OS2IDirectSound
    2124{
     
    3336    inline  HRESULT       GetLastError()    { return lastError;    };
    3437    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?)
    3541
    3642 private:
  • trunk/src/dsound/OS2PrimBuff.cpp

    r3100 r3555  
    1212/*  NOTES:
    1313
    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
    2617      that the Win32 program can write to. The GetPosition function will
    2718      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).
    3225
    3326*/
     
    4235#include <dsound.h>
    4336
    44 #include "DSound.h"
     37//#include "DSound.h"
    4538#include "OS2DSound.h"
    4639#include "OS2SndBuffer.h"
     
    159152      return DS_OK;
    160153   }
     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???
    161157
    162158   return E_NOINTERFACE;
     
    528524HRESULT __stdcall PrimBufUnlock(THIS_ LPVOID,DWORD,LPVOID,DWORD )
    529525{
    530    // I don't think we really need any code here.. This may be a handly place to
     526   // I don't think we really need any code here..
    531527
    532528   dprintf(("DSOUND-PrimBuff: Unlock"));
     
    539535HRESULT __stdcall PrimBufRestore(THIS )
    540536{
     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
    541541   dprintf(("DSOUND-PrimBuff: Restore"));
    542542
  • trunk/src/dsound/OS2PrimBuff.h

    r3099 r3555  
    11/*
    2  * Direct Sound Primary Buffer Implemetation ofr ODIN
     2 * Direct Sound Primary Buffer Implemetation for ODIN
    33 *
    4  * Kevin Langman
     4 * Kevin Langman (langman@earthling.net)
    55 *
    66 * 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 sandervl Exp $ */
     1/* $Id: OS2SNDBUFFER.CPP,v 1.8 2000-05-18 20:37:09 mike Exp $ */
    22
    33/*
     
    7575   dprintf(("DSOUND-OS2IDirectSoundBuffer::OS2IDirectSoundBuffer (buf=%X)", this));
    7676
     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!
    7781   // If the primary SoundBuffer doesn't exist by now, we have to create it!
    7882   if (primary == NULL) {
  • trunk/src/dsound/OS2SNDBUFFER.H

    r3099 r3555  
    1 /* $Id: OS2SNDBUFFER.H,v 1.6 2000-03-13 12:47:48 sandervl Exp $ */
     1/* $Id: OS2SNDBUFFER.H,v 1.7 2000-05-18 20:37:09 mike Exp $ */
    22
    33/*
     
    2121class OS2IDirectSoundNotify;
    2222class OS2IDirectSound3DBuffer;
     23class OS2IDirectSound;
    2324
    2425class OS2IDirectSoundBuffer
  • 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}
  • trunk/src/dsound/dsmixer.cpp

    r3099 r3555  
    183183      data8b = (unsigned char *) outBuf->lpBuffer;
    184184      for (i = 0; i < tomix * outnch; i++) {
    185          if (mixbuf[i] <= -32768) data16b[outpos] = 0;
    186          else if (mixbuf[i] >= 32767) data16b[outpos] = 255;
    187          else data16b[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;
    188188         outpos++;
    189189         if (outpos >= outlen) outpos = 0;
Note: See TracChangeset for help on using the changeset viewer.