Ignore:
Timestamp:
Aug 2, 2010, 11:30:35 PM (15 years ago)
Author:
David Azarewicz
Message:

Fix for when u32 byte counter wraps

File:
1 edited

Legend:

Unmodified
Added
Removed
  • OCO/trunk/drv16/wavestrm.cpp

    r529 r533  
    5555USHORT  WAVESTREAM::_vRealignBuffer(ULONG ulEndPos, PSTREAMBUFFER pBuffer)
    5656{
    57         if (ulEndPos >= pBuffer->ulDonepos) { /* all of the data has been consumed */
     57        if (ARG1_IS_AFTER_OR_EQUAL_TO_ARG2(ulEndPos, pBuffer->ulDonepos)) { /* all of the data has been consumed */
    5858                pBuffer->ulBuffpos = pBuffer->ulBuffsz;
    5959                pBuffer->ulDonepos = 0;
     
    6161        }
    6262
    63         if (ulEndPos >= (pBuffer->ulDonepos - pBuffer->ulBuffpos)) { /* some of the data has been consumed */
     63        if (ARG1_IS_AFTER_OR_EQUAL_TO_ARG2(ulEndPos, (pBuffer->ulDonepos - pBuffer->ulBuffpos))) { /* some of the data has been consumed */
    6464                pBuffer->ulBuffpos = pBuffer->ulDonepos - ulEndPos;
    6565                pBuffer->ulBuffpos &= 0xFFFFFFFC; //keep it on a dword boundary
     
    155155        fUnderrun = TRUE;
    156156        _ulBytesProcessed = 0;
     157        _ulLastPosition = 0;
    157158        _ulBytesWritten = 0;
    158159}
     
    175176
    176177        _ulBytesProcessed = 0;
     178        _ulLastPosition = 0;
    177179        _ulBytesWritten = 0;
    178180        ulStreamState = STREAM_STREAMING;
     
    298300
    299301        if (pahw->Transfer(StreamId, &_configinfo, pDataBuf, ulBuffLeft, &ulBytesWritten) == FALSE) {
    300                 // This could mean that the hardware has underrun TODO: implement underrun logic
     302                // This could mean that the hardware has underrun
    301303                rprintf(("WS::AB: pahw->Transfer failed"));
    302304                return (ULONG)-1;
     
    304306        //dprintf(("WS::AB: %lx of %lx bytes written", ulBytesWritten, ulBuffLeft));
    305307        if (ulBytesWritten == 0) {
    306                 // This could mean that the hardware has underrun TODO: implement underrun logic
     308                // This could mean that the hardware has underrun
    307309                //rprintf(("WS::AddBuffer: 0 of %lx bytes written by transfer", ulBuffLeft));
    308310                return (ULONG)-1;
     
    322324        return ulBytesWritten;
    323325}
     326
    324327//******************************************************************************
    325328// Read data from the audio Buffer.
     
    363366        return TRUE;
    364367}
     368
    365369//******************************************************************************
    366370// called by the irq function in the hardware object when we get an interrupt
     
    377381                        {
    378382                        PSTREAMBUFFER pTemp;
    379                         ULONG   ulBytes;
     383                        ULONG   ulBytes, ulDelta;
    380384
    381385                        // get the stream position. if we get a bad rc or the position is 0
     
    391395                                return;
    392396                        }
    393                         _ulBytesProcessed = ulBytes;
     397
     398                        ulDelta = ulBytes - _ulLastPosition;
     399                        if (ulBytes < _ulLastPosition) { /* the byte counter in uniaud32 has wrapped */
     400                                ulDelta = ulBytes;
     401                                if (_configinfo.ulBytesPerIRQ > ulDelta) ulDelta = _configinfo.ulBytesPerIRQ;
     402                                rprintf(("u32 wrap: BytesProcessed=%lx LastPosition=%lx Bytes=%lx Delta=%lx InProcess=%lx Done=%lx",
     403                                        _ulBytesProcessed, _ulLastPosition, ulBytes, ulDelta, qhInProcess.IsElements(), qhDone.IsElements()));
     404                        }
     405
     406                        _ulBytesProcessed += ulDelta;
     407                        _ulLastPosition = ulBytes;
    394408
    395409                        if(!qhInProcess.IsElements() && !qhDone.IsElements()) {
     
    407421                                // done playing the stream
    408422                                if ((qhDone.Head() == qhDone.Tail()) && !qhInProcess.IsElements()) {  /* only one buffer left */
    409                                         if (_ulBytesProcessed < pTemp->ulDonepos) break;
     423                                        if (ARG1_IS_BEFORE_ARG2(_ulBytesProcessed, pTemp->ulDonepos)) break;
    410424                                } else { /* not the last buffer */
    411                                         /* if the buffer is bigger than BytesPerIRQ and it's not finished yet, hang on to it */
    412                                         if (!usBufferMode && (_ulBytesProcessed < pTemp->ulDonepos)) break;
    413                                         //if ((_ulBytesProcessed + _configinfo.ulBytesPerIRQ) < pTemp->ulDonepos) break;
     425                                        /* if uniaud32 is not done playing the data hang on to the buffer */
     426                                        if (!usBufferMode && ARG1_IS_BEFORE_ARG2(_ulBytesProcessed, pTemp->ulDonepos)) break;
    414427                                }
    415428                                ReturnBuffer();
     
    485498        ULONG Seconds, MilliSeconds, Overflow, Processed;
    486499
    487         //PS++ optimize code
    488500        Processed = _ulBytesProcessed;
    489         if (ulStreamState == STREAM_STREAMING)  // if the stream is active
    490         {
    491            if (ulStreamType & STREAM_WRITE)
    492            {
    493                    if (pahw->GetPosition(StreamId, &_configinfo, &Processed) == FALSE)
    494                    {
    495                                 //DebugInt3();
    496                                 Processed = _ulBytesProcessed; //last known position
    497                    }
     501        if (ulStreamState == STREAM_STREAMING) {        // if the stream is active
     502           if (ulStreamType & STREAM_WRITE) {
     503                        if (pahw->GetPosition(StreamId, &_configinfo, &Processed) == FALSE) {
     504                                Processed = _ulBytesProcessed;
     505                        }
    498506                }
    499507        }
    500508
    501509        // if we haven't processed anything then just return _ulTimeBase
    502         if(Processed == 0)
    503                 return(_ulTimeBase);
     510        if(Processed == 0) return(_ulTimeBase);
    504511
    505512        Seconds  = Processed / _configinfo.ulPCMConsumeRate;
     
    515522        ULONG Processed;
    516523
    517         //PS++ optimize code
    518524        Processed = _ulBytesProcessed;
    519         if (ulStreamState == STREAM_STREAMING)  // if the stream is active
    520         {
    521                 if (ulStreamType & STREAM_WRITE)
    522                 {
    523                         if (pahw->GetPosition(StreamId, &_configinfo, &Processed) == FALSE)
    524                         {
     525        if (ulStreamState == STREAM_STREAMING) {        // if the stream is active
     526                if (ulStreamType & STREAM_WRITE) {
     527                        if (pahw->GetPosition(StreamId, &_configinfo, &Processed) == FALSE) {
    525528                                DebugInt3();
    526529                                Processed = _ulBytesProcessed; //last known position
     
    590593
    591594        _ulBytesProcessed = 0;
     595        _ulLastPosition = 0;
    592596        _ulBytesWritten = 0;
    593597        fUnderrun = FALSE;
     
    632636                return NO_ERROR;
    633637        }
     638
    634639        //silence wave stream before stopping it (removes clicks)
    635640        if(ulStreamType == STREAM_WAVE_PLAY) {
     
    652657        // DDCMD_ENABLE_EVENT the event time will get screwed up. rjj
    653658        _ulBytesProcessed = 0;
     659        _ulLastPosition = 0;
    654660        _ulBytesWritten = 0;
    655661        return NO_ERROR;
     
    659665ULONG  WAVESTREAM::PauseStream(PCONTROL_PARM pControl)
    660666{
    661         ULONG ulEndPos;
     667        //DAZ ULONG ulEndPos;
    662668
    663669        if(ulStreamState == STREAM_PAUSED) {
     
    668674        }
    669675
    670         pahw->GetPosition(StreamId, &_configinfo, &ulEndPos);
     676        //DAZ pahw->GetPosition(StreamId, &_configinfo, &ulEndPos);
    671677        //silence wave stream before stopping it (removes clicks)
    672678        pahw->SetVolume(StreamId, getMixerStreamId(), 0);
     
    677683        dprintf(("WS::PauseStream %lx", StreamId));
    678684
    679         _ulBytesProcessed = ulEndPos;
    680 
    681         _vRealignPausedBuffers(ulEndPos);
     685        //DAZ _ulBytesProcessed = ulEndPos;
     686
     687        _vRealignPausedBuffers(_ulBytesProcessed);
    682688
    683689        pControl->ulTime = GetCurrentTime();
    684690
    685691        _ulBytesProcessed = 0;
     692        _ulLastPosition = 0;
    686693        _ulBytesWritten = 0;
    687694        fUnderrun = FALSE;
     
    755762        _ulBytesWritten                         = 0;
    756763        _ulBytesProcessed                       = 0;
     764        _ulLastPosition                         = 0;
    757765        _ulTimeBase                             = 0;
    758766        ulSavedInputGain                        = 0;
Note: See TracChangeset for help on using the changeset viewer.