VirtualBox

Changeset 69876 in vbox


Ignore:
Timestamp:
Nov 30, 2017 9:49:32 AM (7 years ago)
Author:
vboxsync
Message:

Audio/SB16: Fixed volume handling.

File:
1 edited

Legend:

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

    r69288 r69876  
    12141214}
    12151215
    1216 static void sb16SetMasterVolume(PSB16STATE pThis)
     1216/**
     1217 * Returns the device's current master volume.
     1218 *
     1219 * @param   pThis               SB16 state.
     1220 * @param   pVol                Where to store the master volume information.
     1221 */
     1222static void sb16GetMasterVolume(PSB16STATE pThis, PPDMAUDIOVOLUME pVol)
    12171223{
    12181224    /* There's no mute switch, only volume controls. */
     
    12201226    uint8_t rvol = sb16MixRegToVol(pThis, 0x31);
    12211227
    1222     PDMAUDIOVOLUME Vol = { false /* fMute */, lvol, rvol };
    1223 
    1224     PSB16DRIVER pDrv;
    1225     RTListForEach(&pThis->lstDrv, pDrv, SB16DRIVER, Node)
    1226     {
    1227         int rc2 = pDrv->pConnector->pfnStreamSetVolume(pDrv->pConnector, pDrv->Out.pStream, &Vol);
    1228         AssertRC(rc2);
    1229     }
    1230 }
    1231 
    1232 static void sb16SetPcmOutVolume(PSB16STATE pThis)
     1228    pVol->fMuted = false;
     1229    pVol->uLeft  = lvol;
     1230    pVol->uRight = rvol;
     1231}
     1232
     1233/**
     1234 * Returns the device's current output stream volume.
     1235 *
     1236 * @param   pThis               SB16 state.
     1237 * @param   pVol                Where to store the output stream volume information.
     1238 */
     1239static void sb16GetPcmOutVolume(PSB16STATE pThis, PPDMAUDIOVOLUME pVol)
    12331240{
    12341241    /* There's no mute switch, only volume controls. */
     
    12361243    uint8_t rvol = sb16MixRegToVol(pThis, 0x33);
    12371244
    1238     PDMAUDIOVOLUME Vol = { false /* fMute */, lvol, rvol };
     1245    pVol->fMuted = false;
     1246    pVol->uLeft  = lvol;
     1247    pVol->uRight = rvol;
     1248}
     1249
     1250static void sb16UpdateVolume(PSB16STATE pThis)
     1251{
     1252    PDMAUDIOVOLUME VolMaster;
     1253    sb16GetMasterVolume(pThis, &VolMaster);
     1254
     1255    PDMAUDIOVOLUME VolOut;
     1256    sb16GetPcmOutVolume(pThis, &VolOut);
     1257
     1258    /* Combine the master + output stream volume. */
     1259    PDMAUDIOVOLUME VolCombined;
     1260    RT_ZERO(VolCombined);
     1261
     1262    VolCombined.fMuted = VolMaster.fMuted || VolOut.fMuted;
     1263    if (!VolCombined.fMuted)
     1264    {
     1265        VolCombined.uLeft  = (   (VolOut.uLeft    ? VolOut.uLeft     : 1)
     1266                               * (VolMaster.uLeft ? VolMaster.uLeft  : 1)) / PDMAUDIO_VOLUME_MAX;
     1267
     1268        VolCombined.uRight = (  (VolOut.uRight    ? VolOut.uRight    : 1)
     1269                              * (VolMaster.uRight ? VolMaster.uRight : 1)) / PDMAUDIO_VOLUME_MAX;
     1270    }
    12391271
    12401272    PSB16DRIVER pDrv;
    12411273    RTListForEach(&pThis->lstDrv, pDrv, SB16DRIVER, Node)
    12421274    {
    1243         int rc2 = pDrv->pConnector->pfnStreamSetVolume(pDrv->pConnector, pDrv->Out.pStream, &Vol);
     1275        int rc2 = pDrv->pConnector->pfnStreamSetVolume(pDrv->pConnector, pDrv->Out.pStream, &VolCombined);
    12441276        AssertRC(rc2);
    12451277    }
     
    15111543
    15121544    /* Update the master (mixer) and PCM out volumes. */
    1513     sb16SetMasterVolume(pThis);
    1514     sb16SetPcmOutVolume(pThis);
     1545    sb16UpdateVolume(pThis);
    15151546}
    15161547
     
    16861717
    16871718    /* Update the master (mixer) volume. */
    1688     if (fUpdateMaster)
    1689         sb16SetMasterVolume(pThis);
    1690 
    1691     /* Update the stream (PCM) volume. */
    1692     if (fUpdateStream)
    1693         sb16SetPcmOutVolume(pThis);
     1719    if (   fUpdateMaster
     1720        || fUpdateStream)
     1721    {
     1722        sb16UpdateVolume(pThis);
     1723    }
    16941724
    16951725    return VINF_SUCCESS;
     
    21842214
    21852215    /* Update the master (mixer) and PCM out volumes. */
    2186     sb16SetMasterVolume(pThis);
    2187     sb16SetPcmOutVolume(pThis);
     2216    sb16UpdateVolume(pThis);
    21882217
    21892218    return VINF_SUCCESS;
     
    23422371            rc = rc2;
    23432372    }
     2373
     2374    sb16UpdateVolume(pThis);
    23442375
    23452376    LogFlowFuncLeaveRC(rc);
Note: See TracChangeset for help on using the changeset viewer.

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