VirtualBox

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


Ignore:
Timestamp:
May 28, 2021 12:18:56 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
144701
Message:

AudioMixBuffer: More cleanups. bugref:9890

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

Legend:

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

    r89351 r89352  
    154154
    155155
    156 /*********************************************************************************************************************************
    157 *   Internal Functions                                                                                                           *
    158 *********************************************************************************************************************************/
    159 #ifdef DEBUG
    160 static void audioMixBufDbgPrintInternal(PAUDIOMIXBUF pMixBuf, const char *pszFunc);
     156
     157#ifdef VBOX_STRICT
    161158# ifdef UNUSED
    162 static bool audioMixBufDbgValidate(PAUDIOMIXBUF pMixBuf);
    163 # endif
    164 #endif
    165 
     159
     160/**
     161 * Prints a single mixing buffer.
     162 * Internal helper function for debugging. Do not use directly.
     163 *
     164 * @returns VBox status code.
     165 * @param   pMixBuf                 Mixing buffer to print.
     166 * @param   pszFunc                 Function name to log this for.
     167 * @param   uIdtLvl                 Indention level to use.
     168 */
     169static void audioMixBufDbgPrintSingle(PAUDIOMIXBUF pMixBuf, const char *pszFunc, uint16_t uIdtLvl)
     170{
     171    Log(("%s: %*s %s: offRead=%RU32, offWrite=%RU32, cMixed=%RU32 -> %RU32/%RU32\n",
     172         pszFunc, uIdtLvl * 4, "",
     173         pMixBuf->pszName, pMixBuf->offRead, pMixBuf->offWrite, pMixBuf->cMixed, pMixBuf->cUsed, pMixBuf->cFrames));
     174}
     175
     176static void audioMixBufDbgPrintInternal(PAUDIOMIXBUF pMixBuf, const char *pszFunc)
     177{
     178    audioMixBufDbgPrintSingle(pMixBuf, pszFunc, 0 /* iIdtLevel */);
     179}
     180
     181/**
     182 * Validates a single mixing buffer.
     183 *
     184 * @return  @true if the buffer state is valid or @false if not.
     185 * @param   pMixBuf                 Mixing buffer to validate.
     186 */
     187static bool audioMixBufDbgValidate(PAUDIOMIXBUF pMixBuf)
     188{
     189    //const uint32_t offReadEnd  = (pMixBuf->offRead + pMixBuf->cUsed) % pMixBuf->cFrames;
     190    //const uint32_t offWriteEnd = (pMixBuf->offWrite + (pMixBuf->cFrames - pMixBuf->cUsed)) % pMixBuf->cFrames;
     191
     192    bool fValid = true;
     193
     194    AssertStmt(pMixBuf->offRead  <= pMixBuf->cFrames, fValid = false);
     195    AssertStmt(pMixBuf->offWrite <= pMixBuf->cFrames, fValid = false);
     196    AssertStmt(pMixBuf->cUsed    <= pMixBuf->cFrames, fValid = false);
     197
     198    if (pMixBuf->offWrite > pMixBuf->offRead)
     199    {
     200        if (pMixBuf->offWrite - pMixBuf->offRead != pMixBuf->cUsed)
     201            fValid = false;
     202    }
     203    else if (pMixBuf->offWrite < pMixBuf->offRead)
     204    {
     205        if (pMixBuf->offWrite + pMixBuf->cFrames - pMixBuf->offRead != pMixBuf->cUsed)
     206            fValid = false;
     207    }
     208
     209    if (!fValid)
     210    {
     211        audioMixBufDbgPrintInternal(pMixBuf, __FUNCTION__);
     212        AssertFailed();
     213    }
     214
     215    return fValid;
     216}
     217
     218# endif /* UNUSED */
     219#endif /* VBOX_STRICT */
    166220
    167221
     
    658712#undef AUDMIXBUF_MACRO_LOG
    659713
    660 /**
    661  * Initializes a mixing buffer.
    662  *
    663  * @returns VBox status code.
    664  * @param   pMixBuf                 Mixing buffer to initialize.
    665  * @param   pszName                 Name of mixing buffer for easier identification. Optional.
    666  * @param   pProps                  PCM audio properties to use for the mixing buffer.
    667  * @param   cFrames                 Maximum number of audio frames the mixing buffer can hold.
    668  */
    669 int AudioMixBufInit(PAUDIOMIXBUF pMixBuf, const char *pszName, PCPDMAUDIOPCMPROPS pProps, uint32_t cFrames)
    670 {
    671     AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER);
    672     AssertPtrReturn(pszName, VERR_INVALID_POINTER);
    673     AssertPtrReturn(pProps,  VERR_INVALID_POINTER);
    674     Assert(PDMAudioPropsAreValid(pProps));
    675 
    676     pMixBuf->uMagic  = AUDIOMIXBUF_MAGIC;
    677 
    678     pMixBuf->pFrames = NULL;
    679     pMixBuf->cFrames = 0;
    680 
    681     pMixBuf->offRead  = 0;
    682     pMixBuf->offWrite = 0;
    683     pMixBuf->cMixed   = 0;
    684     pMixBuf->cUsed    = 0;
    685 
    686     /* Set initial volume to max. */
    687     pMixBuf->Volume.fMuted = false;
    688     pMixBuf->Volume.uLeft  = AUDIOMIXBUF_VOL_0DB;
    689     pMixBuf->Volume.uRight = AUDIOMIXBUF_VOL_0DB;
    690 
    691     pMixBuf->Props       = *pProps;
    692 
    693     pMixBuf->pszName = RTStrDup(pszName);
    694     if (pMixBuf->pszName)
    695     {
    696         pMixBuf->pFrames = (PPDMAUDIOFRAME)RTMemAllocZ(cFrames * sizeof(PDMAUDIOFRAME));
    697         if (pMixBuf->pFrames)
    698         {
    699             pMixBuf->cFrames = cFrames;
    700 #ifdef AUDMIXBUF_LOG_ENABLED
    701             char szTmp[PDMAUDIOPROPSTOSTRING_MAX];
    702             AUDMIXBUF_LOG(("%s: %s - cFrames=%#x (%d)\n",
    703                            pMixBuf->pszName, PDMAudioPropsToString(pProps, szTmp, sizeof(szTmp)), cFrames, cFrames));
    704 #endif
    705             return VINF_SUCCESS;
    706         }
    707         RTStrFree(pMixBuf->pszName);
    708         pMixBuf->pszName = NULL;
    709     }
    710     pMixBuf->uMagic = AUDIOMIXBUF_MAGIC_DEAD;
    711     return VERR_NO_MEMORY;
    712 }
    713 
    714 /**
    715  * Destroys (uninitializes) a mixing buffer.
    716  *
    717  * @param   pMixBuf                 Mixing buffer to destroy.
    718  */
    719 void AudioMixBufDestroy(PAUDIOMIXBUF pMixBuf)
    720 {
    721     if (!pMixBuf)
    722         return;
    723 
    724     /* Ignore calls for an uninitialized (zeroed) or already destroyed instance.  Happens a lot. */
    725     if (   pMixBuf->uMagic == 0
    726         || pMixBuf->uMagic == ~AUDIOMIXBUF_MAGIC)
    727     {
    728         Assert(!pMixBuf->pszName);
    729         Assert(!pMixBuf->pFrames);
    730         Assert(!pMixBuf->cFrames);
    731         return;
    732     }
    733 
    734     Assert(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC);
    735     pMixBuf->uMagic = ~AUDIOMIXBUF_MAGIC;
    736 
    737     if (pMixBuf->pszName)
    738     {
    739         AUDMIXBUF_LOG(("%s\n", pMixBuf->pszName));
    740 
    741         RTStrFree(pMixBuf->pszName);
    742         pMixBuf->pszName = NULL;
    743     }
    744 
    745     if (pMixBuf->pFrames)
    746     {
    747         Assert(pMixBuf->cFrames);
    748 
    749         RTMemFree(pMixBuf->pFrames);
    750         pMixBuf->pFrames = NULL;
    751     }
    752 
    753     pMixBuf->cFrames = 0;
    754 }
    755 
    756 
    757 /**
    758  * Drops all the frames in the given mixing buffer
    759  *
    760  * This will reset the read and write offsets to zero.
    761  *
    762  * @param   pMixBuf             The mixing buffer.
    763  */
    764 void AudioMixBufDrop(PAUDIOMIXBUF pMixBuf)
    765 {
    766     AssertPtrReturnVoid(pMixBuf);
    767     AssertReturnVoid(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC);
    768 
    769     AUDMIXBUF_LOG(("%s\n", pMixBuf->pszName));
    770 
    771     pMixBuf->offRead  = 0;
    772     pMixBuf->offWrite = 0;
    773     pMixBuf->cMixed   = 0;
    774     pMixBuf->cUsed    = 0;
    775 }
    776 
    777 
    778 /**
    779  * Gets the maximum number of audio frames this buffer can hold.
    780  *
    781  * @returns Number of frames.
    782  * @param   pMixBuf     The mixing buffer.
    783  */
    784 uint32_t AudioMixBufSize(PCAUDIOMIXBUF pMixBuf)
    785 {
    786     AssertPtrReturn(pMixBuf, 0);
    787     Assert(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC);
    788     return pMixBuf->cFrames;
    789 }
    790 
    791 
    792 /**
    793  * Gets the maximum number of bytes this buffer can hold.
    794  *
    795  * @returns Number of bytes.
    796  * @param   pMixBuf     The mixing buffer.
    797  */
    798 uint32_t AudioMixBufSizeBytes(PCAUDIOMIXBUF pMixBuf)
    799 {
    800     AssertPtrReturn(pMixBuf, 0);
    801     AssertReturn(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC, 0);
    802     return AUDIOMIXBUF_F2B(pMixBuf, pMixBuf->cFrames);
    803 }
    804 
    805 
    806 /**
    807  * Worker for AudioMixBufUsed and AudioMixBufUsedBytes.
    808  */
    809 DECLINLINE(uint32_t) audioMixBufUsedInternal(PCAUDIOMIXBUF pMixBuf)
    810 {
    811     uint32_t const cFrames = pMixBuf->cFrames;
    812     uint32_t       cUsed   = pMixBuf->cUsed;
    813     AssertStmt(cUsed <= cFrames, cUsed = cFrames);
    814     return cUsed;
    815 }
    816 
    817 
    818 /**
    819  * Get the number of used (readable) frames in the buffer.
    820  *
    821  * @returns Number of frames.
    822  * @param   pMixBuf     The mixing buffer.
    823  */
    824 uint32_t AudioMixBufUsed(PCAUDIOMIXBUF pMixBuf)
    825 {
    826     AssertPtrReturn(pMixBuf, 0);
    827     Assert(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC);
    828     return audioMixBufUsedInternal(pMixBuf);
    829 }
    830 
    831 
    832 /**
    833  * Get the number of (readable) bytes in the buffer.
    834  *
    835  * @returns Number of bytes.
    836  * @param   pMixBuf     The mixing buffer.
    837  */
    838 uint32_t AudioMixBufUsedBytes(PCAUDIOMIXBUF pMixBuf)
    839 {
    840     AssertPtrReturn(pMixBuf, 0);
    841     Assert(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC);
    842     return AUDIOMIXBUF_F2B(pMixBuf, audioMixBufUsedInternal(pMixBuf));
    843 }
    844 
    845 
    846 /**
    847  * Worker for AudioMixBufFree and AudioMixBufFreeBytes.
    848  */
    849 DECLINLINE(uint32_t) audioMixBufFreeInternal(PCAUDIOMIXBUF pMixBuf)
    850 {
    851     uint32_t const cFrames = pMixBuf->cFrames;
    852     uint32_t       cUsed   = pMixBuf->cUsed;
    853     AssertStmt(cUsed <= cFrames, cUsed = cFrames);
    854     uint32_t const cFramesFree = cFrames - cUsed;
    855 
    856     AUDMIXBUF_LOG(("%s: %RU32 of %RU32\n", pMixBuf->pszName, cFramesFree, cFrames));
    857     return cFramesFree;
    858 }
    859 
    860 /**
    861  * Gets the free buffer space in frames.
    862  *
    863  * @return  Number of frames.
    864  * @param   pMixBuf     The mixing buffer.
    865  */
    866 uint32_t AudioMixBufFree(PCAUDIOMIXBUF pMixBuf)
    867 {
    868     AssertPtrReturn(pMixBuf, 0);
    869     Assert(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC);
    870     return audioMixBufFreeInternal(pMixBuf);
    871 }
    872 
    873 /**
    874  * Gets the free buffer space in bytes.
    875  *
    876  * @return  Number of bytes.
    877  * @param   pMixBuf     The mixing buffer.
    878  */
    879 uint32_t AudioMixBufFreeBytes(PCAUDIOMIXBUF pMixBuf)
    880 {
    881     AssertPtrReturn(pMixBuf, 0);
    882     Assert(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC);
    883     return AUDIOMIXBUF_F2B(pMixBuf, audioMixBufFreeInternal(pMixBuf));
    884 }
    885 
    886 
    887 /**
    888  * Checks if the buffer is empty.
    889  *
    890  * @retval  true if empty buffer.
    891  * @retval  false if not empty and there are frames to be processed.
    892  * @param   pMixBuf     The mixing buffer.
    893  */
    894 bool AudioMixBufIsEmpty(PCAUDIOMIXBUF pMixBuf)
    895 {
    896     AssertPtrReturn(pMixBuf, true);
    897     Assert(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC);
    898     return pMixBuf->cUsed == 0;
    899 }
    900 
    901 
    902 /**
    903  * Get the current read position.
    904  *
    905  * This is for the testcase.
    906  *
    907  * @returns Frame number.
    908  * @param   pMixBuf     The mixing buffer.
    909  */
    910 uint32_t AudioMixBufReadPos(PCAUDIOMIXBUF pMixBuf)
    911 {
    912     AssertPtrReturn(pMixBuf, 0);
    913     Assert(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC);
    914     return pMixBuf->offRead;
    915 }
    916 
    917 
    918 /**
    919  * Gets the current write position.
    920  *
    921  * This is for the testcase.
    922  *
    923  * @returns Frame number.
    924  * @param   pMixBuf     The mixing buffer.
    925  */
    926 uint32_t AudioMixBufWritePos(PCAUDIOMIXBUF pMixBuf)
    927 {
    928     AssertPtrReturn(pMixBuf, 0);
    929     Assert(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC);
    930     return pMixBuf->offWrite;
    931 }
    932 
    933 #ifdef DEBUG
    934 
    935 /**
    936  * Prints a single mixing buffer.
    937  * Internal helper function for debugging. Do not use directly.
    938  *
    939  * @returns VBox status code.
    940  * @param   pMixBuf                 Mixing buffer to print.
    941  * @param   pszFunc                 Function name to log this for.
    942  * @param   uIdtLvl                 Indention level to use.
    943  */
    944 static void audioMixBufDbgPrintSingle(PAUDIOMIXBUF pMixBuf, const char *pszFunc, uint16_t uIdtLvl)
    945 {
    946     Log(("%s: %*s %s: offRead=%RU32, offWrite=%RU32, cMixed=%RU32 -> %RU32/%RU32\n",
    947          pszFunc, uIdtLvl * 4, "",
    948          pMixBuf->pszName, pMixBuf->offRead, pMixBuf->offWrite, pMixBuf->cMixed, pMixBuf->cUsed, pMixBuf->cFrames));
    949 }
    950 
    951 # ifdef UNUSED
    952 /**
    953  * Validates a single mixing buffer.
    954  *
    955  * @return  @true if the buffer state is valid or @false if not.
    956  * @param   pMixBuf                 Mixing buffer to validate.
    957  */
    958 static bool audioMixBufDbgValidate(PAUDIOMIXBUF pMixBuf)
    959 {
    960     //const uint32_t offReadEnd  = (pMixBuf->offRead + pMixBuf->cUsed) % pMixBuf->cFrames;
    961     //const uint32_t offWriteEnd = (pMixBuf->offWrite + (pMixBuf->cFrames - pMixBuf->cUsed)) % pMixBuf->cFrames;
    962 
    963     bool fValid = true;
    964 
    965     AssertStmt(pMixBuf->offRead  <= pMixBuf->cFrames, fValid = false);
    966     AssertStmt(pMixBuf->offWrite <= pMixBuf->cFrames, fValid = false);
    967     AssertStmt(pMixBuf->cUsed    <= pMixBuf->cFrames, fValid = false);
    968 
    969     if (pMixBuf->offWrite > pMixBuf->offRead)
    970     {
    971         if (pMixBuf->offWrite - pMixBuf->offRead != pMixBuf->cUsed)
    972             fValid = false;
    973     }
    974     else if (pMixBuf->offWrite < pMixBuf->offRead)
    975     {
    976         if (pMixBuf->offWrite + pMixBuf->cFrames - pMixBuf->offRead != pMixBuf->cUsed)
    977             fValid = false;
    978     }
    979 
    980     if (!fValid)
    981     {
    982         audioMixBufDbgPrintInternal(pMixBuf, __FUNCTION__);
    983         AssertFailed();
    984     }
    985 
    986     return fValid;
    987 }
    988 # endif
    989 
    990 /**
    991  * Prints statistics and status of the full chain of a mixing buffer to the logger,
    992  * starting from the top root mixing buffer.
    993  * For debug versions only.
    994  *
    995  * @returns VBox status code.
    996  * @param   pMixBuf                 Mixing buffer to print.
    997  */
    998 void AudioMixBufDbgPrintChain(PAUDIOMIXBUF pMixBuf)
    999 {
    1000     audioMixBufDbgPrintSingle(pMixBuf, __FUNCTION__, 0 /* uIdtLvl */);
    1001 }
    1002 
    1003 DECL_FORCE_INLINE(void) audioMixBufDbgPrintInternal(PAUDIOMIXBUF pMixBuf, const char *pszFunc)
    1004 {
    1005     audioMixBufDbgPrintSingle(pMixBuf, pszFunc, 0 /* iIdtLevel */);
    1006 }
    1007 
    1008 /**
    1009  * Prints statistics and status of a mixing buffer to the logger.
    1010  * For debug versions only.
    1011  *
    1012  * @returns VBox status code.
    1013  * @param   pMixBuf                 Mixing buffer to print.
    1014  */
    1015 void AudioMixBufDbgPrint(PAUDIOMIXBUF pMixBuf)
    1016 {
    1017     audioMixBufDbgPrintInternal(pMixBuf, __FUNCTION__);
    1018 }
    1019 
    1020 #endif /* DEBUG */
    1021 
    1022 
    1023714/*
    1024715 * Resampling core.
     
    1176867
    1177868
     869/**
     870 * Initializes a mixing buffer.
     871 *
     872 * @returns VBox status code.
     873 * @param   pMixBuf                 Mixing buffer to initialize.
     874 * @param   pszName                 Name of mixing buffer for easier identification. Optional.
     875 * @param   pProps                  PCM audio properties to use for the mixing buffer.
     876 * @param   cFrames                 Maximum number of audio frames the mixing buffer can hold.
     877 */
     878int AudioMixBufInit(PAUDIOMIXBUF pMixBuf, const char *pszName, PCPDMAUDIOPCMPROPS pProps, uint32_t cFrames)
     879{
     880    AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER);
     881    AssertPtrReturn(pszName, VERR_INVALID_POINTER);
     882    AssertPtrReturn(pProps,  VERR_INVALID_POINTER);
     883    Assert(PDMAudioPropsAreValid(pProps));
     884
     885    pMixBuf->uMagic  = AUDIOMIXBUF_MAGIC;
     886
     887    pMixBuf->pFrames = NULL;
     888    pMixBuf->cFrames = 0;
     889
     890    pMixBuf->offRead  = 0;
     891    pMixBuf->offWrite = 0;
     892    pMixBuf->cMixed   = 0;
     893    pMixBuf->cUsed    = 0;
     894
     895    /* Set initial volume to max. */
     896    pMixBuf->Volume.fMuted = false;
     897    pMixBuf->Volume.uLeft  = AUDIOMIXBUF_VOL_0DB;
     898    pMixBuf->Volume.uRight = AUDIOMIXBUF_VOL_0DB;
     899
     900    pMixBuf->Props       = *pProps;
     901
     902    pMixBuf->pszName = RTStrDup(pszName);
     903    if (pMixBuf->pszName)
     904    {
     905        pMixBuf->pFrames = (PPDMAUDIOFRAME)RTMemAllocZ(cFrames * sizeof(PDMAUDIOFRAME));
     906        if (pMixBuf->pFrames)
     907        {
     908            pMixBuf->cFrames = cFrames;
     909#ifdef AUDMIXBUF_LOG_ENABLED
     910            char szTmp[PDMAUDIOPROPSTOSTRING_MAX];
     911            AUDMIXBUF_LOG(("%s: %s - cFrames=%#x (%d)\n",
     912                           pMixBuf->pszName, PDMAudioPropsToString(pProps, szTmp, sizeof(szTmp)), cFrames, cFrames));
     913#endif
     914            return VINF_SUCCESS;
     915        }
     916        RTStrFree(pMixBuf->pszName);
     917        pMixBuf->pszName = NULL;
     918    }
     919    pMixBuf->uMagic = AUDIOMIXBUF_MAGIC_DEAD;
     920    return VERR_NO_MEMORY;
     921}
     922
     923/**
     924 * Destroys (uninitializes) a mixing buffer.
     925 *
     926 * @param   pMixBuf                 Mixing buffer to destroy.
     927 */
     928void AudioMixBufDestroy(PAUDIOMIXBUF pMixBuf)
     929{
     930    if (!pMixBuf)
     931        return;
     932
     933    /* Ignore calls for an uninitialized (zeroed) or already destroyed instance.  Happens a lot. */
     934    if (   pMixBuf->uMagic == 0
     935        || pMixBuf->uMagic == ~AUDIOMIXBUF_MAGIC)
     936    {
     937        Assert(!pMixBuf->pszName);
     938        Assert(!pMixBuf->pFrames);
     939        Assert(!pMixBuf->cFrames);
     940        return;
     941    }
     942
     943    Assert(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC);
     944    pMixBuf->uMagic = ~AUDIOMIXBUF_MAGIC;
     945
     946    if (pMixBuf->pszName)
     947    {
     948        AUDMIXBUF_LOG(("%s\n", pMixBuf->pszName));
     949
     950        RTStrFree(pMixBuf->pszName);
     951        pMixBuf->pszName = NULL;
     952    }
     953
     954    if (pMixBuf->pFrames)
     955    {
     956        Assert(pMixBuf->cFrames);
     957
     958        RTMemFree(pMixBuf->pFrames);
     959        pMixBuf->pFrames = NULL;
     960    }
     961
     962    pMixBuf->cFrames = 0;
     963}
     964
     965
     966/**
     967 * Drops all the frames in the given mixing buffer
     968 *
     969 * This will reset the read and write offsets to zero.
     970 *
     971 * @param   pMixBuf             The mixing buffer.
     972 */
     973void AudioMixBufDrop(PAUDIOMIXBUF pMixBuf)
     974{
     975    AssertPtrReturnVoid(pMixBuf);
     976    AssertReturnVoid(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC);
     977
     978    AUDMIXBUF_LOG(("%s\n", pMixBuf->pszName));
     979
     980    pMixBuf->offRead  = 0;
     981    pMixBuf->offWrite = 0;
     982    pMixBuf->cMixed   = 0;
     983    pMixBuf->cUsed    = 0;
     984}
     985
     986
     987/**
     988 * Gets the maximum number of audio frames this buffer can hold.
     989 *
     990 * @returns Number of frames.
     991 * @param   pMixBuf     The mixing buffer.
     992 */
     993uint32_t AudioMixBufSize(PCAUDIOMIXBUF pMixBuf)
     994{
     995    AssertPtrReturn(pMixBuf, 0);
     996    Assert(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC);
     997    return pMixBuf->cFrames;
     998}
     999
     1000
     1001/**
     1002 * Gets the maximum number of bytes this buffer can hold.
     1003 *
     1004 * @returns Number of bytes.
     1005 * @param   pMixBuf     The mixing buffer.
     1006 */
     1007uint32_t AudioMixBufSizeBytes(PCAUDIOMIXBUF pMixBuf)
     1008{
     1009    AssertPtrReturn(pMixBuf, 0);
     1010    AssertReturn(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC, 0);
     1011    return AUDIOMIXBUF_F2B(pMixBuf, pMixBuf->cFrames);
     1012}
     1013
     1014
     1015/**
     1016 * Worker for AudioMixBufUsed and AudioMixBufUsedBytes.
     1017 */
     1018DECLINLINE(uint32_t) audioMixBufUsedInternal(PCAUDIOMIXBUF pMixBuf)
     1019{
     1020    uint32_t const cFrames = pMixBuf->cFrames;
     1021    uint32_t       cUsed   = pMixBuf->cUsed;
     1022    AssertStmt(cUsed <= cFrames, cUsed = cFrames);
     1023    return cUsed;
     1024}
     1025
     1026
     1027/**
     1028 * Get the number of used (readable) frames in the buffer.
     1029 *
     1030 * @returns Number of frames.
     1031 * @param   pMixBuf     The mixing buffer.
     1032 */
     1033uint32_t AudioMixBufUsed(PCAUDIOMIXBUF pMixBuf)
     1034{
     1035    AssertPtrReturn(pMixBuf, 0);
     1036    Assert(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC);
     1037    return audioMixBufUsedInternal(pMixBuf);
     1038}
     1039
     1040
     1041/**
     1042 * Get the number of (readable) bytes in the buffer.
     1043 *
     1044 * @returns Number of bytes.
     1045 * @param   pMixBuf     The mixing buffer.
     1046 */
     1047uint32_t AudioMixBufUsedBytes(PCAUDIOMIXBUF pMixBuf)
     1048{
     1049    AssertPtrReturn(pMixBuf, 0);
     1050    Assert(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC);
     1051    return AUDIOMIXBUF_F2B(pMixBuf, audioMixBufUsedInternal(pMixBuf));
     1052}
     1053
     1054
     1055/**
     1056 * Worker for AudioMixBufFree and AudioMixBufFreeBytes.
     1057 */
     1058DECLINLINE(uint32_t) audioMixBufFreeInternal(PCAUDIOMIXBUF pMixBuf)
     1059{
     1060    uint32_t const cFrames = pMixBuf->cFrames;
     1061    uint32_t       cUsed   = pMixBuf->cUsed;
     1062    AssertStmt(cUsed <= cFrames, cUsed = cFrames);
     1063    uint32_t const cFramesFree = cFrames - cUsed;
     1064
     1065    AUDMIXBUF_LOG(("%s: %RU32 of %RU32\n", pMixBuf->pszName, cFramesFree, cFrames));
     1066    return cFramesFree;
     1067}
     1068
     1069
     1070/**
     1071 * Gets the free buffer space in frames.
     1072 *
     1073 * @return  Number of frames.
     1074 * @param   pMixBuf     The mixing buffer.
     1075 */
     1076uint32_t AudioMixBufFree(PCAUDIOMIXBUF pMixBuf)
     1077{
     1078    AssertPtrReturn(pMixBuf, 0);
     1079    Assert(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC);
     1080    return audioMixBufFreeInternal(pMixBuf);
     1081}
     1082
     1083
     1084/**
     1085 * Gets the free buffer space in bytes.
     1086 *
     1087 * @return  Number of bytes.
     1088 * @param   pMixBuf     The mixing buffer.
     1089 */
     1090uint32_t AudioMixBufFreeBytes(PCAUDIOMIXBUF pMixBuf)
     1091{
     1092    AssertPtrReturn(pMixBuf, 0);
     1093    Assert(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC);
     1094    return AUDIOMIXBUF_F2B(pMixBuf, audioMixBufFreeInternal(pMixBuf));
     1095}
     1096
     1097
     1098/**
     1099 * Checks if the buffer is empty.
     1100 *
     1101 * @retval  true if empty buffer.
     1102 * @retval  false if not empty and there are frames to be processed.
     1103 * @param   pMixBuf     The mixing buffer.
     1104 */
     1105bool AudioMixBufIsEmpty(PCAUDIOMIXBUF pMixBuf)
     1106{
     1107    AssertPtrReturn(pMixBuf, true);
     1108    Assert(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC);
     1109    return pMixBuf->cUsed == 0;
     1110}
     1111
     1112
     1113/**
     1114 * Get the current read position.
     1115 *
     1116 * This is for the testcase.
     1117 *
     1118 * @returns Frame number.
     1119 * @param   pMixBuf     The mixing buffer.
     1120 */
     1121uint32_t AudioMixBufReadPos(PCAUDIOMIXBUF pMixBuf)
     1122{
     1123    AssertPtrReturn(pMixBuf, 0);
     1124    Assert(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC);
     1125    return pMixBuf->offRead;
     1126}
     1127
     1128
     1129/**
     1130 * Gets the current write position.
     1131 *
     1132 * This is for the testcase.
     1133 *
     1134 * @returns Frame number.
     1135 * @param   pMixBuf     The mixing buffer.
     1136 */
     1137uint32_t AudioMixBufWritePos(PCAUDIOMIXBUF pMixBuf)
     1138{
     1139    AssertPtrReturn(pMixBuf, 0);
     1140    Assert(pMixBuf->uMagic == AUDIOMIXBUF_MAGIC);
     1141    return pMixBuf->offWrite;
     1142}
     1143
    11781144
    11791145/**
  • trunk/src/VBox/Devices/Audio/AudioMixBuffer.h

    r89351 r89352  
    219219/** @} */
    220220
    221 
    222 #ifdef DEBUG
    223 void AudioMixBufDbgPrint(PAUDIOMIXBUF pMixBuf);
    224 void AudioMixBufDbgPrintChain(PAUDIOMIXBUF pMixBuf);
    225 #endif
    226 
    227221#endif /* !VBOX_INCLUDED_SRC_Audio_AudioMixBuffer_h */
    228222
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