- Timestamp:
- May 18, 2015 7:11:51 PM (10 years ago)
- Location:
- trunk/src/VBox/Devices/Audio
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/AudioMixBuffer.cpp
r55852 r55920 83 83 84 84 85 /** 86 uint32_taVolumeConv[256] = {85 /** Logarithmic/exponential volume conversion table. */ 86 static uint32_t s_aVolumeConv[256] = { 87 87 1, 1, 1, 1, 1, 1, 1, 1, /* 7 */ 88 88 1, 2, 2, 2, 2, 2, 2, 2, /* 15 */ … … 120 120 121 121 /* Bit shift for fixed point conversion. */ 122 #define VOL_SHIFT 30122 #define AUDIOMIXBUF_VOL_SHIFT 30 123 123 124 124 /* Internal representation of 0dB volume (1.0 in fixed point). */ 125 #define VOL_0DB (1 <<VOL_SHIFT)126 127 AssertCompile( VOL_0DB <= 0x40000000); /* Must always hold. */128 AssertCompile( VOL_0DB == 0x40000000); /* For now -- when only attenuation is used. */125 #define AUDIOMIXBUF_VOL_0DB (1 << AUDIOMIXBUF_VOL_SHIFT) 126 127 AssertCompile(AUDIOMIXBUF_VOL_0DB <= 0x40000000); /* Must always hold. */ 128 AssertCompile(AUDIOMIXBUF_VOL_0DB == 0x40000000); /* For now -- when only attenuation is used. */ 129 129 130 130 /** … … 155 155 #ifdef DEBUG 156 156 static uint64_t s_cSamplesMixedTotal = 0; 157 static inline void audioMixBufPrint(PPDMAUDIOMIXBUF pMixBuf); 157 158 #endif 158 159 static void audioMixBufFreeBuf(PPDMAUDIOMIXBUF pMixBuf);160 static inline void audioMixBufPrint(PPDMAUDIOMIXBUF pMixBuf);161 159 162 160 typedef uint32_t (AUDMIXBUF_FN_CONVFROM) (PPDMAUDIOSAMPLE paDst, const void *pvSrc, uint32_t cbSrc, const PAUDMIXBUF_CONVOPTS pOpts); … … 167 165 168 166 /* Can return VINF_TRY_AGAIN for getting next pointer at beginning (circular) */ 169 int audioMixBufAcquire(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToRead, 167 168 /** 169 * Acquires (reads) a mutable pointer to the mixing buffer's audio samples without 170 * any conversion done. 171 ** @todo Rename to AudioMixBufPeek(Mutable/Raw)? 172 ** @todo Protect the buffer's data? 173 * 174 * @return IPRT status code. 175 * @param pMixBuf Mixing buffer to acquire audio samples from. 176 * @param cSamplesToRead Number of audio samples to read. 177 * @param ppvSamples Returns a mutable pointer to the buffer's audio sample data. 178 * @param pcSamplesRead Number of audio samples read (acquired). 179 * 180 * @remark This function is not thread safe! 181 */ 182 int AudioMixBufAcquire(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToRead, 170 183 PPDMAUDIOSAMPLE *ppvSamples, uint32_t *pcSamplesRead) 171 184 { … … 210 223 * keeps track to eventually assigned children buffers. 211 224 * 212 * @param pMixBuf 213 * @param cSamplesToClear 214 */ 215 void audioMixBufFinish(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToClear)225 * @param pMixBuf Mixing buffer to clear. 226 * @param cSamplesToClear Number of audio samples to clear. 227 */ 228 void AudioMixBufFinish(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToClear) 216 229 { 217 230 AUDMIXBUF_LOG(("cSamples=%RU32\n", cSamplesToClear)); … … 255 268 } 256 269 257 void audioMixBufDestroy(PPDMAUDIOMIXBUF pMixBuf) 270 /** 271 * Destroys (uninitializes) a mixing buffer. 272 * 273 * @param pMixBuf Mixing buffer to destroy. 274 */ 275 void AudioMixBufDestroy(PPDMAUDIOMIXBUF pMixBuf) 258 276 { 259 277 if (!pMixBuf) 260 278 return; 261 279 262 audioMixBufUnlink(pMixBuf);280 AudioMixBufUnlink(pMixBuf); 263 281 264 282 if (pMixBuf->pszName) … … 276 294 } 277 295 278 audioMixBufFreeBuf(pMixBuf); 279 } 280 281 /** @todo Rename this function! Too confusing in combination with audioMixBufFreeBuf(). */ 282 uint32_t audioMixBufFree(PPDMAUDIOMIXBUF pMixBuf) 296 if (pMixBuf->pSamples) 297 { 298 Assert(pMixBuf->cSamples); 299 300 RTMemFree(pMixBuf->pSamples); 301 pMixBuf->pSamples = NULL; 302 } 303 304 pMixBuf->cSamples = 0; 305 } 306 307 /** 308 * Returns the size (in audio samples) of free audio buffer space. 309 * 310 * @return uint32_t Size (in audio samples) of free audio buffer space. 311 * @param pMixBuf Mixing buffer to return free size for. 312 */ 313 uint32_t AudioMixBufFree(PPDMAUDIOMIXBUF pMixBuf) 283 314 { 284 315 AssertPtrReturn(pMixBuf, 0); 285 316 286 uint32_t c Free;317 uint32_t cSamplesFree; 287 318 if (pMixBuf->pParent) 288 319 { … … 292 323 */ 293 324 Assert(pMixBuf->cMixed <= pMixBuf->pParent->cSamples); 294 cFree = pMixBuf->pParent->cSamples - pMixBuf->cMixed; 295 } 296 else 297 cFree = pMixBuf->cSamples - pMixBuf->cProcessed; 298 299 AUDMIXBUF_LOG(("%s: cFree=%RU32\n", pMixBuf->pszName, cFree)); 300 return cFree; 301 } 302 303 uint32_t audioMixBufFreeBytes(PPDMAUDIOMIXBUF pMixBuf) 304 { 305 return AUDIOMIXBUF_S2B(pMixBuf, audioMixBufFree(pMixBuf)); 306 } 307 308 static int audioMixBufAllocBuf(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamples) 325 cSamplesFree = pMixBuf->pParent->cSamples - pMixBuf->cMixed; 326 } 327 else /* As a parent. */ 328 { 329 Assert(pMixBuf->cSamples >= pMixBuf->cProcessed); 330 cSamplesFree = pMixBuf->cSamples - pMixBuf->cProcessed; 331 } 332 333 AUDMIXBUF_LOG(("%s: cSamplesFree=%RU32\n", pMixBuf->pszName, cSamplesFree)); 334 return cSamplesFree; 335 } 336 337 /** 338 * Returns the size (in bytes) of free audio buffer space. 339 * 340 * @return uint32_t Size (in bytes) of free audio buffer space. 341 * @param pMixBuf Mixing buffer to return free size for. 342 */ 343 uint32_t AudioMixBufFreeBytes(PPDMAUDIOMIXBUF pMixBuf) 344 { 345 return AUDIOMIXBUF_S2B(pMixBuf, AudioMixBufFree(pMixBuf)); 346 } 347 348 /** 349 * Allocates the internal audio sample buffer. 350 * 351 * @return IPRT status code. 352 * @param pMixBuf Mixing buffer to allocate sample buffer for. 353 * @param cSamples Number of audio samples to allocate. 354 */ 355 static int audioMixBufAlloc(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamples) 309 356 { 310 357 AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER); … … 376 423 { \ 377 424 AUDMIXBUF_MACRO_LOG(("%p: l=%RI16, r=%RI16\n", paDst, *pSrc, *(pSrc + 1))); \ 378 paDst->i64LSample = ASMMult2xS32RetS64((int32_t)audioMixBufClipFrom##_aName(*pSrc++), pOpts->Volume.uLeft ) >> VOL_SHIFT; \379 paDst->i64RSample = ASMMult2xS32RetS64((int32_t)audioMixBufClipFrom##_aName(*pSrc++), pOpts->Volume.uRight) >> VOL_SHIFT; \425 paDst->i64LSample = ASMMult2xS32RetS64((int32_t)audioMixBufClipFrom##_aName(*pSrc++), pOpts->Volume.uLeft ) >> AUDIOMIXBUF_VOL_SHIFT; \ 426 paDst->i64RSample = ASMMult2xS32RetS64((int32_t)audioMixBufClipFrom##_aName(*pSrc++), pOpts->Volume.uRight) >> AUDIOMIXBUF_VOL_SHIFT; \ 380 427 AUDMIXBUF_MACRO_LOG(("\t-> l=%RI64, r=%RI64\n", paDst->i64LSample, paDst->i64RSample)); \ 381 428 paDst++; \ … … 395 442 { \ 396 443 AUDMIXBUF_MACRO_LOG(("%p: s=%RI16\n", paDst, *pSrc)); \ 397 paDst->i64LSample = ASMMult2xS32RetS64((int32_t)audioMixBufClipFrom##_aName(*pSrc), pOpts->Volume.uLeft) >>VOL_SHIFT; \398 paDst->i64RSample = ASMMult2xS32RetS64((int32_t)audioMixBufClipFrom##_aName(*pSrc), pOpts->Volume.uRight) >> VOL_SHIFT; \444 paDst->i64LSample = ASMMult2xS32RetS64((int32_t)audioMixBufClipFrom##_aName(*pSrc), pOpts->Volume.uLeft) >> AUDIOMIXBUF_VOL_SHIFT; \ 445 paDst->i64RSample = ASMMult2xS32RetS64((int32_t)audioMixBufClipFrom##_aName(*pSrc), pOpts->Volume.uRight) >> AUDIOMIXBUF_VOL_SHIFT; \ 399 446 ++pSrc; \ 400 447 AUDMIXBUF_MACRO_LOG(("\t-> l=%RI64, r=%RI64\n", paDst->i64LSample, paDst->i64RSample)); \ … … 570 617 571 618 /** 619 * Looks up the matching conversion (macro) routine for converting 620 * audio samples from a source format. 572 621 * 573 622 ** @todo Speed up the lookup by binding it to the actual stream state. 574 623 * 575 * @return PAUDMIXBUF_FN_CONVFROM 576 * @param enmFmt The source audio stream format577 * @param fMuted Flag determining whether the source is muted624 * @return PAUDMIXBUF_FN_CONVFROM Function pointer to conversion macro if found, NULL if not supported. 625 * @param enmFmt Audio format to lookup conversion macro for. 626 * @param fMuted Flag determining whether the source is muted. 578 627 */ 579 628 static inline PAUDMIXBUF_FN_CONVFROM audioMixBufConvFromLookup(PDMAUDIOMIXBUFFMT enmFmt, bool fMuted) … … 633 682 634 683 /** 684 * Looks up the matching conversion (macro) routine for converting 685 * audio samples to a destination format. 635 686 * 636 687 ** @todo Speed up the lookup by binding it to the actual stream state. 637 688 * 638 * @return PAUDMIXBUF_FN_CONVTO 639 * @param enmFmt 689 * @return PAUDMIXBUF_FN_CONVTO Function pointer to conversion macro if found, NULL if not supported. 690 * @param enmFmt Audio format to lookup conversion macro for. 640 691 */ 641 692 static inline PAUDMIXBUF_FN_CONVTO audioMixBufConvToLookup(PDMAUDIOMIXBUFFMT enmFmt) … … 691 742 } 692 743 693 static void audioMixBufFreeBuf(PPDMAUDIOMIXBUF pMixBuf) 694 { 695 if (pMixBuf) 696 { 697 if (pMixBuf->pSamples) 698 { 699 RTMemFree(pMixBuf->pSamples); 700 pMixBuf->pSamples = NULL; 701 } 702 703 pMixBuf->cSamples = 0; 704 } 705 } 706 707 int audioMixBufInit(PPDMAUDIOMIXBUF pMixBuf, const char *pszName, PPDMPCMPROPS pProps, uint32_t cSamples) 744 /** 745 * Initializes a mixing buffer. 746 * 747 * @return IPRT status code. 748 * @param pMixBuf Mixing buffer to initialize. 749 * @param pszName Name of mixing buffer for easier identification. Optional. 750 * @param pProps PCM audio properties to use for the mixing buffer. 751 * @param cSamples Maximum number of audio samples the mixing buffer can hold. 752 */ 753 int AudioMixBufInit(PPDMAUDIOMIXBUF pMixBuf, const char *pszName, PPDMPCMPROPS pProps, uint32_t cSamples) 708 754 { 709 755 AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER); … … 723 769 /* Set initial volume to max. */ 724 770 pMixBuf->Volume.fMuted = false; 725 pMixBuf->Volume.uLeft = VOL_0DB;726 pMixBuf->Volume.uRight = VOL_0DB;771 pMixBuf->Volume.uLeft = AUDIOMIXBUF_VOL_0DB; 772 pMixBuf->Volume.uRight = AUDIOMIXBUF_VOL_0DB; 727 773 728 774 /* Prevent division by zero. … … 748 794 RT_BOOL(AUDMIXBUF_FMT_SIGNED(pMixBuf->AudioFmt)))); 749 795 750 return audioMixBufAllocBuf(pMixBuf, cSamples); 751 } 752 753 bool audioMixBufIsEmpty(PPDMAUDIOMIXBUF pMixBuf) 796 return audioMixBufAlloc(pMixBuf, cSamples); 797 } 798 799 /** 800 * Returns @true if there are any audio samples available for processing, 801 * @false if not. 802 * 803 * @return bool @true if there are any audio samples available for processing, @false if not. 804 * @param pMixBuf Mixing buffer to return value for. 805 */ 806 bool AudioMixBufIsEmpty(PPDMAUDIOMIXBUF pMixBuf) 754 807 { 755 808 AssertPtrReturn(pMixBuf, true); … … 760 813 } 761 814 762 int audioMixBufLinkTo(PPDMAUDIOMIXBUF pMixBuf, PPDMAUDIOMIXBUF pParent) 815 /** 816 * Links an audio mixing buffer to a parent mixing buffer. A parent mixing 817 * buffer can have multiple children mixing buffers [1:N], whereas a child only can 818 * have one parent mixing buffer [N:1]. 819 * 820 * The mixing direction always goes from the child/children buffer(s) to the 821 * parent buffer. 822 * 823 * For guest audio output the host backend owns the parent mixing buffer, the 824 * device emulation owns the child/children. 825 * 826 * The audio format of each mixing buffer can vary; the internal mixing code 827 * then will autiomatically do the (needed) conversion. 828 * 829 * @return IPRT status code. 830 * @param pMixBuf Mixing buffer to link parent to. 831 * @param pParent Parent mixing buffer to use for linking. 832 * 833 * @remark Circular linking is not allowed. 834 */ 835 int AudioMixBufLinkTo(PPDMAUDIOMIXBUF pMixBuf, PPDMAUDIOMIXBUF pParent) 763 836 { 764 837 AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER); … … 847 920 } 848 921 849 uint32_t audioMixBufMixed(PPDMAUDIOMIXBUF pMixBuf) 922 /** 923 * Returns the number of audio samples mixed (processed) from 924 * the parent mixing buffer. 925 * 926 * @return uint32_t Number of audio samples mixed (processed). 927 * @param pMixBuf Mixing buffer to return number from. 928 */ 929 uint32_t AudioMixBufMixed(PPDMAUDIOMIXBUF pMixBuf) 850 930 { 851 931 AssertPtrReturn(pMixBuf, 0); … … 859 939 } 860 940 941 /** 942 * Mixes audio samples from a source mixing buffer to a destination mixing buffer. 943 * 944 * @return IPRT status code. 945 * @param pDst Destination mixing buffer. 946 * @param pSrc Source mixing buffer. 947 * @param cSamples Number of source audio samples to mix. 948 * @param pcProcessed Number of audio samples successfully mixed. 949 */ 861 950 static int audioMixBufMixTo(PPDMAUDIOMIXBUF pDst, PPDMAUDIOMIXBUF pSrc, uint32_t cSamples, uint32_t *pcProcessed) 862 951 { … … 942 1031 } 943 1032 944 int audioMixBufMixToChildren(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamples, 1033 /** 1034 * Mixes (multiplexes) audio samples to all connected mixing buffer children. 1035 * 1036 * @return IPRT status code. 1037 * @param pMixBuf Mixing buffer to use. 1038 * @param cSamples Number of audio samples to mix to children. 1039 * @param pcProcessed Maximum number of audio samples successfully mixed 1040 * to all children. Optional. 1041 */ 1042 int AudioMixBufMixToChildren(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamples, 945 1043 uint32_t *pcProcessed) 946 1044 { 1045 AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER); 1046 1047 if (!cSamples) 1048 { 1049 if (pcProcessed) 1050 *pcProcessed = 0; 1051 return VINF_SUCCESS; 1052 } 1053 947 1054 int rc = VINF_SUCCESS; 948 1055 … … 966 1073 } 967 1074 968 int audioMixBufMixToParent(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamples, 1075 /** 1076 * Mixes audio samples down to the parent mixing buffer. 1077 * 1078 * @return IPRT status code. 1079 * @param pMixBuf Mixing buffer to mix samples down to parent. 1080 * @param cSamples Number of audio samples to mix down. 1081 * @param pcProcessed Number of audio samples successfully processed. Optional. 1082 */ 1083 int AudioMixBufMixToParent(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamples, 969 1084 uint32_t *pcProcessed) 970 1085 { … … 976 1091 } 977 1092 1093 #ifdef DEBUG 1094 /** 1095 * Prints statistics and status of a mixing buffer to the logger. 1096 * For debug versions only. 1097 * 1098 * @return IPRT status code. 1099 * @param pMixBuf Mixing buffer to print. 1100 */ 978 1101 static inline void audioMixBufPrint(PPDMAUDIOMIXBUF pMixBuf) 979 1102 { 980 #ifdef DEBUG_DISABLED981 1103 PPDMAUDIOMIXBUF pParent = pMixBuf; 982 1104 if (pMixBuf->pParent) … … 999 1121 AUDMIXBUF_LOG(("Total samples mixed: %RU64\n", s_cSamplesMixedTotal)); 1000 1122 AUDMIXBUF_LOG(("********************************************\n")); 1123 } 1001 1124 #endif 1002 }1003 1125 1004 1126 /** … … 1008 1130 * @param pMixBuf 1009 1131 */ 1010 uint32_t audioMixBufProcessed(PPDMAUDIOMIXBUF pMixBuf)1132 uint32_t AudioMixBufProcessed(PPDMAUDIOMIXBUF pMixBuf) 1011 1133 { 1012 1134 AssertPtrReturn(pMixBuf, 0); … … 1016 1138 } 1017 1139 1018 int audioMixBufReadAt(PPDMAUDIOMIXBUF pMixBuf, 1140 /** 1141 * Reads audio samples at a specific offset. 1142 * 1143 * @return IPRT status code. 1144 * @param pMixBuf Mixing buffer to read audio samples from. 1145 * @param offSamples Offset (in audio samples) to start reading from. 1146 * @param pvBuf Pointer to buffer to write output to. 1147 * @param cbBuf Size (in bytes) of buffer to write to. 1148 * @param pcbRead Size (in bytes) of data read. Optional. 1149 */ 1150 int AudioMixBufReadAt(PPDMAUDIOMIXBUF pMixBuf, 1019 1151 uint32_t offSamples, 1020 1152 void *pvBuf, uint32_t cbBuf, 1021 1153 uint32_t *pcbRead) 1022 1154 { 1023 return audioMixBufReadAtEx(pMixBuf, pMixBuf->AudioFmt,1155 return AudioMixBufReadAtEx(pMixBuf, pMixBuf->AudioFmt, 1024 1156 offSamples, pvBuf, cbBuf, pcbRead); 1025 1157 } 1026 1158 1027 int audioMixBufReadAtEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, 1159 /** 1160 * Reads audio samples at a specific offset. 1161 * If the audio format of the mixing buffer and the requested audio format do 1162 * not match the output will be converted accordingly. 1163 * 1164 * @return IPRT status code. 1165 * @param pMixBuf Mixing buffer to read audio samples from. 1166 * @param enmFmt Audio format to use for output. 1167 * @param offSamples Offset (in audio samples) to start reading from. 1168 * @param pvBuf Pointer to buffer to write output to. 1169 * @param cbBuf Size (in bytes) of buffer to write to. 1170 * @param pcbRead Size (in bytes) of data read. Optional. 1171 */ 1172 int AudioMixBufReadAtEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, 1028 1173 uint32_t offSamples, 1029 1174 void *pvBuf, uint32_t cbBuf, … … 1058 1203 rc = VERR_INVALID_PARAMETER; 1059 1204 1205 #ifdef DEBUG 1060 1206 audioMixBufPrint(pMixBuf); 1207 #endif 1061 1208 } 1062 1209 else … … 1073 1220 } 1074 1221 1075 int audioMixBufReadCirc(PPDMAUDIOMIXBUF pMixBuf, 1222 /** 1223 * Reads audio samples. The audio format of the mixing buffer will be used. 1224 * 1225 * @return IPRT status code. 1226 * @param pMixBuf Mixing buffer to read audio samples from. 1227 * @param pvBuf Pointer to buffer to write output to. 1228 * @param cbBuf Size (in bytes) of buffer to write to. 1229 * @param pcRead Number of audio samples read. Optional. 1230 */ 1231 int AudioMixBufReadCirc(PPDMAUDIOMIXBUF pMixBuf, 1076 1232 void *pvBuf, uint32_t cbBuf, uint32_t *pcRead) 1077 1233 { 1078 return audioMixBufReadCircEx(pMixBuf, pMixBuf->AudioFmt,1234 return AudioMixBufReadCircEx(pMixBuf, pMixBuf->AudioFmt, 1079 1235 pvBuf, cbBuf, pcRead); 1080 1236 } 1081 1237 1082 int audioMixBufReadCircEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, 1238 /** 1239 * Reads audio samples in a specific audio format. 1240 * If the audio format of the mixing buffer and the requested audio format do 1241 * not match the output will be converted accordingly. 1242 * 1243 * @return IPRT status code. 1244 * @param pMixBuf Mixing buffer to read audio samples from. 1245 * @param enmFmt Audio format to use for output. 1246 * @param pvBuf Pointer to buffer to write output to. 1247 * @param cbBuf Size (in bytes) of buffer to write to. 1248 * @param pcRead Number of audio samples read. Optional. 1249 */ 1250 int AudioMixBufReadCircEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, 1083 1251 void *pvBuf, uint32_t cbBuf, uint32_t *pcRead) 1084 1252 { … … 1098 1266 if (!cToRead) 1099 1267 { 1268 #ifdef DEBUG 1100 1269 audioMixBufPrint(pMixBuf); 1101 1270 #endif 1102 1271 if (pcRead) 1103 1272 *pcRead = 0; … … 1180 1349 } 1181 1350 1351 #ifdef DEBUG 1182 1352 audioMixBufPrint(pMixBuf); 1353 #endif 1183 1354 1184 1355 AUDMIXBUF_LOG(("cRead=%RU32 (%zu bytes), rc=%Rrc\n", … … 1188 1359 } 1189 1360 1190 void audioMixBufReset(PPDMAUDIOMIXBUF pMixBuf) 1361 /** 1362 * Resets a mixing buffer. 1363 * 1364 * @param pMixBuf Mixing buffer to reset. 1365 */ 1366 void AudioMixBufReset(PPDMAUDIOMIXBUF pMixBuf) 1191 1367 { 1192 1368 AssertPtrReturnVoid(pMixBuf); … … 1202 1378 } 1203 1379 1204 void audioMixBufSetVolume(PPDMAUDIOMIXBUF pMixBuf, PPDMAUDIOVOLUME pVol) 1380 /** 1381 * Sets the overall (master) volume. 1382 * 1383 * @param pMixBuf Mixing buffer to set volume for. 1384 * @param pVol Pointer to volume structure to set. 1385 */ 1386 void AudioMixBufSetVolume(PPDMAUDIOMIXBUF pMixBuf, PPDMAUDIOVOLUME pVol) 1205 1387 { 1206 1388 AssertPtrReturnVoid(pMixBuf); … … 1210 1392 1211 1393 pMixBuf->Volume.fMuted = pVol->fMuted; 1212 / /@todo: Ensure that the input is in the correct range/initialized!1213 pMixBuf->Volume.uLeft = aVolumeConv[pVol->uLeft & 0xFF] * (VOL_0DB >> 16);1214 pMixBuf->Volume.uRight = aVolumeConv[pVol->uRight & 0xFF] * (VOL_0DB >> 16);1394 /** @todo Ensure that the input is in the correct range/initialized! */ 1395 pMixBuf->Volume.uLeft = s_aVolumeConv[pVol->uLeft & 0xFF] * (AUDIOMIXBUF_VOL_0DB >> 16); 1396 pMixBuf->Volume.uRight = s_aVolumeConv[pVol->uRight & 0xFF] * (AUDIOMIXBUF_VOL_0DB >> 16); 1215 1397 1216 1398 LogFlowFunc(("\t-> lVol=%#RX32, rVol=%#RX32\n", pMixBuf->Volume.uLeft, pMixBuf->Volume.uRight)); 1217 1399 } 1218 1400 1219 uint32_t audioMixBufSize(PPDMAUDIOMIXBUF pMixBuf) 1220 { 1401 /** 1402 * Returns the maximum amount of audio samples this buffer can hold. 1403 * 1404 * @return uint32_t Size (in audio samples) the mixing buffer can hold. 1405 * @param pMixBuf Mixing buffer to retrieve maximum for. 1406 */ 1407 uint32_t AudioMixBufSize(PPDMAUDIOMIXBUF pMixBuf) 1408 { 1409 AssertPtrReturn(pMixBuf, 0); 1221 1410 return pMixBuf->cSamples; 1222 1411 } … … 1225 1414 * Returns the maximum amount of bytes this buffer can hold. 1226 1415 * 1227 * @return uint32_t 1228 * @param pMixBuf 1229 */ 1230 uint32_t audioMixBufSizeBytes(PPDMAUDIOMIXBUF pMixBuf) 1231 { 1416 * @return uint32_t Size (in bytes) the mixing buffer can hold. 1417 * @param pMixBuf Mixing buffer to retrieve maximum for. 1418 */ 1419 uint32_t AudioMixBufSizeBytes(PPDMAUDIOMIXBUF pMixBuf) 1420 { 1421 AssertPtrReturn(pMixBuf, 0); 1232 1422 return AUDIOMIXBUF_S2B(pMixBuf, pMixBuf->cSamples); 1233 1423 } 1234 1424 1235 void audioMixBufUnlink(PPDMAUDIOMIXBUF pMixBuf) 1425 /** 1426 * Unlinks a mixing buffer from its parent, if any. 1427 * 1428 * @return IPRT status code. 1429 * @param pMixBuf Mixing buffer to unlink from parent. 1430 */ 1431 void AudioMixBufUnlink(PPDMAUDIOMIXBUF pMixBuf) 1236 1432 { 1237 1433 if (!pMixBuf || !pMixBuf->pszName) … … 1249 1445 /* Make sure to reset the parent mixing buffer each time it gets linked 1250 1446 * to a new child. */ 1251 audioMixBufReset(pMixBuf->pParent);1447 AudioMixBufReset(pMixBuf->pParent); 1252 1448 pMixBuf->pParent = NULL; 1253 1449 } … … 1260 1456 AUDMIXBUF_LOG(("\tUnlinking \"%s\"\n", pIter->pszName)); 1261 1457 1262 audioMixBufReset(pIter->pParent);1458 AudioMixBufReset(pIter->pParent); 1263 1459 pIter->pParent = NULL; 1264 1460 … … 1275 1471 } 1276 1472 1277 int audioMixBufWriteAt(PPDMAUDIOMIXBUF pMixBuf, 1473 /** 1474 * Writes audio samples at a specific offset. 1475 * The sample format being written must match the format of the mixing buffer. 1476 * 1477 * @return IPRT status code. 1478 * @param pMixBuf Pointer to mixing buffer to write to. 1479 * @param enmFmt Audio format supplied in the buffer. 1480 * @param offSamples Offset (in samples) starting to write at. 1481 * @param pvBuf Pointer to audio buffer to be written. 1482 * @param cbBuf Size (in bytes) of audio buffer. 1483 * @param pcWritten Returns number of audio samples written. Optional. 1484 */ 1485 int AudioMixBufWriteAt(PPDMAUDIOMIXBUF pMixBuf, 1278 1486 uint32_t offSamples, 1279 1487 const void *pvBuf, uint32_t cbBuf, 1280 1488 uint32_t *pcWritten) 1281 1489 { 1282 return audioMixBufWriteAtEx(pMixBuf, pMixBuf->AudioFmt,1490 return AudioMixBufWriteAtEx(pMixBuf, pMixBuf->AudioFmt, 1283 1491 offSamples, pvBuf, cbBuf, pcWritten); 1284 1492 } 1285 1493 1286 1494 /** 1287 * TODO 1495 * Writes audio samples at a specific offset. The audio sample format 1496 * to be written can be different from the audio format the mixing buffer 1497 * operates on. 1288 1498 * 1289 1499 * @return IPRT status code. 1290 * @return int 1291 * @param pMixBuf 1292 * @param enmFmt 1293 * @param offSamples 1294 * @param pvBuf 1295 * @param cbBuf 1296 * @param pcWritten Returns number of samples written. Optional. 1297 */ 1298 int audioMixBufWriteAtEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, 1500 * @param pMixBuf Pointer to mixing buffer to write to. 1501 * @param enmFmt Audio format supplied in the buffer. 1502 * @param offSamples Offset (in samples) starting to write at. 1503 * @param pvBuf Pointer to audio buffer to be written. 1504 * @param cbBuf Size (in bytes) of audio buffer. 1505 * @param pcWritten Returns number of audio samples written. Optional. 1506 */ 1507 int AudioMixBufWriteAtEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, 1299 1508 uint32_t offSamples, 1300 1509 const void *pvBuf, uint32_t cbBuf, … … 1342 1551 1343 1552 cWritten = pConv(pMixBuf->pSamples + offSamples, pvBuf, cbBuf, &convOpts); 1553 #ifdef DEBUG 1344 1554 audioMixBufPrint(pMixBuf); 1345 1555 #endif 1346 1556 rc = cWritten ? VINF_SUCCESS : VERR_GENERAL_FAILURE; /** @todo Fudge! */ 1347 1557 } … … 1362 1572 } 1363 1573 1364 int audioMixBufWriteCirc(PPDMAUDIOMIXBUF pMixBuf, 1574 /** 1575 * Writes audio samples. The sample format being written must match the 1576 * format of the mixing buffer. 1577 * 1578 * @return IPRT status code. 1579 * @param pMixBuf Pointer to mixing buffer to write to. 1580 * @param pvBuf Pointer to audio buffer to be written. 1581 * @param cbBuf Size (in bytes) of audio buffer. 1582 * @param pcWritten Returns number of audio samples written. Optional. 1583 */ 1584 int AudioMixBufWriteCirc(PPDMAUDIOMIXBUF pMixBuf, 1365 1585 const void *pvBuf, uint32_t cbBuf, 1366 1586 uint32_t *pcWritten) 1367 1587 { 1368 return audioMixBufWriteCircEx(pMixBuf, pMixBuf->AudioFmt, pvBuf, cbBuf, pcWritten); 1369 } 1370 1371 int audioMixBufWriteCircEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, 1588 return AudioMixBufWriteCircEx(pMixBuf, pMixBuf->AudioFmt, pvBuf, cbBuf, pcWritten); 1589 } 1590 1591 /** 1592 * Writes audio samples of a specific format. 1593 * 1594 * @return IPRT status code. 1595 * @param pMixBuf Pointer to mixing buffer to write to. 1596 * @param enmFmt Audio format supplied in the buffer. 1597 * @param pvBuf Pointer to audio buffer to be written. 1598 * @param cbBuf Size (in bytes) of audio buffer. 1599 * @param pcWritten Returns number of audio samples written. Optional. 1600 */ 1601 int AudioMixBufWriteCircEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, 1372 1602 const void *pvBuf, uint32_t cbBuf, 1373 1603 uint32_t *pcWritten) … … 1478 1708 } 1479 1709 1710 #ifdef DEBUG 1480 1711 audioMixBufPrint(pMixBuf); 1712 #endif 1481 1713 1482 1714 AUDMIXBUF_LOG(("cWritten=%RU32 (%zu bytes), rc=%Rrc\n", … … 1485 1717 return rc; 1486 1718 } 1719 -
trunk/src/VBox/Devices/Audio/AudioMixBuffer.h
r55340 r55920 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox audio: TODO 3 * VBox audio: Mixing buffer to convert audio samples to/from different 4 * rates / formats. 4 5 */ 5 6 … … 49 50 50 51 51 int audioMixBufAcquire(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToRead, PPDMAUDIOSAMPLE *ppvSamples, uint32_t *pcSamplesRead);52 inline uint32_t audioMixBufBytesToSamples(PPDMAUDIOMIXBUF pMixBuf);53 void audioMixBufDestroy(PPDMAUDIOMIXBUF pMixBuf);54 void audioMixBufFinish(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToClear);55 uint32_t audioMixBufFree(PPDMAUDIOMIXBUF pMixBuf);56 uint32_t audioMixBufFreeBytes(PPDMAUDIOMIXBUF pMixBuf);57 int audioMixBufInit(PPDMAUDIOMIXBUF pMixBuf, const char *pszName, PPDMPCMPROPS pProps, uint32_t cSamples);58 bool audioMixBufIsEmpty(PPDMAUDIOMIXBUF pMixBuf);59 int audioMixBufLinkTo(PPDMAUDIOMIXBUF pMixBuf, PPDMAUDIOMIXBUF pParent);60 uint32_t audioMixBufMixed(PPDMAUDIOMIXBUF pMixBuf);61 int audioMixBufMixToChildren(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamples, uint32_t *pcProcessed);62 int audioMixBufMixToParent(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamples, uint32_t *pcProcessed);63 uint32_t audioMixBufProcessed(PPDMAUDIOMIXBUF pMixBuf);64 int audioMixBufReadAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offSamples, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead);65 int audioMixBufReadAtEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, uint32_t offSamples, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead);66 int audioMixBufReadCirc(PPDMAUDIOMIXBUF pMixBuf, void *pvBuf, uint32_t cbBuf, uint32_t *pcRead);67 int audioMixBufReadCircEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, void *pvBuf, uint32_t cbBuf, uint32_t *pcRead);68 void audioMixBufReset(PPDMAUDIOMIXBUF pMixBuf);69 void audioMixBufSetVolume(PPDMAUDIOMIXBUF pMixBuf, PPDMAUDIOVOLUME pVol);70 uint32_t audioMixBufSize(PPDMAUDIOMIXBUF pMixBuf);71 uint32_t audioMixBufSizeBytes(PPDMAUDIOMIXBUF pMixBuf);72 void audioMixBufUnlink(PPDMAUDIOMIXBUF pMixBuf);73 int audioMixBufWriteAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offSamples, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten);74 int audioMixBufWriteAtEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, uint32_t offSamples, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten);75 int audioMixBufWriteCirc(PPDMAUDIOMIXBUF pMixBuf, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten);76 int audioMixBufWriteCircEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten);52 int AudioMixBufAcquire(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToRead, PPDMAUDIOSAMPLE *ppvSamples, uint32_t *pcSamplesRead); 53 inline uint32_t AudioMixBufBytesToSamples(PPDMAUDIOMIXBUF pMixBuf); 54 void AudioMixBufDestroy(PPDMAUDIOMIXBUF pMixBuf); 55 void AudioMixBufFinish(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamplesToClear); 56 uint32_t AudioMixBufFree(PPDMAUDIOMIXBUF pMixBuf); 57 uint32_t AudioMixBufFreeBytes(PPDMAUDIOMIXBUF pMixBuf); 58 int AudioMixBufInit(PPDMAUDIOMIXBUF pMixBuf, const char *pszName, PPDMPCMPROPS pProps, uint32_t cSamples); 59 bool AudioMixBufIsEmpty(PPDMAUDIOMIXBUF pMixBuf); 60 int AudioMixBufLinkTo(PPDMAUDIOMIXBUF pMixBuf, PPDMAUDIOMIXBUF pParent); 61 uint32_t AudioMixBufMixed(PPDMAUDIOMIXBUF pMixBuf); 62 int AudioMixBufMixToChildren(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamples, uint32_t *pcProcessed); 63 int AudioMixBufMixToParent(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSamples, uint32_t *pcProcessed); 64 uint32_t AudioMixBufProcessed(PPDMAUDIOMIXBUF pMixBuf); 65 int AudioMixBufReadAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offSamples, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead); 66 int AudioMixBufReadAtEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, uint32_t offSamples, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead); 67 int AudioMixBufReadCirc(PPDMAUDIOMIXBUF pMixBuf, void *pvBuf, uint32_t cbBuf, uint32_t *pcRead); 68 int AudioMixBufReadCircEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, void *pvBuf, uint32_t cbBuf, uint32_t *pcRead); 69 void AudioMixBufReset(PPDMAUDIOMIXBUF pMixBuf); 70 void AudioMixBufSetVolume(PPDMAUDIOMIXBUF pMixBuf, PPDMAUDIOVOLUME pVol); 71 uint32_t AudioMixBufSize(PPDMAUDIOMIXBUF pMixBuf); 72 uint32_t AudioMixBufSizeBytes(PPDMAUDIOMIXBUF pMixBuf); 73 void AudioMixBufUnlink(PPDMAUDIOMIXBUF pMixBuf); 74 int AudioMixBufWriteAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offSamples, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten); 75 int AudioMixBufWriteAtEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, uint32_t offSamples, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten); 76 int AudioMixBufWriteCirc(PPDMAUDIOMIXBUF pMixBuf, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten); 77 int AudioMixBufWriteCircEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten); 77 78 78 79 #endif /* AUDIO_MIXBUF_H */ -
trunk/src/VBox/Devices/Audio/AudioMixer.cpp
r55387 r55920 41 41 42 42 43 int audioMixerAddSink(PAUDIOMIXER pMixer, const char *pszName, AUDMIXSINKDIR enmDir, PAUDMIXSINK *ppSink)43 int AudioMixerAddSink(PAUDIOMIXER pMixer, const char *pszName, AUDMIXSINKDIR enmDir, PAUDMIXSINK *ppSink) 44 44 { 45 45 AssertPtrReturn(pMixer, VERR_INVALID_POINTER); … … 86 86 } 87 87 88 int audioMixerAddStreamIn(PAUDMIXSINK pSink, PPDMIAUDIOCONNECTOR pConnector, PPDMAUDIOGSTSTRMIN pStream,88 int AudioMixerAddStreamIn(PAUDMIXSINK pSink, PPDMIAUDIOCONNECTOR pConnector, PPDMAUDIOGSTSTRMIN pStream, 89 89 uint32_t uFlags, PAUDMIXSTREAM *ppStream) 90 90 { … … 124 124 } 125 125 126 int audioMixerAddStreamOut(PAUDMIXSINK pSink, PPDMIAUDIOCONNECTOR pConnector, PPDMAUDIOGSTSTRMOUT pStream,126 int AudioMixerAddStreamOut(PAUDMIXSINK pSink, PPDMIAUDIOCONNECTOR pConnector, PPDMAUDIOGSTSTRMOUT pStream, 127 127 uint32_t uFlags, PAUDMIXSTREAM *ppStream) 128 128 { … … 162 162 } 163 163 164 int audioMixerControlStream(PAUDIOMIXER pMixer, PAUDMIXSTREAM pHandle)164 int AudioMixerControlStream(PAUDIOMIXER pMixer, PAUDMIXSTREAM pHandle) 165 165 { 166 166 return VERR_NOT_IMPLEMENTED; 167 167 } 168 168 169 int audioMixerCreate(const char *pszName, uint32_t uFlags, PAUDIOMIXER *ppMixer)169 int AudioMixerCreate(const char *pszName, uint32_t uFlags, PAUDIOMIXER *ppMixer) 170 170 { 171 171 AssertPtrReturn(pszName, VERR_INVALID_POINTER); … … 205 205 } 206 206 207 void audioMixerDestroy(PAUDIOMIXER pMixer)207 void AudioMixerDestroy(PAUDIOMIXER pMixer) 208 208 { 209 209 if (pMixer) … … 217 217 bool fLast = RTListNodeIsLast(&pMixer->lstSinks, &pSink->Node); 218 218 219 audioMixerRemoveSink(pMixer, pSink);219 AudioMixerRemoveSink(pMixer, pSink); 220 220 221 221 if (fLast) … … 253 253 } 254 254 255 uint32_t audioMixerGetStreamCount(PAUDIOMIXER pMixer)255 uint32_t AudioMixerGetStreamCount(PAUDIOMIXER pMixer) 256 256 { 257 257 AssertPtrReturn(pMixer, 0); … … 266 266 } 267 267 268 void audioMixerInvalidate(PAUDIOMIXER pMixer)268 void AudioMixerInvalidate(PAUDIOMIXER pMixer) 269 269 { 270 270 AssertPtrReturnVoid(pMixer); … … 281 281 } 282 282 283 int audioMixerProcessSinkIn(PAUDMIXSINK pSink, AUDMIXOP enmOp, void *pvBuf, uint32_t cbBuf, uint32_t *pcbProcessed)283 int AudioMixerProcessSinkIn(PAUDMIXSINK pSink, AUDMIXOP enmOp, void *pvBuf, uint32_t cbBuf, uint32_t *pcbProcessed) 284 284 { 285 285 AssertPtrReturn(pSink, VERR_INVALID_POINTER); … … 344 344 } 345 345 346 int audioMixerProcessSinkOut(PAUDMIXSINK pSink, AUDMIXOP enmOp, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbProcessed)346 int AudioMixerProcessSinkOut(PAUDMIXSINK pSink, AUDMIXOP enmOp, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbProcessed) 347 347 { 348 348 return VERR_NOT_IMPLEMENTED; 349 349 } 350 350 351 void audioMixerRemoveSink(PAUDIOMIXER pMixer, PAUDMIXSINK pSink)351 void AudioMixerRemoveSink(PAUDIOMIXER pMixer, PAUDMIXSINK pSink) 352 352 { 353 353 AssertPtrReturnVoid(pMixer); … … 361 361 bool fLast = RTListNodeIsLast(&pSink->lstStreams, &pStream->Node); 362 362 363 audioMixerRemoveStream(pSink, pStream);363 AudioMixerRemoveStream(pSink, pStream); 364 364 365 365 if (fLast) … … 381 381 } 382 382 383 void audioMixerRemoveStream(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream)383 void AudioMixerRemoveStream(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream) 384 384 { 385 385 AssertPtrReturnVoid(pSink); … … 400 400 } 401 401 402 int audioMixerSetDeviceFormat(PAUDIOMIXER pMixer, PPDMAUDIOSTREAMCFG pCfg)402 int AudioMixerSetDeviceFormat(PAUDIOMIXER pMixer, PPDMAUDIOSTREAMCFG pCfg) 403 403 { 404 404 AssertPtrReturn(pMixer, VERR_INVALID_POINTER); … … 438 438 { 439 439 if (fOut) 440 audioMixBufSetVolume(&pStream->pOut->MixBuf, &volSink);440 AudioMixBufSetVolume(&pStream->pOut->MixBuf, &volSink); 441 441 else 442 audioMixBufSetVolume(&pStream->pIn->MixBuf, &volSink);442 AudioMixBufSetVolume(&pStream->pIn->MixBuf, &volSink); 443 443 } 444 444 … … 447 447 448 448 /** Set the master volume of the mixer. */ 449 int audioMixerSetMasterVolume(PAUDIOMIXER pMixer, PPDMAUDIOVOLUME pVol)449 int AudioMixerSetMasterVolume(PAUDIOMIXER pMixer, PPDMAUDIOVOLUME pVol) 450 450 { 451 451 AssertPtrReturn(pMixer, VERR_INVALID_POINTER); … … 458 458 pMixer->VolMaster.fMuted, pMixer->VolMaster.uLeft, pMixer->VolMaster.uRight)); 459 459 460 audioMixerInvalidate(pMixer);460 AudioMixerInvalidate(pMixer); 461 461 return VINF_SUCCESS; 462 462 } 463 463 464 464 /** Set the volume of an individual sink. */ 465 int audioMixerSetSinkVolume(PAUDMIXSINK pSink, PPDMAUDIOVOLUME pVol)465 int AudioMixerSetSinkVolume(PAUDMIXSINK pSink, PPDMAUDIOVOLUME pVol) 466 466 { 467 467 AssertPtrReturn(pSink, VERR_INVALID_POINTER); -
trunk/src/VBox/Devices/Audio/AudioMixer.h
r55340 r55920 92 92 93 93 94 int audioMixerAddSink(PAUDIOMIXER pMixer, const char *pszName, AUDMIXSINKDIR enmDir, PAUDMIXSINK *ppSink);95 int audioMixerAddStreamIn(PAUDMIXSINK pSink, PPDMIAUDIOCONNECTOR pConnector, PPDMAUDIOGSTSTRMIN pStream, uint32_t uFlags, PAUDMIXSTREAM *ppStream);96 int audioMixerAddStreamOut(PAUDMIXSINK pSink, PPDMIAUDIOCONNECTOR pConnector, PPDMAUDIOGSTSTRMOUT pStream, uint32_t uFlags, PAUDMIXSTREAM *ppStream);97 int audioMixerControlStream(AUDMIXSTREAM pHandle); /** @todo Implement me. */98 int audioMixerCreate(const char *pszName, uint32_t uFlags, PAUDIOMIXER *ppMixer);99 void audioMixerDestroy(PAUDIOMIXER pMixer);100 uint32_t audioMixerGetStreamCount(PAUDIOMIXER pMixer);101 void audioMixerInvalidate(PAUDIOMIXER pMixer);102 int audioMixerProcessSinkIn(PAUDMIXSINK pSink, AUDMIXOP enmOp, void *pvBuf, uint32_t cbBuf, uint32_t *pcbProcessed);103 int audioMixerProcessSinkOut(PAUDMIXSINK pSink, AUDMIXOP enmOp, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbProcessed);104 void audioMixerRemoveSink(PAUDIOMIXER pMixer, PAUDMIXSINK pSink);105 void audioMixerRemoveStream(PAUDMIXSINK pMixer, PAUDMIXSTREAM pStream);106 int audioMixerSetDeviceFormat(PAUDIOMIXER pMixer, PPDMAUDIOSTREAMCFG pCfg);107 int audioMixerSetMasterVolume(PAUDIOMIXER pMixer, PPDMAUDIOVOLUME pVol);108 int audioMixerSetSinkVolume(PAUDMIXSINK pSink, PPDMAUDIOVOLUME pVol);94 int AudioMixerAddSink(PAUDIOMIXER pMixer, const char *pszName, AUDMIXSINKDIR enmDir, PAUDMIXSINK *ppSink); 95 int AudioMixerAddStreamIn(PAUDMIXSINK pSink, PPDMIAUDIOCONNECTOR pConnector, PPDMAUDIOGSTSTRMIN pStream, uint32_t uFlags, PAUDMIXSTREAM *ppStream); 96 int AudioMixerAddStreamOut(PAUDMIXSINK pSink, PPDMIAUDIOCONNECTOR pConnector, PPDMAUDIOGSTSTRMOUT pStream, uint32_t uFlags, PAUDMIXSTREAM *ppStream); 97 int AudioMixerControlStream(AUDMIXSTREAM pHandle); /** @todo Implement me. */ 98 int AudioMixerCreate(const char *pszName, uint32_t uFlags, PAUDIOMIXER *ppMixer); 99 void AudioMixerDestroy(PAUDIOMIXER pMixer); 100 uint32_t AudioMixerGetStreamCount(PAUDIOMIXER pMixer); 101 void AudioMixerInvalidate(PAUDIOMIXER pMixer); 102 int AudioMixerProcessSinkIn(PAUDMIXSINK pSink, AUDMIXOP enmOp, void *pvBuf, uint32_t cbBuf, uint32_t *pcbProcessed); 103 int AudioMixerProcessSinkOut(PAUDMIXSINK pSink, AUDMIXOP enmOp, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbProcessed); 104 void AudioMixerRemoveSink(PAUDIOMIXER pMixer, PAUDMIXSINK pSink); 105 void AudioMixerRemoveStream(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream); 106 int AudioMixerSetDeviceFormat(PAUDIOMIXER pMixer, PPDMAUDIOSTREAMCFG pCfg); 107 int AudioMixerSetMasterVolume(PAUDIOMIXER pMixer, PPDMAUDIOVOLUME pVol); 108 int AudioMixerSetSinkVolume(PAUDMIXSINK pSink, PPDMAUDIOVOLUME pVol); 109 109 110 110 #endif /* AUDIO_MIXER_H */ -
trunk/src/VBox/Devices/Audio/DevIchAc97.cpp
r55430 r55920 582 582 if (rc == VINF_SUCCESS) /* Note: Could return VWRN_ALREADY_EXISTS. */ 583 583 { 584 audioMixerRemoveStream(pThis->pSinkLineIn, pDrv->LineIn.phStrmIn);585 rc = audioMixerAddStreamIn(pThis->pSinkLineIn,584 AudioMixerRemoveStream(pThis->pSinkLineIn, pDrv->LineIn.phStrmIn); 585 rc = AudioMixerAddStreamIn(pThis->pSinkLineIn, 586 586 pDrv->pConnector, pDrv->LineIn.pStrmIn, 587 587 0 /* uFlags */, … … 609 609 if (rc == VINF_SUCCESS) /* Note: Could return VWRN_ALREADY_EXISTS. */ 610 610 { 611 audioMixerRemoveStream(pThis->pSinkOutput, pDrv->Out.phStrmOut);612 rc = audioMixerAddStreamOut(pThis->pSinkOutput,611 AudioMixerRemoveStream(pThis->pSinkOutput, pDrv->Out.phStrmOut); 612 rc = AudioMixerAddStreamOut(pThis->pSinkOutput, 613 613 pDrv->pConnector, pDrv->Out.pStrmOut, 614 614 0 /* uFlags */, … … 637 637 if (rc == VINF_SUCCESS) /* Note: Could return VWRN_ALREADY_EXISTS. */ 638 638 { 639 audioMixerRemoveStream(pThis->pSinkMicIn, pDrv->MicIn.phStrmIn);640 rc = audioMixerAddStreamIn(pThis->pSinkMicIn,639 AudioMixerRemoveStream(pThis->pSinkMicIn, pDrv->MicIn.phStrmIn); 640 rc = AudioMixerAddStreamIn(pThis->pSinkMicIn, 641 641 pDrv->pConnector, pDrv->MicIn.pStrmIn, 642 642 0 /* uFlags */, … … 665 665 { 666 666 pDrv->pConnector->pfnCloseIn(pDrv->pConnector, pDrv->LineIn.pStrmIn); 667 audioMixerRemoveStream(pThis->pSinkLineIn, pDrv->LineIn.phStrmIn);667 AudioMixerRemoveStream(pThis->pSinkLineIn, pDrv->LineIn.phStrmIn); 668 668 669 669 pDrv->LineIn.pStrmIn = NULL; … … 680 680 { 681 681 pDrv->pConnector->pfnCloseOut(pDrv->pConnector, pDrv->Out.pStrmOut); 682 audioMixerRemoveStream(pThis->pSinkOutput, pDrv->Out.phStrmOut);682 AudioMixerRemoveStream(pThis->pSinkOutput, pDrv->Out.phStrmOut); 683 683 684 684 pDrv->Out.pStrmOut = NULL; … … 695 695 { 696 696 pDrv->pConnector->pfnCloseIn(pDrv->pConnector, pDrv->MicIn.pStrmIn); 697 audioMixerRemoveStream(pThis->pSinkMicIn, pDrv->MicIn.phStrmIn);697 AudioMixerRemoveStream(pThis->pSinkMicIn, pDrv->MicIn.phStrmIn); 698 698 699 699 pDrv->MicIn.pStrmIn = NULL; … … 713 713 } 714 714 715 audioMixerInvalidate(pThis->pMixer);715 AudioMixerInvalidate(pThis->pMixer); 716 716 #else 717 717 if (freq) … … 863 863 { 864 864 case PDMAUDIOMIXERCTL_VOLUME: 865 audioMixerSetMasterVolume(pThis->pMixer, &vol);865 AudioMixerSetMasterVolume(pThis->pMixer, &vol); 866 866 break; 867 867 868 868 case PDMAUDIOMIXERCTL_PCM: 869 audioMixerSetSinkVolume(pThis->pSinkOutput, &vol);869 AudioMixerSetSinkVolume(pThis->pSinkOutput, &vol); 870 870 break; 871 871 872 872 case PDMAUDIOMIXERCTL_MIC_IN: 873 audioMixerSetSinkVolume(pThis->pSinkMicIn, &vol);873 AudioMixerSetSinkVolume(pThis->pSinkMicIn, &vol); 874 874 break; 875 875 876 876 case PDMAUDIOMIXERCTL_LINE_IN: 877 audioMixerSetSinkVolume(pThis->pSinkLineIn, &vol);877 AudioMixerSetSinkVolume(pThis->pSinkLineIn, &vol); 878 878 break; 879 879 … … 982 982 if (pThis->pMixer) 983 983 { 984 audioMixerDestroy(pThis->pMixer);984 AudioMixerDestroy(pThis->pMixer); 985 985 pThis->pMixer = NULL; 986 986 } 987 987 988 int rc2 = audioMixerCreate("AC'97 Mixer", 0 /* uFlags */, &pThis->pMixer);988 int rc2 = AudioMixerCreate("AC'97 Mixer", 0 /* uFlags */, &pThis->pMixer); 989 989 if (RT_SUCCESS(rc2)) 990 990 { … … 996 996 streamCfg.enmEndianness = PDMAUDIOHOSTENDIANNESS; 997 997 998 rc2 = audioMixerSetDeviceFormat(pThis->pMixer, &streamCfg);998 rc2 = AudioMixerSetDeviceFormat(pThis->pMixer, &streamCfg); 999 999 AssertRC(rc2); 1000 1000 1001 1001 /* Add all required audio sinks. */ 1002 rc2 = audioMixerAddSink(pThis->pMixer, "[Playback] PCM Output",1002 rc2 = AudioMixerAddSink(pThis->pMixer, "[Playback] PCM Output", 1003 1003 AUDMIXSINKDIR_OUTPUT, &pThis->pSinkOutput); 1004 1004 AssertRC(rc2); 1005 1005 1006 rc2 = audioMixerAddSink(pThis->pMixer, "[Recording] Line In",1006 rc2 = AudioMixerAddSink(pThis->pMixer, "[Recording] Line In", 1007 1007 AUDMIXSINKDIR_INPUT, &pThis->pSinkLineIn); 1008 1008 AssertRC(rc2); 1009 1009 1010 rc2 = audioMixerAddSink(pThis->pMixer, "[Recording] Microphone In",1010 rc2 = AudioMixerAddSink(pThis->pMixer, "[Recording] Microphone In", 1011 1011 AUDMIXSINKDIR_INPUT, &pThis->pSinkMicIn); 1012 1012 AssertRC(rc2); … … 1243 1243 if (pvMixBuf) 1244 1244 { 1245 rc = audioMixerProcessSinkIn(pSink, AUDMIXOP_BLEND, pvMixBuf, cbToRead, &cbRead);1245 rc = AudioMixerProcessSinkIn(pSink, AUDMIXOP_BLEND, pvMixBuf, cbToRead, &cbRead); 1246 1246 if ( RT_SUCCESS(rc) 1247 1247 && cbRead) … … 2206 2206 if (pThis->pMixer) 2207 2207 { 2208 audioMixerDestroy(pThis->pMixer);2208 AudioMixerDestroy(pThis->pMixer); 2209 2209 pThis->pMixer = NULL; 2210 2210 } -
trunk/src/VBox/Devices/Audio/DevIchHda.cpp
r55828 r55920 2210 2210 { 2211 2211 uint32_t cbRead = 0; 2212 rc = audioMixerProcessSinkIn(pSink, AUDMIXOP_BLEND, pBdle->au8HdaBuffer, cb2Copy, &cbRead);2212 rc = AudioMixerProcessSinkIn(pSink, AUDMIXOP_BLEND, pBdle->au8HdaBuffer, cb2Copy, &cbRead); 2213 2213 if (RT_SUCCESS(rc)) 2214 2214 { … … 2475 2475 if (rc == VINF_SUCCESS) /* Note: Could return VWRN_ALREADY_EXISTS. */ 2476 2476 { 2477 audioMixerRemoveStream(pSink, pDrv->LineIn.phStrmIn);2478 rc = audioMixerAddStreamIn(pSink,2477 AudioMixerRemoveStream(pSink, pDrv->LineIn.phStrmIn); 2478 rc = AudioMixerAddStreamIn(pSink, 2479 2479 pDrv->pConnector, pDrv->LineIn.pStrmIn, 2480 2480 0 /* uFlags */, &pDrv->LineIn.phStrmIn); … … 2507 2507 if (rc == VINF_SUCCESS) /* Note: Could return VWRN_ALREADY_EXISTS. */ 2508 2508 { 2509 audioMixerRemoveStream(pThis->pSinkOutput, pDrv->Out.phStrmOut);2510 rc = audioMixerAddStreamOut(pThis->pSinkOutput,2509 AudioMixerRemoveStream(pThis->pSinkOutput, pDrv->Out.phStrmOut); 2510 rc = AudioMixerAddStreamOut(pThis->pSinkOutput, 2511 2511 pDrv->pConnector, pDrv->Out.pStrmOut, 2512 2512 0 /* uFlags */, &pDrv->Out.phStrmOut); … … 2543 2543 2544 2544 /* Set the volume. Codec already converted it to the correct range. */ 2545 audioMixerSetSinkVolume(pSink, &vol);2545 AudioMixerSetSinkVolume(pSink, &vol); 2546 2546 2547 2547 LogFlowFuncLeaveRC(rc); … … 3589 3589 if (pThis->pMixer) 3590 3590 { 3591 audioMixerDestroy(pThis->pMixer);3591 AudioMixerDestroy(pThis->pMixer); 3592 3592 pThis->pMixer = NULL; 3593 3593 } … … 3858 3858 if (RT_SUCCESS(rc)) 3859 3859 { 3860 rc = audioMixerCreate("HDA Mixer", 0 /* uFlags */, &pThis->pMixer);3860 rc = AudioMixerCreate("HDA Mixer", 0 /* uFlags */, &pThis->pMixer); 3861 3861 if (RT_SUCCESS(rc)) 3862 3862 { … … 3868 3868 streamCfg.enmEndianness = PDMAUDIOHOSTENDIANNESS; 3869 3869 3870 rc = audioMixerSetDeviceFormat(pThis->pMixer, &streamCfg);3870 rc = AudioMixerSetDeviceFormat(pThis->pMixer, &streamCfg); 3871 3871 AssertRC(rc); 3872 3872 3873 3873 /* Add all required audio sinks. */ 3874 rc = audioMixerAddSink(pThis->pMixer, "[Playback] PCM Output",3874 rc = AudioMixerAddSink(pThis->pMixer, "[Playback] PCM Output", 3875 3875 AUDMIXSINKDIR_OUTPUT, &pThis->pSinkOutput); 3876 3876 AssertRC(rc); 3877 3877 3878 rc = audioMixerAddSink(pThis->pMixer, "[Recording] Line In",3878 rc = AudioMixerAddSink(pThis->pMixer, "[Recording] Line In", 3879 3879 AUDMIXSINKDIR_INPUT, &pThis->pSinkLineIn); 3880 3880 AssertRC(rc); 3881 3881 3882 rc = audioMixerAddSink(pThis->pMixer, "[Recording] Microphone In",3882 rc = AudioMixerAddSink(pThis->pMixer, "[Recording] Microphone In", 3883 3883 AUDMIXSINKDIR_INPUT, &pThis->pSinkMicIn); 3884 3884 AssertRC(rc); … … 3886 3886 /* There is no master volume control. Set the master to max. */ 3887 3887 PDMAUDIOVOLUME vol = { false, 255, 255 }; 3888 rc = audioMixerSetMasterVolume(pThis->pMixer, &vol);3888 rc = AudioMixerSetMasterVolume(pThis->pMixer, &vol); 3889 3889 AssertRC(rc); 3890 3890 } -
trunk/src/VBox/Devices/Audio/DevSB16.cpp
r55908 r55920 1075 1075 uint8_t rvol = sb16MixRegToVol(pThis, 0x31); 1076 1076 PDMAUDIOVOLUME vol = { false, lvol, rvol }; 1077 audioMixerSetMasterVolume(pThis->pMixer, &vol);1077 AudioMixerSetMasterVolume(pThis->pMixer, &vol); 1078 1078 #else 1079 1079 int mute = 0; … … 1092 1092 uint8_t rvol = sb16MixRegToVol(pThis, 0x33); 1093 1093 PDMAUDIOVOLUME vol = { false, lvol, rvol }; 1094 audioMixerSetSinkVolume(pThis->pSinkOutput, &vol);1094 AudioMixerSetSinkVolume(pThis->pSinkOutput, &vol); 1095 1095 #else 1096 1096 int mute = 0; … … 1348 1348 if (pThis->pMixer) 1349 1349 { 1350 audioMixerDestroy(pThis->pMixer);1350 AudioMixerDestroy(pThis->pMixer); 1351 1351 pThis->pMixer = NULL; 1352 1352 } … … 1383 1383 1384 1384 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1385 int rc2 = audioMixerCreate("SB16 Mixer", 0 /* uFlags */, &pThis->pMixer);1385 int rc2 = AudioMixerCreate("SB16 Mixer", 0 /* uFlags */, &pThis->pMixer); 1386 1386 if (RT_SUCCESS(rc2)) 1387 1387 { … … 1393 1393 streamCfg.enmEndianness = PDMAUDIOHOSTENDIANNESS; 1394 1394 1395 rc2 = audioMixerSetDeviceFormat(pThis->pMixer, &streamCfg);1395 rc2 = AudioMixerSetDeviceFormat(pThis->pMixer, &streamCfg); 1396 1396 AssertRC(rc2); 1397 1397 1398 1398 /* Add all required audio sinks. */ 1399 rc2 = audioMixerAddSink(pThis->pMixer, "[Playback] PCM Output",1399 rc2 = AudioMixerAddSink(pThis->pMixer, "[Playback] PCM Output", 1400 1400 AUDMIXSINKDIR_OUTPUT, &pThis->pSinkOutput); 1401 1401 AssertRC(rc2); … … 2119 2119 if (rc2 == VINF_SUCCESS) /* Note: Could return VWRN_ALREADY_EXISTS. */ 2120 2120 { 2121 audioMixerRemoveStream(pThis->pSinkOutput, pDrv->Out.phStrmOut);2122 rc = audioMixerAddStreamOut(pThis->pSinkOutput,2121 AudioMixerRemoveStream(pThis->pSinkOutput, pDrv->Out.phStrmOut); 2122 rc = AudioMixerAddStreamOut(pThis->pSinkOutput, 2123 2123 pDrv->pConnector, pDrv->Out.pStrmOut, 2124 2124 0 /* uFlags */, … … 2138 2138 } 2139 2139 /* Ensure volume gets propagated. */ 2140 audioMixerInvalidate(pThis->pMixer);2140 AudioMixerInvalidate(pThis->pMixer); 2141 2141 2142 2142 return rc; … … 2206 2206 if (pThis->pMixer) 2207 2207 { 2208 audioMixerDestroy(pThis->pMixer);2208 AudioMixerDestroy(pThis->pMixer); 2209 2209 pThis->pMixer = NULL; 2210 2210 } -
trunk/src/VBox/Devices/Audio/DrvAudio.cpp
r55355 r55920 490 490 return VERR_NO_MEMORY; 491 491 492 rc = audioMixBufInit(&pGstStrmOut->MixBuf, pszTemp, &pGstStrmOut->Props, audioMixBufSize(&pHostStrmOut->MixBuf));492 rc = AudioMixBufInit(&pGstStrmOut->MixBuf, pszTemp, &pGstStrmOut->Props, AudioMixBufSize(&pHostStrmOut->MixBuf)); 493 493 if (RT_SUCCESS(rc)) 494 rc = audioMixBufLinkTo(&pGstStrmOut->MixBuf, &pHostStrmOut->MixBuf);494 rc = AudioMixBufLinkTo(&pGstStrmOut->MixBuf, &pHostStrmOut->MixBuf); 495 495 496 496 RTStrFree(pszTemp); … … 564 564 } 565 565 566 rc = audioMixBufInit(&pHstStrmOut->MixBuf, pszTemp, &pHstStrmOut->Props, cSamples);566 rc = AudioMixBufInit(&pHstStrmOut->MixBuf, pszTemp, &pHstStrmOut->Props, cSamples); 567 567 if (RT_SUCCESS(rc)) 568 568 { … … 742 742 return VERR_NO_MEMORY; 743 743 744 rc = audioMixBufInit(&pGstStrmIn->MixBuf, pszTemp, &pGstStrmIn->Props, audioMixBufSize(&pHstStrmIn->MixBuf));744 rc = AudioMixBufInit(&pGstStrmIn->MixBuf, pszTemp, &pGstStrmIn->Props, AudioMixBufSize(&pHstStrmIn->MixBuf)); 745 745 if (RT_SUCCESS(rc)) 746 rc = audioMixBufLinkTo(&pHstStrmIn->MixBuf, &pGstStrmIn->MixBuf);746 rc = AudioMixBufLinkTo(&pHstStrmIn->MixBuf, &pGstStrmIn->MixBuf); 747 747 748 748 RTStrFree(pszTemp); … … 816 816 } 817 817 818 rc = audioMixBufInit(&pHstStrmIn->MixBuf, pszTemp, &pHstStrmIn->Props, cSamples);818 rc = AudioMixBufInit(&pHstStrmIn->MixBuf, pszTemp, &pHstStrmIn->Props, cSamples); 819 819 if (RT_SUCCESS(rc)) 820 820 { … … 885 885 */ 886 886 uint32_t cWritten; 887 int rc = audioMixBufWriteAt(&pGstStrmOut->MixBuf, 0 /* Offset in samples */, pvBuf, cbBuf, &cWritten);887 int rc = AudioMixBufWriteAt(&pGstStrmOut->MixBuf, 0 /* Offset in samples */, pvBuf, cbBuf, &cWritten); 888 888 889 889 /* … … 895 895 && cWritten) 896 896 { 897 rc = audioMixBufMixToParent(&pGstStrmOut->MixBuf, cWritten, &cMixed);897 rc = AudioMixBufMixToParent(&pGstStrmOut->MixBuf, cWritten, &cMixed); 898 898 } 899 899 else … … 1078 1078 * so that it can start writing PCM data to us. */ 1079 1079 cbFree2 = RT_MIN(cbFree2, AUDIOMIXBUF_S2B_RATIO(&pGstStrmOut->MixBuf, 1080 audioMixBufFree(&pGstStrmOut->MixBuf)));1080 AudioMixBufFree(&pGstStrmOut->MixBuf))); 1081 1081 1082 1082 LogFlowFunc(("\t[%s] cbFree=%RU32\n", pGstStrmOut->MixBuf.pszName, cbFree2)); … … 1108 1108 { 1109 1109 cbAvailIn = RT_MAX(cbAvailIn, AUDIOMIXBUF_S2B(&pHstStrmIn->MixBuf, 1110 audioMixBufMixed(&pHstStrmIn->MixBuf)));1110 AudioMixBufMixed(&pHstStrmIn->MixBuf))); 1111 1111 1112 1112 LogFlowFunc(("\t[%s] cbFree=%RU32\n", pHstStrmIn->MixBuf.pszName, cbAvailIn)); … … 1194 1194 continue; 1195 1195 1196 if ( audioMixBufIsEmpty(&pGstStrmOut->MixBuf))1196 if (AudioMixBufIsEmpty(&pGstStrmOut->MixBuf)) 1197 1197 { 1198 1198 pGstStrmOut->State.fEmpty = true; … … 1428 1428 */ 1429 1429 uint32_t cRead; 1430 int rc = audioMixBufReadCirc(&pGstStrmIn->MixBuf,1430 int rc = AudioMixBufReadCirc(&pGstStrmIn->MixBuf, 1431 1431 pvBuf, cbBuf, &cRead); 1432 1432 if (RT_SUCCESS(rc)) 1433 1433 { 1434 audioMixBufFinish(&pGstStrmIn->MixBuf, cRead);1434 AudioMixBufFinish(&pGstStrmIn->MixBuf, cRead); 1435 1435 1436 1436 if (pcbRead) -
trunk/src/VBox/Devices/Audio/DrvAudioCommon.cpp
r55335 r55920 147 147 } 148 148 149 audioMixBufDestroy(&pGstStrmIn->MixBuf);149 AudioMixBufDestroy(&pGstStrmIn->MixBuf); 150 150 } 151 151 … … 153 153 { 154 154 AssertPtrReturnVoid(pHstStrmIn); 155 audioMixBufDestroy(&pHstStrmIn->MixBuf);155 AudioMixBufDestroy(&pHstStrmIn->MixBuf); 156 156 } 157 157 … … 167 167 } 168 168 169 audioMixBufDestroy(&pGstStrmOut->MixBuf);169 AudioMixBufDestroy(&pGstStrmOut->MixBuf); 170 170 } 171 171 … … 226 226 { 227 227 AssertPtrReturnVoid(pHstStrmOut); 228 audioMixBufDestroy(&pHstStrmOut->MixBuf);228 AudioMixBufDestroy(&pHstStrmOut->MixBuf); 229 229 } 230 230 … … 438 438 || !pGstStrmOut->State.fEmpty) 439 439 { 440 cSamples = audioMixBufMixed(&pGstStrmOut->MixBuf);440 cSamples = AudioMixBufMixed(&pGstStrmOut->MixBuf); 441 441 cMinSamplesMixed = RT_MIN(cMinSamplesMixed, cSamples); 442 442 … … 473 473 { 474 474 if ( cSamplesMin == UINT32_MAX 475 || cSamplesMin > audioMixBufSize(&pHstStrmOut->MixBuf))475 || cSamplesMin > AudioMixBufSize(&pHstStrmOut->MixBuf)) 476 476 { 477 477 LogFlowFunc(("Error: cSamplesMin=%RU32\n", cSamplesMin)); -
trunk/src/VBox/Devices/Audio/DrvHostALSAAudio.cpp
r55335 r55920 801 801 { 802 802 case SND_PCM_STATE_PREPARED: 803 cAvail = audioMixBufFree(&pHstStrmIn->MixBuf);803 cAvail = AudioMixBufFree(&pHstStrmIn->MixBuf); 804 804 break; 805 805 … … 882 882 { 883 883 uint32_t cWritten; 884 rc = audioMixBufWriteCirc(&pHstStrmIn->MixBuf,884 rc = AudioMixBufWriteCirc(&pHstStrmIn->MixBuf, 885 885 pThisStrmIn->pvBuf, AUDIOMIXBUF_S2B(&pHstStrmIn->MixBuf, cRead), 886 886 &cWritten); … … 900 900 uint32_t cProcessed = 0; 901 901 if (cWrittenTotal) 902 rc = audioMixBufMixToParent(&pHstStrmIn->MixBuf, cWrittenTotal,902 rc = AudioMixBufMixToParent(&pHstStrmIn->MixBuf, cWrittenTotal, 903 903 &cProcessed); 904 904 … … 946 946 while (cbToRead) 947 947 { 948 rc = audioMixBufReadCirc(&pHstStrmOut->MixBuf, pThisStrmOut->pvBuf, cbToRead, &cRead);948 rc = AudioMixBufReadCirc(&pHstStrmOut->MixBuf, pThisStrmOut->pvBuf, cbToRead, &cRead); 949 949 if (RT_FAILURE(rc)) 950 950 break; … … 1011 1011 uint32_t cReadTotal = AUDIOMIXBUF_B2S(&pHstStrmOut->MixBuf, cbReadTotal); 1012 1012 if (cReadTotal) 1013 audioMixBufFinish(&pHstStrmOut->MixBuf, cReadTotal);1013 AudioMixBufFinish(&pHstStrmOut->MixBuf, cReadTotal); 1014 1014 1015 1015 if (pcSamplesPlayed) -
trunk/src/VBox/Devices/Audio/DrvHostCoreAudio.cpp
r55035 r55920 1320 1320 do 1321 1321 { 1322 size_t cbBuf = audioMixBufSizeBytes(&pHstStrmIn->MixBuf);1322 size_t cbBuf = AudioMixBufSizeBytes(&pHstStrmIn->MixBuf); 1323 1323 size_t cbToWrite = RT_MIN(cbBuf, RTCircBufFree(pStreamIn->pBuf)); 1324 1324 LogFlowFunc(("cbToWrite=%zu\n", cbToWrite)); … … 1338 1338 } 1339 1339 1340 rc = audioMixBufWriteCirc(&pHstStrmIn->MixBuf, puBuf, cbToRead, &cWritten);1340 rc = AudioMixBufWriteCirc(&pHstStrmIn->MixBuf, puBuf, cbToRead, &cWritten); 1341 1341 if (RT_FAILURE(rc)) 1342 1342 break; … … 1358 1358 uint32_t cWrittenTotal = AUDIOMIXBUF_B2S(&pHstStrmIn->MixBuf, cbWrittenTotal); 1359 1359 if (cWrittenTotal) 1360 audioMixBufFinish(&pHstStrmIn->MixBuf, cWrittenTotal);1360 AudioMixBufFinish(&pHstStrmIn->MixBuf, cWrittenTotal); 1361 1361 1362 1362 LogFlowFunc(("cWrittenTotal=%RU32 (%RU32 bytes)\n", cWrittenTotal, cbWrittenTotal)); … … 1477 1477 do 1478 1478 { 1479 size_t cbBuf = RT_MIN( audioMixBufSizeBytes(&pHstStrmOut->MixBuf), pStreamOut->cbPCMBuf);1479 size_t cbBuf = RT_MIN(AudioMixBufSizeBytes(&pHstStrmOut->MixBuf), pStreamOut->cbPCMBuf); 1480 1480 size_t cbToRead = RT_MIN(cbBuf, RTCircBufFree(pStreamOut->pBuf)); 1481 1481 LogFlowFunc(("cbToRead=%zu\n", cbToRead)); … … 1487 1487 while (cbToRead) 1488 1488 { 1489 rc = audioMixBufReadCirc(&pHstStrmOut->MixBuf,1489 rc = AudioMixBufReadCirc(&pHstStrmOut->MixBuf, 1490 1490 pStreamOut->pvPCMBuf, cbToRead, &cRead); 1491 1491 if ( RT_FAILURE(rc) … … 1522 1522 uint32_t cReadTotal = AUDIOMIXBUF_B2S(&pHstStrmOut->MixBuf, cbReadTotal); 1523 1523 if (cReadTotal) 1524 audioMixBufFinish(&pHstStrmOut->MixBuf, cReadTotal);1524 AudioMixBufFinish(&pHstStrmOut->MixBuf, cReadTotal); 1525 1525 1526 1526 LogFlowFunc(("cReadTotal=%RU32 (%RU32 bytes)\n", cReadTotal, cbReadTotal)); -
trunk/src/VBox/Devices/Audio/DrvHostDSound.cpp
r55335 r55920 1167 1167 if (pv1 && cb1) 1168 1168 { 1169 rc = audioMixBufReadCirc(&pHstStrmOut->MixBuf, pv1, cb1, &cRead);1169 rc = AudioMixBufReadCirc(&pHstStrmOut->MixBuf, pv1, cb1, &cRead); 1170 1170 if (RT_SUCCESS(rc)) 1171 1171 cReadTotal += cRead; … … 1176 1176 && pv2 && cb2) 1177 1177 { 1178 rc = audioMixBufReadCirc(&pHstStrmOut->MixBuf, pv2, cb2, &cRead);1178 rc = AudioMixBufReadCirc(&pHstStrmOut->MixBuf, pv2, cb2, &cRead); 1179 1179 if (RT_SUCCESS(rc)) 1180 1180 cReadTotal += cRead; … … 1192 1192 if (cReadTotal) 1193 1193 { 1194 audioMixBufFinish(&pHstStrmOut->MixBuf, cReadTotal);1194 AudioMixBufFinish(&pHstStrmOut->MixBuf, cReadTotal); 1195 1195 rc = VINF_SUCCESS; /* Played something. */ 1196 1196 } … … 1352 1352 1353 1353 /* Using as an intermediate not circular buffer. */ 1354 audioMixBufReset(&pHstStrmIn->MixBuf);1354 AudioMixBufReset(&pHstStrmIn->MixBuf); 1355 1355 1356 1356 /* Get number of free samples in the mix buffer and check that is has free space */ 1357 uint32_t csMixFree = audioMixBufFree(&pHstStrmIn->MixBuf);1357 uint32_t csMixFree = AudioMixBufFree(&pHstStrmIn->MixBuf); 1358 1358 if (csMixFree == 0) 1359 1359 { … … 1392 1392 if (pv1 && len1) 1393 1393 { 1394 rc = audioMixBufWriteAt(&pHstStrmIn->MixBuf, 0 /* offWrite */,1394 rc = AudioMixBufWriteAt(&pHstStrmIn->MixBuf, 0 /* offWrite */, 1395 1395 pv1, cb1, &csWritten); 1396 1396 if (RT_SUCCESS(rc)) … … 1402 1402 && pv2 && len2) 1403 1403 { 1404 rc = audioMixBufWriteAt(&pHstStrmIn->MixBuf, csWrittenTotal,1404 rc = AudioMixBufWriteAt(&pHstStrmIn->MixBuf, csWrittenTotal, 1405 1405 pv2, cb2, &csWritten); 1406 1406 if (RT_SUCCESS(rc)) … … 1414 1414 { 1415 1415 /* Captured something. */ 1416 rc = audioMixBufMixToParent(&pHstStrmIn->MixBuf, csWrittenTotal,1416 rc = AudioMixBufMixToParent(&pHstStrmIn->MixBuf, csWrittenTotal, 1417 1417 &csProcessed); 1418 1418 } -
trunk/src/VBox/Devices/Audio/DrvHostNullAudio.cpp
r55649 r55920 175 175 cSamplesPlayed = csLive; 176 176 177 audioMixBufFinish(&pHstStrmOut->MixBuf, cSamplesPlayed);177 AudioMixBufFinish(&pHstStrmOut->MixBuf, cSamplesPlayed); 178 178 179 179 if (pcSamplesPlayed) -
trunk/src/VBox/Devices/Audio/DrvHostOSSAudio.cpp
r55335 r55920 366 366 { 367 367 audio_pcm_info_clear_buf(&pHstStrmOut->Props, 368 pThisStrmOut->pvPCMBuf, audioMixBufSize(&pHstStrmOut->MixBuf));368 pThisStrmOut->pvPCMBuf, AudioMixBufSize(&pHstStrmOut->MixBuf)); 369 369 370 370 mask = PCM_ENABLE_OUTPUT; … … 419 419 int rc = VINF_SUCCESS; 420 420 size_t cbToRead = RT_MIN(pThisStrmIn->cbBuf, 421 audioMixBufFreeBytes(&pHstStrmIn->MixBuf));421 AudioMixBufFreeBytes(&pHstStrmIn->MixBuf)); 422 422 423 423 LogFlowFunc(("cbToRead=%zu\n", cbToRead)); … … 466 466 { 467 467 uint32_t cWritten; 468 rc = audioMixBufWriteCirc(&pHstStrmIn->MixBuf,468 rc = AudioMixBufWriteCirc(&pHstStrmIn->MixBuf, 469 469 pThisStrmIn->pvBuf, cbRead, 470 470 &cWritten); … … 490 490 uint32_t cProcessed = 0; 491 491 if (cWrittenTotal) 492 rc = audioMixBufMixToParent(&pHstStrmIn->MixBuf, cWrittenTotal,492 rc = AudioMixBufMixToParent(&pHstStrmIn->MixBuf, cWrittenTotal, 493 493 &cProcessed); 494 494 … … 786 786 do 787 787 { 788 size_t cbBuf = audioMixBufSizeBytes(&pHstStrmOut->MixBuf);788 size_t cbBuf = AudioMixBufSizeBytes(&pHstStrmOut->MixBuf); 789 789 790 790 uint32_t cLive = drvAudioHstOutSamplesLive(pHstStrmOut, … … 861 861 while (cbToRead) 862 862 { 863 rc = audioMixBufReadCirc(&pHstStrmOut->MixBuf,863 rc = AudioMixBufReadCirc(&pHstStrmOut->MixBuf, 864 864 pThisStrmOut->pvPCMBuf, cbToRead, &cRead); 865 865 if (RT_FAILURE(rc)) … … 893 893 uint32_t cReadTotal = AUDIOMIXBUF_B2S(&pHstStrmOut->MixBuf, cbReadTotal); 894 894 if (cReadTotal) 895 audioMixBufFinish(&pHstStrmOut->MixBuf, cReadTotal);895 AudioMixBufFinish(&pHstStrmOut->MixBuf, cReadTotal); 896 896 897 897 if (pcSamplesPlayed) -
trunk/src/VBox/Devices/Audio/DrvHostPulseAudio.cpp
r55339 r55920 723 723 724 724 int rc = VINF_SUCCESS; 725 size_t cbToRead = RT_MIN(cbAvail, audioMixBufFreeBytes(&pHstStrmIn->MixBuf));725 size_t cbToRead = RT_MIN(cbAvail, AudioMixBufFreeBytes(&pHstStrmIn->MixBuf)); 726 726 727 727 LogFlowFunc(("cbToRead=%zu, cbAvail=%zu, offPeekBuf=%zu, cbPeekBuf=%zu\n", … … 763 763 { 764 764 uint32_t cWritten; 765 rc = audioMixBufWriteCirc(&pHstStrmIn->MixBuf,765 rc = AudioMixBufWriteCirc(&pHstStrmIn->MixBuf, 766 766 pThisStrmIn->pu8PeekBuf + pThisStrmIn->offPeekBuf, 767 767 cbToWrite, &cWritten); … … 796 796 uint32_t cProcessed = 0; 797 797 if (cWrittenTotal) 798 rc = audioMixBufMixToParent(&pHstStrmIn->MixBuf, cWrittenTotal,798 rc = AudioMixBufMixToParent(&pHstStrmIn->MixBuf, cWrittenTotal, 799 799 &cProcessed); 800 800 … … 852 852 while (cbToRead) 853 853 { 854 rc = audioMixBufReadCirc(&pHstStrmOut->MixBuf, pThisStrmOut->pvPCMBuf,854 rc = AudioMixBufReadCirc(&pHstStrmOut->MixBuf, pThisStrmOut->pvPCMBuf, 855 855 RT_MIN(cbToRead, pThisStrmOut->cbPCMBuf), &cRead); 856 856 if ( !cRead … … 884 884 uint32_t cReadTotal = AUDIOMIXBUF_B2S(&pHstStrmOut->MixBuf, cbReadTotal); 885 885 if (cReadTotal) 886 audioMixBufFinish(&pHstStrmOut->MixBuf, cReadTotal);886 AudioMixBufFinish(&pHstStrmOut->MixBuf, cReadTotal); 887 887 888 888 if (pcSamplesPlayed) -
trunk/src/VBox/Devices/Audio/testcase/tstAudioMixBuffer.cpp
r55495 r55920 59 59 */ 60 60 PDMAUDIOMIXBUF mb; 61 RTTESTI_CHECK_RC_OK( audioMixBufInit(&mb, "Single", &props, cBufSize));62 RTTESTI_CHECK( audioMixBufSize(&mb) == cBufSize);63 RTTESTI_CHECK(AUDIOMIXBUF_B2S(&mb, audioMixBufSizeBytes(&mb)) == cBufSize);64 RTTESTI_CHECK(AUDIOMIXBUF_S2B(&mb, audioMixBufSize(&mb)) == audioMixBufSizeBytes(&mb));65 RTTESTI_CHECK( audioMixBufFree(&mb) == cBufSize);66 RTTESTI_CHECK(AUDIOMIXBUF_S2B(&mb, audioMixBufFree(&mb)) == audioMixBufFreeBytes(&mb));61 RTTESTI_CHECK_RC_OK(AudioMixBufInit(&mb, "Single", &props, cBufSize)); 62 RTTESTI_CHECK(AudioMixBufSize(&mb) == cBufSize); 63 RTTESTI_CHECK(AUDIOMIXBUF_B2S(&mb, AudioMixBufSizeBytes(&mb)) == cBufSize); 64 RTTESTI_CHECK(AUDIOMIXBUF_S2B(&mb, AudioMixBufSize(&mb)) == AudioMixBufSizeBytes(&mb)); 65 RTTESTI_CHECK(AudioMixBufFree(&mb) == cBufSize); 66 RTTESTI_CHECK(AUDIOMIXBUF_S2B(&mb, AudioMixBufFree(&mb)) == AudioMixBufFreeBytes(&mb)); 67 67 68 68 /* … … 75 75 int64_t samples64[2] = { 0xEE, 0xFF }; 76 76 77 RTTESTI_CHECK_RC_OK( audioMixBufWriteAt(&mb, 0, &samples8, sizeof(samples8), &written));77 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 0, &samples8, sizeof(samples8), &written)); 78 78 RTTESTI_CHECK(written == 0 /* Samples */); 79 79 80 RTTESTI_CHECK_RC_OK( audioMixBufWriteAt(&mb, 0, &samples16, sizeof(samples16), &written));80 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 0, &samples16, sizeof(samples16), &written)); 81 81 RTTESTI_CHECK(written == 1 /* Samples */); 82 82 83 RTTESTI_CHECK_RC_OK( audioMixBufWriteAt(&mb, 2, &samples32, sizeof(samples32), &written));83 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 2, &samples32, sizeof(samples32), &written)); 84 84 RTTESTI_CHECK(written == 2 /* Samples */); 85 85 written_abs = 0; 86 86 87 87 /* Beyond buffer. */ 88 RTTESTI_CHECK_RC( audioMixBufWriteAt(&mb, audioMixBufSize(&mb) + 1, &samples16, sizeof(samples16),88 RTTESTI_CHECK_RC(AudioMixBufWriteAt(&mb, AudioMixBufSize(&mb) + 1, &samples16, sizeof(samples16), 89 89 &written), VERR_BUFFER_OVERFLOW); 90 90 … … 92 92 * Circular writes. 93 93 */ 94 uint32_t cToWrite = audioMixBufSize(&mb) - written_abs - 1; /* -1 as padding plus -2 samples for above. */94 uint32_t cToWrite = AudioMixBufSize(&mb) - written_abs - 1; /* -1 as padding plus -2 samples for above. */ 95 95 for (uint32_t i = 0; i < cToWrite; i++) 96 96 { 97 RTTESTI_CHECK_RC_OK( audioMixBufWriteCirc(&mb, &samples16, sizeof(samples16), &written));97 RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&mb, &samples16, sizeof(samples16), &written)); 98 98 RTTESTI_CHECK(written == 1); 99 99 } 100 RTTESTI_CHECK(! audioMixBufIsEmpty(&mb));101 RTTESTI_CHECK( audioMixBufFree(&mb) == 1);102 RTTESTI_CHECK( audioMixBufFreeBytes(&mb) == AUDIOMIXBUF_S2B(&mb, 1U));103 RTTESTI_CHECK( audioMixBufProcessed(&mb) == cToWrite + written_abs /* + last absolute write */);104 105 RTTESTI_CHECK_RC_OK( audioMixBufWriteCirc(&mb, &samples16, sizeof(samples16), &written));100 RTTESTI_CHECK(!AudioMixBufIsEmpty(&mb)); 101 RTTESTI_CHECK(AudioMixBufFree(&mb) == 1); 102 RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_S2B(&mb, 1U)); 103 RTTESTI_CHECK(AudioMixBufProcessed(&mb) == cToWrite + written_abs /* + last absolute write */); 104 105 RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&mb, &samples16, sizeof(samples16), &written)); 106 106 RTTESTI_CHECK(written == 1); 107 RTTESTI_CHECK( audioMixBufFree(&mb) == 0);108 RTTESTI_CHECK( audioMixBufFreeBytes(&mb) == AUDIOMIXBUF_S2B(&mb, 0));109 RTTESTI_CHECK( audioMixBufProcessed(&mb) == cBufSize);107 RTTESTI_CHECK(AudioMixBufFree(&mb) == 0); 108 RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_S2B(&mb, 0)); 109 RTTESTI_CHECK(AudioMixBufProcessed(&mb) == cBufSize); 110 110 111 111 /* Circular reads. */ 112 uint32_t cToRead = audioMixBufSize(&mb) - written_abs - 1;112 uint32_t cToRead = AudioMixBufSize(&mb) - written_abs - 1; 113 113 for (uint32_t i = 0; i < cToWrite; i++) 114 114 { 115 RTTESTI_CHECK_RC_OK( audioMixBufReadCirc(&mb, &samples16, sizeof(samples16), &read));115 RTTESTI_CHECK_RC_OK(AudioMixBufReadCirc(&mb, &samples16, sizeof(samples16), &read)); 116 116 RTTESTI_CHECK(read == 1); 117 audioMixBufFinish(&mb, read);118 } 119 RTTESTI_CHECK(! audioMixBufIsEmpty(&mb));120 RTTESTI_CHECK( audioMixBufFree(&mb) == audioMixBufSize(&mb) - written_abs - 1);121 RTTESTI_CHECK( audioMixBufFreeBytes(&mb) == AUDIOMIXBUF_S2B(&mb, cBufSize - written_abs - 1));122 RTTESTI_CHECK( audioMixBufProcessed(&mb) == cBufSize - cToRead + written_abs);123 124 RTTESTI_CHECK_RC_OK( audioMixBufReadCirc(&mb, &samples16, sizeof(samples16), &read));117 AudioMixBufFinish(&mb, read); 118 } 119 RTTESTI_CHECK(!AudioMixBufIsEmpty(&mb)); 120 RTTESTI_CHECK(AudioMixBufFree(&mb) == AudioMixBufSize(&mb) - written_abs - 1); 121 RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_S2B(&mb, cBufSize - written_abs - 1)); 122 RTTESTI_CHECK(AudioMixBufProcessed(&mb) == cBufSize - cToRead + written_abs); 123 124 RTTESTI_CHECK_RC_OK(AudioMixBufReadCirc(&mb, &samples16, sizeof(samples16), &read)); 125 125 RTTESTI_CHECK(read == 1); 126 audioMixBufFinish(&mb, read);127 RTTESTI_CHECK( audioMixBufFree(&mb) == cBufSize - written_abs);128 RTTESTI_CHECK( audioMixBufFreeBytes(&mb) == AUDIOMIXBUF_S2B(&mb, cBufSize - written_abs));129 RTTESTI_CHECK( audioMixBufProcessed(&mb) == written_abs);130 131 audioMixBufDestroy(&mb);126 AudioMixBufFinish(&mb, read); 127 RTTESTI_CHECK(AudioMixBufFree(&mb) == cBufSize - written_abs); 128 RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_S2B(&mb, cBufSize - written_abs)); 129 RTTESTI_CHECK(AudioMixBufProcessed(&mb) == written_abs); 130 131 AudioMixBufDestroy(&mb); 132 132 133 133 return RTTestSubErrorCount(hTest) ? VERR_GENERAL_FAILURE : VINF_SUCCESS; … … 153 153 154 154 PDMAUDIOMIXBUF parent; 155 RTTESTI_CHECK_RC_OK( audioMixBufInit(&parent, "Parent", &props, cBufSize));155 RTTESTI_CHECK_RC_OK(AudioMixBufInit(&parent, "Parent", &props, cBufSize)); 156 156 157 157 PDMAUDIOSTREAMCFG cfg_c1 = /* Upmixing to parent */ … … 167 167 168 168 PDMAUDIOMIXBUF child1; 169 RTTESTI_CHECK_RC_OK( audioMixBufInit(&child1, "Child1", &props, cBufSize));170 RTTESTI_CHECK_RC_OK( audioMixBufLinkTo(&child1, &parent));169 RTTESTI_CHECK_RC_OK(AudioMixBufInit(&child1, "Child1", &props, cBufSize)); 170 RTTESTI_CHECK_RC_OK(AudioMixBufLinkTo(&child1, &parent)); 171 171 172 172 PDMAUDIOSTREAMCFG cfg_c2 = /* Downmixing to parent */ … … 182 182 183 183 PDMAUDIOMIXBUF child2; 184 RTTESTI_CHECK_RC_OK( audioMixBufInit(&child2, "Child2", &props, cBufSize));185 RTTESTI_CHECK_RC_OK( audioMixBufLinkTo(&child2, &parent));184 RTTESTI_CHECK_RC_OK(AudioMixBufInit(&child2, "Child2", &props, cBufSize)); 185 RTTESTI_CHECK_RC_OK(AudioMixBufLinkTo(&child2, &parent)); 186 186 187 187 /* … … 208 208 { 209 209 RTTestPrintf(hTest, RTTESTLVL_DEBUG, "i=%RU32\n", i); 210 RTTESTI_CHECK_RC_OK_BREAK( audioMixBufWriteAt(&child1, 0, &samples, sizeof(samples), &written));210 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufWriteAt(&child1, 0, &samples, sizeof(samples), &written)); 211 211 RTTESTI_CHECK_MSG_BREAK(written == cSamplesChild1, ("Child1: Expected %RU32 written samples, got %RU32\n", cSamplesChild1, written)); 212 RTTESTI_CHECK_RC_OK_BREAK( audioMixBufMixToParent(&child1, written, &mixed));213 temp = audioMixBufProcessed(&parent) - audioMixBufMixed(&child2);214 RTTESTI_CHECK_MSG_BREAK( audioMixBufMixed(&child1) == temp, ("Child1: Expected %RU32 mixed samples, got %RU32\n", audioMixBufMixed(&child1), temp));215 216 RTTESTI_CHECK_RC_OK_BREAK( audioMixBufWriteAt(&child2, 0, &samples, sizeof(samples), &written));212 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufMixToParent(&child1, written, &mixed)); 213 temp = AudioMixBufProcessed(&parent) - AudioMixBufMixed(&child2); 214 RTTESTI_CHECK_MSG_BREAK(AudioMixBufMixed(&child1) == temp, ("Child1: Expected %RU32 mixed samples, got %RU32\n", AudioMixBufMixed(&child1), temp)); 215 216 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufWriteAt(&child2, 0, &samples, sizeof(samples), &written)); 217 217 RTTESTI_CHECK_MSG_BREAK(written == cSamplesChild2, ("Child2: Expected %RU32 written samples, got %RU32\n", cSamplesChild2, written)); 218 RTTESTI_CHECK_RC_OK_BREAK( audioMixBufMixToParent(&child2, written, &mixed));219 temp = audioMixBufProcessed(&parent) - audioMixBufMixed(&child1);220 RTTESTI_CHECK_MSG_BREAK( audioMixBufMixed(&child2) == temp, ("Child2: Expected %RU32 mixed samples, got %RU32\n", audioMixBufMixed(&child2), temp));221 } 222 223 RTTESTI_CHECK( audioMixBufProcessed(&parent) == audioMixBufMixed(&child1) + audioMixBufMixed(&child2));218 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufMixToParent(&child2, written, &mixed)); 219 temp = AudioMixBufProcessed(&parent) - AudioMixBufMixed(&child1); 220 RTTESTI_CHECK_MSG_BREAK(AudioMixBufMixed(&child2) == temp, ("Child2: Expected %RU32 mixed samples, got %RU32\n", AudioMixBufMixed(&child2), temp)); 221 } 222 223 RTTESTI_CHECK(AudioMixBufProcessed(&parent) == AudioMixBufMixed(&child1) + AudioMixBufMixed(&child2)); 224 224 225 225 for (;;) 226 226 { 227 RTTESTI_CHECK_RC_OK_BREAK( audioMixBufReadCirc(&parent, pvBuf, cbBuf, &read));227 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, pvBuf, cbBuf, &read)); 228 228 if (!read) 229 229 break; 230 audioMixBufFinish(&parent, read);231 } 232 233 RTTESTI_CHECK( audioMixBufProcessed(&parent) == 0);234 RTTESTI_CHECK( audioMixBufMixed(&child1) == 0);235 RTTESTI_CHECK( audioMixBufMixed(&child2) == 0);236 237 audioMixBufDestroy(&parent);238 audioMixBufDestroy(&child1);239 audioMixBufDestroy(&child2);230 AudioMixBufFinish(&parent, read); 231 } 232 233 RTTESTI_CHECK(AudioMixBufProcessed(&parent) == 0); 234 RTTESTI_CHECK(AudioMixBufMixed(&child1) == 0); 235 RTTESTI_CHECK(AudioMixBufMixed(&child2) == 0); 236 237 AudioMixBufDestroy(&parent); 238 AudioMixBufDestroy(&child1); 239 AudioMixBufDestroy(&child2); 240 240 241 241 return RTTestSubErrorCount(hTest) ? VERR_GENERAL_FAILURE : VINF_SUCCESS; … … 264 264 265 265 PDMAUDIOMIXBUF parent; 266 RTTESTI_CHECK_RC_OK( audioMixBufInit(&parent, "Parent", &props, cBufSize));266 RTTESTI_CHECK_RC_OK(AudioMixBufInit(&parent, "Parent", &props, cBufSize)); 267 267 268 268 /* Child uses half the sample rate; that ensures the mixing engine can't … … 285 285 286 286 PDMAUDIOMIXBUF child; 287 RTTESTI_CHECK_RC_OK( audioMixBufInit(&child, "Child", &props, cBufSize));288 RTTESTI_CHECK_RC_OK( audioMixBufLinkTo(&child, &parent));287 RTTESTI_CHECK_RC_OK(AudioMixBufInit(&child, "Child", &props, cBufSize)); 288 RTTESTI_CHECK_RC_OK(AudioMixBufLinkTo(&child, &parent)); 289 289 290 290 /* 8-bit unsigned samples. Often used with SB16 device. */ … … 307 307 /**** 8-bit unsigned samples ****/ 308 308 RTTestPrintf(hTest, RTTESTLVL_DEBUG, "Conversion test %uHz %uch 8-bit\n", cfg_c.uHz, cfg_c.cChannels); 309 RTTESTI_CHECK_RC_OK( audioMixBufWriteAt(&child, 0, &samples, sizeof(samples), &written));309 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&child, 0, &samples, sizeof(samples), &written)); 310 310 RTTESTI_CHECK_MSG(written == cSamplesChild, ("Child: Expected %RU32 written samples, got %RU32\n", cSamplesChild, written)); 311 RTTESTI_CHECK_RC_OK( audioMixBufMixToParent(&child, written, &mixed));312 temp = audioMixBufProcessed(&parent);313 RTTESTI_CHECK_MSG( audioMixBufMixed(&child) == temp, ("Child: Expected %RU32 mixed samples, got %RU32\n", audioMixBufMixed(&child), temp));314 315 RTTESTI_CHECK( audioMixBufProcessed(&parent) == audioMixBufMixed(&child));311 RTTESTI_CHECK_RC_OK(AudioMixBufMixToParent(&child, written, &mixed)); 312 temp = AudioMixBufProcessed(&parent); 313 RTTESTI_CHECK_MSG(AudioMixBufMixed(&child) == temp, ("Child: Expected %RU32 mixed samples, got %RU32\n", AudioMixBufMixed(&child), temp)); 314 315 RTTESTI_CHECK(AudioMixBufProcessed(&parent) == AudioMixBufMixed(&child)); 316 316 317 317 for (;;) 318 318 { 319 RTTESTI_CHECK_RC_OK_BREAK( audioMixBufReadCirc(&parent, achBuf, cbBuf, &read));319 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, achBuf, cbBuf, &read)); 320 320 if (!read) 321 321 break; 322 322 cSamplesRead += read; 323 audioMixBufFinish(&parent, read);323 AudioMixBufFinish(&parent, read); 324 324 } 325 325 RTTESTI_CHECK_MSG(cSamplesRead == cSamplesParent, ("Parent: Expected %RU32 mixed samples, got %RU32\n", cSamplesParent, cSamplesRead)); … … 337 337 } 338 338 339 RTTESTI_CHECK( audioMixBufProcessed(&parent) == 0);340 RTTESTI_CHECK( audioMixBufMixed(&child) == 0);341 342 audioMixBufDestroy(&parent);343 audioMixBufDestroy(&child);339 RTTESTI_CHECK(AudioMixBufProcessed(&parent) == 0); 340 RTTESTI_CHECK(AudioMixBufMixed(&child) == 0); 341 342 AudioMixBufDestroy(&parent); 343 AudioMixBufDestroy(&child); 344 344 345 345 return RTTestSubErrorCount(hTest) ? VERR_GENERAL_FAILURE : VINF_SUCCESS; … … 368 368 369 369 PDMAUDIOMIXBUF parent; 370 RTTESTI_CHECK_RC_OK( audioMixBufInit(&parent, "Parent", &props, cBufSize));370 RTTESTI_CHECK_RC_OK(AudioMixBufInit(&parent, "Parent", &props, cBufSize)); 371 371 372 372 PDMAUDIOSTREAMCFG cfg_c = /* Upmixing to parent */ … … 382 382 383 383 PDMAUDIOMIXBUF child; 384 RTTESTI_CHECK_RC_OK( audioMixBufInit(&child, "Child", &props, cBufSize));385 RTTESTI_CHECK_RC_OK( audioMixBufLinkTo(&child, &parent));384 RTTESTI_CHECK_RC_OK(AudioMixBufInit(&child, "Child", &props, cBufSize)); 385 RTTESTI_CHECK_RC_OK(AudioMixBufLinkTo(&child, &parent)); 386 386 387 387 /* 16-bit signed. More or less exclusively used as output, and usually as input, too. */ … … 404 404 /**** 16-bit signed samples ****/ 405 405 RTTestPrintf(hTest, RTTESTLVL_DEBUG, "Conversion test %uHz %uch 16-bit\n", cfg_c.uHz, cfg_c.cChannels); 406 RTTESTI_CHECK_RC_OK( audioMixBufWriteAt(&child, 0, &samples, sizeof(samples), &written));406 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&child, 0, &samples, sizeof(samples), &written)); 407 407 RTTESTI_CHECK_MSG(written == cSamplesChild, ("Child: Expected %RU32 written samples, got %RU32\n", cSamplesChild, written)); 408 RTTESTI_CHECK_RC_OK( audioMixBufMixToParent(&child, written, &mixed));409 temp = audioMixBufProcessed(&parent);410 RTTESTI_CHECK_MSG( audioMixBufMixed(&child) == temp, ("Child: Expected %RU32 mixed samples, got %RU32\n", audioMixBufMixed(&child), temp));411 412 RTTESTI_CHECK( audioMixBufProcessed(&parent) == audioMixBufMixed(&child));408 RTTESTI_CHECK_RC_OK(AudioMixBufMixToParent(&child, written, &mixed)); 409 temp = AudioMixBufProcessed(&parent); 410 RTTESTI_CHECK_MSG(AudioMixBufMixed(&child) == temp, ("Child: Expected %RU32 mixed samples, got %RU32\n", AudioMixBufMixed(&child), temp)); 411 412 RTTESTI_CHECK(AudioMixBufProcessed(&parent) == AudioMixBufMixed(&child)); 413 413 414 414 for (;;) 415 415 { 416 RTTESTI_CHECK_RC_OK_BREAK( audioMixBufReadCirc(&parent, achBuf, cbBuf, &read));416 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, achBuf, cbBuf, &read)); 417 417 if (!read) 418 418 break; 419 419 cSamplesRead += read; 420 audioMixBufFinish(&parent, read);420 AudioMixBufFinish(&parent, read); 421 421 } 422 422 RTTESTI_CHECK_MSG(cSamplesRead == cSamplesParent, ("Parent: Expected %RU32 mixed samples, got %RU32\n", cSamplesParent, cSamplesRead)); … … 434 434 } 435 435 436 RTTESTI_CHECK( audioMixBufProcessed(&parent) == 0);437 RTTESTI_CHECK( audioMixBufMixed(&child) == 0);438 439 audioMixBufDestroy(&parent);440 audioMixBufDestroy(&child);436 RTTESTI_CHECK(AudioMixBufProcessed(&parent) == 0); 437 RTTESTI_CHECK(AudioMixBufMixed(&child) == 0); 438 439 AudioMixBufDestroy(&parent); 440 AudioMixBufDestroy(&child); 441 441 442 442 return RTTestSubErrorCount(hTest) ? VERR_GENERAL_FAILURE : VINF_SUCCESS; … … 467 467 PDMAUDIOVOLUME vol = { false, 0, 0 }; /* Not muted. */ 468 468 PDMAUDIOMIXBUF parent; 469 RTTESTI_CHECK_RC_OK( audioMixBufInit(&parent, "Parent", &props, cBufSize));469 RTTESTI_CHECK_RC_OK(AudioMixBufInit(&parent, "Parent", &props, cBufSize)); 470 470 471 471 PDMAUDIOMIXBUF child; 472 RTTESTI_CHECK_RC_OK( audioMixBufInit(&child, "Child", &props, cBufSize));473 RTTESTI_CHECK_RC_OK( audioMixBufLinkTo(&child, &parent));472 RTTESTI_CHECK_RC_OK(AudioMixBufInit(&child, "Child", &props, cBufSize)); 473 RTTESTI_CHECK_RC_OK(AudioMixBufLinkTo(&child, &parent)); 474 474 475 475 /* A few 16-bit signed samples. */ … … 497 497 /* 1) Full volume/0dB attenuation (255). */ 498 498 vol.uLeft = vol.uRight = 255; 499 audioMixBufSetVolume(&child, &vol);500 501 RTTESTI_CHECK_RC_OK( audioMixBufWriteAt(&child, 0, &samples, sizeof(samples), &written));499 AudioMixBufSetVolume(&child, &vol); 500 501 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&child, 0, &samples, sizeof(samples), &written)); 502 502 RTTESTI_CHECK_MSG(written == cSamplesChild, ("Child: Expected %RU32 written samples, got %RU32\n", cSamplesChild, written)); 503 RTTESTI_CHECK_RC_OK( audioMixBufMixToParent(&child, written, &mixed));503 RTTESTI_CHECK_RC_OK(AudioMixBufMixToParent(&child, written, &mixed)); 504 504 505 505 cSamplesRead = 0; 506 506 for (;;) 507 507 { 508 RTTESTI_CHECK_RC_OK_BREAK( audioMixBufReadCirc(&parent, achBuf, cbBuf, &read));508 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, achBuf, cbBuf, &read)); 509 509 if (!read) 510 510 break; 511 511 cSamplesRead += read; 512 audioMixBufFinish(&parent, read);512 AudioMixBufFinish(&parent, read); 513 513 } 514 514 RTTESTI_CHECK_MSG(cSamplesRead == cSamplesParent, ("Parent: Expected %RU32 mixed samples, got %RU32\n", cSamplesParent, cSamplesRead)); … … 524 524 ++pDst16; 525 525 } 526 audioMixBufReset(&child);526 AudioMixBufReset(&child); 527 527 528 528 /* 2) Half volume/-6dB attenuation (16 steps down). */ 529 529 vol.uLeft = vol.uRight = 255 - 16; 530 audioMixBufSetVolume(&child, &vol);531 532 RTTESTI_CHECK_RC_OK( audioMixBufWriteAt(&child, 0, &samples, sizeof(samples), &written));530 AudioMixBufSetVolume(&child, &vol); 531 532 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&child, 0, &samples, sizeof(samples), &written)); 533 533 RTTESTI_CHECK_MSG(written == cSamplesChild, ("Child: Expected %RU32 written samples, got %RU32\n", cSamplesChild, written)); 534 RTTESTI_CHECK_RC_OK( audioMixBufMixToParent(&child, written, &mixed));534 RTTESTI_CHECK_RC_OK(AudioMixBufMixToParent(&child, written, &mixed)); 535 535 536 536 cSamplesRead = 0; 537 537 for (;;) 538 538 { 539 RTTESTI_CHECK_RC_OK_BREAK( audioMixBufReadCirc(&parent, achBuf, cbBuf, &read));539 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, achBuf, cbBuf, &read)); 540 540 if (!read) 541 541 break; 542 542 cSamplesRead += read; 543 audioMixBufFinish(&parent, read);543 AudioMixBufFinish(&parent, read); 544 544 } 545 545 RTTESTI_CHECK_MSG(cSamplesRead == cSamplesParent, ("Parent: Expected %RU32 mixed samples, got %RU32\n", cSamplesParent, cSamplesRead)); … … 557 557 } 558 558 559 audioMixBufDestroy(&parent);560 audioMixBufDestroy(&child);559 AudioMixBufDestroy(&parent); 560 AudioMixBufDestroy(&child); 561 561 562 562 return RTTestSubErrorCount(hTest) ? VERR_GENERAL_FAILURE : VINF_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.