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/waveplay.cpp

    r391 r468  
    7979            dprintf(("OSS16_WaveOpen failed!!"));
    8080#endif
    81 //            DevHelp_Beep(1000, 100);
    8281            DebugInt3();
    8382//            StreamId = 0;
     
    108107{
    109108#ifdef DEBUG
    110     dprintf(("WAVEPLAY::Close stream: %lx, %lx, os: %lx\n", StreamId, waveOpened,open_strategy));
     109    dprintf(("WAVEPLAY::Close stream: %lx, %lx, os: %lx", StreamId, waveOpened,open_strategy));
    111110#endif
    112111#if 0 // fixme to be gone?
     
    120119        force_closed = 0;
    121120#ifdef DEBUG
    122         dprintf(("WAVEPLAY::Closed stream: %lx, %lx, os: %lx\n", StreamId, waveOpened,open_strategy));
     121        dprintf(("WAVEPLAY::Closed stream: %lx, %lx, os: %lx", StreamId, waveOpened,open_strategy));
    123122#endif
    124123        return TRUE;
     
    141140                open_strategy = 0UL;
    142141#ifdef DEBUG
    143                 dprintf(("OSS16_WAVECLOSE: Success\n"));
     142                dprintf(("OSS16_WAVECLOSE: Success"));
    144143#endif /* DEBUG */
    145144                return TRUE;
    146145            } else
    147146#ifdef DEBUG
    148                 dprintf(("OSS16_WAVECLOSE: Error\n"));
     147                dprintf(("OSS16_WAVECLOSE: Error"));
    149148#endif /* DEBUG */
    150149                return FALSE;
     
    166165    int            samplesize;
    167166    ULONG          ulPCMConsumeRate;
    168     int rc;
     167    USHORT        rc;
    169168
    170169
     
    195194#endif
    196195
    197     if(ulFirstBufSize == 0) {
     196    if(ulFirstBufSize == 0)
     197    {
    198198        ulFirstBufSize = pConfigInfo->ulFragsize; //no conversion required (see below)
    199         if(ulFirstBufSize == 0) {
     199        if (ulFirstBufSize == 0)
     200        {
    200201            DebugInt3();
    201202            ulFirstBufSize = 8192; //should never happen!
     
    205206        }
    206207    }
    207     else {
     208    else
     209    {
    208210        //convert size of first buffer
    209211        ulFirstBufSize = ConvertLength(ulFirstBufSize, pConfigInfo);
     
    212214#endif /* DEBUG */
    213215    }
    214 
    215216    //Must call this method (i.e. resets sample rate conversion position)
    216217    WAVEAUDIO::ConfigDev(StreamId, pConfigInfo, ulFirstBufSize);
     
    225226#endif /* DEBUG */
    226227
    227     fragsize = ulPCMConsumeRate/64; //start with 64 irqs/sec
     228    fragsize = ulPCMConsumeRate/64; //start with 64 irqs/sec   2756
    228229
    229230    //if the buffer is smaller than our predefined fragmentsize (*2), then correct it
     
    232233    //There's nothing we can do about it as the fragment size can't be changed
    233234    //while the stream is playing.
    234     ULONG minimumsize = ulFirstBufSize/2;
     235    ULONG minimumsize = ulFirstBufSize/2;  //650
    235236    if(minimumsize && minimumsize < fragsize)
    236237    {
    237         while(minimumsize < fragsize) fragsize = fragsize / 2;
    238 
     238        while(minimumsize < fragsize) fragsize = fragsize / 2; //
     239 
    239240            if(fragsize < ulPCMConsumeRate/256)
    240241            {//lower limit; don't accept extremely small buffers
     
    257258    hwparam.ulNumChannels   = pConfigInfo->ulHwNumChannels;
    258259    hwparam.ulDataType      = QueryOSSDataFormat(OPERATION_PLAY, pConfigInfo->ulDataType, pConfigInfo->ulHwBitsPerSample);
    259     rc = (int)OSS16_WaveSetFormat(StreamId, &hwparam);
     260    rc = (USHORT)OSS16_WaveSetFormat(StreamId, &hwparam);
    260261#ifdef DEBUG
    261262        dprintf(("WAVEPLAY:ConfigDev:OSS16_WaveSetFormat . rc = %d",rc));
     
    267268#endif
    268269    if( rc != OSSERR_SUCCESS) {
    269 //        DevHelp_Beep(500, 100);
     270        dprintf(("WAVEPLAY:ConfigDev: rc %d",rc));
    270271        DebugInt3();
    271272        // vladest
     
    287288
    288289#ifdef DEBUG
    289 //    dprintf(("WAVEPLAY::Transfer"));
     290//    dprintf(("WAVEPLAY::Transfer %ld",ulBytesToTransfer));
    290291#endif
    291292
     
    299300    }
    300301
     302    //PS very strange
     303    if (!ulBytesToTransfer)
     304    {
     305        return TRUE;
     306    }
     307
    301308//    if (!waveOpened) return TRUE;
    302309
    303310    if(pConfigInfo->usConversion == CONVERT_NONE)
    304311    {
    305 #ifdef DEBUG
    306         dprintf(("Transfer. NoConv ulB %ld",ulBytesToTransfer));
    307 #endif /* DEBUG */
    308         if(AddBuffer(StreamId, pConfigInfo, pUserBuffer, ulBytesToTransfer, pulBytesTransferred) == FALSE)
    309         {
     312        if (AddBuffer(StreamId, pConfigInfo, pUserBuffer, ulBytesToTransfer, pulBytesTransferred) == FALSE)
     313        {
     314#ifdef DEBUG
     315            dprintf(("Transfer.False. NoConv ulB %ld tr:%ld",ulBytesToTransfer,*pulBytesTransferred));
     316#endif /* DEBUG */
    310317            *pulBytesTransferred = 0;
    311318            return FALSE;
    312319        }
    313320    }
    314     else {
    315         if(pConfigInfo->pfnConvert) {
     321    else
     322    {
     323        if(pConfigInfo->pfnConvert)
     324        {
    316325            ULONG ulCvtBufferSize;
    317326
     
    323332            ulBytesToTransfer = CONVERT_LENGTH(ulCvtBufferSize, CONVERSION_INVERT(pConfigInfo->ulConversionFactor));
    324333
    325             if(ulBytesToTransfer & (pConfigInfo->ulSampleSize-1)) {
    326                 DebugInt3();
     334            if(ulBytesToTransfer & (pConfigInfo->ulSampleSize-1))
     335            {
     336                dprintf(("Transfer New ulBr %ld" , ulBytesToTransfer));
     337//                DebugInt3();
    327338                ulBytesToTransfer = ulBytesToTransfer & ~(pConfigInfo->ulSampleSize-1);
    328339#ifdef DEBUG
    329                 dprintf(("New ulBr %ld" , ulBytesToTransfer));
     340                dprintf(("Transfer New ulBr %ld" , ulBytesToTransfer));
    330341#endif
    331342            }
     
    338349            //convert back from conversion to 'real'
    339350            *pulBytesTransferred = CONVERT_LENGTH(*pulBytesTransferred, CONVERSION_INVERT(pConfigInfo->ulConversionFactor));
    340             if(*pulBytesTransferred & (pConfigInfo->ulSampleSize-1)) {
    341                 DebugInt3();
    342 #ifdef DEBUG
    343                 dprintf(("New pulBr %ld" , pulBytesTransferred));
    344 #endif
     351            if(*pulBytesTransferred & (pConfigInfo->ulSampleSize-1))
     352            {
     353#ifdef DEBUG
     354                dprintf(("Transfer New pulBr %ld" , pulBytesTransferred));
     355#endif
     356//                DebugInt3();
    345357            }
    346358        }
    347         else {
    348             DebugInt3();
     359        else
     360        {
     361            dprintf(("Transfer Zero pConfigInfo->pfnConvert"));
     362//            DebugInt3();
    349363            return FALSE;
    350364        }
     
    363377//    if (!waveOpened) return TRUE;
    364378
     379//PS Here is inrerrupt time....
    365380    if (fAPMSuspend)
    366381    {
    367382#ifdef DEBUG
    368         dprintf(("WAVEPLAY::AddBuffer. Suspend state"));
     383//        dprintf(("WAVEPLAY::AddBuffer. Suspend state"));
    369384#endif
    370385        apm_resume();
     
    372387    }
    373388
    374     if(pConfigInfo->fSampleRateConversion)
     389    if (pConfigInfo->fSampleRateConversion)
    375390    {
    376391        ULONG  ulCvtBufferSize, ulSampleCount, ulHwSampleCount;
     
    378393
    379394        //bytes to convert is bounded by bytes to transfer & max conversion buffer size
    380         ulCvtBufferSize = SRATE_CONVERT_LENGTH(ulBytesToTransfer, pConfigInfo->ulSRatePosition,
    381                                                pConfigInfo->ulSRateIncrement);
     395        ulCvtBufferSize = SRATE_CONVERT_LENGTH(ulBytesToTransfer, pConfigInfo->ulSRatePosition, pConfigInfo->ulSRateIncrement);
    382396        ulCvtBufferSize = min(CONVERSION_BUFFER_SIZE, ulCvtBufferSize);
    383397        //round to sample boundary
    384398        ulCvtBufferSize &= ~(pConfigInfo->ulHwSampleSize - 1);
    385399
    386         if(ulCvtBufferSize == 0) {
     400        if(ulCvtBufferSize == 0)
     401        {
    387402            *pulBytesTransferred = ulBytesToTransfer;
    388             if(pConfigInfo->ulSRatePosition >= pConfigInfo->ulSRateIncrement) {
     403            if(pConfigInfo->ulSRatePosition >= pConfigInfo->ulSRateIncrement)
     404            {
    389405                pConfigInfo->ulSRatePosition -= pConfigInfo->ulSRateIncrement;
    390406            }
    391 #ifdef DEBUG
    392             dprintf(("WAVEPLAY::AddBuffer %lx %lx %lx -> nothing left", ulBytesToTransfer, pConfigInfo->ulSRatePosition, pConfigInfo->ulSRateIncrement));
    393 #endif /* DEBUG */
    394407            return TRUE;
    395408        }
    396409        pConfigInfo->pfnSRateConv(pUserBuffer, ulCvtBufferSize, pConfigInfo->pSRateConvBuffer,
    397410                                  pConfigInfo->ulSRatePosition, pConfigInfo->ulSRateIncrement);
    398 //PS++ !!!!! This don't be !!!!!!!
    399411        OSS16_WaveGetSpace(StreamId, &Space);
    400412        if (ulCvtBufferSize > Space)
     
    403415            dprintf(("WPLAY::AddBuffer need %ld space:%ld", ulCvtBufferSize, Space));
    404416#endif
    405             for (i=0; i < 0xffffff; i++)
     417            while (!Space)
     418               for (i=0; i < 0xffffff; i++)
     419               {
     420                    OSS16_WaveGetSpace(StreamId, &Space);
     421                    if (Space & ~(pConfigInfo->ulHwSampleSize - 1)) break;
     422               }
     423#ifdef DEBUG
     424            dprintf(("OUT %lx need %ld space:%ld ",i, ulCvtBufferSize, Space));
     425#endif
     426            if (ulCvtBufferSize > Space)
     427                ulCvtBufferSize = Space & ~(pConfigInfo->ulHwSampleSize - 1);
     428        }
     429        if ((rc = OSS16_WaveAddBuffer(StreamId, pConfigInfo->pSRateConvBuffer, ulCvtBufferSize, pulBytesTransferred)) != OSSERR_SUCCESS
     430             ||  *pulBytesTransferred == 0)
     431        {
     432            if(rc == OSSERR_BUFFER_FULL)
    406433            {
    407                  OSS16_WaveGetSpace(StreamId, &Space);
    408                  if (ulCvtBufferSize <= Space) break;
    409             }
    410 #ifdef DEBUG
    411             dprintf(("OUT %ld need %ld space:%ld Last:%ld",i, ulCvtBufferSize, Space,LastSpace));
    412 #endif
    413         }
    414         if((rc = OSS16_WaveAddBuffer(StreamId, pConfigInfo->pSRateConvBuffer, ulCvtBufferSize, pulBytesTransferred)) != OSSERR_SUCCESS ||
    415            *pulBytesTransferred == 0)
    416         {
    417             if(rc == OSSERR_BUFFER_FULL) {
    418434                 GetSpace(StreamId, pConfigInfo, &Space);
    419435                 dprintf(("WPLAY::AddBuffer; OSS16_WaveAddBuffer %ld %x failed due to full buffer free space:%ld", ulCvtBufferSize, (USHORT)rc,Space));
    420436            }
    421             else dprintf(("WPLAY::AddBuffer; OSS16_WaveAddBuffer %ld rc=%x failed", ulCvtBufferSize, (USHORT)rc));
     437#ifdef DEBUG
     438            else
     439                dprintf(("WPLAY::AddBuffer; OSS16_WaveAddBuffer %ld rc=%x failed", ulCvtBufferSize, (USHORT)rc));
     440#endif
    422441            *pulBytesTransferred = 0;
    423442            return FALSE;
     
    437456        // if the last sample is still needed for the next run, then adjust sample count and
    438457        // sample rate conversion position
    439         if(lSRatePosition < 0) {
     458        if(lSRatePosition < 0)
     459        {
    440460            dprintf4(("WAVEPLAY::AddBuffer; sratepos < 0"));
    441461            dprintf4(("ulHwSampleCount %lx pConfigInfo->ulSRateIncrement %lx ulSampleCount %lx", ulHwSampleCount, pConfigInfo->ulSRateIncrement, ulSampleCount));
    442462            pConfigInfo->ulSRatePosition = 0;
    443463        }
    444         else {
     464        else
     465        {
    445466            pConfigInfo->ulSRatePosition = (ULONG)lSRatePosition;
    446467        }
     
    451472       if( (rc=OSS16_WaveAddBuffer(StreamId, pUserBuffer, ulBytesToTransfer, pulBytesTransferred)) != OSSERR_SUCCESS)
    452473       {
    453         *pulBytesTransferred = 0;
    454         dprintf(("WPLAY::AddBuffer; OSS16_WaveAddBuffer failed due to an error rc=%x",(USHORT)rc));
    455         return FALSE;
    456         }
     474            *pulBytesTransferred = 0;
     475            dprintf(("WPLAY::AddBuffer; OSS16_WaveAddBuffer failed due to an error rc=%x",(USHORT)rc));
     476            dprintf(("StreamID:%x PUB:%lx BtTr:%ld",(USHORT)StreamId, pUserBuffer, ulBytesToTransfer));
     477            return FALSE;
     478       }
    457479    }
    458480    return TRUE;
     
    489511//    if (!waveOpened) return TRUE;
    490512
    491     if(OSS16_WaveGetSpace(StreamId, &space) != OSSERR_SUCCESS) {
     513    if(OSS16_WaveGetSpace(StreamId, &space) != OSSERR_SUCCESS)
     514    {
    492515        *pulStreamSpace = 0;
    493516#ifdef DEBUG
     
    496519        return FALSE;
    497520    }
    498     LastSpace = space;
     521
     522//    dprintf(("GetSpace: len %ld",space));
    499523    cvt  = ConvertLengthInvert(space, pConfigInfo);
    500524    //round to sample boundary
     
    509533    ULONG space,cvt;
    510534
    511     if(OSS16_WaveGetHwPtr(StreamId, &space) != OSSERR_SUCCESS) {
     535    if(OSS16_WaveGetHwPtr(StreamId, &space) != OSSERR_SUCCESS)
     536    {
    512537        *pulHwPtr = 0;
    513538        #ifdef DEBUG
     
    516541        return FALSE;
    517542    }
     543
    518544    cvt  = ConvertLengthInvert(space, pConfigInfo);
    519545    //round to sample boundary
    520     *pulHwPtr = cvt & ( ~(pConfigInfo->ulSampleSize - 1));
     546    *pulHwPtr = cvt & (~(pConfigInfo->ulSampleSize - 1));
    521547    return TRUE;
    522548}
Note: See TracChangeset for help on using the changeset viewer.