VirtualBox

Changeset 89529 in vbox


Ignore:
Timestamp:
Jun 6, 2021 11:59:10 PM (3 years ago)
Author:
vboxsync
Message:

AudioMixBuffer: Corrected a couple of frame calculations in the write/blend resampling paths. bugref:9890

File:
1 edited

Legend:

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

    r89448 r89529  
    14841484        int32_t  ai32DstRate[1024];
    14851485        uint32_t cSrcFrames    = RT_MIN(pMixBuf->cFrames - offSrcFrame, cMaxSrcFrames);
    1486         uint32_t cMaxDstFrames = RT_MIN(RT_ELEMENTS(ai32DstRate) / pState->cSrcChannels, cbDst / pState->cbDstFrame);
    1487         uint32_t const cDstFrames = pState->Rate.pfnResample(ai32DstRate, cMaxDstFrames,
     1486        uint32_t cDstMaxFrames = RT_MIN(RT_ELEMENTS(ai32DstRate) / pState->cSrcChannels, cbDst / pState->cbDstFrame);
     1487        uint32_t const cDstFrames = pState->Rate.pfnResample(ai32DstRate, cDstMaxFrames,
    14881488                                                             &pMixBuf->pi32Samples[offSrcFrame * pMixBuf->cChannels],
    14891489                                                             cSrcFrames, &cSrcFrames, &pState->Rate);
     
    15761576DECL_NO_INLINE(static, void)
    15771577audioMixBufWriteResampling(PAUDIOMIXBUF pMixBuf, PAUDIOMIXBUFWRITESTATE pState, const void *pvSrcBuf, uint32_t cbSrcBuf,
    1578                            uint32_t offDstFrame, uint32_t cMaxDstFrames, uint32_t *pcDstFramesWritten)
     1578                           uint32_t offDstFrame, uint32_t cDstMaxFrames, uint32_t *pcDstFramesWritten)
    15791579{
    15801580    *pcDstFramesWritten = 0;
    1581     while (cMaxDstFrames > 0 && cbSrcBuf >= pState->cbSrcFrame)
     1581    while (cDstMaxFrames > 0 && cbSrcBuf >= pState->cbSrcFrame)
    15821582    {
    15831583        /* Decode into temporary buffer. */
    1584         int32_t  ai32SrcDecoded[1024];
    1585         uint32_t cFramesDecoded = RT_MIN(RT_ELEMENTS(ai32SrcDecoded) / pState->cSrcChannels, cbSrcBuf / pState->cbSrcFrame);
    1586         pState->pfnDecode(ai32SrcDecoded, pvSrcBuf, cFramesDecoded, pState);
     1584        int32_t  ai32Decoded[1024];
     1585        uint32_t cFramesDecoded = RT_MIN(RT_ELEMENTS(ai32Decoded) / pState->cDstChannels, cbSrcBuf / pState->cbSrcFrame);
     1586        pState->pfnDecode(ai32Decoded, pvSrcBuf, cFramesDecoded, pState);
    15871587        cbSrcBuf -= cFramesDecoded * pState->cbSrcFrame;
    15881588        pvSrcBuf  = (uint8_t const *)pvSrcBuf + cFramesDecoded * pState->cbSrcFrame;
     
    15921592        while (iFrameDecoded < cFramesDecoded)
    15931593        {
    1594             uint32_t cDstMaxFrames    = RT_MIN(pMixBuf->cFrames - offDstFrame, cMaxDstFrames);
     1594            uint32_t cDstMaxFramesNow = RT_MIN(pMixBuf->cFrames - offDstFrame, cDstMaxFrames);
    15951595            uint32_t cSrcFrames       = cFramesDecoded - iFrameDecoded;
    15961596            uint32_t const cDstFrames = pState->Rate.pfnResample(&pMixBuf->pi32Samples[offDstFrame * pMixBuf->cChannels],
    1597                                                                  cDstMaxFrames,
    1598                                                                  &ai32SrcDecoded[iFrameDecoded * pState->cSrcChannels],
     1597                                                                 cDstMaxFramesNow,
     1598                                                                 &ai32Decoded[iFrameDecoded * pState->cDstChannels],
    15991599                                                                 cSrcFrames, &cSrcFrames, &pState->Rate);
    16001600
     
    16201620 * @param   offDstFrame         Mixing buffer offset relative to the write
    16211621 *                              position.
    1622  * @param   cMaxDstFrames       Max number of frames to write.
     1622 * @param   cDstMaxFrames       Max number of frames to write.
    16231623 * @param   pcDstFramesWritten  Where to return the number of frames actually
    16241624 *                              written.
     
    16281628 */
    16291629void AudioMixBufWrite(PAUDIOMIXBUF pMixBuf, PAUDIOMIXBUFWRITESTATE pState, const void *pvSrcBuf, uint32_t cbSrcBuf,
    1630                       uint32_t offDstFrame, uint32_t cMaxDstFrames, uint32_t *pcDstFramesWritten)
     1630                      uint32_t offDstFrame, uint32_t cDstMaxFrames, uint32_t *pcDstFramesWritten)
    16311631{
    16321632    /*
     
    16391639    AssertPtr(pState->pfnDecodeBlend);
    16401640    Assert(pState->cDstChannels == PDMAudioPropsChannels(&pMixBuf->Props));
    1641     Assert(cMaxDstFrames > 0);
    1642     Assert(cMaxDstFrames <= pMixBuf->cFrames - pMixBuf->cUsed);
     1641    Assert(cDstMaxFrames > 0);
     1642    Assert(cDstMaxFrames <= pMixBuf->cFrames - pMixBuf->cUsed);
    16431643    Assert(offDstFrame <= pMixBuf->cFrames);
    16441644    AssertPtr(pvSrcBuf);
     
    16571657    {
    16581658        /* Figure out how much we should convert. */
    1659         Assert(cMaxDstFrames >= cbSrcBuf / pState->cbSrcFrame);
    1660         cMaxDstFrames       = RT_MIN(cMaxDstFrames, cbSrcBuf / pState->cbSrcFrame);
    1661         *pcDstFramesWritten = cMaxDstFrames;
    1662 
    1663         //Log10Func(("cbSrc=%#x\n%32.*Rhxd\n", pState->cbSrcFrame * cMaxDstFrames, pState->cbSrcFrame * cMaxDstFrames, pvSrcBuf));
     1659        Assert(cDstMaxFrames >= cbSrcBuf / pState->cbSrcFrame);
     1660        cDstMaxFrames       = RT_MIN(cDstMaxFrames, cbSrcBuf / pState->cbSrcFrame);
     1661        *pcDstFramesWritten = cDstMaxFrames;
     1662
     1663        //Log10Func(("cbSrc=%#x\n%32.*Rhxd\n", pState->cbSrcFrame * cDstMaxFrames, pState->cbSrcFrame * cDstMaxFrames, pvSrcBuf));
    16641664
    16651665        /* First chunk. */
    1666         uint32_t const cDstFrames1 = RT_MIN(pMixBuf->cFrames - offDstFrame, cMaxDstFrames);
     1666        uint32_t const cDstFrames1 = RT_MIN(pMixBuf->cFrames - offDstFrame, cDstMaxFrames);
    16671667        pState->pfnDecode(&pMixBuf->pi32Samples[offDstFrame * pMixBuf->cChannels], pvSrcBuf, cDstFrames1, pState);
    16681668        //Log8Func(("offDstFrame=%#x cDstFrames1=%#x\n%32.*Rhxd\n", offDstFrame, cDstFrames1,
     
    16701670
    16711671        /* Another chunk from the start of the mixing buffer? */
    1672         if (cMaxDstFrames > cDstFrames1)
     1672        if (cDstMaxFrames > cDstFrames1)
    16731673        {
    16741674            pState->pfnDecode(&pMixBuf->pi32Samples[0], (uint8_t *)pvSrcBuf + cDstFrames1 * pState->cbSrcFrame,
    1675                               cMaxDstFrames - cDstFrames1, pState);
    1676             //Log8Func(("cDstFrames2=%#x\n%32.*Rhxd\n", cMaxDstFrames - cDstFrames1,
    1677             //          (cMaxDstFrames - cDstFrames1) * pMixBuf->cbFrame, &pMixBuf->pi32Samples[0]));
     1675                              cDstMaxFrames - cDstFrames1, pState);
     1676            //Log8Func(("cDstFrames2=%#x\n%32.*Rhxd\n", cDstMaxFrames - cDstFrames1,
     1677            //          (cDstMaxFrames - cDstFrames1) * pMixBuf->cbFrame, &pMixBuf->pi32Samples[0]));
    16781678        }
    16791679    }
    16801680    else
    1681         audioMixBufWriteResampling(pMixBuf, pState, pvSrcBuf, cbSrcBuf, offDstFrame, cMaxDstFrames, pcDstFramesWritten);
     1681        audioMixBufWriteResampling(pMixBuf, pState, pvSrcBuf, cbSrcBuf, offDstFrame, cDstMaxFrames, pcDstFramesWritten);
    16821682}
    16831683
     
    16881688DECL_NO_INLINE(static, void)
    16891689audioMixBufBlendResampling(PAUDIOMIXBUF pMixBuf, PAUDIOMIXBUFWRITESTATE pState, const void *pvSrcBuf, uint32_t cbSrcBuf,
    1690                            uint32_t offDstFrame, uint32_t cMaxDstFrames, uint32_t *pcDstFramesBlended)
     1690                           uint32_t offDstFrame, uint32_t cDstMaxFrames, uint32_t *pcDstFramesBlended)
    16911691{
    16921692    *pcDstFramesBlended = 0;
    1693     while (cMaxDstFrames > 0 && cbSrcBuf >= pState->cbSrcFrame)
    1694     {
    1695         /* Decode into temporary buffer. */
    1696         int32_t  ai32SrcDecoded[1024];
    1697         uint32_t cFramesDecoded = RT_MIN(RT_ELEMENTS(ai32SrcDecoded) / pState->cSrcChannels, cbSrcBuf / pState->cbSrcFrame);
    1698         pState->pfnDecode(ai32SrcDecoded, pvSrcBuf, cFramesDecoded, pState);
     1693    while (cDstMaxFrames > 0 && cbSrcBuf >= pState->cbSrcFrame)
     1694    {
     1695        /* Decode into temporary buffer.  This then has the destination channel count. */
     1696        int32_t  ai32Decoded[1024];
     1697        uint32_t cFramesDecoded = RT_MIN(RT_ELEMENTS(ai32Decoded) / pState->cDstChannels, cbSrcBuf / pState->cbSrcFrame);
     1698        pState->pfnDecode(ai32Decoded, pvSrcBuf, cFramesDecoded, pState);
    16991699        cbSrcBuf -= cFramesDecoded * pState->cbSrcFrame;
    17001700        pvSrcBuf  = (uint8_t const *)pvSrcBuf + cFramesDecoded * pState->cbSrcFrame;
     
    17041704        while (iFrameDecoded < cFramesDecoded)
    17051705        {
    1706             int32_t  ai32SrcRate[1024];
    1707             uint32_t cDstMaxFrames    = RT_MIN(RT_ELEMENTS(ai32SrcRate), cMaxDstFrames);
     1706            int32_t  ai32Rate[1024];
     1707            uint32_t cDstMaxFramesNow = RT_MIN(RT_ELEMENTS(ai32Rate) / pState->cDstChannels, cDstMaxFrames);
    17081708            uint32_t cSrcFrames       = cFramesDecoded - iFrameDecoded;
    1709             uint32_t const cDstFrames = pState->Rate.pfnResample(&ai32SrcRate[0], cDstMaxFrames,
    1710                                                                  &ai32SrcDecoded[iFrameDecoded * pState->cSrcChannels],
     1709            uint32_t const cDstFrames = pState->Rate.pfnResample(&ai32Rate[0], cDstMaxFramesNow,
     1710                                                                 &ai32Decoded[iFrameDecoded * pState->cDstChannels],
    17111711                                                                 cSrcFrames, &cSrcFrames, &pState->Rate);
    17121712
     
    17141714            uint32_t const cDstFrames1 = RT_MIN(pMixBuf->cFrames - offDstFrame, cDstFrames);
    17151715            audioMixBufBlendBuffer(&pMixBuf->pi32Samples[offDstFrame * pMixBuf->cChannels],
    1716                                    ai32SrcRate, cDstFrames1, pState->cSrcChannels);
     1716                                   ai32Rate, cDstFrames1, pState->cDstChannels);
    17171717
    17181718            /* Another chunk from the start of the mixing buffer? */
    17191719            if (cDstFrames > cDstFrames1)
    1720                 audioMixBufBlendBuffer(&pMixBuf->pi32Samples[0], &ai32SrcRate[cDstFrames1 * pState->cSrcChannels],
    1721                                        cDstFrames - cDstFrames1, pState->cSrcChannels);
     1720                audioMixBufBlendBuffer(&pMixBuf->pi32Samples[0], &ai32Rate[cDstFrames1 * pState->cDstChannels],
     1721                                       cDstFrames - cDstFrames1, pState->cDstChannels);
    17221722
    17231723            /* Advance */
     
    17371737 */
    17381738void AudioMixBufBlend(PAUDIOMIXBUF pMixBuf, PAUDIOMIXBUFWRITESTATE pState, const void *pvSrcBuf, uint32_t cbSrcBuf,
    1739                       uint32_t offDstFrame, uint32_t cMaxDstFrames, uint32_t *pcDstFramesBlended)
     1739                      uint32_t offDstFrame, uint32_t cDstMaxFrames, uint32_t *pcDstFramesBlended)
    17401740{
    17411741    /*
     
    17481748    AssertPtr(pState->pfnDecodeBlend);
    17491749    Assert(pState->cDstChannels == PDMAudioPropsChannels(&pMixBuf->Props));
    1750     Assert(cMaxDstFrames > 0);
    1751     Assert(cMaxDstFrames <= pMixBuf->cFrames - pMixBuf->cUsed);
     1750    Assert(cDstMaxFrames > 0);
     1751    Assert(cDstMaxFrames <= pMixBuf->cFrames - pMixBuf->cUsed);
    17521752    Assert(offDstFrame <= pMixBuf->cFrames);
    17531753    AssertPtr(pvSrcBuf);
     
    17661766    {
    17671767        /* Figure out how much we should convert. */
    1768         Assert(cMaxDstFrames >= cbSrcBuf / pState->cbSrcFrame);
    1769         cMaxDstFrames       = RT_MIN(cMaxDstFrames, cbSrcBuf / pState->cbSrcFrame);
    1770         *pcDstFramesBlended = cMaxDstFrames;
     1768        Assert(cDstMaxFrames >= cbSrcBuf / pState->cbSrcFrame);
     1769        cDstMaxFrames       = RT_MIN(cDstMaxFrames, cbSrcBuf / pState->cbSrcFrame);
     1770        *pcDstFramesBlended = cDstMaxFrames;
    17711771
    17721772        /* First chunk. */
    1773         uint32_t const cDstFrames1 = RT_MIN(pMixBuf->cFrames - offDstFrame, cMaxDstFrames);
     1773        uint32_t const cDstFrames1 = RT_MIN(pMixBuf->cFrames - offDstFrame, cDstMaxFrames);
    17741774        pState->pfnDecodeBlend(&pMixBuf->pi32Samples[offDstFrame * pMixBuf->cChannels], pvSrcBuf, cDstFrames1, pState);
    17751775
    17761776        /* Another chunk from the start of the mixing buffer? */
    1777         if (cMaxDstFrames > cDstFrames1)
     1777        if (cDstMaxFrames > cDstFrames1)
    17781778            pState->pfnDecodeBlend(&pMixBuf->pi32Samples[0], (uint8_t *)pvSrcBuf + cDstFrames1 * pState->cbSrcFrame,
    1779                                    cMaxDstFrames - cDstFrames1, pState);
     1779                                   cDstMaxFrames - cDstFrames1, pState);
    17801780    }
    17811781    else
    1782         audioMixBufBlendResampling(pMixBuf, pState, pvSrcBuf, cbSrcBuf, offDstFrame, cMaxDstFrames, pcDstFramesBlended);
     1782        audioMixBufBlendResampling(pMixBuf, pState, pvSrcBuf, cbSrcBuf, offDstFrame, cDstMaxFrames, pcDstFramesBlended);
    17831783}
    17841784
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