Changeset 533


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

Fix for when u32 byte counter wraps

Location:
OCO/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • OCO/trunk/drv16/convert.h

    r271 r533  
    11#ifndef __CONVERT_H__
    22#define __CONVERT_H__
     3
     4/* Comparison functions for handling wrapping */
     5#define ARG1_IS_AFTER_ARG2(a,b) ((long)(b) - (long)(a) < 0)
     6#define ARG1_IS_BEFORE_ARG2(a,b) ARG1_IS_AFTER_ARG2(b,a)
     7
     8#define ARG1_IS_AFTER_OR_EQUAL_TO_ARG2(a,b) ((long)(a) - (long)(b) >= 0)
     9#define ARG1_IS_BEFORE_OR_EQUAL_TO_ARG2(a,b) ARG1_IS_AFTER_OR_EQUAL_TO_ARG2(b,a)
    310
    411//Use one page to temporarily hold converted wave data
  • OCO/trunk/drv16/ioctl.cpp

    r529 r533  
    33/* SCCSID = %W% %E% */
    44/****************************************************************************
    5  *                                                                          *
    6  * Copyright (c) IBM Corporation 1994 - 1997.                               *
    7  *                                                                          *
    8  * The following IBM OS/2 source code is provided to you solely for the     *
     5 *                                                                                                                                                      *
     6 * Copyright (c) IBM Corporation 1994 - 1997.                                                           *
     7 *                                                                                                                                                      *
     8 * The following IBM OS/2 source code is provided to you solely for the         *
    99 * the purpose of assisting you in your development of OS/2 device drivers. *
    10  * You may use this code in accordance with the IBM License Agreement       *
    11  * provided in the IBM Device Driver Source Kit for OS/2.                   *
    12  *                                                                          *
     10 * You may use this code in accordance with the IBM License Agreement           *
     11 * provided in the IBM Device Driver Source Kit for OS/2.                                       *
     12 *                                                                                                                                                      *
    1313 ****************************************************************************/
    1414/**@internal %W%
     
    1818 * @version %I%
    1919 * @context Unless otherwise noted, all interfaces are Ring-0, 16-bit,
    20  *  <stack context>.
     20 *      <stack context>.
    2121 * @history
    2222 *
     
    4646#include <daudio.h>
    4747
    48 int       numFreeStreams      = ALSACAPS_MAXSTREAMS;
     48int       numFreeStreams          = ALSACAPS_MAXSTREAMS;
    4949
    5050/**@internal
    51  * @param    PREQPACKET pointer to the strategy request packet
    52  * @return  None  But the Status in the request packet is updated on error
     51 * @param        PREQPACKET pointer to the strategy request packet
     52 * @return      None  But the Status in the request packet is updated on error
    5353 * @notes
    5454 * The Audio Init Ioctl only 2 things happen in here :
     
    6868   PFN_SHD pfnSHD = NULL;
    6969
    70       // if this is an IDLE or De-Init request
    71       // fetch the stream object based on the sysfilenum and turn on the
    72       // stream idle bit in the stream state then write the sysfilenum
    73       // into the request packet, set rc = 0 and return
     70          // if this is an IDLE or De-Init request
     71          // fetch the stream object based on the sysfilenum and turn on the
     72          // stream idle bit in the stream state then write the sysfilenum
     73          // into the request packet, set rc = 0 and return
    7474   if (p->sMode == IDLE)
    7575   {
    76        pstream = FindStream_fromFile((ULONG) prp->s.ioctl.usSysFileNum);
    77        if (pstream)
    78            pstream->ulStreamState |= STREAM_IDLE;
    79        p->pvReserved = (VOID FAR *) (ULONG)prp->s.ioctl.usSysFileNum;
    80        p->sReturnCode = 0;
    81        return;
    82    }
    83        // call FindStream_fromFile to see if there is already a stream
    84        // for this sysfilenum. if there is then see if the idle bit is on,
    85        // if the idle bit is on, reset it, then write the sysfilenum
    86       // into the request packet, set rc = 0 and return
    87       // MMPM sends idle down to a stream that is "losing" the hardware but
    88       // should not go away. It usually is associated with an app losing
    89       // focus. If the idle bit is not the stream is either not registered or
    90       // is being "re-initted" in another mode or with different file
    91       // attributes. "Re-initting" a stream is a total hack on the part
    92       // of MMPM they should de-register the stream and then init a new
    93       // stream but they don't . If anyone ever writes a VSD that behaves
    94       // "correctly" then this code can be deleted.
    95       // Either way delete the stream and build a new one with
    96       // this request packet.
     76           pstream = FindStream_fromFile((ULONG) prp->s.ioctl.usSysFileNum);
     77           if (pstream)
     78                   pstream->ulStreamState |= STREAM_IDLE;
     79           p->pvReserved = (VOID FAR *) (ULONG)prp->s.ioctl.usSysFileNum;
     80           p->sReturnCode = 0;
     81           return;
     82   }
     83           // call FindStream_fromFile to see if there is already a stream
     84           // for this sysfilenum. if there is then see if the idle bit is on,
     85           // if the idle bit is on, reset it, then write the sysfilenum
     86          // into the request packet, set rc = 0 and return
     87          // MMPM sends idle down to a stream that is "losing" the hardware but
     88          // should not go away. It usually is associated with an app losing
     89          // focus. If the idle bit is not the stream is either not registered or
     90          // is being "re-initted" in another mode or with different file
     91          // attributes. "Re-initting" a stream is a total hack on the part
     92          // of MMPM they should de-register the stream and then init a new
     93          // stream but they don't . If anyone ever writes a VSD that behaves
     94          // "correctly" then this code can be deleted.
     95          // Either way delete the stream and build a new one with
     96          // this request packet.
    9797   pstream = FindStream_fromFile((ULONG) prp->s.ioctl.usSysFileNum);
    98    if (pstream) {
    99       if (pstream->ulStreamState & STREAM_IDLE) {
    100          pstream->ulStreamState &= STREAM_NOT_IDLE;
    101          p->pvReserved = (VOID FAR *) (ULONG)prp->s.ioctl.usSysFileNum;
    102          p->sReturnCode = 0;
    103          return;
    104       }
    105       else {
     98        if (pstream) {
     99                if (pstream->ulStreamState & STREAM_IDLE) {
     100                        pstream->ulStreamState &= STREAM_NOT_IDLE;
     101                        p->pvReserved = (VOID FAR *) (ULONG)prp->s.ioctl.usSysFileNum;
     102                        p->sReturnCode = 0;
     103                        return;
     104                } else {
    106105#if 1
    107         // Rudi: Workaround for MMPM device sharing bug
    108         if (pstream->ulStreamState & STREAM_STREAMING) {
    109           CONTROL_PARM dummy;
    110           pstream->PauseStream(&dummy);
    111           pstream->ResumeStream();
    112           p->pvReserved = (VOID FAR *) (ULONG)prp->s.ioctl.usSysFileNum;
    113           p->sReturnCode = 0;
    114           return;
    115         }
     106                        // Rudi: Workaround for MMPM device sharing bug
     107                        if (pstream->ulStreamState & STREAM_STREAMING) {
     108                                CONTROL_PARM dummy;
     109                                pstream->PauseStream(&dummy);
     110                                pstream->ResumeStream();
     111                                p->pvReserved = (VOID FAR *) (ULONG)prp->s.ioctl.usSysFileNum;
     112                                p->sReturnCode = 0;
     113                                return;
     114                        }
    116115#endif
    117          //HACK BEGIN
    118          //SvL: Save stream handle & SHD entrypoint in case MMPM2 reinitializes
    119          //     a stream that was already registered
    120          //HACK END
    121          if(pstream->pfnSHD) {
    122              hstream = (USHORT)pstream->hstream;
    123              pfnSHD  = pstream->pfnSHD;
    124          }
    125          delete pstream;
    126       }
    127    }
     116                        //HACK BEGIN
     117                        //SvL: Save stream handle & SHD entrypoint in case MMPM2 reinitializes
     118                        //      a stream that was already registered
     119                        //HACK END
     120                        if (pstream->pfnSHD) {
     121                                hstream = (USHORT)pstream->hstream;
     122                                pfnSHD  = pstream->pfnSHD;
     123                        }
     124                        delete pstream;
     125                }
     126        }
    128127
    129128   // get the hardware type
     
    131130   HardwareType = GetHardwareType(p->sMode, (USHORT)p->ulOperation, LDev);
    132131   if (HardwareType == AUDIOHW_INVALID_DEVICE) {
    133       p->sReturnCode = INVALID_REQUEST;
    134       prp->usStatus |= RPERR;
    135       return;
    136    }
    137       // make sure we have a Hardware object that can handle this
    138       // data type and operation..
     132          p->sReturnCode = INVALID_REQUEST;
     133          prp->usStatus |= RPERR;
     134          return;
     135   }
     136          // make sure we have a Hardware object that can handle this
     137          // data type and operation..
    139138   pHWobj = GetHardwareDevice(HardwareType);
    140139   if (pHWobj == NULL) {
    141       p->sReturnCode = INVALID_REQUEST;
    142       prp->usStatus |= RPERR;
    143       return;
    144    }
    145 
    146    p->ulFlags = 0;  /* Zero the Flags  */
     140          p->sReturnCode = INVALID_REQUEST;
     141          prp->usStatus |= RPERR;
     142          return;
     143   }
     144
     145   p->ulFlags = 0;      /* Zero the Flags  */
    147146   switch (HardwareType)
    148147   {
    149       case AUDIOHW_WAVE_PLAY:
    150       case AUDIOHW_WAVE_CAPTURE:
    151         pstream = new WAVESTREAM(HardwareType,p,prp->s.ioctl.usSysFileNum, MixerStreamId);
    152          p->sDeviceID = ALSA_ID;         /* Reported in VSD dll           */
    153         break;
    154 
    155       case AUDIOHW_FMSYNTH_PLAY:
    156         if(devCaps[current_device].ulCaps & OSS32_CAPS_FMSYNTH_PLAYBACK)
    157         {
    158             pstream = new MIDISTREAM(HardwareType, prp->s.ioctl.usSysFileNum, MixerStreamId);
    159              p->sDeviceID = ALSA_MIDI_ID;         /* Reported in VSD dll           */
    160         }
    161         else {
    162             p->sReturnCode = INVALID_REQUEST;
    163             prp->usStatus |= RPERR;
    164             return;
    165         }
    166         break;
    167 
    168       default:
    169         p->sReturnCode = INVALID_REQUEST;
    170         prp->usStatus |= RPERR;
    171         return;
     148          case AUDIOHW_WAVE_PLAY:
     149          case AUDIOHW_WAVE_CAPTURE:
     150                pstream = new WAVESTREAM(HardwareType,p,prp->s.ioctl.usSysFileNum, MixerStreamId);
     151                 p->sDeviceID = ALSA_ID;                 /* Reported in VSD dll                   */
     152                break;
     153
     154          case AUDIOHW_FMSYNTH_PLAY:
     155                if(devCaps[current_device].ulCaps & OSS32_CAPS_FMSYNTH_PLAYBACK)
     156                {
     157                        pstream = new MIDISTREAM(HardwareType, prp->s.ioctl.usSysFileNum, MixerStreamId);
     158                         p->sDeviceID = ALSA_MIDI_ID;             /* Reported in VSD dll                   */
     159                }
     160                else {
     161                        p->sReturnCode = INVALID_REQUEST;
     162                        prp->usStatus |= RPERR;
     163                        return;
     164                }
     165                break;
     166
     167          default:
     168                p->sReturnCode = INVALID_REQUEST;
     169                prp->usStatus |= RPERR;
     170                return;
    172171   } /* endswitch */
    173172
    174    p->ulFlags    |= VOLUME;           /* volume control is supported   */
    175    p->ulFlags    |= INPUT;            /* Input select is supported     */
    176    p->ulFlags    |= OUTPUT;           /* Output select is supported    */
    177    p->ulFlags    |= MONITOR;          /* Record Monitor is supported   */
     173   p->ulFlags    |= VOLUME;               /* volume control is supported   */
     174   p->ulFlags    |= INPUT;                        /* Input select is supported     */
     175   p->ulFlags    |= OUTPUT;               /* Output select is supported    */
     176   p->ulFlags    |= MONITOR;              /* Record Monitor is supported   */
    178177   pstream->ulSysFileNum = prp->s.ioctl.usSysFileNum;
    179178   p->pvReserved  = (VOID FAR *) (ULONG) prp->s.ioctl.usSysFileNum;
    180179   p->sReturnCode = 0;
    181 //  dprintf(("IoctlAudioInit: file nr: %lx", pstream->ulSysFileNum));
     180//      dprintf(("IoctlAudioInit: file nr: %lx", pstream->ulSysFileNum));
    182181
    183182   //HACK BEGIN
    184183   if(pfnSHD) {
    185 //      dprintf(("Stream was previously registered; reregister it"));
    186        pstream->pfnSHD  = pfnSHD;
    187        pstream->hstream = hstream;
     184//              dprintf(("Stream was previously registered; reregister it"));
     185           pstream->pfnSHD      = pfnSHD;
     186           pstream->hstream = hstream;
    188187   }
    189188   //HACK END
     
    192191
    193192/**@internal
    194  * @param    PREQPACKET pointer to the strategy request packet
    195  * @return  None  But the Status in the request packet is updated on error
     193 * @param        PREQPACKET pointer to the strategy request packet
     194 * @return      None  But the Status in the request packet is updated on error
    196195 * @notes
    197196 */
     
    218217   if (pHWobj)
    219218   {
    220       pHWobj->DevCaps(p);
    221       if (p->ulSupport != SUPPORT_SUCCESS)
    222       {
    223         //PS+++ filling to our parameters as say mmpm2.inf for returning error in this call
    224         // (for HDA only!!!!!)
    225          p->ulDataType     = WAVE_FORMAT_4S16;
    226          p->ulChannels     = 2;
    227         p->ulSamplingRate = HZ_44100;
    228         //
    229         //dprintf(("IACapability: Error support"));
    230         prp->usStatus |= RPERR;
    231       }
     219          pHWobj->DevCaps(p);
     220          if (p->ulSupport != SUPPORT_SUCCESS)
     221          {
     222                //PS+++ filling to our parameters as say mmpm2.inf for returning error in this call
     223                // (for HDA only!!!!!)
     224                 p->ulDataType     = WAVE_FORMAT_4S16;
     225                 p->ulChannels     = 2;
     226                p->ulSamplingRate = HZ_44100;
     227                //
     228                //dprintf(("IACapability: Error support"));
     229                prp->usStatus |= RPERR;
     230          }
    232231   }
    233232   else {
    234233        //dprintf(("IACapability: Error get HW obj"));
    235       //PS+++ filling to our parameters as say mmpm2.inf for returning error in this call
    236       // (for HDA only!!!!!)
    237       p->ulDataType     = WAVE_FORMAT_4S16;
    238       p->ulChannels     = 2;
    239       p->ulSamplingRate = HZ_44100;
    240       //
    241       p->ulSupport = UNSUPPORTED_DATATYPE;
    242       prp->usStatus |= RPERR;
     234          //PS+++ filling to our parameters as say mmpm2.inf for returning error in this call
     235          // (for HDA only!!!!!)
     236          p->ulDataType         = WAVE_FORMAT_4S16;
     237          p->ulChannels         = 2;
     238          p->ulSamplingRate = HZ_44100;
     239          //
     240          p->ulSupport = UNSUPPORTED_DATATYPE;
     241          prp->usStatus |= RPERR;
    243242   }
    244243}
    245244
    246245/**@internal IoctlAudioControl
    247  * @param    PREQPACKET pointer to the strategy request packet
    248  * @return  None  But the Status in the request packet is updated on error
     246 * @param        PREQPACKET pointer to the strategy request packet
     247 * @return      None  But the Status in the request packet is updated on error
    249248 * @notes
    250249 * if it's AUDIO_CHANGE, just report success, otherwise report failure
     
    258257   LPMCI_AUDIO_CHANGE  pAudChange;
    259258   LPMCI_TRACK_INFO    pMasterVol;
    260    PSTREAM             pStream;
    261    ULONG               volume;
    262    ULONG               addr;
     259   PSTREAM                         pStream;
     260   ULONG                           volume;
     261   ULONG                           addr;
    263262
    264263   if (p->usIOCtlRequest != AUDIO_CHANGE)
    265264   {
    266        rprintf(("IAudioControl: Error support req:%x",p->usIOCtlRequest));
    267        p->sReturnCode = INVALID_REQUEST;
    268        prp->usStatus |= RPERR | RPBADCMD;
    269        return;
     265           rprintf(("IAudioControl: Error support req:%x",p->usIOCtlRequest));
     266           p->sReturnCode = INVALID_REQUEST;
     267           prp->usStatus |= RPERR | RPBADCMD;
     268           return;
    270269   }
    271270   p->sReturnCode=0;
     
    278277   if(addr >= 0x10000UL)
    279278   {
    280        rprintf(("Invalid MCI_AUDIO_CHANGE pnt %lx!!", (ULONG)pAudChange));
    281        p->sReturnCode = INVALID_REQUEST;
    282        prp->usStatus |= RPERR | RPBADCMD;
    283        return;
     279           rprintf(("Invalid MCI_AUDIO_CHANGE pnt %lx!!", (ULONG)pAudChange));
     280           p->sReturnCode = INVALID_REQUEST;
     281           prp->usStatus |= RPERR | RPBADCMD;
     282           return;
    284283   }
    285284   pMasterVol = (LPMCI_TRACK_INFO)pAudChange->pvDevInfo;
     
    290289   if(addr >= 0x10000UL)
    291290   {
    292        rprintf(("Invalid MCI_TRACK_INFO pnt %lx!!", (ULONG)pMasterVol));
    293        p->sReturnCode = INVALID_REQUEST;
    294        prp->usStatus |= RPERR | RPBADCMD;
    295        return;
     291           rprintf(("Invalid MCI_TRACK_INFO pnt %lx!!", (ULONG)pMasterVol));
     292           p->sReturnCode = INVALID_REQUEST;
     293           prp->usStatus |= RPERR | RPBADCMD;
     294           return;
    296295   }
    297296
    298297   pStream = FindStream_fromFile((ULONG) prp->s.ioctl.usSysFileNum);
    299298   if(pStream == NULL) {
    300        rprintf(("IAudioControl stream %lx not found!", (ULONG) prp->s.ioctl.usSysFileNum));
    301        DebugInt3();
    302        return;
     299           rprintf(("IAudioControl stream %lx not found!", (ULONG) prp->s.ioctl.usSysFileNum));
     300           DebugInt3();
     301           return;
    303302   }
    304303   if(pAudChange->lBalance != AUDIO_IGNORE)
    305        pStream->SetProperty(PROPERTY_BALANCE, pAudChange->lBalance);
     304           pStream->SetProperty(PROPERTY_BALANCE, pAudChange->lBalance);
    306305
    307306   if (pAudChange->lVolume != AUDIO_IGNORE)
    308307   {
    309        // stream volume ranges from 0 to 0x7FFFFFFF (linear)
    310        volume = pAudChange->lVolume >> 16UL;
    311        volume = (volume*OSS32_MAX_VOLUME)/0x7FFFUL;
     308           // stream volume ranges from 0 to 0x7FFFFFFF (linear)
     309           volume = pAudChange->lVolume >> 16UL;
     310           volume = (volume*OSS32_MAX_VOLUME)/0x7FFFUL;
    312311                //dprintf(("Set stream volume of %x to %d", prp->s.ioctl.usSysFileNum, volume));
    313        pStream->SetProperty(PROPERTY_VOLUME, MAKE_VOLUME_LR(volume, volume));
     312           pStream->SetProperty(PROPERTY_VOLUME, MAKE_VOLUME_LR(volume, volume));
    314313   }
    315314
    316315   if (pMasterVol && pMasterVol->usMasterVolume != AUDIO_IGNORE)
    317316   {
    318        // master volume ranges from 0 to 0x7FFF (linear)
    319        volume = pMasterVol->usMasterVolume;
    320        volume = (volume*OSS32_MAX_VOLUME)/0x7FFFUL;
    321        if (volume > OSS32_MAX_VOLUME)
    322        {
    323            volume = OSS32_MAX_VOLUME;
    324        }
    325 //      dprintf(("IlAudioControl:Set MV to %d", volume));
    326        MixerSetVolume(MixerStreamId, OSS32_MIX_VOLUME_MASTER_FRONT, MAKE_VOLUME_LR(volume, volume));
    327        if(mixcaps.fuCtrlCaps & OSS32_MIX_FLAG(OSS32_MIX_VOLUME_MASTER_REAR))
    328        {
    329            MixerSetVolume(MixerStreamId, OSS32_MIX_VOLUME_MASTER_REAR, MAKE_VOLUME_LR(volume, volume));
    330        }
     317           // master volume ranges from 0 to 0x7FFF (linear)
     318           volume = pMasterVol->usMasterVolume;
     319           volume = (volume*OSS32_MAX_VOLUME)/0x7FFFUL;
     320           if (volume > OSS32_MAX_VOLUME)
     321           {
     322                   volume = OSS32_MAX_VOLUME;
     323           }
     324//              dprintf(("IlAudioControl:Set MV to %d", volume));
     325           MixerSetVolume(MixerStreamId, OSS32_MIX_VOLUME_MASTER_FRONT, MAKE_VOLUME_LR(volume, volume));
     326           if(mixcaps.fuCtrlCaps & OSS32_MIX_FLAG(OSS32_MIX_VOLUME_MASTER_REAR))
     327           {
     328                   MixerSetVolume(MixerStreamId, OSS32_MIX_VOLUME_MASTER_REAR, MAKE_VOLUME_LR(volume, volume));
     329           }
    331330   }
    332331   if(!fRecSrcIOCTL90) {
    333     for(int i=0;i<8;i++)
    334     {
    335         switch(pAudChange->rInputList[0].ulDevType) {
    336         case NULL_INPUT:
    337             break; //continue;
    338         case STEREO_LINE_INPUT:
    339         case LEFT_LINE_INPUT:
    340         case RIGHT_LINE_INPUT:
    341             pStream->SetProperty(PROPERTY_INPUTSRC, OSS32_MIX_RECSRC_LINE);
    342             break;
    343 
    344         case MIC_INPUT:
    345         case BOOSTED_MIC_INPUT:
    346             pStream->SetProperty(PROPERTY_INPUTSRC, OSS32_MIX_RECSRC_MIC);
    347             break;
    348 
    349         case PHONE_LINE_INPUT:
    350         case HANDSET_INPUT:
    351         case SYNTH_INPUT:
    352         case DIGITAL_PHONE_LINE_INPUT:
    353         case DIGITAL_HANDSET_INPUT:
    354         case MIDI_IN_PORT:
    355 //      case LOOPBACK:
    356             pStream->SetProperty(PROPERTY_INPUTSRC, OSS32_MIX_RECSRC_MIXER);
    357             break;
    358         }
    359     }
     332        for(int i=0;i<8;i++)
     333        {
     334                switch(pAudChange->rInputList[0].ulDevType) {
     335                case NULL_INPUT:
     336                        break; //continue;
     337                case STEREO_LINE_INPUT:
     338                case LEFT_LINE_INPUT:
     339                case RIGHT_LINE_INPUT:
     340                        pStream->SetProperty(PROPERTY_INPUTSRC, OSS32_MIX_RECSRC_LINE);
     341                        break;
     342
     343                case MIC_INPUT:
     344                case BOOSTED_MIC_INPUT:
     345                        pStream->SetProperty(PROPERTY_INPUTSRC, OSS32_MIX_RECSRC_MIC);
     346                        break;
     347
     348                case PHONE_LINE_INPUT:
     349                case HANDSET_INPUT:
     350                case SYNTH_INPUT:
     351                case DIGITAL_PHONE_LINE_INPUT:
     352                case DIGITAL_HANDSET_INPUT:
     353                case MIDI_IN_PORT:
     354//              case LOOPBACK:
     355                        pStream->SetProperty(PROPERTY_INPUTSRC, OSS32_MIX_RECSRC_MIXER);
     356                        break;
     357                }
     358        }
    360359   }
    361360   if(!fRecGainIOCTL90 && pAudChange->lGain != AUDIO_IGNORE) {
    362        // input ranges from 0 to 0x7FFFFFFF (linear)
    363        volume = pAudChange->lGain >> 16UL;
    364        volume = (volume*OSS32_MAX_VOLUME)/0x7FFFUL;
    365        if(volume > OSS32_MAX_VOLUME) {
    366            volume = OSS32_MAX_VOLUME;
    367        }
    368 //      dprintf(("IAudioControl:Set IG of %x to %d", prp->s.ioctl.usSysFileNum, volume));
    369        pStream->SetProperty(PROPERTY_INPUTGAIN, MAKE_VOLUME_LR(volume, volume));
     361           // input ranges from 0 to 0x7FFFFFFF (linear)
     362           volume = pAudChange->lGain >> 16UL;
     363           volume = (volume*OSS32_MAX_VOLUME)/0x7FFFUL;
     364           if(volume > OSS32_MAX_VOLUME) {
     365                   volume = OSS32_MAX_VOLUME;
     366           }
     367//              dprintf(("IAudioControl:Set IG of %x to %d", prp->s.ioctl.usSysFileNum, volume));
     368           pStream->SetProperty(PROPERTY_INPUTGAIN, MAKE_VOLUME_LR(volume, volume));
    370369   }
    371370}
     
    374373void IoctlDirectAudio(PREQPACKET prp)
    375374{
    376 //    dprintf(("IoctlDirectAudio Code:0x%x",prp->s.ioctl.bCode));
    377     if(prp->s.ioctl.bCode == DAUDIO_OPEN)
    378     {
    379         LPMCI_AUDIO_INIT pInit = (LPMCI_AUDIO_INIT) prp->s.ioctl.pvData;
    380         PAUDIOHW pHWobj;
    381         MCI_AUDIO_CAPS audioCaps;
    382         PDWAVESTREAM pStream;
    383 
    384         if(DevHelp_VerifyAccess(SELECTOROF(pInit), sizeof(MCI_AUDIO_INIT), OFFSETOF(pInit), VERIFY_READWRITE))
    385         {
    386             rprintf(("Invalid MCI_AUDIO_INIT pnt %lx!!", (ULONG)pInit));
    387             prp->usStatus |= RPERR | RPBADCMD;
    388             return;
    389         }
    390 
    391         audioCaps.ulLength        = sizeof(MCI_AUDIO_CAPS);
    392         audioCaps.ulSamplingRate  = pInit->lSRate;
    393         audioCaps.ulChannels      = pInit->sChannels;
    394         audioCaps.ulBitsPerSample = pInit->lBitsPerSRate;
    395         audioCaps.ulDataType      = pInit->sMode;
    396         audioCaps.ulOperation     = OPERATION_PLAY;
    397 
    398         // get the pointer to the hardware object
    399         // call DevCaps
    400         // bailout if no hardware object is returned..
    401         pHWobj = GetHardwareDevice(AUDIOHW_WAVE_PLAY);
    402         if (pHWobj)
    403         {
    404             pHWobj->DevCaps(&audioCaps);
    405             if (audioCaps.ulSupport != SUPPORT_SUCCESS)
    406             {
    407                 rprintf(("IDirectAudio: DevCaps failed"));
    408                 pInit->sReturnCode = INVALID_REQUEST;
    409                 prp->usStatus |= RPERR;
    410                 return;
    411             }
    412         }
    413         else
    414         {
    415             rprintf(("IDirectAudio: HW DevCaps failed"));
    416             pInit->sReturnCode = INVALID_REQUEST;
    417             prp->usStatus |= RPERR;
    418             return;
    419         }
    420 
    421         pStream = new DWAVESTREAM(AUDIOHW_WAVE_PLAY, pInit,  prp->s.ioctl.usSysFileNum, MixerStreamId);
    422         if(pStream == NULL) {
     375//        dprintf(("IoctlDirectAudio Code:0x%x",prp->s.ioctl.bCode));
     376        if(prp->s.ioctl.bCode == DAUDIO_OPEN)
     377        {
     378                LPMCI_AUDIO_INIT pInit = (LPMCI_AUDIO_INIT) prp->s.ioctl.pvData;
     379                PAUDIOHW pHWobj;
     380                MCI_AUDIO_CAPS audioCaps;
     381                PDWAVESTREAM pStream;
     382
     383                if(DevHelp_VerifyAccess(SELECTOROF(pInit), sizeof(MCI_AUDIO_INIT), OFFSETOF(pInit), VERIFY_READWRITE))
     384                {
     385                        rprintf(("Invalid MCI_AUDIO_INIT pnt %lx!!", (ULONG)pInit));
     386                        prp->usStatus |= RPERR | RPBADCMD;
     387                        return;
     388                }
     389
     390                audioCaps.ulLength                = sizeof(MCI_AUDIO_CAPS);
     391                audioCaps.ulSamplingRate  = pInit->lSRate;
     392                audioCaps.ulChannels      = pInit->sChannels;
     393                audioCaps.ulBitsPerSample = pInit->lBitsPerSRate;
     394                audioCaps.ulDataType      = pInit->sMode;
     395                audioCaps.ulOperation     = OPERATION_PLAY;
     396
     397                // get the pointer to the hardware object
     398                // call DevCaps
     399                // bailout if no hardware object is returned..
     400                pHWobj = GetHardwareDevice(AUDIOHW_WAVE_PLAY);
     401                if (pHWobj)
     402                {
     403                        pHWobj->DevCaps(&audioCaps);
     404                        if (audioCaps.ulSupport != SUPPORT_SUCCESS)
     405                        {
     406                                rprintf(("IDirectAudio: DevCaps failed"));
     407                                pInit->sReturnCode = INVALID_REQUEST;
     408                                prp->usStatus |= RPERR;
     409                                return;
     410                        }
     411                }
     412                else
     413                {
     414                        rprintf(("IDirectAudio: HW DevCaps failed"));
     415                        pInit->sReturnCode = INVALID_REQUEST;
     416                        prp->usStatus |= RPERR;
     417                        return;
     418                }
     419
     420                pStream = new DWAVESTREAM(AUDIOHW_WAVE_PLAY, pInit,  prp->s.ioctl.usSysFileNum, MixerStreamId);
     421                if(pStream == NULL) {
    423422                        //dprintf(("IDirectAudio: pStream"));
    424             DebugInt3();
    425             pInit->sReturnCode = INVALID_REQUEST;
    426             prp->usStatus |= RPERR;
    427             return;
    428         }
    429 
    430         if(!pStream->IsEverythingOk())
    431         {
    432             delete pStream;
     423                        DebugInt3();
     424                        pInit->sReturnCode = INVALID_REQUEST;
     425                        prp->usStatus |= RPERR;
     426                        return;
     427                }
     428
     429                if(!pStream->IsEverythingOk())
     430                {
     431                        delete pStream;
    433432                        //dprintf(("IlDirectAudio: IsEverythingOk"));
    434             DebugInt3();
    435             pInit->sReturnCode = INVALID_REQUEST;
    436             prp->usStatus |= RPERR;
    437             return;
    438         }
    439         pInit->ulFlags |= VOLUME;           /* volume control is supported  */
    440         pInit->ulFlags |= INPUT;            /* Input select is supported    */
    441         pInit->ulFlags |= OUTPUT;           /* Output select is supported    */
    442         pInit->ulFlags |= MONITOR;          /* Record Monitor is supported  */
    443         pInit->sDeviceID = ALSA_ID;      /* Reported in VSD dll           */
    444         pStream->ulSysFileNum = prp->s.ioctl.usSysFileNum;
    445         pInit->pvReserved = (VOID FAR *) (ULONG) prp->s.ioctl.usSysFileNum;
    446         pInit->sReturnCode = 0;
    447 
    448         return;
    449     }
    450     else
    451     if(prp->s.ioctl.bCode == DAUDIO_QUERYFORMAT)
    452     {
    453         LPMCI_AUDIO_INIT pInit = (LPMCI_AUDIO_INIT) prp->s.ioctl.pvData;
    454         PAUDIOHW pHWobj;
    455         MCI_AUDIO_CAPS audioCaps;
    456 
    457         if(DevHelp_VerifyAccess(SELECTOROF(pInit), sizeof(MCI_AUDIO_INIT), OFFSETOF(pInit), VERIFY_READWRITE))
    458         {
    459             rprintf(("Invalid MCI_AUDIO_INIT pnt %lx!!", (ULONG)pInit));
    460             prp->usStatus |= RPERR | RPBADCMD;
    461             return;
    462         }
    463 
    464         audioCaps.ulLength        = sizeof(MCI_AUDIO_CAPS);
    465         audioCaps.ulSamplingRate  = pInit->lSRate;
    466         audioCaps.ulChannels      = pInit->sChannels;
    467         audioCaps.ulBitsPerSample = pInit->lBitsPerSRate;
    468         audioCaps.ulDataType      = pInit->sMode;
    469         audioCaps.ulOperation     = OPERATION_PLAY;
    470 
    471         // get the pointer to the hardware object
    472         // call DevCaps
    473         // bailout if no hardware object is returned..
    474         pHWobj = GetHardwareDevice(AUDIOHW_WAVE_PLAY);
    475         if (pHWobj)
    476         {
    477             pHWobj->DevCaps(&audioCaps);
    478             if (audioCaps.ulSupport != SUPPORT_SUCCESS)
    479             {
    480                 rprintf(("IlDirectAudio: DevCaps failed"));
    481                 prp->usStatus |= RPERR;
    482                 pInit->sReturnCode = INVALID_REQUEST;
    483                 return;
    484             }
     433                        DebugInt3();
     434                        pInit->sReturnCode = INVALID_REQUEST;
     435                        prp->usStatus |= RPERR;
     436                        return;
     437                }
     438                pInit->ulFlags |= VOLUME;                       /* volume control is supported  */
     439                pInit->ulFlags |= INPUT;                        /* Input select is supported    */
     440                pInit->ulFlags |= OUTPUT;                       /* Output select is supported    */
     441                pInit->ulFlags |= MONITOR;                      /* Record Monitor is supported  */
     442                pInit->sDeviceID = ALSA_ID;      /* Reported in VSD dll                   */
     443                pStream->ulSysFileNum = prp->s.ioctl.usSysFileNum;
     444                pInit->pvReserved = (VOID FAR *) (ULONG) prp->s.ioctl.usSysFileNum;
     445                pInit->sReturnCode = 0;
     446
     447                return;
     448        }
     449        else
     450        if(prp->s.ioctl.bCode == DAUDIO_QUERYFORMAT)
     451        {
     452                LPMCI_AUDIO_INIT pInit = (LPMCI_AUDIO_INIT) prp->s.ioctl.pvData;
     453                PAUDIOHW pHWobj;
     454                MCI_AUDIO_CAPS audioCaps;
     455
     456                if(DevHelp_VerifyAccess(SELECTOROF(pInit), sizeof(MCI_AUDIO_INIT), OFFSETOF(pInit), VERIFY_READWRITE))
     457                {
     458                        rprintf(("Invalid MCI_AUDIO_INIT pnt %lx!!", (ULONG)pInit));
     459                        prp->usStatus |= RPERR | RPBADCMD;
     460                        return;
     461                }
     462
     463                audioCaps.ulLength                = sizeof(MCI_AUDIO_CAPS);
     464                audioCaps.ulSamplingRate  = pInit->lSRate;
     465                audioCaps.ulChannels      = pInit->sChannels;
     466                audioCaps.ulBitsPerSample = pInit->lBitsPerSRate;
     467                audioCaps.ulDataType      = pInit->sMode;
     468                audioCaps.ulOperation     = OPERATION_PLAY;
     469
     470                // get the pointer to the hardware object
     471                // call DevCaps
     472                // bailout if no hardware object is returned..
     473                pHWobj = GetHardwareDevice(AUDIOHW_WAVE_PLAY);
     474                if (pHWobj)
     475                {
     476                        pHWobj->DevCaps(&audioCaps);
     477                        if (audioCaps.ulSupport != SUPPORT_SUCCESS)
     478                        {
     479                                rprintf(("IlDirectAudio: DevCaps failed"));
     480                                prp->usStatus |= RPERR;
     481                                pInit->sReturnCode = INVALID_REQUEST;
     482                                return;
     483                        }
    485484                        //dprintf(("IoctlDirectAudio ret0"));
    486             pInit->sReturnCode = 0;
    487             return;
    488         }
    489         else {
    490             rprintf(("IoctlDirectAudio err req"));
    491             pInit->sReturnCode = INVALID_REQUEST;
    492             prp->usStatus |= RPERR;
    493             return;
    494         }
    495     }
    496     else
    497     if(prp->s.ioctl.bCode == DAUDIO_QUERYCAPS)
    498     {
    499         LPOSS32_DEVCAPS lpCaps = (LPOSS32_DEVCAPS) prp->s.ioctl.pvData;
    500         PWAVEAUDIO pHWobj;
    501 
    502         if(DevHelp_VerifyAccess(SELECTOROF(lpCaps), sizeof(OSS32_DEVCAPS), OFFSETOF(lpCaps), VERIFY_READWRITE))
    503         {
    504             rprintf(("Invalid OSS32_DEVCAPS pnt %lx!!", (ULONG)lpCaps));
    505             prp->usStatus |= RPERR | RPBADCMD;
    506             return;
    507         }
    508         // get the pointer to the hardware object
    509         // call DevCaps
    510         // bailout if no hardware object is returned..
    511         pHWobj = (PWAVEAUDIO)GetHardwareDevice(AUDIOHW_WAVE_PLAY);
    512         if (pHWobj)
    513         {
    514             pHWobj->DevCaps(lpCaps);
     485                        pInit->sReturnCode = 0;
     486                        return;
     487                }
     488                else {
     489                        rprintf(("IoctlDirectAudio err req"));
     490                        pInit->sReturnCode = INVALID_REQUEST;
     491                        prp->usStatus |= RPERR;
     492                        return;
     493                }
     494        }
     495        else
     496        if(prp->s.ioctl.bCode == DAUDIO_QUERYCAPS)
     497        {
     498                LPOSS32_DEVCAPS lpCaps = (LPOSS32_DEVCAPS) prp->s.ioctl.pvData;
     499                PWAVEAUDIO pHWobj;
     500
     501                if(DevHelp_VerifyAccess(SELECTOROF(lpCaps), sizeof(OSS32_DEVCAPS), OFFSETOF(lpCaps), VERIFY_READWRITE))
     502                {
     503                        rprintf(("Invalid OSS32_DEVCAPS pnt %lx!!", (ULONG)lpCaps));
     504                        prp->usStatus |= RPERR | RPBADCMD;
     505                        return;
     506                }
     507                // get the pointer to the hardware object
     508                // call DevCaps
     509                // bailout if no hardware object is returned..
     510                pHWobj = (PWAVEAUDIO)GetHardwareDevice(AUDIOHW_WAVE_PLAY);
     511                if (pHWobj)
     512                {
     513                        pHWobj->DevCaps(lpCaps);
    515514                        //dprintf(("IoctlDirectAudio ret1"));
    516             return;
    517         }
    518         else
    519         {
    520             prp->usStatus |= RPERR;
     515                        return;
     516                }
     517                else
     518                {
     519                        prp->usStatus |= RPERR;
    521520                        //dprintf(("IoctlDirectAudio ret err1"));
    522             return;
    523         }
    524     }
    525     PSTREAM pStream;
    526 
    527     pStream = FindStream_fromFile((ULONG) prp->s.ioctl.usSysFileNum);
    528     if(pStream == NULL)
    529     {
    530         rprintf(("IDirectAudio stream %lx not found!", (ULONG) prp->s.ioctl.usSysFileNum));
    531         DebugInt3();
    532         prp->usStatus |= RPERR | RPBADCMD;
    533         return;
    534     }
    535 
    536     LPDAUDIO_CMD pDAudioCmd = (LPDAUDIO_CMD) prp->s.ioctl.pvData;
    537     ULONG        rc = 0;
    538 
    539     if(DevHelp_VerifyAccess(SELECTOROF(pDAudioCmd), sizeof(DAUDIO_CMD), OFFSETOF(pDAudioCmd), VERIFY_READWRITE))
    540     {
    541         rprintf(("Invalid DAUDIO_CMD pnt %lx!!", (ULONG)pDAudioCmd));
    542         prp->usStatus |= RPERR | RPBADCMD;
    543         return;
    544     }
    545 
    546     switch(prp->s.ioctl.bCode)
    547     {
    548     case DAUDIO_CLOSE:
     521                        return;
     522                }
     523        }
     524        PSTREAM pStream;
     525
     526        pStream = FindStream_fromFile((ULONG) prp->s.ioctl.usSysFileNum);
     527        if(pStream == NULL)
     528        {
     529                rprintf(("IDirectAudio stream %lx not found!", (ULONG) prp->s.ioctl.usSysFileNum));
     530                DebugInt3();
     531                prp->usStatus |= RPERR | RPBADCMD;
     532                return;
     533        }
     534
     535        LPDAUDIO_CMD pDAudioCmd = (LPDAUDIO_CMD) prp->s.ioctl.pvData;
     536        ULONG            rc = 0;
     537
     538        if(DevHelp_VerifyAccess(SELECTOROF(pDAudioCmd), sizeof(DAUDIO_CMD), OFFSETOF(pDAudioCmd), VERIFY_READWRITE))
     539        {
     540                rprintf(("Invalid DAUDIO_CMD pnt %lx!!", (ULONG)pDAudioCmd));
     541                prp->usStatus |= RPERR | RPBADCMD;
     542                return;
     543        }
     544
     545        switch(prp->s.ioctl.bCode)
     546        {
     547        case DAUDIO_CLOSE:
    549548                //dprintf(("ID close"));
    550         delete pStream;
    551         break;
    552 
    553     case DAUDIO_SETVOLUME:
    554     {
     549                delete pStream;
     550                break;
     551
     552        case DAUDIO_SETVOLUME:
     553        {
    555554                //dprintf(("ID SetVolume"));
    556         pStream->SetProperty(PROPERTY_VOLUME, MAKE_VOLUME_LR(pDAudioCmd->Vol.VolumeL, pDAudioCmd->Vol.VolumeR));
    557         break;
    558     }
    559 
    560     case DAUDIO_GETVOLUME:
    561     {
     555                pStream->SetProperty(PROPERTY_VOLUME, MAKE_VOLUME_LR(pDAudioCmd->Vol.VolumeL, pDAudioCmd->Vol.VolumeR));
     556                break;
     557        }
     558
     559        case DAUDIO_GETVOLUME:
     560        {
    562561                //dprintf(("ID GetVolume"));
    563         pDAudioCmd->Vol.VolumeL = GET_VOLUME_L(pStream->GetProperty(PROPERTY_VOLUME));
    564         pDAudioCmd->Vol.VolumeR = GET_VOLUME_R(pStream->GetProperty(PROPERTY_VOLUME));
    565         break;
    566     }
    567 
    568     case DAUDIO_START:
    569     {
    570         dprintf(("ID Start NF:%d",(USHORT)numFreeStreams));
    571         if(numFreeStreams > 0)
    572         {
    573               rc = pStream->StartStream();
    574               if(!rc) numFreeStreams--;
    575         }
    576         else
    577         {
    578               rprintf(("ID Start rc1"));
    579               rc = 1; //fail
    580         }
    581         break;
    582     }
    583 
    584     case DAUDIO_STOP:
    585     {
    586         CONTROL_PARM cParm;
    587         int          fActive = pStream->isActive();
    588 
    589         dprintf(("ID Stop NF:%d",(USHORT)numFreeStreams));
    590         rc = pStream->StopStream(&cParm);
    591         if(!rc && fActive) numFreeStreams++;
    592         break;
    593     }
    594 
    595     case DAUDIO_PAUSE:
    596     {
    597         CONTROL_PARM cParm;
    598         dprintf(("ID Pause"));
    599         rc = pStream->PauseStream(&cParm);
    600         break;
    601     }
    602 
    603     case DAUDIO_RESUME:
    604     {
    605         dprintf(("ID Resume"));
    606         rc = pStream->ResumeStream();
    607         break;
    608     }
    609 
    610     case DAUDIO_GETPOS:
    611     {
     562                pDAudioCmd->Vol.VolumeL = GET_VOLUME_L(pStream->GetProperty(PROPERTY_VOLUME));
     563                pDAudioCmd->Vol.VolumeR = GET_VOLUME_R(pStream->GetProperty(PROPERTY_VOLUME));
     564                break;
     565        }
     566
     567        case DAUDIO_START:
     568        {
     569                dprintf(("ID Start NF:%d",(USHORT)numFreeStreams));
     570                if(numFreeStreams > 0)
     571                {
     572                          rc = pStream->StartStream();
     573                          if(!rc) numFreeStreams--;
     574                }
     575                else
     576                {
     577                          rprintf(("ID Start rc1"));
     578                          rc = 1; //fail
     579                }
     580                break;
     581        }
     582
     583        case DAUDIO_STOP:
     584        {
     585                CONTROL_PARM cParm;
     586                int              fActive = pStream->isActive();
     587
     588                dprintf(("ID Stop NF:%d",(USHORT)numFreeStreams));
     589                rc = pStream->StopStream(&cParm);
     590                if(!rc && fActive) numFreeStreams++;
     591                break;
     592        }
     593
     594        case DAUDIO_PAUSE:
     595        {
     596                CONTROL_PARM cParm;
     597                dprintf(("ID Pause"));
     598                rc = pStream->PauseStream(&cParm);
     599                break;
     600        }
     601
     602        case DAUDIO_RESUME:
     603        {
     604                dprintf(("ID Resume"));
     605                rc = pStream->ResumeStream();
     606                break;
     607        }
     608
     609        case DAUDIO_GETPOS:
     610        {
    612611                //dprintf(("ID GetPos"));
    613         pDAudioCmd->Pos.ulCurrentPos = pStream->GetCurrentPos();
    614         pDAudioCmd->Pos.ulWritePos  = pStream->GetCurrentWritePos();
    615         break;
    616     }
    617 
    618     case DAUDIO_ADDBUFFER:
    619     {
     612                pDAudioCmd->Pos.ulCurrentPos = pStream->GetCurrentPos();
     613                pDAudioCmd->Pos.ulWritePos      = pStream->GetCurrentWritePos();
     614                break;
     615        }
     616
     617        case DAUDIO_ADDBUFFER:
     618        {
    620619                //dprintf(("ID AddBuffer"));
    621         rc = pStream->Write((PSTREAMBUF)pDAudioCmd->Buffer.lpBuffer, pDAudioCmd->Buffer.ulBufferLength);
    622         break;
    623     }
    624 
    625     case DAUDIO_SETPROPERTY:
    626     {
     620                rc = pStream->Write((PSTREAMBUF)pDAudioCmd->Buffer.lpBuffer, pDAudioCmd->Buffer.ulBufferLength);
     621                break;
     622        }
     623
     624        case DAUDIO_SETPROPERTY:
     625        {
    627626                //dprintf(("ID SetProp"));
    628         rc = pStream->SetProperty((USHORT)pDAudioCmd->SetProperty.type, pDAudioCmd->SetProperty.value);
    629         break;
    630     }
    631 
    632     case DAUDIO_REGISTER_THREAD:
    633     {
    634         DDCMDREGISTER reg;
     627                rc = pStream->SetProperty((USHORT)pDAudioCmd->SetProperty.type, pDAudioCmd->SetProperty.value);
     628                break;
     629        }
     630
     631        case DAUDIO_REGISTER_THREAD:
     632        {
     633                DDCMDREGISTER reg;
    635634
    636635                //dprintf(("ID Reg"));
    637         reg.ulFunction     = DDCMD_REG_STREAM;
    638         reg.hStream        = pDAudioCmd->Thread.hSemaphore;
    639         reg.ulSysFileNum   = prp->s.ioctl.usSysFileNum;
    640         reg.pSHDEntryPoint = NULL;
    641         rc = pStream->Register(&reg);
    642         break;
    643     }
    644 
    645     case DAUDIO_DEREGISTER_THREAD:
    646     {
     636                reg.ulFunction     = DDCMD_REG_STREAM;
     637                reg.hStream        = pDAudioCmd->Thread.hSemaphore;
     638                reg.ulSysFileNum   = prp->s.ioctl.usSysFileNum;
     639                reg.pSHDEntryPoint = NULL;
     640                rc = pStream->Register(&reg);
     641                break;
     642        }
     643
     644        case DAUDIO_DEREGISTER_THREAD:
     645        {
    647646                //dprintf(("ID DeReg"));
    648         pStream->DeRegister();
    649         break;
    650     }
    651 
    652     case DAUDIO_QUERYVERSION:
     647                pStream->DeRegister();
     648                break;
     649        }
     650
     651        case DAUDIO_QUERYVERSION:
    653652                //dprintf(("ID qVer"));
    654         pDAudioCmd->Version.ulVersion = DAUDIO_VERSION;
    655         break;
    656     }
    657 
    658     if(rc)
    659     {
     653                pDAudioCmd->Version.ulVersion = DAUDIO_VERSION;
     654                break;
     655        }
     656
     657        if(rc)
     658        {
    660659                //dprintf(("IoctlDirectAudio ret err rc=%ld",rc));
    661         prp->usStatus |= RPERR | RPBADCMD;
    662         return;
    663     }
     660                prp->usStatus |= RPERR | RPBADCMD;
     661                return;
     662        }
    664663        //dprintf(("IoctlDirectAudio ret Ok"));
    665     return;
     664        return;
    666665}
    667666//******************************************************************************
    668667//******************************************************************************
    669668/**@internal
    670  * @param    PREQPACKET pointer to the strategy request packet
    671  * @return  None  But the Status in the request packet is updated on error
     669 * @param        PREQPACKET pointer to the strategy request packet
     670 * @return      None  But the Status in the request packet is updated on error
    672671 * @notes
    673672 * StrategyIoctl is called from the strategy entry point to process IOCTL
     
    681680extern "C" void StrategyIoctl(PREQPACKET prp, USHORT LDev)
    682681{
    683     dprintf(("StrategyIoctl:cat:0x%x, code:0x%x cd %d gd %d", prp->s.ioctl.bCategory, prp->s.ioctl.bCode, current_device, LDev));
     682        dprintf(("StrategyIoctl:cat:0x%x, code:0x%x cd %d gd %d", prp->s.ioctl.bCategory, prp->s.ioctl.bCode, current_device, LDev));
    684683        switch (prp->s.ioctl.bCategory) {
    685684        case DAUDIO_IOCTL_CAT: /* 0x91 */
    686         IoctlDirectAudio(prp);
    687         break;
     685                IoctlDirectAudio(prp);
     686                break;
    688687
    689688        case MIXER_IOCTL_CAT: /* 0x90 */
    690         IoctlMixer(prp, LDev);
    691         break;
     689                IoctlMixer(prp, LDev);
     690                break;
    692691
    693692        case AUDIO_IOCTL_CAT: /* 0x80 */
  • OCO/trunk/drv16/waudio.cpp

    r526 r533  
    13601360        ulBytesPerIRQ = pConfigInfo->ulPCMConsumeRate >> 6;  // 64 interrupts per second
    13611361                                                                                                                 // we can tweak this as needed but generally this should do rjj
     1362#if 0 // commented out by DAZ
    13621363        // make sure it's an even multiple of 64
    13631364        ulBytesPerIRQ += 0x00000040;
     
    13671368                  ulBytesPerIRQ = 0x800;
    13681369        }
     1370#endif
    13691371        pConfigInfo->ulBytesPerIRQ = ulBytesPerIRQ;
    13701372        dprintf4(("WAVEAUDIO::ConfigDev BytesPerIRQ:%ld",ulBytesPerIRQ));
  • OCO/trunk/drv16/wavestrm.cpp

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

    r526 r533  
    6363   ULONG   _ulBytesWritten;       // number of bytes transferred to uniaud32
    6464   ULONG   _ulBytesProcessed;     // number of bytes consumed or produced
     65   ULONG   _ulLastPosition;       // Last position of consumed bytes
    6566   ULONG   _ulTimeBase;           // value in ms. MMPM sends for stream time
    6667
  • OCO/trunk/install/CHANGELOG.TXT

    r510 r533  
    22UNIAUD CHANGELOG
    33================
     4
     5===== Uniaud16 1.9.5 and Uniaud32 1.9.24/2.1.1 : July 31, 2010 =====
     6
     7 * Added code to handle when uniaud32 processed byte counter wraps
     8   (uniaud16)
     9
     10 * All above changes by David Azarewicz
     11
     12===== Uniaud16 1.9.4 and Uniaud32 1.9.24/2.1.1 : July 27, 2010 =====
     13
     14 * Driver level underrun detection and attempted recovery removed
     15   from Uniaud16.
     16
     17 * Xrun restart fixed in Uniaud32.
     18
     19 * PCI bus scan now scans all 256 busses rather than just 16.
     20   Dynamic allocation of bus structure instead of static.
     21   Other PCI bus scan bugs fixed. (uniaud32)
     22
     23 * Implemented wild card (PCI_ANY_ID) device matching in PCI bus
     24   scan (uniaud32)
     25
     26 * Implemented wild card (PCI_ANY_ID) device matching in deregister
     27   driver (uniaud32)
     28
     29 * Changed flush_workqueue to not hang on shutdown. (uniaud32)
     30
     31 * Added mixer quirk for Intel Gateway/eMachines with STAC 922x mixer
     32   (uniaud32)
     33
     34 * All above changes by David Azarewicz
    435
    536===== 1.9.3 and 1.9.23 : July 10, 2010 =====
  • OCO/trunk/install/control.scr

    r529 r533  
    2525ssgroup=0
    2626ssname="mmbase"
    27 ssversion="1.9.4-SVNr529"
     27ssversion="1.9.5-SVNr533"
    2828sstermdll="ITERM.DLL"
    2929sstermdllentry="ITermEntry"
     
    4343ssgroup=17
    4444ssname="OS/2 Universal Audio: Wave"
    45 ssversion="1.9.4-SVNr529"
     45ssversion="1.9.5-SVNr533"
    4646sssize=680
    4747ssdll="genin.dll"
  • OCO/trunk/uniaud.inc

    r529 r533  
    77# BUILDVERSION must be 3 parts, and only numbers like 5.44.108
    88# It is best that 2nd number is always 2 digits, eg at least 10
    9 BUILDVERSION = 1.9.4
     9BUILDVERSION = 1.9.5
    1010
    1111# Fixpack version
     
    1313# ex RC3  GA  FIXPACK2 beta_47
    1414# Comment out to avoid a fixpack line in bldlevel
    15 FIXPACK = SVNr529
     15FIXPACK = SVNr533
    1616
    1717# ALSA BUILD VERSION
Note: See TracChangeset for help on using the changeset viewer.