Ignore:
Timestamp:
Oct 17, 2008, 5:37:44 PM (17 years ago)
Author:
rjerant
Message:

Update buffer handeling routines. This should allow merging back to a single Uniaud32

File:
1 edited

Legend:

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

    r379 r396  
    1 
    21/* SCCSID = %W% %E% */
    32/****************************************************************************
     
    5150// the data has been played and 1 if there is still some data left.
    5251//******************************************************************************
    53 USHORT WAVESTREAM::_vRealignBuffer(ULONG FAR *bytesinc, PSTREAMBUFFER pbuffer)
    54 {
    55     // if none of the data in this stream buffer has been consumed
    56     if (!*bytesinc) {
    57         pbuffer->ulDonepos = 0;
    58         pbuffer->ulBuffpos = 0;
    59         return 1;
    60     }
    61 
    62     pbuffer->ulDonepos += *bytesinc;
    63     pbuffer->ulBuffpos  = pbuffer->ulDonepos;
    64     *bytesinc           = 0;
    65     if(pbuffer->ulDonepos >= pbuffer->ulBuffsz) {
    66             //calc position in next buffer
    67             *bytesinc = pbuffer->ulDonepos - pbuffer->ulBuffsz;
    68             return 0; //all of the buffer has been consumed
    69     }
    70     return 1;
    71 }
     52USHORT  WAVESTREAM::_vRealignBuffer(ULONG endpos, PSTREAMBUFFER pbuffer)
     53{
     54   ULONG streambuf_start, bufconsumed;
     55   USHORT usRC;
     56
     57   streambuf_start = pbuffer->ulDonepos - pbuffer->ulBuffpos;
     58      // if none of the data in this stream buffer has been consumed
     59   if (endpos <= streambuf_start) {
     60      pbuffer->ulDonepos = 0;
     61      pbuffer->ulBuffpos = 0;
     62      usRC = 1;
     63   }
     64     // else some or all of the data has been consumed
     65   else {
     66      bufconsumed = endpos - streambuf_start;
     67        // some of the buffer has been consumed
     68      if (bufconsumed <= pbuffer->ulBuffsz) {
     69         pbuffer->ulDonepos = 0;
     70         pbuffer->ulBuffpos = pbuffer->ulBuffsz - bufconsumed;
     71         pbuffer->ulBuffpos &= 0xFFFFFFFC; //keep it on a dword boundary
     72         usRC = 1;
     73      }
     74        // all of the buffer has been consumed
     75      else {
     76         pbuffer->ulDonepos = 0;
     77         pbuffer->ulBuffpos = pbuffer->ulBuffsz;
     78         usRC = 0;
     79      }
     80   }
     81   return(usRC);
     82}
     83
    7284//******************************************************************************
    7385// _vRealignPausedBuffers(void)
     
    89101void WAVESTREAM::_vRealignPausedBuffers(ULONG endpos)
    90102{
    91     PSTREAMBUFFER ptempbuff;
    92 
    93     switch (ulStreamType & STREAM_WRITE) {
    94     case STREAM_READ:
    95             //SvL: Don't get the lastest recording data as a read command
    96         //     would now restart recording (as it's stopped)
    97         //     Just return what we've got or push the buffer on the inprocess queue
    98             ptempbuff = (PSTREAMBUFFER)qhDone.Head();
    99             if(ptempbuff) {
    100                     if(ptempbuff->ulBuffpos) {//if we recorded anything into this buffer, then return it now
    101                         ReturnBuffer();
    102                             return;
    103                     }
    104                     ptempbuff->ulBuffpos = 0;
    105                     ptempbuff->ulDonepos = 0;
    106                     qhInProcess.PushOnHead(qhDone.PopHead());
    107             }
    108         break;
     103   PQUEUEHEAD pTempHead = new QUEUEHEAD;
     104   PSTREAMBUFFER ptempbuff;
     105   USHORT usRC;
     106
     107
     108   switch (ulStreamType & STREAM_WRITE) {
     109   case STREAM_READ:
     110      _vReadAudioBuf();
     111      break;
    109112
    110113   case STREAM_WRITE:
    111    {
    112         PQUEUEHEAD pTempHead = new QUEUEHEAD;
    113         ULONG bytesinc;
    114         USHORT usRC;
    115 
    116             bytesinc = endpos - _ulBytesProcessed;
    117         bytesinc &= 0xFFFFFFFC; //keep it on a dword boundary
    118 
    119         // if there are bufferes on the done queue, pop them off the head and
    120         // push them on the head of qhTempHead.  This will reorder them so
    121         // that the more recently used ones will be in the front of the queue.
    122         // Pass them all to _vRealignBuffer. If the rc from _vRealignBuffer is
    123         // 0 then there is no unprocessed data in the buffer (it is ready to
    124         // be returned) so put it on the Tail of the done queue.
    125         // If the rc is 1 then put it on the head of the InProcess queue.
    126 
    127         while (qhDone.IsElements()) {
    128                 pTempHead->PushOnTail(qhDone.PopHead());
    129         } /* endwhile */
    130 
    131         while (qhInProcess.IsElements()) {
    132                 pTempHead->PushOnTail(qhInProcess.PopHead());
    133         } /* endwhile */
    134 
    135         while(pTempHead->IsElements()) {
    136                 usRC = _vRealignBuffer(&bytesinc, (PSTREAMBUFFER)pTempHead->Head());
    137                 if (usRC) {
    138                         qhInProcess.PushOnTail(pTempHead->PopHead());
    139                     }
    140                 else {
    141                         qhDone.PushOnTail(pTempHead->PopHead());
    142                     }
    143         } /* endwhile */
    144             if(qhDone.IsElements())
    145                 ReturnBuffer();
    146 
    147         delete pTempHead; // free the memory this ain't no Java here !!
    148         break;
    149     }
    150     default:
    151         break;
    152     } /* endswitch */
    153 }
     114
     115      // if there is a buffer on the InProcess Queue
     116      // only check the first one as any others are just waiting.....
     117      if (qhInProcess.IsElements()) {
     118           // if any data has been written from this stream buffer
     119         ptempbuff = (PSTREAMBUFFER)qhInProcess.Head();
     120         if (ptempbuff->ulDonepos) {
     121            _vRealignBuffer(endpos, ptempbuff);
     122         } /* end if ulDonepos */
     123      }
     124
     125      // if there are bufferes on the done queue, pop them off the head and
     126      // push them on the head of qhTempHead.  This will reorder them so
     127      // that the more recently used ones will be in the front of the queue.
     128      // Pass them all to _vRealignBuffer. If the rc from _vRealignBuffer is
     129      // 0 then there is no unprocessed data in the buffer (it is ready to
     130      // be returned) so put it on the Tail of the done queue.
     131      // If the rc is 1 then put it on the head of the InProcess queue.
     132
     133      while (qhDone.IsElements()) {
     134         pTempHead->PushOnHead(qhDone.PopHead());
     135      } /* endwhile */
     136
     137      while (pTempHead->IsElements()) {
     138         usRC = _vRealignBuffer(endpos, (PSTREAMBUFFER)pTempHead->Head());
     139         if (usRC)
     140           qhInProcess.PushOnHead(pTempHead->PopHead());
     141         else
     142           qhDone.PushOnTail(pTempHead->PopHead());
     143      } /* endwhile */
     144      break;
     145   default:
     146      break;
     147   } /* endswitch */
     148   delete pTempHead; // free the memory this ain't no Java here !!
     149}
     150
    154151//******************************************************************************
    155152// get ready to start streaming
     
    164161    ULONG space, byteswritten;
    165162
     163    dgprintf(("AddBuffers"));
     164
     165    byteswritten = 0;
    166166    if (ulStreamType & STREAM_WRITE) {
    167             if(!qhInProcess.Head() && !qhDone.Head()) {
    168                 //underrun: stop playback
    169 //                  dprintf(("underrun: stop playback"));
    170 
    171             //save last known position
    172             _ulUnderrunBase = GetCurrentPos();
    173            
    174             //silence wave stream before stopping it (removes clicks)
    175             pahw->SetVolume(StreamId, getMixerStreamId(), 0);
    176 
    177             //and stop it
    178                     pahw->Stop(StreamId);
    179                     fUnderrun = TRUE;
    180                     return;
    181             }
    182             if(pahw->GetSpace(StreamId, &_configinfo, &space) == FALSE) {
    183             dprintf(("pahw->getSpace: No room!"));
     167        // get the space available in the hardware buffer
     168        // only call GetSpace once because the amount of free space in
     169        // the hardware buffer is a moving target and calling it more than once
     170        // could keep us in this loop writing 4 or 8 bytes at a time.
     171        // In extream cases we will stay stuck in this loop long enough to casue a trap rjj
     172        if(pahw->GetSpace(StreamId, &_configinfo, &space) == FALSE) {
     173            dgprintf(("WAVESTREAM::AddBuffers Error 1"));
    184174            return;
    185175        }
    186             while(space) {
    187                     byteswritten = AddBuffer(space);
    188                     if(byteswritten == (ULONG)-1) break;
    189                     space -= byteswritten;
    190             }
    191     }
    192 }
    193 //******************************************************************************
    194 // write one buffer to the audio buffer
     176        space &= ( ~(_configinfo.ulSampleSize - 1));
     177        while (space && qhInProcess.IsElements()) {
     178            byteswritten = AddBuffer(space);
     179            if(byteswritten == (ULONG)-1)
     180                break;
     181            space -= byteswritten;
     182            space &= ( ~(_configinfo.ulSampleSize - 1));
     183        }
     184
     185    }
     186}
     187//******************************************************************************
     188// write one buffer to the audio buffer                                           1
    195189// the caller of this function MUST make sure it ok to write the audio buffer..
    196190// _AudioBufWrite will not check if there is room in the audio buffer of if
     
    199193ULONG WAVESTREAM::AddBuffer(ULONG space)
    200194{
    201     PSTREAMBUFFER pTemp = (PSTREAMBUFFER)qhDone.Tail();
     195    PSTREAMBUFFER pTemp = (PSTREAMBUFFER)qhInProcess.Head();
    202196    ULONG pdataBuf;
    203     ULONG Buff_left, byteswritten;
    204 
    205     if(!pTemp || pTemp->ulBuffpos >= (pTemp->ulBuffsz & 0xFFFFFFFC)) {
    206             pTemp = (PSTREAMBUFFER)qhInProcess.Head();
    207     }
    208     if(!pTemp) {
    209 #ifdef DEBUG
    210             dprintf(("AddBuffer: pTemp == NULL"));
    211 #endif /* DEBUG */
    212             return (ULONG)-1;
     197    ULONG Buff_left, byteswritten, start_pos;
     198
     199    ddprintf(("AddBuffer"));
     200    // make sure we have a buffer to copy from.....
     201    if (!pTemp) {
     202        return (ULONG)-1;
     203    }
     204
     205    // get the starting position. Call WaveGetHwPtr. if we get a bad rc
     206    // then we bail out.
     207    if(pahw->GetHwPtr(StreamId, &_configinfo, &start_pos) == FALSE)
     208    {
     209        dgprintf(("WAVESTREAM::AddBuffer Error in WaveGetHwPtr"));
     210        DebugInt3();
     211        return (ULONG)-1;
    213212    }
    214213
     
    216215    pdataBuf  = (ULONG)pTemp->pBuffptr + pTemp->ulBuffpos;
    217216    Buff_left = pTemp->ulBuffsz - pTemp->ulBuffpos;
    218 
    219     if(Buff_left) {
    220        // write the audio buffer
    221        Buff_left = min(Buff_left, space);
    222        if(pahw->Transfer(StreamId, &_configinfo, pdataBuf, Buff_left, &byteswritten) == FALSE) {
    223            dprintf(("AddBuffer: pahw->Transfer failed!!"));
    224            return (ULONG)-1;
    225        }
    226        if(byteswritten == 0) {
    227            return (ULONG)-1; //no more room
    228        }
    229 
    230        // update the buffer pos counter
    231        pTemp->ulBuffpos += byteswritten;
    232     }
    233     else byteswritten = 0;
    234 
    235     if(pTemp == qhInProcess.Head()) {
    236         qhDone.PushOnTail(qhInProcess.PopHead());
    237     }
    238     dprintf(("AddBuffer %lx size %d, bytes written %d", pdataBuf, (USHORT)Buff_left, (USHORT)byteswritten));
     217    Buff_left = min(Buff_left, space);
     218
     219    if(pahw->Transfer(StreamId, &_configinfo, pdataBuf, Buff_left, &byteswritten) == FALSE) {
     220        dgprintf(("AddBuffer: pahw->Transfer failed!!"));
     221        return (ULONG)-1;
     222    }
     223    if(byteswritten == 0) {
     224        return (ULONG)-1; //no more room
     225    }
     226    // update the buffer pos counter
     227    pTemp->ulBuffpos += byteswritten;
     228
     229    // update the done Position
     230    pTemp->ulDonepos = start_pos + byteswritten;
     231
     232    // check to see if the buffer has been copied and needs to be put on the done queue
     233    if (pTemp->ulBuffpos >= (pTemp->ulBuffsz & 0xFFFFFFFC)) {
     234        qhDone.PushOnTail(qhInProcess.PopHead());
     235    }
     236    dgprintf(("WAVESTREAM::AddBuffer sz %lx, bywr %lx dp %lx", Buff_left, byteswritten,pTemp->ulDonepos));
    239237    return byteswritten;
    240238}
     
    249247    ULONG Buff_left, bytesread;
    250248
    251     if(!pTemp) 
     249    if(!pTemp)
    252250        return FALSE;
    253251
     
    290288 PSTREAMBUFFER ptemp;
    291289 ULONG         ulCurBytesProcessed = 0;
    292  ULONG         bytesinc;
     290// ULONG         bytesinc;
    293291
    294292#ifdef DEBUG
    295 //    dprintf(("WAVESTREAM::Process"));
     293    ddprintf(("WAVESTREAM::Process"));
    296294#endif
    297295
     296    // get the stream position. if we get a bad rc or the position is 0
     297    // then we bail out. Hopefully this will be better next time.
     298    // GetPostiion returns the adjusted hw pointer from the ALSA status ioctl
     299    // This is really a running total of bytes consumed by the hardware.
     300    if(pahw->GetPosition(StreamId, &_configinfo, &ulCurBytesProcessed) == FALSE)
     301    {
     302        ddprintf(("Error No bytes processed"));
     303        DebugInt3();
     304        return;
     305    }
     306    ddprintf(("StPos: %lx", ulCurBytesProcessed));
     307    // save the bytes processed in the stream object
     308    _ulBytesProcessed = ulCurBytesProcessed;
     309
    298310    switch (ulStreamType & STREAM_WRITE) {
    299     case STREAM_WRITE:
    300     {
    301         if(pahw->GetPosition(StreamId, &_configinfo, &ulCurBytesProcessed) == FALSE ||
    302            ulCurBytesProcessed == 0)
    303         {//shouldn't happen
    304             DebugInt3();
    305             return;
    306         }
    307 
    308         bytesinc  = ulCurBytesProcessed - _ulBytesProcessed;
    309         dprintf3(("P: %lx %x", ulCurBytesProcessed, (USHORT)bytesinc));
    310 
    311         if(ulCurBytesProcessed < _ulBytesProcessed)
     311
     312        // if there are buffers that have been completly written to the audio buffer
     313        // check the first one on the done queue
     314        // if it's data has been consumed by the hardware return it.
     315        //
     316        // Bug #18 Sometimes MMPM gives us really small buffers. If we
     317        // wait for the buffer to be completly consumed and there is a tiny buffer
     318        // on the queue after this one, the sound part could underrun before we get a
     319        // chance to refill it. To fix this we will return the buffer if it will be
     320        // consumed before the next call to WAVESTREAM:Process().
     321        // rjj Fix for Bug #18 28082008
     322        case STREAM_WRITE:
    312323        {
    313             ULONG ulCurBytesProcessed, ulStreamPos;
    314 
    315             if(OSS16_WaveGetPos(StreamId, &ulCurBytesProcessed) != OSSERR_SUCCESS) {
    316                 ulCurBytesProcessed = 0;
     324          if(qhDone.IsElements()) {
     325                ptemp = (PSTREAMBUFFER)qhDone.Head();
     326                while ((_ulBytesProcessed + _configinfo.ulBytesPerIRQ) >= ptemp->ulDonepos)
     327                {
     328                    ReturnBuffer();
     329                    ptemp = (PSTREAMBUFFER)qhDone.Head();
     330                }
    317331            }
    318 
    319             ulStreamPos  = pahw->ConvertPositionInvert(ulCurBytesProcessed, &_configinfo);
    320             //round to sample boundary
    321             ulStreamPos &= ~(_configinfo.ulSampleSize - 1);
    322 
    323 #ifdef DEBUG
    324             dprintf(("WARNING: Process: Current pos %ld pos %ld incr %d", ulCurBytesProcessed, _ulBytesProcessed, bytesinc));
    325             dprintf(("WARNING: hw pos %lx, streampos %lx", ulCurBytesProcessed, ulStreamPos));
    326 #endif /* DEBUG */
    327         }
    328         _ulBytesProcessed = ulCurBytesProcessed;
    329 
    330         while(bytesinc)
    331         {
    332           if(qhDone.IsElements()) {  // if there are buffers that have been completly written to the audio buffer
    333                                        // check the first one on the done queue
    334                                        // if it's data has been consumed by the hardware return it.
    335                                                          // Bug #18 Sometimes MMPM gives us really small buffers. If we
    336                                                          // wait for the buffer to be completly consumed and there is a tiny buffer
    337                                                          // on the queue after this one, the sound part could underrun before we get a
    338                                                          // chance to refill it. To fix this we will return the buffer if it will be 
    339                                                          // consumed before the next call to WAVESTREAM:Process().
    340                                                          // rjj Fix for Bug #18 28082008
    341                 ptemp = (PSTREAMBUFFER)qhDone.Head();
    342                 ptemp->ulDonepos += bytesinc;
    343                 bytesinc          = 0;
    344                                   if ((ptemp->ulDonepos + _configinfo.ulBytesPerIRQ) >= ptemp->ulBuffsz)
    345                 {
    346                     //calc position in next buffer
    347                     bytesinc = ptemp->ulDonepos - ptemp->ulBuffsz;
    348 //                  dprintf2(("Process: Return buffer %lx size %d", ptemp->pBuffptr, ptemp->ulBuffsz));
    349                     ReturnBuffer();
    350                           }
    351           }
    352             else        break; //shouldn't happen
    353         }
    354 
    355         if (qhInProcess.IsElements()){
    356             AddBuffers(FALSE);
    357         }
     332            if (qhInProcess.IsElements()){
     333               AddBuffers(FALSE);
     334            }
     335
    358336        break;
    359     }
    360     case STREAM_READ:
     337
     338        }
     339        case STREAM_READ:
    361340            while(_vReadAudioBuf());
    362341            break;
    363     default:
    364         break;
     342        default:
     343            break;
    365344    } /* endswitch */
    366345
     
    382361{
    383362    qhInProcess.PushOnTail((PQUEUEELEMENT)pStreamBuf);
    384 //    dprintf2(("WAVESTREAM::Write: Push on tail %lx %ld", ((PSTREAMBUFFER)qhInProcess.Tail())->pBuffptr, ((PSTREAMBUFFER)qhInProcess.Tail())->ulBuffsz));
    385     if(fUnderrun) {
    386         PSTREAMBUFFER pTemp = (PSTREAMBUFFER)qhInProcess.Head();
    387 
    388 //        dprintf(("Restart after underrun!"));
    389             fUnderrun = FALSE;
    390 
    391         // configure the wave device
    392         // (NOTE: Must call this function; sample rate position is reset there)
    393         if(pahw->ConfigDev(StreamId, &_configinfo, pTemp->ulBuffsz) == FALSE) {
    394             dprintf(("ConfigDev failed!!"));
    395         }
    396 
    397         // prepare wave device for playback/recording
    398         if(pahw->Prepare(StreamId) == FALSE) {
    399             dprintf(("Prepare failed!!"));
    400         }
    401             AddBuffers(TRUE);
    402             if(ulStreamType == STREAM_WAVE_PLAY)
    403                     MixerSetWaveVolume(getMixerStreamId(), StreamId, volume);
    404     }
     363    //    dprintf2(("WAVESTREAM::Write: Push on tail %lx %ld", ((PSTREAMBUFFER)qhInProcess.Tail())->pBuffptr, ((PSTREAMBUFFER)qhInProcess.Tail())->ulBuffsz));
    405364    return 0;
    406365}
     
    433392    if (ulStreamState == STREAM_STREAMING)  // if the stream is active
    434393    {
    435             if (ulStreamType & STREAM_WRITE)
     394        if (ulStreamType & STREAM_WRITE)
    436395        {
    437                 if(pahw->GetPosition(StreamId, &_configinfo, &Processed) == FALSE)
     396            if(pahw->GetPosition(StreamId, &_configinfo, &Processed) == FALSE)
    438397            {
    439398                DebugInt3();
    440399                Processed = _ulBytesProcessed; //last known position
    441400            }
    442             }
    443             else        Processed = _ulBytesProcessed;
    444     }
    445     else Processed = _ulBytesProcessed;
    446 
    447     //add position of underrun (if one occurred in the past)
    448     Processed += _ulUnderrunBase;
     401        }
     402        else
     403            Processed = _ulBytesProcessed;
     404    }
     405    else
     406        Processed = _ulBytesProcessed;
    449407
    450408    // if we haven't processed anything then just return
     
    467425    if (ulStreamState == STREAM_STREAMING)  // if the stream is active
    468426    {
    469             if (ulStreamType & STREAM_WRITE) {
    470                 if(pahw->GetPosition(StreamId, &_configinfo, &Processed) == FALSE)
     427        if (ulStreamType & STREAM_WRITE) {
     428            if(pahw->GetPosition(StreamId, &_configinfo, &Processed) == FALSE)
    471429            {
    472430                DebugInt3();
    473431                Processed = _ulBytesProcessed; //last known position
    474432            }
    475             }
    476             else        Processed = _ulBytesProcessed;
    477     }
    478     else Processed = _ulBytesProcessed;
    479 
    480     //add position of underrun (if one occurred in the past)
    481     Processed += _ulUnderrunBase;
     433        }
     434        else
     435            Processed = _ulBytesProcessed;
     436    }
     437    else
     438        Processed = _ulBytesProcessed;
     439
    482440    return Processed;
    483441}
     
    517475
    518476#ifdef DEBUG
    519 //    dprintf(("WAVESTREAM::StartStream"));
     477    ddprintf(("WAVESTREAM::StartStream"));
    520478#endif
    521479
    522480    if(ulStreamState == STREAM_STREAMING) {
    523         dprintf(("StartStream: already playing!!"));
     481        ddprintf(("StartStream: already playing!!"));
    524482        return NO_ERROR;
    525483    }
     
    528486    // (NOTE: Must call this function; sample rate position is reset there)
    529487    if(pahw->ConfigDev(StreamId, &_configinfo, (pTemp) ? pTemp->ulBuffsz : 0) == FALSE) {
    530         dprintf(("StartStream: ConfigDev failed!!"));
     488        ddprintf(("StartStream: ConfigDev failed!!"));
    531489        goto fail;
    532490    }
    533 
    534491    // prepare wave device for playback/recording
    535492    if(pahw->Prepare(StreamId) == FALSE) {
    536         dprintf(("StartStream: Prepare failed!!"));
     493        ddprintf(("StartStream: Prepare failed!!"));
    537494        goto fail;
    538495    }
    539496
    540497    _ulBytesProcessed = 0;
    541     _ulUnderrunBase   = 0;
    542     fUnderrun = FALSE;
    543498
    544499    ulStreamState = STREAM_STREAMING;
    545500    //Adding the first buffer also starts playback
    546501    if(ulStreamType == STREAM_WAVE_PLAY) {
    547             AddBuffers(TRUE);
     502        AddBuffers(TRUE);
    548503        //Must set volume after adding buffers (voices inside sblive driver might not
    549504        //be allocated otherwise (first start) )
     505        dprintf(("SetVolume %lx",volume));
    550506        pahw->SetVolume(StreamId, getMixerStreamId(), volume);
    551507    }
     
    555511        pahw->SetVolume(StreamId, getMixerStreamId(), inputgain);
    556512
    557             if(pahw->Start(StreamId) != TRUE) {
     513        if(pahw->Start(StreamId) != TRUE) {
    558514            dprintf(("pahw->Start failed!!"));
    559515            goto fail;
    560516        }
    561517    }
    562 //    dprintf(("WAVESTREAM::StartStream %lx", StreamId));
     518    ddprintf(("WAVESTREAM::StartStream %lx", StreamId));
    563519    return NO_ERROR;
    564520
     
    573529    if(ulStreamState == STREAM_STOPPED) {
    574530        dprintf(("WAVESTREAM::StopStream %lx (already stopped)", StreamId));
    575             fUnderrun = FALSE;
    576531            pControl->ulTime = GetCurrentTime();
    577532            return NO_ERROR;
     
    587542
    588543    ulStreamState = STREAM_STOPPED;
    589     fUnderrun = FALSE;
    590 //    dprintf(("WAVESTREAM::StopStream %lx", StreamId));
     544    ddprintf(("WAVESTREAM::StopStream %lx", StreamId));
    591545    ReturnBuffers();
    592546    pControl->ulTime = GetCurrentTime();
    593     _ulTimeBase = GetCurrentTime();
     547
     548    // We need to set _ulBytesProcessed to 0 here. if we do not
     549    // and MMPM restarts the stream by sending a DDCMD_SETUP followed By
     550    // DDCMD_ENABLE_EVENT the event time will get screwed up. rjj
     551    _ulBytesProcessed = 0;
    594552    return NO_ERROR;
    595553}
     
    606564
    607565    ulStreamState = STREAM_PAUSED;
    608     fUnderrun = FALSE;
    609 
    610 //    dprintf(("WAVESTREAM::PauseStream %lx", StreamId));
     566
     567    ddprintf(("WAVESTREAM::PauseStream %lx", StreamId));
     568
    611569    _vRealignPausedBuffers(endpos);
    612570
    613571    _ulBytesProcessed = endpos;
    614572    pControl->ulTime = GetCurrentTime();
     573    _ulBytesProcessed = 0;
    615574    return NO_ERROR;
    616575}
     
    634593    switch(type) {
    635594    case PROPERTY_VOLUME:
    636         volume = value;
     595        volume = value;
     596        dprintf(("WAVESTREAM::SetProperty() Vol: %0lx",value));
    637597        if(ulStreamState == STREAM_STREAMING && ulStreamType == STREAM_WAVE_PLAY) {
    638598            MixerSetWaveVolume(getMixerStreamId(), StreamId, volume);
     
    655615//******************************************************************************
    656616//******************************************************************************
    657 ULONG WAVESTREAM::GetProperty(int type) 
     617ULONG WAVESTREAM::GetProperty(int type)
    658618{
    659619#ifdef DEBUG
     
    677637//******************************************************************************
    678638WAVESTREAM::WAVESTREAM(ULONG streamtype, LPMCI_AUDIO_INIT pinit, USHORT filesysnum, OSSSTREAMID mixerStreamId):
    679    STREAM(streamtype, filesysnum, mixerStreamId) 
     639   STREAM(streamtype, filesysnum, mixerStreamId)
    680640{
    681641#ifdef DEBUG
     
    692652    _ulBytesProcessed           = 0;
    693653    _ulTimeBase                 = 0;
    694     _ulUnderrunBase             = 0;
     654    //_ulUnderrunBase             = 0;
    695655    ulSavedInputGain            = 0;
    696656
    697657    _configinfo.pConversionBuffer  = 0;
    698658    pahw->SetupConversion(&_configinfo, pinit->ulOperation, pinit->sMode, pinit->sChannels, pinit->lBitsPerSRate);
    699    
    700     if(_configinfo.usConversion != CONVERT_NONE) 
     659
     660    if(_configinfo.usConversion != CONVERT_NONE)
    701661    {//allocate conversion buffer
    702662        PVOID pSelOff;
    703663        LIN   linAddr;
    704664
    705         if(DevHelp_VMAlloc(VMDHA_FIXED, CONVERSION_BUFFER_SIZE, (ULONG)-1L, &linAddr, &pSelOff) != 0)
     665        if(DevHelp_VMAlloc((VMDHA_FIXED | VMDHA_CONTIG), CONVERSION_BUFFER_SIZE, (ULONG)-1L, &linAddr, &pSelOff) != 0)
    706666        {
     667                           //dgprintf(("Error in DevHelp_VMAlloc Conversion Buffer"));
    707668             DebugInt3(); //should never happen!!
    708669             _configinfo.usConversion = CONVERT_NONE;
     
    710671        else _configinfo.pConversionBuffer = linAddr;
    711672    }
    712     if(_configinfo.fSampleRateConversion == TRUE) 
     673    if(_configinfo.fSampleRateConversion == TRUE)
    713674    {//allocate buffer for sample rate conversion
    714675        PVOID pSelOff;
    715676        LIN   linAddr;
    716677
    717         if(DevHelp_VMAlloc(VMDHA_FIXED, CONVERSION_BUFFER_SIZE, (ULONG)-1L, &linAddr, &pSelOff) != 0)
     678        if(DevHelp_VMAlloc((VMDHA_FIXED | VMDHA_CONTIG), CONVERSION_BUFFER_SIZE, (ULONG)-1L, &linAddr, &pSelOff) != 0)
    718679        {
    719              DebugInt3(); //should never happen!!
     680                         //dgprintf(("Error in DevHelp_VMAlloc SR Conversion Buffer"));
     681                         DebugInt3(); //should never happen!!
    720682        }
    721683        else _configinfo.pSRateConvBuffer = linAddr;
     
    724686    pinit->ulFlags |= pahw->QueryDataFlags(pinit->ulOperation, pinit->sMode, pinit->lBitsPerSRate);
    725687
    726     fUnderrun   = FALSE;
     688    //fUnderrun   = FALSE;
    727689    StreamId    = 0;
    728    
     690
    729691    if(pahw->Open(current_device, ulStreamType, ulSysFileNum, &StreamId) != TRUE)
    730692    {
Note: See TracChangeset for help on using the changeset viewer.