VirtualBox

Changeset 89768 in vbox for trunk/src/VBox/Devices/Audio


Ignore:
Timestamp:
Jun 17, 2021 11:03:19 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
145220
Message:

Audio: Made PDMAUDIOVOLUME multichannel. bugref:9890

Location:
trunk/src/VBox/Devices/Audio
Files:
7 edited

Legend:

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

    r89529 r89768  
    20822082    AssertPtrReturnVoid(pVol);
    20832083
    2084     LogFlowFunc(("%s: lVol=%RU8, rVol=%RU8, fMuted=%RTbool\n", pMixBuf->pszName, pVol->uLeft, pVol->uRight, pVol->fMuted));
     2084    LogFlowFunc(("%s: fMuted=%RTbool auChannels=%.*Rhxs\n",
     2085                 pMixBuf->pszName, pVol->fMuted, sizeof(pVol->auChannels), pVol->auChannels));
    20852086
    20862087    /*
     
    20912092        pMixBuf->Volume.fMuted  = false;
    20922093
    2093         AssertCompileSize(pVol->uLeft, sizeof(uint8_t));
    2094         pMixBuf->Volume.auChannels[0] = s_aVolumeConv[pVol->uLeft ] * (AUDIOMIXBUF_VOL_0DB >> 16);
    2095         pMixBuf->Volume.auChannels[1] = s_aVolumeConv[pVol->uRight] * (AUDIOMIXBUF_VOL_0DB >> 16);
     2094        AssertCompileSize(pVol->auChannels[0], sizeof(uint8_t));
    20962095        for (uintptr_t i = 2; i < pMixBuf->cChannels; i++)
    2097             pMixBuf->Volume.auChannels[i] = pMixBuf->Volume.auChannels[1];
     2096            pMixBuf->Volume.auChannels[i] = s_aVolumeConv[pVol->auChannels[i]] * (AUDIOMIXBUF_VOL_0DB >> 16);
    20982097
    20992098        pMixBuf->Volume.fAllMax = true;
  • trunk/src/VBox/Devices/Audio/AudioMixer.cpp

    r89559 r89768  
    193193
    194194            /* Set master volume to the max. */
    195             pMixer->VolMaster.fMuted = false;
    196             pMixer->VolMaster.uLeft  = PDMAUDIO_VOLUME_MAX;
    197             pMixer->VolMaster.uRight = PDMAUDIO_VOLUME_MAX;
     195            PDMAudioVolumeInitMax(&pMixer->VolMaster);
    198196
    199197            LogFlowFunc(("Created mixer '%s'\n", pMixer->pszName));
     
    262260    AssertRCReturnVoid(rc2);
    263261
    264     pHlp->pfnPrintf(pHlp, "[Master] %s: lVol=%u, rVol=%u, fMuted=%RTbool\n", pMixer->pszName,
    265                     pMixer->VolMaster.uLeft, pMixer->VolMaster.uRight, pMixer->VolMaster.fMuted);
     262    pHlp->pfnPrintf(pHlp, "[Master] %s: fMuted=%RTbool auChannels=%.*Rhxs\n",
     263                    pMixer->pszName, pMixer->VolMaster.fMuted, sizeof(pMixer->VolMaster.auChannels), pMixer->VolMaster.auChannels);
    266264
    267265    PAUDMIXSINK pSink;
     
    269267    RTListForEach(&pMixer->lstSinks, pSink, AUDMIXSINK, Node)
    270268    {
    271         pHlp->pfnPrintf(pHlp, "[Sink %u] %s: lVol=%u, rVol=%u, fMuted=%RTbool\n", iSink, pSink->pszName,
    272                         pSink->Volume.uLeft, pSink->Volume.uRight, pSink->Volume.fMuted);
     269        pHlp->pfnPrintf(pHlp, "[Sink %u] %s: fMuted=%RTbool auChannels=%.*Rhxs\n",
     270                        iSink, pSink->pszName, pSink->Volume.fMuted, sizeof(pSink->Volume.auChannels), pSink->Volume.auChannels);
    273271        ++iSink;
    274272    }
     
    298296     * Make a copy.
    299297     */
     298    LogFlowFunc(("[%s] fMuted=%RTbool auChannels=%.*Rhxs => fMuted=%RTbool auChannels=%.*Rhxs\n", pMixer->pszName,
     299                 pMixer->VolMaster.fMuted, sizeof(pMixer->VolMaster.auChannels), pMixer->VolMaster.auChannels,
     300                 pVol->fMuted, sizeof(pVol->auChannels), pVol->auChannels ));
    300301    memcpy(&pMixer->VolMaster, pVol, sizeof(PDMAUDIOVOLUME));
    301     LogFlowFunc(("[%s] lVol=%RU32, rVol=%RU32 => fMuted=%RTbool, lVol=%RU32, rVol=%RU32\n",
    302                  pMixer->pszName, pVol->uLeft, pVol->uRight,
    303                  pMixer->VolMaster.fMuted, pMixer->VolMaster.uLeft, pMixer->VolMaster.uRight));
    304302
    305303    /*
     
    395393
    396394            /* Set initial volume to max. */
    397             pSink->Volume.fMuted = false;
    398             pSink->Volume.uLeft  = PDMAUDIO_VOLUME_MAX;
    399             pSink->Volume.uRight = PDMAUDIO_VOLUME_MAX;
     395            PDMAudioVolumeInitMax(&pSink->Volume);
    400396
    401397            /* Ditto for the combined volume. */
    402             pSink->VolumeCombined.fMuted = false;
    403             pSink->VolumeCombined.uLeft  = PDMAUDIO_VOLUME_MAX;
    404             pSink->VolumeCombined.uRight = PDMAUDIO_VOLUME_MAX;
     398            PDMAudioVolumeInitMax(&pSink->VolumeCombined);
    405399
    406400            /* AIO */
     
    10621056    Assert(pSink->uMagic == AUDMIXSINK_MAGIC);
    10631057    AssertPtr(pVolMaster);
    1064     LogFlowFunc(("[%s] Master fMuted=%RTbool, lVol=%RU32, rVol=%RU32\n",
    1065                   pSink->pszName, pVolMaster->fMuted, pVolMaster->uLeft, pVolMaster->uRight));
    1066 
    1067     pSink->VolumeCombined.fMuted = pVolMaster->fMuted || pSink->Volume.fMuted;
    1068     /** @todo Very crude implementation for now -- needs more work! */
    1069     pSink->VolumeCombined.uLeft  = (uint32_t)RT_MAX(pSink->Volume.uLeft, 1)  * RT_MAX(pVolMaster->uLeft, 1)  / PDMAUDIO_VOLUME_MAX;
    1070     pSink->VolumeCombined.uRight = (uint32_t)RT_MAX(pSink->Volume.uRight, 1) * RT_MAX(pVolMaster->uRight, 1) / PDMAUDIO_VOLUME_MAX;
    1071 
    1072     LogFlowFunc(("[%s] fMuted=%RTbool, lVol=%RU32, rVol=%RU32 -> fMuted=%RTbool, lVol=%RU32, rVol=%RU32\n",
    1073                  pSink->pszName, pSink->Volume.fMuted, pSink->Volume.uLeft, pSink->Volume.uRight,
    1074                  pSink->VolumeCombined.fMuted, pSink->VolumeCombined.uLeft, pSink->VolumeCombined.uRight));
     1058    LogFlowFunc(("[%s] Master fMuted=%RTbool auChannels=%.*Rhxs\n",
     1059                  pSink->pszName, pVolMaster->fMuted, sizeof(pVolMaster->auChannels), pVolMaster->auChannels));
     1060
     1061    PDMAudioVolumeCombine(&pSink->VolumeCombined, &pSink->Volume, pVolMaster);
     1062
     1063    LogFlowFunc(("[%s] fMuted=%RTbool auChannels=%.*Rhxs -> fMuted=%RTbool auChannels=%.*Rhxs\n", pSink->pszName,
     1064                 pSink->Volume.fMuted, sizeof(pSink->Volume.auChannels), pSink->Volume.auChannels,
     1065                 pSink->VolumeCombined.fMuted, sizeof(pSink->VolumeCombined.auChannels), pSink->VolumeCombined.auChannels ));
    10751066
    10761067    AudioMixBufSetVolume(&pSink->MixBuf, &pSink->VolumeCombined);
     
    10971088    memcpy(&pSink->Volume, pVol, sizeof(PDMAUDIOVOLUME));
    10981089
    1099     LogRel2(("Audio Mixer: Setting volume of sink '%s' to %RU8/%RU8 (%s)\n",
    1100              pSink->pszName, pVol->uLeft, pVol->uRight, pVol->fMuted ? "Muted" : "Unmuted"));
     1090    LogRel2(("Audio Mixer: Setting volume of sink '%s' to fMuted=%RTbool auChannels=%.*Rhxs\n",
     1091              pSink->pszName, pVol->fMuted, sizeof(pVol->auChannels), pVol->auChannels));
    11011092
    11021093    Assert(pSink->pParent);
  • trunk/src/VBox/Devices/Audio/DevHda.cpp

    r89757 r89768  
    25852585        && pSink->pMixSink)
    25862586    {
    2587         LogRel2(("HDA: Setting volume for mixer sink '%s' to %RU8/%RU8 (%s)\n",
    2588                  pSink->pMixSink->pszName, pVol->uLeft, pVol->uRight, pVol->fMuted ? "Muted" : "Unmuted"));
     2587        LogRel2(("HDA: Setting volume for mixer sink '%s' to fMuted=%RTbool auChannels=%.*Rhxs\n",
     2588                 pSink->pMixSink->pszName, pVol->fMuted, sizeof(pVol->auChannels), pVol->auChannels));
    25892589
    25902590        /* Set the volume.
     
    49214921
    49224922    /* There is no master volume control. Set the master to max. */
    4923     PDMAUDIOVOLUME vol = { false, 255, 255 };
    4924     rc = AudioMixerSetMasterVolume(pThisCC->pMixer, &vol);
     4923    PDMAUDIOVOLUME Vol = PDMAUDIOVOLUME_INITIALIZER_MAX;
     4924    rc = AudioMixerSetMasterVolume(pThisCC->pMixer, &Vol);
    49254925    AssertRCReturn(rc, rc);
    49264926
  • trunk/src/VBox/Devices/Audio/DevHdaCodec.cpp

    r89213 r89768  
    896896    iMute &= 0x1;
    897897
    898     uint8_t lVol = AMPLIFIER_REGISTER(*pAmp, iDir, AMPLIFIER_LEFT,  0) & 0x7f;
    899     uint8_t rVol = AMPLIFIER_REGISTER(*pAmp, iDir, AMPLIFIER_RIGHT, 0) & 0x7f;
     898    uint8_t bLeft = AMPLIFIER_REGISTER(*pAmp, iDir, AMPLIFIER_LEFT,  0) & 0x7f;
     899    uint8_t bRight = AMPLIFIER_REGISTER(*pAmp, iDir, AMPLIFIER_RIGHT, 0) & 0x7f;
    900900
    901901    /*
     
    905905     * to 1 (rather than zero) internally.
    906906     */
    907     lVol = (lVol + 1) * (2 * 255) / 256;
    908     rVol = (rVol + 1) * (2 * 255) / 256;
    909 
    910     PDMAUDIOVOLUME Vol = { RT_BOOL(iMute), lVol, rVol };
    911 
    912     LogFunc(("[NID0x%02x] %RU8/%RU8 (%s)\n",
    913              pNode->node.uID, lVol, rVol, RT_BOOL(iMute) ? "Muted" : "Unmuted"));
    914 
    915     LogRel2(("HDA: Setting volume for mixer control '%s' to %RU8/%RU8 (%s)\n",
    916              PDMAudioMixerCtlGetName(enmMixerCtl), lVol, rVol, RT_BOOL(iMute) ? "Muted" : "Unmuted"));
     907    bLeft = (bLeft + 1) * (2 * 255) / 256;
     908    bRight = (bRight + 1) * (2 * 255) / 256;
     909
     910    PDMAUDIOVOLUME Vol;
     911    PDMAudioVolumeInitFromStereo(&Vol, RT_BOOL(iMute), bLeft, bRight);
     912
     913    LogFunc(("[NID0x%02x] %RU8/%RU8%s\n", pNode->node.uID, bLeft, bRight, Vol.fMuted ? "- Muted!" : ""));
     914    LogRel2(("HDA: Setting volume for mixer control '%s' to %RU8/%RU8%s\n",
     915             PDMAudioMixerCtlGetName(enmMixerCtl), bLeft, bRight, Vol.fMuted ? "- Muted!" : ""));
    917916
    918917    return pThisCC->pfnCbMixerSetVolume(pThisCC->pDevIns, enmMixerCtl, &Vol);
  • trunk/src/VBox/Devices/Audio/DevIchAc97.cpp

    r89759 r89768  
    12761276        {
    12771277            STAM_REL_COUNTER_INC(&pStreamCC->State.StatDmaFlowProblems);
    1278             Log(("ichac97R3StreamUpdateDma: Warning! Stream #%u has insufficient space free: %u bytes, need %u.  Will try move data out of the buffer...\n",
     1278            LogFunc(("Warning! Stream #%u has insufficient space free: %u bytes, need %u.  Will try move data out of the buffer...\n",
    12791279                 pStreamCC->u8SD, cbStreamFree, cbPeriod));
    12801280            int rc = AudioMixerSinkTryLock(pSink);
     
    12871287            else
    12881288                RTThreadYield();
    1289             Log(("ichac97R3StreamUpdateDma: Gained %u bytes.\n", ichac97R3StreamGetFree(pStreamCC) - cbStreamFree));
     1289            LogFunc(("Gained %u bytes.\n", ichac97R3StreamGetFree(pStreamCC) - cbStreamFree));
    12901290
    12911291            cbStreamFree = ichac97R3StreamGetFree(pStreamCC);
     
    13561356            if (cbStreamUsed < cbPreBuffer)
    13571357            {
    1358                 Log3(("hdaR3StreamUpdateDma: Pre-buffering (got %#x out of %#x bytes)...\n", cbStreamUsed, cbPreBuffer));
     1358                Log3Func(("Pre-buffering (got %#x out of %#x bytes)...\n", cbStreamUsed, cbPreBuffer));
    13591359                fWriteSilence = true;
    13601360                cbStreamUsed  = cbPeriod;
     
    13621362            else
    13631363            {
    1364                 Log3(("hdaR3StreamUpdateDma: Completed pre-buffering (got %#x, needed %#x bytes).\n", cbStreamUsed, cbPreBuffer));
     1364                Log3Func(("Completed pre-buffering (got %#x, needed %#x bytes).\n", cbStreamUsed, cbPreBuffer));
    13651365                pStreamCC->State.fInputPreBuffered = true;
    13661366                fWriteSilence = ichac97R3StreamGetFree(pStreamCC) >= cbPreBuffer + cbPreBuffer / 2;
     
    13761376        {
    13771377            STAM_REL_COUNTER_INC(&pStreamCC->State.StatDmaFlowProblems);
    1378             Log(("ichac97R3StreamUpdateDma: Warning! Stream #%u has insufficient data available: %u bytes, need %u.  Will try move pull more data into the buffer...\n",
     1378            LogFunc(("Warning! Stream #%u has insufficient data available: %u bytes, need %u.  Will try move pull more data into the buffer...\n",
    13791379                 pStreamCC->u8SD, cbStreamUsed, cbPeriod));
    13801380            int rc = AudioMixerSinkTryLock(pSink);
     
    13871387            else
    13881388                RTThreadYield();
    1389             Log(("ichac97R3StreamUpdateDma: Gained %u bytes.\n", ichac97R3StreamGetUsed(pStreamCC) - cbStreamUsed));
     1389            LogFunc(("Gained %u bytes.\n", ichac97R3StreamGetUsed(pStreamCC) - cbStreamUsed));
    13901390            cbStreamUsed = ichac97R3StreamGetUsed(pStreamCC);
    13911391            if (cbStreamUsed < cbPeriod)
     
    30343034    if (pThisCC->pMixer) /* Device can be in reset state, so no mixer available. */
    30353035    {
    3036         PDMAUDIOVOLUME Vol   = { fCtlMuted, lVol, rVol };
    3037         PAUDMIXSINK    pSink = NULL;
    3038 
     3036        PDMAUDIOVOLUME Vol;
     3037        PDMAudioVolumeInitFromStereo(&Vol, fCtlMuted, lVol, rVol);
     3038
     3039        PAUDMIXSINK pSink = NULL;
    30393040        switch (enmMixerCtl)
    30403041        {
     
    31183119    if (pThisCC->pMixer) /* Device can be in reset state, so no mixer available. */
    31193120    {
    3120         PDMAUDIOVOLUME Vol   = { fCtlMuted, lVol, rVol };
     3121        PDMAUDIOVOLUME Vol;
     3122        PDMAudioVolumeInitFromStereo(&Vol, fCtlMuted, lVol, rVol);
     3123
    31213124        PAUDMIXSINK    pSink = NULL;
    3122 
    31233125        switch (enmMixerCtl)
    31243126        {
     
    31373139        }
    31383140
    3139         if (pSink) {
     3141        if (pSink)
     3142        {
    31403143            rc = AudioMixerSinkSetVolume(pSink, &Vol);
    31413144            /* There is only one AC'97 recording gain control. If line in
     
    31443147             * NB: The codecs we support do not have the dedicated microphone control.
    31453148             */
    3146             if ((pSink == pThisCC->pSinkLineIn) && pThisCC->pSinkMicIn)
     3149            if (pSink == pThisCC->pSinkLineIn && pThisCC->pSinkMicIn)
    31473150                rc = AudioMixerSinkSetVolume(pSink, &Vol);
    31483151        }
  • trunk/src/VBox/Devices/Audio/DevSB16.cpp

    r89379 r89768  
    11831183 * @param   pVol                Where to store the master volume information.
    11841184 */
    1185 static void sb16GetMasterVolume(PSB16STATE pThis, PPDMAUDIOVOLUME pVol)
     1185DECLINLINE(void) sb16GetMasterVolume(PSB16STATE pThis, PPDMAUDIOVOLUME pVol)
    11861186{
    11871187    /* There's no mute switch, only volume controls. */
    1188     uint8_t lvol = sb16MixRegToVol(pThis, 0x30);
    1189     uint8_t rvol = sb16MixRegToVol(pThis, 0x31);
    1190 
    1191     pVol->fMuted = false;
    1192     pVol->uLeft  = lvol;
    1193     pVol->uRight = rvol;
     1188    PDMAudioVolumeInitFromStereo(pVol, false /*fMuted*/, sb16MixRegToVol(pThis, 0x30), sb16MixRegToVol(pThis, 0x31));
    11941189}
    11951190
     
    12001195 * @param   pVol                Where to store the output stream volume information.
    12011196 */
    1202 static void sb16GetPcmOutVolume(PSB16STATE pThis, PPDMAUDIOVOLUME pVol)
     1197DECLINLINE(void) sb16GetPcmOutVolume(PSB16STATE pThis, PPDMAUDIOVOLUME pVol)
    12031198{
    12041199    /* There's no mute switch, only volume controls. */
    1205     uint8_t lvol = sb16MixRegToVol(pThis, 0x32);
    1206     uint8_t rvol = sb16MixRegToVol(pThis, 0x33);
    1207 
    1208     pVol->fMuted = false;
    1209     pVol->uLeft  = lvol;
    1210     pVol->uRight = rvol;
     1200    PDMAudioVolumeInitFromStereo(pVol, false /*fMuted*/, sb16MixRegToVol(pThis, 0x32), sb16MixRegToVol(pThis, 0x33));
    12111201}
    12121202
     
    12211211    /* Combine the master + output stream volume. */
    12221212    PDMAUDIOVOLUME VolCombined;
    1223     RT_ZERO(VolCombined);
    1224 
    1225     VolCombined.fMuted = VolMaster.fMuted || VolOut.fMuted;
    1226     if (!VolCombined.fMuted)
    1227     {
    1228         VolCombined.uLeft  = (   (VolOut.uLeft    ? VolOut.uLeft     : 1)
    1229                                * (VolMaster.uLeft ? VolMaster.uLeft  : 1)) / PDMAUDIO_VOLUME_MAX;
    1230 
    1231         VolCombined.uRight = (  (VolOut.uRight    ? VolOut.uRight    : 1)
    1232                               * (VolMaster.uRight ? VolMaster.uRight : 1)) / PDMAUDIO_VOLUME_MAX;
    1233     }
     1213    PDMAudioVolumeCombine(&VolCombined, &VolMaster, &VolOut);
    12341214
    12351215    int rc2 = AudioMixerSinkSetVolume(pThis->pSinkOut, &VolCombined);
  • trunk/src/VBox/Devices/Audio/testcase/tstAudioMixBuffer.cpp

    r89377 r89768  
    794794     * 1) Full volume/0dB attenuation (255).
    795795     */
    796     PDMAUDIOVOLUME Vol;
    797     Vol.fMuted = false;
    798     Vol.uLeft  = 255;
    799     Vol.uRight = 255;
     796    PDMAUDIOVOLUME Vol = PDMAUDIOVOLUME_INITIALIZER_MAX;
    800797    AudioMixBufSetVolume(&MixBuf, &Vol);
    801798
     
    826823     * 2) Half volume/-6dB attenuation (16 steps down).
    827824     */
    828     Vol.uLeft  = 255 - 16;
    829     Vol.uRight = 255 - 16;
     825    PDMAudioVolumeInitFromStereo(&Vol, false, 255 - 16, 255 - 16);
    830826    AudioMixBufSetVolume(&MixBuf, &Vol);
    831827
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