VirtualBox

Changeset 55649 in vbox for trunk/src


Ignore:
Timestamp:
May 4, 2015 2:46:57 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
100024
Message:

DrvHostNullAudio: consume samples at configured rate

File:
1 edited

Legend:

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

    r54967 r55649  
    6161    /** Note: Always must come first! */
    6262    PDMAUDIOHSTSTRMOUT hw;
     63    uint64_t u64TicksLast;
    6364} NULLAUDIOSTREAMOUT;
    6465
     
    134135    if (RT_SUCCESS(rc))
    135136    {
     137        NULLAUDIOSTREAMOUT *pNullStrmOut = (NULLAUDIOSTREAMOUT *)pHstStrmOut;
     138        pNullStrmOut->u64TicksLast = 0;
    136139        if (pcSamples)
    137140            *pcSamples = _1K;
     
    151154                                                 uint32_t *pcSamplesPlayed)
    152155{
    153     /* Always pretend consuming all samples available at this time. */
    154     const uint32_t cSamplesPlayed = audioMixBufSize(&pHstStrmOut->MixBuf);
     156    PDRVHOSTNULLAUDIO pDrv = RT_FROM_MEMBER(pInterface, DRVHOSTNULLAUDIO, IHostAudio);
     157    NULLAUDIOSTREAMOUT *pNullStrmOut = (NULLAUDIOSTREAMOUT *)pHstStrmOut;
     158
     159    /* Consume as many samples as would be played at the current frequency since last call. */
     160    uint32_t csLive = drvAudioHstOutSamplesLive(pHstStrmOut, NULL /* pcStreamsLive */);
     161    uint64_t u64TicksNow = PDMDrvHlpTMGetVirtualTime(pDrv->pDrvIns);
     162    uint64_t u64TicksElapsed = u64TicksNow  - pNullStrmOut->u64TicksLast;
     163    uint64_t u64TicksFreq = PDMDrvHlpTMGetVirtualFreq(pDrv->pDrvIns);
     164
     165    /* Remember when samples were consumed. */
     166    pNullStrmOut->u64TicksLast = u64TicksNow;
     167
     168    /* Minimize the rounding error by adding 0.5: samples = int((u64TicksElapsed * samplesFreq) / u64TicksFreq + 0.5).
     169     * If rounding is not taken into account then the playback rate will be consistently lower that expected.
     170     */
     171    uint64_t cSamplesPlayed = (2 * u64TicksElapsed * pHstStrmOut->Props.uHz + u64TicksFreq) / u64TicksFreq / 2;
     172
     173    /* Don't play more than available. */
     174    if (cSamplesPlayed > csLive)
     175        cSamplesPlayed = csLive;
     176
    155177    audioMixBufFinish(&pHstStrmOut->MixBuf, cSamplesPlayed);
    156178
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