VirtualBox

Changeset 76879 in vbox for trunk/src/VBox/Devices/Audio


Ignore:
Timestamp:
Jan 18, 2019 10:17:25 AM (6 years ago)
Author:
vboxsync
Message:

Audio/DrvAudio: Added DrvAudioHlpBytesToMicro() and optimized DrvAudioHlpBytesToNano() + DrvAudioHlpBytesToMilli() calculations.

Location:
trunk/src/VBox/Devices/Audio
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Audio/DrvAudio.h

    r76857 r76879  
    189189uint32_t DrvAudioHlpBytesToFrames(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps);
    190190uint64_t DrvAudioHlpBytesToMilli(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps);
     191uint64_t DrvAudioHlpBytesToMicro(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps);
    191192uint64_t DrvAudioHlpBytesToNano(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps);
    192193uint32_t DrvAudioHlpFramesToBytes(uint32_t cFrames, const PPDMAUDIOPCMPROPS pProps);
  • trunk/src/VBox/Devices/Audio/DrvAudioCommon.cpp

    r76860 r76879  
    12381238 * @param   cbBytes             Amount of bytes to calculate time for.
    12391239 * @param   pProps              PCM properties to calculate amount of bytes for.
     1240 *
     1241 * @note    Does rounding up the result.
    12401242 */
    12411243uint64_t DrvAudioHlpBytesToMilli(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps)
     
    12431245    AssertPtrReturn(pProps, 0);
    12441246
    1245     if (!cbBytes)
    1246         return 0;
    1247 
    1248     const double dbBytesPerMs = (double)drvAudioHlpBytesPerSec(pProps) / (double)RT_MS_1SEC;
    1249     Assert(dbBytesPerMs >= 0.0f);
    1250     if (!dbBytesPerMs) /* Prevent division by zero. */
    1251         return 0;
    1252 
    1253     return (double)cbBytes / (double)dbBytesPerMs;
     1247    const unsigned cbFrame = PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */);
     1248
     1249    uint64_t uTimeMs = ((cbBytes + cbFrame - 1) / cbFrame) * RT_MS_1SEC;
     1250
     1251    return (uTimeMs + pProps->uHz - 1) / pProps->uHz;
     1252}
     1253
     1254/**
     1255 * Returns the time (in us) for given byte amount and PCM properties.
     1256 *
     1257 * @return  uint64_t            Calculated time (in us).
     1258 * @param   cbBytes             Amount of bytes to calculate time for.
     1259 * @param   pProps              PCM properties to calculate amount of bytes for.
     1260 *
     1261 * @note    Does rounding up the result.
     1262 */
     1263uint64_t DrvAudioHlpBytesToMicro(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps)
     1264{
     1265    AssertPtrReturn(pProps, 0);
     1266
     1267    const unsigned cbFrame = PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */);
     1268
     1269    uint64_t uTimeUs = ((cbBytes + cbFrame - 1) / cbFrame) * RT_US_1SEC;
     1270
     1271    return (uTimeUs + pProps->uHz - 1) / pProps->uHz;
    12541272}
    12551273
     
    12601278 * @param   cbBytes             Amount of bytes to calculate time for.
    12611279 * @param   pProps              PCM properties to calculate amount of bytes for.
     1280 *
     1281 * @note    Does rounding up the result.
    12621282 */
    12631283uint64_t DrvAudioHlpBytesToNano(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps)
     
    12651285    AssertPtrReturn(pProps, 0);
    12661286
    1267     if (!cbBytes)
    1268         return 0;
    1269 
    1270     const double dbBytesPerMs = (PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */) * pProps->uHz) / RT_NS_1SEC;
    1271     Assert(dbBytesPerMs >= 0.0f);
    1272     if (!dbBytesPerMs) /* Prevent division by zero. */
    1273         return 0;
    1274 
    1275     return cbBytes / dbBytesPerMs;
     1287    const unsigned cbFrame = PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */);
     1288
     1289    uint64_t uTimeNs = ((cbBytes + cbFrame - 1) / cbFrame) * RT_NS_1SEC;
     1290
     1291    return (uTimeNs + pProps->uHz - 1) / pProps->uHz;
    12761292}
    12771293
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