VirtualBox

Changeset 61091 in vbox for trunk


Ignore:
Timestamp:
May 20, 2016 10:52:22 AM (9 years ago)
Author:
vboxsync
Message:

Audio/AudioMixBuffer: Cache pfnConvTo/pfnConvFrom function pointer for default format.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/pdmaudioifs.h

    r61050 r61091  
    340340
    341341/**
     342 * Structure for holding sample conversion parameters for
     343 * the audioMixBufConvFromXXX / audioMixBufConvToXXX macros.
     344 */
     345typedef struct AUDMIXBUF_CONVOPTS
     346{
     347    /** Number of audio samples to convert. */
     348    uint32_t       cSamples;
     349    /** Volume to apply during conversion. Pass 0
     350     *  to convert the original values. May not apply to
     351     *  all conversion functions. */
     352    PDMAUDIOVOLUME Volume;
     353} AUDMIXBUF_CONVOPTS, *PAUDMIXBUF_CONVOPTS;
     354
     355/**
    342356 * Note: All internal handling is done in samples,
    343357 *       not in bytes!
     
    345359typedef uint32_t PDMAUDIOMIXBUFFMT;
    346360typedef PDMAUDIOMIXBUFFMT *PPDMAUDIOMIXBUFFMT;
     361
     362typedef uint32_t (AUDMIXBUF_FN_CONVFROM) (PPDMAUDIOSAMPLE paDst, const void *pvSrc, uint32_t cbSrc, const PAUDMIXBUF_CONVOPTS pOpts);
     363typedef AUDMIXBUF_FN_CONVFROM *PAUDMIXBUF_FN_CONVFROM;
     364
     365typedef void (AUDMIXBUF_FN_CONVTO) (void *pvDst, const PPDMAUDIOSAMPLE paSrc, const PAUDMIXBUF_CONVOPTS pOpts);
     366typedef AUDMIXBUF_FN_CONVTO *PAUDMIXBUF_FN_CONVTO;
    347367
    348368typedef struct PDMAUDIOMIXBUF *PPDMAUDIOMIXBUF;
     
    378398    /** This buffer's audio format. */
    379399    PDMAUDIOMIXBUFFMT      AudioFmt;
     400    /** Standard conversion-to function for set AudioFmt. */
     401    PAUDMIXBUF_FN_CONVTO   pConvTo;
     402    /** Standard conversion-from function for set AudioFmt. */
     403    PAUDMIXBUF_FN_CONVFROM pConvFrom;
    380404    /**
    381405     * Ratio of the associated parent stream's frequency by this stream's
  • trunk/src/VBox/Devices/Audio/AudioMixBuffer.cpp

    r61089 r61091  
    131131AssertCompile(AUDIOMIXBUF_VOL_0DB == 0x40000000);   /* For now -- when only attenuation is used. */
    132132
    133 /**
    134  * Structure for holding sample conversion parameters for
    135  * the audioMixBufConvFromXXX / audioMixBufConvToXXX macros.
    136  */
    137 typedef struct AUDMIXBUF_CONVOPTS
    138 {
    139     /** Number of audio samples to convert. */
    140     uint32_t       cSamples;
    141     /** Volume to apply during conversion. Pass 0
    142      *  to convert the original values. May not apply to
    143      *  all conversion functions. */
    144     PDMAUDIOVOLUME Volume;
    145 } AUDMIXBUF_CONVOPTS, *PAUDMIXBUF_CONVOPTS;
    146 
    147133/*
    148134 * When running the audio testcases we want to verfiy
     
    160146static inline void audioMixBufDbgPrint(PPDMAUDIOMIXBUF pMixBuf);
    161147#endif
    162 
    163 typedef uint32_t (AUDMIXBUF_FN_CONVFROM) (PPDMAUDIOSAMPLE paDst, const void *pvSrc, uint32_t cbSrc, const PAUDMIXBUF_CONVOPTS pOpts);
    164 typedef AUDMIXBUF_FN_CONVFROM *PAUDMIXBUF_FN_CONVFROM;
    165 
    166 typedef void (AUDMIXBUF_FN_CONVTO) (void *pvDst, const PPDMAUDIOSAMPLE paSrc, const PAUDMIXBUF_CONVOPTS pOpts);
    167 typedef AUDMIXBUF_FN_CONVTO *PAUDMIXBUF_FN_CONVTO;
    168148
    169149/* Can return VINF_TRY_AGAIN for getting next pointer at beginning (circular) */
     
    649629 * @return  PAUDMIXBUF_FN_CONVFROM  Function pointer to conversion macro if found, NULL if not supported.
    650630 * @param   enmFmt                  Audio format to lookup conversion macro for.
    651  * @param   fMuted                  Flag determining whether the source is muted.
    652  */
    653 static inline PAUDMIXBUF_FN_CONVFROM audioMixBufConvFromLookup(PDMAUDIOMIXBUFFMT enmFmt, bool fMuted)
    654 {
    655     if (fMuted)
    656         return audioMixBufConvFromSilence;
    657 
     631 */
     632static inline PAUDMIXBUF_FN_CONVFROM audioMixBufConvFromLookup(PDMAUDIOMIXBUFFMT enmFmt)
     633{
    658634    if (AUDMIXBUF_FMT_SIGNED(enmFmt))
    659635    {
     
    807783                                                 pProps->cBits,
    808784                                                 pProps->fSigned);
     785
     786    pMixBuf->pConvFrom = audioMixBufConvFromLookup(pMixBuf->AudioFmt);
     787    pMixBuf->pConvTo   = audioMixBufConvToLookup(pMixBuf->AudioFmt);
     788
    809789    pMixBuf->cShift = pProps->cShift;
    810790    pMixBuf->pszName = RTStrDup(pszName);
     
    13211301    if (cToProcess)
    13221302    {
    1323         PAUDMIXBUF_FN_CONVTO pConv = audioMixBufConvToLookup(enmFmt);
     1303        PAUDMIXBUF_FN_CONVTO pConv;
     1304        if (pMixBuf->AudioFmt != enmFmt)
     1305            pConv = audioMixBufConvToLookup(enmFmt);
     1306        else
     1307            pConv = pMixBuf->pConvTo;
     1308
    13241309        if (pConv)
    13251310        {
    13261311            AUDMIXBUF_CONVOPTS convOpts = { cToProcess, pMixBuf->Volume };
     1312
     1313            AssertPtr(pConv);
    13271314            pConv(pvBuf, pMixBuf->pSamples + offSamples, &convOpts);
    13281315
     1316#ifdef DEBUG
     1317            AudioMixBufDbgPrint(pMixBuf);
     1318#endif
    13291319            rc = VINF_SUCCESS;
    13301320        }
    13311321        else
    1332             rc = VERR_INVALID_PARAMETER;
    1333 
    1334 #ifdef DEBUG
    1335         AudioMixBufDbgPrint(pMixBuf);
    1336 #endif
     1322            rc = VERR_NOT_SUPPORTED;
    13371323    }
    13381324    else
     
    16511637        return VERR_BUFFER_OVERFLOW;
    16521638
    1653     PAUDMIXBUF_FN_CONVFROM pConv = audioMixBufConvFromLookup(enmFmt, pMixBuf->Volume.fMuted);
     1639    PAUDMIXBUF_FN_CONVFROM pConv;
     1640    if (pMixBuf->AudioFmt != enmFmt)
     1641        pConv = audioMixBufConvFromLookup(enmFmt);
     1642    else
     1643    {
     1644        pConv = pMixBuf->Volume.fMuted
     1645              ? &audioMixBufConvFromSilence : pMixBuf->pConvFrom;
     1646    }
     1647
    16541648    if (!pConv)
    16551649        return VERR_NOT_SUPPORTED;
     
    17541748    }
    17551749
    1756     PAUDMIXBUF_FN_CONVFROM pConv = audioMixBufConvFromLookup(enmFmt, pMixBuf->Volume.fMuted);
     1750    PAUDMIXBUF_FN_CONVFROM pConv;
     1751    if (pMixBuf->AudioFmt != enmFmt)
     1752        pConv = audioMixBufConvFromLookup(enmFmt);
     1753    else
     1754    {
     1755        pConv = pMixBuf->Volume.fMuted
     1756              ? &audioMixBufConvFromSilence : pMixBuf->pConvFrom;
     1757    }
     1758
    17571759    if (!pConv)
    17581760        return VERR_NOT_SUPPORTED;
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