VirtualBox

Ignore:
Timestamp:
Mar 24, 2021 11:45:54 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
143474
Message:

Audio: Made sure PDMAUDIOPCMPROPS is initialized using a helper function or the initializer macro, and that vital changes are made using setting helper functions. There are now two derived fields (frame size and shift count) that must be maintained, so this was the sanest way of doing it. Added a raw flag to PDMAUDIOPCMPROPS for VRDE/VRDP, since it wants the raw mixer content and we need a way of expressing this (PDMAUDIOSTREAMLAYOUT isn't the right place). The mixer buffers now uses PDMAUDIOPCMPROPS rather than the weird 32-bit format contraption for picking conversion functions. Simplify the drvAudioStreamPlay code by eliminating the PDMAUDIOSTREAMLAYOUT_RAW special case. bugref:9890

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Audio/DrvHostAudioAlsa.cpp

    r88235 r88269  
    149149static snd_pcm_format_t alsaAudioPropsToALSA(PPDMAUDIOPCMPROPS pProps)
    150150{
    151     switch (pProps->cbSample)
     151    switch (PDMAudioPropsSampleSize(pProps))
    152152    {
    153153        case 1:
     
    155155
    156156        case 2:
    157             return pProps->fSigned ? SND_PCM_FORMAT_S16_LE : SND_PCM_FORMAT_U16_LE;
     157            if (PDMAudioPropsIsLittleEndian(pProps))
     158                return pProps->fSigned ? SND_PCM_FORMAT_S16_LE : SND_PCM_FORMAT_U16_LE;
     159            return pProps->fSigned ? SND_PCM_FORMAT_S16_BE : SND_PCM_FORMAT_U16_BE;
    158160
    159161        case 4:
    160             return pProps->fSigned ? SND_PCM_FORMAT_S32_LE : SND_PCM_FORMAT_U32_LE;
     162            if (PDMAudioPropsIsLittleEndian(pProps))
     163                return pProps->fSigned ? SND_PCM_FORMAT_S32_LE : SND_PCM_FORMAT_U32_LE;
     164            return pProps->fSigned ? SND_PCM_FORMAT_S32_BE : SND_PCM_FORMAT_U32_BE;
    161165
    162166        default:
    163             break;
    164     }
    165 
    166     AssertMsgFailed(("%RU8 bytes not supported\n", pProps->cbSample));
    167     return SND_PCM_FORMAT_U8;
     167            AssertMsgFailed(("%RU8 bytes not supported\n", PDMAudioPropsSampleSize(pProps)));
     168            return SND_PCM_FORMAT_U8;
     169    }
    168170}
    169171
     
    173175 *
    174176 * @returns VBox status code.
    175  * @param   fmt                 ALSA PCM format to convert.
    176  * @param   pProps              Where to store the converted PCM properties on success.
    177  */
    178 static int alsaALSAToAudioProps(snd_pcm_format_t fmt, PPDMAUDIOPCMPROPS pProps)
    179 {
     177 * @param   pProps      Where to store the converted PCM properties on success.
     178 * @param   fmt         ALSA PCM format to convert.
     179 * @param   cChannels   Number of channels.
     180 * @param   uHz         Frequency.
     181 */
     182static int alsaALSAToAudioProps(PPDMAUDIOPCMPROPS pProps, snd_pcm_format_t fmt, int cChannels, unsigned uHz)
     183{
     184    AssertReturn(cChannels > 0, VERR_INVALID_PARAMETER);
     185    AssertReturn(cChannels < 16, VERR_INVALID_PARAMETER);
    180186    switch (fmt)
    181187    {
    182188        case SND_PCM_FORMAT_S8:
    183             pProps->cbSample    = 1;
    184             pProps->fSigned     = true;
    185             pProps->fSwapEndian = false;
     189            PDMAudioPropsInit(pProps, 1 /*8-bit*/,  true /*signed*/, cChannels, uHz);
    186190            break;
    187191
    188192        case SND_PCM_FORMAT_U8:
    189             pProps->cbSample    = 1;
    190             pProps->fSigned     = false;
    191             pProps->fSwapEndian = false;
     193            PDMAudioPropsInit(pProps, 1 /*8-bit*/, false /*signed*/, cChannels, uHz);
    192194            break;
    193195
    194196        case SND_PCM_FORMAT_S16_LE:
    195             pProps->cbSample    = 2;
    196             pProps->fSigned     = true;
    197             pProps->fSwapEndian = false;
     197            PDMAudioPropsInitEx(pProps, 2 /*16-bit*/,  true /*signed*/, cChannels, uHz, true /*fLittleEndian*/, false /*fRaw*/);
    198198            break;
    199199
    200200        case SND_PCM_FORMAT_U16_LE:
    201             pProps->cbSample    = 2;
    202             pProps->fSigned     = false;
    203             pProps->fSwapEndian = false;
     201            PDMAudioPropsInitEx(pProps, 2 /*16-bit*/, false /*signed*/, cChannels, uHz, true /*fLittleEndian*/, false /*fRaw*/);
    204202            break;
    205203
    206204        case SND_PCM_FORMAT_S16_BE:
    207             pProps->cbSample    = 2;
    208             pProps->fSigned     = true;
    209 #ifdef RT_LITTLE_ENDIAN
    210             pProps->fSwapEndian = true;
    211 #endif
     205            PDMAudioPropsInitEx(pProps, 2 /*16-bit*/,  true /*signed*/, cChannels, uHz, false /*fLittleEndian*/, false /*fRaw*/);
    212206            break;
    213207
    214208        case SND_PCM_FORMAT_U16_BE:
    215             pProps->cbSample    = 2;
    216             pProps->fSigned     = false;
    217 #ifdef RT_LITTLE_ENDIAN
    218             pProps->fSwapEndian = true;
    219 #endif
     209            PDMAudioPropsInitEx(pProps, 2 /*16-bit*/, false /*signed*/, cChannels, uHz, false /*fLittleEndian*/, false /*fRaw*/);
    220210            break;
    221211
    222212        case SND_PCM_FORMAT_S32_LE:
    223             pProps->cbSample    = 4;
    224             pProps->fSigned     = true;
    225             pProps->fSwapEndian = false;
     213            PDMAudioPropsInitEx(pProps, 4 /*32-bit*/,  true /*signed*/, cChannels, uHz, true /*fLittleEndian*/, false /*fRaw*/);
    226214            break;
    227215
    228216        case SND_PCM_FORMAT_U32_LE:
    229             pProps->cbSample    = 4;
    230             pProps->fSigned     = false;
    231             pProps->fSwapEndian = false;
     217            PDMAudioPropsInitEx(pProps, 4 /*32-bit*/, false /*signed*/, cChannels, uHz, true /*fLittleEndian*/, false /*fRaw*/);
    232218            break;
    233219
    234220        case SND_PCM_FORMAT_S32_BE:
    235             pProps->cbSample    = 4;
    236             pProps->fSigned     = true;
    237 #ifdef RT_LITTLE_ENDIAN
    238             pProps->fSwapEndian = true;
    239 #endif
     221            PDMAudioPropsInitEx(pProps, 4 /*32-bit*/,  true /*signed*/, cChannels, uHz, false /*fLittleEndian*/, false /*fRaw*/);
    240222            break;
    241223
    242224        case SND_PCM_FORMAT_U32_BE:
    243             pProps->cbSample    = 4;
    244             pProps->fSigned     = false;
    245 #ifdef RT_LITTLE_ENDIAN
    246             pProps->fSwapEndian = true;
    247 #endif
     225            PDMAudioPropsInitEx(pProps, 4 /*32-bit*/, false /*signed*/, cChannels, uHz, false /*fLittleEndian*/, false /*fRaw*/);
    248226            break;
    249227
     
    251229            AssertMsgFailedReturn(("Format %d not supported\n", fmt), VERR_NOT_SUPPORTED);
    252230    }
    253 
    254     AssertReturn(pProps->cbSample > 0,  VERR_NOT_SUPPORTED);
    255     AssertReturn(pProps->cChannels > 0, VERR_INVALID_PARAMETER);
    256 
    257     pProps->cShift = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(pProps->cbSample, pProps->cChannels);
    258 
    259231    return VINF_SUCCESS;
    260232}
     
    937909        ALSAAUDIOSTREAMCFG req;
    938910        req.fmt         = alsaAudioPropsToALSA(&pCfgReq->Props);
    939         req.freq        = pCfgReq->Props.uHz;
    940         req.nchannels   = pCfgReq->Props.cChannels;
     911        req.freq        = PDMAudioPropsHz(&pCfgReq->Props);
     912        req.nchannels   = PDMAudioPropsChannels(&pCfgReq->Props);
    941913        req.period_size = pCfgReq->Backend.cFramesPeriod;
    942914        req.buffer_size = pCfgReq->Backend.cFramesBufferSize;
     
    948920            break;
    949921
    950         pCfgAcq->Props.uHz       = obt.freq;
    951         pCfgAcq->Props.cChannels = obt.nchannels;
    952 
    953         rc = alsaALSAToAudioProps(obt.fmt, &pCfgAcq->Props);
     922        rc = alsaALSAToAudioProps(&pCfgAcq->Props, obt.fmt, obt.nchannels, obt.freq);
    954923        if (RT_FAILURE(rc))
    955924            break;
     
    1000969        ALSAAUDIOSTREAMCFG req;
    1001970        req.fmt         = alsaAudioPropsToALSA(&pCfgReq->Props);
    1002         req.freq        = pCfgReq->Props.uHz;
    1003         req.nchannels   = pCfgReq->Props.cChannels;
     971        req.freq        = PDMAudioPropsHz(&pCfgReq->Props);
     972        req.nchannels   = PDMAudioPropsChannels(&pCfgReq->Props);
    1004973        req.period_size = PDMAudioPropsMilliToFrames(&pCfgReq->Props, 50 /*ms*/); /** @todo Make this configurable. */
    1005974        req.buffer_size = req.period_size * 2; /** @todo Make this configurable. */
     
    1011980            break;
    1012981
    1013         pCfgAcq->Props.uHz       = obt.freq;
    1014         pCfgAcq->Props.cChannels = obt.nchannels;
    1015 
    1016         rc = alsaALSAToAudioProps(obt.fmt, &pCfgAcq->Props);
     982        rc = alsaALSAToAudioProps(&pCfgAcq->Props, obt.fmt, obt.nchannels, obt.freq);
    1017983        if (RT_FAILURE(rc))
    1018984            break;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette