VirtualBox

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


Ignore:
Timestamp:
Mar 7, 2021 2:29:40 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
143113
Message:

Audio: Fixed broken DrvAudioHlpBytesToNano and DrvAudioHlpBytesToMicro implementation (overflow), the latter is the only one used. Also fixed silly confusion about 'const' and pointers (you want what they point to to be const, not the pointers themselves. duh) bugref:9890

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

Legend:

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

    r87861 r87990  
    20882088        return 0;
    20892089
    2090     const uint64_t usBytes        = DrvAudioHlpBytesToMicro(cbBytes, &pStreamCC->State.Cfg.Props);
     2090    const uint64_t usBytes        = DrvAudioHlpBytesToMicro(&pStreamCC->State.Cfg.Props, cbBytes);
    20912091    const uint64_t cTransferTicks = PDMDevHlpTimerFromMicro(pDevIns, pStream->hTimer, usBytes);
    20922092
  • trunk/src/VBox/Devices/Audio/DrvAudio.h

    r87875 r87990  
    195195/** @name Audio calculation helper methods.
    196196 * @{ */
    197 void DrvAudioHlpClearBuf(const PPDMAUDIOPCMPROPS pPCMProps, void *pvBuf, size_t cbBuf, uint32_t cFrames);
     197void DrvAudioHlpClearBuf(PCPDMAUDIOPCMPROPS pPCMProps, void *pvBuf, size_t cbBuf, uint32_t cFrames);
    198198uint32_t DrvAudioHlpCalcBitrate(uint8_t cBits, uint32_t uHz, uint8_t cChannels);
    199 uint32_t DrvAudioHlpCalcBitrate(const PPDMAUDIOPCMPROPS pProps);
    200 uint32_t DrvAudioHlpBytesAlign(uint32_t cbSize, const PPDMAUDIOPCMPROPS pProps);
    201 bool     DrvAudioHlpBytesIsAligned(uint32_t cbSize, const PPDMAUDIOPCMPROPS pProps);
    202 uint32_t DrvAudioHlpBytesToFrames(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps);
    203 uint64_t DrvAudioHlpBytesToMilli(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps);
    204 uint64_t DrvAudioHlpBytesToMicro(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps);
    205 uint64_t DrvAudioHlpBytesToNano(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps);
    206 uint32_t DrvAudioHlpFramesToBytes(uint32_t cFrames, const PPDMAUDIOPCMPROPS pProps);
    207 uint64_t DrvAudioHlpFramesToMilli(uint32_t cFrames, const PPDMAUDIOPCMPROPS pProps);
    208 uint64_t DrvAudioHlpFramesToNano(uint32_t cFrames, const PPDMAUDIOPCMPROPS pProps);
    209 uint32_t DrvAudioHlpMilliToBytes(uint64_t uMs, const PPDMAUDIOPCMPROPS pProps);
    210 uint32_t DrvAudioHlpNanoToBytes(uint64_t uNs, const PPDMAUDIOPCMPROPS pProps);
    211 uint32_t DrvAudioHlpMilliToFrames(uint64_t uMs, const PPDMAUDIOPCMPROPS pProps);
    212 uint32_t DrvAudioHlpNanoToFrames(uint64_t uNs, const PPDMAUDIOPCMPROPS pProps);
     199uint32_t DrvAudioHlpCalcBitrate(PCPDMAUDIOPCMPROPS pProps);
     200uint32_t DrvAudioHlpBytesAlign(uint32_t cbSize, PCPDMAUDIOPCMPROPS pProps);
     201bool     DrvAudioHlpBytesIsAligned(uint32_t cbSize, PCPDMAUDIOPCMPROPS pProps);
     202uint32_t DrvAudioHlpBytesToFrames(uint32_t cbBytes, PCPDMAUDIOPCMPROPS pProps);
     203uint64_t DrvAudioHlpBytesToMilli(uint32_t cbBytes, PCPDMAUDIOPCMPROPS pProps);
     204uint64_t DrvAudioHlpBytesToMicro(PCPDMAUDIOPCMPROPS pProps, uint32_t cb);
     205uint64_t DrvAudioHlpBytesToNano(PCPDMAUDIOPCMPROPS pProps, uint32_t cb);
     206uint32_t DrvAudioHlpFramesToBytes(uint32_t cFrames, PCPDMAUDIOPCMPROPS pProps);
     207uint64_t DrvAudioHlpFramesToMilli(uint32_t cFrames, PCPDMAUDIOPCMPROPS pProps);
     208uint64_t DrvAudioHlpFramesToNano(uint32_t cFrames, PCPDMAUDIOPCMPROPS pProps);
     209uint32_t DrvAudioHlpMilliToBytes(uint64_t uMs, PCPDMAUDIOPCMPROPS pProps);
     210uint32_t DrvAudioHlpNanoToBytes(uint64_t uNs, PCPDMAUDIOPCMPROPS pProps);
     211uint32_t DrvAudioHlpMilliToFrames(uint64_t uMs, PCPDMAUDIOPCMPROPS pProps);
     212uint32_t DrvAudioHlpNanoToFrames(uint64_t uNs, PCPDMAUDIOPCMPROPS pProps);
    213213/** @}  */
    214214
    215215/** @name Audio PCM properties helper methods.
    216216 * @{ */
    217 bool DrvAudioHlpPCMPropsAreEqual(const PPDMAUDIOPCMPROPS pPCMProps1, const PPDMAUDIOPCMPROPS pPCMProps2);
    218 bool DrvAudioHlpPCMPropsAreEqual(const PPDMAUDIOPCMPROPS pPCMProps, const PPDMAUDIOSTREAMCFG pCfg);
    219 bool DrvAudioHlpPCMPropsAreValid(const PPDMAUDIOPCMPROPS pProps);
    220 uint32_t DrvAudioHlpPCMPropsBytesPerFrame(const PPDMAUDIOPCMPROPS pProps);
    221 void DrvAudioHlpPCMPropsPrint(const PPDMAUDIOPCMPROPS pProps);
    222 int DrvAudioHlpPCMPropsToStreamCfg(const PPDMAUDIOPCMPROPS pPCMProps, PPDMAUDIOSTREAMCFG pCfg);
     217bool DrvAudioHlpPCMPropsAreEqual(PCPDMAUDIOPCMPROPS pPCMProps1, PCPDMAUDIOPCMPROPS pPCMProps2);
     218bool DrvAudioHlpPCMPropsAreEqual(PCPDMAUDIOPCMPROPS pPCMProps, PCPDMAUDIOSTREAMCFG pCfg);
     219bool DrvAudioHlpPCMPropsAreValid(PCPDMAUDIOPCMPROPS pProps);
     220uint32_t DrvAudioHlpPCMPropsBytesPerFrame(PCPDMAUDIOPCMPROPS pProps);
     221void DrvAudioHlpPCMPropsPrint(PCPDMAUDIOPCMPROPS pProps);
     222int DrvAudioHlpPCMPropsToStreamCfg(PCPDMAUDIOPCMPROPS pPCMProps, PPDMAUDIOSTREAMCFG pCfg);
    223223/** @}  */
    224224
     
    226226 * @{ */
    227227void DrvAudioHlpStreamCfgInit(PPDMAUDIOSTREAMCFG pCfg);
    228 bool DrvAudioHlpStreamCfgIsValid(const PPDMAUDIOSTREAMCFG pCfg);
    229 int DrvAudioHlpStreamCfgCopy(PPDMAUDIOSTREAMCFG pDstCfg, const PPDMAUDIOSTREAMCFG pSrcCfg);
    230 PPDMAUDIOSTREAMCFG DrvAudioHlpStreamCfgDup(const PPDMAUDIOSTREAMCFG pCfg);
     228bool DrvAudioHlpStreamCfgIsValid(PCPDMAUDIOSTREAMCFG pCfg);
     229int DrvAudioHlpStreamCfgCopy(PPDMAUDIOSTREAMCFG pDstCfg, PCPDMAUDIOSTREAMCFG pSrcCfg);
     230PPDMAUDIOSTREAMCFG DrvAudioHlpStreamCfgDup(PCPDMAUDIOSTREAMCFG pCfg);
    231231void DrvAudioHlpStreamCfgFree(PPDMAUDIOSTREAMCFG pCfg);
    232 void DrvAudioHlpStreamCfgPrint(const PPDMAUDIOSTREAMCFG pCfg);
     232void DrvAudioHlpStreamCfgPrint(PCPDMAUDIOSTREAMCFG pCfg);
    233233/** @}  */
    234234
     
    287287int DrvAudioHlpFileCreate(PDMAUDIOFILETYPE enmType, const char *pszFile, uint32_t fFlags, PPDMAUDIOFILE *ppFile);
    288288void DrvAudioHlpFileDestroy(PPDMAUDIOFILE pFile);
    289 int DrvAudioHlpFileOpen(PPDMAUDIOFILE pFile, uint32_t fOpen, const PPDMAUDIOPCMPROPS pProps);
     289int DrvAudioHlpFileOpen(PPDMAUDIOFILE pFile, uint32_t fOpen, PCPDMAUDIOPCMPROPS pProps);
    290290int DrvAudioHlpFileClose(PPDMAUDIOFILE pFile);
    291291int DrvAudioHlpFileDelete(PPDMAUDIOFILE pFile);
  • trunk/src/VBox/Devices/Audio/DrvAudioCommon.cpp

    r87987 r87990  
    128128 * @param   cFrames                 Number of audio frames to clear in the buffer.
    129129 */
    130 void DrvAudioHlpClearBuf(const PPDMAUDIOPCMPROPS pPCMProps, void *pvBuf, size_t cbBuf, uint32_t cFrames)
     130void DrvAudioHlpClearBuf(PCPDMAUDIOPCMPROPS pPCMProps, void *pvBuf, size_t cbBuf, uint32_t cFrames)
    131131{
    132132    AssertPtrReturnVoid(pPCMProps);
     
    822822 * @param   pProps2             Second properties to compare.
    823823 */
    824 bool DrvAudioHlpPCMPropsAreEqual(const PPDMAUDIOPCMPROPS pProps1, const PPDMAUDIOPCMPROPS pProps2)
     824bool DrvAudioHlpPCMPropsAreEqual(PCPDMAUDIOPCMPROPS pProps1, PCPDMAUDIOPCMPROPS pProps2)
    825825{
    826826    AssertPtrReturn(pProps1, false);
     
    843843 * @param   pProps              PCM properties to check.
    844844 */
    845 bool DrvAudioHlpPCMPropsAreValid(const PPDMAUDIOPCMPROPS pProps)
     845bool DrvAudioHlpPCMPropsAreValid(PCPDMAUDIOPCMPROPS pProps)
    846846{
    847847    AssertPtrReturn(pProps, false);
     
    892892 * @param   pCfg                Stream configuration to compare.
    893893 */
    894 bool DrvAudioHlpPCMPropsAreEqual(const PPDMAUDIOPCMPROPS pProps, const PPDMAUDIOSTREAMCFG pCfg)
     894bool DrvAudioHlpPCMPropsAreEqual(PCPDMAUDIOPCMPROPS pProps, PCPDMAUDIOSTREAMCFG pCfg)
    895895{
    896896    AssertPtrReturn(pProps, false);
     
    906906 * @param  pProps               PCM properties to retrieve bytes per frame for.
    907907 */
    908 uint32_t DrvAudioHlpPCMPropsBytesPerFrame(const PPDMAUDIOPCMPROPS pProps)
     908uint32_t DrvAudioHlpPCMPropsBytesPerFrame(PCPDMAUDIOPCMPROPS pProps)
    909909{
    910910    return PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */);
     
    916916 * @param   pProps              Stream configuration to log.
    917917 */
    918 void DrvAudioHlpPCMPropsPrint(const PPDMAUDIOPCMPROPS pProps)
     918void DrvAudioHlpPCMPropsPrint(PCPDMAUDIOPCMPROPS pProps)
    919919{
    920920    AssertPtrReturnVoid(pProps);
     
    931931 * @param   pCfg                Stream configuration to store result into.
    932932 */
    933 int DrvAudioHlpPCMPropsToStreamCfg(const PPDMAUDIOPCMPROPS pProps, PPDMAUDIOSTREAMCFG pCfg)
     933int DrvAudioHlpPCMPropsToStreamCfg(PCPDMAUDIOPCMPROPS pProps, PPDMAUDIOSTREAMCFG pCfg)
    934934{
    935935    AssertPtrReturn(pProps, VERR_INVALID_POINTER);
     
    962962 * @param   pCfg                Stream configuration to check.
    963963 */
    964 bool DrvAudioHlpStreamCfgIsValid(const PPDMAUDIOSTREAMCFG pCfg)
     964bool DrvAudioHlpStreamCfgIsValid(PCPDMAUDIOSTREAMCFG pCfg)
    965965{
    966966    AssertPtrReturn(pCfg, false);
     
    999999 * @param   pSrcCfg             Source stream configuration to copy to destination.
    10001000 */
    1001 int DrvAudioHlpStreamCfgCopy(PPDMAUDIOSTREAMCFG pDstCfg, const PPDMAUDIOSTREAMCFG pSrcCfg)
     1001int DrvAudioHlpStreamCfgCopy(PPDMAUDIOSTREAMCFG pDstCfg, PCPDMAUDIOSTREAMCFG pSrcCfg)
    10021002{
    10031003    AssertPtrReturn(pDstCfg, VERR_INVALID_POINTER);
     
    10241024 * @param   pCfg                    Audio stream configuration to duplicate.
    10251025 */
    1026 PPDMAUDIOSTREAMCFG DrvAudioHlpStreamCfgDup(const PPDMAUDIOSTREAMCFG pCfg)
     1026PPDMAUDIOSTREAMCFG DrvAudioHlpStreamCfgDup(PCPDMAUDIOSTREAMCFG pCfg)
    10271027{
    10281028    AssertPtrReturn(pCfg, NULL);
     
    10561056 * @param   pCfg                Stream configuration to log.
    10571057 */
    1058 void DrvAudioHlpStreamCfgPrint(const PPDMAUDIOSTREAMCFG pCfg)
     1058void DrvAudioHlpStreamCfgPrint(PCPDMAUDIOSTREAMCFG pCfg)
    10591059{
    10601060    if (!pCfg)
     
    11681168 * @remark
    11691169 */
    1170 uint32_t DrvAudioHlpCalcBitrate(const PPDMAUDIOPCMPROPS pProps)
     1170uint32_t DrvAudioHlpCalcBitrate(PCPDMAUDIOPCMPROPS pProps)
    11711171{
    11721172    return DrvAudioHlpCalcBitrate(pProps->cbSample * 8, pProps->uHz, pProps->cChannels);
     
    11811181 * @param   pProps              PCM properties to align size to.
    11821182 */
    1183 uint32_t DrvAudioHlpBytesAlign(uint32_t cbSize, const PPDMAUDIOPCMPROPS pProps)
     1183uint32_t DrvAudioHlpBytesAlign(uint32_t cbSize, PCPDMAUDIOPCMPROPS pProps)
    11841184{
    11851185    AssertPtrReturn(pProps, 0);
     
    11981198 * @param   pProps              PCM properties to use for checking the alignment.
    11991199 */
    1200 bool DrvAudioHlpBytesIsAligned(uint32_t cbSize, const PPDMAUDIOPCMPROPS pProps)
     1200bool DrvAudioHlpBytesIsAligned(uint32_t cbSize, PCPDMAUDIOPCMPROPS pProps)
    12011201{
    12021202    AssertPtrReturn(pProps, 0);
     
    12141214 * @param   pProps              PCM properties to retrieve size for.
    12151215 */
    1216 DECLINLINE(uint64_t) drvAudioHlpBytesPerSec(const PPDMAUDIOPCMPROPS pProps)
     1216DECLINLINE(uint64_t) drvAudioHlpBytesPerSec(PCPDMAUDIOPCMPROPS pProps)
    12171217{
    12181218    return PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */) * pProps->uHz;
     
    12261226 * @param  pProps               PCM properties to calulate frames for.
    12271227 */
    1228 uint32_t DrvAudioHlpBytesToFrames(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps)
     1228uint32_t DrvAudioHlpBytesToFrames(uint32_t cbBytes, PCPDMAUDIOPCMPROPS pProps)
    12291229{
    12301230    AssertPtrReturn(pProps, 0);
     
    12341234
    12351235/**
    1236  * Returns the time (in ms) for given byte amount and PCM properties.
    1237  *
    1238  * @return  uint64_t            Calculated time (in ms).
    1239  * @param   cbBytes             Amount of bytes to calculate time for.
    1240  * @param   pProps              PCM properties to calculate amount of bytes for.
    1241  *
    1242  * @note    Does rounding up the result.
    1243  */
    1244 uint64_t DrvAudioHlpBytesToMilli(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps)
     1236 * Converts bytes to milliseconds.
     1237 *
     1238 * @return  Number milliseconds @a cb takes to play or record.
     1239 * @param   pProps      PCM properties to use.
     1240 * @param   cb          The number of bytes to convert.
     1241 *
     1242 * @note    Rounds up the result.
     1243 */
     1244uint64_t DrvAudioHlpBytesToMilli(uint32_t cb, PCPDMAUDIOPCMPROPS pProps)
    12451245{
    12461246    AssertPtrReturn(pProps, 0);
    12471247
    1248     if (!pProps->uHz) /* Prevent division by zero. */
    1249         return 0;
    1250 
    1251     const unsigned cbFrame = PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */);
    1252 
    1253     if (!cbFrame) /* Prevent division by zero. */
    1254         return 0;
    1255 
    1256     uint64_t uTimeMs = ((cbBytes + cbFrame - 1) / cbFrame) * RT_MS_1SEC;
    1257 
    1258     return (uTimeMs + pProps->uHz - 1) / pProps->uHz;
    1259 }
    1260 
    1261 /**
    1262  * Returns the time (in us) for given byte amount and PCM properties.
    1263  *
    1264  * @return  uint64_t            Calculated time (in us).
    1265  * @param   cbBytes             Amount of bytes to calculate time for.
    1266  * @param   pProps              PCM properties to calculate amount of bytes for.
    1267  *
    1268  * @note    Does rounding up the result.
    1269  */
    1270 uint64_t DrvAudioHlpBytesToMicro(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps)
     1248    /* Check parameters to prevent division by chainsaw: */
     1249    uint32_t const uHz = pProps->uHz;
     1250    if (uHz)
     1251    {
     1252        const unsigned cbFrame = PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */);
     1253        if (cbFrame)
     1254        {
     1255            /* Round cb up to closest frame size: */
     1256            cb = (cb + cbFrame - 1) / cbFrame;
     1257
     1258            /* Convert to milliseconds. */
     1259            return (cb * (uint64_t)RT_MS_1SEC + uHz - 1) / uHz;
     1260        }
     1261    }
     1262    return 0;
     1263}
     1264
     1265/**
     1266 * Converts bytes to microseconds.
     1267 *
     1268 * @return  Number microseconds @a cb takes to play or record.
     1269 * @param   pProps      PCM properties to use.
     1270 * @param   cb          The number of bytes to convert.
     1271 *
     1272 * @note    Rounds up the result.
     1273 */
     1274uint64_t DrvAudioHlpBytesToMicro(PCPDMAUDIOPCMPROPS pProps, uint32_t cb)
    12711275{
    12721276    AssertPtrReturn(pProps, 0);
    12731277
    1274     if (!pProps->uHz) /* Prevent division by zero. */
    1275         return 0;
    1276 
    1277     const unsigned cbFrame = PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */);
    1278 
    1279     if (!cbFrame) /* Prevent division by zero. */
    1280         return 0;
    1281 
    1282     uint64_t uTimeUs = ((cbBytes + cbFrame - 1) / cbFrame) * RT_US_1SEC;
    1283 
    1284     return (uTimeUs + pProps->uHz - 1) / pProps->uHz;
    1285 }
    1286 
    1287 /**
    1288  * Returns the time (in ns) for given byte amount and PCM properties.
    1289  *
    1290  * @return  uint64_t            Calculated time (in ns).
    1291  * @param   cbBytes             Amount of bytes to calculate time for.
    1292  * @param   pProps              PCM properties to calculate amount of bytes for.
    1293  *
    1294  * @note    Does rounding up the result.
    1295  */
    1296 uint64_t DrvAudioHlpBytesToNano(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps)
     1278    /* Check parameters to prevent division by chainsaw: */
     1279    uint32_t const uHz = pProps->uHz;
     1280    if (uHz)
     1281    {
     1282        const unsigned cbFrame = PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */);
     1283        if (cbFrame)
     1284        {
     1285            /* Round cb up to closest frame size: */
     1286            cb = (cb + cbFrame - 1) / cbFrame;
     1287
     1288            /* Convert to microseconds. */
     1289            return (cb * (uint64_t)RT_US_1SEC + uHz - 1) / uHz;
     1290        }
     1291    }
     1292    return 0;
     1293}
     1294
     1295/**
     1296 * Converts bytes to nanoseconds.
     1297 *
     1298 * @return  Number nanoseconds @a cb takes to play or record.
     1299 * @param   pProps      PCM properties to use.
     1300 * @param   cb          The number of bytes to convert.
     1301 *
     1302 * @note    Rounds up the result.
     1303 */
     1304uint64_t DrvAudioHlpBytesToNano(PCPDMAUDIOPCMPROPS pProps, uint32_t cb)
    12971305{
    12981306    AssertPtrReturn(pProps, 0);
    12991307
    1300     if (!pProps->uHz) /* Prevent division by zero. */
    1301         return 0;
    1302 
    1303     const unsigned cbFrame = PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */);
    1304 
    1305     if (!cbFrame) /* Prevent division by zero. */
    1306         return 0;
    1307 
    1308     uint64_t uTimeNs = ((cbBytes + cbFrame - 1) / cbFrame) * RT_NS_1SEC;
    1309 
    1310     return (uTimeNs + pProps->uHz - 1) / pProps->uHz;
     1308    /* Check parameters to prevent division by chainsaw: */
     1309    uint32_t const uHz = pProps->uHz;
     1310    if (uHz)
     1311    {
     1312        const unsigned cbFrame = PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */);
     1313        if (cbFrame)
     1314        {
     1315            /* Round cb up to closest frame size: */
     1316            cb = (cb + cbFrame - 1) / cbFrame;
     1317
     1318            /* Convert to nanoseconds. */
     1319            return (cb * (uint64_t)RT_NS_1SEC + uHz - 1) / uHz;
     1320        }
     1321    }
     1322    return 0;
    13111323}
    13121324
     
    13181330 * @param  pProps               PCM properties to calculate bytes for.
    13191331 */
    1320 uint32_t DrvAudioHlpFramesToBytes(uint32_t cFrames, const PPDMAUDIOPCMPROPS pProps)
     1332uint32_t DrvAudioHlpFramesToBytes(uint32_t cFrames, PCPDMAUDIOPCMPROPS pProps)
    13211333{
    13221334    AssertPtrReturn(pProps, 0);
     
    13351347 * @param   pProps              PCM properties to calculate time (in ms) for.
    13361348 */
    1337 uint64_t DrvAudioHlpFramesToMilli(uint32_t cFrames, const PPDMAUDIOPCMPROPS pProps)
     1349uint64_t DrvAudioHlpFramesToMilli(uint32_t cFrames, PCPDMAUDIOPCMPROPS pProps)
    13381350{
    13391351    AssertPtrReturn(pProps, 0);
     
    13621374 * @param   pProps              PCM properties to calculate time (in ns) for.
    13631375 */
    1364 uint64_t DrvAudioHlpFramesToNano(uint32_t cFrames, const PPDMAUDIOPCMPROPS pProps)
     1376uint64_t DrvAudioHlpFramesToNano(uint32_t cFrames, PCPDMAUDIOPCMPROPS pProps)
    13651377{
    13661378    AssertPtrReturn(pProps, 0);
     
    13841396 * @param   pProps              PCM properties to calculate amount of bytes for.
    13851397 */
    1386 uint32_t DrvAudioHlpMilliToBytes(uint64_t uMs, const PPDMAUDIOPCMPROPS pProps)
     1398uint32_t DrvAudioHlpMilliToBytes(uint64_t uMs, PCPDMAUDIOPCMPROPS pProps)
    13871399{
    13881400    AssertPtrReturn(pProps, 0);
     
    14111423 * @param   pProps              PCM properties to calculate amount of bytes for.
    14121424 */
    1413 uint32_t DrvAudioHlpNanoToBytes(uint64_t uNs, const PPDMAUDIOPCMPROPS pProps)
     1425uint32_t DrvAudioHlpNanoToBytes(uint64_t uNs, PCPDMAUDIOPCMPROPS pProps)
    14141426{
    14151427    AssertPtrReturn(pProps, 0);
     
    14361448 * @param   pProps              PCM properties to calculate amount of frames for.
    14371449 */
    1438 uint32_t DrvAudioHlpMilliToFrames(uint64_t uMs, const PPDMAUDIOPCMPROPS pProps)
     1450uint32_t DrvAudioHlpMilliToFrames(uint64_t uMs, PCPDMAUDIOPCMPROPS pProps)
    14391451{
    14401452    AssertPtrReturn(pProps, 0);
     
    14541466 * @param   pProps              PCM properties to calculate amount of frames for.
    14551467 */
    1456 uint32_t DrvAudioHlpNanoToFrames(uint64_t uNs, const PPDMAUDIOPCMPROPS pProps)
     1468uint32_t DrvAudioHlpNanoToFrames(uint64_t uNs, PCPDMAUDIOPCMPROPS pProps)
    14571469{
    14581470    AssertPtrReturn(pProps, 0);
     
    17041716 * @param   pProps              PCM properties to use.
    17051717 */
    1706 int DrvAudioHlpFileOpen(PPDMAUDIOFILE pFile, uint32_t fOpen, const PPDMAUDIOPCMPROPS pProps)
     1718int DrvAudioHlpFileOpen(PPDMAUDIOFILE pFile, uint32_t fOpen, PCPDMAUDIOPCMPROPS pProps)
    17071719{
    17081720    AssertPtrReturn(pFile,   VERR_INVALID_POINTER);
  • trunk/src/VBox/Devices/Audio/testcase/tstAudioMixBuffer.cpp

    r82968 r87990  
    3333
    3434
    35 /*********************************************************************************************************************************
    36 *   Structures and Typedefs                                                                                                      *
    37 *********************************************************************************************************************************/
     35static void tstBasics(RTTEST hTest)
     36{
     37    RTTestSubF(hTest, "Single buffer");
     38
     39    static const PDMAUDIOPCMPROPS s_Cfg441StereoS16 = PDMAUDIOPCMPROPS_INITIALIZOR(
     40        /* a_cb: */             2,
     41        /* a_fSigned: */        true,
     42        /* a_cChannels: */      2,
     43        /* a_uHz: */            44100,
     44        /* a_cShift: */         PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(2 /* cb */, 2 /* cChannels */),
     45        /* a_fSwapEndian: */    false
     46    );
     47
     48    RTTESTI_CHECK_MSG(PDMAUDIOPCMPROPS_F2B(&s_Cfg441StereoS16, 1) == 4,
     49                      ("got %x, expected 4\n", PDMAUDIOPCMPROPS_F2B(&s_Cfg441StereoS16, 1)));
     50
     51    uint32_t u32;
     52    RTTESTI_CHECK_MSG((u32 = DrvAudioHlpFramesToBytes(44100, &s_Cfg441StereoS16)) == 44100 * 2 * 2,
     53                      ("cb=%RU32\n", u32));
     54    RTTESTI_CHECK_MSG((u32 = DrvAudioHlpFramesToBytes(2, &s_Cfg441StereoS16)) == 2 * 2 * 2,
     55                      ("cb=%RU32\n", u32));
     56
     57    uint64_t u64;
     58    RTTESTI_CHECK_MSG((u64 = DrvAudioHlpBytesToNano(&s_Cfg441StereoS16, 44100 * 2 * 2)) == RT_NS_1SEC,
     59                      ("ns=%RU64\n", u64));
     60    RTTESTI_CHECK_MSG((u64 = DrvAudioHlpBytesToMicro(&s_Cfg441StereoS16, 44100 * 2 * 2)) == RT_US_1SEC,
     61                      ("us=%RU64\n", u64));
     62    RTTESTI_CHECK_MSG((u64 = DrvAudioHlpBytesToMilli(44100 * 2 * 2, &s_Cfg441StereoS16)) == RT_MS_1SEC,
     63                      ("ms=%RU64\n", u64));
     64
     65
     66
     67}
     68
    3869
    3970static int tstSingle(RTTEST hTest)
    4071{
    41     RTTestSubF(hTest, "Single buffer");
     72    RTTestSub(hTest, "Single buffer");
    4273
    4374    /* 44100Hz, 2 Channels, S16 */
     
    232263     * Using AudioMixBufWriteAt for writing to children.
    233264     */
    234     RTTestSubF(hTest, "2 Children -> Parent (AudioMixBufWriteAt)");
     265    RTTestSub(hTest, "2 Children -> Parent (AudioMixBufWriteAt)");
    235266
    236267    uint32_t cChildrenSamplesMixedTotal = 0;
     
    308339    uint32_t         cBufSize = 256;
    309340
    310     RTTestSubF(hTest, "Sample conversion (U8)");
     341    RTTestSub(hTest, "Sample conversion (U8)");
    311342
    312343    /* 44100Hz, 1 Channel, U8 */
     
    413444    uint32_t         cBufSize = 256;
    414445
    415     RTTestSubF(hTest, "Sample conversion (S16)");
     446    RTTestSub(hTest, "Sample conversion (S16)");
    416447
    417448    /* 44100Hz, 1 Channel, S16 */
     
    509540    uint32_t         cBufSize = 256;
    510541
    511     RTTestSubF(hTest, "Volume control");
     542    RTTestSub(hTest, "Volume control");
    512543
    513544    /* Same for parent/child. */
     
    635666    RTTestBanner(hTest);
    636667
    637     rc = tstSingle(hTest);
    638     if (RT_SUCCESS(rc))
    639         rc = tstParentChild(hTest);
    640     if (RT_SUCCESS(rc))
    641         rc = tstConversion8(hTest);
    642     if (RT_SUCCESS(rc))
    643         rc = tstConversion16(hTest);
    644     if (RT_SUCCESS(rc))
    645         rc = tstVolume(hTest);
     668    tstBasics(hTest);
     669    tstSingle(hTest);
     670    tstParentChild(hTest);
     671    tstConversion8(hTest);
     672    tstConversion16(hTest);
     673    tstVolume(hTest);
    646674
    647675    /*
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette