Ignore:
Timestamp:
Jul 12, 2010, 12:57:31 AM (15 years ago)
Author:
David Azarewicz
Message:

AddBuffers reentry fix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • OCO/branches/DAZ/drv16/waveplay.cpp

    r507 r513  
    22/* SCCSID = %W% %E% */
    33/****************************************************************************
    4  *                                                                          *
    5  * Copyright (c) IBM Corporation 1994 - 1997.                               *
    6  *                                                                          *
    7  * The following IBM OS/2 source code is provided to you solely for the     *
     4 *                                                                                                                                                      *
     5 * Copyright (c) IBM Corporation 1994 - 1997.                                                           *
     6 *                                                                                                                                                      *
     7 * The following IBM OS/2 source code is provided to you solely for the         *
    88 * the purpose of assisting you in your development of OS/2 device drivers. *
    9  * You may use this code in accordance with the IBM License Agreement       *
    10  * provided in the IBM Device Driver Source Kit for OS/2.                   *
    11  *                                                                          *
     9 * You may use this code in accordance with the IBM License Agreement           *
     10 * provided in the IBM Device Driver Source Kit for OS/2.                                       *
     11 *                                                                                                                                                      *
    1212 ****************************************************************************/
    1313/**@internal %W%
     
    1515 * @version %I%
    1616 * @context Unless otherwise noted, all interfaces are Ring-0, 16-bit,
    17  *  <stack context>.
     17 *      <stack context>.
    1818 * @history
    1919 *
     
    4444extern "C"
    4545{
    46     ULONG open_strategy = 0UL;
    47     ULONG LastSpace=0;
     46        ULONG open_strategy = 0UL;
     47        ULONG LastSpace=0;
    4848        //int force_close(void);
    4949}
     
    5959BOOL WAVEPLAY::Open(ULONG ulDevice, ULONG ulStreamType, ULONG ulSysFileNum, OSSSTREAMID FAR *pStreamId)
    6060{
    61     ULONG ret;
     61        ULONG ret;
    6262        //dprintf(("WAVEPLAY::Open %lx",StreamId));
    63     if (fAPMSuspend)
    64     {
     63        if (fAPMSuspend)
     64        {
    6565                //dprintf(("WAVEPLAY::Open. Suspend state"));
    66         apm_resume();
    67     }
    68 
    69     if(StreamId == 0UL)
    70     {
    71         if((ret = OSS16_WaveOpen(ulDevice, ulStreamType, ulSysFileNum, pStreamId)) != OSSERR_SUCCESS)
    72         {
    73             dprintf(("OSS16_WaveOpen failed!!"));
    74             DebugInt3();
     66                apm_resume();
     67        }
     68
     69        if(StreamId == 0UL)
     70        {
     71                if((ret = OSS16_WaveOpen(ulDevice, ulStreamType, ulSysFileNum, pStreamId)) != OSSERR_SUCCESS)
     72                {
     73                        dprintf(("OSS16_WaveOpen failed!!"));
     74                        DebugInt3();
    7575                        //StreamId = 0;
    7676                        //waveOpened = 0;
    77             return FALSE;
    78         } else
    79             waveOpened++;
    80         //if the device only supports one active stream, then it is shared by
    81         //all wave stream instances. MMPM/2 takes care of proper sharing for us
    82         //if the device supports multiple active streams, then we always open
    83         //a new ALSA stream
    84         //if(devCaps[ulDevice].waveOutCaps.nrStreams == 1) {
    85             StreamId = *pStreamId;
    86         //}
    87         ulDeviceSave = ulDevice;
    88         ulStreamTypeSave = ulStreamType;
    89         ulSysFileNumSave = ulSysFileNum;
    90     }
    91     else {
    92         *pStreamId = StreamId;
    93     }
    94     return TRUE;
     77                        return FALSE;
     78                } else
     79                        waveOpened++;
     80                //if the device only supports one active stream, then it is shared by
     81                //all wave stream instances. MMPM/2 takes care of proper sharing for us
     82                //if the device supports multiple active streams, then we always open
     83                //a new ALSA stream
     84                //if(devCaps[ulDevice].waveOutCaps.nrStreams == 1) {
     85                        StreamId = *pStreamId;
     86                //}
     87                ulDeviceSave = ulDevice;
     88                ulStreamTypeSave = ulStreamType;
     89                ulSysFileNumSave = ulSysFileNum;
     90        }
     91        else {
     92                *pStreamId = StreamId;
     93        }
     94        return TRUE;
    9595}
    9696
     
    101101        //dprintf(("WAVEPLAY::Close stream: %lx, %lx, os: %lx", StreamId, waveOpened,open_strategy));
    102102#if 0 // fixme to be gone?
    103     //if ((open_strategy & 1))
    104     //if (waveOpened == 1)
    105     if (force_closed)
    106     {
    107         waveOpened--;
    108         StreamId = 0UL;
    109         open_strategy = 0UL;
    110         force_closed = 0;
     103        //if ((open_strategy & 1))
     104        //if (waveOpened == 1)
     105        if (force_closed)
     106        {
     107                waveOpened--;
     108                StreamId = 0UL;
     109                open_strategy = 0UL;
     110                force_closed = 0;
    111111                //dprintf(("WAVEPLAY::Closed stream: %lx, %lx, os: %lx", StreamId, waveOpened,open_strategy));
    112         return TRUE;
    113     }
    114     else
     112                return TRUE;
     113        }
     114        else
    115115#endif // fixme to be gone?
    116     {
    117 /* Setting DISABLE_STREAM_REUSE will close the open stream here.      */
     116        {
     117/* Setting DISABLE_STREAM_REUSE will close the open stream here.          */
    118118/* If left unset, the idea is the open stream will be reused instead. */
    119 /* FIXME: Does it make sense that a Close function does not close     */
    120 /* anything?                                                          */
     119/* FIXME: Does it make sense that a Close function does not close         */
     120/* anything?                                                                                                              */
    121121#ifdef DISABLE_STREAM_REUSE
    122         if(devCaps[ulDeviceNr].waveOutCaps.nrStreams > 1)
    123         {
    124             if (OSS16_WaveClose(StreamIdl) == OSSERR_SUCCESS)
    125             {
    126                 waveOpened--;
    127                 StreamId = 0UL;
    128                 open_strategy = 0UL;
     122                if(devCaps[ulDeviceNr].waveOutCaps.nrStreams > 1)
     123                {
     124                        if (OSS16_WaveClose(StreamIdl) == OSSERR_SUCCESS)
     125                        {
     126                                waveOpened--;
     127                                StreamId = 0UL;
     128                                open_strategy = 0UL;
    129129                                dprintf(("OSS16_WAVECLOSE: Success"));
    130                 return TRUE;
    131             } else {
    132                 dprintf(("OSS16_WAVECLOSE: Error"));
    133                 return FALSE;
    134                         }
    135         }
    136         else
     130                                return TRUE;
     131                        } else {
     132                                dprintf(("OSS16_WAVECLOSE: Error"));
     133                                return FALSE;
     134                        }
     135                }
     136                else
    137137#else /* !DISABLE_STREAM_REUSE */
    138138                if (StreamIdl == NULL) return FALSE;
    139139#endif /* DISABLE_STREAM_REUSE */
    140         return TRUE;
    141     }
     140                return TRUE;
     141        }
    142142}
    143143//******************************************************************************
     
    145145BOOL WAVEPLAY::ConfigDev(OSSSTREAMID StreamId, PWAVECONFIGINFO pConfigInfo, ULONG ulFirstBufSize)
    146146{
    147     OSS32_HWPARAMS hwparam;
    148     ULONG          fragsize;
    149     int            samplesize;
    150     ULONG          ulPCMConsumeRate;
    151     USHORT         rc;
    152 
    153 
    154     if (fAPMSuspend)
    155     {
     147        OSS32_HWPARAMS hwparam;
     148        ULONG              fragsize;
     149        int                samplesize;
     150        ULONG              ulPCMConsumeRate;
     151        USHORT             rc;
     152
     153
     154        if (fAPMSuspend)
     155        {
    156156                //dprintf(("WAVEPLAY::ConfigDev. Suspend state"));
    157         apm_resume();
    158     }
    159 
    160     if (StreamId == NULL)
    161     {
    162         WAVEPLAY::Open(ulDeviceSave, ulStreamTypeSave, ulSysFileNumSave, &StreamId);
    163         if (StreamId == NULL)
    164         {
    165             dprintf(("WAVEPLAY::ConfigDev. Error reopening stream"));
    166             return FALSE;
    167         }
    168     }
    169     dprintf4(("WAVEPLAY::ConfigDev SampleRate %ld", pConfigInfo->ulHwSampleRate));
    170     dprintf4(("WAVEPLAY::ConfigDev ulFirstBufSize=%lx ulFragsize=%lx", ulFirstBufSize, pConfigInfo->ulFragsize));
    171 
    172     if(ulFirstBufSize == 0)
    173     {
    174         ulFirstBufSize = pConfigInfo->ulFragsize; //no conversion required (see below)
    175         if (ulFirstBufSize == 0)
    176         {
    177             DebugInt3();
    178             ulFirstBufSize = 8192; //should never happen!
    179             dprintf(("Arg - shouldn't happen"));
    180         }
    181     }
    182     else
    183     {
    184         //convert size of first buffer
    185         ulFirstBufSize = ConvertLength(ulFirstBufSize, pConfigInfo);
    186         dprintf4(("ulFirstBufSize %lx", ulFirstBufSize));
    187     }
    188     //Must call this method (i.e. resets sample rate conversion position)
    189     WAVEAUDIO::ConfigDev(StreamId, pConfigInfo, ulFirstBufSize);
    190 
    191     //get real sample format used to program the audio hardware (taking conversion into account)
    192     QuerySampleFormat(OPERATION_PLAY, pConfigInfo);
    193 
    194     //convert consume rate
    195     ulPCMConsumeRate = ConvertLength(pConfigInfo->ulPCMConsumeRate, pConfigInfo);
    196     dprintf4(("cons rate %lx buf size %lx init rate %ld", ulPCMConsumeRate, ulFirstBufSize, pConfigInfo->ulHwSampleRate));
    197 
    198     fragsize = ulPCMConsumeRate/64; //start with 64 irqs/sec   2756
    199 
    200     //if the buffer is smaller than our predefined fragmentsize (*2), then correct it
    201     //I assume here that buffers sizes don't radically change (except the last one)
    202     //while playing a stream. If they do get a lot smaller, then we'll run into problems.
    203     //There's nothing we can do about it as the fragment size can't be changed
    204     //while the stream is playing.
    205     ULONG minimumsize = ulFirstBufSize/2;  //650
    206     if(minimumsize && minimumsize < fragsize)
    207     {
    208         while(minimumsize < fragsize) fragsize = fragsize / 2; //
    209 
    210             if(fragsize < ulPCMConsumeRate/256)
    211             {//lower limit; don't accept extremely small buffers
    212                 fragsize = ulPCMConsumeRate/256;
    213             }
    214     }
    215     samplesize = (int)pConfigInfo->ulHwSampleSize;
    216 
    217     //round to nearest 64 byte boundary
    218     fragsize = (fragsize + 63) & ~(63);
    219 
    220     hwparam.ulPeriodSize    = fragsize;
    221     pConfigInfo->ulFragsize = fragsize;
    222 
    223     dprintf4(("fragsize %lx", fragsize));
    224     hwparam.ulSampleRate    = pConfigInfo->ulHwSampleRate;
    225     hwparam.ulBitsPerSample = pConfigInfo->ulHwBitsPerSample;
    226     hwparam.ulNumChannels   = pConfigInfo->ulHwNumChannels;
    227     hwparam.ulDataType      = QueryOSSDataFormat(OPERATION_PLAY, pConfigInfo->ulDataType, pConfigInfo->ulHwBitsPerSample);
    228     rc = (USHORT)OSS16_WaveSetFormat(StreamId, &hwparam);
    229         dprintf4(("WAVEPLAY:ConfigDev:OSS16_WaveSetFormat . rc = %d",rc));
    230         dprintf4(("samp rate=%ld bps=%ld channels=%ld type=%ld", hwparam.ulSampleRate, hwparam.ulBitsPerSample, hwparam.ulNumChannels, hwparam.ulDataType));
    231 
    232     if( rc != OSSERR_SUCCESS) {
    233         dprintf(("WAVEPLAY:ConfigDev: rc %d",rc));
    234         DebugInt3();
    235         // vladest
    236 //        OSS16_WaveClose(StreamId);
    237 //        StreamId = 0;
    238 //        waveOpened = 0;
    239         return FALSE;
    240     }
    241     return TRUE;
     157                apm_resume();
     158        }
     159
     160        if (StreamId == NULL)
     161        {
     162                WAVEPLAY::Open(ulDeviceSave, ulStreamTypeSave, ulSysFileNumSave, &StreamId);
     163                if (StreamId == NULL)
     164                {
     165                        dprintf(("WAVEPLAY::ConfigDev. Error reopening stream"));
     166                        return FALSE;
     167                }
     168        }
     169        dprintf4(("WAVEPLAY::ConfigDev SampleRate %ld", pConfigInfo->ulHwSampleRate));
     170        dprintf4(("WAVEPLAY::ConfigDev ulFirstBufSize=%lx ulFragsize=%lx", ulFirstBufSize, pConfigInfo->ulFragsize));
     171
     172        if(ulFirstBufSize == 0)
     173        {
     174                ulFirstBufSize = pConfigInfo->ulFragsize; //no conversion required (see below)
     175                if (ulFirstBufSize == 0)
     176                {
     177                        DebugInt3();
     178                        ulFirstBufSize = 8192; //should never happen!
     179                        dprintf(("Arg - shouldn't happen"));
     180                }
     181        }
     182        else
     183        {
     184                //convert size of first buffer
     185                ulFirstBufSize = ConvertLength(ulFirstBufSize, pConfigInfo);
     186                dprintf4(("ulFirstBufSize %lx", ulFirstBufSize));
     187        }
     188        //Must call this method (i.e. resets sample rate conversion position)
     189        WAVEAUDIO::ConfigDev(StreamId, pConfigInfo, ulFirstBufSize);
     190
     191        //get real sample format used to program the audio hardware (taking conversion into account)
     192        QuerySampleFormat(OPERATION_PLAY, pConfigInfo);
     193
     194        //convert consume rate
     195        ulPCMConsumeRate = ConvertLength(pConfigInfo->ulPCMConsumeRate, pConfigInfo);
     196        dprintf4(("cons rate %lx buf size %lx init rate %ld", ulPCMConsumeRate, ulFirstBufSize, pConfigInfo->ulHwSampleRate));
     197
     198        fragsize = ulPCMConsumeRate/64; //start with 64 irqs/sec   2756
     199
     200        //if the buffer is smaller than our predefined fragmentsize (*2), then correct it
     201        //I assume here that buffers sizes don't radically change (except the last one)
     202        //while playing a stream. If they do get a lot smaller, then we'll run into problems.
     203        //There's nothing we can do about it as the fragment size can't be changed
     204        //while the stream is playing.
     205        ULONG minimumsize = ulFirstBufSize/2;  //650
     206        if(minimumsize && minimumsize < fragsize)
     207        {
     208                while(minimumsize < fragsize) fragsize = fragsize / 2; //
     209
     210                if(fragsize < ulPCMConsumeRate/256)
     211                {//lower limit; don't accept extremely small buffers
     212                        fragsize = ulPCMConsumeRate/256;
     213                }
     214        }
     215        samplesize = (int)pConfigInfo->ulHwSampleSize;
     216
     217        //round to nearest 64 byte boundary
     218        fragsize = (fragsize + 63) & ~(63);
     219
     220        hwparam.ulPeriodSize    = fragsize;
     221        pConfigInfo->ulFragsize = fragsize;
     222
     223        dprintf4(("fragsize %lx", fragsize));
     224        hwparam.ulSampleRate    = pConfigInfo->ulHwSampleRate;
     225        hwparam.ulBitsPerSample = pConfigInfo->ulHwBitsPerSample;
     226        hwparam.ulNumChannels   = pConfigInfo->ulHwNumChannels;
     227        hwparam.ulDataType              = QueryOSSDataFormat(OPERATION_PLAY, pConfigInfo->ulDataType, pConfigInfo->ulHwBitsPerSample);
     228        rc = (USHORT)OSS16_WaveSetFormat(StreamId, &hwparam);
     229                dprintf4(("WAVEPLAY:ConfigDev:OSS16_WaveSetFormat . rc = %d",rc));
     230                dprintf4(("samp rate=%ld bps=%ld channels=%ld type=%ld", hwparam.ulSampleRate, hwparam.ulBitsPerSample, hwparam.ulNumChannels, hwparam.ulDataType));
     231
     232        if( rc != OSSERR_SUCCESS) {
     233                dprintf(("WAVEPLAY:ConfigDev: rc %d",rc));
     234                DebugInt3();
     235                // vladest
     236//                OSS16_WaveClose(StreamId);
     237//                StreamId = 0;
     238//                waveOpened = 0;
     239                return FALSE;
     240        }
     241        return TRUE;
    242242}
    243243//******************************************************************************
     
    246246//******************************************************************************
    247247BOOL WAVEPLAY::Transfer(OSSSTREAMID StreamId, PWAVECONFIGINFO pConfigInfo,
    248                         LINEAR pUserBuffer, ULONG ulBytesToTransfer,
    249                         ULONG FAR *pulBytesTransferred)
    250 {
    251     *pulBytesTransferred = 0;
    252 
    253     //dprintf(("WAVEPLAY::Transfer %ld",ulBytesToTransfer));
    254 
    255     if (fAPMSuspend) {
     248                                                LINEAR pUserBuffer, ULONG ulBytesToTransfer,
     249                                                ULONG FAR *pulBytesTransferred)
     250{
     251        *pulBytesTransferred = 0;
     252
     253        //dprintf(("WAVEPLAY::Transfer %ld",ulBytesToTransfer));
     254
     255        if (fAPMSuspend) {
    256256                //dprintf(("WAVEPLAY::Transfer. Suspend state"));
    257         apm_resume();
    258     }
    259 
    260     if (!ulBytesToTransfer) {
    261         return TRUE;
    262     }
     257                apm_resume();
     258        }
     259
     260        if (!ulBytesToTransfer) {
     261                return TRUE;
     262        }
    263263
    264264        //if (!waveOpened) return TRUE;
    265265
    266     if(pConfigInfo->usConversion == CONVERT_NONE)
    267     {
    268         if (AddBuffer(StreamId, pConfigInfo, pUserBuffer, ulBytesToTransfer, pulBytesTransferred) == FALSE)
    269         {
    270             dprintf(("Transfer.False. NoConv ulB %ld tr:%ld",ulBytesToTransfer,*pulBytesTransferred));
    271             *pulBytesTransferred = 0;
    272             return FALSE;
    273         }
    274     }
    275     else
    276     {
    277         if(pConfigInfo->pfnConvert)
    278         {
    279             ULONG ulCvtBufferSize;
    280 
    281             //bytes to convert is bounded by bytes to transfer & max conversion buffer size
    282             ulCvtBufferSize = CONVERT_LENGTH(ulBytesToTransfer, pConfigInfo->ulConversionFactor);
    283             ulCvtBufferSize = min(CONVERSION_BUFFER_SIZE, ulCvtBufferSize);
    284 
    285             //convert back from conversion to 'real'
    286             ulBytesToTransfer = CONVERT_LENGTH(ulCvtBufferSize, CONVERSION_INVERT(pConfigInfo->ulConversionFactor));
    287 
    288             if(ulBytesToTransfer & (pConfigInfo->ulSampleSize-1))
    289             {
    290                 dprintf(("Transfer New ulBr %ld" , ulBytesToTransfer));
     266        if(pConfigInfo->usConversion == CONVERT_NONE)
     267        {
     268                if (AddBuffer(StreamId, pConfigInfo, pUserBuffer, ulBytesToTransfer, pulBytesTransferred) == FALSE)
     269                {
     270                        dprintf(("Transfer.False. NoConv ulB %ld tr:%ld",ulBytesToTransfer,*pulBytesTransferred));
     271                        *pulBytesTransferred = 0;
     272                        return FALSE;
     273                }
     274        }
     275        else
     276        {
     277                if(pConfigInfo->pfnConvert)
     278                {
     279                        ULONG ulCvtBufferSize;
     280
     281                        //bytes to convert is bounded by bytes to transfer & max conversion buffer size
     282                        ulCvtBufferSize = CONVERT_LENGTH(ulBytesToTransfer, pConfigInfo->ulConversionFactor);
     283                        ulCvtBufferSize = min(CONVERSION_BUFFER_SIZE, ulCvtBufferSize);
     284
     285                        //convert back from conversion to 'real'
     286                        ulBytesToTransfer = CONVERT_LENGTH(ulCvtBufferSize, CONVERSION_INVERT(pConfigInfo->ulConversionFactor));
     287
     288                        if(ulBytesToTransfer & (pConfigInfo->ulSampleSize-1))
     289                        {
     290                                dprintf(("Transfer New ulBr %ld" , ulBytesToTransfer));
    291291                                //DebugInt3();
    292                 ulBytesToTransfer = ulBytesToTransfer & ~(pConfigInfo->ulSampleSize-1);
    293                 dprintf(("Transfer New ulBr %ld" , ulBytesToTransfer));
    294             }
    295             pConfigInfo->pfnConvert(pUserBuffer, ulBytesToTransfer, pConfigInfo->pConversionBuffer);
    296             if(AddBuffer(StreamId, pConfigInfo, pConfigInfo->pConversionBuffer, ulCvtBufferSize, pulBytesTransferred) == FALSE)
    297             {
    298                 *pulBytesTransferred = 0;
    299                 return FALSE;
    300             }
    301             //convert back from conversion to 'real'
    302             *pulBytesTransferred = CONVERT_LENGTH(*pulBytesTransferred, CONVERSION_INVERT(pConfigInfo->ulConversionFactor));
    303             if(*pulBytesTransferred & (pConfigInfo->ulSampleSize-1))
    304             {
    305                 dprintf(("Transfer New pulBr %ld" , pulBytesTransferred));
     292                                ulBytesToTransfer = ulBytesToTransfer & ~(pConfigInfo->ulSampleSize-1);
     293                                dprintf(("Transfer New ulBr %ld" , ulBytesToTransfer));
     294                        }
     295                        pConfigInfo->pfnConvert(pUserBuffer, ulBytesToTransfer, pConfigInfo->pConversionBuffer);
     296                        if(AddBuffer(StreamId, pConfigInfo, pConfigInfo->pConversionBuffer, ulCvtBufferSize, pulBytesTransferred) == FALSE)
     297                        {
     298                                *pulBytesTransferred = 0;
     299                                return FALSE;
     300                        }
     301                        //convert back from conversion to 'real'
     302                        *pulBytesTransferred = CONVERT_LENGTH(*pulBytesTransferred, CONVERSION_INVERT(pConfigInfo->ulConversionFactor));
     303                        if(*pulBytesTransferred & (pConfigInfo->ulSampleSize-1))
     304                        {
     305                                dprintf(("Transfer New pulBr %ld" , pulBytesTransferred));
    306306                                //DebugInt3();
    307             }
    308         }
    309         else
    310         {
    311             dprintf(("Transfer Zero pConfigInfo->pfnConvert"));
     307                        }
     308                }
     309                else
     310                {
     311                        dprintf(("Transfer Zero pConfigInfo->pfnConvert"));
    312312                        //DebugInt3();
    313             return FALSE;
    314         }
    315     }
    316     return TRUE;
     313                        return FALSE;
     314                }
     315        }
     316        return TRUE;
    317317}
    318318//******************************************************************************
     
    320320//******************************************************************************
    321321BOOL WAVEPLAY::AddBuffer(OSSSTREAMID StreamId, PWAVECONFIGINFO pConfigInfo, LINEAR pUserBuffer,
    322                         ULONG ulBytesToTransfer, ULONG FAR *pulBytesTransferred)
    323 {
    324     OSSRET rc;
    325     ULONG  Space;
     322                                                ULONG ulBytesToTransfer, ULONG FAR *pulBytesTransferred)
     323{
     324        OSSRET rc;
     325        ULONG  Space;
    326326        //if (!waveOpened) return TRUE;
    327327
    328328        //PS Here is inrerrupt time....
    329     if (fAPMSuspend) {
     329        if (fAPMSuspend) {
    330330                //dprintf(("WAVEPLAY::AddBuffer. Suspend state"));
    331         apm_resume();
    332         //return FALSE;
    333     }
    334 
    335     if (pConfigInfo->fSampleRateConversion)
    336     {
    337         ULONG  ulCvtBufferSize, ulSampleCount, ulHwSampleCount;
    338         LONG   lSRatePosition;
    339 
    340         //bytes to convert is bounded by bytes to transfer & max conversion buffer size
    341         ulCvtBufferSize = SRATE_CONVERT_LENGTH(ulBytesToTransfer, pConfigInfo->ulSRatePosition, pConfigInfo->ulSRateIncrement);
    342         ulCvtBufferSize = min(CONVERSION_BUFFER_SIZE, ulCvtBufferSize);
    343         //round to sample boundary
    344         ulCvtBufferSize &= ~(pConfigInfo->ulHwSampleSize - 1);
    345 
    346         if(ulCvtBufferSize == 0)
    347         {
    348             *pulBytesTransferred = ulBytesToTransfer;
    349             if(pConfigInfo->ulSRatePosition >= pConfigInfo->ulSRateIncrement)
    350             {
    351                 pConfigInfo->ulSRatePosition -= pConfigInfo->ulSRateIncrement;
    352             }
    353             return TRUE;
    354         }
    355         pConfigInfo->pfnSRateConv(pUserBuffer, ulCvtBufferSize, pConfigInfo->pSRateConvBuffer,
    356                                   pConfigInfo->ulSRatePosition, pConfigInfo->ulSRateIncrement);
    357         OSS16_WaveGetSpace(StreamId, &Space);
    358         if (ulCvtBufferSize > Space)
    359         {
    360             dprintf(("WPLAY::AddBuffer need %ld space:%ld", ulCvtBufferSize, Space));
    361             if (Space < pConfigInfo->ulBytesPerIRQ)
    362             {
    363                return TRUE;
    364             }
    365 
    366             if (ulCvtBufferSize > Space)
    367                 ulCvtBufferSize = Space & ~(pConfigInfo->ulHwSampleSize - 1);
    368         }
    369         if ((rc = OSS16_WaveAddBuffer(StreamId, pConfigInfo->pSRateConvBuffer, ulCvtBufferSize, pulBytesTransferred)) != OSSERR_SUCCESS
    370              ||  *pulBytesTransferred == 0)
    371         {
    372             if(rc == OSSERR_BUFFER_FULL)
    373             {
    374                  GetSpace(StreamId, pConfigInfo, &Space);
    375                  dprintf(("WPLAY::AddBuffer; %ld %x failed due to full buffer free space:%ld", ulCvtBufferSize, (USHORT)rc,Space));
    376             }
    377 #ifdef DEBUG
    378             else
    379                 dprintf(("WPLAY::AddBuffer; %ld rc=%x failed", ulCvtBufferSize, (USHORT)rc));
    380 #endif
    381             *pulBytesTransferred = 0;
    382             return FALSE;
    383         }
    384         ulHwSampleCount = *pulBytesTransferred/pConfigInfo->ulHwSampleSize;
    385 
    386         //convert back from conversion to 'real'
    387         ulSampleCount   = SRATE_CONVERT_LENGTH_INVERT(ulHwSampleCount,
    388                                                       pConfigInfo->ulSRatePosition,
    389                                                       pConfigInfo->ulSRateIncrement);
    390 
    391         //update sample rate position
    392 
    393         lSRatePosition = (LONG)(pConfigInfo->ulSRatePosition + ulHwSampleCount * pConfigInfo->ulSRateIncrement);
    394         lSRatePosition = lSRatePosition - (LONG)ulSampleCount*(LONG)SRATE_SHIFT_VALUE;
    395 
    396         // if the last sample is still needed for the next run, then adjust sample count and
    397         // sample rate conversion position
    398         if(lSRatePosition < 0)
    399         {
    400             dprintf4(("WAVEPLAY::AddBuffer; sratepos < 0"));
    401             dprintf4(("ulHwSampleCount %lx pConfigInfo->ulSRateIncrement %lx ulSampleCount %lx", ulHwSampleCount, pConfigInfo->ulSRateIncrement, ulSampleCount));
    402             pConfigInfo->ulSRatePosition = 0;
    403         }
    404         else
    405         {
    406             pConfigInfo->ulSRatePosition = (ULONG)lSRatePosition;
    407         }
    408         *pulBytesTransferred = ulSampleCount*pConfigInfo->ulHwSampleSize;
    409     }
    410     else
    411     {
    412        if( (rc=OSS16_WaveAddBuffer(StreamId, pUserBuffer, ulBytesToTransfer, pulBytesTransferred)) != OSSERR_SUCCESS)
    413        {
    414             *pulBytesTransferred = 0;
    415             dprintf(("WPLAY::AddBuffer; OSS16_WaveAddBuffer failed due to an error rc=%x",(USHORT)rc));
    416             dprintf(("StreamID:%x PUB:%lx BtTr:%ld",(USHORT)StreamId, pUserBuffer, ulBytesToTransfer));
    417             return FALSE;
    418        }
    419     }
    420     return TRUE;
     331                apm_resume();
     332                //return FALSE;
     333        }
     334
     335        if (pConfigInfo->fSampleRateConversion)
     336        {
     337                ULONG  ulCvtBufferSize, ulSampleCount, ulHwSampleCount;
     338                LONG   lSRatePosition;
     339
     340                //bytes to convert is bounded by bytes to transfer & max conversion buffer size
     341                ulCvtBufferSize = SRATE_CONVERT_LENGTH(ulBytesToTransfer, pConfigInfo->ulSRatePosition, pConfigInfo->ulSRateIncrement);
     342                ulCvtBufferSize = min(CONVERSION_BUFFER_SIZE, ulCvtBufferSize);
     343                //round to sample boundary
     344                ulCvtBufferSize &= ~(pConfigInfo->ulHwSampleSize - 1);
     345
     346                if(ulCvtBufferSize == 0)
     347                {
     348                        *pulBytesTransferred = ulBytesToTransfer;
     349                        if(pConfigInfo->ulSRatePosition >= pConfigInfo->ulSRateIncrement)
     350                        {
     351                                pConfigInfo->ulSRatePosition -= pConfigInfo->ulSRateIncrement;
     352                        }
     353                        return TRUE;
     354                }
     355                pConfigInfo->pfnSRateConv(pUserBuffer, ulCvtBufferSize, pConfigInfo->pSRateConvBuffer,
     356                                                                  pConfigInfo->ulSRatePosition, pConfigInfo->ulSRateIncrement);
     357                OSS16_WaveGetSpace(StreamId, &Space);
     358                if (ulCvtBufferSize > Space)
     359                {
     360                        dprintf(("WPLAY::AddBuffer need %ld space:%ld", ulCvtBufferSize, Space));
     361                        if (Space < pConfigInfo->ulBytesPerIRQ)
     362                        {
     363                           return TRUE;
     364                        }
     365
     366                        if (ulCvtBufferSize > Space)
     367                                ulCvtBufferSize = Space & ~(pConfigInfo->ulHwSampleSize - 1);
     368                }
     369                if ((rc = OSS16_WaveAddBuffer(StreamId, pConfigInfo->pSRateConvBuffer, ulCvtBufferSize, pulBytesTransferred)) != OSSERR_SUCCESS
     370                         ||  *pulBytesTransferred == 0)
     371                {
     372                        if(rc == OSSERR_BUFFER_FULL) {
     373                                 GetSpace(StreamId, pConfigInfo, &Space);
     374                                 dprintf(("WPLAY::AddBuffer; %ld %x failed due to full buffer free space:%ld", ulCvtBufferSize, (USHORT)rc,Space));
     375                        } else {
     376                                dprintf(("WPLAY::AddBuffer; %ld rc=%x failed", ulCvtBufferSize, (USHORT)rc));
     377                        }
     378                        *pulBytesTransferred = 0;
     379                        return FALSE;
     380                }
     381                ulHwSampleCount = *pulBytesTransferred/pConfigInfo->ulHwSampleSize;
     382
     383                //convert back from conversion to 'real'
     384                ulSampleCount   = SRATE_CONVERT_LENGTH_INVERT(ulHwSampleCount,
     385                                                                                                          pConfigInfo->ulSRatePosition,
     386                                                                                                          pConfigInfo->ulSRateIncrement);
     387
     388                //update sample rate position
     389
     390                lSRatePosition = (LONG)(pConfigInfo->ulSRatePosition + ulHwSampleCount * pConfigInfo->ulSRateIncrement);
     391                lSRatePosition = lSRatePosition - (LONG)ulSampleCount*(LONG)SRATE_SHIFT_VALUE;
     392
     393                // if the last sample is still needed for the next run, then adjust sample count and
     394                // sample rate conversion position
     395                if(lSRatePosition < 0)
     396                {
     397                        dprintf4(("WAVEPLAY::AddBuffer; sratepos < 0"));
     398                        dprintf4(("ulHwSampleCount %lx pConfigInfo->ulSRateIncrement %lx ulSampleCount %lx", ulHwSampleCount, pConfigInfo->ulSRateIncrement, ulSampleCount));
     399                        pConfigInfo->ulSRatePosition = 0;
     400                }
     401                else
     402                {
     403                        pConfigInfo->ulSRatePosition = (ULONG)lSRatePosition;
     404                }
     405                *pulBytesTransferred = ulSampleCount*pConfigInfo->ulHwSampleSize;
     406        }
     407        else
     408        {
     409           if( (rc=OSS16_WaveAddBuffer(StreamId, pUserBuffer, ulBytesToTransfer, pulBytesTransferred)) != OSSERR_SUCCESS)
     410           {
     411                        *pulBytesTransferred = 0;
     412                        dprintf(("WPLAY::AddBuffer; OSS16_WaveAddBuffer failed due to an error rc=%x",(USHORT)rc));
     413                        dprintf(("StreamID:%x PUB:%lx BtTr:%ld",(USHORT)StreamId, pUserBuffer, ulBytesToTransfer));
     414                        return FALSE;
     415           }
     416        }
     417        return TRUE;
    421418}
    422419//******************************************************************************
     
    425422BOOL WAVEPLAY::GetPosition(OSSSTREAMID StreamId, PWAVECONFIGINFO pConfigInfo, ULONG FAR *pulStreamPosition)
    426423{
    427     ULONG ulCurBytesProcessed;
    428 
    429 //    if (!waveOpened) return TRUE;
    430 
    431     if(OSS16_WaveGetPos(StreamId, &ulCurBytesProcessed) != OSSERR_SUCCESS) {
    432         *pulStreamPosition = 0;
    433         dprintf(("WAVEPLAY::GetPosition: Failed"));
    434         return FALSE;
    435     }
    436 
    437     *pulStreamPosition  = ConvertPositionInvert(ulCurBytesProcessed, pConfigInfo);
    438     //round to sample boundary
    439     *pulStreamPosition &= ~(pConfigInfo->ulSampleSize - 1);
    440     return TRUE;
     424        ULONG ulCurBytesProcessed;
     425
     426        //if (!waveOpened) return TRUE;
     427
     428        if(OSS16_WaveGetPos(StreamId, &ulCurBytesProcessed) != OSSERR_SUCCESS) {
     429                *pulStreamPosition = 0;
     430                dprintf(("WAVEPLAY::GetPosition: Failed"));
     431                return FALSE;
     432        }
     433
     434        *pulStreamPosition      = ConvertPositionInvert(ulCurBytesProcessed, pConfigInfo);
     435        //round to sample boundary
     436        *pulStreamPosition &= ~(pConfigInfo->ulSampleSize - 1);
     437        return TRUE;
    441438}
    442439//******************************************************************************
     
    445442BOOL WAVEPLAY::GetSpace(OSSSTREAMID StreamId, PWAVECONFIGINFO pConfigInfo, ULONG FAR *pulStreamSpace)
    446443{
    447     ULONG space,cvt;
    448 
    449 //    if (!waveOpened) return TRUE;
    450 
    451     if(OSS16_WaveGetSpace(StreamId, &space) != OSSERR_SUCCESS)
    452     {
    453         *pulStreamSpace = 0;
    454         dprintf(("WAVEPLAY::GetSpace: Failed"));
    455         return FALSE;
    456     }
    457 
    458 //    dprintf(("GetSpace: len %ld",space));
    459     cvt  = ConvertLengthInvert(space, pConfigInfo);
    460     //round to sample boundary
    461     *pulStreamSpace =cvt & ( ~(pConfigInfo->ulSampleSize - 1));
    462     return TRUE;
     444        ULONG space,cvt;
     445
     446        //if (!waveOpened) return TRUE;
     447
     448        if(OSS16_WaveGetSpace(StreamId, &space) != OSSERR_SUCCESS)
     449        {
     450                *pulStreamSpace = 0;
     451                dprintf(("WAVEPLAY::GetSpace: Failed"));
     452                return FALSE;
     453        }
     454
     455        //dprintf(("GetSpace: len %ld",space));
     456        cvt  = ConvertLengthInvert(space, pConfigInfo);
     457        //round to sample boundary
     458        *pulStreamSpace =cvt & ( ~(pConfigInfo->ulSampleSize - 1));
     459        return TRUE;
    463460}
    464461//******************************************************************************
     
    467464BOOL WAVEPLAY::GetHwPtr(OSSSTREAMID StreamId, PWAVECONFIGINFO pConfigInfo, ULONG FAR *pulHwPtr)
    468465{
    469     ULONG space,cvt;
    470 
    471     if(OSS16_WaveGetHwPtr(StreamId, &space) != OSSERR_SUCCESS)
    472     {
    473         *pulHwPtr = 0;
    474         dprintf(("WAVEPLAY::WaveGetHwPtr: Failed"));
    475         return FALSE;
    476     }
    477 
    478     cvt  = ConvertLengthInvert(space, pConfigInfo);
    479     //round to sample boundary
    480     *pulHwPtr = cvt & (~(pConfigInfo->ulSampleSize - 1));
    481     return TRUE;
     466        ULONG space,cvt;
     467
     468        if(OSS16_WaveGetHwPtr(StreamId, &space) != OSSERR_SUCCESS)
     469        {
     470                *pulHwPtr = 0;
     471                dprintf(("WAVEPLAY::WaveGetHwPtr: Failed"));
     472                return FALSE;
     473        }
     474
     475        cvt  = ConvertLengthInvert(space, pConfigInfo);
     476        //round to sample boundary
     477        *pulHwPtr = cvt & (~(pConfigInfo->ulSampleSize - 1));
     478        return TRUE;
    482479}
    483480//******************************************************************************
     
    486483BOOL WAVEPLAY::SetVolume(OSSSTREAMID StreamId, OSSSTREAMID mixerStreamId, ULONG ulVolume)
    487484{
    488     return MixerSetWaveVolume(mixerStreamId, StreamId, ulVolume);
     485        return MixerSetWaveVolume(mixerStreamId, StreamId, ulVolume);
    489486}
    490487//******************************************************************************
     
    494491#pragma on (unreferenced)
    495492{
    496     return MixerQueryVolume(mixerStreamId, OSS32_MIX_VOLUME_CAPTURE);
     493        return MixerQueryVolume(mixerStreamId, OSS32_MIX_VOLUME_CAPTURE);
    497494}
    498495//******************************************************************************
     
    502499#pragma on (unreferenced)
    503500{
    504     DebugInt3();
    505     return FALSE;
     501        DebugInt3();
     502        return FALSE;
    506503}
    507504
     
    509506#pragma data_seg ("_initdata","endds");
    510507/******************************************************************************/
    511 /* WAVEPLAY::WAVEPLAY(USHORT PrimeDma, USHORT SecDma, USHORT Irq)             */
    512 /* The constructor, basicly passes the resources info up the stream to the    */
    513 /* "parent classes" and calles _vSetup which constructs all the resource      */
    514 /* class objects we need to run.                                              */
    515 /*                                                                            */
     508/* WAVEPLAY::WAVEPLAY(USHORT PrimeDma, USHORT SecDma, USHORT Irq)                         */
     509/* The constructor, basicly passes the resources info up the stream to the        */
     510/* "parent classes" and calles _vSetup which constructs all the resource          */
     511/* class objects we need to run.                                                                                          */
     512/*                                                                                                                                                        */
    516513/******************************************************************************/
    517514
Note: See TracChangeset for help on using the changeset viewer.