VirtualBox

Changeset 76679 in vbox


Ignore:
Timestamp:
Jan 7, 2019 1:50:26 PM (6 years ago)
Author:
vboxsync
Message:

Audio/Common: DrvAudioHlpMilliToBytes() / DrvAudioHlpNanoToBytes(): Make sure to always return an audio-frame-aligned value.

File:
1 edited

Legend:

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

    r76553 r76679  
    13201320 * Returns the amount of bytes for a given time (in ms) and PCM properties.
    13211321 *
     1322 * Note: The result will return an amount of bytes which is aligned to the audio frame size.
     1323 *
    13221324 * @return  uint32_t            Calculated amount of bytes.
    13231325 * @param   uMs                 Time (in ms) to calculate amount of bytes for.
     
    13311333        return 0;
    13321334
    1333     return ((double)drvAudioHlpBytesPerSec(pProps) / (double)RT_MS_1SEC) * uMs;
     1335    const uint32_t uBytesPerFrame = DrvAudioHlpPCMPropsBytesPerFrame(pProps);
     1336
     1337    uint32_t uBytes = ((double)drvAudioHlpBytesPerSec(pProps) / (double)RT_MS_1SEC) * uMs;
     1338    if (uBytes % uBytesPerFrame) /* Any remainder? Make the returned bytes an integral number to the given frames. */
     1339        uBytes = uBytes + (uBytesPerFrame - uBytes % uBytesPerFrame);
     1340
     1341    Assert(uBytes % uBytesPerFrame == 0); /* Paranoia. */
     1342
     1343    return uBytes;
    13341344}
    13351345
    13361346/**
    13371347 * Returns the amount of bytes for a given time (in ns) and PCM properties.
     1348 *
     1349 * Note: The result will return an amount of bytes which is aligned to the audio frame size.
    13381350 *
    13391351 * @return  uint32_t            Calculated amount of bytes.
     
    13481360        return 0;
    13491361
    1350     return ((double)drvAudioHlpBytesPerSec(pProps) / (double)RT_NS_1SEC) * uNs;
     1362    const uint32_t uBytesPerFrame = DrvAudioHlpPCMPropsBytesPerFrame(pProps);
     1363
     1364    uint32_t uBytes = ((double)drvAudioHlpBytesPerSec(pProps) / (double)RT_NS_1SEC) * uNs;
     1365    if (uBytes % uBytesPerFrame) /* Any remainder? Make the returned bytes an integral number to the given frames. */
     1366        uBytes = uBytes + (uBytesPerFrame - uBytes % uBytesPerFrame);
     1367
     1368    Assert(uBytes % uBytesPerFrame == 0); /* Paranoia. */
     1369
     1370    return uBytes;
    13511371}
    13521372
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