VirtualBox

Changeset 58378 in vbox for trunk/src/VBox/Devices/Audio


Ignore:
Timestamp:
Oct 22, 2015 12:46:32 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
103601
Message:

Audio: Renaming / cleanups:

  • Got rid of custom shifting and use AUDIOMIXBUF_S2B / AUDIOMIXBUF_B2S instead.
  • Renamed drvAudioStreamCfgToProps() to DrvAudioStreamCfgToProps() as this is a public function for the host backends.
  • Replaced drvAudioHstOutSamplesLive() with AudioMixBufAvail().
Location:
trunk/src/VBox/Devices/Audio
Files:
10 edited

Legend:

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

    r58344 r58378  
    310310}
    311311
    312 void drvAudioClearBuf(PPDMPCMPROPS pPCMInfo, void *pvBuf, size_t cbBuf)
    313 {
    314     AssertPtrReturnVoid(pPCMInfo);
     312/**
     313 * Clears a sample buffer by the given amount of audio samples.
     314 *
     315 * @return  IPRT status code.
     316 * @param   pPCMProps               PCM properties to use for the buffer to clear.
     317 * @param   pvBuf                   Buffer to clear.
     318 * @param   cbBuf                   Size (in bytes) of the buffer.
     319 * @param   cSamples                Number of audio samples to clear in the buffer.
     320 */
     321void DrvAudioClearBuf(PPDMPCMPROPS pPCMProps, void *pvBuf, size_t cbBuf, uint32_t cSamples)
     322{
     323    AssertPtrReturnVoid(pPCMProps);
    315324    AssertPtrReturnVoid(pvBuf);
    316325
    317     if (!cbBuf)
     326    if (!cbBuf || !cSamples)
    318327        return;
    319328
    320     Log2Func(("pPCMInfo=%p, pvBuf=%p, cbBuf=%zu, fSigned=%RTbool, cBits=%RU8, cShift=%RU8\n",
    321               pPCMInfo, pvBuf, cbBuf, pPCMInfo->fSigned, pPCMInfo->cBits, pPCMInfo->cShift));
    322 
    323     if (pPCMInfo->fSigned)
    324     {
    325         memset(pvBuf, 0, cbBuf << pPCMInfo->cShift);
     329    Log2Func(("pPCMInfo=%p, pvBuf=%p, cSamples=%RU32, fSigned=%RTbool, cBits=%RU8, cShift=%RU8\n",
     330              pPCMProps, pvBuf, cSamples, pPCMProps->fSigned, pPCMProps->cBits, pPCMProps->cShift));
     331
     332    if (pPCMProps->fSigned)
     333    {
     334        memset(pvBuf, 0, cSamples << pPCMProps->cShift);
    326335    }
    327336    else
    328337    {
    329         switch (pPCMInfo->cBits)
    330         {
    331 
    332         case 8:
    333             memset(pvBuf, 0x80, cbBuf << pPCMInfo->cShift);
    334             break;
    335 
    336         case 16:
    337         {
    338             uint16_t *p = (uint16_t *)pvBuf;
    339             int shift = pPCMInfo->cChannels - 1;
    340             short s = INT16_MAX;
    341 
    342             if (pPCMInfo->fSwapEndian)
    343                 s = RT_BSWAP_U16(s);
    344 
    345             for (unsigned i = 0; i < cbBuf << shift; i++)
    346                 p[i] = s;
    347 
    348             break;
    349         }
    350 
    351         case 32:
    352         {
    353             uint32_t *p = (uint32_t *)pvBuf;
    354             int shift = pPCMInfo->cChannels - 1;
    355             int32_t s = INT32_MAX;
    356 
    357             if (pPCMInfo->fSwapEndian)
    358                 s = RT_BSWAP_U32(s);
    359 
    360             for (unsigned i = 0; i < cbBuf << shift; i++)
    361                 p[i] = s;
    362 
    363             break;
    364         }
    365 
    366         default:
    367             AssertMsgFailed(("Invalid bits: %RU8\n", pPCMInfo->cBits));
    368             break;
     338        switch (pPCMProps->cBits)
     339        {
     340            case 8:
     341            {
     342                memset(pvBuf, 0x80, cSamples << pPCMProps->cShift);
     343                break;
     344            }
     345
     346            case 16:
     347            {
     348                uint16_t *p = (uint16_t *)pvBuf;
     349                int shift = pPCMProps->cChannels - 1;
     350                short s = INT16_MAX;
     351
     352                if (pPCMProps->fSwapEndian)
     353                    s = RT_BSWAP_U16(s);
     354
     355                for (unsigned i = 0; i < cSamples << shift; i++)
     356                    p[i] = s;
     357
     358                break;
     359            }
     360
     361            case 32:
     362            {
     363                uint32_t *p = (uint32_t *)pvBuf;
     364                int shift = pPCMProps->cChannels - 1;
     365                int32_t s = INT32_MAX;
     366
     367                if (pPCMProps->fSwapEndian)
     368                    s = RT_BSWAP_U32(s);
     369
     370                for (unsigned i = 0; i < cSamples << shift; i++)
     371                    p[i] = s;
     372
     373                break;
     374            }
     375
     376            default:
     377            {
     378                AssertMsgFailed(("Invalid bits: %RU8\n", pPCMProps->cBits));
     379                break;
     380            }
    369381        }
    370382    }
     
    639651    AssertPtrReturn(pCfg,         VERR_INVALID_POINTER);
    640652
    641     int rc = drvAudioStreamCfgToProps(pCfg, &pGstStrmOut->Props);
     653    int rc = DrvAudioStreamCfgToProps(pCfg, &pGstStrmOut->Props);
    642654    if (RT_SUCCESS(rc))
    643655    {
     
    891903    AssertPtrReturn(pCfg, VERR_INVALID_POINTER);
    892904
    893     int rc = drvAudioStreamCfgToProps(pCfg, &pGstStrmIn->Props);
     905    int rc = DrvAudioStreamCfgToProps(pCfg, &pGstStrmIn->Props);
    894906    if (RT_SUCCESS(rc))
    895907    {
     
    11921204    while ((pHstStrmOut = drvAudioHstFindAnyEnabledOut(pThis, pHstStrmOut)))
    11931205    {
    1194         cSamplesLive = drvAudioHstOutSamplesLive(pHstStrmOut);
     1206        cSamplesLive = AudioMixBufAvail(&pHstStrmOut->MixBuf);
    11951207
    11961208        /* Has this stream marked as disabled but there still were guest streams relying
  • trunk/src/VBox/Devices/Audio/DrvAudio.h

    r57451 r58378  
    110110
    111111bool drvAudioPCMPropsAreEqual(PPDMPCMPROPS info, PPDMAUDIOSTREAMCFG pCfg);
    112 int drvAudioStreamCfgToProps(PPDMAUDIOSTREAMCFG pCfg, PPDMPCMPROPS pProps);
    113112void drvAudioStreamCfgPrint(PPDMAUDIOSTREAMCFG pCfg);
    114113
     
    144143
    145144/* Common functions between DrvAudio and backends (host audio drivers). */
    146 int  drvAudioAttachCapture(PDRVAUDIO pDrvAudio, PPDMAUDIOHSTSTRMOUT pHstStrmOut);
    147 void drvAudioClearBuf(PPDMPCMPROPS pPCMInfo, void *pvBuf, size_t cbBuf);
    148 void drvAudioDetachCapture(PPDMAUDIOHSTSTRMOUT pHstStrmOut);
    149 uint32_t drvAudioHstOutSamplesLive(PPDMAUDIOHSTSTRMOUT pHstStrmOut);
    150 
     145void DrvAudioClearBuf(PPDMPCMPROPS pPCMInfo, void *pvBuf, size_t cbBuf, uint32_t cSamples);
     146int DrvAudioStreamCfgToProps(PPDMAUDIOSTREAMCFG pCfg, PPDMPCMPROPS pProps);
    151147
    152148typedef struct fixed_settings
  • trunk/src/VBox/Devices/Audio/DrvAudioCommon.cpp

    r57451 r58378  
    309309}
    310310
    311 int drvAudioStreamCfgToProps(PPDMAUDIOSTREAMCFG pCfg, PPDMPCMPROPS pProps)
    312 {
     311/**
     312 * Converts an audio stream configuration to matching PCM properties.
     313 *
     314 * @return  IPRT status code.
     315 * @param   pCfg                    Audio stream configuration to convert.
     316 * @param   pProps                  PCM properties to save result to.
     317 */
     318int DrvAudioStreamCfgToProps(PPDMAUDIOSTREAMCFG pCfg, PPDMPCMPROPS pProps)
     319{
     320    AssertPtrReturn(pCfg,   VERR_INVALID_POINTER);
     321    AssertPtrReturn(pProps, VERR_INVALID_POINTER);
     322
    313323    int rc = VINF_SUCCESS;
    314324
     
    407417    }
    408418}
    409 
    410 /**
    411  * Finds the number of live samples for a specific output stream.
    412  *
    413  * @return  uint32_t                Minimum number of live host output samples processed
    414  *                                  by all connected guest output streams.
    415  * @param   pHstStrmOut             Host output stream to search in.
    416  */
    417 uint32_t drvAudioHstOutSamplesLive(PPDMAUDIOHSTSTRMOUT pHstStrmOut)
    418 {
    419     AssertPtrReturn(pHstStrmOut, 0);
    420 
    421     uint32_t cSamplesLive = AudioMixBufAvail(&pHstStrmOut->MixBuf);
    422 
    423     LogFlowFunc(("%s: cStreamsLive=%RU32, cSamplesLive=%RU32\n", pHstStrmOut->MixBuf.pszName, cSamplesLive));
    424     return cSamplesLive;
    425 }
    426 
  • trunk/src/VBox/Devices/Audio/DrvHostALSAAudio.cpp

    r57451 r58378  
    946946                                                 (uint32_t)cAvail), /* cAvail is always >= 0 */
    947947                                 AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf,
    948                                                  drvAudioHstOutSamplesLive(pHstStrmOut)));
     948                                                 AudioMixBufAvail(&pHstStrmOut->MixBuf)));
    949949        LogFlowFunc(("cbToRead=%zu, cbAvail=%zu\n",
    950950                     cbToRead, AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, cAvail)));
     
    11181118        streamCfg.enmEndianness = enmEnd;
    11191119
    1120         rc = drvAudioStreamCfgToProps(&streamCfg, &pHstStrmOut->Props);
     1120        rc = DrvAudioStreamCfgToProps(&streamCfg, &pHstStrmOut->Props);
    11211121        if (RT_FAILURE(rc))
    11221122            break;
     
    11891189        streamCfg.enmEndianness = enmEnd;
    11901190
    1191         rc = drvAudioStreamCfgToProps(&streamCfg, &pHstStrmIn->Props);
     1191        rc = DrvAudioStreamCfgToProps(&streamCfg, &pHstStrmIn->Props);
    11921192        if (RT_FAILURE(rc))
    11931193            break;
  • trunk/src/VBox/Devices/Audio/DrvHostCoreAudio.cpp

    r57571 r58378  
    14811481    /* Not much else to do here. */
    14821482
    1483     uint32_t cLive = drvAudioHstOutSamplesLive(pHstStrmOut);
     1483    uint32_t cLive = AudioMixBufAvail(&pHstStrmOut->MixBuf);;
    14841484    if (!cLive) /* Not samples to play? Bail out. */
    14851485    {
     
    15081508            RTCircBufReleaseWriteBlock(pStreamOut->pBuf, cbCopy);
    15091509            break;
    1510         }       
     1510        }
    15111511
    15121512        Assert(cbCopy <= cbToRead);
     
    18791879
    18801880    /* Initialize the hardware info section with the audio settings */
    1881     int rc = drvAudioStreamCfgToProps(pCfg, &pStreamIn->streamIn.Props);
     1881    int rc = DrvAudioStreamCfgToProps(pCfg, &pStreamIn->streamIn.Props);
    18821882    if (RT_SUCCESS(rc))
    18831883    {
     
    19381938
    19391939    /* Initialize the hardware info section with the audio settings */
    1940     drvAudioStreamCfgToProps(pCfg, &pStreamOut->streamOut.Props);
     1940    DrvAudioStreamCfgToProps(pCfg, &pStreamOut->streamOut.Props);
    19411941
    19421942#if 0
  • trunk/src/VBox/Devices/Audio/DrvHostDSound.cpp

    r58075 r58378  
    514514    AssertPtrReturnVoid(pDSoundStrmOut);
    515515
     516    PPDMAUDIOHSTSTRMOUT pStrmOut = &pDSoundStrmOut->strmOut;
     517
    516518    LPVOID pv1, pv2;
    517519    DWORD cb1, cb2;
    518520    HRESULT hr = directSoundPlayLock(pDSoundStrmOut->pDSB, &pDSoundStrmOut->strmOut.Props,
    519                                      0, pDSoundStrmOut->csPlaybackBufferSize << pDSoundStrmOut->strmOut.Props.cShift,
     521                                     0 /* dwOffset */, AUDIOMIXBUF_S2B(&pStrmOut->MixBuf, pDSoundStrmOut->csPlaybackBufferSize),
    520522                                     &pv1, &pv2, &cb1, &cb2, DSBLOCK_ENTIREBUFFER);
    521523    if (SUCCEEDED(hr))
    522524    {
    523         int len1 = cb1 >> pDSoundStrmOut->strmOut.Props.cShift;
    524         int len2 = cb2 >> pDSoundStrmOut->strmOut.Props.cShift;
     525        DWORD len1 = AUDIOMIXBUF_B2S(&pStrmOut->MixBuf, cb1);
     526        DWORD len2 = AUDIOMIXBUF_B2S(&pStrmOut->MixBuf, cb2);
    525527
    526528        if (pv1 && len1)
    527             drvAudioClearBuf(&pDSoundStrmOut->strmOut.Props, pv1, len1);
     529            DrvAudioClearBuf(&pDSoundStrmOut->strmOut.Props, pv1, cb1, len1);
    528530
    529531        if (pv2 && len2)
    530             drvAudioClearBuf(&pDSoundStrmOut->strmOut.Props, pv2, len2);
     532            DrvAudioClearBuf(&pDSoundStrmOut->strmOut.Props, pv2, cb2, len2);
    531533
    532534        directSoundPlayUnlock(pDSoundStrmOut->pDSB, pv1, pv2, cb1, cb2);
     
    534536}
    535537
    536 static HRESULT directSoundPlayGetStatus(LPDIRECTSOUNDBUFFER8 pDSB, DWORD *pStatus)
     538static HRESULT directSoundPlayGetStatus(LPDIRECTSOUNDBUFFER8 pDSB, DWORD *pdwStatus)
    537539{
    538540    AssertPtrReturn(pDSB, E_POINTER);
    539     /* pStatus is optional. */
     541    /* pdwStatus is optional. */
    540542
    541543    DWORD dwStatus = 0;
     
    553555    if (SUCCEEDED(hr))
    554556    {
    555         if (pStatus)
    556             *pStatus = dwStatus;
     557        if (pdwStatus)
     558            *pdwStatus = dwStatus;
    557559    }
    558560    else
     
    10241026    pDSoundStrmOut->streamCfg.enmEndianness = PDMAUDIOHOSTENDIANNESS;
    10251027
    1026     int rc = drvAudioStreamCfgToProps(&pDSoundStrmOut->streamCfg, &pDSoundStrmOut->strmOut.Props);
     1028    int rc = DrvAudioStreamCfgToProps(&pDSoundStrmOut->streamCfg, &pDSoundStrmOut->strmOut.Props);
    10271029    if (RT_SUCCESS(rc))
    10281030    {
     
    11201122
    11211123        int cShift = pHstStrmOut->Props.cShift;
    1122         DWORD cbBuffer = pDSoundStrmOut->csPlaybackBufferSize << cShift;
     1124        DWORD cbBuffer = AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, pDSoundStrmOut->csPlaybackBufferSize);
    11231125
    11241126        /* Get the current play position which is used for calculating the free space in the buffer. */
     
    11421144
    11431145        DWORD cbFree = cbBuffer - dsoundRingDistance(pDSoundStrmOut->cbPlayWritePos, cbPlayPos, cbBuffer);
    1144 
    1145         /* Check for full buffer, do not allow the cbPlayWritePos to catch cbPlayPos during playback,
     1146        /*
     1147         * Check for full buffer, do not allow the cbPlayWritePos to catch cbPlayPos during playback,
    11461148         * i.e. always leave a free space for 1 audio sample.
    11471149         */
    1148         if (cbFree <= (1U << cShift))
    1149             break;
    1150         cbFree -= (1U << cShift);
    1151 
    1152         uint32_t csLive = drvAudioHstOutSamplesLive(pHstStrmOut);
    1153         uint32_t cbLive = csLive << cShift;
     1150        const DWORD cbSample = AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, 1);
     1151        if (cbFree <= cbSample)
     1152            break;
     1153        cbFree     -= cbSample;
     1154
     1155        uint32_t csLive = AudioMixBufAvail(&pHstStrmOut->MixBuf);
     1156        uint32_t cbLive = AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, csLive);
    11541157
    11551158        /* Do not write more than available space in the DirectSound playback buffer. */
     
    11711174            break;
    11721175
    1173         DWORD len1 = cb1 >> cShift;
    1174         DWORD len2 = cb2 >> cShift;
     1176        DWORD len1 = AUDIOMIXBUF_B2S(&pHstStrmOut->MixBuf, cb1);
     1177        DWORD len2 = AUDIOMIXBUF_B2S(&pHstStrmOut->MixBuf, cb2);
    11751178
    11761179        uint32_t cRead = 0;
     
    11941197        directSoundPlayUnlock(pDSB, pv1, pv2, cb1, cb2);
    11951198
    1196         pDSoundStrmOut->cbPlayWritePos = (pDSoundStrmOut->cbPlayWritePos + (cReadTotal << cShift)) % cbBuffer;
     1199        pDSoundStrmOut->cbPlayWritePos =
     1200            (pDSoundStrmOut->cbPlayWritePos + AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, cReadTotal)) % cbBuffer;
    11971201
    11981202        DSLOGF(("DSound: %RU32 (%RU32 samples) out of %RU32%s, buffer write pos %ld, rc=%Rrc\n",
     
    12621266
    12631267    /** @todo caller should already init Props? */
    1264     int rc = drvAudioStreamCfgToProps(&pDSoundStrmIn->streamCfg, &pHstStrmIn->Props);
     1268    int rc = DrvAudioStreamCfgToProps(&pDSoundStrmIn->streamCfg, &pHstStrmIn->Props);
    12651269    if (RT_SUCCESS(rc))
    12661270    {
     
    14051409    DWORD cb1, cb2;
    14061410    hr = directSoundCaptureLock(pDSCB, &pHstStrmIn->Props,
    1407                                 pDSoundStrmIn->csCaptureReadPos << pHstStrmIn->Props.cShift,
    1408                                 csCaptured << pHstStrmIn->Props.cShift,
     1411                                AUDIOMIXBUF_S2B(&pHstStrmIn->MixBuf, pDSoundStrmIn->csCaptureReadPos), /* dwOffset */
     1412                                AUDIOMIXBUF_S2B(&pHstStrmIn->MixBuf, csCaptured),                      /* dwBytes */
    14091413                                &pv1, &pv2, &cb1, &cb2,
    14101414                                0 /* dwFlags */);
     
    14161420    }
    14171421
    1418     DWORD len1 = cb1 >> pHstStrmIn->Props.cShift;
    1419     DWORD len2 = cb2 >> pHstStrmIn->Props.cShift;
     1422    DWORD len1 = AUDIOMIXBUF_B2S(&pHstStrmIn->MixBuf, cb1);
     1423    DWORD len2 = AUDIOMIXBUF_B2S(&pHstStrmIn->MixBuf, cb2);
    14201424
    14211425    uint32_t csWrittenTotal = 0;
  • trunk/src/VBox/Devices/Audio/DrvHostNullAudio.cpp

    r58372 r58378  
    112112
    113113    /* Just adopt the wanted stream configuration. */
    114     int rc = drvAudioStreamCfgToProps(pCfg, &pHstStrmIn->Props);
     114    int rc = DrvAudioStreamCfgToProps(pCfg, &pHstStrmIn->Props);
    115115    if (RT_SUCCESS(rc))
    116116    {
     
    129129
    130130    /* Just adopt the wanted stream configuration. */
    131     int rc = drvAudioStreamCfgToProps(pCfg, &pHstStrmOut->Props);
     131    int rc = DrvAudioStreamCfgToProps(pCfg, &pHstStrmOut->Props);
    132132    if (RT_SUCCESS(rc))
    133133    {
     
    164164
    165165    /* Consume as many samples as would be played at the current frequency since last call. */
    166     uint32_t csLive          = drvAudioHstOutSamplesLive(pHstStrmOut);
     166    uint32_t csLive          = AudioMixBufAvail(&pHstStrmOut->MixBuf);;
    167167    uint64_t u64TicksNow     = PDMDrvHlpTMGetVirtualTime(pDrv->pDrvIns);
    168168    uint64_t u64TicksElapsed = u64TicksNow  - pNullStrmOut->u64TicksLast;
     
    185185
    186186    uint32_t csRead = 0;
    187     AudioMixBufReadCirc(&pHstStrmOut->MixBuf, pNullStrmOut->pu8PlayBuffer, cSamplesPlayed << pHstStrmOut->Props.cShift, &csRead);
     187    AudioMixBufReadCirc(&pHstStrmOut->MixBuf, pNullStrmOut->pu8PlayBuffer,
     188                        AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, cSamplesPlayed), &csRead);
    188189    AudioMixBufFinish(&pHstStrmOut->MixBuf, csRead);
    189190
  • trunk/src/VBox/Devices/Audio/DrvHostOSSAudio.cpp

    r57451 r58378  
    6666    int                cFragments;
    6767    int                cbFragmentSize;
    68     void              *pvBuf;
    69     size_t             cbBuf;
     68    /** Own PCM buffer. */
     69    void              *pvPCMBuf;
     70    /** Size (in bytes) of own PCM buffer. */
     71    size_t             cbPCMBuf;
    7072    int                old_optr;
    7173} OSSAUDIOSTREAMIN, *POSSAUDIOSTREAMIN;
     
    7981    int                 cbFragmentSize;
    8082#ifndef RT_OS_L4
     83    /** Whether we use a memory mapped file instead of our
     84     *  own allocated PCM buffer below. */
    8185    bool                fMemMapped;
    8286#endif
     87    /** Own PCM buffer in case memory mapping is unavailable. */
    8388    void               *pvPCMBuf;
     89    /** Size (in bytes) of own PCM buffer. */
     90    size_t              cbPCMBuf;
    8491    int                 old_optr;
    8592} OSSAUDIOSTREAMOUT, *POSSAUDIOSTREAMOUT;
     
    353360        case PDMAUDIOSTREAMCMD_ENABLE:
    354361        {
    355             drvAudioClearBuf(&pHstStrmOut->Props,
    356                              pThisStrmOut->pvPCMBuf, AudioMixBufSize(&pHstStrmOut->MixBuf));
     362            DrvAudioClearBuf(&pHstStrmOut->Props,
     363                             pThisStrmOut->pvPCMBuf, pThisStrmOut->cbPCMBuf, AudioMixBufSize(&pHstStrmOut->MixBuf));
    357364
    358365            mask = PCM_ENABLE_OUTPUT;
     
    406413
    407414    int rc = VINF_SUCCESS;
    408     size_t cbToRead = RT_MIN(pThisStrmIn->cbBuf,
     415    size_t cbToRead = RT_MIN(pThisStrmIn->cbPCMBuf,
    409416                             AudioMixBufFreeBytes(&pHstStrmIn->MixBuf));
    410417
     
    418425    while (cbToRead)
    419426    {
    420         cbTemp = RT_MIN(cbToRead, pThisStrmIn->cbBuf);
     427        cbTemp = RT_MIN(cbToRead, pThisStrmIn->cbPCMBuf);
    421428        AssertBreakStmt(cbTemp, rc = VERR_NO_DATA);
    422         cbRead = read(pThisStrmIn->hFile, (uint8_t *)pThisStrmIn->pvBuf + offWrite, cbTemp);
     429        cbRead = read(pThisStrmIn->hFile, (uint8_t *)pThisStrmIn->pvPCMBuf + offWrite, cbTemp);
    423430
    424431        LogFlowFunc(("cbRead=%zi, cbTemp=%RU32, cbToRead=%zu\n",
     
    455462            uint32_t cWritten;
    456463            rc = AudioMixBufWriteCirc(&pHstStrmIn->MixBuf,
    457                                       pThisStrmIn->pvBuf, cbRead,
     464                                      pThisStrmIn->pvPCMBuf, cbRead,
    458465                                      &cWritten);
    459466            if (RT_FAILURE(rc))
     
    501508    LogFlowFuncEnter();
    502509
    503     if (pThisStrmIn->pvBuf)
    504     {
    505         RTMemFree(pThisStrmIn->pvBuf);
    506         pThisStrmIn->pvBuf = NULL;
     510    if (pThisStrmIn->pvPCMBuf)
     511    {
     512        Assert(pThisStrmIn->cbPCMBuf);
     513
     514        RTMemFree(pThisStrmIn->pvPCMBuf);
     515        pThisStrmIn->pvPCMBuf = NULL;
    507516    }
     517
     518    pThisStrmIn->cbPCMBuf = 0;
    508519
    509520    return VINF_SUCCESS;
     
    524535        if (pThisStrmOut->pvPCMBuf)
    525536        {
     537            Assert(pThisStrmOut->cbPCMBuf);
     538
    526539            RTMemFree(pThisStrmOut->pvPCMBuf);
    527540            pThisStrmOut->pvPCMBuf = NULL;
    528541        }
     542
     543        pThisStrmOut->cbPCMBuf = 0;
    529544    }
    530545#endif
     
    587602            streamCfg.enmEndianness = obtStream.enmENDIANNESS;
    588603
    589             rc = drvAudioStreamCfgToProps(&streamCfg, &pHstStrmIn->Props);
     604            rc = DrvAudioStreamCfgToProps(&streamCfg, &pHstStrmIn->Props);
    590605            if (RT_SUCCESS(rc))
    591606            {
     
    599614        if (RT_SUCCESS(rc))
    600615        {
    601             size_t cbBuf = cSamples * (1 << pHstStrmIn->Props.cShift);
    602             pThisStrmIn->pvBuf = RTMemAlloc(cbBuf);
    603             if (!pThisStrmIn->pvBuf)
    604             {
    605                 LogRel(("OSS: Failed allocating ADC buffer with %RU32 samples, each %d bytes\n",
    606                         cSamples, 1 << pHstStrmIn->Props.cShift));
     616            size_t cbSample = (1 << pHstStrmIn->Props.cShift);
     617            size_t cbBuf    = cSamples * cbSample;
     618            pThisStrmIn->pvPCMBuf = RTMemAlloc(cbBuf);
     619            if (!pThisStrmIn->pvPCMBuf)
     620            {
     621                LogRel(("OSS: Failed allocating ADC buffer with %RU32 samples (%zu bytes per sample)\n", cSamples, cbSample));
    607622                rc = VERR_NO_MEMORY;
    608623            }
    609624
    610             pThisStrmIn->cbBuf = cbBuf;
     625            pThisStrmIn->cbPCMBuf = cbBuf;
    611626
    612627            if (pcSamples)
     
    664679            streamCfg.enmEndianness = obtStream.enmENDIANNESS;
    665680
    666             rc = drvAudioStreamCfgToProps(&streamCfg, &pHstStrmOut->Props);
     681            rc = DrvAudioStreamCfgToProps(&streamCfg, &pHstStrmOut->Props);
    667682            if (RT_SUCCESS(rc))
    668683                cSamples = (obtStream.cFragments * obtStream.cbFragmentSize)
     
    714729                                         cSamples << pHstStrmOut->Props.cShift);
    715730                        if (rc2)
    716                             LogRel(("OSS: Failed to unmap DAC output file: %s\n",
    717                                     strerror(errno)));
    718 
     731                            LogRel(("OSS: Failed to unmap DAC output file: %s\n", strerror(errno)));
    719732                        break;
    720733                    }
     
    728741            {
    729742#endif
     743                size_t cbSample = (1 << pHstStrmOut->Props.cShift);
     744                size_t cbPCMBuf = cSamples * cbSample;
     745
    730746                LogFlowFunc(("cSamples=%RU32\n", cSamples));
    731                 pThisStrmOut->pvPCMBuf = RTMemAlloc(cSamples * (1 << pHstStrmOut->Props.cShift));
     747
     748                pThisStrmOut->pvPCMBuf = RTMemAlloc(cbPCMBuf);
    732749                if (!pThisStrmOut->pvPCMBuf)
    733750                {
    734                     LogRel(("OSS: Failed allocating DAC buffer with %RU32 samples, each %d bytes\n",
    735                             cSamples, 1 << pHstStrmOut->Props.cShift));
     751                    LogRel(("OSS: Failed allocating DAC buffer with %RU32 samples (%zu bytes per sample)\n", cSamples, cbSample));
    736752                    rc = VERR_NO_MEMORY;
    737753                    break;
    738754                }
     755
     756                pThisStrmOut->cbPCMBuf = cbPCMBuf;
    739757#ifndef RT_OS_L4
    740758            }
     
    776794        size_t cbBuf = AudioMixBufSizeBytes(&pHstStrmOut->MixBuf);
    777795
    778         uint32_t cLive = drvAudioHstOutSamplesLive(pHstStrmOut);
     796        uint32_t cLive = AudioMixBufAvail(&pHstStrmOut->MixBuf);
    779797        uint32_t cToRead;
    780798
     
    858876            if (cbWritten == -1)
    859877            {
    860                 LogRel(("OSS: Failed writing output data %s\n", strerror(errno)));
     878                LogRel(("OSS: Failed writing output data: %s\n", strerror(errno)));
    861879                rc = RTErrConvertFromErrno(errno);
    862880                break;
  • trunk/src/VBox/Devices/Audio/DrvHostPulseAudio.cpp

    r57451 r58378  
    599599    streamCfg.cChannels = pThisStrmOut->SampleSpec.channels;
    600600
    601     rc = drvAudioStreamCfgToProps(&streamCfg, &pHstStrmOut->Props);
     601    rc = DrvAudioStreamCfgToProps(&streamCfg, &pHstStrmOut->Props);
    602602    if (RT_SUCCESS(rc))
    603603    {
     
    682682    streamCfg.cChannels = pThisStrmIn->SampleSpec.channels;
    683683
    684     rc = drvAudioStreamCfgToProps(&streamCfg, &pHstStrmIn->Props);
     684    rc = DrvAudioStreamCfgToProps(&streamCfg, &pHstStrmIn->Props);
    685685    if (RT_SUCCESS(rc))
    686686    {
     
    833833    uint32_t cbReadTotal = 0;
    834834
    835     uint32_t cLive = drvAudioHstOutSamplesLive(pHstStrmOut);
     835    uint32_t cLive = AudioMixBufAvail(&pHstStrmOut->MixBuf);
    836836    if (!cLive)
    837837    {
  • trunk/src/VBox/Devices/Audio/testcase/tstAudioMixBuffer.cpp

    r57358 r58378  
    5050    PDMPCMPROPS props;
    5151
    52     int rc = drvAudioStreamCfgToProps(&config, &props);
     52    int rc = DrvAudioStreamCfgToProps(&config, &props);
    5353    AssertRC(rc);
    5454
     
    149149    PDMPCMPROPS props;
    150150
    151     int rc = drvAudioStreamCfgToProps(&cfg_p, &props);
     151    int rc = DrvAudioStreamCfgToProps(&cfg_p, &props);
    152152    AssertRC(rc);
    153153
     
    163163    };
    164164
    165     rc = drvAudioStreamCfgToProps(&cfg_c1, &props);
     165    rc = DrvAudioStreamCfgToProps(&cfg_c1, &props);
    166166    AssertRC(rc);
    167167
     
    178178    };
    179179
    180     rc = drvAudioStreamCfgToProps(&cfg_c2, &props);
     180    rc = DrvAudioStreamCfgToProps(&cfg_c2, &props);
    181181    AssertRC(rc);
    182182
     
    260260    };
    261261
    262     int rc = drvAudioStreamCfgToProps(&cfg_p, &props);
     262    int rc = DrvAudioStreamCfgToProps(&cfg_p, &props);
    263263    AssertRC(rc);
    264264
     
    281281    };
    282282
    283     rc = drvAudioStreamCfgToProps(&cfg_c, &props);
     283    rc = DrvAudioStreamCfgToProps(&cfg_c, &props);
    284284    AssertRC(rc);
    285285
     
    364364    };
    365365
    366     int rc = drvAudioStreamCfgToProps(&cfg_p, &props);
     366    int rc = DrvAudioStreamCfgToProps(&cfg_p, &props);
    367367    AssertRC(rc);
    368368
     
    378378    };
    379379
    380     rc = drvAudioStreamCfgToProps(&cfg_c, &props);
     380    rc = DrvAudioStreamCfgToProps(&cfg_c, &props);
    381381    AssertRC(rc);
    382382
     
    462462    };
    463463
    464     int rc = drvAudioStreamCfgToProps(&cfg, &props);
     464    int rc = DrvAudioStreamCfgToProps(&cfg, &props);
    465465    AssertRC(rc);
    466466
Note: See TracChangeset for help on using the changeset viewer.

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