VirtualBox

Changeset 73379 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Jul 27, 2018 9:03:35 AM (6 years ago)
Author:
vboxsync
Message:

Audio/DrvAudioCommon.cpp: Implemented DrvAudioHlpBytesAlign() and DrvAudioHlpBytesIsAligned().

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

Legend:

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

    r73370 r73379  
    184184uint32_t DrvAudioHlpCalcBitrate(uint8_t cBits, uint32_t uHz, uint8_t cChannels);
    185185uint32_t DrvAudioHlpCalcBitrate(const PPDMAUDIOPCMPROPS pProps);
     186uint32_t DrvAudioHlpBytesAlign(uint32_t cbSize, const PPDMAUDIOPCMPROPS pProps);
     187bool     DrvAudioHlpBytesIsAligned(uint32_t cbSize, const PPDMAUDIOPCMPROPS pProps);
    186188uint32_t DrvAudioHlpBytesToFrames(const PPDMAUDIOPCMPROPS pProps, uint32_t cbBytes);
    187189uint64_t DrvAudioHlpBytesToMs(const PPDMAUDIOPCMPROPS pProps, uint32_t cbBytes);
  • trunk/src/VBox/Devices/Audio/DrvAudioCommon.cpp

    r73378 r73379  
    10611061{
    10621062    return DrvAudioHlpCalcBitrate(pProps->cBits, pProps->uHz, pProps->cChannels);
     1063}
     1064
     1065/**
     1066 * Aligns the given byte amount to the given PCM properties and returns the aligned
     1067 * size.
     1068 *
     1069 * @return  Aligned size (in bytes).
     1070 * @param   cbSize              Size (in bytes) to align.
     1071 * @param   pProps              PCM properties to align size to.
     1072 */
     1073uint32_t DrvAudioHlpBytesAlign(uint32_t cbSize, const PPDMAUDIOPCMPROPS pProps)
     1074{
     1075    AssertPtrReturn(pProps, 0);
     1076
     1077    if (!cbSize)
     1078        return 0;
     1079
     1080    const uint32_t cbFrameSize = DrvAudioHlpPCMPropsBytesPerFrame(pProps);
     1081    return (cbSize / cbFrameSize) * cbFrameSize;
     1082}
     1083
     1084/**
     1085 * Returns if the the given size is properly aligned to the given PCM properties.
     1086 *
     1087 * @return  @c true if properly aligned, @c false if not.
     1088 * @param   cbSize              Size (in bytes) to check alignment for.
     1089 * @param   pProps              PCM properties to use for checking the alignment.
     1090 */
     1091bool DrvAudioHlpBytesIsAligned(uint32_t cbSize, const PPDMAUDIOPCMPROPS pProps)
     1092{
     1093    AssertPtrReturn(pProps, 0);
     1094
     1095    if (!cbSize)
     1096        return true;
     1097
     1098    return (cbSize % DrvAudioHlpPCMPropsBytesPerFrame(pProps) == 0);
    10631099}
    10641100
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