VirtualBox

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


Ignore:
Timestamp:
Jul 27, 2017 8:15:43 AM (7 years ago)
Author:
vboxsync
Message:

Audio: Renamed audio samples to audio frame because that's what they really are. No actual code changes.

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

Legend:

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

    r67742 r68132  
    11/* $Id$ */
    22/** @file
    3  * VBox audio: Audio mixing buffer for converting reading/writing audio
    4  *             samples.
     3 * VBox audio: Audio mixing buffer for converting reading/writing audio data.
    54 */
    65
     
    137136
    138137/**
    139  * Peeks for audio samples without any conversion done.
    140  * This will get the raw sample data out of a mixing buffer.
     138 * Peeks for audio frames without any conversion done.
     139 * This will get the raw frame data out of a mixing buffer.
    141140 *
    142141 * @return  IPRT status code or VINF_AUDIO_MORE_DATA_AVAILABLE if more data is available to read.
    143142 *
    144  * @param   pMixBuf                 Mixing buffer to acquire audio samples from.
    145  * @param   cSamplesToRead          Number of audio samples to read.
    146  * @param   paSampleBuf             Buffer where to store the returned audio samples.
    147  * @param   cSampleBuf              Size (in samples) of the buffer to store audio samples into.
    148  * @param   pcSamplesRead           Returns number of read audio samples. Optional.
     143 * @param   pMixBuf                 Mixing buffer to acquire audio frames from.
     144 * @param   cFramesToRead           Number of audio frames to read.
     145 * @param   paFrameBuf              Buffer where to store the returned audio frames.
     146 * @param   cFrameBuf               Size (in frames) of the buffer to store audio frames into.
     147 * @param   pcFramesRead            Returns number of read audio frames. Optional.
    149148 *
    150149 * @remark  This function is not thread safe!
    151150 */
    152 int AudioMixBufPeek(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToRead,
    153                     PPDMAUDIOSAMPLE paSampleBuf, uint32_t cSampleBuf, uint32_t *pcSamplesRead)
    154 {
    155     AssertPtrReturn(pMixBuf,     VERR_INVALID_POINTER);
    156     AssertPtrReturn(paSampleBuf, VERR_INVALID_POINTER);
    157     AssertReturn(cSampleBuf,     VERR_INVALID_PARAMETER);
     151int AudioMixBufPeek(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFramesToRead,
     152                    PPDMAUDIOFRAME paFrameBuf, uint32_t cFrameBuf, uint32_t *pcFramesRead)
     153{
     154    AssertPtrReturn(pMixBuf,    VERR_INVALID_POINTER);
     155    AssertPtrReturn(paFrameBuf, VERR_INVALID_POINTER);
     156    AssertReturn(cFrameBuf,     VERR_INVALID_PARAMETER);
    158157    /* pcRead is optional. */
    159158
    160159    int rc;
    161160
    162     if (!cSamplesToRead)
    163     {
    164         if (pcSamplesRead)
    165             *pcSamplesRead = 0;
     161    if (!cFramesToRead)
     162    {
     163        if (pcFramesRead)
     164            *pcFramesRead = 0;
    166165        return VINF_SUCCESS;
    167166    }
    168167
    169168    uint32_t cRead;
    170     if (pMixBuf->offRead + cSamplesToRead > pMixBuf->cSamples)
    171     {
    172         cRead = pMixBuf->cSamples - pMixBuf->offRead;
     169    if (pMixBuf->offRead + cFramesToRead > pMixBuf->cFrames)
     170    {
     171        cRead = pMixBuf->cFrames - pMixBuf->offRead;
    173172        rc = VINF_AUDIO_MORE_DATA_AVAILABLE;
    174173    }
    175174    else
    176175    {
    177         cRead = cSamplesToRead;
     176        cRead = cFramesToRead;
    178177        rc = VINF_SUCCESS;
    179178    }
    180179
    181     if (cRead > cSampleBuf)
    182     {
    183         cRead = cSampleBuf;
     180    if (cRead > cFrameBuf)
     181    {
     182        cRead = cFrameBuf;
    184183        rc = VINF_AUDIO_MORE_DATA_AVAILABLE;
    185184    }
     
    187186    if (cRead)
    188187    {
    189         memcpy(paSampleBuf, &pMixBuf->pSamples[pMixBuf->offRead], sizeof(PDMAUDIOSAMPLE) * cRead);
    190 
    191         pMixBuf->offRead = (pMixBuf->offRead + cRead) % pMixBuf->cSamples;
    192         Assert(pMixBuf->offRead <= pMixBuf->cSamples);
     188        memcpy(paFrameBuf, &pMixBuf->pFrames[pMixBuf->offRead], sizeof(PDMAUDIOFRAME) * cRead);
     189
     190        pMixBuf->offRead = (pMixBuf->offRead + cRead) % pMixBuf->cFrames;
     191        Assert(pMixBuf->offRead <= pMixBuf->cFrames);
    193192        pMixBuf->cUsed  -= RT_MIN(cRead, pMixBuf->cUsed);
    194193    }
    195194
    196     if (pcSamplesRead)
    197         *pcSamplesRead = cRead;
     195    if (pcFramesRead)
     196        *pcFramesRead = cRead;
    198197
    199198    return rc;
     
    201200
    202201/**
    203  * Returns a mutable pointer to the mixing buffer's audio sample buffer for writing raw
    204  * audio samples.
     202 * Returns a mutable pointer to the mixing buffer's audio frame buffer for writing raw
     203 * audio frames.
    205204 *
    206205 * @return  IPRT status code. VINF_TRY_AGAIN for getting next pointer at beginning (circular).
    207  * @param   pMixBuf                 Mixing buffer to acquire audio samples from.
    208  * @param   cSamples                Number of requested audio samples to write.
    209  * @param   ppvSamples              Returns a mutable pointer to the buffer's audio sample data.
    210  * @param   pcSamplesToWrite        Number of available audio samples to write.
     206 * @param   pMixBuf                 Mixing buffer to acquire audio frames from.
     207 * @param   cFrames                 Number of requested audio frames to write.
     208 * @param   ppvFrames               Returns a mutable pointer to the buffer's audio frame data.
     209 * @param   pcFramesToWrite         Number of available audio frames to write.
    211210 *
    212211 * @remark  This function is not thread safe!
    213212 */
    214 int AudioMixBufPeekMutable(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamples,
    215                            PPDMAUDIOSAMPLE *ppvSamples, uint32_t *pcSamplesToWrite)
    216 {
    217     AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER);
    218     AssertPtrReturn(ppvSamples, VERR_INVALID_POINTER);
    219     AssertPtrReturn(pcSamplesToWrite, VERR_INVALID_POINTER);
     213int AudioMixBufPeekMutable(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFrames,
     214                           PPDMAUDIOFRAME *ppvFrames, uint32_t *pcFramesToWrite)
     215{
     216    AssertPtrReturn(pMixBuf,         VERR_INVALID_POINTER);
     217    AssertPtrReturn(ppvFrames,      VERR_INVALID_POINTER);
     218    AssertPtrReturn(pcFramesToWrite, VERR_INVALID_POINTER);
    220219
    221220    int rc;
    222221
    223     if (!cSamples)
    224     {
    225         *pcSamplesToWrite = 0;
     222    if (!cFrames)
     223    {
     224        *pcFramesToWrite = 0;
    226225        return VINF_SUCCESS;
    227226    }
    228227
    229     uint32_t cSamplesToWrite;
    230     if (pMixBuf->offWrite + cSamples > pMixBuf->cSamples)
    231     {
    232         cSamplesToWrite = pMixBuf->cSamples - pMixBuf->offWrite;
     228    uint32_t cFramesToWrite;
     229    if (pMixBuf->offWrite + cFrames > pMixBuf->cFrames)
     230    {
     231        cFramesToWrite = pMixBuf->cFrames - pMixBuf->offWrite;
    233232        rc = VINF_TRY_AGAIN;
    234233    }
    235234    else
    236235    {
    237         cSamplesToWrite = cSamples;
     236        cFramesToWrite = cFrames;
    238237        rc = VINF_SUCCESS;
    239238    }
    240239
    241     *ppvSamples = &pMixBuf->pSamples[pMixBuf->offWrite];
    242     AssertPtr(ppvSamples);
    243 
    244     pMixBuf->offWrite = (pMixBuf->offWrite + cSamplesToWrite) % pMixBuf->cSamples;
    245     Assert(pMixBuf->offWrite <= pMixBuf->cSamples);
    246     pMixBuf->cUsed += RT_MIN(cSamplesToWrite, pMixBuf->cUsed);
    247 
    248     *pcSamplesToWrite = cSamplesToWrite;
     240    *ppvFrames = &pMixBuf->pFrames[pMixBuf->offWrite];
     241    AssertPtr(ppvFrames);
     242
     243    pMixBuf->offWrite = (pMixBuf->offWrite + cFramesToWrite) % pMixBuf->cFrames;
     244    Assert(pMixBuf->offWrite <= pMixBuf->cFrames);
     245    pMixBuf->cUsed += RT_MIN(cFramesToWrite, pMixBuf->cUsed);
     246
     247    *pcFramesToWrite = cFramesToWrite;
    249248
    250249    return rc;
     
    252251
    253252/**
    254  * Clears the entire sample buffer.
     253 * Clears the entire frame buffer.
    255254 *
    256255 * @param   pMixBuf                 Mixing buffer to clear.
     
    261260    AssertPtrReturnVoid(pMixBuf);
    262261
    263     if (pMixBuf->cSamples)
    264         RT_BZERO(pMixBuf->pSamples, pMixBuf->cSamples * sizeof(PDMAUDIOSAMPLE));
    265 }
    266 
    267 /**
    268  * Clears (zeroes) the buffer by a certain amount of (used) samples and
     262    if (pMixBuf->cFrames)
     263        RT_BZERO(pMixBuf->pFrames, pMixBuf->cFrames * sizeof(PDMAUDIOFRAME));
     264}
     265
     266/**
     267 * Clears (zeroes) the buffer by a certain amount of (used) frames and
    269268 * keeps track to eventually assigned children buffers.
    270269 *
    271270 * @param   pMixBuf                 Mixing buffer to clear.
    272  * @param   cSamplesToClear         Number of audio samples to clear.
    273  */
    274 void AudioMixBufFinish(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToClear)
    275 {
    276     AUDMIXBUF_LOG(("cSamplesToClear=%RU32\n", cSamplesToClear));
     271 * @param   cFramesToClear          Number of audio frames to clear.
     272 */
     273void AudioMixBufFinish(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFramesToClear)
     274{
     275    AUDMIXBUF_LOG(("cFramesToClear=%RU32\n", cFramesToClear));
    277276    AUDMIXBUF_LOG(("%s: offRead=%RU32, cUsed=%RU32\n",
    278277                   pMixBuf->pszName, pMixBuf->offRead, pMixBuf->cUsed));
     
    282281    {
    283282        AUDMIXBUF_LOG(("\t%s: cMixed=%RU32 -> %RU32\n",
    284                        pIter->pszName, pIter->cMixed, pIter->cMixed - cSamplesToClear));
    285 
    286         pIter->cMixed -= RT_MIN(pIter->cMixed, cSamplesToClear);
     283                       pIter->pszName, pIter->cMixed, pIter->cMixed - cFramesToClear));
     284
     285        pIter->cMixed -= RT_MIN(pIter->cMixed, cFramesToClear);
    287286        /* Note: Do not increment pIter->cUsed here, as this gets done when reading from that buffer using AudioMixBufReadXXX. */
    288287    }
    289288
    290     Assert(cSamplesToClear <= pMixBuf->cSamples);
     289    Assert(cFramesToClear <= pMixBuf->cFrames);
    291290
    292291    uint32_t cClearOff;
     
    294293
    295294    /* Clear end of buffer (wrap around). */
    296     if (cSamplesToClear > pMixBuf->offRead)
    297     {
    298         cClearOff = pMixBuf->cSamples - (cSamplesToClear - pMixBuf->offRead);
    299         cClearLen = pMixBuf->cSamples - cClearOff;
     295    if (cFramesToClear > pMixBuf->offRead)
     296    {
     297        cClearOff = pMixBuf->cFrames - (cFramesToClear - pMixBuf->offRead);
     298        cClearLen = pMixBuf->cFrames - cClearOff;
    300299
    301300        AUDMIXBUF_LOG(("Clearing1: %RU32 - %RU32\n", cClearOff, cClearOff + cClearLen));
    302301
    303         RT_BZERO(pMixBuf->pSamples + cClearOff, cClearLen * sizeof(PDMAUDIOSAMPLE));
    304 
    305         Assert(cSamplesToClear >= cClearLen);
    306         cSamplesToClear -= cClearLen;
     302        RT_BZERO(pMixBuf->pFrames + cClearOff, cClearLen * sizeof(PDMAUDIOFRAME));
     303
     304        Assert(cFramesToClear >= cClearLen);
     305        cFramesToClear -= cClearLen;
    307306    }
    308307
    309308    /* Clear beginning of buffer. */
    310     if (   cSamplesToClear
     309    if (   cFramesToClear
    311310        && pMixBuf->offRead)
    312311    {
    313         Assert(pMixBuf->offRead >= cSamplesToClear);
    314 
    315         cClearOff = pMixBuf->offRead - cSamplesToClear;
    316         cClearLen = cSamplesToClear;
    317 
    318         Assert(cClearOff + cClearLen <= pMixBuf->cSamples);
     312        Assert(pMixBuf->offRead >= cFramesToClear);
     313
     314        cClearOff = pMixBuf->offRead - cFramesToClear;
     315        cClearLen = cFramesToClear;
     316
     317        Assert(cClearOff + cClearLen <= pMixBuf->cFrames);
    319318
    320319        AUDMIXBUF_LOG(("Clearing2: %RU32 - %RU32\n", cClearOff, cClearOff + cClearLen));
    321320
    322         RT_BZERO(pMixBuf->pSamples + cClearOff, cClearLen * sizeof(PDMAUDIOSAMPLE));
     321        RT_BZERO(pMixBuf->pFrames + cClearOff, cClearLen * sizeof(PDMAUDIOFRAME));
    323322    }
    324323}
     
    350349    }
    351350
    352     if (pMixBuf->pSamples)
    353     {
    354         Assert(pMixBuf->cSamples);
    355 
    356         RTMemFree(pMixBuf->pSamples);
    357         pMixBuf->pSamples = NULL;
    358     }
    359 
    360     pMixBuf->cSamples = 0;
    361 }
    362 
    363 /**
    364  * Returns the size (in audio samples) of free audio buffer space.
    365  *
    366  * @return  uint32_t                Size (in audio samples) of free audio buffer space.
     351    if (pMixBuf->pFrames)
     352    {
     353        Assert(pMixBuf->cFrames);
     354
     355        RTMemFree(pMixBuf->pFrames);
     356        pMixBuf->pFrames = NULL;
     357    }
     358
     359    pMixBuf->cFrames = 0;
     360}
     361
     362/**
     363 * Returns the size (in audio frames) of free audio buffer space.
     364 *
     365 * @return  uint32_t                Size (in audio frames) of free audio buffer space.
    367366 * @param   pMixBuf                 Mixing buffer to return free size for.
    368367 */
     
    371370    AssertPtrReturn(pMixBuf, 0);
    372371
    373     uint32_t cSamples, cSamplesFree;
     372    uint32_t cFrames, cFramesFree;
    374373    if (pMixBuf->pParent)
    375374    {
    376375        /*
    377          * As a linked child buffer we want to know how many samples
     376         * As a linked child buffer we want to know how many frames
    378377         * already have been consumed by the parent.
    379378         */
    380         cSamples = pMixBuf->pParent->cSamples;
    381 
    382         Assert(pMixBuf->cMixed <= cSamples);
    383         cSamplesFree = cSamples - pMixBuf->cMixed;
     379        cFrames = pMixBuf->pParent->cFrames;
     380
     381        Assert(pMixBuf->cMixed <= cFrames);
     382        cFramesFree = cFrames - pMixBuf->cMixed;
    384383    }
    385384    else /* As a parent. */
    386385    {
    387         cSamples     = pMixBuf->cSamples;
    388         Assert(cSamples >= pMixBuf->cUsed);
    389         cSamplesFree = pMixBuf->cSamples - pMixBuf->cUsed;
    390     }
    391 
    392     AUDMIXBUF_LOG(("%s: %RU32 of %RU32\n", pMixBuf->pszName, cSamplesFree, cSamples));
    393     return cSamplesFree;
     386        cFrames     = pMixBuf->cFrames;
     387        Assert(cFrames >= pMixBuf->cUsed);
     388        cFramesFree = pMixBuf->cFrames - pMixBuf->cUsed;
     389    }
     390
     391    AUDMIXBUF_LOG(("%s: %RU32 of %RU32\n", pMixBuf->pszName, cFramesFree, cFrames));
     392    return cFramesFree;
    394393}
    395394
     
    402401uint32_t AudioMixBufFreeBytes(PPDMAUDIOMIXBUF pMixBuf)
    403402{
    404     return AUDIOMIXBUF_S2B(pMixBuf, AudioMixBufFree(pMixBuf));
    405 }
    406 
    407 /**
    408  * Allocates the internal audio sample buffer.
     403    return AUDIOMIXBUF_F2B(pMixBuf, AudioMixBufFree(pMixBuf));
     404}
     405
     406/**
     407 * Allocates the internal audio frame buffer.
    409408 *
    410409 * @return  IPRT status code.
    411  * @param   pMixBuf                 Mixing buffer to allocate sample buffer for.
    412  * @param   cSamples                Number of audio samples to allocate.
    413  */
    414 static int audioMixBufAlloc(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamples)
     410 * @param   pMixBuf                 Mixing buffer to allocate frame buffer for.
     411 * @param   cFrames                 Number of audio frames to allocate.
     412 */
     413static int audioMixBufAlloc(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFrames)
    415414{
    416415    AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER);
    417     AssertReturn(cSamples, VERR_INVALID_PARAMETER);
    418 
    419     AUDMIXBUF_LOG(("%s: cSamples=%RU32\n", pMixBuf->pszName, cSamples));
    420 
    421     size_t cbSamples = cSamples * sizeof(PDMAUDIOSAMPLE);
    422     pMixBuf->pSamples = (PPDMAUDIOSAMPLE)RTMemAllocZ(cbSamples);
    423     if (pMixBuf->pSamples)
    424     {
    425         pMixBuf->cSamples = cSamples;
     416    AssertReturn(cFrames, VERR_INVALID_PARAMETER);
     417
     418    AUDMIXBUF_LOG(("%s: cFrames=%RU32\n", pMixBuf->pszName, cFrames));
     419
     420    size_t cbFrames = cFrames * sizeof(PDMAUDIOFRAME);
     421    pMixBuf->pFrames = (PPDMAUDIOFRAME)RTMemAllocZ(cbFrames);
     422    if (pMixBuf->pFrames)
     423    {
     424        pMixBuf->cFrames = cFrames;
    426425        return VINF_SUCCESS;
    427426    }
     
    467466    } \
    468467    \
    469     DECLCALLBACK(uint32_t) audioMixBufConvFrom##_aName##Stereo(PPDMAUDIOSAMPLE paDst, const void *pvSrc, uint32_t cbSrc, \
     468    DECLCALLBACK(uint32_t) audioMixBufConvFrom##_aName##Stereo(PPDMAUDIOFRAME paDst, const void *pvSrc, uint32_t cbSrc, \
    470469                                                               PCPDMAUDMIXBUFCONVOPTS pOpts) \
    471470    { \
    472471        _aType const *pSrc = (_aType const *)pvSrc; \
    473         uint32_t cSamples = RT_MIN(pOpts->cSamples, cbSrc / sizeof(_aType)); \
    474         AUDMIXBUF_MACRO_LOG(("cSamples=%RU32, BpS=%zu, lVol=%RU32, rVol=%RU32\n", \
    475                              pOpts->cSamples, sizeof(_aType), pOpts->From.Volume.uLeft, pOpts->From.Volume.uRight)); \
    476         for (uint32_t i = 0; i < cSamples; i++) \
     472        uint32_t cFrames = RT_MIN(pOpts->cFrames, cbSrc / sizeof(_aType)); \
     473        AUDMIXBUF_MACRO_LOG(("cFrames=%RU32, BpS=%zu, lVol=%RU32, rVol=%RU32\n", \
     474                             pOpts->cFrames, sizeof(_aType), pOpts->From.Volume.uLeft, pOpts->From.Volume.uRight)); \
     475        for (uint32_t i = 0; i < cFrames; i++) \
    477476        { \
    478477            paDst->i64LSample = ASMMult2xS32RetS64((int32_t)audioMixBufClipFrom##_aName(*pSrc++), pOpts->From.Volume.uLeft ) >> AUDIOMIXBUF_VOL_SHIFT; \
     
    481480        } \
    482481        \
    483         return cSamples; \
     482        return cFrames; \
    484483    } \
    485484    \
    486     DECLCALLBACK(uint32_t) audioMixBufConvFrom##_aName##Mono(PPDMAUDIOSAMPLE paDst, const void *pvSrc, uint32_t cbSrc, \
     485    DECLCALLBACK(uint32_t) audioMixBufConvFrom##_aName##Mono(PPDMAUDIOFRAME paDst, const void *pvSrc, uint32_t cbSrc, \
    487486                                                             PCPDMAUDMIXBUFCONVOPTS pOpts) \
    488487    { \
    489488        _aType const *pSrc = (_aType const *)pvSrc; \
    490         const uint32_t cSamples = RT_MIN(pOpts->cSamples, cbSrc / sizeof(_aType)); \
    491         AUDMIXBUF_MACRO_LOG(("cSamples=%RU32, BpS=%zu, lVol=%RU32, rVol=%RU32\n", \
    492                              cSamples, sizeof(_aType), pOpts->From.Volume.uLeft, pOpts->From.Volume.uRight)); \
    493         for (uint32_t i = 0; i < cSamples; i++) \
     489        const uint32_t cFrames = RT_MIN(pOpts->cFrames, cbSrc / sizeof(_aType)); \
     490        AUDMIXBUF_MACRO_LOG(("cFrames=%RU32, BpS=%zu, lVol=%RU32, rVol=%RU32\n", \
     491                             cFrames, sizeof(_aType), pOpts->From.Volume.uLeft, pOpts->From.Volume.uRight)); \
     492        for (uint32_t i = 0; i < cFrames; i++) \
    494493        { \
    495494            paDst->i64LSample = ASMMult2xS32RetS64((int32_t)audioMixBufClipFrom##_aName(*pSrc), pOpts->From.Volume.uLeft)  >> AUDIOMIXBUF_VOL_SHIFT; \
     
    499498        } \
    500499        \
    501         return cSamples; \
     500        return cFrames; \
    502501    } \
    503502    \
    504     DECLCALLBACK(void) audioMixBufConvTo##_aName##Stereo(void *pvDst, PCPDMAUDIOSAMPLE paSrc, PCPDMAUDMIXBUFCONVOPTS pOpts) \
     503    DECLCALLBACK(void) audioMixBufConvTo##_aName##Stereo(void *pvDst, PCPDMAUDIOFRAME paSrc, PCPDMAUDMIXBUFCONVOPTS pOpts) \
    505504    { \
    506         PCPDMAUDIOSAMPLE pSrc = paSrc; \
     505        PCPDMAUDIOFRAME pSrc = paSrc; \
    507506        _aType *pDst = (_aType *)pvDst; \
    508507        _aType l, r; \
    509         uint32_t cSamples = pOpts->cSamples; \
    510         while (cSamples--) \
     508        uint32_t cFrames = pOpts->cFrames; \
     509        while (cFrames--) \
    511510        { \
    512511            AUDMIXBUF_MACRO_LOG(("%p: l=%RI64, r=%RI64\n", pSrc, pSrc->i64LSample, pSrc->i64RSample)); \
     
    520519    } \
    521520    \
    522     DECLCALLBACK(void) audioMixBufConvTo##_aName##Mono(void *pvDst, PCPDMAUDIOSAMPLE paSrc, PCPDMAUDMIXBUFCONVOPTS pOpts) \
     521    DECLCALLBACK(void) audioMixBufConvTo##_aName##Mono(void *pvDst, PCPDMAUDIOFRAME paSrc, PCPDMAUDMIXBUFCONVOPTS pOpts) \
    523522    { \
    524         PCPDMAUDIOSAMPLE pSrc = paSrc; \
     523        PCPDMAUDIOFRAME pSrc = paSrc; \
    525524        _aType *pDst = (_aType *)pvDst; \
    526         uint32_t cSamples = pOpts->cSamples; \
    527         while (cSamples--) \
     525        uint32_t cFrames = pOpts->cFrames; \
     526        while (cFrames--) \
    528527        { \
    529528            *pDst++ = audioMixBufClipTo##_aName((pSrc->i64LSample + pSrc->i64RSample) / 2); \
     
    548547
    549548#define AUDMIXBUF_MIXOP(_aName, _aOp) \
    550     static void audioMixBufOp##_aName(PPDMAUDIOSAMPLE paDst, uint32_t cDstSamples, \
    551                                       PPDMAUDIOSAMPLE paSrc, uint32_t cSrcSamples, \
     549    static void audioMixBufOp##_aName(PPDMAUDIOFRAME paDst, uint32_t cDstFrames, \
     550                                      PPDMAUDIOFRAME paSrc, uint32_t cSrcFrames, \
    552551                                      PPDMAUDIOSTRMRATE pRate, \
    553552                                      uint32_t *pcDstWritten, uint32_t *pcSrcRead) \
    554553    { \
    555         AUDMIXBUF_MACRO_LOG(("cSrcSamples=%RU32, cDstSamples=%RU32\n", cSrcSamples, cDstSamples)); \
     554        AUDMIXBUF_MACRO_LOG(("cSrcFrames=%RU32, cDstFrames=%RU32\n", cSrcFrames, cDstFrames)); \
    556555        AUDMIXBUF_MACRO_LOG(("Rate: srcOffset=%RU32, dstOffset=%RU32, dstInc=%RU32\n", \
    557556                             pRate->srcOffset, \
     
    560559        if (pRate->dstInc == (UINT64_C(1) + UINT32_MAX)) /* No conversion needed? */ \
    561560        { \
    562             uint32_t cSamples = RT_MIN(cSrcSamples, cDstSamples); \
    563             AUDMIXBUF_MACRO_LOG(("cSamples=%RU32\n", cSamples)); \
    564             for (uint32_t i = 0; i < cSamples; i++) \
     561            uint32_t cFrames = RT_MIN(cSrcFrames, cDstFrames); \
     562            AUDMIXBUF_MACRO_LOG(("cFrames=%RU32\n", cFrames)); \
     563            for (uint32_t i = 0; i < cFrames; i++) \
    565564            { \
    566565                paDst[i].i64LSample _aOp paSrc[i].i64LSample; \
     
    569568            \
    570569            if (pcDstWritten) \
    571                 *pcDstWritten = cSamples; \
     570                *pcDstWritten = cFrames; \
    572571            if (pcSrcRead) \
    573                 *pcSrcRead = cSamples; \
     572                *pcSrcRead = cFrames; \
    574573            return; \
    575574        } \
    576575        \
    577         PPDMAUDIOSAMPLE paSrcStart = paSrc; \
    578         PPDMAUDIOSAMPLE paSrcEnd   = paSrc + cSrcSamples; \
    579         PPDMAUDIOSAMPLE paDstStart = paDst; \
    580         PPDMAUDIOSAMPLE paDstEnd   = paDst + cDstSamples; \
    581         PDMAUDIOSAMPLE  samCur     = { 0 }; \
    582         PDMAUDIOSAMPLE  samOut; \
    583         PDMAUDIOSAMPLE  samLast    = pRate->srcSampleLast; \
     576        PPDMAUDIOFRAME paSrcStart = paSrc; \
     577        PPDMAUDIOFRAME paSrcEnd   = paSrc + cSrcFrames; \
     578        PPDMAUDIOFRAME paDstStart = paDst; \
     579        PPDMAUDIOFRAME paDstEnd   = paDst + cDstFrames; \
     580        PDMAUDIOFRAME  frameCur   = { 0 }; \
     581        PDMAUDIOFRAME  frameOut; \
     582        PDMAUDIOFRAME  frameLast  = pRate->srcFrameLast; \
    584583        \
    585584        while (paDst < paDstEnd) \
     
    593592            { \
    594593                Assert(paSrc <= paSrcEnd); \
    595                 samLast = *paSrc++; \
     594                frameLast = *paSrc++; \
    596595                pRate->srcOffset++; \
    597596                if (paSrc == paSrcEnd) \
     
    603602                break; \
    604603            \
    605             samCur = *paSrc; \
     604            frameCur = *paSrc; \
    606605            \
    607606            /* Interpolate. */ \
    608607            int64_t iDstOffInt = pRate->dstOffset & UINT32_MAX; \
    609608            \
    610             samOut.i64LSample = (samLast.i64LSample * ((int64_t) (INT64_C(1) << 32) - iDstOffInt) + samCur.i64LSample * iDstOffInt) >> 32; \
    611             samOut.i64RSample = (samLast.i64RSample * ((int64_t) (INT64_C(1) << 32) - iDstOffInt) + samCur.i64RSample * iDstOffInt) >> 32; \
     609            frameOut.i64LSample = (frameLast.i64LSample * ((int64_t) (INT64_C(1) << 32) - iDstOffInt) + frameCur.i64LSample * iDstOffInt) >> 32; \
     610            frameOut.i64RSample = (frameLast.i64RSample * ((int64_t) (INT64_C(1) << 32) - iDstOffInt) + frameCur.i64RSample * iDstOffInt) >> 32; \
    612611            \
    613             paDst->i64LSample _aOp samOut.i64LSample; \
    614             paDst->i64RSample _aOp samOut.i64RSample; \
     612            paDst->i64LSample _aOp frameOut.i64LSample; \
     613            paDst->i64RSample _aOp frameOut.i64RSample; \
    615614            \
    616615            AUDMIXBUF_MACRO_LOG(("\tiDstOffInt=%RI64, l=%RI64, r=%RI64 (cur l=%RI64, r=%RI64)\n", \
    617616                                 iDstOffInt, \
    618617                                 paDst->i64LSample >> 32, paDst->i64RSample >> 32, \
    619                                  samCur.i64LSample >> 32, samCur.i64RSample >> 32)); \
     618                                 frameCur.i64LSample >> 32, frameCur.i64RSample >> 32)); \
    620619            \
    621620            paDst++; \
     
    626625        } \
    627626        \
    628         AUDMIXBUF_MACRO_LOG(("%zu source samples -> %zu dest samples\n", paSrc - paSrcStart, paDst - paDstStart)); \
     627        AUDMIXBUF_MACRO_LOG(("%zu source frames -> %zu dest frames\n", paSrc - paSrcStart, paDst - paDstStart)); \
    629628        \
    630         pRate->srcSampleLast = samLast; \
     629        pRate->srcFrameLast = frameLast; \
    631630        \
    632631        AUDMIXBUF_MACRO_LOG(("pRate->srcSampleLast l=%RI64, r=%RI64\n", \
    633                               pRate->srcSampleLast.i64LSample, pRate->srcSampleLast.i64RSample)); \
     632                              pRate->srcFrameLast.i64LSample, pRate->srcFrameLast.i64RSample)); \
    634633        \
    635634        if (pcDstWritten) \
     
    651650/** Dummy conversion used when the source is muted. */
    652651static DECLCALLBACK(uint32_t)
    653 audioMixBufConvFromSilence(PPDMAUDIOSAMPLE paDst, const void *pvSrc, uint32_t cbSrc, PCPDMAUDMIXBUFCONVOPTS pOpts)
     652audioMixBufConvFromSilence(PPDMAUDIOFRAME paDst, const void *pvSrc, uint32_t cbSrc, PCPDMAUDMIXBUFCONVOPTS pOpts)
    654653{
    655654    RT_NOREF(cbSrc, pvSrc);
    656655
    657656    /* Internally zero always corresponds to silence. */
    658     RT_BZERO(paDst, pOpts->cSamples * sizeof(paDst[0]));
    659     return pOpts->cSamples;
     657    RT_BZERO(paDst, pOpts->cFrames * sizeof(paDst[0]));
     658    return pOpts->cFrames;
    660659}
    661660
    662661/**
    663662 * Looks up the matching conversion (macro) routine for converting
    664  * audio samples from a source format.
     663 * audio frames from a source format.
    665664 *
    666665 ** @todo Speed up the lookup by binding it to the actual stream state.
     
    722721/**
    723722 * Looks up the matching conversion (macro) routine for converting
    724  * audio samples to a destination format.
     723 * audio frames to a destination format.
    725724 *
    726725 ** @todo Speed up the lookup by binding it to the actual stream state.
     
    811810 * @param   pszName                 Name of mixing buffer for easier identification. Optional.
    812811 * @param   pProps                  PCM audio properties to use for the mixing buffer.
    813  * @param   cSamples                Maximum number of audio samples the mixing buffer can hold.
    814  */
    815 int AudioMixBufInit(PPDMAUDIOMIXBUF pMixBuf, const char *pszName, PPDMAUDIOPCMPROPS pProps, uint32_t cSamples)
     812 * @param   cFrames                 Maximum number of audio frames the mixing buffer can hold.
     813 */
     814int AudioMixBufInit(PPDMAUDIOMIXBUF pMixBuf, const char *pszName, PPDMAUDIOPCMPROPS pProps, uint32_t cFrames)
    816815{
    817816    AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER);
     
    824823    pMixBuf->cChildren = 0;
    825824
    826     pMixBuf->pSamples = NULL;
    827     pMixBuf->cSamples = 0;
     825    pMixBuf->pFrames = NULL;
     826    pMixBuf->cFrames = 0;
    828827
    829828    pMixBuf->offRead  = 0;
     
    863862                   RT_BOOL(AUDMIXBUF_FMT_SIGNED(pMixBuf->AudioFmt))));
    864863
    865     return audioMixBufAlloc(pMixBuf, cSamples);
    866 }
    867 
    868 /**
    869  * Returns @c true if there are any audio samples available for processing,
     864    return audioMixBufAlloc(pMixBuf, cFrames);
     865}
     866
     867/**
     868 * Returns @c true if there are any audio frames available for processing,
    870869 * @c false if not.
    871870 *
    872  * @return  bool                    @c true if there are any audio samples available for processing, @c false if not.
     871 * @return  bool                    @c true if there are any audio frames available for processing, @c false if not.
    873872 * @param   pMixBuf                 Mixing buffer to return value for.
    874873 */
     
    926925
    927926    AssertMsgReturn(AUDMIXBUF_FMT_SAMPLE_FREQ(pParent->AudioFmt),
    928                     ("Parent sample frequency (Hz) not set\n"), VERR_INVALID_PARAMETER);
     927                    ("Parent frame frequency (Hz) not set\n"), VERR_INVALID_PARAMETER);
    929928    AssertMsgReturn(AUDMIXBUF_FMT_SAMPLE_FREQ(pMixBuf->AudioFmt),
    930929                    ("Buffer sample frequency (Hz) not set\n"), VERR_INVALID_PARAMETER);
     
    950949    int rc = VINF_SUCCESS;
    951950#if 0
    952     uint32_t cSamples = (uint32_t)RT_MIN(  ((uint64_t)pParent->cSamples << 32)
    953                                          / pMixBuf->iFreqRatio, _64K /* 64K samples max. */);
    954     if (!cSamples)
    955         cSamples = pParent->cSamples;
     951    uint32_t cFrames = (uint32_t)RT_MIN(  ((uint64_t)pParent->cFrames << 32)
     952                                         / pMixBuf->iFreqRatio, _64K /* 64K frames max. */);
     953    if (!cFrames)
     954        cFrames = pParent->cFrames;
    956955
    957956    int rc = VINF_SUCCESS;
    958957
    959     if (cSamples != pMixBuf->cSamples)
    960     {
    961         AUDMIXBUF_LOG(("%s: Reallocating samples %RU32 -> %RU32\n",
    962                        pMixBuf->pszName, pMixBuf->cSamples, cSamples));
    963 
    964         uint32_t cbSamples = cSamples * sizeof(PDMAUDIOSAMPLE);
     958    if (cFrames != pMixBuf->cFrames)
     959    {
     960        AUDMIXBUF_LOG(("%s: Reallocating frames %RU32 -> %RU32\n",
     961                       pMixBuf->pszName, pMixBuf->cFrames, cFrames));
     962
     963        uint32_t cbSamples = cFrames * sizeof(PDMAUDIOSAMPLE);
    965964        Assert(cbSamples);
    966965        pMixBuf->pSamples = (PPDMAUDIOSAMPLE)RTMemRealloc(pMixBuf->pSamples, cbSamples);
     
    970969        if (RT_SUCCESS(rc))
    971970        {
    972             pMixBuf->cSamples = cSamples;
     971            pMixBuf->cFrames = cFrames;
    973972
    974973            /* Make sure to zero the reallocated buffer so that it can be
     
    994993                               /            AUDMIXBUF_FMT_SAMPLE_FREQ(pParent->AudioFmt);
    995994
    996         AUDMIXBUF_LOG(("uThisHz=%RU32, uParentHz=%RU32, iFreqRatio=0x%RX64 (%RI64), uRateInc=0x%RX64 (%RU64), cSamples=%RU32 (%RU32 parent)\n",
     995        AUDMIXBUF_LOG(("uThisHz=%RU32, uParentHz=%RU32, iFreqRatio=0x%RX64 (%RI64), uRateInc=0x%RX64 (%RU64), cFrames=%RU32 (%RU32 parent)\n",
    997996                       AUDMIXBUF_FMT_SAMPLE_FREQ(pMixBuf->AudioFmt),
    998997                       AUDMIXBUF_FMT_SAMPLE_FREQ(pParent->AudioFmt),
    999998                       pMixBuf->iFreqRatio, pMixBuf->iFreqRatio,
    1000999                       pMixBuf->pRate->dstInc, pMixBuf->pRate->dstInc,
    1001                        pMixBuf->cSamples,
    1002                        pParent->cSamples));
     1000                       pMixBuf->cFrames,
     1001                       pParent->cFrames));
    10031002        AUDMIXBUF_LOG(("%s (%RU32Hz) -> %s (%RU32Hz)\n",
    10041003                       pMixBuf->pszName, AUDMIXBUF_FMT_SAMPLE_FREQ(pMixBuf->AudioFmt),
     
    10101009
    10111010/**
    1012  * Returns number of available live samples, that is, samples that
     1011 * Returns number of available live frames, that is, frames that
    10131012 * have been written into the mixing buffer but not have been processed yet.
    10141013 *
    1015  * For a parent buffer, this simply returns the currently used number of samples
     1014 * For a parent buffer, this simply returns the currently used number of frames
    10161015 * in the buffer.
    10171016 *
    1018  * For a child buffer, this returns the number of samples which have been mixed
     1017 * For a child buffer, this returns the number of frames which have been mixed
    10191018 * to the parent and were not processed by the parent yet.
    10201019 *
    1021  * @return  uint32_t                Number of live samples available.
     1020 * @return  uint32_t                Number of live frames available.
    10221021 * @param   pMixBuf                 Mixing buffer to return value for.
    10231022 */
     
    10271026
    10281027#ifdef RT_STRICT
    1029     uint32_t cSamples;
     1028    uint32_t cFrames;
    10301029#endif
    10311030    uint32_t cAvail;
     
    10331032    {
    10341033#ifdef RT_STRICT
    1035         /* Use the sample count from the parent, as
    1036          * pMixBuf->cMixed specifies the sample count
    1037          * in parent samples. */
    1038         cSamples = pMixBuf->pParent->cSamples;
     1034        /* Use the frame count from the parent, as
     1035         * pMixBuf->cMixed specifies the frame count
     1036         * in parent frames. */
     1037        cFrames = pMixBuf->pParent->cFrames;
    10391038#endif
    10401039        cAvail   = pMixBuf->cMixed;
     
    10431042    {
    10441043#ifdef RT_STRICT
    1045         cSamples = pMixBuf->cSamples;
     1044        cFrames = pMixBuf->cFrames;
    10461045#endif
    10471046        cAvail   = pMixBuf->cUsed;
    10481047    }
    10491048
    1050     Assert(cAvail <= cSamples);
     1049    Assert(cAvail <= cFrames);
    10511050    return cAvail;
    10521051}
    10531052
    10541053/**
    1055  * Mixes audio samples from a source mixing buffer to a destination mixing buffer.
     1054 * Mixes audio frames from a source mixing buffer to a destination mixing buffer.
    10561055 *
    10571056 * @return  IPRT status code.
     
    10611060 * @param   pDst                    Destination mixing buffer.
    10621061 * @param   pSrc                    Source mixing buffer.
    1063  * @param   cSrcOff                 Offset of source audio samples to mix.
    1064  * @param   cSrcSamples             Number of source audio samples to mix.
    1065  * @param   pcSrcMixed              Number of source audio samples successfully mixed. Optional.
    1066  */
    1067 static int audioMixBufMixTo(PPDMAUDIOMIXBUF pDst, PPDMAUDIOMIXBUF pSrc, uint32_t cSrcOff, uint32_t cSrcSamples,
     1062 * @param   cSrcOff                 Offset of source audio frames to mix.
     1063 * @param   cSrcFrames              Number of source audio frames to mix.
     1064 * @param   pcSrcMixed              Number of source audio frames successfully mixed. Optional.
     1065 */
     1066static int audioMixBufMixTo(PPDMAUDIOMIXBUF pDst, PPDMAUDIOMIXBUF pSrc, uint32_t cSrcOff, uint32_t cSrcFrames,
    10681067                            uint32_t *pcSrcMixed)
    10691068{
     
    10771076    uint32_t cWrittenTotal = 0;
    10781077
    1079     Assert(pSrc->cMixed <= pDst->cSamples);
     1078    Assert(pSrc->cMixed <= pDst->cFrames);
    10801079
    10811080    Assert(pSrc->cUsed >= pDst->cMixed);
    1082     Assert(pDst->cUsed <= pDst->cSamples);
     1081    Assert(pDst->cUsed <= pDst->cFrames);
    10831082
    10841083    uint32_t offSrcRead  = cSrcOff;
     
    10871086    uint32_t cDstMixed   = pSrc->cMixed;
    10881087
    1089     uint32_t cSrcAvail   = RT_MIN(cSrcSamples, pSrc->cUsed);
    1090     uint32_t cDstAvail   = pDst->cSamples - pDst->cUsed; /** @todo Use pDst->cMixed later? */
     1088    uint32_t cSrcAvail   = RT_MIN(cSrcFrames, pSrc->cUsed);
     1089    uint32_t cDstAvail   = pDst->cFrames - pDst->cUsed; /** @todo Use pDst->cMixed later? */
    10911090
    10921091    AUDMIXBUF_LOG(("%s (%RU32 available) -> %s (%RU32 available)\n",
     
    11121111    while (cSrcAvail && cDstAvail)
    11131112    {
    1114         cSrcToRead  = RT_MIN(cSrcAvail, pSrc->cSamples - offSrcRead);
    1115         cDstToWrite = RT_MIN(cDstAvail, pDst->cSamples - offDstWrite);
     1113        cSrcToRead  = RT_MIN(cSrcAvail, pSrc->cFrames - offSrcRead);
     1114        cDstToWrite = RT_MIN(cDstAvail, pDst->cFrames - offDstWrite);
    11161115
    11171116        AUDMIXBUF_LOG(("\tSource: %RU32 @ %RU32 -> reading %RU32\n", cSrcAvail, offSrcRead, cSrcToRead));
     
    11261125        cDstWritten = cSrcRead = 0;
    11271126
    1128         Assert(offSrcRead < pSrc->cSamples);
    1129         Assert(offSrcRead + cSrcToRead <= pSrc->cSamples);
    1130 
    1131         Assert(offDstWrite < pDst->cSamples);
    1132         Assert(offDstWrite + cDstToWrite <= pDst->cSamples);
    1133 
    1134         audioMixBufOpAssign(pDst->pSamples + offDstWrite, cDstToWrite,
    1135                             pSrc->pSamples + offSrcRead,  cSrcToRead,
     1127        Assert(offSrcRead < pSrc->cFrames);
     1128        Assert(offSrcRead + cSrcToRead <= pSrc->cFrames);
     1129
     1130        Assert(offDstWrite < pDst->cFrames);
     1131        Assert(offDstWrite + cDstToWrite <= pDst->cFrames);
     1132
     1133        audioMixBufOpAssign(pDst->pFrames + offDstWrite, cDstToWrite,
     1134                            pSrc->pFrames + offSrcRead,  cSrcToRead,
    11361135                            pSrc->pRate, &cDstWritten, &cSrcRead);
    11371136
     
    11391138        cWrittenTotal += cDstWritten;
    11401139
    1141         offSrcRead     = (offSrcRead  + cSrcRead)    % pSrc->cSamples;
    1142         offDstWrite    = (offDstWrite + cDstWritten) % pDst->cSamples;
     1140        offSrcRead     = (offSrcRead  + cSrcRead)    % pSrc->cFrames;
     1141        offDstWrite    = (offDstWrite + cDstWritten) % pDst->cFrames;
    11431142
    11441143        cDstMixed     += cDstWritten;
     
    11591158    pSrc->cUsed      -= RT_MIN(pSrc->cUsed, cReadTotal);
    11601159
    1161     /* Note: Always count in parent samples, as the rate can differ! */
    1162     pSrc->cMixed      = RT_MIN(cDstMixed, pDst->cSamples);
     1160    /* Note: Always count in parent frames, as the rate can differ! */
     1161    pSrc->cMixed      = RT_MIN(cDstMixed, pDst->cFrames);
    11631162
    11641163    pDst->offWrite    = offDstWrite;
    1165     Assert(pDst->offWrite <= pDst->cSamples);
    1166     Assert((pDst->cUsed + cWrittenTotal) <= pDst->cSamples);
     1164    Assert(pDst->offWrite <= pDst->cFrames);
     1165    Assert((pDst->cUsed + cWrittenTotal) <= pDst->cFrames);
    11671166    pDst->cUsed      += cWrittenTotal;
    11681167
    1169     /* If there are more used samples than fitting in the destination buffer,
     1168    /* If there are more used frames than fitting in the destination buffer,
    11701169     * adjust the values accordingly.
    11711170     *
    11721171     * This can happen if this routine has been called too often without
    11731172     * actually processing the destination buffer in between. */
    1174     if (pDst->cUsed > pDst->cSamples)
    1175     {
    1176         LogFunc(("%s: Warning: Destination buffer used %RU32 / %RU32 samples\n", pDst->pszName, pDst->cUsed, pDst->cSamples));
     1173    if (pDst->cUsed > pDst->cFrames)
     1174    {
     1175        LogFunc(("%s: Warning: Destination buffer used %RU32 / %RU32 frames\n", pDst->pszName, pDst->cUsed, pDst->cFrames));
    11771176        pDst->offWrite     = 0;
    1178         pDst->cUsed        = pDst->cSamples;
     1177        pDst->cUsed        = pDst->cFrames;
    11791178
    11801179        rc = VERR_BUFFER_OVERFLOW;
     
    11851184    audioMixBufDbgValidate(pDst);
    11861185
    1187     Assert(pSrc->cMixed <= pDst->cSamples);
     1186    Assert(pSrc->cMixed <= pDst->cFrames);
    11881187#endif
    11891188
     
    12001199        Assert(sizeof(auBuf) % 4 == 0);
    12011200
    1202         uint32_t cToRead = RT_MIN(AUDIOMIXBUF_B2S(pDst, sizeof(auBuf)), RT_MIN(cLeft, pDst->cSamples - offRead));
     1201        uint32_t cToRead = RT_MIN(AUDIOMIXBUF_B2F(pDst, sizeof(auBuf)), RT_MIN(cLeft, pDst->cFrames - offRead));
    12031202        Assert(cToRead <= pDst->cUsed);
    12041203
    12051204        PDMAUDMIXBUFCONVOPTS convOpts;
    12061205        RT_ZERO(convOpts);
    1207         convOpts.cSamples = cToRead;
    1208 
    1209         pDst->pfnConvTo(auBuf, pDst->pSamples + offRead, &convOpts);
     1206        convOpts.cFrames = cToRead;
     1207
     1208        pDst->pfnConvTo(auBuf, pDst->pFrames + offRead, &convOpts);
    12101209
    12111210        RTFILE fh;
     
    12141213        if (RT_SUCCESS(rc2))
    12151214        {
    1216             RTFileWrite(fh, auBuf, AUDIOMIXBUF_S2B(pDst, cToRead), NULL);
     1215            RTFileWrite(fh, auBuf, AUDIOMIXBUF_F2B(pDst, cToRead), NULL);
    12171216            RTFileClose(fh);
    12181217        }
    12191218
    1220         offRead  = (offRead + cToRead) % pDst->cSamples;
     1219        offRead  = (offRead + cToRead) % pDst->cFrames;
    12211220        cLeft   -= cToRead;
    12221221    }
     
    12361235
    12371236/**
    1238  * Mixes audio samples down to the parent mixing buffer, extended version.
     1237 * Mixes audio frames down to the parent mixing buffer, extended version.
    12391238 *
    12401239 * @return  IPRT status code. See audioMixBufMixTo() for a more detailed explanation.
    12411240 * @param   pMixBuf                 Source mixing buffer to mix to its parent.
    1242  * @param   cSrcOffset              Offset (in samples) of source mixing buffer.
    1243  * @param   cSrcSamples             Number of source audio samples to mix to its parent.
    1244  * @param   pcSrcMixed              Number of source audio samples successfully mixed. Optional.
    1245  */
    1246 int AudioMixBufMixToParentEx(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSrcOffset, uint32_t cSrcSamples, uint32_t *pcSrcMixed)
     1241 * @param   cSrcOffset              Offset (in frames) of source mixing buffer.
     1242 * @param   cSrcFrames              Number of source audio frames to mix to its parent.
     1243 * @param   pcSrcMixed              Number of source audio frames successfully mixed. Optional.
     1244 */
     1245int AudioMixBufMixToParentEx(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSrcOffset, uint32_t cSrcFrames, uint32_t *pcSrcMixed)
    12471246{
    12481247    AssertMsgReturn(VALID_PTR(pMixBuf->pParent),
     
    12501249                    VERR_INVALID_PARAMETER);
    12511250
    1252     return audioMixBufMixTo(pMixBuf->pParent, pMixBuf, cSrcOffset, cSrcSamples, pcSrcMixed);
    1253 }
    1254 
    1255 /**
    1256  * Mixes audio samples down to the parent mixing buffer.
     1251    return audioMixBufMixTo(pMixBuf->pParent, pMixBuf, cSrcOffset, cSrcFrames, pcSrcMixed);
     1252}
     1253
     1254/**
     1255 * Mixes audio frames down to the parent mixing buffer.
    12571256 *
    12581257 * @return  IPRT status code. See audioMixBufMixTo() for a more detailed explanation.
    12591258 * @param   pMixBuf                 Source mixing buffer to mix to its parent.
    1260  * @param   cSrcSamples             Number of source audio samples to mix to its parent.
    1261  * @param   pcSrcMixed              Number of source audio samples successfully mixed. Optional.
    1262  */
    1263 int AudioMixBufMixToParent(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSrcSamples, uint32_t *pcSrcMixed)
    1264 {
    1265     return audioMixBufMixTo(pMixBuf->pParent, pMixBuf, pMixBuf->offRead, cSrcSamples, pcSrcMixed);
     1259 * @param   cSrcFrames              Number of source audio frames to mix to its parent.
     1260 * @param   pcSrcMixed              Number of source audio frames successfully mixed. Optional.
     1261 */
     1262int AudioMixBufMixToParent(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSrcFrames, uint32_t *pcSrcMixed)
     1263{
     1264    return audioMixBufMixTo(pMixBuf->pParent, pMixBuf, pMixBuf->offRead, cSrcFrames, pcSrcMixed);
    12661265}
    12671266
     
    12811280    Log(("%s: %*s[%s] %s: offRead=%RU32, offWrite=%RU32, cMixed=%RU32 -> %RU32/%RU32\n",
    12821281         pszFunc, uIdtLvl * 4, "", fIsParent ? "PARENT" : "CHILD",
    1283          pMixBuf->pszName, pMixBuf->offRead, pMixBuf->offWrite, pMixBuf->cMixed, pMixBuf->cUsed, pMixBuf->cSamples));
     1282         pMixBuf->pszName, pMixBuf->offRead, pMixBuf->offWrite, pMixBuf->cMixed, pMixBuf->cUsed, pMixBuf->cFrames));
    12841283}
    12851284
     
    12921291DECL_FORCE_INLINE(bool) audioMixBufDbgValidate(PPDMAUDIOMIXBUF pMixBuf)
    12931292{
    1294     //const uint32_t offReadEnd  = (pMixBuf->offRead + pMixBuf->cUsed) % pMixBuf->cSamples;
    1295     //const uint32_t offWriteEnd = (pMixBuf->offWrite + (pMixBuf->cSamples - pMixBuf->cUsed)) % pMixBuf->cSamples;
     1293    //const uint32_t offReadEnd  = (pMixBuf->offRead + pMixBuf->cUsed) % pMixBuf->cFrames;
     1294    //const uint32_t offWriteEnd = (pMixBuf->offWrite + (pMixBuf->cFrames - pMixBuf->cUsed)) % pMixBuf->cFrames;
    12961295
    12971296    bool fValid = true;
    12981297
    1299     AssertStmt(pMixBuf->offRead  <= pMixBuf->cSamples, fValid = false);
    1300     AssertStmt(pMixBuf->offWrite <= pMixBuf->cSamples, fValid = false);
    1301     AssertStmt(pMixBuf->cUsed    <= pMixBuf->cSamples, fValid = false);
     1298    AssertStmt(pMixBuf->offRead  <= pMixBuf->cFrames, fValid = false);
     1299    AssertStmt(pMixBuf->offWrite <= pMixBuf->cFrames, fValid = false);
     1300    AssertStmt(pMixBuf->cUsed    <= pMixBuf->cFrames, fValid = false);
    13021301
    13031302    if (pMixBuf->offWrite > pMixBuf->offRead)
     
    13081307    else if (pMixBuf->offWrite < pMixBuf->offRead)
    13091308    {
    1310         if (pMixBuf->offWrite + pMixBuf->cSamples - pMixBuf->offRead != pMixBuf->cUsed)
     1309        if (pMixBuf->offWrite + pMixBuf->cFrames - pMixBuf->offRead != pMixBuf->cUsed)
    13111310            fValid = false;
    13121311    }
     
    14091408
    14101409/**
    1411  * Returns the total number of samples used.
     1410 * Returns the total number of frames used.
    14121411 *
    14131412 * @return  uint32_t
     
    14211420
    14221421/**
    1423  * Reads audio samples at a specific offset.
     1422 * Reads audio frames at a specific offset.
    14241423 *
    14251424 * @return  IPRT status code.
    1426  * @param   pMixBuf                 Mixing buffer to read audio samples from.
    1427  * @param   offSamples              Offset (in audio samples) to start reading from.
     1425 * @param   pMixBuf                 Mixing buffer to read audio frames from.
     1426 * @param   offFrames               Offset (in audio frames) to start reading from.
    14281427 * @param   pvBuf                   Pointer to buffer to write output to.
    14291428 * @param   cbBuf                   Size (in bytes) of buffer to write to.
     
    14311430 */
    14321431int AudioMixBufReadAt(PPDMAUDIOMIXBUF pMixBuf,
    1433                       uint32_t offSamples,
     1432                      uint32_t offFrames,
    14341433                      void *pvBuf, uint32_t cbBuf,
    14351434                      uint32_t *pcbRead)
    14361435{
    14371436    return AudioMixBufReadAtEx(pMixBuf, pMixBuf->AudioFmt,
    1438                                offSamples, pvBuf, cbBuf, pcbRead);
    1439 }
    1440 
    1441 /**
    1442  * Reads audio samples at a specific offset.
     1437                               offFrames, pvBuf, cbBuf, pcbRead);
     1438}
     1439
     1440/**
     1441 * Reads audio frames at a specific offset.
    14431442 * If the audio format of the mixing buffer and the requested audio format do
    14441443 * not match the output will be converted accordingly.
    14451444 *
    14461445 * @return  IPRT status code.
    1447  * @param   pMixBuf                 Mixing buffer to read audio samples from.
     1446 * @param   pMixBuf                 Mixing buffer to read audio frames from.
    14481447 * @param   enmFmt                  Audio format to use for output.
    1449  * @param   offSamples              Offset (in audio samples) to start reading from.
     1448 * @param   offFrames               Offset (in audio frames) to start reading from.
    14501449 * @param   pvBuf                   Pointer to buffer to write output to.
    14511450 * @param   cbBuf                   Size (in bytes) of buffer to write to.
     
    14531452 */
    14541453int AudioMixBufReadAtEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt,
    1455                         uint32_t offSamples,
     1454                        uint32_t offFrames,
    14561455                        void *pvBuf, uint32_t cbBuf,
    14571456                        uint32_t *pcbRead)
     
    14611460    /* pcbRead is optional. */
    14621461
    1463     uint32_t cDstSamples = pMixBuf->cSamples;
     1462    uint32_t cDstFrames = pMixBuf->cFrames;
    14641463    uint32_t cLive = pMixBuf->cUsed;
    14651464
    1466     uint32_t cDead = cDstSamples - cLive;
    1467     uint32_t cToProcess = (uint32_t)AUDIOMIXBUF_S2S_RATIO(pMixBuf, cDead);
    1468     cToProcess = RT_MIN(cToProcess, AUDIOMIXBUF_B2S(pMixBuf, cbBuf));
    1469 
    1470     AUDMIXBUF_LOG(("%s: offSamples=%RU32, cLive=%RU32, cDead=%RU32, cToProcess=%RU32\n",
    1471                    pMixBuf->pszName, offSamples, cLive, cDead, cToProcess));
     1465    uint32_t cDead = cDstFrames - cLive;
     1466    uint32_t cToProcess = (uint32_t)AUDIOMIXBUF_F2F_RATIO(pMixBuf, cDead);
     1467    cToProcess = RT_MIN(cToProcess, AUDIOMIXBUF_B2F(pMixBuf, cbBuf));
     1468
     1469    AUDMIXBUF_LOG(("%s: offFrames=%RU32, cLive=%RU32, cDead=%RU32, cToProcess=%RU32\n",
     1470                   pMixBuf->pszName, offFrames, cLive, cDead, cToProcess));
    14721471
    14731472    int rc;
     
    14861485            /* Note: No volume handling/conversion done in the conversion-to macros (yet). */
    14871486
    1488             convOpts.cSamples = cToProcess;
    1489 
    1490             pfnConvTo(pvBuf, pMixBuf->pSamples + offSamples, &convOpts);
     1487            convOpts.cFrames = cToProcess;
     1488
     1489            pfnConvTo(pvBuf, pMixBuf->pFrames + offFrames, &convOpts);
    14911490
    14921491#ifdef DEBUG
     
    15071506    {
    15081507        if (pcbRead)
    1509             *pcbRead = AUDIOMIXBUF_S2B(pMixBuf, cToProcess);
    1510     }
    1511 
    1512     AUDMIXBUF_LOG(("cbRead=%RU32, rc=%Rrc\n", AUDIOMIXBUF_S2B(pMixBuf, cToProcess), rc));
     1508            *pcbRead = AUDIOMIXBUF_F2B(pMixBuf, cToProcess);
     1509    }
     1510
     1511    AUDMIXBUF_LOG(("cbRead=%RU32, rc=%Rrc\n", AUDIOMIXBUF_F2B(pMixBuf, cToProcess), rc));
    15131512    return rc;
    15141513}
    15151514
    15161515/**
    1517  * Reads audio samples. The audio format of the mixing buffer will be used.
     1516 * Reads audio frames. The audio format of the mixing buffer will be used.
    15181517 *
    15191518 * @return  IPRT status code.
    1520  * @param   pMixBuf                 Mixing buffer to read audio samples from.
     1519 * @param   pMixBuf                 Mixing buffer to read audio frames from.
    15211520 * @param   pvBuf                   Pointer to buffer to write output to.
    15221521 * @param   cbBuf                   Size (in bytes) of buffer to write to.
    1523  * @param   pcRead                  Number of audio samples read. Optional.
     1522 * @param   pcRead                  Number of audio frames read. Optional.
    15241523 */
    15251524int AudioMixBufReadCirc(PPDMAUDIOMIXBUF pMixBuf, void *pvBuf, uint32_t cbBuf, uint32_t *pcRead)
     
    15291528
    15301529/**
    1531  * Reads audio samples in a specific audio format.
     1530 * Reads audio frames in a specific audio format.
    15321531 * If the audio format of the mixing buffer and the requested audio format do
    15331532 * not match the output will be converted accordingly.
    15341533 *
    15351534 * @return  IPRT status code.
    1536  * @param   pMixBuf                 Mixing buffer to read audio samples from.
     1535 * @param   pMixBuf                 Mixing buffer to read audio frames from.
    15371536 * @param   enmFmt                  Audio format to use for output.
    15381537 * @param   pvBuf                   Pointer to buffer to write output to.
    15391538 * @param   cbBuf                   Size (in bytes) of buffer to write to.
    1540  * @param   pcRead                  Number of audio samples read. Optional.
     1539 * @param   pcRead                  Number of audio frames read. Optional.
    15411540 */
    15421541int AudioMixBufReadCircEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, void *pvBuf, uint32_t cbBuf, uint32_t *pcRead)
     
    15471546    /* pcRead is optional. */
    15481547
    1549     /* Make sure that we at least have space for a full audio sample. */
    1550     AssertReturn(AUDIOMIXBUF_B2S(pMixBuf, cbBuf), VERR_INVALID_PARAMETER);
    1551 
    1552     uint32_t cToRead = RT_MIN(pMixBuf->cUsed, AUDIOMIXBUF_B2S(pMixBuf, cbBuf));
    1553 
    1554     AUDMIXBUF_LOG(("%s: cbBuf=%RU32 (%RU32 samples), cToRead=%RU32, fmtSrc=0x%x, fmtDst=0x%x\n",
    1555                    pMixBuf->pszName, cbBuf, AUDIOMIXBUF_B2S(pMixBuf, cbBuf), cToRead, pMixBuf->AudioFmt, enmFmt));
     1548    /* Make sure that we at least have space for a full audio frame. */
     1549    AssertReturn(AUDIOMIXBUF_B2F(pMixBuf, cbBuf), VERR_INVALID_PARAMETER);
     1550
     1551    uint32_t cToRead = RT_MIN(pMixBuf->cUsed, AUDIOMIXBUF_B2F(pMixBuf, cbBuf));
     1552
     1553    AUDMIXBUF_LOG(("%s: cbBuf=%RU32 (%RU32 frames), cToRead=%RU32, fmtSrc=0x%x, fmtDst=0x%x\n",
     1554                   pMixBuf->pszName, cbBuf, AUDIOMIXBUF_B2F(pMixBuf, cbBuf), cToRead, pMixBuf->AudioFmt, enmFmt));
    15561555
    15571556    if (!cToRead)
     
    15771576    }
    15781577
    1579     cToRead = RT_MIN(cToRead, pMixBuf->cSamples - pMixBuf->offRead);
     1578    cToRead = RT_MIN(cToRead, pMixBuf->cFrames - pMixBuf->offRead);
    15801579    if (cToRead)
    15811580    {
    15821581        PDMAUDMIXBUFCONVOPTS convOpts;
    15831582        RT_ZERO(convOpts);
    1584         convOpts.cSamples = cToRead;
     1583        convOpts.cFrames = cToRead;
    15851584
    15861585        AUDMIXBUF_LOG(("cToRead=%RU32\n", cToRead));
    15871586
    1588         pfnConvTo(pvBuf, pMixBuf->pSamples + pMixBuf->offRead, &convOpts);
     1587        pfnConvTo(pvBuf, pMixBuf->pFrames + pMixBuf->offRead, &convOpts);
    15891588
    15901589#ifdef AUDIOMIXBUF_DEBUG_DUMP_PCM_DATA
     
    15941593        if (RT_SUCCESS(rc2))
    15951594        {
    1596             RTFileWrite(fh, pvBuf, AUDIOMIXBUF_S2B(pMixBuf, cToRead), NULL);
     1595            RTFileWrite(fh, pvBuf, AUDIOMIXBUF_F2B(pMixBuf, cToRead), NULL);
    15971596            RTFileClose(fh);
    15981597        }
    15991598#endif
    1600         pMixBuf->offRead  = (pMixBuf->offRead + cToRead) % pMixBuf->cSamples;
     1599        pMixBuf->offRead  = (pMixBuf->offRead + cToRead) % pMixBuf->cFrames;
    16011600        Assert(pMixBuf->cUsed >= cToRead);
    16021601        pMixBuf->cUsed   -= cToRead;
     
    16101609#endif
    16111610
    1612     AUDMIXBUF_LOG(("cRead=%RU32 (%RU32 bytes)\n", cToRead, AUDIOMIXBUF_S2B(pMixBuf, cToRead)));
     1611    AUDMIXBUF_LOG(("cRead=%RU32 (%RU32 bytes)\n", cToRead, AUDIOMIXBUF_F2B(pMixBuf, cToRead)));
    16131612    return VINF_SUCCESS;
    16141613}
     
    16641663
    16651664/**
    1666  * Returns the maximum amount of audio samples this buffer can hold.
    1667  *
    1668  * @return  uint32_t                Size (in audio samples) the mixing buffer can hold.
     1665 * Returns the maximum amount of audio frames this buffer can hold.
     1666 *
     1667 * @return  uint32_t                Size (in audio frames) the mixing buffer can hold.
    16691668 * @param   pMixBuf                 Mixing buffer to retrieve maximum for.
    16701669 */
     
    16721671{
    16731672    AssertPtrReturn(pMixBuf, 0);
    1674     return pMixBuf->cSamples;
     1673    return pMixBuf->cFrames;
    16751674}
    16761675
     
    16841683{
    16851684    AssertPtrReturn(pMixBuf, 0);
    1686     return AUDIOMIXBUF_S2B(pMixBuf, pMixBuf->cSamples);
     1685    return AUDIOMIXBUF_F2B(pMixBuf, pMixBuf->cFrames);
    16871686}
    16881687
     
    17491748
    17501749/**
    1751  * Writes audio samples at a specific offset.
     1750 * Writes audio frames at a specific offset.
    17521751 * The sample format being written must match the format of the mixing buffer.
    17531752 *
    17541753 * @return  IPRT status code.
    17551754 * @param   pMixBuf                 Pointer to mixing buffer to write to.
    1756  * @param   offSamples              Offset (in samples) starting to write at.
     1755 * @param   offFrames               Offset (in frames) starting to write at.
    17571756 * @param   pvBuf                   Pointer to audio buffer to be written.
    17581757 * @param   cbBuf                   Size (in bytes) of audio buffer.
    1759  * @param   pcWritten               Returns number of audio samples written. Optional.
    1760  */
    1761 int AudioMixBufWriteAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offSamples, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten)
    1762 {
    1763     return AudioMixBufWriteAtEx(pMixBuf, pMixBuf->AudioFmt, offSamples, pvBuf, cbBuf, pcWritten);
    1764 }
    1765 
    1766 /**
    1767  * Writes audio samples at a specific offset.
     1758 * @param   pcWritten               Returns number of audio frames written. Optional.
     1759 */
     1760int AudioMixBufWriteAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offFrames, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten)
     1761{
     1762    return AudioMixBufWriteAtEx(pMixBuf, pMixBuf->AudioFmt, offFrames, pvBuf, cbBuf, pcWritten);
     1763}
     1764
     1765/**
     1766 * Writes audio frames at a specific offset.
    17681767 *
    17691768 * Note that this operation also modifies the current read and write position
    1770  * to \a offSamples + written samples on success.
     1769 * to \a offFrames + written frames on success.
    17711770 *
    17721771 * The audio sample format to be written can be different from the audio format
     
    17761775 * @param   pMixBuf                 Pointer to mixing buffer to write to.
    17771776 * @param   enmFmt                  Audio format supplied in the buffer.
    1778  * @param   offSamples              Offset (in samples) starting to write at.
     1777 * @param   offFrames               Offset (in frames) starting to write at.
    17791778 * @param   pvBuf                   Pointer to audio buffer to be written.
    17801779 * @param   cbBuf                   Size (in bytes) of audio buffer.
    1781  * @param   pcWritten               Returns number of audio samples written. Optional.
     1780 * @param   pcWritten               Returns number of audio frames written. Optional.
    17821781 */
    17831782int AudioMixBufWriteAtEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt,
    1784                          uint32_t offSamples, const void *pvBuf, uint32_t cbBuf,
     1783                         uint32_t offFrames, const void *pvBuf, uint32_t cbBuf,
    17851784                         uint32_t *pcWritten)
    17861785{
     
    17901789    /* pcbWritten is optional. */
    17911790
    1792     if (offSamples >= pMixBuf->cSamples)
     1791    if (offFrames >= pMixBuf->cFrames)
    17931792    {
    17941793        if (pcWritten)
     
    18001799     * Adjust cToWrite so we don't overflow our buffers.
    18011800     */
    1802     uint32_t cToWrite = RT_MIN(AUDIOMIXBUF_B2S(pMixBuf, cbBuf), pMixBuf->cSamples - offSamples);
     1801    uint32_t cToWrite = RT_MIN(AUDIOMIXBUF_B2F(pMixBuf, cbBuf), pMixBuf->cFrames - offFrames);
    18031802
    18041803#ifdef AUDIOMIXBUF_DEBUG_DUMP_PCM_DATA
     
    18111810    if (RT_SUCCESS(rc2))
    18121811    {
    1813         RTFileWrite(hFile, pvBuf, AUDIOMIXBUF_S2B(pMixBuf, cToWrite), NULL);
     1812        RTFileWrite(hFile, pvBuf, AUDIOMIXBUF_F2B(pMixBuf, cToWrite), NULL);
    18141813        RTFileClose(hFile);
    18151814    }
     
    18381837        PDMAUDMIXBUFCONVOPTS convOpts;
    18391838
    1840         convOpts.cSamples           = cToWrite;
     1839        convOpts.cFrames           = cToWrite;
    18411840        convOpts.From.Volume.fMuted = pMixBuf->Volume.fMuted;
    18421841        convOpts.From.Volume.uLeft  = pMixBuf->Volume.uLeft;
    18431842        convOpts.From.Volume.uRight = pMixBuf->Volume.uRight;
    18441843
    1845         cWritten = pfnConvFrom(pMixBuf->pSamples + offSamples, pvBuf, AUDIOMIXBUF_S2B(pMixBuf, cToWrite), &convOpts);
     1844        cWritten = pfnConvFrom(pMixBuf->pFrames + offFrames, pvBuf, AUDIOMIXBUF_F2B(pMixBuf, cToWrite), &convOpts);
    18461845    }
    18471846    else
     
    18551854    }
    18561855
    1857     AUDMIXBUF_LOG(("%s: offSamples=%RU32, cbBuf=%RU32, cToWrite=%RU32 (%zu bytes), cWritten=%RU32 (%zu bytes), rc=%Rrc\n",
    1858                    pMixBuf->pszName, offSamples, cbBuf,
    1859                    cToWrite, AUDIOMIXBUF_S2B(pMixBuf, cToWrite),
    1860                    cWritten, AUDIOMIXBUF_S2B(pMixBuf, cWritten), rc));
     1856    AUDMIXBUF_LOG(("%s: offFrames=%RU32, cbBuf=%RU32, cToWrite=%RU32 (%zu bytes), cWritten=%RU32 (%zu bytes), rc=%Rrc\n",
     1857                   pMixBuf->pszName, offFrames, cbBuf,
     1858                   cToWrite, AUDIOMIXBUF_F2B(pMixBuf, cToWrite),
     1859                   cWritten, AUDIOMIXBUF_F2B(pMixBuf, cWritten), rc));
    18611860
    18621861    if (RT_SUCCESS(rc))
    18631862    {
    1864         pMixBuf->offRead  = offSamples % pMixBuf->cSamples;
    1865         pMixBuf->offWrite = (offSamples + cWritten) % pMixBuf->cSamples;
     1863        pMixBuf->offRead  = offFrames % pMixBuf->cFrames;
     1864        pMixBuf->offWrite = (offFrames + cWritten) % pMixBuf->cFrames;
    18661865        pMixBuf->cUsed    = cWritten;
    18671866        pMixBuf->cMixed   = 0;
     
    18801879
    18811880/**
    1882  * Writes audio samples.
     1881 * Writes audio frames.
    18831882 *
    18841883 * The sample format being written must match the format of the mixing buffer.
    18851884 *
    1886  * @return  IPRT status code, or VERR_BUFFER_OVERFLOW if samples which not have
     1885 * @return  IPRT status code, or VERR_BUFFER_OVERFLOW if frames which not have
    18871886 *          been processed yet have been overwritten (due to cyclic buffer).
    18881887 * @param   pMixBuf                 Pointer to mixing buffer to write to.
    18891888 * @param   pvBuf                   Pointer to audio buffer to be written.
    18901889 * @param   cbBuf                   Size (in bytes) of audio buffer.
    1891  * @param   pcWritten               Returns number of audio samples written. Optional.
     1890 * @param   pcWritten               Returns number of audio frames written. Optional.
    18921891 */
    18931892int AudioMixBufWriteCirc(PPDMAUDIOMIXBUF pMixBuf,
     
    18991898
    19001899/**
    1901  * Writes audio samples of a specific format.
     1900 * Writes audio frames of a specific format.
    19021901 * This function might write less data at once than requested.
    19031902 *
     
    19071906 * @param   pvBuf                   Pointer to audio buffer to be written.
    19081907 * @param   cbBuf                   Size (in bytes) of audio buffer.
    1909  * @param   pcWritten               Returns number of audio samples written. Optional.
     1908 * @param   pcWritten               Returns number of audio frames written. Optional.
    19101909 */
    19111910int AudioMixBufWriteCircEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt,
     
    19231922    }
    19241923
    1925     /* Make sure that we at least write a full audio sample. */
    1926     AssertReturn(AUDIOMIXBUF_B2S(pMixBuf, cbBuf), VERR_INVALID_PARAMETER);
    1927 
    1928     Assert(pMixBuf->cSamples);
    1929     AssertPtr(pMixBuf->pSamples);
     1924    /* Make sure that we at least write a full audio frame. */
     1925    AssertReturn(AUDIOMIXBUF_B2F(pMixBuf, cbBuf), VERR_INVALID_PARAMETER);
     1926
     1927    Assert(pMixBuf->cFrames);
     1928    AssertPtr(pMixBuf->pFrames);
    19301929
    19311930    PFNPDMAUDIOMIXBUFCONVFROM pfnConvFrom = NULL;
     
    19501949    uint32_t cWritten = 0;
    19511950
    1952     uint32_t cFree = pMixBuf->cSamples - pMixBuf->cUsed;
     1951    uint32_t cFree = pMixBuf->cFrames - pMixBuf->cUsed;
    19531952    if (cFree)
    19541953    {
    1955         if ((pMixBuf->cSamples - pMixBuf->offWrite) == 0)
     1954        if ((pMixBuf->cFrames - pMixBuf->offWrite) == 0)
    19561955            pMixBuf->offWrite = 0;
    19571956
    1958         uint32_t cToWrite = RT_MIN(AUDIOMIXBUF_B2S(pMixBuf, cbBuf), RT_MIN(pMixBuf->cSamples - pMixBuf->offWrite, cFree));
     1957        uint32_t cToWrite = RT_MIN(AUDIOMIXBUF_B2F(pMixBuf, cbBuf), RT_MIN(pMixBuf->cFrames - pMixBuf->offWrite, cFree));
    19591958        Assert(cToWrite);
    19601959
     
    19661965        convOpts.From.Volume.uRight = pMixBuf->Volume.uRight;
    19671966
    1968         convOpts.cSamples = cToWrite;
    1969 
    1970         cWritten = pfnConvFrom(pMixBuf->pSamples + pMixBuf->offWrite,
    1971                                pvBuf, AUDIOMIXBUF_S2B(pMixBuf, cToWrite), &convOpts);
     1967        convOpts.cFrames = cToWrite;
     1968
     1969        cWritten = pfnConvFrom(pMixBuf->pFrames + pMixBuf->offWrite,
     1970                               pvBuf, AUDIOMIXBUF_F2B(pMixBuf, cToWrite), &convOpts);
    19721971        Assert(cWritten == cToWrite);
    19731972
     
    19761975        RTFileOpen(&fh, AUDIOMIXBUF_DEBUG_DUMP_PCM_DATA_PATH "mixbuf_writecirc_ex.pcm",
    19771976                   RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND | RTFILE_O_WRITE | RTFILE_O_DENY_NONE);
    1978         RTFileWrite(fh, pvBuf, AUDIOMIXBUF_S2B(pMixBuf, cToWrite), NULL);
     1977        RTFileWrite(fh, pvBuf, AUDIOMIXBUF_F2B(pMixBuf, cToWrite), NULL);
    19791978        RTFileClose(fh);
    19801979#endif
    19811980        pMixBuf->cUsed   += cWritten;
    1982         Assert(pMixBuf->cUsed <= pMixBuf->cSamples);
    1983 
    1984         pMixBuf->offWrite = (pMixBuf->offWrite + cWritten) % pMixBuf->cSamples;
    1985         Assert(pMixBuf->offWrite <= pMixBuf->cSamples);
     1981        Assert(pMixBuf->cUsed <= pMixBuf->cFrames);
     1982
     1983        pMixBuf->offWrite = (pMixBuf->offWrite + cWritten) % pMixBuf->cFrames;
     1984        Assert(pMixBuf->offWrite <= pMixBuf->cFrames);
    19861985    }
    19871986    else
     
    19961995        *pcWritten = cWritten;
    19971996
    1998     AUDMIXBUF_LOG(("%s: enmFmt=0x%x, cbBuf=%RU32 (%RU32 samples), cWritten=%RU32, rc=%Rrc\n",
    1999                    pMixBuf->pszName, enmFmt, cbBuf, AUDIOMIXBUF_B2S(pMixBuf, cbBuf), cWritten, rc));
     1997    AUDMIXBUF_LOG(("%s: enmFmt=0x%x, cbBuf=%RU32 (%RU32 frames), cWritten=%RU32, rc=%Rrc\n",
     1998                   pMixBuf->pszName, enmFmt, cbBuf, AUDIOMIXBUF_B2F(pMixBuf, cbBuf), cWritten, rc));
    20001999    return rc;
    20012000}
  • trunk/src/VBox/Devices/Audio/AudioMixBuffer.h

    r67365 r68132  
    3737#define AUDMIXBUF_FMT_BYTES_PER_SAMPLE(a) ((AUDMIXBUF_AUDIO_FMT_BITS_PER_SAMPLE(a) + 7) / 8)
    3838
    39 /** Converts samples to bytes. */
    40 #define AUDIOMIXBUF_S2B(pBuf, samples) ((samples) << (pBuf)->cShift)
    41 /** Converts samples to bytes, respecting the conversion ratio to
     39/** Converts frames to bytes. */
     40#define AUDIOMIXBUF_F2B(pBuf, frames) ((frames) << (pBuf)->cShift)
     41/** Converts frames to bytes, respecting the conversion ratio to
    4242 *  a linked buffer. */
    43 #define AUDIOMIXBUF_S2B_RATIO(pBuf, samples) ((((int64_t) samples << 32) / (pBuf)->iFreqRatio) << (pBuf)->cShift)
    44 /** Converts bytes to samples, *not* taking the conversion ratio
     43#define AUDIOMIXBUF_F2B_RATIO(pBuf, frames) ((((int64_t) frames << 32) / (pBuf)->iFreqRatio) << (pBuf)->cShift)
     44/** Converts bytes to frames, *not* taking the conversion ratio
    4545 *  into account. */
    46 #define AUDIOMIXBUF_B2S(pBuf, cb)  (cb >> (pBuf)->cShift)
    47 /** Converts number of samples according to the buffer's ratio. */
    48 #define AUDIOMIXBUF_S2S_RATIO(pBuf, samples)  (((int64_t) samples << 32) / (pBuf)->iFreqRatio)
     46#define AUDIOMIXBUF_B2F(pBuf, cb)  (cb >> (pBuf)->cShift)
     47/** Converts number of frames according to the buffer's ratio. */
     48#define AUDIOMIXBUF_F2F_RATIO(pBuf, frames)  (((int64_t) frames << 32) / (pBuf)->iFreqRatio)
    4949
    5050
     
    5252void AudioMixBufClear(PPDMAUDIOMIXBUF pMixBuf);
    5353void AudioMixBufDestroy(PPDMAUDIOMIXBUF pMixBuf);
    54 void AudioMixBufFinish(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToClear);
     54void AudioMixBufFinish(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFramesToClear);
    5555uint32_t AudioMixBufFree(PPDMAUDIOMIXBUF pMixBuf);
    5656uint32_t AudioMixBufFreeBytes(PPDMAUDIOMIXBUF pMixBuf);
    57 int AudioMixBufInit(PPDMAUDIOMIXBUF pMixBuf, const char *pszName, PPDMAUDIOPCMPROPS pProps, uint32_t cSamples);
     57int AudioMixBufInit(PPDMAUDIOMIXBUF pMixBuf, const char *pszName, PPDMAUDIOPCMPROPS pProps, uint32_t cFrames);
    5858bool AudioMixBufIsEmpty(PPDMAUDIOMIXBUF pMixBuf);
    5959int AudioMixBufLinkTo(PPDMAUDIOMIXBUF pMixBuf, PPDMAUDIOMIXBUF pParent);
    6060uint32_t AudioMixBufLive(PPDMAUDIOMIXBUF pMixBuf);
    61 int AudioMixBufMixToParent(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSrcSamples, uint32_t *pcSrcMixed);
    62 int AudioMixBufMixToParentEx(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSrcOffset, uint32_t cSrcSamples, uint32_t *pcSrcMixed);
    63 int AudioMixBufPeek(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToRead, PPDMAUDIOSAMPLE paSampleBuf, uint32_t cSampleBuf, uint32_t *pcSamplesRead);
    64 int AudioMixBufPeekMutable(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToRead, PPDMAUDIOSAMPLE *ppvSamples, uint32_t *pcSamplesRead);
     61int AudioMixBufMixToParent(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSrcFrames, uint32_t *pcSrcMixed);
     62int AudioMixBufMixToParentEx(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSrcOffset, uint32_t cSrcFrames, uint32_t *pcSrcMixed);
     63int AudioMixBufPeek(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFramesToRead, PPDMAUDIOFRAME paSampleBuf, uint32_t cSampleBuf, uint32_t *pcFramesRead);
     64int AudioMixBufPeekMutable(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFramesToRead, PPDMAUDIOFRAME *ppvSamples, uint32_t *pcFramesRead);
    6565uint32_t AudioMixBufUsed(PPDMAUDIOMIXBUF pMixBuf);
    6666int AudioMixBufReadAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offSamples, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead);
  • trunk/src/VBox/Devices/Audio/AudioMixer.cpp

    r68021 r68132  
    14401440        AssertPtr(pConn);
    14411441
    1442         uint32_t csProc = 0;
     1442        uint32_t cfProc = 0;
    14431443
    14441444        int rc2 = pConn->pfnStreamIterate(pConn, pStream);
     
    14471447            if (pSink->enmDir == AUDMIXSINKDIR_INPUT)
    14481448            {
    1449                 rc = pConn->pfnStreamCapture(pConn, pStream, &csProc);
     1449                rc = pConn->pfnStreamCapture(pConn, pStream, &cfProc);
    14501450                if (RT_FAILURE(rc2))
    14511451                {
     
    14561456                }
    14571457
    1458                 if (csProc)
     1458                if (cfProc)
    14591459                    pSink->fStatus |= AUDMIXSINK_STS_DIRTY;
    14601460            }
    14611461            else if (pSink->enmDir == AUDMIXSINKDIR_OUTPUT)
    14621462            {
    1463                 rc2 = pConn->pfnStreamPlay(pConn, pStream, &csProc);
     1463                rc2 = pConn->pfnStreamPlay(pConn, pStream, &cfProc);
    14641464                if (RT_FAILURE(rc2))
    14651465                {
     
    14951495        }
    14961496
    1497         Log3Func(("\t%s: cPlayed/cCaptured=%RU32, rc2=%Rrc\n", pStream->szName, csProc, rc2));
     1497        Log3Func(("\t%s: cPlayed/cCaptured=%RU32, rc2=%Rrc\n", pStream->szName, cfProc, rc2));
    14981498    }
    14991499
  • trunk/src/VBox/Devices/Audio/DevHDA.cpp

    r68021 r68132  
    26902690        RTListForEach(&pThis->lstDrv, pDrv, HDADRIVER, Node)
    26912691        {
    2692             uint32_t cSamplesPlayed;
    2693             int rc2 = pDrv->pConnector->pfnPlay(pDrv->pConnector, &cSamplesPlayed);
    2694             LogFlowFunc(("LUN#%RU8: cSamplesPlayed=%RU32, rc=%Rrc\n", pDrv->uLUN, cSamplesPlayed, rc2));
     2692            uint32_t cFramesPlayed;
     2693            int rc2 = pDrv->pConnector->pfnPlay(pDrv->pConnector, &cFramesPlayed);
     2694            LogFlowFunc(("LUN#%RU8: cFramesPlayed=%RU32, rc=%Rrc\n", pDrv->uLUN, cFramesPlayed, rc2));
    26952695        }
    26962696    }
  • trunk/src/VBox/Devices/Audio/DrvAudio.cpp

    r68076 r68132  
    645645#endif
    646646
    647     /* No sample buffer size hint given by the backend? Default to some sane value. */
    648     if (!CfgHostAcq.cSampleBufferHint)
    649     {
    650         CfgHostAcq.cSampleBufferHint = _1K; /** @todo Make this configurable? */
     647    /* No frame buffer size hint given by the backend? Default to some sane value. */
     648    if (!CfgHostAcq.cFrameBufferHint)
     649    {
     650        CfgHostAcq.cFrameBufferHint = _1K; /** @todo Make this configurable? */
    651651    }
    652652
     
    658658
    659659    /* Set set host buffer size multiplicator. */
    660     const unsigned cSampleBufferHostFactor = 2; /** @todo Make this configurable. */
    661 
    662     LogFunc(("[%s] cSamples=%RU32 (x %u)\n", pHstStream->szName, CfgHostAcq.cSampleBufferHint, cSampleBufferHostFactor));
     660    const unsigned cFrameBufferHostFactor = 2; /** @todo Make this configurable. */
     661
     662    LogFunc(("[%s] cFrames=%RU32 (x %u)\n", pHstStream->szName, CfgHostAcq.cFrameBufferHint, cFrameBufferHostFactor));
    663663
    664664    int rc2 = AudioMixBufInit(&pHstStream->MixBuf, pHstStream->szName, &CfgHostAcq.Props,
    665                               CfgHostAcq.cSampleBufferHint * cSampleBufferHostFactor);
     665                              CfgHostAcq.cFrameBufferHint * cFrameBufferHostFactor);
    666666    AssertRC(rc2);
    667667
     
    684684
    685685    /* Set set guest buffer size multiplicator. */
    686     const unsigned cSampleBufferGuestFactor = 10; /** @todo Make this configurable. */
    687 
    688     LogFunc(("[%s] cSamples=%RU32 (x %u)\n", pGstStream->szName, CfgHostAcq.cSampleBufferHint, cSampleBufferGuestFactor));
     686    const unsigned cFrameBufferGuestFactor = 10; /** @todo Make this configurable. */
     687
     688    LogFunc(("[%s] cFrames=%RU32 (x %u)\n", pGstStream->szName, CfgHostAcq.cFrameBufferHint, cFrameBufferGuestFactor));
    689689
    690690    rc2 = AudioMixBufInit(&pGstStream->MixBuf, pGstStream->szName, &pCfgGuest->Props,
    691                           CfgHostAcq.cSampleBufferHint * cSampleBufferGuestFactor);
     691                          CfgHostAcq.cFrameBufferHint * cFrameBufferGuestFactor);
    692692    AssertRC(rc2);
    693693
     
    834834                STAM_COUNTER_RESET(&pHstStream->In.StatBytesElapsed);
    835835                STAM_COUNTER_RESET(&pHstStream->In.StatBytesTotalRead);
    836                 STAM_COUNTER_RESET(&pHstStream->In.StatSamplesCaptured);
     836                STAM_COUNTER_RESET(&pHstStream->In.StatFramesCaptured);
    837837
    838838                if (pGstStream)
     
    842842                    STAM_COUNTER_RESET(&pGstStream->In.StatBytesElapsed);
    843843                    STAM_COUNTER_RESET(&pGstStream->In.StatBytesTotalRead);
    844                     STAM_COUNTER_RESET(&pGstStream->In.StatSamplesCaptured);
     844                    STAM_COUNTER_RESET(&pGstStream->In.StatFramesCaptured);
    845845                }
    846846            }
     
    849849                STAM_COUNTER_RESET(&pHstStream->Out.StatBytesElapsed);
    850850                STAM_COUNTER_RESET(&pHstStream->Out.StatBytesTotalWritten);
    851                 STAM_COUNTER_RESET(&pHstStream->Out.StatSamplesPlayed);
     851                STAM_COUNTER_RESET(&pHstStream->Out.StatFramesPlayed);
    852852
    853853                if (pGstStream)
     
    857857                    STAM_COUNTER_RESET(&pGstStream->Out.StatBytesElapsed);
    858858                    STAM_COUNTER_RESET(&pGstStream->Out.StatBytesTotalWritten);
    859                     STAM_COUNTER_RESET(&pGstStream->Out.StatSamplesPlayed);
     859                    STAM_COUNTER_RESET(&pGstStream->Out.StatFramesPlayed);
    860860                }
    861861            }
     
    953953        /* We use the guest side mixing buffer as an intermediate buffer to do some
    954954         * (first) processing (if needed), so always write the incoming data at offset 0. */
    955         uint32_t csWritten = 0;
    956         rc = AudioMixBufWriteAt(&pGstStream->MixBuf, 0 /* offSamples */, pvBuf, cbBuf, &csWritten);
     955        uint32_t cfWritten = 0;
     956        rc = AudioMixBufWriteAt(&pGstStream->MixBuf, 0 /* offFrames */, pvBuf, cbBuf, &cfWritten);
    957957        if (   RT_FAILURE(rc)
    958             || !csWritten)
    959         {
    960             AssertMsgFailed(("[%s] Write failed: cbBuf=%RU32, csWritten=%RU32, rc=%Rrc\n",
    961                              pGstStream->szName, cbBuf, csWritten, rc));
     958            || !cfWritten)
     959        {
     960            AssertMsgFailed(("[%s] Write failed: cbBuf=%RU32, cfWritten=%RU32, rc=%Rrc\n",
     961                             pGstStream->szName, cbBuf, cfWritten, rc));
    962962            break;
    963963        }
     
    968968
    969969#ifdef VBOX_WITH_STATISTICS
    970         STAM_COUNTER_ADD(&pThis->Stats.TotalSamplesWritten, csWritten);
    971 #endif
    972         uint32_t csMixed = 0;
    973         if (csWritten)
    974         {
    975             int rc2 = AudioMixBufMixToParentEx(&pGstStream->MixBuf, 0 /* Offset */, csWritten /* Samples */, &csMixed);
     970        STAM_COUNTER_ADD(&pThis->Stats.TotalFramesWritten, cfWritten);
     971#endif
     972        uint32_t cfMixed = 0;
     973        if (cfWritten)
     974        {
     975            int rc2 = AudioMixBufMixToParentEx(&pGstStream->MixBuf, 0 /* Offset */, cfWritten /* Frames */, &cfMixed);
    976976            if (   RT_FAILURE(rc2)
    977                 || csMixed < csWritten)
     977                || cfMixed < cfWritten)
    978978            {
    979                 AssertMsgFailed(("[%s] Mixing failed: cbBuf=%RU32, csWritten=%RU32, csMixed=%RU32, rc=%Rrc\n",
    980                                  pGstStream->szName, cbBuf, csWritten, csMixed, rc2));
    981 
    982                 LogRel2(("Audio: Lost audio samples (%RU32) due to full host stream '%s', expect stuttering audio output\n",
    983                          csWritten - csMixed, pHstStream->szName));
     979                AssertMsgFailed(("[%s] Mixing failed: cbBuf=%RU32, cfWritten=%RU32, cfMixed=%RU32, rc=%Rrc\n",
     980                                 pGstStream->szName, cbBuf, cfWritten, cfMixed, rc2));
     981
     982                LogRel2(("Audio: Lost audio frames (%RU32) due to full host stream '%s', expect stuttering audio output\n",
     983                         cfWritten - cfMixed, pHstStream->szName));
    984984
    985985                /* Keep going. */
     
    989989                rc = rc2;
    990990
    991             cbWritten = AUDIOMIXBUF_S2B(&pGstStream->MixBuf, csWritten);
     991            cbWritten = AUDIOMIXBUF_F2B(&pGstStream->MixBuf, cfWritten);
    992992
    993993#ifdef VBOX_WITH_STATISTICS
    994             STAM_COUNTER_ADD(&pThis->Stats.TotalSamplesMixedOut,     csMixed);
    995             Assert(csWritten >= csMixed);
    996             STAM_COUNTER_ADD(&pThis->Stats.TotalSamplesLostOut,      csWritten - csMixed);
     994            STAM_COUNTER_ADD(&pThis->Stats.TotalFramesMixedOut,      cfMixed);
     995            Assert(cfWritten >= cfMixed);
     996            STAM_COUNTER_ADD(&pThis->Stats.TotalFramesLostOut,       cfWritten - cfMixed);
    997997            STAM_COUNTER_ADD(&pThis->Stats.TotalBytesWritten,        cbWritten);
    998998            STAM_COUNTER_ADD(&pGstStream->Out.StatBytesTotalWritten, cbWritten);
     
    10021002        Log3Func(("[%s] cbBuf=%RU32, cUsed=%RU32, cLive=%RU32, cWritten=%RU32, cMixed=%RU32, rc=%Rrc\n",
    10031003                  pGstStream->szName,
    1004                   cbBuf, AudioMixBufUsed(&pGstStream->MixBuf), AudioMixBufLive(&pGstStream->MixBuf), csWritten, csMixed, rc));
     1004                  cbBuf, AudioMixBufUsed(&pGstStream->MixBuf), AudioMixBufLive(&pGstStream->MixBuf), cfWritten, cfMixed, rc));
    10051005
    10061006    } while (0);
     
    11431143    do
    11441144    {
    1145         uint32_t csMixed = 0;
     1145        uint32_t cfMixed = 0;
    11461146
    11471147        rc = pThis->pHostDrvAudio->pfnStreamIterate(pThis->pHostDrvAudio, pHstStream->pvBackend);
     
    11511151        if (pHstStream->enmDir == PDMAUDIODIR_IN)
    11521152        {
    1153             /* Has the host captured any samples which were not mixed to the guest side yet? */
    1154             uint32_t csCaptured = AudioMixBufUsed(&pHstStream->MixBuf);
    1155             if (csCaptured)
     1153            /* Has the host captured any frames which were not mixed to the guest side yet? */
     1154            uint32_t cfCaptured = AudioMixBufUsed(&pHstStream->MixBuf);
     1155            if (cfCaptured)
    11561156            {
    1157                 /* When capturing samples, the guest is the parent while the host is the child.
    1158                  * So try mixing not yet mixed host-side samples to the guest-side buffer. */
    1159                 rc = AudioMixBufMixToParent(&pHstStream->MixBuf, csCaptured, &csMixed);
     1157                /* When capturing frames, the guest is the parent while the host is the child.
     1158                 * So try mixing not yet mixed host-side frames to the guest-side buffer. */
     1159                rc = AudioMixBufMixToParent(&pHstStream->MixBuf, cfCaptured, &cfMixed);
    11601160                if (RT_FAILURE(rc))
    11611161                {
     
    11701170
    11711171#ifdef VBOX_WITH_STATISTICS
    1172                 STAM_COUNTER_ADD(&pThis->Stats.TotalSamplesMixedIn, csMixed);
    1173                 Assert(csCaptured >= csMixed);
    1174                 STAM_COUNTER_ADD(&pThis->Stats.TotalSamplesLostIn,  csCaptured - csMixed);
    1175 #endif
    1176                 Log3Func(("[%s] %RU32/%RU32 input samples mixed, rc=%Rrc\n", pHstStream->szName, csMixed, csCaptured, rc));
     1172                STAM_COUNTER_ADD(&pThis->Stats.TotalFramesMixedIn, cfMixed);
     1173                Assert(cfCaptured >= cfMixed);
     1174                STAM_COUNTER_ADD(&pThis->Stats.TotalFramesLostIn,  cfCaptured - cfMixed);
     1175#endif
     1176                Log3Func(("[%s] %RU32/%RU32 input frames mixed, rc=%Rrc\n", pHstStream->szName, cfMixed, cfCaptured, rc));
    11771177            }
    11781178            else
     
    12571257 * @param   pThis               Pointer to driver instance.
    12581258 * @param   pHstStream          Host stream to play.
    1259  * @param   csToPlay            Number of audio samples to play.
    1260  * @param   pcsPlayed           Returns number of audio samples played. Optional.
     1259 * @param   cfToPlay            Number of audio frames to play.
     1260 * @param   pcfPlayed           Returns number of audio frames played. Optional.
    12611261 */
    12621262static int drvAudioStreamPlayNonInterleaved(PDRVAUDIO pThis,
    1263                                             PPDMAUDIOSTREAM pHstStream, uint32_t csToPlay, uint32_t *pcsPlayed)
     1263                                            PPDMAUDIOSTREAM pHstStream, uint32_t cfToPlay, uint32_t *pcfPlayed)
    12641264{
    12651265    AssertPtrReturn(pThis,      VERR_INVALID_POINTER);
    12661266    AssertPtrReturn(pHstStream, VERR_INVALID_POINTER);
    1267     /* pcsPlayed is optional. */
     1267    /* pcfPlayed is optional. */
    12681268
    12691269    /* Sanity. */
     
    12721272    Assert(pHstStream->Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED);
    12731273
    1274     if (!csToPlay)
    1275     {
    1276         if (pcsPlayed)
    1277             *pcsPlayed = 0;
     1274    if (!cfToPlay)
     1275    {
     1276        if (pcfPlayed)
     1277            *pcfPlayed = 0;
    12781278        return VINF_SUCCESS;
    12791279    }
     
    12811281    int rc = VINF_SUCCESS;
    12821282
    1283     uint32_t csPlayedTotal = 0;
     1283    uint32_t cfPlayedTotal = 0;
    12841284
    12851285    AssertPtr(pThis->pHostDrvAudio->pfnStreamGetWritable);
     
    12871287    if (cbWritable)
    12881288    {
    1289         if (csToPlay > AUDIOMIXBUF_B2S(&pHstStream->MixBuf, cbWritable)) /* More samples available than we can write? Limit. */
    1290             csToPlay = AUDIOMIXBUF_B2S(&pHstStream->MixBuf, cbWritable);
    1291 
    1292         if (csToPlay)
     1289        if (cfToPlay > AUDIOMIXBUF_B2F(&pHstStream->MixBuf, cbWritable)) /* More frames available than we can write? Limit. */
     1290            cfToPlay = AUDIOMIXBUF_B2F(&pHstStream->MixBuf, cbWritable);
     1291
     1292        if (cfToPlay)
    12931293        {
    12941294            uint8_t auBuf[256]; /** @todo Get rid of this here. */
    12951295
    1296             uint32_t cbLeft  = AUDIOMIXBUF_S2B(&pHstStream->MixBuf, csToPlay);
     1296            uint32_t cbLeft  = AUDIOMIXBUF_F2B(&pHstStream->MixBuf, cfToPlay);
    12971297            uint32_t cbChunk = sizeof(auBuf);
    12981298
    12991299            while (cbLeft)
    13001300            {
    1301                 uint32_t csRead = 0;
    1302                 rc = AudioMixBufReadCirc(&pHstStream->MixBuf, auBuf, RT_MIN(cbChunk, cbLeft), &csRead);
    1303                 if (   !csRead
     1301                uint32_t cfRead = 0;
     1302                rc = AudioMixBufReadCirc(&pHstStream->MixBuf, auBuf, RT_MIN(cbChunk, cbLeft), &cfRead);
     1303                if (   !cfRead
    13041304                    || RT_FAILURE(rc))
    13051305                {
     
    13071307                }
    13081308
    1309                 uint32_t cbRead = AUDIOMIXBUF_S2B(&pHstStream->MixBuf, csRead);
     1309                uint32_t cbRead = AUDIOMIXBUF_F2B(&pHstStream->MixBuf, cfRead);
    13101310                Assert(cbRead <= cbChunk);
    13111311
     
    13261326#if 0 /** @todo Also handle mono channels. Needs fixing */
    13271327                AssertMsg(cbPlayed % 2 == 0,
    1328                           ("Backend for stream '%s' returned uneven played bytes count (csRead=%RU32, cbPlayed=%RU32)\n",
    1329                            pHstStream->szName, csRead, cbPlayed));*/
    1330 #endif
    1331                 csPlayedTotal += AUDIOMIXBUF_B2S(&pHstStream->MixBuf, cbPlayed);
     1328                          ("Backend for stream '%s' returned uneven played bytes count (cfRead=%RU32, cbPlayed=%RU32)\n",
     1329                           pHstStream->szName, cfRead, cbPlayed));*/
     1330#endif
     1331                cfPlayedTotal += AUDIOMIXBUF_B2F(&pHstStream->MixBuf, cbPlayed);
    13321332                Assert(cbLeft >= cbPlayed);
    13331333                cbLeft        -= cbPlayed;
     
    13361336    }
    13371337
    1338     Log3Func(("[%s] Played %RU32/%RU32 samples, rc=%Rrc\n", pHstStream->szName, csPlayedTotal, csToPlay, rc));
     1338    Log3Func(("[%s] Played %RU32/%RU32 frames, rc=%Rrc\n", pHstStream->szName, cfPlayedTotal, cfToPlay, rc));
    13391339
    13401340    if (RT_SUCCESS(rc))
    13411341    {
    1342         if (pcsPlayed)
    1343             *pcsPlayed = csPlayedTotal;
     1342        if (pcfPlayed)
     1343            *pcfPlayed = cfPlayedTotal;
    13441344    }
    13451345
     
    13531353 * @param   pThis               Pointer to driver instance.
    13541354 * @param   pHstStream          Host stream to play.
    1355  * @param   csToPlay            Number of audio samples to play.
    1356  * @param   pcsPlayed           Returns number of audio samples played. Optional.
     1355 * @param   cfToPlay            Number of audio frames to play.
     1356 * @param   pcfPlayed           Returns number of audio frames played. Optional.
    13571357 */
    13581358static int drvAudioStreamPlayRaw(PDRVAUDIO pThis,
    1359                                  PPDMAUDIOSTREAM pHstStream, uint32_t csToPlay, uint32_t *pcsPlayed)
     1359                                 PPDMAUDIOSTREAM pHstStream, uint32_t cfToPlay, uint32_t *pcfPlayed)
    13601360{
    13611361    AssertPtrReturn(pThis,      VERR_INVALID_POINTER);
    13621362    AssertPtrReturn(pHstStream, VERR_INVALID_POINTER);
    1363     /* pcsPlayed is optional. */
     1363    /* pcfPlayed is optional. */
    13641364
    13651365    /* Sanity. */
     
    13681368    Assert(pHstStream->Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_RAW);
    13691369
    1370     if (!csToPlay)
    1371     {
    1372         if (pcsPlayed)
    1373             *pcsPlayed = 0;
     1370    if (!cfToPlay)
     1371    {
     1372        if (pcfPlayed)
     1373            *pcfPlayed = 0;
    13741374        return VINF_SUCCESS;
    13751375    }
     
    13771377    int rc = VINF_SUCCESS;
    13781378
    1379     uint32_t csPlayedTotal = 0;
     1379    uint32_t cfPlayedTotal = 0;
    13801380
    13811381    AssertPtr(pThis->pHostDrvAudio->pfnStreamGetWritable);
    1382     uint32_t csWritable = pThis->pHostDrvAudio->pfnStreamGetWritable(pThis->pHostDrvAudio, pHstStream->pvBackend);
    1383     if (csWritable)
    1384     {
    1385         if (csToPlay > csWritable) /* More samples available than we can write? Limit. */
    1386             csToPlay = csWritable;
    1387 
    1388         PDMAUDIOSAMPLE aSampleBuf[256]; /** @todo Get rid of this here. */
    1389 
    1390         uint32_t csLeft = csToPlay;
    1391         while (csLeft)
    1392         {
    1393             uint32_t csRead = 0;
    1394             rc = AudioMixBufPeek(&pHstStream->MixBuf, csLeft, aSampleBuf,
    1395                                  RT_MIN(csLeft, RT_ELEMENTS(aSampleBuf)), &csRead);
     1382    uint32_t cfWritable = pThis->pHostDrvAudio->pfnStreamGetWritable(pThis->pHostDrvAudio, pHstStream->pvBackend);
     1383    if (cfWritable)
     1384    {
     1385        if (cfToPlay > cfWritable) /* More frames available than we can write? Limit. */
     1386            cfToPlay = cfWritable;
     1387
     1388        PDMAUDIOFRAME aFrameBuf[256]; /** @todo Get rid of this here. */
     1389
     1390        uint32_t cfLeft = cfToPlay;
     1391        while (cfLeft)
     1392        {
     1393            uint32_t cfRead = 0;
     1394            rc = AudioMixBufPeek(&pHstStream->MixBuf, cfLeft, aFrameBuf,
     1395                                 RT_MIN(cfLeft, RT_ELEMENTS(aFrameBuf)), &cfRead);
    13961396
    13971397            if (RT_SUCCESS(rc))
    13981398            {
    1399                 if (csRead)
     1399                if (cfRead)
    14001400                {
    1401                     uint32_t csPlayed;
     1401                    uint32_t cfPlayed;
    14021402
    14031403                    /* Note: As the stream layout is RPDMAUDIOSTREAMLAYOUT_RAW, operate on audio frames
    14041404                     *       rather on bytes. */
    1405                     Assert(csRead <= RT_ELEMENTS(aSampleBuf));
     1405                    Assert(cfRead <= RT_ELEMENTS(aFrameBuf));
    14061406                    rc = pThis->pHostDrvAudio->pfnStreamPlay(pThis->pHostDrvAudio, pHstStream->pvBackend,
    1407                                                              aSampleBuf, csRead, &csPlayed);
     1407                                                             aFrameBuf, cfRead, &cfPlayed);
    14081408                    if (   RT_FAILURE(rc)
    1409                         || !csPlayed)
     1409                        || !cfPlayed)
    14101410                    {
    14111411                        break;
    14121412                    }
    14131413
    1414                     csPlayedTotal += csPlayed;
    1415                     Assert(csPlayedTotal <= csToPlay);
    1416 
    1417                     Assert(csLeft >= csRead);
    1418                     csLeft        -= csRead;
     1414                    cfPlayedTotal += cfPlayed;
     1415                    Assert(cfPlayedTotal <= cfToPlay);
     1416
     1417                    Assert(cfLeft >= cfRead);
     1418                    cfLeft        -= cfRead;
    14191419                }
    14201420                else
     
    14311431    }
    14321432
    1433     Log3Func(("[%s] Played %RU32/%RU32 samples, rc=%Rrc\n", pHstStream->szName, csPlayedTotal, csToPlay, rc));
     1433    Log3Func(("[%s] Played %RU32/%RU32 frames, rc=%Rrc\n", pHstStream->szName, cfPlayedTotal, cfToPlay, rc));
    14341434
    14351435    if (RT_SUCCESS(rc))
    14361436    {
    1437         if (pcsPlayed)
    1438             *pcsPlayed = csPlayedTotal;
     1437        if (pcfPlayed)
     1438            *pcfPlayed = cfPlayedTotal;
    14391439
    14401440    }
     
    14471447 */
    14481448static DECLCALLBACK(int) drvAudioStreamPlay(PPDMIAUDIOCONNECTOR pInterface,
    1449                                             PPDMAUDIOSTREAM pStream, uint32_t *pcSamplesPlayed)
     1449                                            PPDMAUDIOSTREAM pStream, uint32_t *pcFramesPlayed)
    14501450{
    14511451    AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
    14521452    AssertPtrReturn(pStream,    VERR_INVALID_POINTER);
    1453     /* pcSamplesPlayed is optional. */
     1453    /* pcFramesPlayed is optional. */
    14541454
    14551455    PDRVAUDIO pThis = PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface);
     
    14631463               pStream->szName, pStream->enmDir));
    14641464
    1465     uint32_t csPlayedTotal = 0;
     1465    uint32_t cfPlayedTotal = 0;
    14661466
    14671467    do
     
    15011501            break;
    15021502
    1503         uint32_t csToPlay = AudioMixBufLive(&pHstStream->MixBuf);
     1503        uint32_t cfToPlay = AudioMixBufLive(&pHstStream->MixBuf);
    15041504
    15051505        if (pThis->pHostDrvAudio->pfnStreamPlayBegin)
     
    15081508        if (RT_LIKELY(pHstStream->Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED))
    15091509        {
    1510             rc = drvAudioStreamPlayNonInterleaved(pThis, pHstStream, csToPlay, &csPlayedTotal);
     1510            rc = drvAudioStreamPlayNonInterleaved(pThis, pHstStream, cfToPlay, &cfPlayedTotal);
    15111511        }
    15121512        else if (pHstStream->Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_RAW)
    15131513        {
    1514             rc = drvAudioStreamPlayRaw(pThis, pHstStream, csToPlay, &csPlayedTotal);
     1514            rc = drvAudioStreamPlayRaw(pThis, pHstStream, cfToPlay, &cfPlayedTotal);
    15151515        }
    15161516        else
     
    15201520            pThis->pHostDrvAudio->pfnStreamPlayEnd(pThis->pHostDrvAudio, pHstStream->pvBackend);
    15211521
    1522         uint32_t csLive = 0;
     1522        uint32_t cfLive = 0;
    15231523
    15241524        if (RT_SUCCESS(rc))
    15251525        {
    1526             AudioMixBufFinish(&pHstStream->MixBuf, csPlayedTotal);
     1526            AudioMixBufFinish(&pHstStream->MixBuf, cfPlayedTotal);
    15271527
    15281528#ifdef VBOX_WITH_STATISTICS
    1529             STAM_COUNTER_ADD(&pThis->Stats.TotalSamplesOut, csPlayedTotal);
     1529            STAM_COUNTER_ADD     (&pThis->Stats.TotalFramesOut, cfPlayedTotal);
    15301530            STAM_PROFILE_ADV_STOP(&pThis->Stats.DelayOut, out);
    1531             STAM_COUNTER_ADD(&pHstStream->Out.StatSamplesPlayed, csPlayedTotal);
    1532 #endif
    1533             csLive = AudioMixBufLive(&pHstStream->MixBuf);
     1531            STAM_COUNTER_ADD     (&pHstStream->Out.StatFramesPlayed, cfPlayedTotal);
     1532#endif
     1533            cfLive = AudioMixBufLive(&pHstStream->MixBuf);
    15341534        }
    15351535
    15361536#ifdef LOG_ENABLED
    15371537        pszBackendSts = dbgAudioStreamStatusToStr(stsBackend);
    1538         Log3Func(("[%s] End: stsBackend=%s, csLive=%RU32, csPlayedTotal=%RU32, rc=%Rrc\n",
    1539                   pHstStream->szName, pszBackendSts, csLive, csPlayedTotal, rc));
     1538        Log3Func(("[%s] End: stsBackend=%s, cfLive=%RU32, cfPlayedTotal=%RU32, rc=%Rrc\n",
     1539                  pHstStream->szName, pszBackendSts, cfLive, cfPlayedTotal, rc));
    15401540        RTStrFree(pszBackendSts);
    15411541#endif /* LOG_ENABLED */
    15421542
    1543         if (!csLive)
     1543        if (!cfLive)
    15441544        {
    15451545            /* Has the host stream marked as disabled but there still were guest streams relying
     
    15661566    if (RT_SUCCESS(rc))
    15671567    {
    1568         if (pcSamplesPlayed)
    1569             *pcSamplesPlayed = csPlayedTotal;
     1568        if (pcFramesPlayed)
     1569            *pcFramesPlayed = cfPlayedTotal;
    15701570    }
    15711571
     
    15821582 * @param   pThis               Driver instance.
    15831583 * @param   pHstStream          Host stream to capture from.
    1584  * @param   pcsCaptured         Number of (host) audio samples captured. Optional.
    1585  */
    1586 static int drvAudioStreamCaptureNonInterleaved(PDRVAUDIO pThis, PPDMAUDIOSTREAM pHstStream, uint32_t *pcsCaptured)
     1584 * @param   pcfCaptured         Number of (host) audio frames captured. Optional.
     1585 */
     1586static int drvAudioStreamCaptureNonInterleaved(PDRVAUDIO pThis, PPDMAUDIOSTREAM pHstStream, uint32_t *pcfCaptured)
    15871587{
    15881588    AssertPtrReturn(pThis,      VERR_INVALID_POINTER);
    15891589    AssertPtrReturn(pHstStream, VERR_INVALID_POINTER);
    1590     /* pcsCaptured is optional. */
     1590    /* pcfCaptured is optional. */
    15911591
    15921592    /* Sanity. */
     
    15971597    int rc = VINF_SUCCESS;
    15981598
    1599     uint32_t csCapturedTotal = 0;
     1599    uint32_t cfCapturedTotal = 0;
    16001600
    16011601    AssertPtr(pThis->pHostDrvAudio->pfnStreamGetReadable);
     
    16101610            break;
    16111611
    1612         uint32_t cbFree = AUDIOMIXBUF_S2B(&pHstStream->MixBuf, AudioMixBufFree(&pHstStream->MixBuf));
     1612        uint32_t cbFree = AUDIOMIXBUF_F2B(&pHstStream->MixBuf, AudioMixBufFree(&pHstStream->MixBuf));
    16131613        if (!cbFree)
    16141614            break;
     
    16401640                cbCaptured = (uint32_t)cbBuf;
    16411641
    1642             uint32_t csCaptured = 0;
    1643             rc = AudioMixBufWriteCirc(&pHstStream->MixBuf, auBuf, cbCaptured, &csCaptured);
     1642            uint32_t cfCaptured = 0;
     1643            rc = AudioMixBufWriteCirc(&pHstStream->MixBuf, auBuf, cbCaptured, &cfCaptured);
    16441644            if (RT_SUCCESS(rc))
    1645                 csCapturedTotal += csCaptured;
     1645                cfCapturedTotal += cfCaptured;
    16461646        }
    16471647        else /* Nothing captured -- bail out. */
     
    16521652    }
    16531653
    1654     Log2Func(("[%s] %RU32 samples captured, rc=%Rrc\n", pHstStream->szName, csCapturedTotal, rc));
    1655 
    1656     if (pcsCaptured)
    1657         *pcsCaptured = csCapturedTotal;
     1654    Log2Func(("[%s] %RU32 frames captured, rc=%Rrc\n", pHstStream->szName, cfCapturedTotal, rc));
     1655
     1656    if (pcfCaptured)
     1657        *pcfCaptured = cfCapturedTotal;
    16581658
    16591659    return rc;
     
    16621662/**
    16631663 * Captures raw input from a host stream.
    1664  * Raw input means that the backend directly operates on PDMAUDIOSAMPLE structs without
     1664 * Raw input means that the backend directly operates on PDMAUDIOFRAME structs without
    16651665 * no data layout processing done in between.
    16661666 *
     
    16701670 * @param   pThis               Driver instance.
    16711671 * @param   pHstStream          Host stream to capture from.
    1672  * @param   pcsCaptured         Number of (host) audio samples captured. Optional.
    1673  */
    1674 static int drvAudioStreamCaptureRaw(PDRVAUDIO pThis, PPDMAUDIOSTREAM pHstStream, uint32_t *pcsCaptured)
     1672 * @param   pcfCaptured         Number of (host) audio frames captured. Optional.
     1673 */
     1674static int drvAudioStreamCaptureRaw(PDRVAUDIO pThis, PPDMAUDIOSTREAM pHstStream, uint32_t *pcfCaptured)
    16751675{
    16761676    AssertPtrReturn(pThis,      VERR_INVALID_POINTER);
    16771677    AssertPtrReturn(pHstStream, VERR_INVALID_POINTER);
    1678     /* pcsCaptured is optional. */
     1678    /* pcfCaptured is optional. */
    16791679
    16801680    /* Sanity. */
     
    16851685    int rc = VINF_SUCCESS;
    16861686
    1687     uint32_t csCapturedTotal = 0;
     1687    uint32_t cfCapturedTotal = 0;
    16881688
    16891689    AssertPtr(pThis->pHostDrvAudio->pfnStreamGetReadable);
     
    17021702            cbReadable = cbFree;
    17031703
    1704         PPDMAUDIOSAMPLE paSamples;
    1705         uint32_t csWritable;
    1706         rc = AudioMixBufPeekMutable(&pHstStream->MixBuf, AUDIOMIXBUF_B2S(&pHstStream->MixBuf, cbReadable),
    1707                                     &paSamples, &csWritable);
     1704        PPDMAUDIOFRAME paFrames;
     1705        uint32_t cfWritable;
     1706        rc = AudioMixBufPeekMutable(&pHstStream->MixBuf, AUDIOMIXBUF_B2F(&pHstStream->MixBuf, cbReadable),
     1707                                    &paFrames, &cfWritable);
    17081708        if (   RT_FAILURE(rc)
    1709             || !csWritable)
    1710         {
    1711             break;
    1712         }
    1713 
    1714         uint32_t csCaptured;
     1709            || !cfWritable)
     1710        {
     1711            break;
     1712        }
     1713
     1714        uint32_t cfCaptured;
    17151715        rc = pThis->pHostDrvAudio->pfnStreamCapture(pThis->pHostDrvAudio, pHstStream->pvBackend,
    1716                                                     paSamples, csWritable, &csCaptured);
     1716                                                    paFrames, cfWritable, &cfCaptured);
    17171717        if (RT_FAILURE(rc))
    17181718        {
     
    17201720            AssertRC(rc2);
    17211721        }
    1722         else if (csCaptured)
    1723         {
    1724             Assert(csCaptured <= csWritable);
    1725             if (csCaptured > csWritable) /* Paranoia. */
    1726                 csCaptured = csWritable;
    1727 
    1728             csCapturedTotal += csCaptured;
     1722        else if (cfCaptured)
     1723        {
     1724            Assert(cfCaptured <= cfWritable);
     1725            if (cfCaptured > cfWritable) /* Paranoia. */
     1726                cfCaptured = cfWritable;
     1727
     1728            cfCapturedTotal += cfCaptured;
    17291729        }
    17301730        else /* Nothing captured -- bail out. */
     
    17351735    }
    17361736
    1737     Log2Func(("[%s] %RU32 samples captured, rc=%Rrc\n", pHstStream->szName, csCapturedTotal, rc));
    1738 
    1739     if (pcsCaptured)
    1740         *pcsCaptured = csCapturedTotal;
     1737    Log2Func(("[%s] %RU32 frames captured, rc=%Rrc\n", pHstStream->szName, cfCapturedTotal, rc));
     1738
     1739    if (pcfCaptured)
     1740        *pcfCaptured = cfCapturedTotal;
    17411741
    17421742    return rc;
     
    17471747 */
    17481748static DECLCALLBACK(int) drvAudioStreamCapture(PPDMIAUDIOCONNECTOR pInterface,
    1749                                                PPDMAUDIOSTREAM pStream, uint32_t *pcSamplesCaptured)
     1749                                               PPDMAUDIOSTREAM pStream, uint32_t *pcFramesCaptured)
    17501750{
    17511751    PDRVAUDIO pThis = PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface);
     
    17591759               pStream->szName, pStream->enmDir));
    17601760
    1761     uint32_t csCaptured = 0;
     1761    uint32_t cfCaptured = 0;
    17621762
    17631763    do
     
    18001800        if (RT_LIKELY(pHstStream->Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED))
    18011801        {
    1802             rc = drvAudioStreamCaptureNonInterleaved(pThis, pHstStream, &csCaptured);
     1802            rc = drvAudioStreamCaptureNonInterleaved(pThis, pHstStream, &cfCaptured);
    18031803        }
    18041804        else if (pHstStream->Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_RAW)
    18051805        {
    1806             rc = drvAudioStreamCaptureRaw(pThis, pHstStream, &csCaptured);
     1806            rc = drvAudioStreamCaptureRaw(pThis, pHstStream, &cfCaptured);
    18071807        }
    18081808        else
     
    18141814#ifdef LOG_ENABLED
    18151815        pszBackendSts = dbgAudioStreamStatusToStr(stsBackend);
    1816         Log3Func(("[%s] End: stsBackend=%s, csCaptured=%RU32, rc=%Rrc\n",
    1817                   pHstStream->szName, pszBackendSts, csCaptured, rc));
     1816        Log3Func(("[%s] End: stsBackend=%s, cfCaptured=%RU32, rc=%Rrc\n",
     1817                  pHstStream->szName, pszBackendSts, cfCaptured, rc));
    18181818        RTStrFree(pszBackendSts);
    18191819#endif /* LOG_ENABLED */
     
    18211821        if (RT_SUCCESS(rc))
    18221822        {
    1823             Log3Func(("[%s] %RU32 samples captured, rc=%Rrc\n", pHstStream->szName, csCaptured, rc));
     1823            Log3Func(("[%s] %RU32 frames captured, rc=%Rrc\n", pHstStream->szName, cfCaptured, rc));
    18241824
    18251825#ifdef VBOX_WITH_STATISTICS
    1826             STAM_COUNTER_ADD(&pThis->Stats.TotalSamplesIn,        csCaptured);
    1827             STAM_COUNTER_ADD(&pHstStream->In.StatSamplesCaptured, csCaptured);
     1826            STAM_COUNTER_ADD(&pThis->Stats.TotalFramesIn,        cfCaptured);
     1827            STAM_COUNTER_ADD(&pHstStream->In.StatFramesCaptured, cfCaptured);
    18281828#endif
    18291829        }
     
    18381838    } while (0);
    18391839
    1840     if (pcSamplesCaptured)
    1841         *pcSamplesCaptured = csCaptured;
     1840    if (pcFramesCaptured)
     1841        *pcFramesCaptured = cfCaptured;
    18421842
    18431843    int rc2 = RTCritSectLeave(&pThis->CritSect);
     
    23652365        uint32_t cReadTotal = 0;
    23662366
    2367         uint32_t cToRead = RT_MIN(AUDIOMIXBUF_B2S(&pGstStream->MixBuf, cbBuf), AudioMixBufUsed(&pGstStream->MixBuf));
     2367        uint32_t cToRead = RT_MIN(AUDIOMIXBUF_B2F(&pGstStream->MixBuf, cbBuf), AudioMixBufUsed(&pGstStream->MixBuf));
    23682368        while (cToRead)
    23692369        {
    23702370            uint32_t cRead;
    2371             rc = AudioMixBufReadCirc(&pGstStream->MixBuf, (uint8_t *)pvBuf + AUDIOMIXBUF_S2B(&pGstStream->MixBuf, cReadTotal),
    2372                                      AUDIOMIXBUF_S2B(&pGstStream->MixBuf, cToRead), &cRead);
     2371            rc = AudioMixBufReadCirc(&pGstStream->MixBuf, (uint8_t *)pvBuf + AUDIOMIXBUF_F2B(&pGstStream->MixBuf, cReadTotal),
     2372                                     AUDIOMIXBUF_F2B(&pGstStream->MixBuf, cToRead), &cRead);
    23732373            if (RT_FAILURE(rc))
    23742374                break;
    23752375
    23762376#if defined (VBOX_WITH_STATISTICS) || defined (VBOX_AUDIO_DEBUG_DUMP_PCM_DATA)
    2377             const uint32_t cbRead = AUDIOMIXBUF_S2B(&pGstStream->MixBuf, cRead);
     2377            const uint32_t cbRead = AUDIOMIXBUF_F2B(&pGstStream->MixBuf, cRead);
    23782378#endif
    23792379
     
    23922392#ifdef VBOX_AUDIO_DEBUG_DUMP_PCM_DATA
    23932393            drvAudioDbgPCMDump(pThis, VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH, "StreamRead.pcm",
    2394                                pvBuf, AUDIOMIXBUF_S2B(&pGstStream->MixBuf, cReadTotal));
     2394                               pvBuf, AUDIOMIXBUF_F2B(&pGstStream->MixBuf, cReadTotal));
    23952395#endif
    23962396            AudioMixBufFinish(&pGstStream->MixBuf, cReadTotal);
     
    23982398            pGstStream->In.tsLastReadMS = RTTimeMilliTS();
    23992399
    2400             cbReadTotal = AUDIOMIXBUF_S2B(&pGstStream->MixBuf, cReadTotal);
     2400            cbReadTotal = AUDIOMIXBUF_F2B(&pGstStream->MixBuf, cReadTotal);
    24012401        }
    24022402
     
    25482548                                      szStatName, STAMUNIT_BYTES, "Total bytes read.");
    25492549
    2550             RTStrPrintf(szStatName, sizeof(szStatName), "Host/%s/SamplesCaptured", pHstStrm->szName);
    2551             PDMDrvHlpSTAMRegCounterEx(pThis->pDrvIns, &pHstStrm->In.StatSamplesCaptured,
    2552                                       szStatName, STAMUNIT_COUNT, "Total samples captured.");
     2550            RTStrPrintf(szStatName, sizeof(szStatName), "Host/%s/FramesCaptured", pHstStrm->szName);
     2551            PDMDrvHlpSTAMRegCounterEx(pThis->pDrvIns, &pHstStrm->In.StatFramesCaptured,
     2552                                      szStatName, STAMUNIT_COUNT, "Total frames captured.");
    25532553        }
    25542554        else if (pCfgGuest->enmDir == PDMAUDIODIR_OUT)
     
    25622562                                      szStatName, STAMUNIT_BYTES, "Total bytes written.");
    25632563
    2564             RTStrPrintf(szStatName, sizeof(szStatName), "Host/%s/SamplesPlayed", pHstStrm->szName);
    2565             PDMDrvHlpSTAMRegCounterEx(pThis->pDrvIns, &pHstStrm->Out.StatSamplesPlayed,
    2566                                       szStatName, STAMUNIT_COUNT, "Total samples played.");
     2564            RTStrPrintf(szStatName, sizeof(szStatName), "Host/%s/FramesPlayed", pHstStrm->szName);
     2565            PDMDrvHlpSTAMRegCounterEx(pThis->pDrvIns, &pHstStrm->Out.StatFramesPlayed,
     2566                                      szStatName, STAMUNIT_COUNT, "Total frames played.");
    25672567        }
    25682568        else
     
    27232723
    27242724    Log3Func(("[%s] cbReadable=%RU32 (%zu bytes)\n", pHstStream->szName, cReadable,
    2725               AUDIOMIXBUF_S2B(&pGstStream->MixBuf, cReadable)));
    2726 
    2727     uint32_t cbReadable = AUDIOMIXBUF_S2B(&pGstStream->MixBuf, cReadable);
     2725              AUDIOMIXBUF_F2B(&pGstStream->MixBuf, cReadable)));
     2726
     2727    uint32_t cbReadable = AUDIOMIXBUF_F2B(&pGstStream->MixBuf, cReadable);
    27282728
    27292729    rc2 = RTCritSectLeave(&pThis->CritSect);
    27302730    AssertRC(rc2);
    27312731
    2732     /* Return bytes instead of audio samples. */
     2732    /* Return bytes instead of audio frames. */
    27332733    return cbReadable;
    27342734}
     
    28622862                if (pHstStream->enmDir == PDMAUDIODIR_IN)
    28632863                {
    2864                     PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pHstStream->In.StatSamplesCaptured);
     2864                    PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pHstStream->In.StatFramesCaptured);
    28652865                }
    28662866                else if (pHstStream->enmDir == PDMAUDIODIR_OUT)
    28672867                {
    2868                     PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pHstStream->Out.StatSamplesPlayed);
     2868                    PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pHstStream->Out.StatFramesPlayed);
    28692869                }
    28702870                else
     
    28912891                    PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pGstStream->In.StatBytesElapsed);
    28922892                    PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pGstStream->In.StatBytesTotalRead);
    2893                     PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pGstStream->In.StatSamplesCaptured);
     2893                    PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pGstStream->In.StatFramesCaptured);
    28942894                }
    28952895                else if (pGstStream->enmDir == PDMAUDIODIR_OUT)
     
    28972897                    PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pGstStream->Out.StatBytesElapsed);
    28982898                    PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pGstStream->Out.StatBytesTotalWritten);
    2899                     PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pGstStream->Out.StatSamplesPlayed);
     2899                    PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pGstStream->Out.StatFramesPlayed);
    29002900                }
    29012901                else
     
    32173217        PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalStreamsCreated,  "TotalStreamsCreated",
    32183218                                  STAMUNIT_COUNT, "Total created audio streams.");
    3219         PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalSamplesRead,     "TotalSamplesRead",
    3220                                   STAMUNIT_COUNT, "Total samples read by device emulation.");
    3221         PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalSamplesWritten,  "TotalSamplesWritten",
    3222                                   STAMUNIT_COUNT, "Total samples written by device emulation ");
    3223         PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalSamplesMixedIn,  "TotalSamplesMixedIn",
    3224                                   STAMUNIT_COUNT, "Total input samples mixed.");
    3225         PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalSamplesMixedOut, "TotalSamplesMixedOut",
    3226                                   STAMUNIT_COUNT, "Total output samples mixed.");
    3227         PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalSamplesLostIn,   "TotalSamplesLostIn",
    3228                                   STAMUNIT_COUNT, "Total input samples lost.");
    3229         PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalSamplesLostOut,  "TotalSamplesLostOut",
    3230                                   STAMUNIT_COUNT, "Total output samples lost.");
    3231         PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalSamplesOut,      "TotalSamplesPlayed",
    3232                                   STAMUNIT_COUNT, "Total samples played by backend.");
    3233         PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalSamplesIn,       "TotalSamplesCaptured",
    3234                                   STAMUNIT_COUNT, "Total samples captured by backend.");
     3219        PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalFramesRead,      "TotalFramesRead",
     3220                                  STAMUNIT_COUNT, "Total frames read by device emulation.");
     3221        PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalFramesWritten,   "TotalFramesWritten",
     3222                                  STAMUNIT_COUNT, "Total frames written by device emulation ");
     3223        PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalFramesMixedIn,   "TotalFramesMixedIn",
     3224                                  STAMUNIT_COUNT, "Total input frames mixed.");
     3225        PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalFramesMixedOut,  "TotalFramesMixedOut",
     3226                                  STAMUNIT_COUNT, "Total output frames mixed.");
     3227        PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalFramesLostIn,    "TotalFramesLostIn",
     3228                                  STAMUNIT_COUNT, "Total input frames lost.");
     3229        PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalFramesLostOut,   "TotalFramesLostOut",
     3230                                  STAMUNIT_COUNT, "Total output frames lost.");
     3231        PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalFramesOut,       "TotalFramesPlayed",
     3232                                  STAMUNIT_COUNT, "Total frames played by backend.");
     3233        PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalFramesIn,        "TotalFramesCaptured",
     3234                                  STAMUNIT_COUNT, "Total frames captured by backend.");
    32353235        PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalBytesRead,       "TotalBytesRead",
    32363236                                  STAMUNIT_BYTES, "Total bytes read.");
     
    33343334    PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalStreamsActive);
    33353335    PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalStreamsCreated);
    3336     PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalSamplesRead);
    3337     PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalSamplesWritten);
    3338     PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalSamplesMixedIn);
    3339     PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalSamplesMixedOut);
    3340     PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalSamplesLostIn);
    3341     PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalSamplesLostOut);
    3342     PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalSamplesOut);
    3343     PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalSamplesIn);
     3336    PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalFramesRead);
     3337    PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalFramesWritten);
     3338    PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalFramesMixedIn);
     3339    PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalFramesMixedOut);
     3340    PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalFramesLostIn);
     3341    PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalFramesLostOut);
     3342    PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalFramesOut);
     3343    PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalFramesIn);
    33443344    PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalBytesRead);
    33453345    PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalBytesWritten);
  • trunk/src/VBox/Devices/Audio/DrvAudio.h

    r67362 r68132  
    9494    STAMCOUNTER TotalStreamsActive;
    9595    STAMCOUNTER TotalStreamsCreated;
    96     STAMCOUNTER TotalSamplesRead;
    97     STAMCOUNTER TotalSamplesWritten;
    98     STAMCOUNTER TotalSamplesMixedIn;
    99     STAMCOUNTER TotalSamplesMixedOut;
    100     STAMCOUNTER TotalSamplesLostIn;
    101     STAMCOUNTER TotalSamplesLostOut;
    102     STAMCOUNTER TotalSamplesOut;
    103     STAMCOUNTER TotalSamplesIn;
     96    STAMCOUNTER TotalFramesRead;
     97    STAMCOUNTER TotalFramesWritten;
     98    STAMCOUNTER TotalFramesMixedIn;
     99    STAMCOUNTER TotalFramesMixedOut;
     100    STAMCOUNTER TotalFramesLostIn;
     101    STAMCOUNTER TotalFramesLostOut;
     102    STAMCOUNTER TotalFramesOut;
     103    STAMCOUNTER TotalFramesIn;
    104104    STAMCOUNTER TotalBytesRead;
    105105    STAMCOUNTER TotalBytesWritten;
     
    165165uint8_t DrvAudioHlpAudFmtToBits(PDMAUDIOFMT enmFmt);
    166166const char *DrvAudioHlpAudFmtToStr(PDMAUDIOFMT enmFmt);
    167 void DrvAudioHlpClearBuf(const PPDMAUDIOPCMPROPS pPCMInfo, void *pvBuf, size_t cbBuf, uint32_t cSamples);
     167void DrvAudioHlpClearBuf(const PPDMAUDIOPCMPROPS pPCMInfo, void *pvBuf, size_t cbBuf, uint32_t cFrames);
    168168uint32_t DrvAudioHlpCalcBitrate(uint8_t cBits, uint32_t uHz, uint8_t cChannels);
    169169uint32_t DrvAudioHlpCalcBitrate(const PPDMAUDIOPCMPROPS pProps);
  • trunk/src/VBox/Devices/Audio/DrvHostALSAAudio.cpp

    r68085 r68132  
    10351035        {
    10361036            case SND_PCM_STATE_PREPARED:
    1037                 cAvail = PDMAUDIOSTREAMCFG_B2S(pCfg, cxBuf);
     1037                cAvail = PDMAUDIOSTREAMCFG_B2F(pCfg, cxBuf);
    10381038                break;
    10391039
     
    10651065     * the mixer buffer.
    10661066     */
    1067     size_t cbToRead = RT_MIN((size_t)PDMAUDIOSTREAMCFG_S2B(pCfg, cAvail), cxBuf);
     1067    size_t cbToRead = RT_MIN((size_t)PDMAUDIOSTREAMCFG_F2B(pCfg, cAvail), cxBuf);
    10681068
    10691069    LogFlowFunc(("cbToRead=%zu, cAvail=%RI32\n", cbToRead, cAvail));
     
    10771077           && RT_SUCCESS(rc))
    10781078    {
    1079         cToRead = RT_MIN(PDMAUDIOSTREAMCFG_B2S(pCfg, cbToRead),
    1080                          PDMAUDIOSTREAMCFG_B2S(pCfg, pStreamALSA->cbBuf));
     1079        cToRead = RT_MIN(PDMAUDIOSTREAMCFG_B2F(pCfg, cbToRead),
     1080                         PDMAUDIOSTREAMCFG_B2F(pCfg, pStreamALSA->cbBuf));
    10811081        AssertBreakStmt(cToRead, rc = VERR_NO_DATA);
    10821082        cRead = snd_pcm_readi(pStreamALSA->phPCM, pStreamALSA->pvBuf, cToRead);
     
    11281128             * capture device for example).
    11291129             */
    1130             uint32_t cbRead = PDMAUDIOSTREAMCFG_S2B(pCfg, cRead);
     1130            uint32_t cbRead = PDMAUDIOSTREAMCFG_F2B(pCfg, cRead);
    11311131
    11321132            memcpy(pvBuf, pStreamALSA->pvBuf, cbRead);
     
    11811181            break;
    11821182
    1183         size_t cbToWrite = RT_MIN((unsigned)PDMAUDIOSTREAMCFG_S2B(pCfg, csAvail), pStreamALSA->cbBuf);
     1183        size_t cbToWrite = RT_MIN((unsigned)PDMAUDIOSTREAMCFG_F2B(pCfg, csAvail), pStreamALSA->cbBuf);
    11841184        if (!cbToWrite)
    11851185            break;
     
    11981198        {
    11991199            csWritten = snd_pcm_writei(pStreamALSA->phPCM, pStreamALSA->pvBuf,
    1200                                        PDMAUDIOSTREAMCFG_B2S(pCfg, cbToWrite));
     1200                                       PDMAUDIOSTREAMCFG_B2F(pCfg, cbToWrite));
    12011201            if (csWritten <= 0)
    12021202            {
     
    12511251            break;
    12521252
    1253         cbWrittenTotal = PDMAUDIOSTREAMCFG_S2B(pCfg, csWritten);
     1253        cbWrittenTotal = PDMAUDIOSTREAMCFG_F2B(pCfg, csWritten);
    12541254
    12551255    } while (0);
     
    13201320            break;
    13211321
    1322         pCfgAcq->cSampleBufferHint = obt.samples * 4;
     1322        pCfgAcq->cFrameBufferHint = obt.samples * 4;
    13231323
    13241324        AssertBreakStmt(obt.samples, rc = VERR_INVALID_PARAMETER);
    13251325
    1326         size_t cbBuf = obt.samples * PDMAUDIOSTREAMCFG_S2B(pCfgAcq, 1);
     1326        size_t cbBuf = obt.samples * PDMAUDIOSTREAMCFG_F2B(pCfgAcq, 1);
    13271327        AssertBreakStmt(cbBuf, rc = VERR_INVALID_PARAMETER);
    13281328
     
    13751375            break;
    13761376
    1377         pCfgAcq->cSampleBufferHint = obt.samples;
     1377        pCfgAcq->cFrameBufferHint = obt.samples;
    13781378
    13791379        AssertBreakStmt(obt.samples, rc = VERR_INVALID_PARAMETER);
    13801380
    1381         size_t cbBuf = obt.samples * PDMAUDIOSTREAMCFG_S2B(pCfgAcq, 1);
     1381        size_t cbBuf = obt.samples * PDMAUDIOSTREAMCFG_F2B(pCfgAcq, 1);
    13821382        AssertBreakStmt(cbBuf, rc = VERR_INVALID_PARAMETER);
    13831383
     
    16441644    int rc = alsaStreamGetAvail(pStreamALSA->phPCM, &cFramesAvail);
    16451645    if (RT_SUCCESS(rc))
    1646         cbAvail = PDMAUDIOSTREAMCFG_S2B(pStreamALSA->pCfg, cFramesAvail);
     1646        cbAvail = PDMAUDIOSTREAMCFG_F2B(pStreamALSA->pCfg, cFramesAvail);
    16471647
    16481648    return cbAvail;
     
    16661666        && (uint32_t)cFramesAvail >= pStreamALSA->Out.cSamplesMin)
    16671667    {
    1668         cbAvail = PDMAUDIOSTREAMCFG_S2B(pStreamALSA->pCfg, cFramesAvail);
     1668        cbAvail = PDMAUDIOSTREAMCFG_F2B(pStreamALSA->pCfg, cFramesAvail);
    16691669    }
    16701670
  • trunk/src/VBox/Devices/Audio/DrvHostCoreAudio.cpp

    r68085 r68132  
    15911591    }
    15921592
    1593     rc = RTCircBufCreate(&pCAStream->pCircBuf, PDMAUDIOSTREAMCFG_S2B(pCfgReq, 4096)); /** @todo Make this configurable. */
     1593    rc = RTCircBufCreate(&pCAStream->pCircBuf, PDMAUDIOSTREAMCFG_F2B(pCfgReq, 4096)); /** @todo Make this configurable. */
    15941594    if (RT_FAILURE(rc))
    15951595        return rc;
     
    23082308            if (RT_SUCCESS(rc))
    23092309            {
    2310                 pCfgAcq->cSampleBufferHint = _4K; /** @todo Make this configurable. */
     2310                pCfgAcq->cFrameBufferHint = _4K; /** @todo Make this configurable. */
    23112311            }
    23122312            if (RT_SUCCESS(rc))
  • trunk/src/VBox/Devices/Audio/DrvHostDSound.cpp

    r68085 r68132  
    733733#endif /* VBOX_WITH_AUDIO_DEVICE_CALLBACKS */
    734734
    735         pCfgAcq->cSampleBufferHint = PDMAUDIOSTREAMCFG_B2S(pCfgAcq, pThis->cfg.cbBufferOut);
     735        pCfgAcq->cFrameBufferHint = PDMAUDIOSTREAMCFG_B2F(pCfgAcq, pThis->cfg.cbBufferOut);
    736736
    737737    } while (0);
     
    758758    if (SUCCEEDED(hr))
    759759    {
    760         DWORD len1 = PDMAUDIOPCMPROPS_B2S(pProps, cb1);
    761         DWORD len2 = PDMAUDIOPCMPROPS_B2S(pProps, cb2);
     760        DWORD len1 = PDMAUDIOPCMPROPS_B2F(pProps, cb1);
     761        DWORD len2 = PDMAUDIOPCMPROPS_B2F(pProps, cb2);
    762762
    763763        if (pv1 && len1)
     
    11701170               pStreamDS->In.offCaptureBufRead, pStreamDS->In.cbCaptureBuf));
    11711171
    1172         pCfgAcq->cSampleBufferHint = PDMAUDIOSTREAMCFG_B2S(pCfgAcq, pThis->cfg.cbBufferIn);
     1172        pCfgAcq->cFrameBufferHint = PDMAUDIOSTREAMCFG_B2F(pCfgAcq, pThis->cfg.cbBufferIn);
    11731173
    11741174    } while (0);
     
    15821582         * i.e. always leave a free space for 1 audio sample.
    15831583         */
    1584         const DWORD cbSample = PDMAUDIOPCMPROPS_S2B(pProps, 1);
     1584        const DWORD cbSample = PDMAUDIOPCMPROPS_F2B(pProps, 1);
    15851585        if (cbFree <= cbSample)
    15861586            break;
  • trunk/src/VBox/Devices/Audio/DrvHostDebugAudio.cpp

    r68085 r68132  
    125125
    126126    if (pCfgAcq)
    127         pCfgAcq->cSampleBufferHint = _1K;
     127        pCfgAcq->cFrameBufferHint = _1K;
    128128
    129129    return VINF_SUCCESS;
     
    138138    int rc = VINF_SUCCESS;
    139139
    140     pStreamDbg->Out.cbPlayBuffer  = _1K * PDMAUDIOSTREAMCFG_S2B(pCfgReq, 1); /** @todo Make this configurable? */
     140    pStreamDbg->Out.cbPlayBuffer  = _1K * PDMAUDIOSTREAMCFG_F2B(pCfgReq, 1); /** @todo Make this configurable? */
    141141    pStreamDbg->Out.auPlayBuffer  = (uint8_t *)RTMemAlloc(pStreamDbg->Out.cbPlayBuffer);
    142142    if (!pStreamDbg->Out.auPlayBuffer)
     
    170170    {
    171171        if (pCfgAcq)
    172             pCfgAcq->cSampleBufferHint = PDMAUDIOSTREAMCFG_B2S(pCfgAcq, pStreamDbg->Out.cbPlayBuffer);
     172            pCfgAcq->cFrameBufferHint = PDMAUDIOSTREAMCFG_B2F(pCfgAcq, pStreamDbg->Out.cbPlayBuffer);
    173173    }
    174174
  • trunk/src/VBox/Devices/Audio/DrvHostNullAudio.cpp

    r68085 r68132  
    176176
    177177    if (pCfgAcq)
    178         pCfgAcq->cSampleBufferHint = _1K;
     178        pCfgAcq->cFrameBufferHint = _1K;
    179179
    180180    return VINF_SUCCESS;
     
    187187
    188188    if (pCfgAcq)
    189         pCfgAcq->cSampleBufferHint = _1K; /** @todo Make this configurable. */
     189        pCfgAcq->cFrameBufferHint = _1K; /** @todo Make this configurable. */
    190190
    191191    return VINF_SUCCESS;
  • trunk/src/VBox/Devices/Audio/DrvHostOSSAudio.cpp

    r68085 r68132  
    360360        {
    361361            DrvAudioHlpClearBuf(&pStreamOSS->pCfg->Props, pStreamOSS->pvBuf, pStreamOSS->cbBuf,
    362                                 PDMAUDIOPCMPROPS_B2S(&pStreamOSS->pCfg->Props, pStreamOSS->cbBuf));
     362                                PDMAUDIOPCMPROPS_B2F(&pStreamOSS->pCfg->Props, pStreamOSS->cbBuf));
    363363
    364364            int mask = PCM_ENABLE_OUTPUT;
     
    647647            }
    648648
    649             uint32_t cSamples = PDMAUDIOSTREAMCFG_B2S(pCfgAcq, ossAcq.cFragments * ossAcq.cbFragmentSize);
     649            uint32_t cSamples = PDMAUDIOSTREAMCFG_B2F(pCfgAcq, ossAcq.cFragments * ossAcq.cbFragmentSize);
    650650            if (!cSamples)
    651651                rc = VERR_INVALID_PARAMETER;
     
    653653            if (RT_SUCCESS(rc))
    654654            {
    655                 size_t cbBuf = PDMAUDIOSTREAMCFG_S2B(pCfgAcq, cSamples);
     655                size_t cbBuf = PDMAUDIOSTREAMCFG_F2B(pCfgAcq, cSamples);
    656656                void  *pvBuf = RTMemAlloc(cbBuf);
    657657                if (!pvBuf)
     
    665665                pStreamOSS->cbBuf = cbBuf;
    666666
    667                 pCfgAcq->cSampleBufferHint = cSamples;
     667                pCfgAcq->cFrameBufferHint = cSamples;
    668668            }
    669669        }
     
    700700            memcpy(&pCfgAcq->Props, &obtStream.Props, sizeof(PDMAUDIOPCMPROPS));
    701701
    702             cSamples = PDMAUDIOSTREAMCFG_B2S(pCfgAcq, obtStream.cFragments * obtStream.cbFragmentSize);
     702            cSamples = PDMAUDIOSTREAMCFG_B2F(pCfgAcq, obtStream.cFragments * obtStream.cbFragmentSize);
    703703
    704704            if (obtStream.cFragments * obtStream.cbFragmentSize & pStreamOSS->uAlign)
     
    713713            pStreamOSS->Out.fMMIO = false;
    714714
    715             size_t cbBuf = PDMAUDIOSTREAMCFG_S2B(pCfgAcq, cSamples);
     715            size_t cbBuf = PDMAUDIOSTREAMCFG_F2B(pCfgAcq, cSamples);
    716716            Assert(cbBuf);
    717717
     
    781781            }
    782782#endif
    783             pCfgAcq->cSampleBufferHint = cSamples;
     783            pCfgAcq->cFrameBufferHint = cSamples;
    784784        }
    785785
  • trunk/src/VBox/Devices/Audio/DrvHostPulseAudio.cpp

    r68085 r68132  
    776776    if (cbBuf)
    777777    {
    778         pCfgAcq->cSampleBufferHint = PDMAUDIOSTREAMCFG_B2S(pCfgAcq, cbBuf);
     778        pCfgAcq->cFrameBufferHint = PDMAUDIOSTREAMCFG_B2F(pCfgAcq, cbBuf);
    779779
    780780        pStreamPA->pDrv = pThis;
     
    815815    pCfgAcq->Props.uHz         = pStreamPA->SampleSpec.rate;
    816816    pCfgAcq->Props.cChannels   = pStreamPA->SampleSpec.channels;
    817     pCfgAcq->cSampleBufferHint = PDMAUDIOSTREAMCFG_B2S(pCfgAcq,
     817    pCfgAcq->cFrameBufferHint = PDMAUDIOSTREAMCFG_B2F(pCfgAcq,
    818818                                                       RT_MIN(pStreamPA->BufAttr.fragsize * 10, pStreamPA->BufAttr.maxlength));
    819819
  • trunk/src/VBox/Devices/Audio/DrvHostValidationKit.cpp

    r68085 r68132  
    132132
    133133    if (pCfgAcq)
    134         pCfgAcq->cSampleBufferHint = _1K;
     134        pCfgAcq->cFrameBufferHint = _1K;
    135135
    136136    return VINF_SUCCESS;
     
    148148    pStreamDbg->uSamplesSinceStarted = 0;
    149149    pStreamDbg->Out.tsLastPlayed  = 0;
    150     pStreamDbg->Out.cbPlayBuffer  = 16 * _1K * PDMAUDIOSTREAMCFG_S2B(pCfgReq, 1); /** @todo Make this configurable? */
     150    pStreamDbg->Out.cbPlayBuffer  = 16 * _1K * PDMAUDIOSTREAMCFG_F2B(pCfgReq, 1); /** @todo Make this configurable? */
    151151    pStreamDbg->Out.pu8PlayBuffer = (uint8_t *)RTMemAlloc(pStreamDbg->Out.cbPlayBuffer);
    152152    if (!pStreamDbg->Out.pu8PlayBuffer)
     
    200200    {
    201201        if (pCfgAcq)
    202             pCfgAcq->cSampleBufferHint = PDMAUDIOSTREAMCFG_B2S(pCfgAcq, pStreamDbg->Out.cbPlayBuffer);
     202            pCfgAcq->cFrameBufferHint = PDMAUDIOSTREAMCFG_B2F(pCfgAcq, pStreamDbg->Out.cbPlayBuffer);
    203203    }
    204204
  • trunk/src/VBox/Devices/Audio/testcase/tstAudioMixBuffer.cpp

    r67697 r68132  
    6262    RTTESTI_CHECK_RC_OK(AudioMixBufInit(&mb, "Single", &config, cBufSize));
    6363    RTTESTI_CHECK(AudioMixBufSize(&mb) == cBufSize);
    64     RTTESTI_CHECK(AUDIOMIXBUF_B2S(&mb, AudioMixBufSizeBytes(&mb)) == cBufSize);
    65     RTTESTI_CHECK(AUDIOMIXBUF_S2B(&mb, AudioMixBufSize(&mb)) == AudioMixBufSizeBytes(&mb));
     64    RTTESTI_CHECK(AUDIOMIXBUF_B2F(&mb, AudioMixBufSizeBytes(&mb)) == cBufSize);
     65    RTTESTI_CHECK(AUDIOMIXBUF_F2B(&mb, AudioMixBufSize(&mb)) == AudioMixBufSizeBytes(&mb));
    6666    RTTESTI_CHECK(AudioMixBufFree(&mb) == cBufSize);
    67     RTTESTI_CHECK(AUDIOMIXBUF_S2B(&mb, AudioMixBufFree(&mb)) == AudioMixBufFreeBytes(&mb));
     67    RTTESTI_CHECK(AUDIOMIXBUF_F2B(&mb, AudioMixBufFree(&mb)) == AudioMixBufFreeBytes(&mb));
    6868
    6969    /*
    7070     * Absolute writes.
    7171     */
    72     uint32_t cSamplesRead  = 0, cSamplesWritten = 0, cSamplesWrittenAbs = 0;
    73     int8_t  samples8 [2] = { 0x12, 0x34 };
    74     int16_t samples16[2] = { 0xAA, 0xBB };
    75     int32_t samples32[2] = { 0xCC, 0xDD };
    76     /* int64_t samples64[2] = { 0xEE, 0xFF }; - unused */
    77 
    78     RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 0 /* Offset */, &samples8, sizeof(samples8), &cSamplesWritten));
    79     RTTESTI_CHECK(cSamplesWritten == 0 /* Samples */);
     72    uint32_t cFramesRead  = 0, cFramesWritten = 0, cFramesWrittenAbs = 0;
     73    int8_t  aFrames8 [2] = { 0x12, 0x34 };
     74    int16_t aFrames16[2] = { 0xAA, 0xBB };
     75    int32_t aFrames32[2] = { 0xCC, 0xDD };
     76
     77    RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 0 /* Offset */, &aFrames8, sizeof(aFrames8), &cFramesWritten));
     78    RTTESTI_CHECK(cFramesWritten == 0 /* Frames */);
    8079    RTTESTI_CHECK(AudioMixBufUsed(&mb) == 0);
    8180
    82     RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 0 /* Offset */, &samples16, sizeof(samples16), &cSamplesWritten));
    83     RTTESTI_CHECK(cSamplesWritten == 1 /* Samples */);
     81    RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 0 /* Offset */, &aFrames16, sizeof(aFrames16), &cFramesWritten));
     82    RTTESTI_CHECK(cFramesWritten == 1 /* Frames */);
    8483    RTTESTI_CHECK(AudioMixBufUsed(&mb) == 1);
    8584
    86     RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 2 /* Offset */, &samples32, sizeof(samples32), &cSamplesWritten));
    87     RTTESTI_CHECK(cSamplesWritten == 2 /* Samples */);
     85    RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 2 /* Offset */, &aFrames32, sizeof(aFrames32), &cFramesWritten));
     86    RTTESTI_CHECK(cFramesWritten == 2 /* Frames */);
    8887    RTTESTI_CHECK(AudioMixBufUsed(&mb) == 2);
    8988
    9089    /* Beyond buffer. */
    91     RTTESTI_CHECK_RC(AudioMixBufWriteAt(&mb, AudioMixBufSize(&mb) + 1, &samples16, sizeof(samples16),
    92                                         &cSamplesWritten), VERR_BUFFER_OVERFLOW);
    93 
    94     /* Offset wrap-around: When writing as much (or more) samples the mixing buffer can hold. */
     90    RTTESTI_CHECK_RC(AudioMixBufWriteAt(&mb, AudioMixBufSize(&mb) + 1, &aFrames16, sizeof(aFrames16),
     91                                        &cFramesWritten), VERR_BUFFER_OVERFLOW);
     92
     93    /* Offset wrap-around: When writing as much (or more) frames the mixing buffer can hold. */
    9594    uint32_t  cbSamples = cBufSize * sizeof(int16_t) * 2 /* Channels */;
    9695    RTTESTI_CHECK(cbSamples);
    9796    uint16_t *paSamples = (uint16_t *)RTMemAlloc(cbSamples);
    9897    RTTESTI_CHECK(paSamples);
    99     RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 0 /* Offset */, paSamples, cbSamples, &cSamplesWritten));
    100     RTTESTI_CHECK(cSamplesWritten == cBufSize /* Samples */);
     98    RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 0 /* Offset */, paSamples, cbSamples, &cFramesWritten));
     99    RTTESTI_CHECK(cFramesWritten == cBufSize /* Frames */);
    101100    RTTESTI_CHECK(AudioMixBufUsed(&mb) == cBufSize);
    102101    RTTESTI_CHECK(AudioMixBufReadPos(&mb) == 0);
     
    110109    AudioMixBufReset(&mb);
    111110
    112     RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 2 /* Offset */, &samples32, sizeof(samples32), &cSamplesWritten));
    113     RTTESTI_CHECK(cSamplesWritten == 2 /* Samples */);
     111    RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 2 /* Offset */, &aFrames32, sizeof(aFrames32), &cFramesWritten));
     112    RTTESTI_CHECK(cFramesWritten == 2 /* Frames */);
    114113    RTTESTI_CHECK(AudioMixBufUsed(&mb) == 2);
    115114
    116     cSamplesWrittenAbs = AudioMixBufUsed(&mb);
    117 
    118     uint32_t cToWrite = AudioMixBufSize(&mb) - cSamplesWrittenAbs - 1; /* -1 as padding plus -2 samples for above. */
     115    cFramesWrittenAbs = AudioMixBufUsed(&mb);
     116
     117    uint32_t cToWrite = AudioMixBufSize(&mb) - cFramesWrittenAbs - 1; /* -1 as padding plus -2 frames for above. */
    119118    for (uint32_t i = 0; i < cToWrite; i++)
    120119    {
    121         RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&mb, &samples16, sizeof(samples16), &cSamplesWritten));
    122         RTTESTI_CHECK(cSamplesWritten == 1);
     120        RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&mb, &aFrames16, sizeof(aFrames16), &cFramesWritten));
     121        RTTESTI_CHECK(cFramesWritten == 1);
    123122    }
    124123    RTTESTI_CHECK(!AudioMixBufIsEmpty(&mb));
    125124    RTTESTI_CHECK(AudioMixBufFree(&mb) == 1);
    126     RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_S2B(&mb, 1U));
    127     RTTESTI_CHECK(AudioMixBufUsed(&mb) == cToWrite + cSamplesWrittenAbs /* + last absolute write */);
    128 
    129     RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&mb, &samples16, sizeof(samples16), &cSamplesWritten));
    130     RTTESTI_CHECK(cSamplesWritten == 1);
     125    RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_F2B(&mb, 1U));
     126    RTTESTI_CHECK(AudioMixBufUsed(&mb) == cToWrite + cFramesWrittenAbs /* + last absolute write */);
     127
     128    RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&mb, &aFrames16, sizeof(aFrames16), &cFramesWritten));
     129    RTTESTI_CHECK(cFramesWritten == 1);
    131130    RTTESTI_CHECK(AudioMixBufFree(&mb) == 0);
    132     RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_S2B(&mb, 0U));
     131    RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_F2B(&mb, 0U));
    133132    RTTESTI_CHECK(AudioMixBufUsed(&mb) == cBufSize);
    134133
    135134    /* Circular reads. */
    136     uint32_t cToRead = AudioMixBufSize(&mb) - cSamplesWrittenAbs - 1;
     135    uint32_t cToRead = AudioMixBufSize(&mb) - cFramesWrittenAbs - 1;
    137136    for (uint32_t i = 0; i < cToRead; i++)
    138137    {
    139         RTTESTI_CHECK_RC_OK(AudioMixBufReadCirc(&mb, &samples16, sizeof(samples16), &cSamplesRead));
    140         RTTESTI_CHECK(cSamplesRead == 1);
    141         AudioMixBufFinish(&mb, cSamplesRead);
     138        RTTESTI_CHECK_RC_OK(AudioMixBufReadCirc(&mb, &aFrames16, sizeof(aFrames16), &cFramesRead));
     139        RTTESTI_CHECK(cFramesRead == 1);
     140        AudioMixBufFinish(&mb, cFramesRead);
    142141    }
    143142    RTTESTI_CHECK(!AudioMixBufIsEmpty(&mb));
    144     RTTESTI_CHECK(AudioMixBufFree(&mb) == AudioMixBufSize(&mb) - cSamplesWrittenAbs - 1);
    145     RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_S2B(&mb, cBufSize - cSamplesWrittenAbs - 1));
     143    RTTESTI_CHECK(AudioMixBufFree(&mb) == AudioMixBufSize(&mb) - cFramesWrittenAbs - 1);
     144    RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_F2B(&mb, cBufSize - cFramesWrittenAbs - 1));
    146145    RTTESTI_CHECK(AudioMixBufUsed(&mb) == cBufSize - cToRead);
    147146
    148     RTTESTI_CHECK_RC_OK(AudioMixBufReadCirc(&mb, &samples16, sizeof(samples16), &cSamplesRead));
    149     RTTESTI_CHECK(cSamplesRead == 1);
    150     AudioMixBufFinish(&mb, cSamplesRead);
    151     RTTESTI_CHECK(AudioMixBufFree(&mb) == cBufSize - cSamplesWrittenAbs);
    152     RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_S2B(&mb, cBufSize - cSamplesWrittenAbs));
    153     RTTESTI_CHECK(AudioMixBufUsed(&mb) == cSamplesWrittenAbs);
     147    RTTESTI_CHECK_RC_OK(AudioMixBufReadCirc(&mb, &aFrames16, sizeof(aFrames16), &cFramesRead));
     148    RTTESTI_CHECK(cFramesRead == 1);
     149    AudioMixBufFinish(&mb, cFramesRead);
     150    RTTESTI_CHECK(AudioMixBufFree(&mb) == cBufSize - cFramesWrittenAbs);
     151    RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_F2B(&mb, cBufSize - cFramesWrittenAbs));
     152    RTTESTI_CHECK(AudioMixBufUsed(&mb) == cFramesWrittenAbs);
    154153
    155154    AudioMixBufDestroy(&mb);
     
    191190    RTTESTI_CHECK(DrvAudioHlpPCMPropsAreValid(&cfg_c1));
    192191
    193     uint32_t cSamples      = 16;
    194     uint32_t cChildBufSize = RTRandU32Ex(cSamples /* Min */, 64 /* Max */);
     192    uint32_t cFrames      = 16;
     193    uint32_t cChildBufSize = RTRandU32Ex(cFrames /* Min */, 64 /* Max */);
    195194
    196195    PDMAUDIOMIXBUF child1;
     
    220219    uint32_t cbBuf = _1K;
    221220    char pvBuf[_1K];
    222     int16_t samples[32] = { 0xAA, 0xBB };
    223     uint32_t cSamplesRead, cSamplesWritten, cSamplesMixed;
    224 
    225     uint32_t cSamplesChild1  = cSamples;
    226     uint32_t cSamplesChild2  = cSamples;
     221    int16_t aFrames16[32] = { 0xAA, 0xBB };
     222    uint32_t cFramesRead, cFramesWritten, cFramesMixed;
     223
     224    uint32_t cFramesChild1  = cFrames;
     225    uint32_t cFramesChild2  = cFrames;
    227226
    228227    uint32_t t = RTRandU32() % 32;
    229228
    230229    RTTestPrintf(hTest, RTTESTLVL_DEBUG,
    231                  "cParentBufSize=%RU32, cChildBufSize=%RU32, %RU32 samples -> %RU32 iterations total\n",
    232                  cParentBufSize, cChildBufSize, cSamples, t);
     230                 "cParentBufSize=%RU32, cChildBufSize=%RU32, %RU32 frames -> %RU32 iterations total\n",
     231                 cParentBufSize, cChildBufSize, cFrames, t);
    233232
    234233    /*
     
    248247        {
    249248            /* Child 1. */
    250             RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufWriteAt(&child1, 0, &samples, sizeof(samples), &cSamplesWritten));
    251             RTTESTI_CHECK_MSG_BREAK(cSamplesWritten == cSamplesChild1, ("Child1: Expected %RU32 written samples, got %RU32\n", cSamplesChild1, cSamplesWritten));
    252             RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufMixToParent(&child1, cSamplesWritten, &cSamplesMixed));
    253 
    254             cChildrenSamplesMixedTotal += cSamplesMixed;
    255 
    256             RTTESTI_CHECK_MSG_BREAK(cSamplesWritten == cSamplesMixed, ("Child1: Expected %RU32 mixed samples, got %RU32\n", cSamplesWritten, cSamplesMixed));
    257             RTTESTI_CHECK_MSG_BREAK(AudioMixBufUsed(&child1) == 0, ("Child1: Expected %RU32 used samples, got %RU32\n", 0, AudioMixBufUsed(&child1)));
     249            RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufWriteAt(&child1, 0, &aFrames16, sizeof(aFrames16), &cFramesWritten));
     250            RTTESTI_CHECK_MSG_BREAK(cFramesWritten == cFramesChild1, ("Child1: Expected %RU32 written frames, got %RU32\n", cFramesChild1, cFramesWritten));
     251            RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufMixToParent(&child1, cFramesWritten, &cFramesMixed));
     252
     253            cChildrenSamplesMixedTotal += cFramesMixed;
     254
     255            RTTESTI_CHECK_MSG_BREAK(cFramesWritten == cFramesMixed, ("Child1: Expected %RU32 mixed frames, got %RU32\n", cFramesWritten, cFramesMixed));
     256            RTTESTI_CHECK_MSG_BREAK(AudioMixBufUsed(&child1) == 0, ("Child1: Expected %RU32 used frames, got %RU32\n", 0, AudioMixBufUsed(&child1)));
    258257        }
    259258
     
    263262        {
    264263            /* Child 2. */
    265             RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufWriteAt(&child2, 0, &samples, sizeof(samples), &cSamplesWritten));
    266             RTTESTI_CHECK_MSG_BREAK(cSamplesWritten == cSamplesChild2, ("Child2: Expected %RU32 written samples, got %RU32\n", cSamplesChild2, cSamplesWritten));
    267             RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufMixToParent(&child2, cSamplesWritten, &cSamplesMixed));
    268 
    269             cChildrenSamplesMixedTotal += cSamplesMixed;
    270 
    271             RTTESTI_CHECK_MSG_BREAK(cSamplesWritten == cSamplesMixed, ("Child2: Expected %RU32 mixed samples, got %RU32\n", cSamplesWritten, cSamplesMixed));
    272             RTTESTI_CHECK_MSG_BREAK(AudioMixBufUsed(&child2) == 0, ("Child2: Expected %RU32 used samples, got %RU32\n", 0, AudioMixBufUsed(&child2)));
     264            RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufWriteAt(&child2, 0, &aFrames16, sizeof(aFrames16), &cFramesWritten));
     265            RTTESTI_CHECK_MSG_BREAK(cFramesWritten == cFramesChild2, ("Child2: Expected %RU32 written frames, got %RU32\n", cFramesChild2, cFramesWritten));
     266            RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufMixToParent(&child2, cFramesWritten, &cFramesMixed));
     267
     268            cChildrenSamplesMixedTotal += cFramesMixed;
     269
     270            RTTESTI_CHECK_MSG_BREAK(cFramesWritten == cFramesMixed, ("Child2: Expected %RU32 mixed frames, got %RU32\n", cFramesWritten, cFramesMixed));
     271            RTTESTI_CHECK_MSG_BREAK(AudioMixBufUsed(&child2) == 0, ("Child2: Expected %RU32 used frames, got %RU32\n", 0, AudioMixBufUsed(&child2)));
    273272        }
    274273
    275274        /*
    276          * Read out all samples from the parent buffer and also mark the just-read samples as finished
     275         * Read out all frames from the parent buffer and also mark the just-read frames as finished
    277276         * so that both connected children buffers can keep track of their stuff.
    278277         */
     
    280279        while (cParentSamples)
    281280        {
    282             RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, pvBuf, cbBuf, &cSamplesRead));
    283             if (!cSamplesRead)
     281            RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, pvBuf, cbBuf, &cFramesRead));
     282            if (!cFramesRead)
    284283                break;
    285284
    286             AudioMixBufFinish(&parent, cSamplesRead);
    287 
    288             RTTESTI_CHECK(cParentSamples >= cSamplesRead);
    289             cParentSamples -= cSamplesRead;
     285            AudioMixBufFinish(&parent, cFramesRead);
     286
     287            RTTESTI_CHECK(cParentSamples >= cFramesRead);
     288            cParentSamples -= cFramesRead;
    290289        }
    291290
     
    331330     * take shortcuts and performs conversion. Because conversion to double
    332331     * the sample rate effectively inserts one additional sample between every
    333      * two source samples, N source samples will be converted to N * 2 - 1
    334      * samples. However, the last source sample will be saved for later
     332     * two source frames, N source frames will be converted to N * 2 - 1
     333     * frames. However, the last source sample will be saved for later
    335334     * interpolation and not immediately output.
    336335     */
     
    353352    RTTESTI_CHECK_RC_OK(AudioMixBufLinkTo(&child, &parent));
    354353
    355     /* 8-bit unsigned samples. Often used with SB16 device. */
    356     uint8_t samples[16]  = { 0xAA, 0xBB, 0, 1, 43, 125, 126, 127,
    357                              128, 129, 130, 131, 132, UINT8_MAX - 1, UINT8_MAX, 0 };
     354    /* 8-bit unsigned frames. Often used with SB16 device. */
     355    uint8_t aFrames8U[16]  = { 0xAA, 0xBB, 0, 1, 43, 125, 126, 127,
     356                               128, 129, 130, 131, 132, UINT8_MAX - 1, UINT8_MAX, 0 };
    358357
    359358    /*
     
    362361    uint32_t    cbBuf = 256;
    363362    char        achBuf[256];
    364     uint32_t    cSamplesRead, cSamplesWritten, cSamplesMixed;
    365 
    366     uint32_t cSamplesChild  = 16;
    367     uint32_t cSamplesParent = cSamplesChild * 2 - 2;
    368     uint32_t cSamplesTotalRead   = 0;
     363    uint32_t    cFramesRead, cFramesWritten, cFramesMixed;
     364
     365    uint32_t cFramesChild  = 16;
     366    uint32_t cFramesParent = cFramesChild * 2 - 2;
     367    uint32_t cFramesTotalRead   = 0;
    369368
    370369    /**** 8-bit unsigned samples ****/
    371370    RTTestPrintf(hTest, RTTESTLVL_DEBUG, "Conversion test %uHz %uch 8-bit\n", cfg_c.uHz, cfg_c.cChannels);
    372     RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&child, &samples, sizeof(samples), &cSamplesWritten));
    373     RTTESTI_CHECK_MSG(cSamplesWritten == cSamplesChild, ("Child: Expected %RU32 written samples, got %RU32\n", cSamplesChild, cSamplesWritten));
    374     RTTESTI_CHECK_RC_OK(AudioMixBufMixToParent(&child, cSamplesWritten, &cSamplesMixed));
    375     uint32_t cSamples = AudioMixBufUsed(&parent);
    376     RTTESTI_CHECK_MSG(AudioMixBufLive(&child) == cSamples, ("Child: Expected %RU32 mixed samples, got %RU32\n", AudioMixBufLive(&child), cSamples));
     371    RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&child, &aFrames8U, sizeof(aFrames8U), &cFramesWritten));
     372    RTTESTI_CHECK_MSG(cFramesWritten == cFramesChild, ("Child: Expected %RU32 written frames, got %RU32\n", cFramesChild, cFramesWritten));
     373    RTTESTI_CHECK_RC_OK(AudioMixBufMixToParent(&child, cFramesWritten, &cFramesMixed));
     374    uint32_t cFrames = AudioMixBufUsed(&parent);
     375    RTTESTI_CHECK_MSG(AudioMixBufLive(&child) == cFrames, ("Child: Expected %RU32 mixed frames, got %RU32\n", AudioMixBufLive(&child), cFrames));
    377376
    378377    RTTESTI_CHECK(AudioMixBufUsed(&parent) == AudioMixBufLive(&child));
     
    380379    for (;;)
    381380    {
    382         RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, achBuf, cbBuf, &cSamplesRead));
    383         if (!cSamplesRead)
     381        RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, achBuf, cbBuf, &cFramesRead));
     382        if (!cFramesRead)
    384383            break;
    385         cSamplesTotalRead += cSamplesRead;
    386         AudioMixBufFinish(&parent, cSamplesRead);
    387     }
    388 
    389     RTTESTI_CHECK_MSG(cSamplesTotalRead == cSamplesParent, ("Parent: Expected %RU32 mixed samples, got %RU32\n", cSamplesParent, cSamplesTotalRead));
    390 
    391     /* Check that the samples came out unharmed. Every other sample is interpolated and we ignore it. */
     384        cFramesTotalRead += cFramesRead;
     385        AudioMixBufFinish(&parent, cFramesRead);
     386    }
     387
     388    RTTESTI_CHECK_MSG(cFramesTotalRead == cFramesParent, ("Parent: Expected %RU32 mixed frames, got %RU32\n", cFramesParent, cFramesTotalRead));
     389
     390    /* Check that the frames came out unharmed. Every other sample is interpolated and we ignore it. */
    392391    /* NB: This also checks that the default volume setting is 0dB attenuation. */
    393     uint8_t *pSrc8 = &samples[0];
     392    uint8_t *pSrc8 = &aFrames8U[0];
    394393    uint8_t *pDst8 = (uint8_t *)achBuf;
    395394
    396     for (i = 0; i < cSamplesChild - 1; ++i)
     395    for (i = 0; i < cFramesChild - 1; ++i)
    397396    {
    398397        RTTESTI_CHECK_MSG(*pSrc8 == *pDst8, ("index %u: Dst=%d, Src=%d\n", i, *pDst8, *pSrc8));
     
    452451
    453452    /* 16-bit signed. More or less exclusively used as output, and usually as input, too. */
    454     int16_t     samples[16] = { 0xAA, 0xBB, INT16_MIN, INT16_MIN + 1, INT16_MIN / 2, -3, -2, -1,
    455                                 0, 1, 2, 3, INT16_MAX / 2, INT16_MAX - 1, INT16_MAX, 0 };
     453    int16_t     aFrames16S[16] = { 0xAA, 0xBB, INT16_MIN, INT16_MIN + 1, INT16_MIN / 2, -3, -2, -1,
     454                                   0, 1, 2, 3, INT16_MAX / 2, INT16_MAX - 1, INT16_MAX, 0 };
    456455
    457456    /*
     
    460459    uint32_t    cbBuf = 256;
    461460    char        achBuf[256];
    462     uint32_t    cSamplesRead, cSamplesWritten, cSamplesMixed;
    463 
    464     uint32_t cSamplesChild  = 16;
    465     uint32_t cSamplesParent = cSamplesChild * 2 - 2;
    466     uint32_t cSamplesTotalRead   = 0;
     461    uint32_t    cFramesRead, cFramesWritten, cFramesMixed;
     462
     463    uint32_t cFramesChild  = 16;
     464    uint32_t cFramesParent = cFramesChild * 2 - 2;
     465    uint32_t cFramesTotalRead   = 0;
    467466
    468467    /**** 16-bit signed samples ****/
    469468    RTTestPrintf(hTest, RTTESTLVL_DEBUG, "Conversion test %uHz %uch 16-bit\n", cfg_c.uHz, cfg_c.cChannels);
    470     RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&child, &samples, sizeof(samples), &cSamplesWritten));
    471     RTTESTI_CHECK_MSG(cSamplesWritten == cSamplesChild, ("Child: Expected %RU32 written samples, got %RU32\n", cSamplesChild, cSamplesWritten));
    472     RTTESTI_CHECK_RC_OK(AudioMixBufMixToParent(&child, cSamplesWritten, &cSamplesMixed));
    473     uint32_t cSamples = AudioMixBufUsed(&parent);
    474     RTTESTI_CHECK_MSG(AudioMixBufLive(&child) == cSamples, ("Child: Expected %RU32 mixed samples, got %RU32\n", AudioMixBufLive(&child), cSamples));
     469    RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&child, &aFrames16S, sizeof(aFrames16S), &cFramesWritten));
     470    RTTESTI_CHECK_MSG(cFramesWritten == cFramesChild, ("Child: Expected %RU32 written frames, got %RU32\n", cFramesChild, cFramesWritten));
     471    RTTESTI_CHECK_RC_OK(AudioMixBufMixToParent(&child, cFramesWritten, &cFramesMixed));
     472    uint32_t cFrames = AudioMixBufUsed(&parent);
     473    RTTESTI_CHECK_MSG(AudioMixBufLive(&child) == cFrames, ("Child: Expected %RU32 mixed frames, got %RU32\n", AudioMixBufLive(&child), cFrames));
    475474
    476475    RTTESTI_CHECK(AudioMixBufUsed(&parent) == AudioMixBufLive(&child));
     
    478477    for (;;)
    479478    {
    480         RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, achBuf, cbBuf, &cSamplesRead));
    481         if (!cSamplesRead)
     479        RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, achBuf, cbBuf, &cFramesRead));
     480        if (!cFramesRead)
    482481            break;
    483         cSamplesTotalRead += cSamplesRead;
    484         AudioMixBufFinish(&parent, cSamplesRead);
    485     }
    486     RTTESTI_CHECK_MSG(cSamplesTotalRead == cSamplesParent, ("Parent: Expected %RU32 mixed samples, got %RU32\n", cSamplesParent, cSamplesTotalRead));
    487 
    488     /* Check that the samples came out unharmed. Every other sample is interpolated and we ignore it. */
     482        cFramesTotalRead += cFramesRead;
     483        AudioMixBufFinish(&parent, cFramesRead);
     484    }
     485    RTTESTI_CHECK_MSG(cFramesTotalRead == cFramesParent, ("Parent: Expected %RU32 mixed frames, got %RU32\n", cFramesParent, cFramesTotalRead));
     486
     487    /* Check that the frames came out unharmed. Every other sample is interpolated and we ignore it. */
    489488    /* NB: This also checks that the default volume setting is 0dB attenuation. */
    490     int16_t *pSrc16 = &samples[0];
     489    int16_t *pSrc16 = &aFrames16S[0];
    491490    int16_t *pDst16 = (int16_t *)achBuf;
    492491
    493     for (i = 0; i < cSamplesChild - 1; ++i)
     492    for (i = 0; i < cFramesChild - 1; ++i)
    494493    {
    495494        RTTESTI_CHECK_MSG(*pSrc16 == *pDst16, ("index %u: Dst=%d, Src=%d\n", i, *pDst16, *pSrc16));
     
    538537
    539538    /* A few 16-bit signed samples. */
    540     int16_t     samples[16] = { INT16_MIN, INT16_MIN + 1, -128, -64, -4, -1, 0, 1,
    541                                 2, 255, 256, INT16_MAX / 2, INT16_MAX - 2, INT16_MAX - 1, INT16_MAX, 0 };
     539    int16_t     aFrames16S[16] = { INT16_MIN, INT16_MIN + 1, -128, -64, -4, -1, 0, 1,
     540                                   2, 255, 256, INT16_MAX / 2, INT16_MAX - 2, INT16_MAX - 1, INT16_MAX, 0 };
    542541
    543542    /*
     
    546545    uint32_t    cbBuf = 256;
    547546    char        achBuf[256];
    548     uint32_t    cSamplesRead, cSamplesWritten, cSamplesMixed;
    549 
    550     uint32_t cSamplesChild  = 8;
    551     uint32_t cSamplesParent = cSamplesChild;
    552     uint32_t cSamplesTotalRead;
     547    uint32_t    cFramesRead, cFramesWritten, cFramesMixed;
     548
     549    uint32_t cFramesChild  = 8;
     550    uint32_t cFramesParent = cFramesChild;
     551    uint32_t cFramesTotalRead;
    553552    int16_t *pSrc16;
    554553    int16_t *pDst16;
     
    561560    AudioMixBufSetVolume(&child, &vol);
    562561
    563     RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&child, &samples, sizeof(samples), &cSamplesWritten));
    564     RTTESTI_CHECK_MSG(cSamplesWritten == cSamplesChild, ("Child: Expected %RU32 written samples, got %RU32\n", cSamplesChild, cSamplesWritten));
    565     RTTESTI_CHECK_RC_OK(AudioMixBufMixToParent(&child, cSamplesWritten, &cSamplesMixed));
    566 
    567     cSamplesTotalRead = 0;
     562    RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&child, &aFrames16S, sizeof(aFrames16S), &cFramesWritten));
     563    RTTESTI_CHECK_MSG(cFramesWritten == cFramesChild, ("Child: Expected %RU32 written frames, got %RU32\n", cFramesChild, cFramesWritten));
     564    RTTESTI_CHECK_RC_OK(AudioMixBufMixToParent(&child, cFramesWritten, &cFramesMixed));
     565
     566    cFramesTotalRead = 0;
    568567    for (;;)
    569568    {
    570         RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, achBuf, cbBuf, &cSamplesRead));
    571         if (!cSamplesRead)
     569        RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, achBuf, cbBuf, &cFramesRead));
     570        if (!cFramesRead)
    572571            break;
    573         cSamplesTotalRead += cSamplesRead;
    574         AudioMixBufFinish(&parent, cSamplesRead);
    575     }
    576     RTTESTI_CHECK_MSG(cSamplesTotalRead == cSamplesParent, ("Parent: Expected %RU32 mixed samples, got %RU32\n", cSamplesParent, cSamplesTotalRead));
    577 
    578     /* Check that at 0dB the samples came out unharmed. */
    579     pSrc16 = &samples[0];
     572        cFramesTotalRead += cFramesRead;
     573        AudioMixBufFinish(&parent, cFramesRead);
     574    }
     575    RTTESTI_CHECK_MSG(cFramesTotalRead == cFramesParent, ("Parent: Expected %RU32 mixed frames, got %RU32\n", cFramesParent, cFramesTotalRead));
     576
     577    /* Check that at 0dB the frames came out unharmed. */
     578    pSrc16 = &aFrames16S[0];
    580579    pDst16 = (int16_t *)achBuf;
    581580
    582     for (i = 0; i < cSamplesParent * 2 /* stereo */; ++i)
     581    for (i = 0; i < cFramesParent * 2 /* stereo */; ++i)
    583582    {
    584583        RTTESTI_CHECK_MSG(*pSrc16 == *pDst16, ("index %u: Dst=%d, Src=%d\n", i, *pDst16, *pSrc16));
     
    592591    AudioMixBufSetVolume(&child, &vol);
    593592
    594     RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&child, &samples, sizeof(samples), &cSamplesWritten));
    595     RTTESTI_CHECK_MSG(cSamplesWritten == cSamplesChild, ("Child: Expected %RU32 written samples, got %RU32\n", cSamplesChild, cSamplesWritten));
    596     RTTESTI_CHECK_RC_OK(AudioMixBufMixToParent(&child, cSamplesWritten, &cSamplesMixed));
    597 
    598     cSamplesTotalRead = 0;
     593    RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&child, &aFrames16S, sizeof(aFrames16S), &cFramesWritten));
     594    RTTESTI_CHECK_MSG(cFramesWritten == cFramesChild, ("Child: Expected %RU32 written frames, got %RU32\n", cFramesChild, cFramesWritten));
     595    RTTESTI_CHECK_RC_OK(AudioMixBufMixToParent(&child, cFramesWritten, &cFramesMixed));
     596
     597    cFramesTotalRead = 0;
    599598    for (;;)
    600599    {
    601         RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, achBuf, cbBuf, &cSamplesRead));
    602         if (!cSamplesRead)
     600        RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, achBuf, cbBuf, &cFramesRead));
     601        if (!cFramesRead)
    603602            break;
    604         cSamplesTotalRead += cSamplesRead;
    605         AudioMixBufFinish(&parent, cSamplesRead);
    606     }
    607     RTTESTI_CHECK_MSG(cSamplesTotalRead == cSamplesParent, ("Parent: Expected %RU32 mixed samples, got %RU32\n", cSamplesParent, cSamplesTotalRead));
     603        cFramesTotalRead += cFramesRead;
     604        AudioMixBufFinish(&parent, cFramesRead);
     605    }
     606    RTTESTI_CHECK_MSG(cFramesTotalRead == cFramesParent, ("Parent: Expected %RU32 mixed frames, got %RU32\n", cFramesParent, cFramesTotalRead));
    608607
    609608    /* Check that at -6dB the sample values are halved. */
    610     pSrc16 = &samples[0];
     609    pSrc16 = &aFrames16S[0];
    611610    pDst16 = (int16_t *)achBuf;
    612611
    613     for (i = 0; i < cSamplesParent * 2 /* stereo */; ++i)
     612    for (i = 0; i < cFramesParent * 2 /* stereo */; ++i)
    614613    {
    615614        /* Watch out! For negative values, x >> 1 is not the same as x / 2. */
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