VirtualBox

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


Ignore:
Timestamp:
Feb 6, 2017 5:01:11 PM (8 years ago)
Author:
vboxsync
Message:

AudioMixBuffer: Renamed AudioMixBufAcquire() to AudioMixBufPeek() and added parameters for supplying a buffer for returning the audio data.

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

Legend:

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

    r65056 r65630  
    140140
    141141/**
    142  * Acquires (reads) a mutable pointer to the mixing buffer's audio samples without
    143  * any conversion done.
    144  ** @todo Rename to AudioMixBufPeek(Mutable/Raw)?
    145  ** @todo Protect the buffer's data?
     142 * Peeks for audio samples without any conversion done.
     143 * This will get the raw sample data out of a mixing buffer.
    146144 *
    147145 * @return  IPRT status code. VINF_TRY_AGAIN for getting next pointer at beginning (circular).
    148146 * @param   pMixBuf                 Mixing buffer to acquire audio samples from.
    149147 * @param   cSamplesToRead          Number of audio samples to read.
    150  * @param   ppvSamples              Returns a mutable pointer to the buffer's audio sample data.
    151  * @param   pcSamplesRead           Number of audio samples read (acquired).
     148 * @param   paSampleBuf             Buffer where to store the returned audio samples.
     149 * @param   cSampleBuf              Size (in samples) of the buffer to store audio samples into.
     150 * @param   pcSamplesRead           Returns number of read audio samples. Optional.
    152151 *
    153152 * @remark  This function is not thread safe!
    154153 */
    155 int AudioMixBufAcquire(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToRead,
    156                        PPDMAUDIOSAMPLE *ppvSamples, uint32_t *pcSamplesRead)
    157 {
    158     AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER);
    159     AssertPtrReturn(ppvSamples, VERR_INVALID_POINTER);
    160     AssertPtrReturn(pcSamplesRead, VERR_INVALID_POINTER);
     154int AudioMixBufPeek(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToRead,
     155                    PPDMAUDIOSAMPLE paSampleBuf, uint32_t cSampleBuf, uint32_t *pcSamplesRead)
     156{
     157    AssertPtrReturn(pMixBuf,     VERR_INVALID_POINTER);
     158    AssertPtrReturn(paSampleBuf, VERR_INVALID_POINTER);
     159    AssertReturn(cSampleBuf,     VERR_INVALID_PARAMETER);
     160    /* pcRead is optional. */
    161161
    162162    int rc;
     
    164164    if (!cSamplesToRead)
    165165    {
    166         *pcSamplesRead = 0;
     166        if (pcSamplesRead)
     167            *pcSamplesRead = 0;
    167168        return VINF_SUCCESS;
    168169    }
    169170
    170     uint32_t cSamplesRead;
     171    uint32_t csRead;
    171172    if (pMixBuf->offRead + cSamplesToRead > pMixBuf->cSamples)
    172173    {
    173         cSamplesRead = pMixBuf->cSamples - pMixBuf->offRead;
     174        csRead = pMixBuf->cSamples - pMixBuf->offRead;
    174175        rc = VINF_TRY_AGAIN;
    175176    }
    176177    else
    177178    {
    178         cSamplesRead = cSamplesToRead;
     179        csRead = cSamplesToRead;
    179180        rc = VINF_SUCCESS;
    180181    }
    181182
    182     *ppvSamples = &pMixBuf->pSamples[pMixBuf->offRead];
    183     AssertPtr(ppvSamples);
    184 
    185     pMixBuf->offRead = (pMixBuf->offRead + cSamplesRead) % pMixBuf->cSamples;
     183    memcpy(paSampleBuf, &pMixBuf->pSamples[pMixBuf->offRead], sizeof(PDMAUDIOSAMPLE) * csRead);
     184
     185    pMixBuf->offRead = (pMixBuf->offRead + csRead) % pMixBuf->cSamples;
    186186    Assert(pMixBuf->offRead <= pMixBuf->cSamples);
    187     pMixBuf->cUsed -= RT_MIN(cSamplesRead, pMixBuf->cUsed);
    188 
    189     *pcSamplesRead = cSamplesRead;
     187    pMixBuf->cUsed -= RT_MIN(csRead, pMixBuf->cUsed);
     188
     189    if (pcSamplesRead)
     190        *pcSamplesRead = csRead;
    190191
    191192    return rc;
  • trunk/src/VBox/Devices/Audio/AudioMixBuffer.h

    r63362 r65630  
    4949
    5050
    51 int AudioMixBufAcquire(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToRead, PPDMAUDIOSAMPLE *ppvSamples, uint32_t *pcSamplesRead);
    5251inline uint32_t AudioMixBufBytesToSamples(PPDMAUDIOMIXBUF pMixBuf);
    5352void AudioMixBufClear(PPDMAUDIOMIXBUF pMixBuf);
     
    6160uint32_t AudioMixBufLive(PPDMAUDIOMIXBUF pMixBuf);
    6261int AudioMixBufMixToParent(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamples, uint32_t *pcProcessed);
     62int AudioMixBufPeek(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToRead, PPDMAUDIOSAMPLE paSampleBuf, uint32_t cSampleBuf, uint32_t *pcSamplesRead);
    6363uint32_t AudioMixBufUsed(PPDMAUDIOMIXBUF pMixBuf);
    6464int AudioMixBufReadAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offSamples, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead);
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