Changeset 54460 in vbox
- Timestamp:
- Feb 24, 2015 4:50:08 PM (10 years ago)
- Location:
- trunk/src/VBox/Devices/Audio
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/AudioMixBuffer.cpp
r54420 r54460 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox audio: TODO 3 * VBox audio: Audio mixing buffer for converting reading/writing audio 4 * samples. 4 5 */ 5 6 … … 229 230 # define AUDMIXBUF_MACRO_LOG(x) RTPrintf x 230 231 #else 231 # define AUDMIXBUF_MACRO_LOG(x) 232 # define AUDMIXBUF_MACRO_LOG(x) do {} while (0) 232 233 #endif 233 234 … … 342 343 uint32_t *pcDstWritten, uint32_t *pcSrcRead) \ 343 344 { \ 344 AUDMIXBUF_MACRO_LOG(("pRate=%p , offSrc=%RU32, offDst=%RU64, incDst=%RU64\n", \345 AUDMIXBUF_MACRO_LOG(("pRate=%p: srcOffset=%RU32, dstOffset=%RU64, dstInc=%RU64\n", \ 345 346 pRate, pRate->srcOffset, pRate->dstOffset, pRate->dstInc)); \ 346 347 \ … … 370 371 uint64_t l = 0; \ 371 372 \ 373 AUDMIXBUF_MACRO_LOG(("Start: paDstEnd=%p - paDstStart=%p -> %zu\n", paDstEnd, paDst, paDstEnd - paDstStart)); \ 374 AUDMIXBUF_MACRO_LOG(("Start: paSrcEnd=%p - paSrcStart=%p -> %zu\n", paSrcEnd, paSrc, paSrcEnd - paSrcStart)); \ 375 \ 372 376 while (paDst < paDstEnd) \ 373 377 { \ … … 377 381 while (pRate->srcOffset <= (pRate->dstOffset >> 32)) \ 378 382 { \ 383 AUDMIXBUF_MACRO_LOG(("foo1\n")); \ 379 384 samLast = *paSrc++; \ 380 385 pRate->srcOffset++; \ … … 382 387 if (paSrc >= paSrcEnd) \ 383 388 break; \ 389 AUDMIXBUF_MACRO_LOG(("foo1.1\n")); \ 384 390 } \ 385 \ 386 if (paSrc >= paSrcEnd) \ 387 break; \ 391 AUDMIXBUF_MACRO_LOG(("foo2\n")); \ 388 392 \ 389 393 samCur = *paSrc; \ … … 405 409 pRate->dstOffset += pRate->dstInc; \ 406 410 \ 407 AUDMIXBUF_MACRO_LOG(("\t\t rate->pos=%RU64\n", pRate->dstOffset)); \411 AUDMIXBUF_MACRO_LOG(("\t\tpRate->dstOffset=%RU64\n", pRate->dstOffset)); \ 408 412 } \ 413 \ 414 AUDMIXBUF_MACRO_LOG(("End: paDst=%p - paDstStart=%p -> %zu\n", paDst, paDstStart, paDst - paDstStart)); \ 415 AUDMIXBUF_MACRO_LOG(("End: paSrc=%p - paSrcStart=%p -> %zu\n", paSrc, paSrcStart, paSrc - paSrcStart)); \ 409 416 \ 410 417 pRate->srcSampleLast = samLast; \ 411 418 \ 412 AUDMIXBUF_MACRO_LOG(("l=%RU64, rate->ilast l=%RI64, r=%RI64\n", \419 AUDMIXBUF_MACRO_LOG(("l=%RU64, pRate->srcSampleLast l=%RI64, r=%RI64\n", \ 413 420 l, pRate->srcSampleLast.u64LSample, pRate->srcSampleLast.u64RSample)); \ 414 421 \ … … 740 747 ("Buffer is not linked to a parent buffer\n"), 741 748 0); 749 750 AUDMIXBUF_LOG(("%s: cMixed=%RU32\n", pMixBuf->pszName, pMixBuf->cMixed)); 742 751 return pMixBuf->cMixed; 743 752 } 744 753 745 static int audioMixBufMixTo(PPDMAUDIOMIXBUF pDst, PPDMAUDIOMIXBUF pSrc, 746 uint32_t cSamples, uint32_t *pcProcessed) 754 static int audioMixBufMixTo(PPDMAUDIOMIXBUF pDst, PPDMAUDIOMIXBUF pSrc, uint32_t cSamples, uint32_t *pcProcessed) 747 755 { 748 756 AssertPtrReturn(pDst, VERR_INVALID_POINTER); … … 780 788 781 789 cToRead = cToReadTotal; 782 cToWrite = RT_MIN(cDead, 783 pDst->cSamples - offWrite); 790 cToWrite = RT_MIN(cDead, pDst->cSamples - offWrite); 784 791 if (!cToWrite) 785 792 { … … 796 803 audioMixBufOpBlend(pDst->pSamples + offWrite, cToWrite, 797 804 pSrc->pSamples + offRead, cToRead, 798 pSrc->pRate, 799 &cWritten, &cRead); 805 pSrc->pRate, &cWritten, &cRead); 800 806 801 807 AUDMIXBUF_LOG(("\t\tcWritten=%RU32, cRead=%RU32\n", cWritten, cRead)); … … 817 823 #ifdef DEBUG 818 824 s_cSamplesMixedTotal += cWrittenTotal; 825 audioMixBufPrint(pDst); 819 826 #endif 820 821 audioMixBufPrint(pDst);822 827 823 828 if (pcProcessed) 824 829 *pcProcessed = cReadTotal; 825 830 826 AUDMIXBUF_LOG(("c SrcRead=%RU32, cSrcMixed=%RU32, rc=%Rrc\n",827 cReadTotal, pSrc->cMixed, VINF_SUCCESS));831 AUDMIXBUF_LOG(("cReadTotal=%RU32 (pcProcessed), cWrittenTotal=%RU32, cSrcMixed=%RU32, cDstProc=%RU32\n", 832 cReadTotal, cWrittenTotal, pSrc->cMixed, pDst->cProcessed)); 828 833 return VINF_SUCCESS; 829 834 } … … 840 845 RTListForEach(&pMixBuf->lstBuffers, pIter, PDMAUDIOMIXBUF, Node) 841 846 { 842 rc = audioMixBufMixTo(pIter, pMixBuf, cSamples, 843 &cProcessed); 847 rc = audioMixBufMixTo(pIter, pMixBuf, cSamples, &cProcessed); 844 848 if (RT_FAILURE(rc)) 845 849 break; … … 861 865 VERR_INVALID_PARAMETER); 862 866 863 return audioMixBufMixTo(pMixBuf->pParent, pMixBuf, cSamples, 864 pcProcessed); 867 return audioMixBufMixTo(pMixBuf->pParent, pMixBuf, cSamples, pcProcessed); 865 868 } 866 869 -
trunk/src/VBox/Devices/Audio/testcase/tstAudioMixBuffer.cpp
r53945 r54460 5 5 6 6 /* 7 * Copyright (C) 2014 Oracle Corporation7 * Copyright (C) 2014-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 133 133 static int tstParentChild(RTTEST hTest) 134 134 { 135 RTTestSubF(hTest, " Child<->Parent");135 RTTestSubF(hTest, "2 Children -> Parent"); 136 136 137 137 uint32_t cBufSize = _1K; 138 138 139 PDMAUDIOSTREAMCFG c p =139 PDMAUDIOSTREAMCFG cfg_p = 140 140 { 141 141 44100, /* Hz */ … … 146 146 PDMPCMPROPS props; 147 147 148 int rc = drvAudioStreamCfgToProps(&c p, &props);148 int rc = drvAudioStreamCfgToProps(&cfg_p, &props); 149 149 AssertRC(rc); 150 150 … … 152 152 RTTESTI_CHECK_RC_OK(audioMixBufInit(&parent, "Parent", &props, cBufSize)); 153 153 154 PDMAUDIOSTREAMCFG c c =154 PDMAUDIOSTREAMCFG cfg_c1 = /* Downmixing */ 155 155 { 156 156 22100, /* Hz */ … … 160 160 }; 161 161 162 rc = drvAudioStreamCfgToProps(&c c, &props);162 rc = drvAudioStreamCfgToProps(&cfg_c1, &props); 163 163 AssertRC(rc); 164 164 … … 167 167 RTTESTI_CHECK_RC_OK(audioMixBufLinkTo(&child1, &parent)); 168 168 169 PDMAUDIOSTREAMCFG cfg_c2 = /* Upmixing */ 170 { 171 48000, /* Hz */ 172 2 /* Channels */, 173 AUD_FMT_S16 /* Format */, 174 PDMAUDIOENDIANESS_LITTLE /* Endianess */ 175 }; 176 177 rc = drvAudioStreamCfgToProps(&cfg_c2, &props); 178 AssertRC(rc); 179 169 180 PDMAUDIOMIXBUF child2; 170 181 RTTESTI_CHECK_RC_OK(audioMixBufInit(&child2, "Child2", &props, cBufSize)); … … 172 183 173 184 /* 174 * Writing + mixing from child(s) -> parent, sequential. 175 */ 176 int16_t samples16[2] = { 0xAA, 0xBB }; 177 uint32_t read = 0, written = 0, proc, mixed = 0; 178 179 RTTESTI_CHECK_RC_OK(audioMixBufWriteAt(&child1, 0, &samples16, sizeof(samples16), 180 &written)); 181 RTTESTI_CHECK_RC_OK(audioMixBufMixToParent(&child1, written, &mixed)); 182 RTTESTI_CHECK(mixed == 1); 183 RTTESTI_CHECK(audioMixBufMixed(&child1) == mixed); 184 185 RTTESTI_CHECK_RC_OK(audioMixBufWriteAt(&child2, 0, &samples16, sizeof(samples16), 186 &written)); 187 RTTESTI_CHECK_RC_OK(audioMixBufMixToParent(&child2, written, &mixed)); 188 RTTESTI_CHECK(mixed == 1); 189 RTTESTI_CHECK(audioMixBufMixed(&child2) == mixed); 185 * Writing + mixing from child/children -> parent, sequential. 186 */ 187 size_t cbBuf = _1K; 188 char pvBuf[_1K]; 189 int16_t samples16[32] = { 0xAA, 0xBB }; 190 uint32_t read , written, proc, mixed; 191 192 uint32_t cSamplesParent1 = 16; 193 uint32_t cSamplesChild1 = 16; 194 uint32_t cSamplesParent2 = 32; 195 uint32_t cSamplesChild2 = 16; 196 197 for (int i = 0; i < 32; i++) 198 { 199 RTTESTI_CHECK_RC_OK(audioMixBufWriteAt(&child1, 0, &samples16, sizeof(samples16), &written)); 200 RTTESTI_CHECK(written == cSamplesChild1); 201 RTTESTI_CHECK_RC_OK(audioMixBufMixToParent(&child1, written, &mixed)); 202 RTTESTI_CHECK(mixed == cSamplesChild1); 203 204 RTTESTI_CHECK_RC_OK(audioMixBufReadCirc(&parent, pvBuf, cbBuf, &read)); 205 RTTESTI_CHECK(read == 31); 206 207 RTTESTI_CHECK_RC_OK(audioMixBufWriteAt(&child2, 0, &samples16, sizeof(samples16), &written)); 208 RTTESTI_CHECK(written == cSamplesChild2); 209 RTTESTI_CHECK_RC_OK(audioMixBufMixToParent(&child2, written, &mixed)); 210 RTTESTI_CHECK(mixed == cSamplesChild2); 211 212 RTTESTI_CHECK_RC_OK(audioMixBufReadCirc(&parent, pvBuf, cbBuf, &read)); 213 RTTESTI_CHECK(read == 15); 214 } 190 215 191 216 RTTESTI_CHECK(audioMixBufProcessed(&parent) == 0); 192 193 217 194 218 return RTTestSubErrorCount(hTest) ? VERR_GENERAL_FAILURE : VINF_SUCCESS; … … 208 232 RTTestBanner(hTest); 209 233 210 rc = tstSingle(hTest);211 if (RT_SUCCESS(rc)) 234 /*rc = tstSingle(hTest); 235 if (RT_SUCCESS(rc))*/ 212 236 rc = tstParentChild(hTest); 213 237
Note:
See TracChangeset
for help on using the changeset viewer.