Changeset 89314 in vbox for trunk/src/VBox/Devices/Audio
- Timestamp:
- May 27, 2021 11:33:04 AM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 144661
- Location:
- trunk/src/VBox/Devices/Audio
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/AudioMixBuffer.cpp
r89305 r89314 491 491 * thus don't do any bounds checking! 492 492 * 493 * Note:Currently does not handle any endianness conversion yet!493 * @note Currently does not handle any endianness conversion yet! 494 494 */ 495 495 #define AUDMIXBUF_CONVERT(a_Name, a_Type, _aMin, _aMax, _aSigned, _aShift) \ … … 513 513 return (a_Type) ((iVal >> (32 - _aShift)) + ((_aMax >> 1) + 1)); \ 514 514 } \ 515 AssertMsgFailed(("%RI64 (%#RX64)\n", iVal, iVal)); /* shouldn't be possible with current buffer operations */ \ 515 516 return iVal >= 0 ? _aMax : _aMin; \ 516 517 } \ … … 1204 1205 * @param pVolSrc Volume to convert. 1205 1206 */ 1206 static int audioMixBufConvVol(PAUDMIXBUFVOL pVolDst, P PDMAUDIOVOLUME pVolSrc)1207 static int audioMixBufConvVol(PAUDMIXBUFVOL pVolDst, PCPDMAUDIOVOLUME pVolSrc) 1207 1208 { 1208 1209 if (!pVolSrc->fMuted) /* Only change/convert the volume value if we're not muted. */ … … 2848 2849 2849 2850 /** 2850 * Advances the write position of the buffer. 2851 * Worker for audioMixAdjustVolume that adjust one contiguous chunk. 2852 */ 2853 static void audioMixAdjustVolumeWorker(PAUDIOMIXBUF pMixBuf, uint32_t off, uint32_t cFrames) 2854 { 2855 PPDMAUDIOFRAME const paFrames = pMixBuf->pFrames; 2856 uint32_t const uLeft = pMixBuf->Volume.uLeft; 2857 uint32_t const uRight = pMixBuf->Volume.uRight; 2858 while (cFrames-- > 0) 2859 { 2860 paFrames[off].i64LSample = ASMMult2xS32RetS64(paFrames[off].i64LSample, uLeft) >> AUDIOMIXBUF_VOL_SHIFT; 2861 paFrames[off].i64RSample = ASMMult2xS32RetS64(paFrames[off].i64RSample, uRight) >> AUDIOMIXBUF_VOL_SHIFT; 2862 off++; 2863 } 2864 } 2865 2866 2867 /** 2868 * Does volume adjustments for the given stretch of the buffer. 2869 * 2870 * @param pMixBuf The mixing buffer. 2871 * @param offFirst Where to start (validated). 2872 * @param cFrames How many frames (validated). 2873 */ 2874 static void audioMixAdjustVolume(PAUDIOMIXBUF pMixBuf, uint32_t offFirst, uint32_t cFrames) 2875 { 2876 /* Caller has already validated these, so we don't need to repeat that in non-strict builds. */ 2877 Assert(offFirst < pMixBuf->cFrames); 2878 Assert(cFrames <= pMixBuf->cFrames); 2879 2880 /* 2881 * Muted? 2882 */ 2883 if (pMixBuf->Volume.fMuted) 2884 { 2885 uint32_t const cFramesChunk1 = RT_MIN(pMixBuf->cFrames - offFirst, cFrames); 2886 RT_BZERO(&pMixBuf->pFrames[offFirst], sizeof(pMixBuf->pFrames[0]) * cFramesChunk1); 2887 if (cFramesChunk1 < cFrames) 2888 RT_BZERO(&pMixBuf->pFrames[0], sizeof(pMixBuf->pFrames[0]) * (cFrames - cFramesChunk1)); 2889 } 2890 /* 2891 * Less than max volume? 2892 */ 2893 else if ( pMixBuf->Volume.uLeft != AUDIOMIXBUF_VOL_0DB 2894 || pMixBuf->Volume.uRight != AUDIOMIXBUF_VOL_0DB) 2895 { 2896 /* first chunk */ 2897 uint32_t const cFramesChunk1 = RT_MIN(pMixBuf->cFrames - offFirst, cFrames); 2898 audioMixAdjustVolumeWorker(pMixBuf, offFirst, cFramesChunk1); 2899 if (cFramesChunk1 < cFrames) 2900 audioMixAdjustVolumeWorker(pMixBuf, 0, cFrames - cFramesChunk1); 2901 } 2902 } 2903 2904 2905 /** 2906 * Adjust for volume settings and advances the write position of the buffer. 2851 2907 * 2852 2908 * For use after done peeking with AudioMixBufWrite(), AudioMixBufSilence(), … … 2863 2919 2864 2920 AssertStmt(cFrames <= pMixBuf->cFrames - pMixBuf->cUsed, cFrames = pMixBuf->cFrames - pMixBuf->cUsed); 2921 2922 audioMixAdjustVolume(pMixBuf, pMixBuf->offWrite, cFrames); 2923 2865 2924 pMixBuf->cUsed += cFrames; 2866 2925 pMixBuf->offWrite = (pMixBuf->offWrite + cFrames) % pMixBuf->cFrames; … … 2875 2934 * @param pVol Pointer to volume structure to set. 2876 2935 */ 2877 void AudioMixBufSetVolume(PAUDIOMIXBUF pMixBuf, P PDMAUDIOVOLUME pVol)2936 void AudioMixBufSetVolume(PAUDIOMIXBUF pMixBuf, PCPDMAUDIOVOLUME pVol) 2878 2937 { 2879 2938 AssertPtrReturnVoid(pMixBuf); … … 2882 2941 LogFlowFunc(("%s: lVol=%RU8, rVol=%RU8, fMuted=%RTbool\n", pMixBuf->pszName, pVol->uLeft, pVol->uRight, pVol->fMuted)); 2883 2942 2884 int rc2 = audioMixBufConvVol(&pMixBuf->Volume /* Dest */, pVol /* Source */);2943 int rc2 = audioMixBufConvVol(&pMixBuf->Volume, pVol); 2885 2944 AssertRC(rc2); 2886 2945 } -
trunk/src/VBox/Devices/Audio/AudioMixBuffer.h
r89302 r89314 329 329 uint32_t AudioMixBufReadPos(PAUDIOMIXBUF pMixBuf); 330 330 void AudioMixBufReset(PAUDIOMIXBUF pMixBuf); 331 void AudioMixBufSetVolume(PAUDIOMIXBUF pMixBuf, P PDMAUDIOVOLUME pVol);331 void AudioMixBufSetVolume(PAUDIOMIXBUF pMixBuf, PCPDMAUDIOVOLUME pVol); 332 332 uint32_t AudioMixBufSize(PAUDIOMIXBUF pMixBuf); 333 333 uint32_t AudioMixBufSizeBytes(PAUDIOMIXBUF pMixBuf); -
trunk/src/VBox/Devices/Audio/AudioMixer.cpp
r89304 r89314 514 514 { 515 515 audioMixerStreamCtlInternal(pStream, PDMAUDIOSTREAMCMD_ENABLE); 516 }517 518 if (pSink->enmDir != PDMAUDIODIR_OUT)519 {520 /* Apply the sink's combined volume to the stream. */521 int rc2 = pStream->pConn->pfnStreamSetVolume(pStream->pConn, pStream->pStream, &pSink->VolumeCombined);522 AssertRC(rc2);523 516 } 524 517 … … 2524 2517 pSink->VolumeCombined.fMuted, pSink->VolumeCombined.uLeft, pSink->VolumeCombined.uRight)); 2525 2518 2526 /* 2527 * Input sinks must currently propagate the new volume settings to 2528 * all the streams. (For output sinks we do the volume control here.) 2529 */ 2530 if (pSink->enmDir != PDMAUDIODIR_OUT) 2531 { 2532 PAUDMIXSTREAM pMixStream; 2533 RTListForEach(&pSink->lstStreams, pMixStream, AUDMIXSTREAM, Node) 2534 { 2535 int rc2 = pMixStream->pConn->pfnStreamSetVolume(pMixStream->pConn, pMixStream->pStream, &pSink->VolumeCombined); 2536 AssertRC(rc2); 2537 } 2538 } 2539 2519 AudioMixBufSetVolume(&pSink->MixBuf, &pSink->VolumeCombined); 2540 2520 return VINF_SUCCESS; 2541 2521 }
Note:
See TracChangeset
for help on using the changeset viewer.