VirtualBox

Changeset 89326 in vbox for trunk/include/VBox/vmm


Ignore:
Timestamp:
May 28, 2021 12:17:20 AM (4 years ago)
Author:
vboxsync
Message:

pdmaudioinline.h: PDMAudioPropsNanoToBytes64 and PDMAudioPropsNanoToFrames64 for use on bigger values without risk of overflowing any time soon (the original routines works with 32-bit values). bugref:9890

File:
1 edited

Legend:

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

    r89301 r89326  
    683683 * Converts nanoseconds to frames.
    684684 *
    685  * @returns Number of frames
     685 * @returns Number of frames.
    686686 * @param   pProps      The PCM properties to use.
    687687 * @param   cNs         The number of nanoseconds to convert.
     
    707707
    708708/**
     709 * Converts nanoseconds to frames, 64-bit return.
     710 *
     711 * @returns Number of frames (64-bit).
     712 * @param   pProps      The PCM properties to use.
     713 * @param   cNs         The number of nanoseconds to convert.
     714 *
     715 * @note    The result is floored!
     716 */
     717DECLINLINE(uint64_t) PDMAudioPropsNanoToFrames64(PCPDMAUDIOPCMPROPS pProps, uint64_t cNs)
     718{
     719    AssertPtrReturn(pProps, 0);
     720
     721    uint32_t const uHz = pProps->uHz;
     722    uint64_t cFrames;
     723    if (cNs < RT_NS_1SEC)
     724        cFrames = 0;
     725    else
     726    {
     727        cFrames = cNs / RT_NS_1SEC * uHz;
     728        cNs %= RT_NS_1SEC;
     729    }
     730    cFrames += ASMMult2xU32RetU64(uHz, (uint32_t)cNs) / RT_NS_1SEC;
     731    return cFrames;
     732}
     733
     734/**
    709735 * Converts nanoseconds to bytes.
    710736 *
     
    716742 */
    717743DECLINLINE(uint32_t) PDMAudioPropsNanoToBytes(PCPDMAUDIOPCMPROPS pProps, uint64_t cNs)
     744{
     745    return PDMAUDIOPCMPROPS_F2B(pProps, PDMAudioPropsNanoToFrames(pProps, cNs));
     746}
     747
     748/**
     749 * Converts nanoseconds to bytes, 64-bit version.
     750 *
     751 * @returns Number of bytes (frame aligned), 64-bit.
     752 * @param   pProps      The PCM properties to use.
     753 * @param   cNs         The number of nanoseconds to convert.
     754 *
     755 * @note    The result is floored.
     756 */
     757DECLINLINE(uint64_t) PDMAudioPropsNanoToBytes64(PCPDMAUDIOPCMPROPS pProps, uint64_t cNs)
    718758{
    719759    return PDMAUDIOPCMPROPS_F2B(pProps, PDMAudioPropsNanoToFrames(pProps, cNs));
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