VirtualBox

Changeset 89416 in vbox for trunk


Ignore:
Timestamp:
May 31, 2021 8:56:37 PM (3 years ago)
Author:
vboxsync
Message:

pdmaudioinline.h: Added PDMAudioPropsBytesToNano64. bugref:9890

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/pdmaudioinline.h

    r89381 r89416  
    476476{
    477477    AssertPtrReturn(pProps, 0);
    478     uint32_t const cbFrame = PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */);
     478    uint32_t const cbFrame = PDMAudioPropsFrameSize(pProps);
    479479    AssertReturn(cbFrame, 0);
    480480    return PDMAUDIOPCMPROPS_F2B(pProps, PDMAUDIOPCMPROPS_B2F(pProps, cb + cbFrame - 1));
     
    491491{
    492492    AssertPtrReturn(pProps, false);
    493     uint32_t const cbFrame = PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */);
     493    uint32_t const cbFrame = PDMAudioPropsFrameSize(pProps);
    494494    AssertReturn(cbFrame, false);
    495495    return cb % cbFrame == 0;
     
    526526    if (uHz)
    527527    {
    528         const unsigned cbFrame = PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */);
     528        const unsigned cbFrame = PDMAudioPropsFrameSize(pProps);
    529529        if (cbFrame)
    530530        {
     
    556556    if (uHz)
    557557    {
    558         const unsigned cbFrame = PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */);
     558        const unsigned cbFrame = PDMAudioPropsFrameSize(pProps);
    559559        if (cbFrame)
    560560        {
     
    586586    if (uHz)
    587587    {
    588         const unsigned cbFrame = PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */);
     588        const unsigned cbFrame = PDMAudioPropsFrameSize(pProps);
    589589        if (cbFrame)
    590590        {
     
    594594            /* Convert to nanoseconds. */
    595595            return (cb * (uint64_t)RT_NS_1SEC + uHz - 1) / uHz;
     596        }
     597    }
     598    return 0;
     599}
     600
     601/**
     602 * Converts bytes to nanoseconds, 64-bit version.
     603 *
     604 * @return  Number nanoseconds @a cb takes to play or record.
     605 * @param   pProps      PCM properties to use.
     606 * @param   cb          The number of bytes to convert (64-bit).
     607 *
     608 * @note    Rounds up the result.
     609 */
     610DECLINLINE(uint64_t) PDMAudioPropsBytesToNano64(PCPDMAUDIOPCMPROPS pProps, uint64_t cb)
     611{
     612    AssertPtrReturn(pProps, 0);
     613
     614    /* Check parameters to prevent division by chainsaw: */
     615    uint32_t const uHz = pProps->uHz;
     616    if (uHz)
     617    {
     618        const unsigned cbFrame = PDMAudioPropsFrameSize(pProps);
     619        if (cbFrame)
     620        {
     621            /* Round cb up to closest frame size: */
     622            cb = (cb + cbFrame - 1) / cbFrame;
     623
     624            /* Convert to nanoseconds. */
     625            return (cb * RT_NS_1SEC + uHz - 1) / uHz;
    596626        }
    597627    }
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