Changeset 89529 in vbox
- Timestamp:
- Jun 6, 2021 11:59:10 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/AudioMixBuffer.cpp
r89448 r89529 1484 1484 int32_t ai32DstRate[1024]; 1485 1485 uint32_t cSrcFrames = RT_MIN(pMixBuf->cFrames - offSrcFrame, cMaxSrcFrames); 1486 uint32_t c MaxDstFrames = RT_MIN(RT_ELEMENTS(ai32DstRate) / pState->cSrcChannels, cbDst / pState->cbDstFrame);1487 uint32_t const cDstFrames = pState->Rate.pfnResample(ai32DstRate, c MaxDstFrames,1486 uint32_t cDstMaxFrames = RT_MIN(RT_ELEMENTS(ai32DstRate) / pState->cSrcChannels, cbDst / pState->cbDstFrame); 1487 uint32_t const cDstFrames = pState->Rate.pfnResample(ai32DstRate, cDstMaxFrames, 1488 1488 &pMixBuf->pi32Samples[offSrcFrame * pMixBuf->cChannels], 1489 1489 cSrcFrames, &cSrcFrames, &pState->Rate); … … 1576 1576 DECL_NO_INLINE(static, void) 1577 1577 audioMixBufWriteResampling(PAUDIOMIXBUF pMixBuf, PAUDIOMIXBUFWRITESTATE pState, const void *pvSrcBuf, uint32_t cbSrcBuf, 1578 uint32_t offDstFrame, uint32_t c MaxDstFrames, uint32_t *pcDstFramesWritten)1578 uint32_t offDstFrame, uint32_t cDstMaxFrames, uint32_t *pcDstFramesWritten) 1579 1579 { 1580 1580 *pcDstFramesWritten = 0; 1581 while (c MaxDstFrames > 0 && cbSrcBuf >= pState->cbSrcFrame)1581 while (cDstMaxFrames > 0 && cbSrcBuf >= pState->cbSrcFrame) 1582 1582 { 1583 1583 /* Decode into temporary buffer. */ 1584 int32_t ai32 SrcDecoded[1024];1585 uint32_t cFramesDecoded = RT_MIN(RT_ELEMENTS(ai32 SrcDecoded) / pState->cSrcChannels, cbSrcBuf / pState->cbSrcFrame);1586 pState->pfnDecode(ai32 SrcDecoded, 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); 1587 1587 cbSrcBuf -= cFramesDecoded * pState->cbSrcFrame; 1588 1588 pvSrcBuf = (uint8_t const *)pvSrcBuf + cFramesDecoded * pState->cbSrcFrame; … … 1592 1592 while (iFrameDecoded < cFramesDecoded) 1593 1593 { 1594 uint32_t cDstMaxFrames = RT_MIN(pMixBuf->cFrames - offDstFrame, cMaxDstFrames);1594 uint32_t cDstMaxFramesNow = RT_MIN(pMixBuf->cFrames - offDstFrame, cDstMaxFrames); 1595 1595 uint32_t cSrcFrames = cFramesDecoded - iFrameDecoded; 1596 1596 uint32_t const cDstFrames = pState->Rate.pfnResample(&pMixBuf->pi32Samples[offDstFrame * pMixBuf->cChannels], 1597 cDstMaxFrames ,1598 &ai32 SrcDecoded[iFrameDecoded * pState->cSrcChannels],1597 cDstMaxFramesNow, 1598 &ai32Decoded[iFrameDecoded * pState->cDstChannels], 1599 1599 cSrcFrames, &cSrcFrames, &pState->Rate); 1600 1600 … … 1620 1620 * @param offDstFrame Mixing buffer offset relative to the write 1621 1621 * position. 1622 * @param c MaxDstFrames Max number of frames to write.1622 * @param cDstMaxFrames Max number of frames to write. 1623 1623 * @param pcDstFramesWritten Where to return the number of frames actually 1624 1624 * written. … … 1628 1628 */ 1629 1629 void AudioMixBufWrite(PAUDIOMIXBUF pMixBuf, PAUDIOMIXBUFWRITESTATE pState, const void *pvSrcBuf, uint32_t cbSrcBuf, 1630 uint32_t offDstFrame, uint32_t c MaxDstFrames, uint32_t *pcDstFramesWritten)1630 uint32_t offDstFrame, uint32_t cDstMaxFrames, uint32_t *pcDstFramesWritten) 1631 1631 { 1632 1632 /* … … 1639 1639 AssertPtr(pState->pfnDecodeBlend); 1640 1640 Assert(pState->cDstChannels == PDMAudioPropsChannels(&pMixBuf->Props)); 1641 Assert(c MaxDstFrames > 0);1642 Assert(c MaxDstFrames <= pMixBuf->cFrames - pMixBuf->cUsed);1641 Assert(cDstMaxFrames > 0); 1642 Assert(cDstMaxFrames <= pMixBuf->cFrames - pMixBuf->cUsed); 1643 1643 Assert(offDstFrame <= pMixBuf->cFrames); 1644 1644 AssertPtr(pvSrcBuf); … … 1657 1657 { 1658 1658 /* Figure out how much we should convert. */ 1659 Assert(c MaxDstFrames >= cbSrcBuf / pState->cbSrcFrame);1660 c MaxDstFrames = RT_MIN(cMaxDstFrames, cbSrcBuf / pState->cbSrcFrame);1661 *pcDstFramesWritten = c MaxDstFrames;1662 1663 //Log10Func(("cbSrc=%#x\n%32.*Rhxd\n", pState->cbSrcFrame * c MaxDstFrames, 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)); 1664 1664 1665 1665 /* First chunk. */ 1666 uint32_t const cDstFrames1 = RT_MIN(pMixBuf->cFrames - offDstFrame, c MaxDstFrames);1666 uint32_t const cDstFrames1 = RT_MIN(pMixBuf->cFrames - offDstFrame, cDstMaxFrames); 1667 1667 pState->pfnDecode(&pMixBuf->pi32Samples[offDstFrame * pMixBuf->cChannels], pvSrcBuf, cDstFrames1, pState); 1668 1668 //Log8Func(("offDstFrame=%#x cDstFrames1=%#x\n%32.*Rhxd\n", offDstFrame, cDstFrames1, … … 1670 1670 1671 1671 /* Another chunk from the start of the mixing buffer? */ 1672 if (c MaxDstFrames > cDstFrames1)1672 if (cDstMaxFrames > cDstFrames1) 1673 1673 { 1674 1674 pState->pfnDecode(&pMixBuf->pi32Samples[0], (uint8_t *)pvSrcBuf + cDstFrames1 * pState->cbSrcFrame, 1675 c MaxDstFrames - cDstFrames1, pState);1676 //Log8Func(("cDstFrames2=%#x\n%32.*Rhxd\n", c MaxDstFrames - cDstFrames1,1677 // (c MaxDstFrames - 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])); 1678 1678 } 1679 1679 } 1680 1680 else 1681 audioMixBufWriteResampling(pMixBuf, pState, pvSrcBuf, cbSrcBuf, offDstFrame, c MaxDstFrames, pcDstFramesWritten);1681 audioMixBufWriteResampling(pMixBuf, pState, pvSrcBuf, cbSrcBuf, offDstFrame, cDstMaxFrames, pcDstFramesWritten); 1682 1682 } 1683 1683 … … 1688 1688 DECL_NO_INLINE(static, void) 1689 1689 audioMixBufBlendResampling(PAUDIOMIXBUF pMixBuf, PAUDIOMIXBUFWRITESTATE pState, const void *pvSrcBuf, uint32_t cbSrcBuf, 1690 uint32_t offDstFrame, uint32_t c MaxDstFrames, uint32_t *pcDstFramesBlended)1690 uint32_t offDstFrame, uint32_t cDstMaxFrames, uint32_t *pcDstFramesBlended) 1691 1691 { 1692 1692 *pcDstFramesBlended = 0; 1693 while (c MaxDstFrames > 0 && cbSrcBuf >= pState->cbSrcFrame)1694 { 1695 /* Decode into temporary buffer. */1696 int32_t ai32 SrcDecoded[1024];1697 uint32_t cFramesDecoded = RT_MIN(RT_ELEMENTS(ai32 SrcDecoded) / pState->cSrcChannels, cbSrcBuf / pState->cbSrcFrame);1698 pState->pfnDecode(ai32 SrcDecoded, 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); 1699 1699 cbSrcBuf -= cFramesDecoded * pState->cbSrcFrame; 1700 1700 pvSrcBuf = (uint8_t const *)pvSrcBuf + cFramesDecoded * pState->cbSrcFrame; … … 1704 1704 while (iFrameDecoded < cFramesDecoded) 1705 1705 { 1706 int32_t ai32 SrcRate[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); 1708 1708 uint32_t cSrcFrames = cFramesDecoded - iFrameDecoded; 1709 uint32_t const cDstFrames = pState->Rate.pfnResample(&ai32 SrcRate[0], cDstMaxFrames,1710 &ai32 SrcDecoded[iFrameDecoded * pState->cSrcChannels],1709 uint32_t const cDstFrames = pState->Rate.pfnResample(&ai32Rate[0], cDstMaxFramesNow, 1710 &ai32Decoded[iFrameDecoded * pState->cDstChannels], 1711 1711 cSrcFrames, &cSrcFrames, &pState->Rate); 1712 1712 … … 1714 1714 uint32_t const cDstFrames1 = RT_MIN(pMixBuf->cFrames - offDstFrame, cDstFrames); 1715 1715 audioMixBufBlendBuffer(&pMixBuf->pi32Samples[offDstFrame * pMixBuf->cChannels], 1716 ai32 SrcRate, cDstFrames1, pState->cSrcChannels);1716 ai32Rate, cDstFrames1, pState->cDstChannels); 1717 1717 1718 1718 /* Another chunk from the start of the mixing buffer? */ 1719 1719 if (cDstFrames > cDstFrames1) 1720 audioMixBufBlendBuffer(&pMixBuf->pi32Samples[0], &ai32 SrcRate[cDstFrames1 * pState->cSrcChannels],1721 cDstFrames - cDstFrames1, pState->c SrcChannels);1720 audioMixBufBlendBuffer(&pMixBuf->pi32Samples[0], &ai32Rate[cDstFrames1 * pState->cDstChannels], 1721 cDstFrames - cDstFrames1, pState->cDstChannels); 1722 1722 1723 1723 /* Advance */ … … 1737 1737 */ 1738 1738 void AudioMixBufBlend(PAUDIOMIXBUF pMixBuf, PAUDIOMIXBUFWRITESTATE pState, const void *pvSrcBuf, uint32_t cbSrcBuf, 1739 uint32_t offDstFrame, uint32_t c MaxDstFrames, uint32_t *pcDstFramesBlended)1739 uint32_t offDstFrame, uint32_t cDstMaxFrames, uint32_t *pcDstFramesBlended) 1740 1740 { 1741 1741 /* … … 1748 1748 AssertPtr(pState->pfnDecodeBlend); 1749 1749 Assert(pState->cDstChannels == PDMAudioPropsChannels(&pMixBuf->Props)); 1750 Assert(c MaxDstFrames > 0);1751 Assert(c MaxDstFrames <= pMixBuf->cFrames - pMixBuf->cUsed);1750 Assert(cDstMaxFrames > 0); 1751 Assert(cDstMaxFrames <= pMixBuf->cFrames - pMixBuf->cUsed); 1752 1752 Assert(offDstFrame <= pMixBuf->cFrames); 1753 1753 AssertPtr(pvSrcBuf); … … 1766 1766 { 1767 1767 /* Figure out how much we should convert. */ 1768 Assert(c MaxDstFrames >= cbSrcBuf / pState->cbSrcFrame);1769 c MaxDstFrames = RT_MIN(cMaxDstFrames, cbSrcBuf / pState->cbSrcFrame);1770 *pcDstFramesBlended = c MaxDstFrames;1768 Assert(cDstMaxFrames >= cbSrcBuf / pState->cbSrcFrame); 1769 cDstMaxFrames = RT_MIN(cDstMaxFrames, cbSrcBuf / pState->cbSrcFrame); 1770 *pcDstFramesBlended = cDstMaxFrames; 1771 1771 1772 1772 /* First chunk. */ 1773 uint32_t const cDstFrames1 = RT_MIN(pMixBuf->cFrames - offDstFrame, c MaxDstFrames);1773 uint32_t const cDstFrames1 = RT_MIN(pMixBuf->cFrames - offDstFrame, cDstMaxFrames); 1774 1774 pState->pfnDecodeBlend(&pMixBuf->pi32Samples[offDstFrame * pMixBuf->cChannels], pvSrcBuf, cDstFrames1, pState); 1775 1775 1776 1776 /* Another chunk from the start of the mixing buffer? */ 1777 if (c MaxDstFrames > cDstFrames1)1777 if (cDstMaxFrames > cDstFrames1) 1778 1778 pState->pfnDecodeBlend(&pMixBuf->pi32Samples[0], (uint8_t *)pvSrcBuf + cDstFrames1 * pState->cbSrcFrame, 1779 c MaxDstFrames - cDstFrames1, pState);1779 cDstMaxFrames - cDstFrames1, pState); 1780 1780 } 1781 1781 else 1782 audioMixBufBlendResampling(pMixBuf, pState, pvSrcBuf, cbSrcBuf, offDstFrame, c MaxDstFrames, pcDstFramesBlended);1782 audioMixBufBlendResampling(pMixBuf, pState, pvSrcBuf, cbSrcBuf, offDstFrame, cDstMaxFrames, pcDstFramesBlended); 1783 1783 } 1784 1784
Note:
See TracChangeset
for help on using the changeset viewer.