VirtualBox

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


Ignore:
Timestamp:
Mar 8, 2021 12:08:34 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
143129
Message:

Audio: DrvAudioHlpBytesAlign -> DrvAudioHlpFloorBytesToFrame as it isn't doing an align operation similar to RT_ALIGN, it's rounding down rather than up. Switched parameters and tweaked the implementation slightly. bugref:9890

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

Legend:

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

    r88005 r88006  
    29842984        /* Make sure to align the readable size to the guest's frame size. */
    29852985        if (cbReadable)
    2986             cbReadable = DrvAudioHlpBytesAlign(cbReadable, &pStream->Guest.Cfg.Props);
     2986            cbReadable = DrvAudioHlpFloorBytesToFrame(&pStream->Guest.Cfg.Props, cbReadable);
    29872987    }
    29882988
     
    30213021
    30223022        /* Make sure to align the writable size to the host's frame size. */
    3023         cbWritable = DrvAudioHlpBytesAlign(cbWritable, &pStream->Host.Cfg.Props);
     3023        cbWritable = DrvAudioHlpFloorBytesToFrame(&pStream->Host.Cfg.Props, cbWritable);
    30243024    }
    30253025
  • trunk/src/VBox/Devices/Audio/DrvAudio.h

    r88004 r88006  
    198198uint32_t DrvAudioHlpCalcBitrate(uint8_t cBits, uint32_t uHz, uint8_t cChannels);
    199199uint32_t DrvAudioHlpGetBitrate(PCPDMAUDIOPCMPROPS pProps);
    200 uint32_t DrvAudioHlpBytesAlign(uint32_t cbSize, PCPDMAUDIOPCMPROPS pProps);
     200uint32_t DrvAudioHlpFloorBytesToFrame(PCPDMAUDIOPCMPROPS pProps, uint32_t cb);
    201201bool     DrvAudioHlpIsBytesAligned(PCPDMAUDIOPCMPROPS pProps, uint32_t cb);
    202202uint32_t DrvAudioHlpBytesToFrames(uint32_t cbBytes, PCPDMAUDIOPCMPROPS pProps);
  • trunk/src/VBox/Devices/Audio/DrvAudioCommon.cpp

    r88004 r88006  
    11591159
    11601160/**
    1161  * Aligns the given byte amount to the given PCM properties and returns the aligned
    1162  * size.
    1163  *
    1164  * @return  Aligned size (in bytes).
    1165  * @param   cbSize              Size (in bytes) to align.
    1166  * @param   pProps              PCM properties to align size to.
    1167  */
    1168 uint32_t DrvAudioHlpBytesAlign(uint32_t cbSize, PCPDMAUDIOPCMPROPS pProps)
     1161 * Rounds down the given byte amount to the nearest frame boundrary.
     1162 *
     1163 * @returns Rounded byte amount.
     1164 * @param   pProps      PCM properties to use.
     1165 * @param   cb          The size (in bytes) to round.
     1166 */
     1167uint32_t DrvAudioHlpFloorBytesToFrame(PCPDMAUDIOPCMPROPS pProps, uint32_t cb)
    11691168{
    11701169    AssertPtrReturn(pProps, 0);
    1171 
    1172     if (!cbSize)
    1173         return 0;
    1174 
    1175     return PDMAUDIOPCMPROPS_B2F(pProps, cbSize) * PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */);
     1170    return PDMAUDIOPCMPROPS_F2B(pProps, PDMAUDIOPCMPROPS_B2F(pProps, cb));
    11761171}
    11771172
  • trunk/src/VBox/Devices/Audio/HDAStream.cpp

    r88005 r88006  
    544544               halve the buffer till we get there. */
    545545            while (cbTransferHeuristics > 1024 && cbTransferHeuristics > cbTransferPerSec / 4)
    546                 cbTransferHeuristics = DrvAudioHlpBytesAlign(cbTransferHeuristics / 2, &pStreamR3->State.Mapping.PCMProps);
     546                cbTransferHeuristics = DrvAudioHlpFloorBytesToFrame(&pStreamR3->State.Mapping.PCMProps, cbTransferHeuristics / 2);
    547547
    548548            /* Set the transfer size per timer callout. (No chunking, so same.) */
     
    18741874            uint32_t       cbToReadFromStream = RT_MIN(cbStreamReadable, cbSinkWritable);
    18751875            /* Make sure that we always align the number of bytes when reading to the stream's PCM properties. */
    1876             cbToReadFromStream = DrvAudioHlpBytesAlign(cbToReadFromStream, &pStreamR3->State.Mapping.PCMProps);
     1876            cbToReadFromStream = DrvAudioHlpFloorBytesToFrame(&pStreamR3->State.Mapping.PCMProps, cbToReadFromStream);
    18771877
    18781878            Assert(tsNowNs >= pStreamShared->State.tsLastReadNs);
  • trunk/src/VBox/Devices/Audio/testcase/tstAudioMixBuffer.cpp

    r88004 r88006  
    7272                      ("got %x, expected 4\n", PDMAUDIOPCMPROPS_F2B(&s_Cfg441StereoU32, 1)));
    7373
     74    uint32_t u32;
    7475    for (uint32_t i = 0; i < 256; i += 8)
    7576    {
    7677        RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i) == true);
    77         RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+1) == false);
    78         RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+2) == false);
    79         RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+3) == false);
    80         RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+4) == false);
    81         RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+5) == false);
    82         RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+6) == false);
    83         RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+7) == false);
     78        for (uint32_t j = 1; j < 8; j++)
     79            RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i + j) == false);
     80        for (uint32_t j = 0; j < 8; j++)
     81            RTTESTI_CHECK(DrvAudioHlpFloorBytesToFrame(&s_Cfg441StereoU32, i + j) == i);
    8482    }
    8583    for (uint32_t i = 0; i < 4096; i += 4)
    8684    {
    8785        RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoS16, i) == true);
    88         RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoS16, i+1) == false);
    89         RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoS16, i+2) == false);
    90         RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoS16, i+3) == false);
    91     }
    92 
    93     uint32_t u32;
     86        for (uint32_t j = 1; j < 4; j++)
     87            RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoS16, i + j) == false);
     88        for (uint32_t j = 0; j < 4; j++)
     89            RTTESTI_CHECK(DrvAudioHlpFloorBytesToFrame(&s_Cfg441StereoS16, i + j) == i);
     90    }
     91
    9492    RTTESTI_CHECK_MSG((u32 = DrvAudioHlpFramesToBytes(&s_Cfg441StereoS16, 44100)) == 44100 * 2 * 2,
    9593                      ("cb=%RU32\n", u32));
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