VirtualBox

Changeset 87583 in vbox


Ignore:
Timestamp:
Feb 3, 2021 4:20:48 PM (4 years ago)
Author:
vboxsync
Message:

Audio/HDA: More timing-related fixes for Windows guests. This is a risky change and needs more testing / verification on other guests. Only got limited testing for Win10 AU / Win10 20H2 and Ubuntu 20.10 guests so far [build fix]. ticketoem2ref:36

File:
1 edited

Legend:

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

    r87573 r87583  
    3030#include <VBox/vmm/pdmaudioifs.h>
    3131
    32 #include <math.h> /* Needed for round(). */
     32#include <math.h> /* Needed for roundl(). */
    3333
    3434#include "DrvAudio.h"
     
    549549
    550550                /* Calculate the timer ticks per byte for this stream. */
    551                 pStreamShared->State.cTicksPerByte = round(cTicksPerByte); /** @todo r=andy Do we have rounding in IPRT? */
     551                pStreamShared->State.cTicksPerByte = roundl(cTicksPerByte); /** @todo r=andy Do we have rounding in IPRT? */
    552552                Assert(pStreamShared->State.cTicksPerByte);
    553553
     
    555555
    556556                /* Calculate timer ticks per transfer. */
    557                 pStreamShared->State.cTransferTicks = round(cTransferTicks);
     557                pStreamShared->State.cTransferTicks = roundl(cTransferTicks);
    558558                Assert(pStreamShared->State.cTransferTicks);
    559559
     
    743743#endif
    744744
    745 /*
     745/**
    746746 * Updates an HDA stream's current read or write buffer position (depending on the stream type) by
    747747 * setting its associated LPIB register and DMA position buffer (if enabled) to an absolute value.
     
    772772}
    773773
    774 /*
     774/**
    775775 * Updates an HDA stream's current read or write buffer position (depending on the stream type) by
    776776 * adding a value to its associated LPIB register and DMA position buffer (if enabled).
     
    985985    if (pcbRead)
    986986        *pcbRead = cbReadTotal;
    987 
    988     return rc;
    989 }
    990 
    991 /*
    992  * Reads DMA data from a given HDA output stream.
    993  *
    994  * @return  IPRT status code.
    995  * @param   pDevIns             The device instance.
    996  * @param   pThis               The shared HDA device state (for stats).
    997  * @param   pStreamShared       HDA output stream to read DMA data from - shared bits.
    998  * @param   pStreamR3           HDA output stream to read DMA data from - shared ring-3.
    999  * @param   pvBuf               Where to store the read data.
    1000  * @param   cbBuf               How much to read in bytes.
    1001  * @param   pcbRead             Returns read bytes from DMA. Optional.
    1002  */
    1003 int hdaR3DMARead2(PPDMDEVINS pDevIns, PHDASTATE pThis, PHDASTREAM pStreamShared, PHDASTREAMR3 pStreamR3,
    1004                   void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead)
    1005 {
    1006     RT_NOREF(pThis);
    1007     PHDABDLE pBDLE = &pStreamShared->State.BDLE;
    1008 
    1009     int rc = VINF_SUCCESS;
    1010 
    1011     uint32_t cbReadTotal = 0;
    1012     uint32_t cbLeft      = RT_MIN(cbBuf, pBDLE->Desc.u32BufSize - pBDLE->State.u32BufOff);
    1013 
    1014 # ifdef HDA_DEBUG_SILENCE
    1015     uint64_t   csSilence = 0;
    1016 
    1017     pStreamR3->Dbg.cSilenceThreshold = 100;
    1018     pStreamR3->Dbg.cbSilenceReadMin  = _1M;
    1019 # endif
    1020 
    1021     RTGCPHYS GCPhysChunk = pBDLE->Desc.u64BufAddr + pBDLE->State.u32BufOff;
    1022 
    1023     while (cbLeft)
    1024     {
    1025         uint32_t cbChunk = RT_MIN(cbLeft, pStreamShared->u8FIFOS);
    1026 
    1027         rc = PDMDevHlpPhysRead(pDevIns, GCPhysChunk, (uint8_t *)pvBuf + cbReadTotal, cbChunk);
    1028         AssertRCBreak(rc);
    1029 
    1030 # ifdef HDA_DEBUG_SILENCE
    1031         uint16_t *pu16Buf = (uint16_t *)pvBuf;
    1032         for (size_t i = 0; i < cbChunk / sizeof(uint16_t); i++)
    1033         {
    1034             if (*pu16Buf == 0)
    1035                 csSilence++;
    1036             else
    1037                 break;
    1038             pu16Buf++;
    1039         }
    1040 # endif
    1041 
    1042         /*
    1043          * Update the stream's current position.
    1044          * Do this as accurate and close to the actual data transfer as possible.
    1045          * All guetsts rely on this, depending on the mechanism they use (LPIB register or DMA counters).
    1046          */
    1047         hdaR3StreamSetPositionAdd(pStreamShared, pDevIns, pThis, /* cbChunk */ 0);
    1048 
    1049         if (RT_LIKELY(!pStreamR3->Dbg.Runtime.fEnabled))
    1050         { /* likely */ }
    1051         else
    1052             DrvAudioHlpFileWrite(pStreamR3->Dbg.Runtime.pFileDMARaw, (uint8_t *)pvBuf + cbReadTotal, cbChunk, 0 /* fFlags */);
    1053 
    1054         STAM_COUNTER_ADD(&pThis->StatBytesRead, cbChunk);
    1055 
    1056         /* advance */
    1057         Assert(cbLeft    >= cbChunk);
    1058         GCPhysChunk       = (GCPhysChunk + cbChunk) % pBDLE->Desc.u32BufSize;
    1059         cbReadTotal      += cbChunk;
    1060         cbLeft           -= cbChunk;
    1061     }
    1062 
    1063 # ifdef HDA_DEBUG_SILENCE
    1064     if (csSilence)
    1065         pStreamR3->Dbg.csSilence += csSilence;
    1066 
    1067     if (   csSilence == 0
    1068         && pStreamR3->Dbg.csSilence   >  pStreamR3->Dbg.cSilenceThreshold
    1069         && pStreamR3->Dbg.cbReadTotal >= pStreamR3->Dbg.cbSilenceReadMin)
    1070     {
    1071         LogFunc(("Silent block detected: %RU64 audio samples\n", pStreamR3->Dbg.csSilence));
    1072         pStreamR3->Dbg.csSilence = 0;
    1073     }
    1074 # endif
    1075 
    1076     if (RT_SUCCESS(rc))
    1077     {
    1078         if (pcbRead)
    1079             *pcbRead = cbReadTotal;
    1080     }
    1081987
    1082988    return rc;
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