VirtualBox

Changeset 73058 in vbox for trunk


Ignore:
Timestamp:
Jul 11, 2018 10:12:55 AM (7 years ago)
Author:
vboxsync
Message:

Audio: Added DrvAudioHlpFramesToMs() and DrvAudioHlpMsToFrames() helpers.

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

Legend:

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

    r71113 r73058  
    155155uint32_t DrvAudioHlpCalcBitrate(const PPDMAUDIOPCMPROPS pProps);
    156156uint64_t DrvAudioHlpBytesToMs(const PPDMAUDIOPCMPROPS pProps, size_t cbBytes);
     157float DrvAudioHlpFramesToMs(const PPDMAUDIOPCMPROPS pProps, size_t cFrames);
    157158uint32_t DrvAudioHlpMsToBytes(const PPDMAUDIOPCMPROPS pProps, uint32_t uMs);
     159uint32_t DrvAudioHlpMsToFrames(const PPDMAUDIOPCMPROPS pProps, uint32_t uMs);
    158160bool DrvAudioHlpPCMPropsAreEqual(const PPDMAUDIOPCMPROPS pPCMProps1, const PPDMAUDIOPCMPROPS pPCMProps2);
    159161bool DrvAudioHlpPCMPropsAreEqual(const PPDMAUDIOPCMPROPS pPCMProps, const PPDMAUDIOSTREAMCFG pCfg);
  • trunk/src/VBox/Devices/Audio/DrvAudioCommon.cpp

    r72111 r73058  
    10751075
    10761076/**
     1077 * Returns the time (in ms) for given audio frames amount and PCM properties.
     1078 *
     1079 * @return  float               Calculated time (in ms).
     1080 * @param   pProps              PCM properties to calculate time (in ms) for.
     1081 * @param   cFrames             Amount of audio frames to calculate time for.
     1082 */
     1083float DrvAudioHlpFramesToMs(const PPDMAUDIOPCMPROPS pProps, size_t cFrames)
     1084{
     1085    AssertPtrReturn(pProps, 0);
     1086
     1087    if (!cFrames)
     1088        return 0;
     1089
     1090    if (!pProps->uHz) /* Prevent division by zero. */
     1091        return 0;
     1092
     1093    return float(cFrames / (pProps->uHz / 1000 /* ms */));
     1094}
     1095
     1096/**
    10771097 * Returns the amount of bytes for a given time (in ms) and PCM properties.
    10781098 *
     
    10891109
    10901110    return float(((pProps->cBits / 8) * pProps->cChannels * pProps->uHz) / 1000) * uMs;
     1111}
     1112
     1113/**
     1114 * Returns the amount of audio for a given time (in ms) and PCM properties.
     1115 *
     1116 * @return  uint32_t            Calculated amount of audio frames.
     1117 * @param   pProps              PCM properties to calculate amount of bytes for.
     1118 * @param   uMs                 Time (in ms) to calculate amount of bytes for.
     1119 */
     1120uint32_t DrvAudioHlpMsToFrames(const PPDMAUDIOPCMPROPS pProps, uint32_t uMs)
     1121{
     1122    AssertPtrReturn(pProps, 0);
     1123
     1124    const size_t cbFrame = (pProps->cBits / 8) * pProps->cChannels;
     1125    if (!cbFrame) /* Prevent division by zero. */
     1126        return 0;
     1127
     1128    return DrvAudioHlpMsToBytes(pProps, uMs) / cbFrame;
    10911129}
    10921130
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