VirtualBox

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


Ignore:
Timestamp:
May 27, 2021 11:33:04 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
144661
Message:

Audio: Reworking the capture (recording) code path, part 3: Apply volume in the device mixer rather than in DrvAudio. bugref:9890

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

Legend:

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

    r89305 r89314  
    491491 * thus don't do any bounds checking!
    492492 *
    493  * Note: Currently does not handle any endianness conversion yet!
     493 * @note Currently does not handle any endianness conversion yet!
    494494 */
    495495#define AUDMIXBUF_CONVERT(a_Name, a_Type, _aMin, _aMax, _aSigned, _aShift) \
     
    513513            return     (a_Type) ((iVal >> (32 - _aShift)) + ((_aMax >> 1) + 1)); \
    514514        } \
     515        AssertMsgFailed(("%RI64 (%#RX64)\n", iVal, iVal)); /* shouldn't be possible with current buffer operations */ \
    515516        return iVal >= 0 ? _aMax : _aMin; \
    516517    } \
     
    12041205 * @param   pVolSrc                 Volume to convert.
    12051206 */
    1206 static int audioMixBufConvVol(PAUDMIXBUFVOL pVolDst, PPDMAUDIOVOLUME pVolSrc)
     1207static int audioMixBufConvVol(PAUDMIXBUFVOL pVolDst, PCPDMAUDIOVOLUME pVolSrc)
    12071208{
    12081209    if (!pVolSrc->fMuted) /* Only change/convert the volume value if we're not muted. */
     
    28482849
    28492850/**
    2850  * Advances the write position of the buffer.
     2851 * Worker for audioMixAdjustVolume that adjust one contiguous chunk.
     2852 */
     2853static void audioMixAdjustVolumeWorker(PAUDIOMIXBUF pMixBuf, uint32_t off, uint32_t cFrames)
     2854{
     2855    PPDMAUDIOFRAME const    paFrames = pMixBuf->pFrames;
     2856    uint32_t const          uLeft    = pMixBuf->Volume.uLeft;
     2857    uint32_t const          uRight   = pMixBuf->Volume.uRight;
     2858    while (cFrames-- > 0)
     2859    {
     2860        paFrames[off].i64LSample = ASMMult2xS32RetS64(paFrames[off].i64LSample, uLeft)  >> AUDIOMIXBUF_VOL_SHIFT;
     2861        paFrames[off].i64RSample = ASMMult2xS32RetS64(paFrames[off].i64RSample, uRight) >> AUDIOMIXBUF_VOL_SHIFT;
     2862        off++;
     2863    }
     2864}
     2865
     2866
     2867/**
     2868 * Does volume adjustments for the given stretch of the buffer.
     2869 *
     2870 * @param   pMixBuf     The mixing buffer.
     2871 * @param   offFirst    Where to start (validated).
     2872 * @param   cFrames     How many frames (validated).
     2873 */
     2874static void audioMixAdjustVolume(PAUDIOMIXBUF pMixBuf, uint32_t offFirst, uint32_t cFrames)
     2875{
     2876    /* Caller has already validated these, so we don't need to repeat that in non-strict builds. */
     2877    Assert(offFirst < pMixBuf->cFrames);
     2878    Assert(cFrames <= pMixBuf->cFrames);
     2879
     2880    /*
     2881     * Muted?
     2882     */
     2883    if (pMixBuf->Volume.fMuted)
     2884    {
     2885        uint32_t const cFramesChunk1 = RT_MIN(pMixBuf->cFrames - offFirst, cFrames);
     2886        RT_BZERO(&pMixBuf->pFrames[offFirst], sizeof(pMixBuf->pFrames[0]) * cFramesChunk1);
     2887        if (cFramesChunk1 < cFrames)
     2888            RT_BZERO(&pMixBuf->pFrames[0], sizeof(pMixBuf->pFrames[0]) * (cFrames - cFramesChunk1));
     2889    }
     2890    /*
     2891     * Less than max volume?
     2892     */
     2893    else if (   pMixBuf->Volume.uLeft  != AUDIOMIXBUF_VOL_0DB
     2894             || pMixBuf->Volume.uRight != AUDIOMIXBUF_VOL_0DB)
     2895    {
     2896        /* first chunk */
     2897        uint32_t const cFramesChunk1 = RT_MIN(pMixBuf->cFrames - offFirst, cFrames);
     2898        audioMixAdjustVolumeWorker(pMixBuf, offFirst, cFramesChunk1);
     2899        if (cFramesChunk1 < cFrames)
     2900            audioMixAdjustVolumeWorker(pMixBuf, 0, cFrames - cFramesChunk1);
     2901    }
     2902}
     2903
     2904
     2905/**
     2906 * Adjust for volume settings and advances the write position of the buffer.
    28512907 *
    28522908 * For use after done peeking with AudioMixBufWrite(), AudioMixBufSilence(),
     
    28632919
    28642920    AssertStmt(cFrames <= pMixBuf->cFrames - pMixBuf->cUsed, cFrames = pMixBuf->cFrames - pMixBuf->cUsed);
     2921
     2922    audioMixAdjustVolume(pMixBuf, pMixBuf->offWrite, cFrames);
     2923
    28652924    pMixBuf->cUsed   += cFrames;
    28662925    pMixBuf->offWrite = (pMixBuf->offWrite + cFrames) % pMixBuf->cFrames;
     
    28752934 * @param   pVol                    Pointer to volume structure to set.
    28762935 */
    2877 void AudioMixBufSetVolume(PAUDIOMIXBUF pMixBuf, PPDMAUDIOVOLUME pVol)
     2936void AudioMixBufSetVolume(PAUDIOMIXBUF pMixBuf, PCPDMAUDIOVOLUME pVol)
    28782937{
    28792938    AssertPtrReturnVoid(pMixBuf);
     
    28822941    LogFlowFunc(("%s: lVol=%RU8, rVol=%RU8, fMuted=%RTbool\n", pMixBuf->pszName, pVol->uLeft, pVol->uRight, pVol->fMuted));
    28832942
    2884     int rc2 = audioMixBufConvVol(&pMixBuf->Volume /* Dest */, pVol /* Source */);
     2943    int rc2 = audioMixBufConvVol(&pMixBuf->Volume, pVol);
    28852944    AssertRC(rc2);
    28862945}
  • trunk/src/VBox/Devices/Audio/AudioMixBuffer.h

    r89302 r89314  
    329329uint32_t AudioMixBufReadPos(PAUDIOMIXBUF pMixBuf);
    330330void AudioMixBufReset(PAUDIOMIXBUF pMixBuf);
    331 void AudioMixBufSetVolume(PAUDIOMIXBUF pMixBuf, PPDMAUDIOVOLUME pVol);
     331void AudioMixBufSetVolume(PAUDIOMIXBUF pMixBuf, PCPDMAUDIOVOLUME pVol);
    332332uint32_t AudioMixBufSize(PAUDIOMIXBUF pMixBuf);
    333333uint32_t AudioMixBufSizeBytes(PAUDIOMIXBUF pMixBuf);
  • trunk/src/VBox/Devices/Audio/AudioMixer.cpp

    r89304 r89314  
    514514    {
    515515        audioMixerStreamCtlInternal(pStream, PDMAUDIOSTREAMCMD_ENABLE);
    516     }
    517 
    518     if (pSink->enmDir != PDMAUDIODIR_OUT)
    519     {
    520         /* Apply the sink's combined volume to the stream. */
    521         int rc2 = pStream->pConn->pfnStreamSetVolume(pStream->pConn, pStream->pStream, &pSink->VolumeCombined);
    522         AssertRC(rc2);
    523516    }
    524517
     
    25242517             pSink->VolumeCombined.fMuted, pSink->VolumeCombined.uLeft, pSink->VolumeCombined.uRight));
    25252518
    2526     /*
    2527      * Input sinks must currently propagate the new volume settings to
    2528      * all the streams.  (For output sinks we do the volume control here.)
    2529      */
    2530     if (pSink->enmDir != PDMAUDIODIR_OUT)
    2531     {
    2532         PAUDMIXSTREAM pMixStream;
    2533         RTListForEach(&pSink->lstStreams, pMixStream, AUDMIXSTREAM, Node)
    2534         {
    2535             int rc2 = pMixStream->pConn->pfnStreamSetVolume(pMixStream->pConn, pMixStream->pStream, &pSink->VolumeCombined);
    2536             AssertRC(rc2);
    2537         }
    2538     }
    2539 
     2519    AudioMixBufSetVolume(&pSink->MixBuf, &pSink->VolumeCombined);
    25402520    return VINF_SUCCESS;
    25412521}
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