Changeset 89331 in vbox for trunk/src/VBox/Devices/Audio
- Timestamp:
- May 28, 2021 1:05:16 AM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 144680
- Location:
- trunk/src/VBox/Devices/Audio
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/AudioMixBuffer.cpp
r89330 r89331 217 217 { 218 218 Assert(!pMixBuf->pszName); 219 Assert(!pMixBuf->pRate);220 219 Assert(!pMixBuf->pFrames); 221 220 Assert(!pMixBuf->cFrames); … … 232 231 RTStrFree(pMixBuf->pszName); 233 232 pMixBuf->pszName = NULL; 234 }235 236 if (pMixBuf->pRate)237 {238 RTMemFree(pMixBuf->pRate);239 pMixBuf->pRate = NULL;240 233 } 241 234 … … 882 875 } 883 876 884 885 886 #define AUDMIXBUF_MIXOP(_aName, _aOp) \887 static void audioMixBufOp##_aName(PPDMAUDIOFRAME paDst, uint32_t cDstFrames, \888 PPDMAUDIOFRAME paSrc, uint32_t cSrcFrames, \889 PAUDIOSTREAMRATE pRate, \890 uint32_t *pcDstWritten, uint32_t *pcSrcRead) \891 { \892 AUDMIXBUF_MACRO_LOG(("cSrcFrames=%RU32, cDstFrames=%RU32\n", cSrcFrames, cDstFrames)); \893 AUDMIXBUF_MACRO_LOG(("Rate: offSrc=%RU32, offDst=%RU32, uDstInc=%RU32\n", \894 pRate->offSrc, \895 (uint32_t)(pRate->offDst >> 32), (uint32_t)(pRate->uDstInc >> 32))); \896 \897 if (pRate->uDstInc == RT_BIT_64(32)) /* No conversion needed? */ \898 { \899 uint32_t cFrames = RT_MIN(cSrcFrames, cDstFrames); \900 AUDMIXBUF_MACRO_LOG(("cFrames=%RU32\n", cFrames)); \901 for (uint32_t i = 0; i < cFrames; i++) \902 { \903 paDst[i].i64LSample _aOp paSrc[i].i64LSample; \904 paDst[i].i64RSample _aOp paSrc[i].i64RSample; \905 } \906 \907 if (pcDstWritten) \908 *pcDstWritten = cFrames; \909 if (pcSrcRead) \910 *pcSrcRead = cFrames; \911 return; \912 } \913 \914 PPDMAUDIOFRAME pSrc = paSrc; \915 PPDMAUDIOFRAME pSrcEnd = &paSrc[cSrcFrames]; \916 PPDMAUDIOFRAME pDst = paDst; \917 PPDMAUDIOFRAME pDstEnd = &paDst[cDstFrames]; \918 PDMAUDIOFRAME frameLast = pRate->SrcLast.Frame; \919 \920 while ((uintptr_t)pDst < (uintptr_t)pDstEnd) \921 { \922 Assert((uintptr_t)pSrc <= (uintptr_t)pSrcEnd); \923 if ((uintptr_t)pSrc >= (uintptr_t)pSrcEnd) \924 break; \925 \926 while (pRate->offSrc <= (pRate->offDst >> 32)) \927 { \928 Assert((uintptr_t)pSrc < (uintptr_t)pSrcEnd); \929 frameLast = *pSrc++; \930 pRate->offSrc++; \931 if (pSrc == pSrcEnd) \932 break; \933 } \934 \935 Assert((uintptr_t)pSrc <= (uintptr_t)pSrcEnd); \936 if (pSrc == pSrcEnd) \937 break; \938 \939 PDMAUDIOFRAME frameCur = *pSrc; \940 \941 /* Interpolate. */ \942 int64_t offDstLow = pRate->offDst & UINT32_MAX; \943 \944 PDMAUDIOFRAME frameOut; \945 frameOut.i64LSample = ( frameLast.i64LSample * ((int64_t)_4G - offDstLow) \946 + frameCur.i64LSample * offDstLow) >> 32; \947 frameOut.i64RSample = ( frameLast.i64RSample * ((int64_t)_4G - offDstLow) \948 + frameCur.i64RSample * offDstLow) >> 32; \949 \950 pDst->i64LSample _aOp frameOut.i64LSample; \951 pDst->i64RSample _aOp frameOut.i64RSample; \952 \953 pDst++; \954 pRate->offDst += pRate->uDstInc; \955 \956 AUDMIXBUF_MACRO_LOG((" offDstLow=%RI64, l=%RI64, r=%RI64 (cur l=%RI64, r=%RI64); offDst=%#'RX64\n", offDstLow, \957 pDst->i64LSample >> 32, pDst->i64RSample >> 32, \958 frameCur.i64LSample >> 32, frameCur.i64RSample >> 32, \959 pRate->offDst)); \960 } \961 \962 pRate->SrcLast.Frame = frameLast; \963 if (pcDstWritten) \964 *pcDstWritten = pDst - paDst; \965 if (pcSrcRead) \966 *pcSrcRead = pSrc - paSrc; \967 \968 AUDMIXBUF_MACRO_LOG(("%zu source frames -> %zu dest frames\n", pSrc - paSrc, pDst - paDst)); \969 AUDMIXBUF_MACRO_LOG(("pRate->srcSampleLast l=%RI64, r=%RI64\n", \970 pRate->SrcFrameLast.i64LSample, pRate->SrcFrameLast.i64RSample)); \971 }972 973 /* audioMixBufOpAssign: Assigns values from source buffer to destination bufffer, overwriting the destination. */974 AUDMIXBUF_MIXOP(Assign /* Name */, = /* Operation */)975 #if 0 /* unused */976 /* audioMixBufOpBlend: Blends together the values from both, the source and the destination buffer. */977 AUDMIXBUF_MIXOP(Blend /* Name */, += /* Operation */)978 #endif979 980 #undef AUDMIXBUF_MIXOP981 877 #undef AUDMIXBUF_MACRO_LOG 982 878 … … 1176 1072 * Do a 1:1 conversion according to AUDIOMIXBUF_S2B_RATIO. */ 1177 1073 pMixBuf->iFreqRatio = 1 << 20; 1178 1179 pMixBuf->pRate = NULL;1180 1181 /** @todo r=bird: Why invent a new representation for the mixer? See also1182 * comment in pdmaudioifs.h about missing MAKE macros. */1183 pMixBuf->uAudioFmt = AUDMIXBUF_AUDIO_FMT_MAKE(pProps->uHz,1184 PDMAudioPropsChannels(pProps),1185 PDMAudioPropsSampleBits(pProps),1186 pProps->fSigned);1187 1074 1188 1075 pMixBuf->Props = *pProps; -
trunk/src/VBox/Devices/Audio/AudioMixBuffer.h
r89330 r89331 106 106 /** Pointer to const conversion parameters for the audio mixer. */ 107 107 typedef AUDMIXBUFCONVOPTS const *PCAUDMIXBUFCONVOPTS; 108 109 /**110 * @note All internal handling is done in audio frames, not in bytes!111 * @todo r=bird: What does this note actually apply to?112 */113 typedef uint32_t AUDIOMIXBUFFMT;114 typedef AUDIOMIXBUFFMT *PAUDIOMIXBUFFMT;115 108 116 109 /** … … 220 213 * @note This also is known as the distance in ring buffer terms. */ 221 214 uint32_t cUsed; 222 /** Intermediate structure for buffer conversion tasks. */223 PAUDIOSTREAMRATE pRate;224 215 /** Internal representation of current volume used for mixing. */ 225 216 AUDMIXBUFVOL Volume; 226 /** This buffer's audio format.227 * @todo r=bird: This seems to be a value created by AUDMIXBUF_AUDIO_FMT_MAKE(),228 * which is not define here. Does this structure really belong here at229 * all? */230 AUDIOMIXBUFFMT uAudioFmt;231 217 /** Audio input properties. 232 218 * @note There is only one set of audio properties here because we have one … … 256 242 /** Dead mixer buffer magic. */ 257 243 #define AUDIOMIXBUF_MAGIC_DEAD UINT32_C(0x17410728) 258 259 260 /** Constructs 32 bit value for given frequency, number of channels, bits per sample and signed bit.261 * @note This currently matches 1:1 the VRDE encoding -- this might change in the future, so better don't rely on this fact! */262 #define AUDMIXBUF_AUDIO_FMT_MAKE(freq, c, bps, s) ((((s) & 0x1) << 28) + (((bps) & 0xFF) << 20) + (((c) & 0xF) << 16) + ((freq) & 0xFFFF))263 264 /** Decodes frequency (Hz). */265 #define AUDMIXBUF_FMT_SAMPLE_FREQ(a) ((a) & 0xFFFF)266 /** Decodes number of channels. */267 #define AUDMIXBUF_FMT_CHANNELS(a) (((a) >> 16) & 0xF)268 /** Decodes signed bit. */269 #define AUDMIXBUF_FMT_SIGNED(a) (((a) >> 28) & 0x1)270 /** Decodes number of bits per sample. */271 #define AUDMIXBUF_FMT_BITS_PER_SAMPLE(a) (((a) >> 20) & 0xFF)272 /** Decodes number of bytes per sample. */273 #define AUDMIXBUF_FMT_BYTES_PER_SAMPLE(a) ((AUDMIXBUF_AUDIO_FMT_BITS_PER_SAMPLE(a) + 7) / 8)274 244 275 245 /** Converts (audio) frames to bytes. */
Note:
See TracChangeset
for help on using the changeset viewer.