Ignore:
Timestamp:
Nov 4, 2009, 4:21:24 PM (16 years ago)
Author:
pasha
Message:

Rebuild buffers supply, fix DDCMD_WRITE with len=0 in WAVE chain, remove/add debug output, change DebugInt3 for debug/nondebug version, move unused code to unused directore

File:
1 edited

Legend:

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

    r396 r468  
    115115      // if there is a buffer on the InProcess Queue
    116116      // only check the first one as any others are just waiting.....
    117       if (qhInProcess.IsElements()) {
     117      if (qhInProcess.IsElements())
     118      {
    118119           // if any data has been written from this stream buffer
    119120         ptempbuff = (PSTREAMBUFFER)qhInProcess.Head();
    120          if (ptempbuff->ulDonepos) {
    121             _vRealignBuffer(endpos, ptempbuff);
    122          } /* end if ulDonepos */
     121         if (ptempbuff->ulDonepos)
     122         {
     123             _vRealignBuffer(endpos, ptempbuff);
     124         }  /* end if ulDonepos */
    123125      }
    124126
     
    131133      // If the rc is 1 then put it on the head of the InProcess queue.
    132134
    133       while (qhDone.IsElements()) {
     135      while (qhDone.IsElements())
     136      {
    134137         pTempHead->PushOnHead(qhDone.PopHead());
    135138      } /* endwhile */
    136139
    137       while (pTempHead->IsElements()) {
     140      while (pTempHead->IsElements())
     141      {
    138142         usRC = _vRealignBuffer(endpos, (PSTREAMBUFFER)pTempHead->Head());
    139143         if (usRC)
     
    159163#pragma on (unreferenced)
    160164{
    161     ULONG space, byteswritten;
    162 
    163     dgprintf(("AddBuffers"));
     165    ULONG space, byteswritten, curspace,i;
     166
     167//    dgprintf(("AddBuffers %d",fFirst == TRUE?1:2));
    164168
    165169    byteswritten = 0;
    166     if (ulStreamType & STREAM_WRITE) {
     170    if (ulStreamType & STREAM_WRITE)
     171    {
    167172        // get the space available in the hardware buffer
    168173        // only call GetSpace once because the amount of free space in
     
    170175        // could keep us in this loop writing 4 or 8 bytes at a time.
    171176        // 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"));
     177         if (pahw->GetSpace(StreamId, &_configinfo, &space) == FALSE)
     178        {
     179//            dgprintf(("WAVESTREAM::AddBuffers Error 1"));
    174180            return;
    175181        }
    176         space &= ( ~(_configinfo.ulSampleSize - 1));
    177         while (space && qhInProcess.IsElements()) {
    178             byteswritten = AddBuffer(space);
     182        space &= (~(_configinfo.ulSampleSize - 1));
     183        curspace = space;
     184        while (space && qhInProcess.IsElements())
     185        {
     186            // Fisrt time going in task time
     187            // for I7 need give time for interrupt time
     188            if (fFirst == TRUE)  //PS+++
     189            {
     190                 DevHelp_ProcBlock (space, 20, 0);
     191            }
     192//            dgprintf(("AddBuffers write %ld SSize:%ld %d",space, _configinfo.ulSampleSize, fFirst == TRUE?1:2));
     193            byteswritten = AddBuffer(space > curspace? curspace: space);
     194            if (pahw->GetSpace(StreamId, &_configinfo, &curspace) == FALSE)
     195            {
     196//                dgprintf(("WAVESTREAM::AddBuffers Error 2"));
     197                return;
     198            }
    179199            if(byteswritten == (ULONG)-1)
    180200                break;
     201            if (!curspace)
     202            {
     203                curspace = _configinfo.ulSampleSize;
     204            }
    181205            space -= byteswritten;
    182206            space &= ( ~(_configinfo.ulSampleSize - 1));
     
    184208
    185209    }
     210//    dgprintf(("AddBuffers %d End",fFirst == TRUE?1:2));
    186211}
    187212//******************************************************************************
     
    197222    ULONG Buff_left, byteswritten, start_pos;
    198223
    199     ddprintf(("AddBuffer"));
     224//    ddprintf(("AddBuffer"));
    200225    // make sure we have a buffer to copy from.....
    201     if (!pTemp) {
     226    if (!pTemp)
     227    {
    202228        return (ULONG)-1;
    203229    }
     
    212238    }
    213239
     240    if (!pTemp->ulBuffsz || !space)
     241    {
     242        dgprintf(("WAVESTREAM::AddBuffer NULL, Bufsz:%ld Space:%ld",pTemp->ulBuffsz, space));
     243        //PS+++ if is ZERO do nothing and ask for give new buffer, See REMARK in mmpm2.inf
     244        qhDone.PushOnTail(qhInProcess.PopHead());
     245//        DebugInt3();
     246        return 0;
     247    }
    214248    // get the buffer pointer and amount of data remaining
    215249    pdataBuf  = (ULONG)pTemp->pBuffptr + pTemp->ulBuffpos;
     
    217251    Buff_left = min(Buff_left, space);
    218252
    219     if(pahw->Transfer(StreamId, &_configinfo, pdataBuf, Buff_left, &byteswritten) == FALSE) {
     253    if (pahw->Transfer(StreamId, &_configinfo, pdataBuf, Buff_left, &byteswritten) == FALSE)
     254    {
    220255        dgprintf(("AddBuffer: pahw->Transfer failed!!"));
     256//        DebugInt3();
    221257        return (ULONG)-1;
    222258    }
    223     if(byteswritten == 0) {
     259    if (byteswritten == 0)
     260    {
     261        dgprintf(("AddBuffer: No more room!!"));
     262//        DebugInt3();
    224263        return (ULONG)-1; //no more room
    225264    }
     
    231270
    232271    // 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)) {
     272    if (pTemp->ulBuffpos >= (pTemp->ulBuffsz & 0xFFFFFFFC))
     273    {
    234274        qhDone.PushOnTail(qhInProcess.PopHead());
    235275    }
    236     dgprintf(("WAVESTREAM::AddBuffer sz %lx, bywr %lx dp %lx", Buff_left, byteswritten,pTemp->ulDonepos));
     276//    dgprintf(("WV::AddBuffer sz %lx, bywr %lx dp %lx", Buff_left, byteswritten,pTemp->ulDonepos));
    237277    return byteswritten;
    238278}
     
    255295
    256296    // read wave data
    257     if(pahw->Transfer(StreamId, &_configinfo, pdataBuf, Buff_left, &bytesread) == FALSE) {
     297    if(pahw->Transfer(StreamId, &_configinfo, pdataBuf, Buff_left, &bytesread) == FALSE)
     298    {
    258299       dprintf(("_vReadAudioBuf: pahw->Transfer failed!!"));
    259300       return FALSE;
     
    284325// can be returned and finally process any events pending.
    285326//******************************************************************************
     327//USHORT ProcNumber = 0;
    286328void DBGCALLCONV WAVESTREAM::Process(void)
    287329{
    288330 PSTREAMBUFFER ptemp;
    289331 ULONG         ulCurBytesProcessed = 0;
    290 // ULONG         bytesinc;
     332// USHORT        CurProcNumber = ProcNumber++;
     333 ULONG         space;
    291334
    292335#ifdef DEBUG
    293     ddprintf(("WAVESTREAM::Process"));
     336//    ddprintf(("WAVESTREAM::Process %d",CurProcNumber));
    294337#endif
    295338
     
    304347        return;
    305348    }
    306     ddprintf(("StPos: %lx", ulCurBytesProcessed));
     349//    ddprintf(("StPos: %lx", ulCurBytesProcessed));
    307350    // save the bytes processed in the stream object
    308351    _ulBytesProcessed = ulCurBytesProcessed;
    309352
     353//    if ((pahw->GetSpace(StreamId, &_configinfo, &space) != FALSE) && (space > _configinfo.ulBytesPerIRQ))
    310354    switch (ulStreamType & STREAM_WRITE) {
    311355
     
    322366        case STREAM_WRITE:
    323367        {
    324           if(qhDone.IsElements()) {
     368            if (qhDone.IsElements())
     369            {
    325370                ptemp = (PSTREAMBUFFER)qhDone.Head();
    326371                while ((_ulBytesProcessed + _configinfo.ulBytesPerIRQ) >= ptemp->ulDonepos)
     
    330375                }
    331376            }
    332             if (qhInProcess.IsElements()){
     377            if (qhInProcess.IsElements())
     378            {
    333379               AddBuffers(FALSE);
    334380            }
     
    345391
    346392    ProcessEvents();
     393//    ddprintf(("WAVESTREAM::Process %d End",CurProcNumber));
    347394}
    348395//******************************************************************************
     
    353400{
    354401    PSTREAMBUFFER pStreamBuf = new STREAMBUFFER(uLength, pbuf);
    355 
     402 
    356403    return Write(pStreamBuf);
    357404}
     
    390437    ULONG Seconds, MilliSeconds, Overflow, Processed;
    391438
     439//PS++ optimize code
     440    Processed = _ulBytesProcessed;
    392441    if (ulStreamState == STREAM_STREAMING)  // if the stream is active
    393442    {
    394         if (ulStreamType & STREAM_WRITE)
    395         {
    396             if(pahw->GetPosition(StreamId, &_configinfo, &Processed) == FALSE)
    397             {
    398                 DebugInt3();
     443       if (ulStreamType & STREAM_WRITE)
     444       {
     445           if (pahw->GetPosition(StreamId, &_configinfo, &Processed) == FALSE)
     446           {
     447//                DebugInt3();
    399448                Processed = _ulBytesProcessed; //last known position
    400             }
    401         }
    402         else
    403             Processed = _ulBytesProcessed;
    404     }
    405     else
    406         Processed = _ulBytesProcessed;
     449           }
     450        }
     451    }
    407452
    408453    // if we haven't processed anything then just return
     
    411456        return(_ulTimeBase);
    412457
    413     Seconds = Processed / _configinfo.ulPCMConsumeRate;
     458    Seconds  = Processed / _configinfo.ulPCMConsumeRate;
    414459    Overflow = Processed - (Seconds * _configinfo.ulPCMConsumeRate);
    415460    MilliSeconds = (Overflow * 1000) / _configinfo.ulPCMConsumeRate;
    416461    MilliSeconds += (Seconds * 1000);
    417     return(MilliSeconds + _ulTimeBase);
     462    return (MilliSeconds + _ulTimeBase);
    418463}
    419464//******************************************************************************
     
    423468    ULONG Processed;
    424469
     470//PS++ optimize code
     471    Processed = _ulBytesProcessed;
    425472    if (ulStreamState == STREAM_STREAMING)  // if the stream is active
    426473    {
    427         if (ulStreamType & STREAM_WRITE) {
    428             if(pahw->GetPosition(StreamId, &_configinfo, &Processed) == FALSE)
    429             {
     474        if (ulStreamType & STREAM_WRITE)
     475       {
     476           if (pahw->GetPosition(StreamId, &_configinfo, &Processed) == FALSE)
     477           {
    430478                DebugInt3();
    431479                Processed = _ulBytesProcessed; //last known position
    432             }
     480           }
    433481        }
    434         else
    435             Processed = _ulBytesProcessed;
    436     }
    437     else
    438         Processed = _ulBytesProcessed;
     482    }
    439483
    440484    return Processed;
     
    446490   ULONG writepos = 0;
    447491
     492// May be lock?
    448493   cli();
    449494   PSTREAMBUFFER pTemp = (PSTREAMBUFFER)qhDone.Tail();
    450495
    451    if(!pTemp) {
     496   if(!pTemp)
     497   {
    452498       pTemp = (PSTREAMBUFFER)qhInProcess.Head();
    453499   }
    454    if(pTemp) {
     500   if(pTemp)
     501   {
    455502       writepos = pTemp->ulBuffpos;
    456503   }
     
    478525#endif
    479526
    480     if(ulStreamState == STREAM_STREAMING) {
     527    if(ulStreamState == STREAM_STREAMING)
     528    {
    481529        ddprintf(("StartStream: already playing!!"));
    482530        return NO_ERROR;
     
    485533    // configure the wave device
    486534    // (NOTE: Must call this function; sample rate position is reset there)
    487     if(pahw->ConfigDev(StreamId, &_configinfo, (pTemp) ? pTemp->ulBuffsz : 0) == FALSE) {
     535    if(pahw->ConfigDev(StreamId, &_configinfo, (pTemp) ? pTemp->ulBuffsz : 0) == FALSE)
     536    {
    488537        ddprintf(("StartStream: ConfigDev failed!!"));
    489         goto fail;
     538        return ERROR_INSUFF_BUFFER;
     539//        goto fail;
    490540    }
    491541    // prepare wave device for playback/recording
    492     if(pahw->Prepare(StreamId) == FALSE) {
     542    if(pahw->Prepare(StreamId) == FALSE)
     543    {
    493544        ddprintf(("StartStream: Prepare failed!!"));
    494545        goto fail;
     
    499550    ulStreamState = STREAM_STREAMING;
    500551    //Adding the first buffer also starts playback
    501     if(ulStreamType == STREAM_WAVE_PLAY) {
     552    if (ulStreamType == STREAM_WAVE_PLAY)
     553    {
     554       pahw->SetVolume(StreamId, getMixerStreamId(), volume);    //PS
    502555        AddBuffers(TRUE);
    503556        //Must set volume after adding buffers (voices inside sblive driver might not
    504557        //be allocated otherwise (first start) )
    505         dprintf(("SetVolume %lx",volume));
    506         pahw->SetVolume(StreamId, getMixerStreamId(), volume);
    507     }
    508     else {
     558//        dprintf(("SetVolume %lx",volume));
     559// PS, removing to high
     560//       pahw->SetVolume(StreamId, getMixerStreamId(), volume);
     561    }
     562    else
     563    {
    509564        ulSavedInputGain = pahw->QueryVolume(StreamId, getMixerStreamId());
    510565        pahw->SetInputSrc(StreamId, getMixerStreamId(), inputsrc);
    511566        pahw->SetVolume(StreamId, getMixerStreamId(), inputgain);
    512567
    513         if(pahw->Start(StreamId) != TRUE) {
     568        if(pahw->Start(StreamId) != TRUE)
     569       {
    514570            dprintf(("pahw->Start failed!!"));
    515571            goto fail;
    516572        }
    517573    }
    518     ddprintf(("WAVESTREAM::StartStream %lx", StreamId));
     574    ddprintf(("WAVESTREAM::StartStream %lx End", StreamId));
    519575    return NO_ERROR;
    520576
     
    665721        if(DevHelp_VMAlloc((VMDHA_FIXED | VMDHA_CONTIG), CONVERSION_BUFFER_SIZE, (ULONG)-1L, &linAddr, &pSelOff) != 0)
    666722        {
    667                            //dgprintf(("Error in DevHelp_VMAlloc Conversion Buffer"));
     723             dgprintf(("Error in DevHelp_VMAlloc Conversion Buffer"));
    668724             DebugInt3(); //should never happen!!
    669725             _configinfo.usConversion = CONVERT_NONE;
     
    676732        LIN   linAddr;
    677733
    678         if(DevHelp_VMAlloc((VMDHA_FIXED | VMDHA_CONTIG), CONVERSION_BUFFER_SIZE, (ULONG)-1L, &linAddr, &pSelOff) != 0)
     734        if (DevHelp_VMAlloc((VMDHA_FIXED | VMDHA_CONTIG), CONVERSION_BUFFER_SIZE, (ULONG)-1L, &linAddr, &pSelOff) != 0)
    679735        {
    680                          //dgprintf(("Error in DevHelp_VMAlloc SR Conversion Buffer"));
    681                         DebugInt3(); //should never happen!!
     736            dgprintf(("Error in DevHelp_VMAlloc SR Conversion Buffer"));
     737            DebugInt3(); //should never happen!!
    682738        }
    683739        else _configinfo.pSRateConvBuffer = linAddr;
Note: See TracChangeset for help on using the changeset viewer.