VirtualBox

Changeset 89301 in vbox for trunk/include/VBox/vmm


Ignore:
Timestamp:
May 26, 2021 8:57:57 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
144648
Message:

pdmaudioinline.h: Added PDMAudioPropsIsBufferSilence. Corrected implementation of unsigned samples above 8 bits in size in PDMAudioPropsClearBuffer. bugref:9890

File:
1 edited

Legend:

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

    r89218 r89301  
    743743    AssertPtrReturnVoid(pvBuf);
    744744
    745     Assert(pProps->fSwapEndian == false); /** @todo Swapping Endianness is not supported yet. */
    746 
    747745    /*
    748746     * Decide how much needs clearing.
     
    769767            case 2: /* 16 bit */
    770768            {
    771                 uint16_t *pu16Dst = (uint16_t *)pvBuf;
    772                 size_t    cLeft   = cbToClear / sizeof(uint16_t);
    773                 while (cLeft-- > 0)
    774                     *pu16Dst++ = 0x80;
     769                uint16_t       *pu16Dst   = (uint16_t *)pvBuf;
     770                uint16_t const  u16Offset = !pProps->fSwapEndian ? UINT16_C(0x8000) : UINT16_C(0x80);
     771                cbBuf /= sizeof(*pu16Dst);
     772                while (cbBuf-- > 0)
     773                    *pu16Dst++ = u16Offset;
    775774                break;
    776775            }
    777776
    778             /** @todo Add 24 bit? */
    779 
    780777            case 4: /* 32 bit */
    781                 ASMMemFill32(pvBuf, cbToClear & ~(size_t)3, 0x80);
     778                ASMMemFill32(pvBuf, cbToClear & ~(size_t)(sizeof(uint32_t) - 1),
     779                             !pProps->fSwapEndian ? UINT32_C(0x80000000) : UINT32_C(0x80));
    782780                break;
    783781
     
    785783                AssertMsgFailed(("Invalid bytes per sample: %RU8\n", pProps->cbSampleX));
    786784        }
     785    }
     786}
     787
     788/**
     789 * Checks if the given buffer is silence.
     790 *
     791 * @param   pProps      The PCM properties to use checking the buffer.
     792 * @param   pvBuf       The buffer to check.
     793 * @param   cbBuf       The number of bytes to check (must be frame aligned).
     794 */
     795DECLINLINE(bool) PDMAudioPropsIsBufferSilence(PCPDMAUDIOPCMPROPS pProps, void const *pvBuf, size_t cbBuf)
     796{
     797    /*
     798     * Validate input
     799     */
     800    AssertPtrReturn(pProps, false);
     801    if (!cbBuf)
     802        return false;
     803    AssertPtrReturn(pvBuf, false);
     804
     805    /*
     806     * Do the job.
     807     */
     808    if (pProps->fSigned)
     809        return ASMMemIsZero(pvBuf, cbBuf);
     810
     811    switch (pProps->cbSampleX)
     812    {
     813        case 1: /* 8 bit */
     814            return ASMMemIsAllU8(pvBuf, cbBuf, 0x80);
     815
     816        case 2: /* 16 bit */
     817        {
     818            uint16_t const *pu16      = (uint16_t const *)pvBuf;
     819            uint16_t const  u16Offset = !pProps->fSwapEndian ? UINT16_C(0x8000) : UINT16_C(0x80);
     820            cbBuf /= sizeof(*pu16);
     821            while (cbBuf-- > 0)
     822                if (*pu16 != u16Offset)
     823                    return false;
     824            return true;
     825        }
     826
     827        case 4: /* 32 bit */
     828        {
     829            uint32_t const *pu32      = (uint32_t const *)pvBuf;
     830            uint32_t const  u32Offset = !pProps->fSwapEndian ? UINT32_C(0x80000000) : UINT32_C(0x80);
     831            cbBuf /= sizeof(*pu32);
     832            while (cbBuf-- > 0)
     833                if (*pu32 != u32Offset)
     834                    return false;
     835            return true;
     836        }
     837
     838        default:
     839            AssertMsgFailed(("Invalid bytes per sample: %RU8\n", pProps->cbSampleX));
     840            return false;
    787841    }
    788842}
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