VirtualBox

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


Ignore:
Timestamp:
Feb 9, 2018 1:39:05 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
120766
Message:

Audio/DevHDA.cpp: Save a few CPU cycles in hdaStreamTransfer() if the stream's audio frame size matches the device's default audio frame size. See the comments for more details.

File:
1 edited

Legend:

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

    r70832 r70933  
    961961            if (RT_SUCCESS(rc))
    962962            {
    963                 uint32_t cbDMARead = pStream->State.cbDMALeft ? pStream->State.cbFrameSize - pStream->State.cbDMALeft : 0;
    964                 uint32_t cbDMALeft = RT_MIN(cbDMA, (uint32_t)RTCircBufFree(pCircBuf));
    965 
    966963#ifndef VBOX_WITH_HDA_AUDIO_INTERLEAVING_STREAMS_SUPPORT
    967                 /**
    968                  * The following code extracts the required audio stream (channel) data
    969                  * of non-interleaved *and* interleaved audio streams.
     964                /*
     965                 * Most guests don't use different stream frame sizes than
     966                 * the default one, so save a bit of CPU time and don't go into
     967                 * the frame extraction code below.
    970968                 *
    971                  * We by default only support 2 channels with 16-bit samples (HDA_FRAME_SIZE),
    972                  * but an HDA audio stream can have interleaved audio data of multiple audio
    973                  * channels in such a single stream ("AA,AA,AA vs. AA,BB,AA,BB").
    974                  *
    975                  * So take this into account by just handling the first channel in such a stream ("A")
    976                  * and just discard the other channel's data.
    977                  *
    978                  * @todo Optimize this stuff -- copying only one frame a time is expensive.
     969                 * Only macOS guests need the frame extraction branch below at the moment AFAIK.
    979970                 */
    980                 while (cbDMALeft >= pStream->State.cbFrameSize)
     971                if (pStream->State.cbFrameSize == HDA_FRAME_SIZE)
    981972                {
    982                     void *pvBuf; size_t cbBuf;
    983                     RTCircBufAcquireWriteBlock(pCircBuf, HDA_FRAME_SIZE, &pvBuf, &cbBuf);
    984 
    985                     AssertBreak(cbDMARead <= sizeof(abChunk));
    986 
    987                     if (cbBuf)
    988                         memcpy(pvBuf, abChunk + cbDMARead, cbBuf);
    989 
    990                     RTCircBufReleaseWriteBlock(pCircBuf, cbBuf);
    991 
    992                     Assert(cbDMALeft >= pStream->State.cbFrameSize);
    993                     cbDMALeft -= pStream->State.cbFrameSize;
    994                     cbDMARead += pStream->State.cbFrameSize;
     973                    uint32_t cbDMARead = 0;
     974                    uint32_t cbDMALeft = RT_MIN(cbDMA, (uint32_t)RTCircBufFree(pCircBuf));
     975
     976                    while (cbDMALeft)
     977                    {
     978                        void *pvBuf; size_t cbBuf;
     979                        RTCircBufAcquireWriteBlock(pCircBuf, cbDMALeft, &pvBuf, &cbBuf);
     980
     981                        if (cbBuf)
     982                        {
     983                            memcpy(pvBuf, abChunk + cbDMARead, cbBuf);
     984                            cbDMARead += (uint32_t)cbBuf;
     985                            cbDMALeft -= (uint32_t)cbBuf;
     986                        }
     987
     988                        RTCircBufReleaseWriteBlock(pCircBuf, cbBuf);
     989                    }
    995990                }
    996 
    997                 pStream->State.cbDMALeft = cbDMALeft;
    998                 Assert(pStream->State.cbDMALeft < pStream->State.cbFrameSize);
     991                else
     992                {
     993                    /**
     994                     * The following code extracts the required audio stream (channel) data
     995                     * of non-interleaved *and* interleaved audio streams.
     996                     *
     997                     * We by default only support 2 channels with 16-bit samples (HDA_FRAME_SIZE),
     998                     * but an HDA audio stream can have interleaved audio data of multiple audio
     999                     * channels in such a single stream ("AA,AA,AA vs. AA,BB,AA,BB").
     1000                     *
     1001                     * So take this into account by just handling the first channel in such a stream ("A")
     1002                     * and just discard the other channel's data.
     1003                     *
     1004                     * @todo Optimize this stuff -- copying only one frame a time is expensive.
     1005                     */
     1006                    uint32_t cbDMARead = pStream->State.cbDMALeft ? pStream->State.cbFrameSize - pStream->State.cbDMALeft : 0;
     1007                    uint32_t cbDMALeft = RT_MIN(cbDMA, (uint32_t)RTCircBufFree(pCircBuf));
     1008
     1009                    while (cbDMALeft >= pStream->State.cbFrameSize)
     1010                    {
     1011                        void *pvBuf; size_t cbBuf;
     1012                        RTCircBufAcquireWriteBlock(pCircBuf, HDA_FRAME_SIZE, &pvBuf, &cbBuf);
     1013
     1014                        AssertBreak(cbDMARead <= sizeof(abChunk));
     1015
     1016                        if (cbBuf)
     1017                            memcpy(pvBuf, abChunk + cbDMARead, cbBuf);
     1018
     1019                        RTCircBufReleaseWriteBlock(pCircBuf, cbBuf);
     1020
     1021                        Assert(cbDMALeft >= pStream->State.cbFrameSize);
     1022                        cbDMALeft -= pStream->State.cbFrameSize;
     1023                        cbDMARead += pStream->State.cbFrameSize;
     1024                    }
     1025
     1026                    pStream->State.cbDMALeft = cbDMALeft;
     1027                    Assert(pStream->State.cbDMALeft < pStream->State.cbFrameSize);
     1028                }
    9991029
    10001030                const size_t cbFree = RTCircBufFree(pCircBuf);
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