Changeset 68132 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Jul 27, 2017 8:15:43 AM (7 years ago)
- Location:
- trunk/src/VBox/Devices/Audio
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/AudioMixBuffer.cpp
r67742 r68132 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox audio: Audio mixing buffer for converting reading/writing audio 4 * samples. 3 * VBox audio: Audio mixing buffer for converting reading/writing audio data. 5 4 */ 6 5 … … 137 136 138 137 /** 139 * Peeks for audio samples without any conversion done.140 * This will get the raw sample data out of a mixing buffer.138 * Peeks for audio frames without any conversion done. 139 * This will get the raw frame data out of a mixing buffer. 141 140 * 142 141 * @return IPRT status code or VINF_AUDIO_MORE_DATA_AVAILABLE if more data is available to read. 143 142 * 144 * @param pMixBuf Mixing buffer to acquire audio samples from.145 * @param c SamplesToRead Number of audio samples to read.146 * @param pa SampleBuf Buffer where to store the returned audio samples.147 * @param c SampleBuf Size (in samples) of the buffer to store audio samples into.148 * @param pc SamplesRead Returns number of read audio samples. Optional.143 * @param pMixBuf Mixing buffer to acquire audio frames from. 144 * @param cFramesToRead Number of audio frames to read. 145 * @param paFrameBuf Buffer where to store the returned audio frames. 146 * @param cFrameBuf Size (in frames) of the buffer to store audio frames into. 147 * @param pcFramesRead Returns number of read audio frames. Optional. 149 148 * 150 149 * @remark This function is not thread safe! 151 150 */ 152 int AudioMixBufPeek(PPDMAUDIOMIXBUF pMixBuf, uint32_t c SamplesToRead,153 PPDMAUDIO SAMPLE paSampleBuf, uint32_t cSampleBuf, uint32_t *pcSamplesRead)154 { 155 AssertPtrReturn(pMixBuf, 156 AssertPtrReturn(pa SampleBuf, VERR_INVALID_POINTER);157 AssertReturn(c SampleBuf, VERR_INVALID_PARAMETER);151 int AudioMixBufPeek(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFramesToRead, 152 PPDMAUDIOFRAME paFrameBuf, uint32_t cFrameBuf, uint32_t *pcFramesRead) 153 { 154 AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER); 155 AssertPtrReturn(paFrameBuf, VERR_INVALID_POINTER); 156 AssertReturn(cFrameBuf, VERR_INVALID_PARAMETER); 158 157 /* pcRead is optional. */ 159 158 160 159 int rc; 161 160 162 if (!c SamplesToRead)163 { 164 if (pc SamplesRead)165 *pc SamplesRead = 0;161 if (!cFramesToRead) 162 { 163 if (pcFramesRead) 164 *pcFramesRead = 0; 166 165 return VINF_SUCCESS; 167 166 } 168 167 169 168 uint32_t cRead; 170 if (pMixBuf->offRead + c SamplesToRead > pMixBuf->cSamples)171 { 172 cRead = pMixBuf->c Samples - pMixBuf->offRead;169 if (pMixBuf->offRead + cFramesToRead > pMixBuf->cFrames) 170 { 171 cRead = pMixBuf->cFrames - pMixBuf->offRead; 173 172 rc = VINF_AUDIO_MORE_DATA_AVAILABLE; 174 173 } 175 174 else 176 175 { 177 cRead = c SamplesToRead;176 cRead = cFramesToRead; 178 177 rc = VINF_SUCCESS; 179 178 } 180 179 181 if (cRead > c SampleBuf)182 { 183 cRead = c SampleBuf;180 if (cRead > cFrameBuf) 181 { 182 cRead = cFrameBuf; 184 183 rc = VINF_AUDIO_MORE_DATA_AVAILABLE; 185 184 } … … 187 186 if (cRead) 188 187 { 189 memcpy(pa SampleBuf, &pMixBuf->pSamples[pMixBuf->offRead], sizeof(PDMAUDIOSAMPLE) * cRead);190 191 pMixBuf->offRead = (pMixBuf->offRead + cRead) % pMixBuf->c Samples;192 Assert(pMixBuf->offRead <= pMixBuf->c Samples);188 memcpy(paFrameBuf, &pMixBuf->pFrames[pMixBuf->offRead], sizeof(PDMAUDIOFRAME) * cRead); 189 190 pMixBuf->offRead = (pMixBuf->offRead + cRead) % pMixBuf->cFrames; 191 Assert(pMixBuf->offRead <= pMixBuf->cFrames); 193 192 pMixBuf->cUsed -= RT_MIN(cRead, pMixBuf->cUsed); 194 193 } 195 194 196 if (pc SamplesRead)197 *pc SamplesRead = cRead;195 if (pcFramesRead) 196 *pcFramesRead = cRead; 198 197 199 198 return rc; … … 201 200 202 201 /** 203 * Returns a mutable pointer to the mixing buffer's audio sample buffer for writing raw204 * audio samples.202 * Returns a mutable pointer to the mixing buffer's audio frame buffer for writing raw 203 * audio frames. 205 204 * 206 205 * @return IPRT status code. VINF_TRY_AGAIN for getting next pointer at beginning (circular). 207 * @param pMixBuf Mixing buffer to acquire audio samples from.208 * @param c Samples Number of requested audio samples to write.209 * @param ppv Samples Returns a mutable pointer to the buffer's audio sample data.210 * @param pc SamplesToWrite Number of available audio samples to write.206 * @param pMixBuf Mixing buffer to acquire audio frames from. 207 * @param cFrames Number of requested audio frames to write. 208 * @param ppvFrames Returns a mutable pointer to the buffer's audio frame data. 209 * @param pcFramesToWrite Number of available audio frames to write. 211 210 * 212 211 * @remark This function is not thread safe! 213 212 */ 214 int AudioMixBufPeekMutable(PPDMAUDIOMIXBUF pMixBuf, uint32_t c Samples,215 PPDMAUDIO SAMPLE *ppvSamples, uint32_t *pcSamplesToWrite)216 { 217 AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER);218 AssertPtrReturn(ppv Samples,VERR_INVALID_POINTER);219 AssertPtrReturn(pc SamplesToWrite, VERR_INVALID_POINTER);213 int AudioMixBufPeekMutable(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFrames, 214 PPDMAUDIOFRAME *ppvFrames, uint32_t *pcFramesToWrite) 215 { 216 AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER); 217 AssertPtrReturn(ppvFrames, VERR_INVALID_POINTER); 218 AssertPtrReturn(pcFramesToWrite, VERR_INVALID_POINTER); 220 219 221 220 int rc; 222 221 223 if (!c Samples)224 { 225 *pc SamplesToWrite = 0;222 if (!cFrames) 223 { 224 *pcFramesToWrite = 0; 226 225 return VINF_SUCCESS; 227 226 } 228 227 229 uint32_t c SamplesToWrite;230 if (pMixBuf->offWrite + c Samples > pMixBuf->cSamples)231 { 232 c SamplesToWrite = pMixBuf->cSamples - pMixBuf->offWrite;228 uint32_t cFramesToWrite; 229 if (pMixBuf->offWrite + cFrames > pMixBuf->cFrames) 230 { 231 cFramesToWrite = pMixBuf->cFrames - pMixBuf->offWrite; 233 232 rc = VINF_TRY_AGAIN; 234 233 } 235 234 else 236 235 { 237 c SamplesToWrite = cSamples;236 cFramesToWrite = cFrames; 238 237 rc = VINF_SUCCESS; 239 238 } 240 239 241 *ppv Samples = &pMixBuf->pSamples[pMixBuf->offWrite];242 AssertPtr(ppv Samples);243 244 pMixBuf->offWrite = (pMixBuf->offWrite + c SamplesToWrite) % pMixBuf->cSamples;245 Assert(pMixBuf->offWrite <= pMixBuf->c Samples);246 pMixBuf->cUsed += RT_MIN(c SamplesToWrite, pMixBuf->cUsed);247 248 *pc SamplesToWrite = cSamplesToWrite;240 *ppvFrames = &pMixBuf->pFrames[pMixBuf->offWrite]; 241 AssertPtr(ppvFrames); 242 243 pMixBuf->offWrite = (pMixBuf->offWrite + cFramesToWrite) % pMixBuf->cFrames; 244 Assert(pMixBuf->offWrite <= pMixBuf->cFrames); 245 pMixBuf->cUsed += RT_MIN(cFramesToWrite, pMixBuf->cUsed); 246 247 *pcFramesToWrite = cFramesToWrite; 249 248 250 249 return rc; … … 252 251 253 252 /** 254 * Clears the entire sample buffer.253 * Clears the entire frame buffer. 255 254 * 256 255 * @param pMixBuf Mixing buffer to clear. … … 261 260 AssertPtrReturnVoid(pMixBuf); 262 261 263 if (pMixBuf->c Samples)264 RT_BZERO(pMixBuf->p Samples, pMixBuf->cSamples * sizeof(PDMAUDIOSAMPLE));265 } 266 267 /** 268 * Clears (zeroes) the buffer by a certain amount of (used) samples and262 if (pMixBuf->cFrames) 263 RT_BZERO(pMixBuf->pFrames, pMixBuf->cFrames * sizeof(PDMAUDIOFRAME)); 264 } 265 266 /** 267 * Clears (zeroes) the buffer by a certain amount of (used) frames and 269 268 * keeps track to eventually assigned children buffers. 270 269 * 271 270 * @param pMixBuf Mixing buffer to clear. 272 * @param c SamplesToClear Number of audio samples to clear.273 */ 274 void AudioMixBufFinish(PPDMAUDIOMIXBUF pMixBuf, uint32_t c SamplesToClear)275 { 276 AUDMIXBUF_LOG(("c SamplesToClear=%RU32\n", cSamplesToClear));271 * @param cFramesToClear Number of audio frames to clear. 272 */ 273 void AudioMixBufFinish(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFramesToClear) 274 { 275 AUDMIXBUF_LOG(("cFramesToClear=%RU32\n", cFramesToClear)); 277 276 AUDMIXBUF_LOG(("%s: offRead=%RU32, cUsed=%RU32\n", 278 277 pMixBuf->pszName, pMixBuf->offRead, pMixBuf->cUsed)); … … 282 281 { 283 282 AUDMIXBUF_LOG(("\t%s: cMixed=%RU32 -> %RU32\n", 284 pIter->pszName, pIter->cMixed, pIter->cMixed - c SamplesToClear));285 286 pIter->cMixed -= RT_MIN(pIter->cMixed, c SamplesToClear);283 pIter->pszName, pIter->cMixed, pIter->cMixed - cFramesToClear)); 284 285 pIter->cMixed -= RT_MIN(pIter->cMixed, cFramesToClear); 287 286 /* Note: Do not increment pIter->cUsed here, as this gets done when reading from that buffer using AudioMixBufReadXXX. */ 288 287 } 289 288 290 Assert(c SamplesToClear <= pMixBuf->cSamples);289 Assert(cFramesToClear <= pMixBuf->cFrames); 291 290 292 291 uint32_t cClearOff; … … 294 293 295 294 /* Clear end of buffer (wrap around). */ 296 if (c SamplesToClear > pMixBuf->offRead)297 { 298 cClearOff = pMixBuf->c Samples - (cSamplesToClear - pMixBuf->offRead);299 cClearLen = pMixBuf->c Samples - cClearOff;295 if (cFramesToClear > pMixBuf->offRead) 296 { 297 cClearOff = pMixBuf->cFrames - (cFramesToClear - pMixBuf->offRead); 298 cClearLen = pMixBuf->cFrames - cClearOff; 300 299 301 300 AUDMIXBUF_LOG(("Clearing1: %RU32 - %RU32\n", cClearOff, cClearOff + cClearLen)); 302 301 303 RT_BZERO(pMixBuf->p Samples + cClearOff, cClearLen * sizeof(PDMAUDIOSAMPLE));304 305 Assert(c SamplesToClear >= cClearLen);306 c SamplesToClear -= cClearLen;302 RT_BZERO(pMixBuf->pFrames + cClearOff, cClearLen * sizeof(PDMAUDIOFRAME)); 303 304 Assert(cFramesToClear >= cClearLen); 305 cFramesToClear -= cClearLen; 307 306 } 308 307 309 308 /* Clear beginning of buffer. */ 310 if ( c SamplesToClear309 if ( cFramesToClear 311 310 && pMixBuf->offRead) 312 311 { 313 Assert(pMixBuf->offRead >= c SamplesToClear);314 315 cClearOff = pMixBuf->offRead - c SamplesToClear;316 cClearLen = c SamplesToClear;317 318 Assert(cClearOff + cClearLen <= pMixBuf->c Samples);312 Assert(pMixBuf->offRead >= cFramesToClear); 313 314 cClearOff = pMixBuf->offRead - cFramesToClear; 315 cClearLen = cFramesToClear; 316 317 Assert(cClearOff + cClearLen <= pMixBuf->cFrames); 319 318 320 319 AUDMIXBUF_LOG(("Clearing2: %RU32 - %RU32\n", cClearOff, cClearOff + cClearLen)); 321 320 322 RT_BZERO(pMixBuf->p Samples + cClearOff, cClearLen * sizeof(PDMAUDIOSAMPLE));321 RT_BZERO(pMixBuf->pFrames + cClearOff, cClearLen * sizeof(PDMAUDIOFRAME)); 323 322 } 324 323 } … … 350 349 } 351 350 352 if (pMixBuf->p Samples)353 { 354 Assert(pMixBuf->c Samples);355 356 RTMemFree(pMixBuf->p Samples);357 pMixBuf->p Samples = NULL;358 } 359 360 pMixBuf->c Samples = 0;361 } 362 363 /** 364 * Returns the size (in audio samples) of free audio buffer space.365 * 366 * @return uint32_t Size (in audio samples) of free audio buffer space.351 if (pMixBuf->pFrames) 352 { 353 Assert(pMixBuf->cFrames); 354 355 RTMemFree(pMixBuf->pFrames); 356 pMixBuf->pFrames = NULL; 357 } 358 359 pMixBuf->cFrames = 0; 360 } 361 362 /** 363 * Returns the size (in audio frames) of free audio buffer space. 364 * 365 * @return uint32_t Size (in audio frames) of free audio buffer space. 367 366 * @param pMixBuf Mixing buffer to return free size for. 368 367 */ … … 371 370 AssertPtrReturn(pMixBuf, 0); 372 371 373 uint32_t c Samples, cSamplesFree;372 uint32_t cFrames, cFramesFree; 374 373 if (pMixBuf->pParent) 375 374 { 376 375 /* 377 * As a linked child buffer we want to know how many samples376 * As a linked child buffer we want to know how many frames 378 377 * already have been consumed by the parent. 379 378 */ 380 c Samples = pMixBuf->pParent->cSamples;381 382 Assert(pMixBuf->cMixed <= c Samples);383 c SamplesFree = cSamples - pMixBuf->cMixed;379 cFrames = pMixBuf->pParent->cFrames; 380 381 Assert(pMixBuf->cMixed <= cFrames); 382 cFramesFree = cFrames - pMixBuf->cMixed; 384 383 } 385 384 else /* As a parent. */ 386 385 { 387 c Samples = pMixBuf->cSamples;388 Assert(c Samples >= pMixBuf->cUsed);389 c SamplesFree = pMixBuf->cSamples - pMixBuf->cUsed;390 } 391 392 AUDMIXBUF_LOG(("%s: %RU32 of %RU32\n", pMixBuf->pszName, c SamplesFree, cSamples));393 return c SamplesFree;386 cFrames = pMixBuf->cFrames; 387 Assert(cFrames >= pMixBuf->cUsed); 388 cFramesFree = pMixBuf->cFrames - pMixBuf->cUsed; 389 } 390 391 AUDMIXBUF_LOG(("%s: %RU32 of %RU32\n", pMixBuf->pszName, cFramesFree, cFrames)); 392 return cFramesFree; 394 393 } 395 394 … … 402 401 uint32_t AudioMixBufFreeBytes(PPDMAUDIOMIXBUF pMixBuf) 403 402 { 404 return AUDIOMIXBUF_ S2B(pMixBuf, AudioMixBufFree(pMixBuf));405 } 406 407 /** 408 * Allocates the internal audio sample buffer.403 return AUDIOMIXBUF_F2B(pMixBuf, AudioMixBufFree(pMixBuf)); 404 } 405 406 /** 407 * Allocates the internal audio frame buffer. 409 408 * 410 409 * @return IPRT status code. 411 * @param pMixBuf Mixing buffer to allocate sample buffer for.412 * @param c Samples Number of audio samples to allocate.413 */ 414 static int audioMixBufAlloc(PPDMAUDIOMIXBUF pMixBuf, uint32_t c Samples)410 * @param pMixBuf Mixing buffer to allocate frame buffer for. 411 * @param cFrames Number of audio frames to allocate. 412 */ 413 static int audioMixBufAlloc(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFrames) 415 414 { 416 415 AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER); 417 AssertReturn(c Samples, VERR_INVALID_PARAMETER);418 419 AUDMIXBUF_LOG(("%s: c Samples=%RU32\n", pMixBuf->pszName, cSamples));420 421 size_t cb Samples = cSamples * sizeof(PDMAUDIOSAMPLE);422 pMixBuf->p Samples = (PPDMAUDIOSAMPLE)RTMemAllocZ(cbSamples);423 if (pMixBuf->p Samples)424 { 425 pMixBuf->c Samples = cSamples;416 AssertReturn(cFrames, VERR_INVALID_PARAMETER); 417 418 AUDMIXBUF_LOG(("%s: cFrames=%RU32\n", pMixBuf->pszName, cFrames)); 419 420 size_t cbFrames = cFrames * sizeof(PDMAUDIOFRAME); 421 pMixBuf->pFrames = (PPDMAUDIOFRAME)RTMemAllocZ(cbFrames); 422 if (pMixBuf->pFrames) 423 { 424 pMixBuf->cFrames = cFrames; 426 425 return VINF_SUCCESS; 427 426 } … … 467 466 } \ 468 467 \ 469 DECLCALLBACK(uint32_t) audioMixBufConvFrom##_aName##Stereo(PPDMAUDIO SAMPLE paDst, const void *pvSrc, uint32_t cbSrc, \468 DECLCALLBACK(uint32_t) audioMixBufConvFrom##_aName##Stereo(PPDMAUDIOFRAME paDst, const void *pvSrc, uint32_t cbSrc, \ 470 469 PCPDMAUDMIXBUFCONVOPTS pOpts) \ 471 470 { \ 472 471 _aType const *pSrc = (_aType const *)pvSrc; \ 473 uint32_t c Samples = RT_MIN(pOpts->cSamples, cbSrc / sizeof(_aType)); \474 AUDMIXBUF_MACRO_LOG(("c Samples=%RU32, BpS=%zu, lVol=%RU32, rVol=%RU32\n", \475 pOpts->c Samples, sizeof(_aType), pOpts->From.Volume.uLeft, pOpts->From.Volume.uRight)); \476 for (uint32_t i = 0; i < c Samples; i++) \472 uint32_t cFrames = RT_MIN(pOpts->cFrames, cbSrc / sizeof(_aType)); \ 473 AUDMIXBUF_MACRO_LOG(("cFrames=%RU32, BpS=%zu, lVol=%RU32, rVol=%RU32\n", \ 474 pOpts->cFrames, sizeof(_aType), pOpts->From.Volume.uLeft, pOpts->From.Volume.uRight)); \ 475 for (uint32_t i = 0; i < cFrames; i++) \ 477 476 { \ 478 477 paDst->i64LSample = ASMMult2xS32RetS64((int32_t)audioMixBufClipFrom##_aName(*pSrc++), pOpts->From.Volume.uLeft ) >> AUDIOMIXBUF_VOL_SHIFT; \ … … 481 480 } \ 482 481 \ 483 return c Samples; \482 return cFrames; \ 484 483 } \ 485 484 \ 486 DECLCALLBACK(uint32_t) audioMixBufConvFrom##_aName##Mono(PPDMAUDIO SAMPLE paDst, const void *pvSrc, uint32_t cbSrc, \485 DECLCALLBACK(uint32_t) audioMixBufConvFrom##_aName##Mono(PPDMAUDIOFRAME paDst, const void *pvSrc, uint32_t cbSrc, \ 487 486 PCPDMAUDMIXBUFCONVOPTS pOpts) \ 488 487 { \ 489 488 _aType const *pSrc = (_aType const *)pvSrc; \ 490 const uint32_t c Samples = RT_MIN(pOpts->cSamples, cbSrc / sizeof(_aType)); \491 AUDMIXBUF_MACRO_LOG(("c Samples=%RU32, BpS=%zu, lVol=%RU32, rVol=%RU32\n", \492 c Samples, sizeof(_aType), pOpts->From.Volume.uLeft, pOpts->From.Volume.uRight)); \493 for (uint32_t i = 0; i < c Samples; i++) \489 const uint32_t cFrames = RT_MIN(pOpts->cFrames, cbSrc / sizeof(_aType)); \ 490 AUDMIXBUF_MACRO_LOG(("cFrames=%RU32, BpS=%zu, lVol=%RU32, rVol=%RU32\n", \ 491 cFrames, sizeof(_aType), pOpts->From.Volume.uLeft, pOpts->From.Volume.uRight)); \ 492 for (uint32_t i = 0; i < cFrames; i++) \ 494 493 { \ 495 494 paDst->i64LSample = ASMMult2xS32RetS64((int32_t)audioMixBufClipFrom##_aName(*pSrc), pOpts->From.Volume.uLeft) >> AUDIOMIXBUF_VOL_SHIFT; \ … … 499 498 } \ 500 499 \ 501 return c Samples; \500 return cFrames; \ 502 501 } \ 503 502 \ 504 DECLCALLBACK(void) audioMixBufConvTo##_aName##Stereo(void *pvDst, PCPDMAUDIO SAMPLE paSrc, PCPDMAUDMIXBUFCONVOPTS pOpts) \503 DECLCALLBACK(void) audioMixBufConvTo##_aName##Stereo(void *pvDst, PCPDMAUDIOFRAME paSrc, PCPDMAUDMIXBUFCONVOPTS pOpts) \ 505 504 { \ 506 PCPDMAUDIO SAMPLE pSrc = paSrc; \505 PCPDMAUDIOFRAME pSrc = paSrc; \ 507 506 _aType *pDst = (_aType *)pvDst; \ 508 507 _aType l, r; \ 509 uint32_t c Samples = pOpts->cSamples; \510 while (c Samples--) \508 uint32_t cFrames = pOpts->cFrames; \ 509 while (cFrames--) \ 511 510 { \ 512 511 AUDMIXBUF_MACRO_LOG(("%p: l=%RI64, r=%RI64\n", pSrc, pSrc->i64LSample, pSrc->i64RSample)); \ … … 520 519 } \ 521 520 \ 522 DECLCALLBACK(void) audioMixBufConvTo##_aName##Mono(void *pvDst, PCPDMAUDIO SAMPLE paSrc, PCPDMAUDMIXBUFCONVOPTS pOpts) \521 DECLCALLBACK(void) audioMixBufConvTo##_aName##Mono(void *pvDst, PCPDMAUDIOFRAME paSrc, PCPDMAUDMIXBUFCONVOPTS pOpts) \ 523 522 { \ 524 PCPDMAUDIO SAMPLE pSrc = paSrc; \523 PCPDMAUDIOFRAME pSrc = paSrc; \ 525 524 _aType *pDst = (_aType *)pvDst; \ 526 uint32_t c Samples = pOpts->cSamples; \527 while (c Samples--) \525 uint32_t cFrames = pOpts->cFrames; \ 526 while (cFrames--) \ 528 527 { \ 529 528 *pDst++ = audioMixBufClipTo##_aName((pSrc->i64LSample + pSrc->i64RSample) / 2); \ … … 548 547 549 548 #define AUDMIXBUF_MIXOP(_aName, _aOp) \ 550 static void audioMixBufOp##_aName(PPDMAUDIO SAMPLE paDst, uint32_t cDstSamples, \551 PPDMAUDIO SAMPLE paSrc, uint32_t cSrcSamples, \549 static void audioMixBufOp##_aName(PPDMAUDIOFRAME paDst, uint32_t cDstFrames, \ 550 PPDMAUDIOFRAME paSrc, uint32_t cSrcFrames, \ 552 551 PPDMAUDIOSTRMRATE pRate, \ 553 552 uint32_t *pcDstWritten, uint32_t *pcSrcRead) \ 554 553 { \ 555 AUDMIXBUF_MACRO_LOG(("cSrc Samples=%RU32, cDstSamples=%RU32\n", cSrcSamples, cDstSamples)); \554 AUDMIXBUF_MACRO_LOG(("cSrcFrames=%RU32, cDstFrames=%RU32\n", cSrcFrames, cDstFrames)); \ 556 555 AUDMIXBUF_MACRO_LOG(("Rate: srcOffset=%RU32, dstOffset=%RU32, dstInc=%RU32\n", \ 557 556 pRate->srcOffset, \ … … 560 559 if (pRate->dstInc == (UINT64_C(1) + UINT32_MAX)) /* No conversion needed? */ \ 561 560 { \ 562 uint32_t c Samples = RT_MIN(cSrcSamples, cDstSamples); \563 AUDMIXBUF_MACRO_LOG(("c Samples=%RU32\n", cSamples)); \564 for (uint32_t i = 0; i < c Samples; i++) \561 uint32_t cFrames = RT_MIN(cSrcFrames, cDstFrames); \ 562 AUDMIXBUF_MACRO_LOG(("cFrames=%RU32\n", cFrames)); \ 563 for (uint32_t i = 0; i < cFrames; i++) \ 565 564 { \ 566 565 paDst[i].i64LSample _aOp paSrc[i].i64LSample; \ … … 569 568 \ 570 569 if (pcDstWritten) \ 571 *pcDstWritten = c Samples; \570 *pcDstWritten = cFrames; \ 572 571 if (pcSrcRead) \ 573 *pcSrcRead = c Samples; \572 *pcSrcRead = cFrames; \ 574 573 return; \ 575 574 } \ 576 575 \ 577 PPDMAUDIO SAMPLE paSrcStart = paSrc; \578 PPDMAUDIO SAMPLE paSrcEnd = paSrc + cSrcSamples;\579 PPDMAUDIO SAMPLE paDstStart = paDst; \580 PPDMAUDIO SAMPLE paDstEnd = paDst + cDstSamples; \581 PDMAUDIO SAMPLE samCur= { 0 }; \582 PDMAUDIO SAMPLE samOut; \583 PDMAUDIO SAMPLE samLast = pRate->srcSampleLast; \576 PPDMAUDIOFRAME paSrcStart = paSrc; \ 577 PPDMAUDIOFRAME paSrcEnd = paSrc + cSrcFrames; \ 578 PPDMAUDIOFRAME paDstStart = paDst; \ 579 PPDMAUDIOFRAME paDstEnd = paDst + cDstFrames; \ 580 PDMAUDIOFRAME frameCur = { 0 }; \ 581 PDMAUDIOFRAME frameOut; \ 582 PDMAUDIOFRAME frameLast = pRate->srcFrameLast; \ 584 583 \ 585 584 while (paDst < paDstEnd) \ … … 593 592 { \ 594 593 Assert(paSrc <= paSrcEnd); \ 595 samLast = *paSrc++; \594 frameLast = *paSrc++; \ 596 595 pRate->srcOffset++; \ 597 596 if (paSrc == paSrcEnd) \ … … 603 602 break; \ 604 603 \ 605 samCur = *paSrc; \604 frameCur = *paSrc; \ 606 605 \ 607 606 /* Interpolate. */ \ 608 607 int64_t iDstOffInt = pRate->dstOffset & UINT32_MAX; \ 609 608 \ 610 samOut.i64LSample = (samLast.i64LSample * ((int64_t) (INT64_C(1) << 32) - iDstOffInt) + samCur.i64LSample * iDstOffInt) >> 32; \611 samOut.i64RSample = (samLast.i64RSample * ((int64_t) (INT64_C(1) << 32) - iDstOffInt) + samCur.i64RSample * iDstOffInt) >> 32; \609 frameOut.i64LSample = (frameLast.i64LSample * ((int64_t) (INT64_C(1) << 32) - iDstOffInt) + frameCur.i64LSample * iDstOffInt) >> 32; \ 610 frameOut.i64RSample = (frameLast.i64RSample * ((int64_t) (INT64_C(1) << 32) - iDstOffInt) + frameCur.i64RSample * iDstOffInt) >> 32; \ 612 611 \ 613 paDst->i64LSample _aOp samOut.i64LSample; \614 paDst->i64RSample _aOp samOut.i64RSample; \612 paDst->i64LSample _aOp frameOut.i64LSample; \ 613 paDst->i64RSample _aOp frameOut.i64RSample; \ 615 614 \ 616 615 AUDMIXBUF_MACRO_LOG(("\tiDstOffInt=%RI64, l=%RI64, r=%RI64 (cur l=%RI64, r=%RI64)\n", \ 617 616 iDstOffInt, \ 618 617 paDst->i64LSample >> 32, paDst->i64RSample >> 32, \ 619 samCur.i64LSample >> 32, samCur.i64RSample >> 32)); \618 frameCur.i64LSample >> 32, frameCur.i64RSample >> 32)); \ 620 619 \ 621 620 paDst++; \ … … 626 625 } \ 627 626 \ 628 AUDMIXBUF_MACRO_LOG(("%zu source samples -> %zu dest samples\n", paSrc - paSrcStart, paDst - paDstStart)); \627 AUDMIXBUF_MACRO_LOG(("%zu source frames -> %zu dest frames\n", paSrc - paSrcStart, paDst - paDstStart)); \ 629 628 \ 630 pRate->src SampleLast = samLast; \629 pRate->srcFrameLast = frameLast; \ 631 630 \ 632 631 AUDMIXBUF_MACRO_LOG(("pRate->srcSampleLast l=%RI64, r=%RI64\n", \ 633 pRate->src SampleLast.i64LSample, pRate->srcSampleLast.i64RSample)); \632 pRate->srcFrameLast.i64LSample, pRate->srcFrameLast.i64RSample)); \ 634 633 \ 635 634 if (pcDstWritten) \ … … 651 650 /** Dummy conversion used when the source is muted. */ 652 651 static DECLCALLBACK(uint32_t) 653 audioMixBufConvFromSilence(PPDMAUDIO SAMPLE paDst, const void *pvSrc, uint32_t cbSrc, PCPDMAUDMIXBUFCONVOPTS pOpts)652 audioMixBufConvFromSilence(PPDMAUDIOFRAME paDst, const void *pvSrc, uint32_t cbSrc, PCPDMAUDMIXBUFCONVOPTS pOpts) 654 653 { 655 654 RT_NOREF(cbSrc, pvSrc); 656 655 657 656 /* Internally zero always corresponds to silence. */ 658 RT_BZERO(paDst, pOpts->c Samples * sizeof(paDst[0]));659 return pOpts->c Samples;657 RT_BZERO(paDst, pOpts->cFrames * sizeof(paDst[0])); 658 return pOpts->cFrames; 660 659 } 661 660 662 661 /** 663 662 * Looks up the matching conversion (macro) routine for converting 664 * audio samples from a source format.663 * audio frames from a source format. 665 664 * 666 665 ** @todo Speed up the lookup by binding it to the actual stream state. … … 722 721 /** 723 722 * Looks up the matching conversion (macro) routine for converting 724 * audio samples to a destination format.723 * audio frames to a destination format. 725 724 * 726 725 ** @todo Speed up the lookup by binding it to the actual stream state. … … 811 810 * @param pszName Name of mixing buffer for easier identification. Optional. 812 811 * @param pProps PCM audio properties to use for the mixing buffer. 813 * @param c Samples Maximum number of audio samples the mixing buffer can hold.814 */ 815 int AudioMixBufInit(PPDMAUDIOMIXBUF pMixBuf, const char *pszName, PPDMAUDIOPCMPROPS pProps, uint32_t c Samples)812 * @param cFrames Maximum number of audio frames the mixing buffer can hold. 813 */ 814 int AudioMixBufInit(PPDMAUDIOMIXBUF pMixBuf, const char *pszName, PPDMAUDIOPCMPROPS pProps, uint32_t cFrames) 816 815 { 817 816 AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER); … … 824 823 pMixBuf->cChildren = 0; 825 824 826 pMixBuf->p Samples = NULL;827 pMixBuf->c Samples = 0;825 pMixBuf->pFrames = NULL; 826 pMixBuf->cFrames = 0; 828 827 829 828 pMixBuf->offRead = 0; … … 863 862 RT_BOOL(AUDMIXBUF_FMT_SIGNED(pMixBuf->AudioFmt)))); 864 863 865 return audioMixBufAlloc(pMixBuf, c Samples);866 } 867 868 /** 869 * Returns @c true if there are any audio samples available for processing,864 return audioMixBufAlloc(pMixBuf, cFrames); 865 } 866 867 /** 868 * Returns @c true if there are any audio frames available for processing, 870 869 * @c false if not. 871 870 * 872 * @return bool @c true if there are any audio samples available for processing, @c false if not.871 * @return bool @c true if there are any audio frames available for processing, @c false if not. 873 872 * @param pMixBuf Mixing buffer to return value for. 874 873 */ … … 926 925 927 926 AssertMsgReturn(AUDMIXBUF_FMT_SAMPLE_FREQ(pParent->AudioFmt), 928 ("Parent sample frequency (Hz) not set\n"), VERR_INVALID_PARAMETER);927 ("Parent frame frequency (Hz) not set\n"), VERR_INVALID_PARAMETER); 929 928 AssertMsgReturn(AUDMIXBUF_FMT_SAMPLE_FREQ(pMixBuf->AudioFmt), 930 929 ("Buffer sample frequency (Hz) not set\n"), VERR_INVALID_PARAMETER); … … 950 949 int rc = VINF_SUCCESS; 951 950 #if 0 952 uint32_t c Samples = (uint32_t)RT_MIN( ((uint64_t)pParent->cSamples << 32)953 / pMixBuf->iFreqRatio, _64K /* 64K samples max. */);954 if (!c Samples)955 c Samples = pParent->cSamples;951 uint32_t cFrames = (uint32_t)RT_MIN( ((uint64_t)pParent->cFrames << 32) 952 / pMixBuf->iFreqRatio, _64K /* 64K frames max. */); 953 if (!cFrames) 954 cFrames = pParent->cFrames; 956 955 957 956 int rc = VINF_SUCCESS; 958 957 959 if (c Samples != pMixBuf->cSamples)960 { 961 AUDMIXBUF_LOG(("%s: Reallocating samples %RU32 -> %RU32\n",962 pMixBuf->pszName, pMixBuf->c Samples, cSamples));963 964 uint32_t cbSamples = c Samples * sizeof(PDMAUDIOSAMPLE);958 if (cFrames != pMixBuf->cFrames) 959 { 960 AUDMIXBUF_LOG(("%s: Reallocating frames %RU32 -> %RU32\n", 961 pMixBuf->pszName, pMixBuf->cFrames, cFrames)); 962 963 uint32_t cbSamples = cFrames * sizeof(PDMAUDIOSAMPLE); 965 964 Assert(cbSamples); 966 965 pMixBuf->pSamples = (PPDMAUDIOSAMPLE)RTMemRealloc(pMixBuf->pSamples, cbSamples); … … 970 969 if (RT_SUCCESS(rc)) 971 970 { 972 pMixBuf->c Samples = cSamples;971 pMixBuf->cFrames = cFrames; 973 972 974 973 /* Make sure to zero the reallocated buffer so that it can be … … 994 993 / AUDMIXBUF_FMT_SAMPLE_FREQ(pParent->AudioFmt); 995 994 996 AUDMIXBUF_LOG(("uThisHz=%RU32, uParentHz=%RU32, iFreqRatio=0x%RX64 (%RI64), uRateInc=0x%RX64 (%RU64), c Samples=%RU32 (%RU32 parent)\n",995 AUDMIXBUF_LOG(("uThisHz=%RU32, uParentHz=%RU32, iFreqRatio=0x%RX64 (%RI64), uRateInc=0x%RX64 (%RU64), cFrames=%RU32 (%RU32 parent)\n", 997 996 AUDMIXBUF_FMT_SAMPLE_FREQ(pMixBuf->AudioFmt), 998 997 AUDMIXBUF_FMT_SAMPLE_FREQ(pParent->AudioFmt), 999 998 pMixBuf->iFreqRatio, pMixBuf->iFreqRatio, 1000 999 pMixBuf->pRate->dstInc, pMixBuf->pRate->dstInc, 1001 pMixBuf->c Samples,1002 pParent->c Samples));1000 pMixBuf->cFrames, 1001 pParent->cFrames)); 1003 1002 AUDMIXBUF_LOG(("%s (%RU32Hz) -> %s (%RU32Hz)\n", 1004 1003 pMixBuf->pszName, AUDMIXBUF_FMT_SAMPLE_FREQ(pMixBuf->AudioFmt), … … 1010 1009 1011 1010 /** 1012 * Returns number of available live samples, that is, samples that1011 * Returns number of available live frames, that is, frames that 1013 1012 * have been written into the mixing buffer but not have been processed yet. 1014 1013 * 1015 * For a parent buffer, this simply returns the currently used number of samples1014 * For a parent buffer, this simply returns the currently used number of frames 1016 1015 * in the buffer. 1017 1016 * 1018 * For a child buffer, this returns the number of samples which have been mixed1017 * For a child buffer, this returns the number of frames which have been mixed 1019 1018 * to the parent and were not processed by the parent yet. 1020 1019 * 1021 * @return uint32_t Number of live samples available.1020 * @return uint32_t Number of live frames available. 1022 1021 * @param pMixBuf Mixing buffer to return value for. 1023 1022 */ … … 1027 1026 1028 1027 #ifdef RT_STRICT 1029 uint32_t c Samples;1028 uint32_t cFrames; 1030 1029 #endif 1031 1030 uint32_t cAvail; … … 1033 1032 { 1034 1033 #ifdef RT_STRICT 1035 /* Use the sample count from the parent, as1036 * pMixBuf->cMixed specifies the sample count1037 * in parent samples. */1038 c Samples = pMixBuf->pParent->cSamples;1034 /* Use the frame count from the parent, as 1035 * pMixBuf->cMixed specifies the frame count 1036 * in parent frames. */ 1037 cFrames = pMixBuf->pParent->cFrames; 1039 1038 #endif 1040 1039 cAvail = pMixBuf->cMixed; … … 1043 1042 { 1044 1043 #ifdef RT_STRICT 1045 c Samples = pMixBuf->cSamples;1044 cFrames = pMixBuf->cFrames; 1046 1045 #endif 1047 1046 cAvail = pMixBuf->cUsed; 1048 1047 } 1049 1048 1050 Assert(cAvail <= c Samples);1049 Assert(cAvail <= cFrames); 1051 1050 return cAvail; 1052 1051 } 1053 1052 1054 1053 /** 1055 * Mixes audio samples from a source mixing buffer to a destination mixing buffer.1054 * Mixes audio frames from a source mixing buffer to a destination mixing buffer. 1056 1055 * 1057 1056 * @return IPRT status code. … … 1061 1060 * @param pDst Destination mixing buffer. 1062 1061 * @param pSrc Source mixing buffer. 1063 * @param cSrcOff Offset of source audio samples to mix.1064 * @param cSrc Samples Number of source audio samples to mix.1065 * @param pcSrcMixed Number of source audio samples successfully mixed. Optional.1066 */ 1067 static int audioMixBufMixTo(PPDMAUDIOMIXBUF pDst, PPDMAUDIOMIXBUF pSrc, uint32_t cSrcOff, uint32_t cSrc Samples,1062 * @param cSrcOff Offset of source audio frames to mix. 1063 * @param cSrcFrames Number of source audio frames to mix. 1064 * @param pcSrcMixed Number of source audio frames successfully mixed. Optional. 1065 */ 1066 static int audioMixBufMixTo(PPDMAUDIOMIXBUF pDst, PPDMAUDIOMIXBUF pSrc, uint32_t cSrcOff, uint32_t cSrcFrames, 1068 1067 uint32_t *pcSrcMixed) 1069 1068 { … … 1077 1076 uint32_t cWrittenTotal = 0; 1078 1077 1079 Assert(pSrc->cMixed <= pDst->c Samples);1078 Assert(pSrc->cMixed <= pDst->cFrames); 1080 1079 1081 1080 Assert(pSrc->cUsed >= pDst->cMixed); 1082 Assert(pDst->cUsed <= pDst->c Samples);1081 Assert(pDst->cUsed <= pDst->cFrames); 1083 1082 1084 1083 uint32_t offSrcRead = cSrcOff; … … 1087 1086 uint32_t cDstMixed = pSrc->cMixed; 1088 1087 1089 uint32_t cSrcAvail = RT_MIN(cSrc Samples, pSrc->cUsed);1090 uint32_t cDstAvail = pDst->c Samples - pDst->cUsed; /** @todo Use pDst->cMixed later? */1088 uint32_t cSrcAvail = RT_MIN(cSrcFrames, pSrc->cUsed); 1089 uint32_t cDstAvail = pDst->cFrames - pDst->cUsed; /** @todo Use pDst->cMixed later? */ 1091 1090 1092 1091 AUDMIXBUF_LOG(("%s (%RU32 available) -> %s (%RU32 available)\n", … … 1112 1111 while (cSrcAvail && cDstAvail) 1113 1112 { 1114 cSrcToRead = RT_MIN(cSrcAvail, pSrc->c Samples - offSrcRead);1115 cDstToWrite = RT_MIN(cDstAvail, pDst->c Samples - offDstWrite);1113 cSrcToRead = RT_MIN(cSrcAvail, pSrc->cFrames - offSrcRead); 1114 cDstToWrite = RT_MIN(cDstAvail, pDst->cFrames - offDstWrite); 1116 1115 1117 1116 AUDMIXBUF_LOG(("\tSource: %RU32 @ %RU32 -> reading %RU32\n", cSrcAvail, offSrcRead, cSrcToRead)); … … 1126 1125 cDstWritten = cSrcRead = 0; 1127 1126 1128 Assert(offSrcRead < pSrc->c Samples);1129 Assert(offSrcRead + cSrcToRead <= pSrc->c Samples);1130 1131 Assert(offDstWrite < pDst->c Samples);1132 Assert(offDstWrite + cDstToWrite <= pDst->c Samples);1133 1134 audioMixBufOpAssign(pDst->p Samples + offDstWrite, cDstToWrite,1135 pSrc->p Samples + offSrcRead, cSrcToRead,1127 Assert(offSrcRead < pSrc->cFrames); 1128 Assert(offSrcRead + cSrcToRead <= pSrc->cFrames); 1129 1130 Assert(offDstWrite < pDst->cFrames); 1131 Assert(offDstWrite + cDstToWrite <= pDst->cFrames); 1132 1133 audioMixBufOpAssign(pDst->pFrames + offDstWrite, cDstToWrite, 1134 pSrc->pFrames + offSrcRead, cSrcToRead, 1136 1135 pSrc->pRate, &cDstWritten, &cSrcRead); 1137 1136 … … 1139 1138 cWrittenTotal += cDstWritten; 1140 1139 1141 offSrcRead = (offSrcRead + cSrcRead) % pSrc->c Samples;1142 offDstWrite = (offDstWrite + cDstWritten) % pDst->c Samples;1140 offSrcRead = (offSrcRead + cSrcRead) % pSrc->cFrames; 1141 offDstWrite = (offDstWrite + cDstWritten) % pDst->cFrames; 1143 1142 1144 1143 cDstMixed += cDstWritten; … … 1159 1158 pSrc->cUsed -= RT_MIN(pSrc->cUsed, cReadTotal); 1160 1159 1161 /* Note: Always count in parent samples, as the rate can differ! */1162 pSrc->cMixed = RT_MIN(cDstMixed, pDst->c Samples);1160 /* Note: Always count in parent frames, as the rate can differ! */ 1161 pSrc->cMixed = RT_MIN(cDstMixed, pDst->cFrames); 1163 1162 1164 1163 pDst->offWrite = offDstWrite; 1165 Assert(pDst->offWrite <= pDst->c Samples);1166 Assert((pDst->cUsed + cWrittenTotal) <= pDst->c Samples);1164 Assert(pDst->offWrite <= pDst->cFrames); 1165 Assert((pDst->cUsed + cWrittenTotal) <= pDst->cFrames); 1167 1166 pDst->cUsed += cWrittenTotal; 1168 1167 1169 /* If there are more used samples than fitting in the destination buffer,1168 /* If there are more used frames than fitting in the destination buffer, 1170 1169 * adjust the values accordingly. 1171 1170 * 1172 1171 * This can happen if this routine has been called too often without 1173 1172 * actually processing the destination buffer in between. */ 1174 if (pDst->cUsed > pDst->c Samples)1175 { 1176 LogFunc(("%s: Warning: Destination buffer used %RU32 / %RU32 samples\n", pDst->pszName, pDst->cUsed, pDst->cSamples));1173 if (pDst->cUsed > pDst->cFrames) 1174 { 1175 LogFunc(("%s: Warning: Destination buffer used %RU32 / %RU32 frames\n", pDst->pszName, pDst->cUsed, pDst->cFrames)); 1177 1176 pDst->offWrite = 0; 1178 pDst->cUsed = pDst->c Samples;1177 pDst->cUsed = pDst->cFrames; 1179 1178 1180 1179 rc = VERR_BUFFER_OVERFLOW; … … 1185 1184 audioMixBufDbgValidate(pDst); 1186 1185 1187 Assert(pSrc->cMixed <= pDst->c Samples);1186 Assert(pSrc->cMixed <= pDst->cFrames); 1188 1187 #endif 1189 1188 … … 1200 1199 Assert(sizeof(auBuf) % 4 == 0); 1201 1200 1202 uint32_t cToRead = RT_MIN(AUDIOMIXBUF_B2 S(pDst, sizeof(auBuf)), RT_MIN(cLeft, pDst->cSamples - offRead));1201 uint32_t cToRead = RT_MIN(AUDIOMIXBUF_B2F(pDst, sizeof(auBuf)), RT_MIN(cLeft, pDst->cFrames - offRead)); 1203 1202 Assert(cToRead <= pDst->cUsed); 1204 1203 1205 1204 PDMAUDMIXBUFCONVOPTS convOpts; 1206 1205 RT_ZERO(convOpts); 1207 convOpts.c Samples = cToRead;1208 1209 pDst->pfnConvTo(auBuf, pDst->p Samples + offRead, &convOpts);1206 convOpts.cFrames = cToRead; 1207 1208 pDst->pfnConvTo(auBuf, pDst->pFrames + offRead, &convOpts); 1210 1209 1211 1210 RTFILE fh; … … 1214 1213 if (RT_SUCCESS(rc2)) 1215 1214 { 1216 RTFileWrite(fh, auBuf, AUDIOMIXBUF_ S2B(pDst, cToRead), NULL);1215 RTFileWrite(fh, auBuf, AUDIOMIXBUF_F2B(pDst, cToRead), NULL); 1217 1216 RTFileClose(fh); 1218 1217 } 1219 1218 1220 offRead = (offRead + cToRead) % pDst->c Samples;1219 offRead = (offRead + cToRead) % pDst->cFrames; 1221 1220 cLeft -= cToRead; 1222 1221 } … … 1236 1235 1237 1236 /** 1238 * Mixes audio samples down to the parent mixing buffer, extended version.1237 * Mixes audio frames down to the parent mixing buffer, extended version. 1239 1238 * 1240 1239 * @return IPRT status code. See audioMixBufMixTo() for a more detailed explanation. 1241 1240 * @param pMixBuf Source mixing buffer to mix to its parent. 1242 * @param cSrcOffset Offset (in samples) of source mixing buffer.1243 * @param cSrc Samples Number of source audio samples to mix to its parent.1244 * @param pcSrcMixed Number of source audio samples successfully mixed. Optional.1245 */ 1246 int AudioMixBufMixToParentEx(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSrcOffset, uint32_t cSrc Samples, uint32_t *pcSrcMixed)1241 * @param cSrcOffset Offset (in frames) of source mixing buffer. 1242 * @param cSrcFrames Number of source audio frames to mix to its parent. 1243 * @param pcSrcMixed Number of source audio frames successfully mixed. Optional. 1244 */ 1245 int AudioMixBufMixToParentEx(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSrcOffset, uint32_t cSrcFrames, uint32_t *pcSrcMixed) 1247 1246 { 1248 1247 AssertMsgReturn(VALID_PTR(pMixBuf->pParent), … … 1250 1249 VERR_INVALID_PARAMETER); 1251 1250 1252 return audioMixBufMixTo(pMixBuf->pParent, pMixBuf, cSrcOffset, cSrc Samples, pcSrcMixed);1253 } 1254 1255 /** 1256 * Mixes audio samples down to the parent mixing buffer.1251 return audioMixBufMixTo(pMixBuf->pParent, pMixBuf, cSrcOffset, cSrcFrames, pcSrcMixed); 1252 } 1253 1254 /** 1255 * Mixes audio frames down to the parent mixing buffer. 1257 1256 * 1258 1257 * @return IPRT status code. See audioMixBufMixTo() for a more detailed explanation. 1259 1258 * @param pMixBuf Source mixing buffer to mix to its parent. 1260 * @param cSrc Samples Number of source audio samples to mix to its parent.1261 * @param pcSrcMixed Number of source audio samples successfully mixed. Optional.1262 */ 1263 int AudioMixBufMixToParent(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSrc Samples, uint32_t *pcSrcMixed)1264 { 1265 return audioMixBufMixTo(pMixBuf->pParent, pMixBuf, pMixBuf->offRead, cSrc Samples, pcSrcMixed);1259 * @param cSrcFrames Number of source audio frames to mix to its parent. 1260 * @param pcSrcMixed Number of source audio frames successfully mixed. Optional. 1261 */ 1262 int AudioMixBufMixToParent(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSrcFrames, uint32_t *pcSrcMixed) 1263 { 1264 return audioMixBufMixTo(pMixBuf->pParent, pMixBuf, pMixBuf->offRead, cSrcFrames, pcSrcMixed); 1266 1265 } 1267 1266 … … 1281 1280 Log(("%s: %*s[%s] %s: offRead=%RU32, offWrite=%RU32, cMixed=%RU32 -> %RU32/%RU32\n", 1282 1281 pszFunc, uIdtLvl * 4, "", fIsParent ? "PARENT" : "CHILD", 1283 pMixBuf->pszName, pMixBuf->offRead, pMixBuf->offWrite, pMixBuf->cMixed, pMixBuf->cUsed, pMixBuf->c Samples));1282 pMixBuf->pszName, pMixBuf->offRead, pMixBuf->offWrite, pMixBuf->cMixed, pMixBuf->cUsed, pMixBuf->cFrames)); 1284 1283 } 1285 1284 … … 1292 1291 DECL_FORCE_INLINE(bool) audioMixBufDbgValidate(PPDMAUDIOMIXBUF pMixBuf) 1293 1292 { 1294 //const uint32_t offReadEnd = (pMixBuf->offRead + pMixBuf->cUsed) % pMixBuf->c Samples;1295 //const uint32_t offWriteEnd = (pMixBuf->offWrite + (pMixBuf->c Samples - pMixBuf->cUsed)) % pMixBuf->cSamples;1293 //const uint32_t offReadEnd = (pMixBuf->offRead + pMixBuf->cUsed) % pMixBuf->cFrames; 1294 //const uint32_t offWriteEnd = (pMixBuf->offWrite + (pMixBuf->cFrames - pMixBuf->cUsed)) % pMixBuf->cFrames; 1296 1295 1297 1296 bool fValid = true; 1298 1297 1299 AssertStmt(pMixBuf->offRead <= pMixBuf->c Samples, fValid = false);1300 AssertStmt(pMixBuf->offWrite <= pMixBuf->c Samples, fValid = false);1301 AssertStmt(pMixBuf->cUsed <= pMixBuf->c Samples, fValid = false);1298 AssertStmt(pMixBuf->offRead <= pMixBuf->cFrames, fValid = false); 1299 AssertStmt(pMixBuf->offWrite <= pMixBuf->cFrames, fValid = false); 1300 AssertStmt(pMixBuf->cUsed <= pMixBuf->cFrames, fValid = false); 1302 1301 1303 1302 if (pMixBuf->offWrite > pMixBuf->offRead) … … 1308 1307 else if (pMixBuf->offWrite < pMixBuf->offRead) 1309 1308 { 1310 if (pMixBuf->offWrite + pMixBuf->c Samples - pMixBuf->offRead != pMixBuf->cUsed)1309 if (pMixBuf->offWrite + pMixBuf->cFrames - pMixBuf->offRead != pMixBuf->cUsed) 1311 1310 fValid = false; 1312 1311 } … … 1409 1408 1410 1409 /** 1411 * Returns the total number of samples used.1410 * Returns the total number of frames used. 1412 1411 * 1413 1412 * @return uint32_t … … 1421 1420 1422 1421 /** 1423 * Reads audio samples at a specific offset.1422 * Reads audio frames at a specific offset. 1424 1423 * 1425 1424 * @return IPRT status code. 1426 * @param pMixBuf Mixing buffer to read audio samples from.1427 * @param off Samples Offset (in audio samples) to start reading from.1425 * @param pMixBuf Mixing buffer to read audio frames from. 1426 * @param offFrames Offset (in audio frames) to start reading from. 1428 1427 * @param pvBuf Pointer to buffer to write output to. 1429 1428 * @param cbBuf Size (in bytes) of buffer to write to. … … 1431 1430 */ 1432 1431 int AudioMixBufReadAt(PPDMAUDIOMIXBUF pMixBuf, 1433 uint32_t off Samples,1432 uint32_t offFrames, 1434 1433 void *pvBuf, uint32_t cbBuf, 1435 1434 uint32_t *pcbRead) 1436 1435 { 1437 1436 return AudioMixBufReadAtEx(pMixBuf, pMixBuf->AudioFmt, 1438 off Samples, pvBuf, cbBuf, pcbRead);1439 } 1440 1441 /** 1442 * Reads audio samples at a specific offset.1437 offFrames, pvBuf, cbBuf, pcbRead); 1438 } 1439 1440 /** 1441 * Reads audio frames at a specific offset. 1443 1442 * If the audio format of the mixing buffer and the requested audio format do 1444 1443 * not match the output will be converted accordingly. 1445 1444 * 1446 1445 * @return IPRT status code. 1447 * @param pMixBuf Mixing buffer to read audio samples from.1446 * @param pMixBuf Mixing buffer to read audio frames from. 1448 1447 * @param enmFmt Audio format to use for output. 1449 * @param off Samples Offset (in audio samples) to start reading from.1448 * @param offFrames Offset (in audio frames) to start reading from. 1450 1449 * @param pvBuf Pointer to buffer to write output to. 1451 1450 * @param cbBuf Size (in bytes) of buffer to write to. … … 1453 1452 */ 1454 1453 int AudioMixBufReadAtEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, 1455 uint32_t off Samples,1454 uint32_t offFrames, 1456 1455 void *pvBuf, uint32_t cbBuf, 1457 1456 uint32_t *pcbRead) … … 1461 1460 /* pcbRead is optional. */ 1462 1461 1463 uint32_t cDst Samples = pMixBuf->cSamples;1462 uint32_t cDstFrames = pMixBuf->cFrames; 1464 1463 uint32_t cLive = pMixBuf->cUsed; 1465 1464 1466 uint32_t cDead = cDst Samples - cLive;1467 uint32_t cToProcess = (uint32_t)AUDIOMIXBUF_ S2S_RATIO(pMixBuf, cDead);1468 cToProcess = RT_MIN(cToProcess, AUDIOMIXBUF_B2 S(pMixBuf, cbBuf));1469 1470 AUDMIXBUF_LOG(("%s: off Samples=%RU32, cLive=%RU32, cDead=%RU32, cToProcess=%RU32\n",1471 pMixBuf->pszName, off Samples, cLive, cDead, cToProcess));1465 uint32_t cDead = cDstFrames - cLive; 1466 uint32_t cToProcess = (uint32_t)AUDIOMIXBUF_F2F_RATIO(pMixBuf, cDead); 1467 cToProcess = RT_MIN(cToProcess, AUDIOMIXBUF_B2F(pMixBuf, cbBuf)); 1468 1469 AUDMIXBUF_LOG(("%s: offFrames=%RU32, cLive=%RU32, cDead=%RU32, cToProcess=%RU32\n", 1470 pMixBuf->pszName, offFrames, cLive, cDead, cToProcess)); 1472 1471 1473 1472 int rc; … … 1486 1485 /* Note: No volume handling/conversion done in the conversion-to macros (yet). */ 1487 1486 1488 convOpts.c Samples = cToProcess;1489 1490 pfnConvTo(pvBuf, pMixBuf->p Samples + offSamples, &convOpts);1487 convOpts.cFrames = cToProcess; 1488 1489 pfnConvTo(pvBuf, pMixBuf->pFrames + offFrames, &convOpts); 1491 1490 1492 1491 #ifdef DEBUG … … 1507 1506 { 1508 1507 if (pcbRead) 1509 *pcbRead = AUDIOMIXBUF_ S2B(pMixBuf, cToProcess);1510 } 1511 1512 AUDMIXBUF_LOG(("cbRead=%RU32, rc=%Rrc\n", AUDIOMIXBUF_ S2B(pMixBuf, cToProcess), rc));1508 *pcbRead = AUDIOMIXBUF_F2B(pMixBuf, cToProcess); 1509 } 1510 1511 AUDMIXBUF_LOG(("cbRead=%RU32, rc=%Rrc\n", AUDIOMIXBUF_F2B(pMixBuf, cToProcess), rc)); 1513 1512 return rc; 1514 1513 } 1515 1514 1516 1515 /** 1517 * Reads audio samples. The audio format of the mixing buffer will be used.1516 * Reads audio frames. The audio format of the mixing buffer will be used. 1518 1517 * 1519 1518 * @return IPRT status code. 1520 * @param pMixBuf Mixing buffer to read audio samples from.1519 * @param pMixBuf Mixing buffer to read audio frames from. 1521 1520 * @param pvBuf Pointer to buffer to write output to. 1522 1521 * @param cbBuf Size (in bytes) of buffer to write to. 1523 * @param pcRead Number of audio samples read. Optional.1522 * @param pcRead Number of audio frames read. Optional. 1524 1523 */ 1525 1524 int AudioMixBufReadCirc(PPDMAUDIOMIXBUF pMixBuf, void *pvBuf, uint32_t cbBuf, uint32_t *pcRead) … … 1529 1528 1530 1529 /** 1531 * Reads audio samples in a specific audio format.1530 * Reads audio frames in a specific audio format. 1532 1531 * If the audio format of the mixing buffer and the requested audio format do 1533 1532 * not match the output will be converted accordingly. 1534 1533 * 1535 1534 * @return IPRT status code. 1536 * @param pMixBuf Mixing buffer to read audio samples from.1535 * @param pMixBuf Mixing buffer to read audio frames from. 1537 1536 * @param enmFmt Audio format to use for output. 1538 1537 * @param pvBuf Pointer to buffer to write output to. 1539 1538 * @param cbBuf Size (in bytes) of buffer to write to. 1540 * @param pcRead Number of audio samples read. Optional.1539 * @param pcRead Number of audio frames read. Optional. 1541 1540 */ 1542 1541 int AudioMixBufReadCircEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, void *pvBuf, uint32_t cbBuf, uint32_t *pcRead) … … 1547 1546 /* pcRead is optional. */ 1548 1547 1549 /* Make sure that we at least have space for a full audio sample. */1550 AssertReturn(AUDIOMIXBUF_B2 S(pMixBuf, cbBuf), VERR_INVALID_PARAMETER);1551 1552 uint32_t cToRead = RT_MIN(pMixBuf->cUsed, AUDIOMIXBUF_B2 S(pMixBuf, cbBuf));1553 1554 AUDMIXBUF_LOG(("%s: cbBuf=%RU32 (%RU32 samples), cToRead=%RU32, fmtSrc=0x%x, fmtDst=0x%x\n",1555 pMixBuf->pszName, cbBuf, AUDIOMIXBUF_B2 S(pMixBuf, cbBuf), cToRead, pMixBuf->AudioFmt, enmFmt));1548 /* Make sure that we at least have space for a full audio frame. */ 1549 AssertReturn(AUDIOMIXBUF_B2F(pMixBuf, cbBuf), VERR_INVALID_PARAMETER); 1550 1551 uint32_t cToRead = RT_MIN(pMixBuf->cUsed, AUDIOMIXBUF_B2F(pMixBuf, cbBuf)); 1552 1553 AUDMIXBUF_LOG(("%s: cbBuf=%RU32 (%RU32 frames), cToRead=%RU32, fmtSrc=0x%x, fmtDst=0x%x\n", 1554 pMixBuf->pszName, cbBuf, AUDIOMIXBUF_B2F(pMixBuf, cbBuf), cToRead, pMixBuf->AudioFmt, enmFmt)); 1556 1555 1557 1556 if (!cToRead) … … 1577 1576 } 1578 1577 1579 cToRead = RT_MIN(cToRead, pMixBuf->c Samples - pMixBuf->offRead);1578 cToRead = RT_MIN(cToRead, pMixBuf->cFrames - pMixBuf->offRead); 1580 1579 if (cToRead) 1581 1580 { 1582 1581 PDMAUDMIXBUFCONVOPTS convOpts; 1583 1582 RT_ZERO(convOpts); 1584 convOpts.c Samples = cToRead;1583 convOpts.cFrames = cToRead; 1585 1584 1586 1585 AUDMIXBUF_LOG(("cToRead=%RU32\n", cToRead)); 1587 1586 1588 pfnConvTo(pvBuf, pMixBuf->p Samples + pMixBuf->offRead, &convOpts);1587 pfnConvTo(pvBuf, pMixBuf->pFrames + pMixBuf->offRead, &convOpts); 1589 1588 1590 1589 #ifdef AUDIOMIXBUF_DEBUG_DUMP_PCM_DATA … … 1594 1593 if (RT_SUCCESS(rc2)) 1595 1594 { 1596 RTFileWrite(fh, pvBuf, AUDIOMIXBUF_ S2B(pMixBuf, cToRead), NULL);1595 RTFileWrite(fh, pvBuf, AUDIOMIXBUF_F2B(pMixBuf, cToRead), NULL); 1597 1596 RTFileClose(fh); 1598 1597 } 1599 1598 #endif 1600 pMixBuf->offRead = (pMixBuf->offRead + cToRead) % pMixBuf->c Samples;1599 pMixBuf->offRead = (pMixBuf->offRead + cToRead) % pMixBuf->cFrames; 1601 1600 Assert(pMixBuf->cUsed >= cToRead); 1602 1601 pMixBuf->cUsed -= cToRead; … … 1610 1609 #endif 1611 1610 1612 AUDMIXBUF_LOG(("cRead=%RU32 (%RU32 bytes)\n", cToRead, AUDIOMIXBUF_ S2B(pMixBuf, cToRead)));1611 AUDMIXBUF_LOG(("cRead=%RU32 (%RU32 bytes)\n", cToRead, AUDIOMIXBUF_F2B(pMixBuf, cToRead))); 1613 1612 return VINF_SUCCESS; 1614 1613 } … … 1664 1663 1665 1664 /** 1666 * Returns the maximum amount of audio samples this buffer can hold.1667 * 1668 * @return uint32_t Size (in audio samples) the mixing buffer can hold.1665 * Returns the maximum amount of audio frames this buffer can hold. 1666 * 1667 * @return uint32_t Size (in audio frames) the mixing buffer can hold. 1669 1668 * @param pMixBuf Mixing buffer to retrieve maximum for. 1670 1669 */ … … 1672 1671 { 1673 1672 AssertPtrReturn(pMixBuf, 0); 1674 return pMixBuf->c Samples;1673 return pMixBuf->cFrames; 1675 1674 } 1676 1675 … … 1684 1683 { 1685 1684 AssertPtrReturn(pMixBuf, 0); 1686 return AUDIOMIXBUF_ S2B(pMixBuf, pMixBuf->cSamples);1685 return AUDIOMIXBUF_F2B(pMixBuf, pMixBuf->cFrames); 1687 1686 } 1688 1687 … … 1749 1748 1750 1749 /** 1751 * Writes audio samples at a specific offset.1750 * Writes audio frames at a specific offset. 1752 1751 * The sample format being written must match the format of the mixing buffer. 1753 1752 * 1754 1753 * @return IPRT status code. 1755 1754 * @param pMixBuf Pointer to mixing buffer to write to. 1756 * @param off Samples Offset (in samples) starting to write at.1755 * @param offFrames Offset (in frames) starting to write at. 1757 1756 * @param pvBuf Pointer to audio buffer to be written. 1758 1757 * @param cbBuf Size (in bytes) of audio buffer. 1759 * @param pcWritten Returns number of audio samples written. Optional.1760 */ 1761 int AudioMixBufWriteAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t off Samples, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten)1762 { 1763 return AudioMixBufWriteAtEx(pMixBuf, pMixBuf->AudioFmt, off Samples, pvBuf, cbBuf, pcWritten);1764 } 1765 1766 /** 1767 * Writes audio samples at a specific offset.1758 * @param pcWritten Returns number of audio frames written. Optional. 1759 */ 1760 int AudioMixBufWriteAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offFrames, const void *pvBuf, uint32_t cbBuf, uint32_t *pcWritten) 1761 { 1762 return AudioMixBufWriteAtEx(pMixBuf, pMixBuf->AudioFmt, offFrames, pvBuf, cbBuf, pcWritten); 1763 } 1764 1765 /** 1766 * Writes audio frames at a specific offset. 1768 1767 * 1769 1768 * Note that this operation also modifies the current read and write position 1770 * to \a off Samples + written samples on success.1769 * to \a offFrames + written frames on success. 1771 1770 * 1772 1771 * The audio sample format to be written can be different from the audio format … … 1776 1775 * @param pMixBuf Pointer to mixing buffer to write to. 1777 1776 * @param enmFmt Audio format supplied in the buffer. 1778 * @param off Samples Offset (in samples) starting to write at.1777 * @param offFrames Offset (in frames) starting to write at. 1779 1778 * @param pvBuf Pointer to audio buffer to be written. 1780 1779 * @param cbBuf Size (in bytes) of audio buffer. 1781 * @param pcWritten Returns number of audio samples written. Optional.1780 * @param pcWritten Returns number of audio frames written. Optional. 1782 1781 */ 1783 1782 int AudioMixBufWriteAtEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, 1784 uint32_t off Samples, const void *pvBuf, uint32_t cbBuf,1783 uint32_t offFrames, const void *pvBuf, uint32_t cbBuf, 1785 1784 uint32_t *pcWritten) 1786 1785 { … … 1790 1789 /* pcbWritten is optional. */ 1791 1790 1792 if (off Samples >= pMixBuf->cSamples)1791 if (offFrames >= pMixBuf->cFrames) 1793 1792 { 1794 1793 if (pcWritten) … … 1800 1799 * Adjust cToWrite so we don't overflow our buffers. 1801 1800 */ 1802 uint32_t cToWrite = RT_MIN(AUDIOMIXBUF_B2 S(pMixBuf, cbBuf), pMixBuf->cSamples - offSamples);1801 uint32_t cToWrite = RT_MIN(AUDIOMIXBUF_B2F(pMixBuf, cbBuf), pMixBuf->cFrames - offFrames); 1803 1802 1804 1803 #ifdef AUDIOMIXBUF_DEBUG_DUMP_PCM_DATA … … 1811 1810 if (RT_SUCCESS(rc2)) 1812 1811 { 1813 RTFileWrite(hFile, pvBuf, AUDIOMIXBUF_ S2B(pMixBuf, cToWrite), NULL);1812 RTFileWrite(hFile, pvBuf, AUDIOMIXBUF_F2B(pMixBuf, cToWrite), NULL); 1814 1813 RTFileClose(hFile); 1815 1814 } … … 1838 1837 PDMAUDMIXBUFCONVOPTS convOpts; 1839 1838 1840 convOpts.c Samples = cToWrite;1839 convOpts.cFrames = cToWrite; 1841 1840 convOpts.From.Volume.fMuted = pMixBuf->Volume.fMuted; 1842 1841 convOpts.From.Volume.uLeft = pMixBuf->Volume.uLeft; 1843 1842 convOpts.From.Volume.uRight = pMixBuf->Volume.uRight; 1844 1843 1845 cWritten = pfnConvFrom(pMixBuf->p Samples + offSamples, pvBuf, AUDIOMIXBUF_S2B(pMixBuf, cToWrite), &convOpts);1844 cWritten = pfnConvFrom(pMixBuf->pFrames + offFrames, pvBuf, AUDIOMIXBUF_F2B(pMixBuf, cToWrite), &convOpts); 1846 1845 } 1847 1846 else … … 1855 1854 } 1856 1855 1857 AUDMIXBUF_LOG(("%s: off Samples=%RU32, cbBuf=%RU32, cToWrite=%RU32 (%zu bytes), cWritten=%RU32 (%zu bytes), rc=%Rrc\n",1858 pMixBuf->pszName, off Samples, cbBuf,1859 cToWrite, AUDIOMIXBUF_ S2B(pMixBuf, cToWrite),1860 cWritten, AUDIOMIXBUF_ S2B(pMixBuf, cWritten), rc));1856 AUDMIXBUF_LOG(("%s: offFrames=%RU32, cbBuf=%RU32, cToWrite=%RU32 (%zu bytes), cWritten=%RU32 (%zu bytes), rc=%Rrc\n", 1857 pMixBuf->pszName, offFrames, cbBuf, 1858 cToWrite, AUDIOMIXBUF_F2B(pMixBuf, cToWrite), 1859 cWritten, AUDIOMIXBUF_F2B(pMixBuf, cWritten), rc)); 1861 1860 1862 1861 if (RT_SUCCESS(rc)) 1863 1862 { 1864 pMixBuf->offRead = off Samples % pMixBuf->cSamples;1865 pMixBuf->offWrite = (off Samples + cWritten) % pMixBuf->cSamples;1863 pMixBuf->offRead = offFrames % pMixBuf->cFrames; 1864 pMixBuf->offWrite = (offFrames + cWritten) % pMixBuf->cFrames; 1866 1865 pMixBuf->cUsed = cWritten; 1867 1866 pMixBuf->cMixed = 0; … … 1880 1879 1881 1880 /** 1882 * Writes audio samples.1881 * Writes audio frames. 1883 1882 * 1884 1883 * The sample format being written must match the format of the mixing buffer. 1885 1884 * 1886 * @return IPRT status code, or VERR_BUFFER_OVERFLOW if samples which not have1885 * @return IPRT status code, or VERR_BUFFER_OVERFLOW if frames which not have 1887 1886 * been processed yet have been overwritten (due to cyclic buffer). 1888 1887 * @param pMixBuf Pointer to mixing buffer to write to. 1889 1888 * @param pvBuf Pointer to audio buffer to be written. 1890 1889 * @param cbBuf Size (in bytes) of audio buffer. 1891 * @param pcWritten Returns number of audio samples written. Optional.1890 * @param pcWritten Returns number of audio frames written. Optional. 1892 1891 */ 1893 1892 int AudioMixBufWriteCirc(PPDMAUDIOMIXBUF pMixBuf, … … 1899 1898 1900 1899 /** 1901 * Writes audio samples of a specific format.1900 * Writes audio frames of a specific format. 1902 1901 * This function might write less data at once than requested. 1903 1902 * … … 1907 1906 * @param pvBuf Pointer to audio buffer to be written. 1908 1907 * @param cbBuf Size (in bytes) of audio buffer. 1909 * @param pcWritten Returns number of audio samples written. Optional.1908 * @param pcWritten Returns number of audio frames written. Optional. 1910 1909 */ 1911 1910 int AudioMixBufWriteCircEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, … … 1923 1922 } 1924 1923 1925 /* Make sure that we at least write a full audio sample. */1926 AssertReturn(AUDIOMIXBUF_B2 S(pMixBuf, cbBuf), VERR_INVALID_PARAMETER);1927 1928 Assert(pMixBuf->c Samples);1929 AssertPtr(pMixBuf->p Samples);1924 /* Make sure that we at least write a full audio frame. */ 1925 AssertReturn(AUDIOMIXBUF_B2F(pMixBuf, cbBuf), VERR_INVALID_PARAMETER); 1926 1927 Assert(pMixBuf->cFrames); 1928 AssertPtr(pMixBuf->pFrames); 1930 1929 1931 1930 PFNPDMAUDIOMIXBUFCONVFROM pfnConvFrom = NULL; … … 1950 1949 uint32_t cWritten = 0; 1951 1950 1952 uint32_t cFree = pMixBuf->c Samples - pMixBuf->cUsed;1951 uint32_t cFree = pMixBuf->cFrames - pMixBuf->cUsed; 1953 1952 if (cFree) 1954 1953 { 1955 if ((pMixBuf->c Samples - pMixBuf->offWrite) == 0)1954 if ((pMixBuf->cFrames - pMixBuf->offWrite) == 0) 1956 1955 pMixBuf->offWrite = 0; 1957 1956 1958 uint32_t cToWrite = RT_MIN(AUDIOMIXBUF_B2 S(pMixBuf, cbBuf), RT_MIN(pMixBuf->cSamples - pMixBuf->offWrite, cFree));1957 uint32_t cToWrite = RT_MIN(AUDIOMIXBUF_B2F(pMixBuf, cbBuf), RT_MIN(pMixBuf->cFrames - pMixBuf->offWrite, cFree)); 1959 1958 Assert(cToWrite); 1960 1959 … … 1966 1965 convOpts.From.Volume.uRight = pMixBuf->Volume.uRight; 1967 1966 1968 convOpts.c Samples = cToWrite;1969 1970 cWritten = pfnConvFrom(pMixBuf->p Samples + pMixBuf->offWrite,1971 pvBuf, AUDIOMIXBUF_ S2B(pMixBuf, cToWrite), &convOpts);1967 convOpts.cFrames = cToWrite; 1968 1969 cWritten = pfnConvFrom(pMixBuf->pFrames + pMixBuf->offWrite, 1970 pvBuf, AUDIOMIXBUF_F2B(pMixBuf, cToWrite), &convOpts); 1972 1971 Assert(cWritten == cToWrite); 1973 1972 … … 1976 1975 RTFileOpen(&fh, AUDIOMIXBUF_DEBUG_DUMP_PCM_DATA_PATH "mixbuf_writecirc_ex.pcm", 1977 1976 RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND | RTFILE_O_WRITE | RTFILE_O_DENY_NONE); 1978 RTFileWrite(fh, pvBuf, AUDIOMIXBUF_ S2B(pMixBuf, cToWrite), NULL);1977 RTFileWrite(fh, pvBuf, AUDIOMIXBUF_F2B(pMixBuf, cToWrite), NULL); 1979 1978 RTFileClose(fh); 1980 1979 #endif 1981 1980 pMixBuf->cUsed += cWritten; 1982 Assert(pMixBuf->cUsed <= pMixBuf->c Samples);1983 1984 pMixBuf->offWrite = (pMixBuf->offWrite + cWritten) % pMixBuf->c Samples;1985 Assert(pMixBuf->offWrite <= pMixBuf->c Samples);1981 Assert(pMixBuf->cUsed <= pMixBuf->cFrames); 1982 1983 pMixBuf->offWrite = (pMixBuf->offWrite + cWritten) % pMixBuf->cFrames; 1984 Assert(pMixBuf->offWrite <= pMixBuf->cFrames); 1986 1985 } 1987 1986 else … … 1996 1995 *pcWritten = cWritten; 1997 1996 1998 AUDMIXBUF_LOG(("%s: enmFmt=0x%x, cbBuf=%RU32 (%RU32 samples), cWritten=%RU32, rc=%Rrc\n",1999 pMixBuf->pszName, enmFmt, cbBuf, AUDIOMIXBUF_B2 S(pMixBuf, cbBuf), cWritten, rc));1997 AUDMIXBUF_LOG(("%s: enmFmt=0x%x, cbBuf=%RU32 (%RU32 frames), cWritten=%RU32, rc=%Rrc\n", 1998 pMixBuf->pszName, enmFmt, cbBuf, AUDIOMIXBUF_B2F(pMixBuf, cbBuf), cWritten, rc)); 2000 1999 return rc; 2001 2000 } -
trunk/src/VBox/Devices/Audio/AudioMixBuffer.h
r67365 r68132 37 37 #define AUDMIXBUF_FMT_BYTES_PER_SAMPLE(a) ((AUDMIXBUF_AUDIO_FMT_BITS_PER_SAMPLE(a) + 7) / 8) 38 38 39 /** Converts samples to bytes. */40 #define AUDIOMIXBUF_ S2B(pBuf, samples) ((samples) << (pBuf)->cShift)41 /** Converts samples to bytes, respecting the conversion ratio to39 /** Converts frames to bytes. */ 40 #define AUDIOMIXBUF_F2B(pBuf, frames) ((frames) << (pBuf)->cShift) 41 /** Converts frames to bytes, respecting the conversion ratio to 42 42 * a linked buffer. */ 43 #define AUDIOMIXBUF_ S2B_RATIO(pBuf, samples) ((((int64_t) samples << 32) / (pBuf)->iFreqRatio) << (pBuf)->cShift)44 /** Converts bytes to samples, *not* taking the conversion ratio43 #define AUDIOMIXBUF_F2B_RATIO(pBuf, frames) ((((int64_t) frames << 32) / (pBuf)->iFreqRatio) << (pBuf)->cShift) 44 /** Converts bytes to frames, *not* taking the conversion ratio 45 45 * into account. */ 46 #define AUDIOMIXBUF_B2 S(pBuf, cb) (cb >> (pBuf)->cShift)47 /** Converts number of samples according to the buffer's ratio. */48 #define AUDIOMIXBUF_ S2S_RATIO(pBuf, samples) (((int64_t) samples << 32) / (pBuf)->iFreqRatio)46 #define AUDIOMIXBUF_B2F(pBuf, cb) (cb >> (pBuf)->cShift) 47 /** Converts number of frames according to the buffer's ratio. */ 48 #define AUDIOMIXBUF_F2F_RATIO(pBuf, frames) (((int64_t) frames << 32) / (pBuf)->iFreqRatio) 49 49 50 50 … … 52 52 void AudioMixBufClear(PPDMAUDIOMIXBUF pMixBuf); 53 53 void AudioMixBufDestroy(PPDMAUDIOMIXBUF pMixBuf); 54 void AudioMixBufFinish(PPDMAUDIOMIXBUF pMixBuf, uint32_t c SamplesToClear);54 void AudioMixBufFinish(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFramesToClear); 55 55 uint32_t AudioMixBufFree(PPDMAUDIOMIXBUF pMixBuf); 56 56 uint32_t AudioMixBufFreeBytes(PPDMAUDIOMIXBUF pMixBuf); 57 int AudioMixBufInit(PPDMAUDIOMIXBUF pMixBuf, const char *pszName, PPDMAUDIOPCMPROPS pProps, uint32_t c Samples);57 int AudioMixBufInit(PPDMAUDIOMIXBUF pMixBuf, const char *pszName, PPDMAUDIOPCMPROPS pProps, uint32_t cFrames); 58 58 bool AudioMixBufIsEmpty(PPDMAUDIOMIXBUF pMixBuf); 59 59 int AudioMixBufLinkTo(PPDMAUDIOMIXBUF pMixBuf, PPDMAUDIOMIXBUF pParent); 60 60 uint32_t AudioMixBufLive(PPDMAUDIOMIXBUF pMixBuf); 61 int AudioMixBufMixToParent(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSrc Samples, uint32_t *pcSrcMixed);62 int AudioMixBufMixToParentEx(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSrcOffset, uint32_t cSrc Samples, uint32_t *pcSrcMixed);63 int AudioMixBufPeek(PPDMAUDIOMIXBUF pMixBuf, uint32_t c SamplesToRead, PPDMAUDIOSAMPLE paSampleBuf, uint32_t cSampleBuf, uint32_t *pcSamplesRead);64 int AudioMixBufPeekMutable(PPDMAUDIOMIXBUF pMixBuf, uint32_t c SamplesToRead, PPDMAUDIOSAMPLE *ppvSamples, uint32_t *pcSamplesRead);61 int AudioMixBufMixToParent(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSrcFrames, uint32_t *pcSrcMixed); 62 int AudioMixBufMixToParentEx(PPDMAUDIOMIXBUF pMixBuf, uint32_t cSrcOffset, uint32_t cSrcFrames, uint32_t *pcSrcMixed); 63 int AudioMixBufPeek(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFramesToRead, PPDMAUDIOFRAME paSampleBuf, uint32_t cSampleBuf, uint32_t *pcFramesRead); 64 int AudioMixBufPeekMutable(PPDMAUDIOMIXBUF pMixBuf, uint32_t cFramesToRead, PPDMAUDIOFRAME *ppvSamples, uint32_t *pcFramesRead); 65 65 uint32_t AudioMixBufUsed(PPDMAUDIOMIXBUF pMixBuf); 66 66 int AudioMixBufReadAt(PPDMAUDIOMIXBUF pMixBuf, uint32_t offSamples, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead); -
trunk/src/VBox/Devices/Audio/AudioMixer.cpp
r68021 r68132 1440 1440 AssertPtr(pConn); 1441 1441 1442 uint32_t c sProc = 0;1442 uint32_t cfProc = 0; 1443 1443 1444 1444 int rc2 = pConn->pfnStreamIterate(pConn, pStream); … … 1447 1447 if (pSink->enmDir == AUDMIXSINKDIR_INPUT) 1448 1448 { 1449 rc = pConn->pfnStreamCapture(pConn, pStream, &c sProc);1449 rc = pConn->pfnStreamCapture(pConn, pStream, &cfProc); 1450 1450 if (RT_FAILURE(rc2)) 1451 1451 { … … 1456 1456 } 1457 1457 1458 if (c sProc)1458 if (cfProc) 1459 1459 pSink->fStatus |= AUDMIXSINK_STS_DIRTY; 1460 1460 } 1461 1461 else if (pSink->enmDir == AUDMIXSINKDIR_OUTPUT) 1462 1462 { 1463 rc2 = pConn->pfnStreamPlay(pConn, pStream, &c sProc);1463 rc2 = pConn->pfnStreamPlay(pConn, pStream, &cfProc); 1464 1464 if (RT_FAILURE(rc2)) 1465 1465 { … … 1495 1495 } 1496 1496 1497 Log3Func(("\t%s: cPlayed/cCaptured=%RU32, rc2=%Rrc\n", pStream->szName, c sProc, rc2));1497 Log3Func(("\t%s: cPlayed/cCaptured=%RU32, rc2=%Rrc\n", pStream->szName, cfProc, rc2)); 1498 1498 } 1499 1499 -
trunk/src/VBox/Devices/Audio/DevHDA.cpp
r68021 r68132 2690 2690 RTListForEach(&pThis->lstDrv, pDrv, HDADRIVER, Node) 2691 2691 { 2692 uint32_t c SamplesPlayed;2693 int rc2 = pDrv->pConnector->pfnPlay(pDrv->pConnector, &c SamplesPlayed);2694 LogFlowFunc(("LUN#%RU8: c SamplesPlayed=%RU32, rc=%Rrc\n", pDrv->uLUN, cSamplesPlayed, rc2));2692 uint32_t cFramesPlayed; 2693 int rc2 = pDrv->pConnector->pfnPlay(pDrv->pConnector, &cFramesPlayed); 2694 LogFlowFunc(("LUN#%RU8: cFramesPlayed=%RU32, rc=%Rrc\n", pDrv->uLUN, cFramesPlayed, rc2)); 2695 2695 } 2696 2696 } -
trunk/src/VBox/Devices/Audio/DrvAudio.cpp
r68076 r68132 645 645 #endif 646 646 647 /* No sample buffer size hint given by the backend? Default to some sane value. */648 if (!CfgHostAcq.c SampleBufferHint)649 { 650 CfgHostAcq.c SampleBufferHint = _1K; /** @todo Make this configurable? */647 /* No frame buffer size hint given by the backend? Default to some sane value. */ 648 if (!CfgHostAcq.cFrameBufferHint) 649 { 650 CfgHostAcq.cFrameBufferHint = _1K; /** @todo Make this configurable? */ 651 651 } 652 652 … … 658 658 659 659 /* Set set host buffer size multiplicator. */ 660 const unsigned c SampleBufferHostFactor = 2; /** @todo Make this configurable. */661 662 LogFunc(("[%s] c Samples=%RU32 (x %u)\n", pHstStream->szName, CfgHostAcq.cSampleBufferHint, cSampleBufferHostFactor));660 const unsigned cFrameBufferHostFactor = 2; /** @todo Make this configurable. */ 661 662 LogFunc(("[%s] cFrames=%RU32 (x %u)\n", pHstStream->szName, CfgHostAcq.cFrameBufferHint, cFrameBufferHostFactor)); 663 663 664 664 int rc2 = AudioMixBufInit(&pHstStream->MixBuf, pHstStream->szName, &CfgHostAcq.Props, 665 CfgHostAcq.c SampleBufferHint * cSampleBufferHostFactor);665 CfgHostAcq.cFrameBufferHint * cFrameBufferHostFactor); 666 666 AssertRC(rc2); 667 667 … … 684 684 685 685 /* Set set guest buffer size multiplicator. */ 686 const unsigned c SampleBufferGuestFactor = 10; /** @todo Make this configurable. */687 688 LogFunc(("[%s] c Samples=%RU32 (x %u)\n", pGstStream->szName, CfgHostAcq.cSampleBufferHint, cSampleBufferGuestFactor));686 const unsigned cFrameBufferGuestFactor = 10; /** @todo Make this configurable. */ 687 688 LogFunc(("[%s] cFrames=%RU32 (x %u)\n", pGstStream->szName, CfgHostAcq.cFrameBufferHint, cFrameBufferGuestFactor)); 689 689 690 690 rc2 = AudioMixBufInit(&pGstStream->MixBuf, pGstStream->szName, &pCfgGuest->Props, 691 CfgHostAcq.c SampleBufferHint * cSampleBufferGuestFactor);691 CfgHostAcq.cFrameBufferHint * cFrameBufferGuestFactor); 692 692 AssertRC(rc2); 693 693 … … 834 834 STAM_COUNTER_RESET(&pHstStream->In.StatBytesElapsed); 835 835 STAM_COUNTER_RESET(&pHstStream->In.StatBytesTotalRead); 836 STAM_COUNTER_RESET(&pHstStream->In.Stat SamplesCaptured);836 STAM_COUNTER_RESET(&pHstStream->In.StatFramesCaptured); 837 837 838 838 if (pGstStream) … … 842 842 STAM_COUNTER_RESET(&pGstStream->In.StatBytesElapsed); 843 843 STAM_COUNTER_RESET(&pGstStream->In.StatBytesTotalRead); 844 STAM_COUNTER_RESET(&pGstStream->In.Stat SamplesCaptured);844 STAM_COUNTER_RESET(&pGstStream->In.StatFramesCaptured); 845 845 } 846 846 } … … 849 849 STAM_COUNTER_RESET(&pHstStream->Out.StatBytesElapsed); 850 850 STAM_COUNTER_RESET(&pHstStream->Out.StatBytesTotalWritten); 851 STAM_COUNTER_RESET(&pHstStream->Out.Stat SamplesPlayed);851 STAM_COUNTER_RESET(&pHstStream->Out.StatFramesPlayed); 852 852 853 853 if (pGstStream) … … 857 857 STAM_COUNTER_RESET(&pGstStream->Out.StatBytesElapsed); 858 858 STAM_COUNTER_RESET(&pGstStream->Out.StatBytesTotalWritten); 859 STAM_COUNTER_RESET(&pGstStream->Out.Stat SamplesPlayed);859 STAM_COUNTER_RESET(&pGstStream->Out.StatFramesPlayed); 860 860 } 861 861 } … … 953 953 /* We use the guest side mixing buffer as an intermediate buffer to do some 954 954 * (first) processing (if needed), so always write the incoming data at offset 0. */ 955 uint32_t c sWritten = 0;956 rc = AudioMixBufWriteAt(&pGstStream->MixBuf, 0 /* off Samples */, pvBuf, cbBuf, &csWritten);955 uint32_t cfWritten = 0; 956 rc = AudioMixBufWriteAt(&pGstStream->MixBuf, 0 /* offFrames */, pvBuf, cbBuf, &cfWritten); 957 957 if ( RT_FAILURE(rc) 958 || !c sWritten)959 { 960 AssertMsgFailed(("[%s] Write failed: cbBuf=%RU32, c sWritten=%RU32, rc=%Rrc\n",961 pGstStream->szName, cbBuf, c sWritten, rc));958 || !cfWritten) 959 { 960 AssertMsgFailed(("[%s] Write failed: cbBuf=%RU32, cfWritten=%RU32, rc=%Rrc\n", 961 pGstStream->szName, cbBuf, cfWritten, rc)); 962 962 break; 963 963 } … … 968 968 969 969 #ifdef VBOX_WITH_STATISTICS 970 STAM_COUNTER_ADD(&pThis->Stats.Total SamplesWritten, csWritten);971 #endif 972 uint32_t c sMixed = 0;973 if (c sWritten)974 { 975 int rc2 = AudioMixBufMixToParentEx(&pGstStream->MixBuf, 0 /* Offset */, c sWritten /* Samples */, &csMixed);970 STAM_COUNTER_ADD(&pThis->Stats.TotalFramesWritten, cfWritten); 971 #endif 972 uint32_t cfMixed = 0; 973 if (cfWritten) 974 { 975 int rc2 = AudioMixBufMixToParentEx(&pGstStream->MixBuf, 0 /* Offset */, cfWritten /* Frames */, &cfMixed); 976 976 if ( RT_FAILURE(rc2) 977 || c sMixed < csWritten)977 || cfMixed < cfWritten) 978 978 { 979 AssertMsgFailed(("[%s] Mixing failed: cbBuf=%RU32, c sWritten=%RU32, csMixed=%RU32, rc=%Rrc\n",980 pGstStream->szName, cbBuf, c sWritten, csMixed, rc2));981 982 LogRel2(("Audio: Lost audio samples (%RU32) due to full host stream '%s', expect stuttering audio output\n",983 c sWritten - csMixed, pHstStream->szName));979 AssertMsgFailed(("[%s] Mixing failed: cbBuf=%RU32, cfWritten=%RU32, cfMixed=%RU32, rc=%Rrc\n", 980 pGstStream->szName, cbBuf, cfWritten, cfMixed, rc2)); 981 982 LogRel2(("Audio: Lost audio frames (%RU32) due to full host stream '%s', expect stuttering audio output\n", 983 cfWritten - cfMixed, pHstStream->szName)); 984 984 985 985 /* Keep going. */ … … 989 989 rc = rc2; 990 990 991 cbWritten = AUDIOMIXBUF_ S2B(&pGstStream->MixBuf, csWritten);991 cbWritten = AUDIOMIXBUF_F2B(&pGstStream->MixBuf, cfWritten); 992 992 993 993 #ifdef VBOX_WITH_STATISTICS 994 STAM_COUNTER_ADD(&pThis->Stats.Total SamplesMixedOut, csMixed);995 Assert(c sWritten >= csMixed);996 STAM_COUNTER_ADD(&pThis->Stats.Total SamplesLostOut, csWritten - csMixed);994 STAM_COUNTER_ADD(&pThis->Stats.TotalFramesMixedOut, cfMixed); 995 Assert(cfWritten >= cfMixed); 996 STAM_COUNTER_ADD(&pThis->Stats.TotalFramesLostOut, cfWritten - cfMixed); 997 997 STAM_COUNTER_ADD(&pThis->Stats.TotalBytesWritten, cbWritten); 998 998 STAM_COUNTER_ADD(&pGstStream->Out.StatBytesTotalWritten, cbWritten); … … 1002 1002 Log3Func(("[%s] cbBuf=%RU32, cUsed=%RU32, cLive=%RU32, cWritten=%RU32, cMixed=%RU32, rc=%Rrc\n", 1003 1003 pGstStream->szName, 1004 cbBuf, AudioMixBufUsed(&pGstStream->MixBuf), AudioMixBufLive(&pGstStream->MixBuf), c sWritten, csMixed, rc));1004 cbBuf, AudioMixBufUsed(&pGstStream->MixBuf), AudioMixBufLive(&pGstStream->MixBuf), cfWritten, cfMixed, rc)); 1005 1005 1006 1006 } while (0); … … 1143 1143 do 1144 1144 { 1145 uint32_t c sMixed = 0;1145 uint32_t cfMixed = 0; 1146 1146 1147 1147 rc = pThis->pHostDrvAudio->pfnStreamIterate(pThis->pHostDrvAudio, pHstStream->pvBackend); … … 1151 1151 if (pHstStream->enmDir == PDMAUDIODIR_IN) 1152 1152 { 1153 /* Has the host captured any samples which were not mixed to the guest side yet? */1154 uint32_t c sCaptured = AudioMixBufUsed(&pHstStream->MixBuf);1155 if (c sCaptured)1153 /* Has the host captured any frames which were not mixed to the guest side yet? */ 1154 uint32_t cfCaptured = AudioMixBufUsed(&pHstStream->MixBuf); 1155 if (cfCaptured) 1156 1156 { 1157 /* When capturing samples, the guest is the parent while the host is the child.1158 * So try mixing not yet mixed host-side samples to the guest-side buffer. */1159 rc = AudioMixBufMixToParent(&pHstStream->MixBuf, c sCaptured, &csMixed);1157 /* When capturing frames, the guest is the parent while the host is the child. 1158 * So try mixing not yet mixed host-side frames to the guest-side buffer. */ 1159 rc = AudioMixBufMixToParent(&pHstStream->MixBuf, cfCaptured, &cfMixed); 1160 1160 if (RT_FAILURE(rc)) 1161 1161 { … … 1170 1170 1171 1171 #ifdef VBOX_WITH_STATISTICS 1172 STAM_COUNTER_ADD(&pThis->Stats.Total SamplesMixedIn, csMixed);1173 Assert(c sCaptured >= csMixed);1174 STAM_COUNTER_ADD(&pThis->Stats.Total SamplesLostIn, csCaptured - csMixed);1175 #endif 1176 Log3Func(("[%s] %RU32/%RU32 input samples mixed, rc=%Rrc\n", pHstStream->szName, csMixed, csCaptured, rc));1172 STAM_COUNTER_ADD(&pThis->Stats.TotalFramesMixedIn, cfMixed); 1173 Assert(cfCaptured >= cfMixed); 1174 STAM_COUNTER_ADD(&pThis->Stats.TotalFramesLostIn, cfCaptured - cfMixed); 1175 #endif 1176 Log3Func(("[%s] %RU32/%RU32 input frames mixed, rc=%Rrc\n", pHstStream->szName, cfMixed, cfCaptured, rc)); 1177 1177 } 1178 1178 else … … 1257 1257 * @param pThis Pointer to driver instance. 1258 1258 * @param pHstStream Host stream to play. 1259 * @param c sToPlay Number of audio samples to play.1260 * @param pc sPlayed Returns number of audio samples played. Optional.1259 * @param cfToPlay Number of audio frames to play. 1260 * @param pcfPlayed Returns number of audio frames played. Optional. 1261 1261 */ 1262 1262 static int drvAudioStreamPlayNonInterleaved(PDRVAUDIO pThis, 1263 PPDMAUDIOSTREAM pHstStream, uint32_t c sToPlay, uint32_t *pcsPlayed)1263 PPDMAUDIOSTREAM pHstStream, uint32_t cfToPlay, uint32_t *pcfPlayed) 1264 1264 { 1265 1265 AssertPtrReturn(pThis, VERR_INVALID_POINTER); 1266 1266 AssertPtrReturn(pHstStream, VERR_INVALID_POINTER); 1267 /* pc sPlayed is optional. */1267 /* pcfPlayed is optional. */ 1268 1268 1269 1269 /* Sanity. */ … … 1272 1272 Assert(pHstStream->Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED); 1273 1273 1274 if (!c sToPlay)1275 { 1276 if (pc sPlayed)1277 *pc sPlayed = 0;1274 if (!cfToPlay) 1275 { 1276 if (pcfPlayed) 1277 *pcfPlayed = 0; 1278 1278 return VINF_SUCCESS; 1279 1279 } … … 1281 1281 int rc = VINF_SUCCESS; 1282 1282 1283 uint32_t c sPlayedTotal = 0;1283 uint32_t cfPlayedTotal = 0; 1284 1284 1285 1285 AssertPtr(pThis->pHostDrvAudio->pfnStreamGetWritable); … … 1287 1287 if (cbWritable) 1288 1288 { 1289 if (c sToPlay > AUDIOMIXBUF_B2S(&pHstStream->MixBuf, cbWritable)) /* More samples available than we can write? Limit. */1290 c sToPlay = AUDIOMIXBUF_B2S(&pHstStream->MixBuf, cbWritable);1291 1292 if (c sToPlay)1289 if (cfToPlay > AUDIOMIXBUF_B2F(&pHstStream->MixBuf, cbWritable)) /* More frames available than we can write? Limit. */ 1290 cfToPlay = AUDIOMIXBUF_B2F(&pHstStream->MixBuf, cbWritable); 1291 1292 if (cfToPlay) 1293 1293 { 1294 1294 uint8_t auBuf[256]; /** @todo Get rid of this here. */ 1295 1295 1296 uint32_t cbLeft = AUDIOMIXBUF_ S2B(&pHstStream->MixBuf, csToPlay);1296 uint32_t cbLeft = AUDIOMIXBUF_F2B(&pHstStream->MixBuf, cfToPlay); 1297 1297 uint32_t cbChunk = sizeof(auBuf); 1298 1298 1299 1299 while (cbLeft) 1300 1300 { 1301 uint32_t c sRead = 0;1302 rc = AudioMixBufReadCirc(&pHstStream->MixBuf, auBuf, RT_MIN(cbChunk, cbLeft), &c sRead);1303 if ( !c sRead1301 uint32_t cfRead = 0; 1302 rc = AudioMixBufReadCirc(&pHstStream->MixBuf, auBuf, RT_MIN(cbChunk, cbLeft), &cfRead); 1303 if ( !cfRead 1304 1304 || RT_FAILURE(rc)) 1305 1305 { … … 1307 1307 } 1308 1308 1309 uint32_t cbRead = AUDIOMIXBUF_ S2B(&pHstStream->MixBuf, csRead);1309 uint32_t cbRead = AUDIOMIXBUF_F2B(&pHstStream->MixBuf, cfRead); 1310 1310 Assert(cbRead <= cbChunk); 1311 1311 … … 1326 1326 #if 0 /** @todo Also handle mono channels. Needs fixing */ 1327 1327 AssertMsg(cbPlayed % 2 == 0, 1328 ("Backend for stream '%s' returned uneven played bytes count (c sRead=%RU32, cbPlayed=%RU32)\n",1329 pHstStream->szName, c sRead, cbPlayed));*/1330 #endif 1331 c sPlayedTotal += AUDIOMIXBUF_B2S(&pHstStream->MixBuf, cbPlayed);1328 ("Backend for stream '%s' returned uneven played bytes count (cfRead=%RU32, cbPlayed=%RU32)\n", 1329 pHstStream->szName, cfRead, cbPlayed));*/ 1330 #endif 1331 cfPlayedTotal += AUDIOMIXBUF_B2F(&pHstStream->MixBuf, cbPlayed); 1332 1332 Assert(cbLeft >= cbPlayed); 1333 1333 cbLeft -= cbPlayed; … … 1336 1336 } 1337 1337 1338 Log3Func(("[%s] Played %RU32/%RU32 samples, rc=%Rrc\n", pHstStream->szName, csPlayedTotal, csToPlay, rc));1338 Log3Func(("[%s] Played %RU32/%RU32 frames, rc=%Rrc\n", pHstStream->szName, cfPlayedTotal, cfToPlay, rc)); 1339 1339 1340 1340 if (RT_SUCCESS(rc)) 1341 1341 { 1342 if (pc sPlayed)1343 *pc sPlayed = csPlayedTotal;1342 if (pcfPlayed) 1343 *pcfPlayed = cfPlayedTotal; 1344 1344 } 1345 1345 … … 1353 1353 * @param pThis Pointer to driver instance. 1354 1354 * @param pHstStream Host stream to play. 1355 * @param c sToPlay Number of audio samples to play.1356 * @param pc sPlayed Returns number of audio samples played. Optional.1355 * @param cfToPlay Number of audio frames to play. 1356 * @param pcfPlayed Returns number of audio frames played. Optional. 1357 1357 */ 1358 1358 static int drvAudioStreamPlayRaw(PDRVAUDIO pThis, 1359 PPDMAUDIOSTREAM pHstStream, uint32_t c sToPlay, uint32_t *pcsPlayed)1359 PPDMAUDIOSTREAM pHstStream, uint32_t cfToPlay, uint32_t *pcfPlayed) 1360 1360 { 1361 1361 AssertPtrReturn(pThis, VERR_INVALID_POINTER); 1362 1362 AssertPtrReturn(pHstStream, VERR_INVALID_POINTER); 1363 /* pc sPlayed is optional. */1363 /* pcfPlayed is optional. */ 1364 1364 1365 1365 /* Sanity. */ … … 1368 1368 Assert(pHstStream->Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_RAW); 1369 1369 1370 if (!c sToPlay)1371 { 1372 if (pc sPlayed)1373 *pc sPlayed = 0;1370 if (!cfToPlay) 1371 { 1372 if (pcfPlayed) 1373 *pcfPlayed = 0; 1374 1374 return VINF_SUCCESS; 1375 1375 } … … 1377 1377 int rc = VINF_SUCCESS; 1378 1378 1379 uint32_t c sPlayedTotal = 0;1379 uint32_t cfPlayedTotal = 0; 1380 1380 1381 1381 AssertPtr(pThis->pHostDrvAudio->pfnStreamGetWritable); 1382 uint32_t c sWritable = pThis->pHostDrvAudio->pfnStreamGetWritable(pThis->pHostDrvAudio, pHstStream->pvBackend);1383 if (c sWritable)1384 { 1385 if (c sToPlay > csWritable) /* More samples available than we can write? Limit. */1386 c sToPlay = csWritable;1387 1388 PDMAUDIO SAMPLE aSampleBuf[256]; /** @todo Get rid of this here. */1389 1390 uint32_t c sLeft = csToPlay;1391 while (c sLeft)1392 { 1393 uint32_t c sRead = 0;1394 rc = AudioMixBufPeek(&pHstStream->MixBuf, c sLeft, aSampleBuf,1395 RT_MIN(c sLeft, RT_ELEMENTS(aSampleBuf)), &csRead);1382 uint32_t cfWritable = pThis->pHostDrvAudio->pfnStreamGetWritable(pThis->pHostDrvAudio, pHstStream->pvBackend); 1383 if (cfWritable) 1384 { 1385 if (cfToPlay > cfWritable) /* More frames available than we can write? Limit. */ 1386 cfToPlay = cfWritable; 1387 1388 PDMAUDIOFRAME aFrameBuf[256]; /** @todo Get rid of this here. */ 1389 1390 uint32_t cfLeft = cfToPlay; 1391 while (cfLeft) 1392 { 1393 uint32_t cfRead = 0; 1394 rc = AudioMixBufPeek(&pHstStream->MixBuf, cfLeft, aFrameBuf, 1395 RT_MIN(cfLeft, RT_ELEMENTS(aFrameBuf)), &cfRead); 1396 1396 1397 1397 if (RT_SUCCESS(rc)) 1398 1398 { 1399 if (c sRead)1399 if (cfRead) 1400 1400 { 1401 uint32_t c sPlayed;1401 uint32_t cfPlayed; 1402 1402 1403 1403 /* Note: As the stream layout is RPDMAUDIOSTREAMLAYOUT_RAW, operate on audio frames 1404 1404 * rather on bytes. */ 1405 Assert(c sRead <= RT_ELEMENTS(aSampleBuf));1405 Assert(cfRead <= RT_ELEMENTS(aFrameBuf)); 1406 1406 rc = pThis->pHostDrvAudio->pfnStreamPlay(pThis->pHostDrvAudio, pHstStream->pvBackend, 1407 a SampleBuf, csRead, &csPlayed);1407 aFrameBuf, cfRead, &cfPlayed); 1408 1408 if ( RT_FAILURE(rc) 1409 || !c sPlayed)1409 || !cfPlayed) 1410 1410 { 1411 1411 break; 1412 1412 } 1413 1413 1414 c sPlayedTotal += csPlayed;1415 Assert(c sPlayedTotal <= csToPlay);1416 1417 Assert(c sLeft >= csRead);1418 c sLeft -= csRead;1414 cfPlayedTotal += cfPlayed; 1415 Assert(cfPlayedTotal <= cfToPlay); 1416 1417 Assert(cfLeft >= cfRead); 1418 cfLeft -= cfRead; 1419 1419 } 1420 1420 else … … 1431 1431 } 1432 1432 1433 Log3Func(("[%s] Played %RU32/%RU32 samples, rc=%Rrc\n", pHstStream->szName, csPlayedTotal, csToPlay, rc));1433 Log3Func(("[%s] Played %RU32/%RU32 frames, rc=%Rrc\n", pHstStream->szName, cfPlayedTotal, cfToPlay, rc)); 1434 1434 1435 1435 if (RT_SUCCESS(rc)) 1436 1436 { 1437 if (pc sPlayed)1438 *pc sPlayed = csPlayedTotal;1437 if (pcfPlayed) 1438 *pcfPlayed = cfPlayedTotal; 1439 1439 1440 1440 } … … 1447 1447 */ 1448 1448 static DECLCALLBACK(int) drvAudioStreamPlay(PPDMIAUDIOCONNECTOR pInterface, 1449 PPDMAUDIOSTREAM pStream, uint32_t *pc SamplesPlayed)1449 PPDMAUDIOSTREAM pStream, uint32_t *pcFramesPlayed) 1450 1450 { 1451 1451 AssertPtrReturn(pInterface, VERR_INVALID_POINTER); 1452 1452 AssertPtrReturn(pStream, VERR_INVALID_POINTER); 1453 /* pc SamplesPlayed is optional. */1453 /* pcFramesPlayed is optional. */ 1454 1454 1455 1455 PDRVAUDIO pThis = PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface); … … 1463 1463 pStream->szName, pStream->enmDir)); 1464 1464 1465 uint32_t c sPlayedTotal = 0;1465 uint32_t cfPlayedTotal = 0; 1466 1466 1467 1467 do … … 1501 1501 break; 1502 1502 1503 uint32_t c sToPlay = AudioMixBufLive(&pHstStream->MixBuf);1503 uint32_t cfToPlay = AudioMixBufLive(&pHstStream->MixBuf); 1504 1504 1505 1505 if (pThis->pHostDrvAudio->pfnStreamPlayBegin) … … 1508 1508 if (RT_LIKELY(pHstStream->Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED)) 1509 1509 { 1510 rc = drvAudioStreamPlayNonInterleaved(pThis, pHstStream, c sToPlay, &csPlayedTotal);1510 rc = drvAudioStreamPlayNonInterleaved(pThis, pHstStream, cfToPlay, &cfPlayedTotal); 1511 1511 } 1512 1512 else if (pHstStream->Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_RAW) 1513 1513 { 1514 rc = drvAudioStreamPlayRaw(pThis, pHstStream, c sToPlay, &csPlayedTotal);1514 rc = drvAudioStreamPlayRaw(pThis, pHstStream, cfToPlay, &cfPlayedTotal); 1515 1515 } 1516 1516 else … … 1520 1520 pThis->pHostDrvAudio->pfnStreamPlayEnd(pThis->pHostDrvAudio, pHstStream->pvBackend); 1521 1521 1522 uint32_t c sLive = 0;1522 uint32_t cfLive = 0; 1523 1523 1524 1524 if (RT_SUCCESS(rc)) 1525 1525 { 1526 AudioMixBufFinish(&pHstStream->MixBuf, c sPlayedTotal);1526 AudioMixBufFinish(&pHstStream->MixBuf, cfPlayedTotal); 1527 1527 1528 1528 #ifdef VBOX_WITH_STATISTICS 1529 STAM_COUNTER_ADD (&pThis->Stats.TotalSamplesOut, csPlayedTotal);1529 STAM_COUNTER_ADD (&pThis->Stats.TotalFramesOut, cfPlayedTotal); 1530 1530 STAM_PROFILE_ADV_STOP(&pThis->Stats.DelayOut, out); 1531 STAM_COUNTER_ADD (&pHstStream->Out.StatSamplesPlayed, csPlayedTotal);1532 #endif 1533 c sLive = AudioMixBufLive(&pHstStream->MixBuf);1531 STAM_COUNTER_ADD (&pHstStream->Out.StatFramesPlayed, cfPlayedTotal); 1532 #endif 1533 cfLive = AudioMixBufLive(&pHstStream->MixBuf); 1534 1534 } 1535 1535 1536 1536 #ifdef LOG_ENABLED 1537 1537 pszBackendSts = dbgAudioStreamStatusToStr(stsBackend); 1538 Log3Func(("[%s] End: stsBackend=%s, c sLive=%RU32, csPlayedTotal=%RU32, rc=%Rrc\n",1539 pHstStream->szName, pszBackendSts, c sLive, csPlayedTotal, rc));1538 Log3Func(("[%s] End: stsBackend=%s, cfLive=%RU32, cfPlayedTotal=%RU32, rc=%Rrc\n", 1539 pHstStream->szName, pszBackendSts, cfLive, cfPlayedTotal, rc)); 1540 1540 RTStrFree(pszBackendSts); 1541 1541 #endif /* LOG_ENABLED */ 1542 1542 1543 if (!c sLive)1543 if (!cfLive) 1544 1544 { 1545 1545 /* Has the host stream marked as disabled but there still were guest streams relying … … 1566 1566 if (RT_SUCCESS(rc)) 1567 1567 { 1568 if (pc SamplesPlayed)1569 *pc SamplesPlayed = csPlayedTotal;1568 if (pcFramesPlayed) 1569 *pcFramesPlayed = cfPlayedTotal; 1570 1570 } 1571 1571 … … 1582 1582 * @param pThis Driver instance. 1583 1583 * @param pHstStream Host stream to capture from. 1584 * @param pc sCaptured Number of (host) audio samples captured. Optional.1585 */ 1586 static int drvAudioStreamCaptureNonInterleaved(PDRVAUDIO pThis, PPDMAUDIOSTREAM pHstStream, uint32_t *pc sCaptured)1584 * @param pcfCaptured Number of (host) audio frames captured. Optional. 1585 */ 1586 static int drvAudioStreamCaptureNonInterleaved(PDRVAUDIO pThis, PPDMAUDIOSTREAM pHstStream, uint32_t *pcfCaptured) 1587 1587 { 1588 1588 AssertPtrReturn(pThis, VERR_INVALID_POINTER); 1589 1589 AssertPtrReturn(pHstStream, VERR_INVALID_POINTER); 1590 /* pc sCaptured is optional. */1590 /* pcfCaptured is optional. */ 1591 1591 1592 1592 /* Sanity. */ … … 1597 1597 int rc = VINF_SUCCESS; 1598 1598 1599 uint32_t c sCapturedTotal = 0;1599 uint32_t cfCapturedTotal = 0; 1600 1600 1601 1601 AssertPtr(pThis->pHostDrvAudio->pfnStreamGetReadable); … … 1610 1610 break; 1611 1611 1612 uint32_t cbFree = AUDIOMIXBUF_ S2B(&pHstStream->MixBuf, AudioMixBufFree(&pHstStream->MixBuf));1612 uint32_t cbFree = AUDIOMIXBUF_F2B(&pHstStream->MixBuf, AudioMixBufFree(&pHstStream->MixBuf)); 1613 1613 if (!cbFree) 1614 1614 break; … … 1640 1640 cbCaptured = (uint32_t)cbBuf; 1641 1641 1642 uint32_t c sCaptured = 0;1643 rc = AudioMixBufWriteCirc(&pHstStream->MixBuf, auBuf, cbCaptured, &c sCaptured);1642 uint32_t cfCaptured = 0; 1643 rc = AudioMixBufWriteCirc(&pHstStream->MixBuf, auBuf, cbCaptured, &cfCaptured); 1644 1644 if (RT_SUCCESS(rc)) 1645 c sCapturedTotal += csCaptured;1645 cfCapturedTotal += cfCaptured; 1646 1646 } 1647 1647 else /* Nothing captured -- bail out. */ … … 1652 1652 } 1653 1653 1654 Log2Func(("[%s] %RU32 samples captured, rc=%Rrc\n", pHstStream->szName, csCapturedTotal, rc));1655 1656 if (pc sCaptured)1657 *pc sCaptured = csCapturedTotal;1654 Log2Func(("[%s] %RU32 frames captured, rc=%Rrc\n", pHstStream->szName, cfCapturedTotal, rc)); 1655 1656 if (pcfCaptured) 1657 *pcfCaptured = cfCapturedTotal; 1658 1658 1659 1659 return rc; … … 1662 1662 /** 1663 1663 * Captures raw input from a host stream. 1664 * Raw input means that the backend directly operates on PDMAUDIO SAMPLE structs without1664 * Raw input means that the backend directly operates on PDMAUDIOFRAME structs without 1665 1665 * no data layout processing done in between. 1666 1666 * … … 1670 1670 * @param pThis Driver instance. 1671 1671 * @param pHstStream Host stream to capture from. 1672 * @param pc sCaptured Number of (host) audio samples captured. Optional.1673 */ 1674 static int drvAudioStreamCaptureRaw(PDRVAUDIO pThis, PPDMAUDIOSTREAM pHstStream, uint32_t *pc sCaptured)1672 * @param pcfCaptured Number of (host) audio frames captured. Optional. 1673 */ 1674 static int drvAudioStreamCaptureRaw(PDRVAUDIO pThis, PPDMAUDIOSTREAM pHstStream, uint32_t *pcfCaptured) 1675 1675 { 1676 1676 AssertPtrReturn(pThis, VERR_INVALID_POINTER); 1677 1677 AssertPtrReturn(pHstStream, VERR_INVALID_POINTER); 1678 /* pc sCaptured is optional. */1678 /* pcfCaptured is optional. */ 1679 1679 1680 1680 /* Sanity. */ … … 1685 1685 int rc = VINF_SUCCESS; 1686 1686 1687 uint32_t c sCapturedTotal = 0;1687 uint32_t cfCapturedTotal = 0; 1688 1688 1689 1689 AssertPtr(pThis->pHostDrvAudio->pfnStreamGetReadable); … … 1702 1702 cbReadable = cbFree; 1703 1703 1704 PPDMAUDIO SAMPLE paSamples;1705 uint32_t c sWritable;1706 rc = AudioMixBufPeekMutable(&pHstStream->MixBuf, AUDIOMIXBUF_B2 S(&pHstStream->MixBuf, cbReadable),1707 &pa Samples, &csWritable);1704 PPDMAUDIOFRAME paFrames; 1705 uint32_t cfWritable; 1706 rc = AudioMixBufPeekMutable(&pHstStream->MixBuf, AUDIOMIXBUF_B2F(&pHstStream->MixBuf, cbReadable), 1707 &paFrames, &cfWritable); 1708 1708 if ( RT_FAILURE(rc) 1709 || !c sWritable)1710 { 1711 break; 1712 } 1713 1714 uint32_t c sCaptured;1709 || !cfWritable) 1710 { 1711 break; 1712 } 1713 1714 uint32_t cfCaptured; 1715 1715 rc = pThis->pHostDrvAudio->pfnStreamCapture(pThis->pHostDrvAudio, pHstStream->pvBackend, 1716 pa Samples, csWritable, &csCaptured);1716 paFrames, cfWritable, &cfCaptured); 1717 1717 if (RT_FAILURE(rc)) 1718 1718 { … … 1720 1720 AssertRC(rc2); 1721 1721 } 1722 else if (c sCaptured)1723 { 1724 Assert(c sCaptured <= csWritable);1725 if (c sCaptured > csWritable) /* Paranoia. */1726 c sCaptured = csWritable;1727 1728 c sCapturedTotal += csCaptured;1722 else if (cfCaptured) 1723 { 1724 Assert(cfCaptured <= cfWritable); 1725 if (cfCaptured > cfWritable) /* Paranoia. */ 1726 cfCaptured = cfWritable; 1727 1728 cfCapturedTotal += cfCaptured; 1729 1729 } 1730 1730 else /* Nothing captured -- bail out. */ … … 1735 1735 } 1736 1736 1737 Log2Func(("[%s] %RU32 samples captured, rc=%Rrc\n", pHstStream->szName, csCapturedTotal, rc));1738 1739 if (pc sCaptured)1740 *pc sCaptured = csCapturedTotal;1737 Log2Func(("[%s] %RU32 frames captured, rc=%Rrc\n", pHstStream->szName, cfCapturedTotal, rc)); 1738 1739 if (pcfCaptured) 1740 *pcfCaptured = cfCapturedTotal; 1741 1741 1742 1742 return rc; … … 1747 1747 */ 1748 1748 static DECLCALLBACK(int) drvAudioStreamCapture(PPDMIAUDIOCONNECTOR pInterface, 1749 PPDMAUDIOSTREAM pStream, uint32_t *pc SamplesCaptured)1749 PPDMAUDIOSTREAM pStream, uint32_t *pcFramesCaptured) 1750 1750 { 1751 1751 PDRVAUDIO pThis = PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface); … … 1759 1759 pStream->szName, pStream->enmDir)); 1760 1760 1761 uint32_t c sCaptured = 0;1761 uint32_t cfCaptured = 0; 1762 1762 1763 1763 do … … 1800 1800 if (RT_LIKELY(pHstStream->Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED)) 1801 1801 { 1802 rc = drvAudioStreamCaptureNonInterleaved(pThis, pHstStream, &c sCaptured);1802 rc = drvAudioStreamCaptureNonInterleaved(pThis, pHstStream, &cfCaptured); 1803 1803 } 1804 1804 else if (pHstStream->Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_RAW) 1805 1805 { 1806 rc = drvAudioStreamCaptureRaw(pThis, pHstStream, &c sCaptured);1806 rc = drvAudioStreamCaptureRaw(pThis, pHstStream, &cfCaptured); 1807 1807 } 1808 1808 else … … 1814 1814 #ifdef LOG_ENABLED 1815 1815 pszBackendSts = dbgAudioStreamStatusToStr(stsBackend); 1816 Log3Func(("[%s] End: stsBackend=%s, c sCaptured=%RU32, rc=%Rrc\n",1817 pHstStream->szName, pszBackendSts, c sCaptured, rc));1816 Log3Func(("[%s] End: stsBackend=%s, cfCaptured=%RU32, rc=%Rrc\n", 1817 pHstStream->szName, pszBackendSts, cfCaptured, rc)); 1818 1818 RTStrFree(pszBackendSts); 1819 1819 #endif /* LOG_ENABLED */ … … 1821 1821 if (RT_SUCCESS(rc)) 1822 1822 { 1823 Log3Func(("[%s] %RU32 samples captured, rc=%Rrc\n", pHstStream->szName, csCaptured, rc));1823 Log3Func(("[%s] %RU32 frames captured, rc=%Rrc\n", pHstStream->szName, cfCaptured, rc)); 1824 1824 1825 1825 #ifdef VBOX_WITH_STATISTICS 1826 STAM_COUNTER_ADD(&pThis->Stats.Total SamplesIn, csCaptured);1827 STAM_COUNTER_ADD(&pHstStream->In.Stat SamplesCaptured, csCaptured);1826 STAM_COUNTER_ADD(&pThis->Stats.TotalFramesIn, cfCaptured); 1827 STAM_COUNTER_ADD(&pHstStream->In.StatFramesCaptured, cfCaptured); 1828 1828 #endif 1829 1829 } … … 1838 1838 } while (0); 1839 1839 1840 if (pc SamplesCaptured)1841 *pc SamplesCaptured = csCaptured;1840 if (pcFramesCaptured) 1841 *pcFramesCaptured = cfCaptured; 1842 1842 1843 1843 int rc2 = RTCritSectLeave(&pThis->CritSect); … … 2365 2365 uint32_t cReadTotal = 0; 2366 2366 2367 uint32_t cToRead = RT_MIN(AUDIOMIXBUF_B2 S(&pGstStream->MixBuf, cbBuf), AudioMixBufUsed(&pGstStream->MixBuf));2367 uint32_t cToRead = RT_MIN(AUDIOMIXBUF_B2F(&pGstStream->MixBuf, cbBuf), AudioMixBufUsed(&pGstStream->MixBuf)); 2368 2368 while (cToRead) 2369 2369 { 2370 2370 uint32_t cRead; 2371 rc = AudioMixBufReadCirc(&pGstStream->MixBuf, (uint8_t *)pvBuf + AUDIOMIXBUF_ S2B(&pGstStream->MixBuf, cReadTotal),2372 AUDIOMIXBUF_ S2B(&pGstStream->MixBuf, cToRead), &cRead);2371 rc = AudioMixBufReadCirc(&pGstStream->MixBuf, (uint8_t *)pvBuf + AUDIOMIXBUF_F2B(&pGstStream->MixBuf, cReadTotal), 2372 AUDIOMIXBUF_F2B(&pGstStream->MixBuf, cToRead), &cRead); 2373 2373 if (RT_FAILURE(rc)) 2374 2374 break; 2375 2375 2376 2376 #if defined (VBOX_WITH_STATISTICS) || defined (VBOX_AUDIO_DEBUG_DUMP_PCM_DATA) 2377 const uint32_t cbRead = AUDIOMIXBUF_ S2B(&pGstStream->MixBuf, cRead);2377 const uint32_t cbRead = AUDIOMIXBUF_F2B(&pGstStream->MixBuf, cRead); 2378 2378 #endif 2379 2379 … … 2392 2392 #ifdef VBOX_AUDIO_DEBUG_DUMP_PCM_DATA 2393 2393 drvAudioDbgPCMDump(pThis, VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH, "StreamRead.pcm", 2394 pvBuf, AUDIOMIXBUF_ S2B(&pGstStream->MixBuf, cReadTotal));2394 pvBuf, AUDIOMIXBUF_F2B(&pGstStream->MixBuf, cReadTotal)); 2395 2395 #endif 2396 2396 AudioMixBufFinish(&pGstStream->MixBuf, cReadTotal); … … 2398 2398 pGstStream->In.tsLastReadMS = RTTimeMilliTS(); 2399 2399 2400 cbReadTotal = AUDIOMIXBUF_ S2B(&pGstStream->MixBuf, cReadTotal);2400 cbReadTotal = AUDIOMIXBUF_F2B(&pGstStream->MixBuf, cReadTotal); 2401 2401 } 2402 2402 … … 2548 2548 szStatName, STAMUNIT_BYTES, "Total bytes read."); 2549 2549 2550 RTStrPrintf(szStatName, sizeof(szStatName), "Host/%s/ SamplesCaptured", pHstStrm->szName);2551 PDMDrvHlpSTAMRegCounterEx(pThis->pDrvIns, &pHstStrm->In.Stat SamplesCaptured,2552 szStatName, STAMUNIT_COUNT, "Total samples captured.");2550 RTStrPrintf(szStatName, sizeof(szStatName), "Host/%s/FramesCaptured", pHstStrm->szName); 2551 PDMDrvHlpSTAMRegCounterEx(pThis->pDrvIns, &pHstStrm->In.StatFramesCaptured, 2552 szStatName, STAMUNIT_COUNT, "Total frames captured."); 2553 2553 } 2554 2554 else if (pCfgGuest->enmDir == PDMAUDIODIR_OUT) … … 2562 2562 szStatName, STAMUNIT_BYTES, "Total bytes written."); 2563 2563 2564 RTStrPrintf(szStatName, sizeof(szStatName), "Host/%s/ SamplesPlayed", pHstStrm->szName);2565 PDMDrvHlpSTAMRegCounterEx(pThis->pDrvIns, &pHstStrm->Out.Stat SamplesPlayed,2566 szStatName, STAMUNIT_COUNT, "Total samples played.");2564 RTStrPrintf(szStatName, sizeof(szStatName), "Host/%s/FramesPlayed", pHstStrm->szName); 2565 PDMDrvHlpSTAMRegCounterEx(pThis->pDrvIns, &pHstStrm->Out.StatFramesPlayed, 2566 szStatName, STAMUNIT_COUNT, "Total frames played."); 2567 2567 } 2568 2568 else … … 2723 2723 2724 2724 Log3Func(("[%s] cbReadable=%RU32 (%zu bytes)\n", pHstStream->szName, cReadable, 2725 AUDIOMIXBUF_ S2B(&pGstStream->MixBuf, cReadable)));2726 2727 uint32_t cbReadable = AUDIOMIXBUF_ S2B(&pGstStream->MixBuf, cReadable);2725 AUDIOMIXBUF_F2B(&pGstStream->MixBuf, cReadable))); 2726 2727 uint32_t cbReadable = AUDIOMIXBUF_F2B(&pGstStream->MixBuf, cReadable); 2728 2728 2729 2729 rc2 = RTCritSectLeave(&pThis->CritSect); 2730 2730 AssertRC(rc2); 2731 2731 2732 /* Return bytes instead of audio samples. */2732 /* Return bytes instead of audio frames. */ 2733 2733 return cbReadable; 2734 2734 } … … 2862 2862 if (pHstStream->enmDir == PDMAUDIODIR_IN) 2863 2863 { 2864 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pHstStream->In.Stat SamplesCaptured);2864 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pHstStream->In.StatFramesCaptured); 2865 2865 } 2866 2866 else if (pHstStream->enmDir == PDMAUDIODIR_OUT) 2867 2867 { 2868 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pHstStream->Out.Stat SamplesPlayed);2868 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pHstStream->Out.StatFramesPlayed); 2869 2869 } 2870 2870 else … … 2891 2891 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pGstStream->In.StatBytesElapsed); 2892 2892 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pGstStream->In.StatBytesTotalRead); 2893 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pGstStream->In.Stat SamplesCaptured);2893 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pGstStream->In.StatFramesCaptured); 2894 2894 } 2895 2895 else if (pGstStream->enmDir == PDMAUDIODIR_OUT) … … 2897 2897 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pGstStream->Out.StatBytesElapsed); 2898 2898 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pGstStream->Out.StatBytesTotalWritten); 2899 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pGstStream->Out.Stat SamplesPlayed);2899 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pGstStream->Out.StatFramesPlayed); 2900 2900 } 2901 2901 else … … 3217 3217 PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalStreamsCreated, "TotalStreamsCreated", 3218 3218 STAMUNIT_COUNT, "Total created audio streams."); 3219 PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.Total SamplesRead, "TotalSamplesRead",3220 STAMUNIT_COUNT, "Total samples read by device emulation.");3221 PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.Total SamplesWritten, "TotalSamplesWritten",3222 STAMUNIT_COUNT, "Total samples written by device emulation ");3223 PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.Total SamplesMixedIn, "TotalSamplesMixedIn",3224 STAMUNIT_COUNT, "Total input samples mixed.");3225 PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.Total SamplesMixedOut, "TotalSamplesMixedOut",3226 STAMUNIT_COUNT, "Total output samples mixed.");3227 PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.Total SamplesLostIn, "TotalSamplesLostIn",3228 STAMUNIT_COUNT, "Total input samples lost.");3229 PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.Total SamplesLostOut, "TotalSamplesLostOut",3230 STAMUNIT_COUNT, "Total output samples lost.");3231 PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.Total SamplesOut, "TotalSamplesPlayed",3232 STAMUNIT_COUNT, "Total samples played by backend.");3233 PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.Total SamplesIn, "TotalSamplesCaptured",3234 STAMUNIT_COUNT, "Total samples captured by backend.");3219 PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalFramesRead, "TotalFramesRead", 3220 STAMUNIT_COUNT, "Total frames read by device emulation."); 3221 PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalFramesWritten, "TotalFramesWritten", 3222 STAMUNIT_COUNT, "Total frames written by device emulation "); 3223 PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalFramesMixedIn, "TotalFramesMixedIn", 3224 STAMUNIT_COUNT, "Total input frames mixed."); 3225 PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalFramesMixedOut, "TotalFramesMixedOut", 3226 STAMUNIT_COUNT, "Total output frames mixed."); 3227 PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalFramesLostIn, "TotalFramesLostIn", 3228 STAMUNIT_COUNT, "Total input frames lost."); 3229 PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalFramesLostOut, "TotalFramesLostOut", 3230 STAMUNIT_COUNT, "Total output frames lost."); 3231 PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalFramesOut, "TotalFramesPlayed", 3232 STAMUNIT_COUNT, "Total frames played by backend."); 3233 PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalFramesIn, "TotalFramesCaptured", 3234 STAMUNIT_COUNT, "Total frames captured by backend."); 3235 3235 PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalBytesRead, "TotalBytesRead", 3236 3236 STAMUNIT_BYTES, "Total bytes read."); … … 3334 3334 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalStreamsActive); 3335 3335 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalStreamsCreated); 3336 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.Total SamplesRead);3337 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.Total SamplesWritten);3338 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.Total SamplesMixedIn);3339 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.Total SamplesMixedOut);3340 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.Total SamplesLostIn);3341 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.Total SamplesLostOut);3342 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.Total SamplesOut);3343 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.Total SamplesIn);3336 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalFramesRead); 3337 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalFramesWritten); 3338 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalFramesMixedIn); 3339 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalFramesMixedOut); 3340 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalFramesLostIn); 3341 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalFramesLostOut); 3342 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalFramesOut); 3343 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalFramesIn); 3344 3344 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalBytesRead); 3345 3345 PDMDrvHlpSTAMDeregister(pThis->pDrvIns, &pThis->Stats.TotalBytesWritten); -
trunk/src/VBox/Devices/Audio/DrvAudio.h
r67362 r68132 94 94 STAMCOUNTER TotalStreamsActive; 95 95 STAMCOUNTER TotalStreamsCreated; 96 STAMCOUNTER Total SamplesRead;97 STAMCOUNTER Total SamplesWritten;98 STAMCOUNTER Total SamplesMixedIn;99 STAMCOUNTER Total SamplesMixedOut;100 STAMCOUNTER Total SamplesLostIn;101 STAMCOUNTER Total SamplesLostOut;102 STAMCOUNTER Total SamplesOut;103 STAMCOUNTER Total SamplesIn;96 STAMCOUNTER TotalFramesRead; 97 STAMCOUNTER TotalFramesWritten; 98 STAMCOUNTER TotalFramesMixedIn; 99 STAMCOUNTER TotalFramesMixedOut; 100 STAMCOUNTER TotalFramesLostIn; 101 STAMCOUNTER TotalFramesLostOut; 102 STAMCOUNTER TotalFramesOut; 103 STAMCOUNTER TotalFramesIn; 104 104 STAMCOUNTER TotalBytesRead; 105 105 STAMCOUNTER TotalBytesWritten; … … 165 165 uint8_t DrvAudioHlpAudFmtToBits(PDMAUDIOFMT enmFmt); 166 166 const char *DrvAudioHlpAudFmtToStr(PDMAUDIOFMT enmFmt); 167 void DrvAudioHlpClearBuf(const PPDMAUDIOPCMPROPS pPCMInfo, void *pvBuf, size_t cbBuf, uint32_t c Samples);167 void DrvAudioHlpClearBuf(const PPDMAUDIOPCMPROPS pPCMInfo, void *pvBuf, size_t cbBuf, uint32_t cFrames); 168 168 uint32_t DrvAudioHlpCalcBitrate(uint8_t cBits, uint32_t uHz, uint8_t cChannels); 169 169 uint32_t DrvAudioHlpCalcBitrate(const PPDMAUDIOPCMPROPS pProps); -
trunk/src/VBox/Devices/Audio/DrvHostALSAAudio.cpp
r68085 r68132 1035 1035 { 1036 1036 case SND_PCM_STATE_PREPARED: 1037 cAvail = PDMAUDIOSTREAMCFG_B2 S(pCfg, cxBuf);1037 cAvail = PDMAUDIOSTREAMCFG_B2F(pCfg, cxBuf); 1038 1038 break; 1039 1039 … … 1065 1065 * the mixer buffer. 1066 1066 */ 1067 size_t cbToRead = RT_MIN((size_t)PDMAUDIOSTREAMCFG_ S2B(pCfg, cAvail), cxBuf);1067 size_t cbToRead = RT_MIN((size_t)PDMAUDIOSTREAMCFG_F2B(pCfg, cAvail), cxBuf); 1068 1068 1069 1069 LogFlowFunc(("cbToRead=%zu, cAvail=%RI32\n", cbToRead, cAvail)); … … 1077 1077 && RT_SUCCESS(rc)) 1078 1078 { 1079 cToRead = RT_MIN(PDMAUDIOSTREAMCFG_B2 S(pCfg, cbToRead),1080 PDMAUDIOSTREAMCFG_B2 S(pCfg, pStreamALSA->cbBuf));1079 cToRead = RT_MIN(PDMAUDIOSTREAMCFG_B2F(pCfg, cbToRead), 1080 PDMAUDIOSTREAMCFG_B2F(pCfg, pStreamALSA->cbBuf)); 1081 1081 AssertBreakStmt(cToRead, rc = VERR_NO_DATA); 1082 1082 cRead = snd_pcm_readi(pStreamALSA->phPCM, pStreamALSA->pvBuf, cToRead); … … 1128 1128 * capture device for example). 1129 1129 */ 1130 uint32_t cbRead = PDMAUDIOSTREAMCFG_ S2B(pCfg, cRead);1130 uint32_t cbRead = PDMAUDIOSTREAMCFG_F2B(pCfg, cRead); 1131 1131 1132 1132 memcpy(pvBuf, pStreamALSA->pvBuf, cbRead); … … 1181 1181 break; 1182 1182 1183 size_t cbToWrite = RT_MIN((unsigned)PDMAUDIOSTREAMCFG_ S2B(pCfg, csAvail), pStreamALSA->cbBuf);1183 size_t cbToWrite = RT_MIN((unsigned)PDMAUDIOSTREAMCFG_F2B(pCfg, csAvail), pStreamALSA->cbBuf); 1184 1184 if (!cbToWrite) 1185 1185 break; … … 1198 1198 { 1199 1199 csWritten = snd_pcm_writei(pStreamALSA->phPCM, pStreamALSA->pvBuf, 1200 PDMAUDIOSTREAMCFG_B2 S(pCfg, cbToWrite));1200 PDMAUDIOSTREAMCFG_B2F(pCfg, cbToWrite)); 1201 1201 if (csWritten <= 0) 1202 1202 { … … 1251 1251 break; 1252 1252 1253 cbWrittenTotal = PDMAUDIOSTREAMCFG_ S2B(pCfg, csWritten);1253 cbWrittenTotal = PDMAUDIOSTREAMCFG_F2B(pCfg, csWritten); 1254 1254 1255 1255 } while (0); … … 1320 1320 break; 1321 1321 1322 pCfgAcq->c SampleBufferHint = obt.samples * 4;1322 pCfgAcq->cFrameBufferHint = obt.samples * 4; 1323 1323 1324 1324 AssertBreakStmt(obt.samples, rc = VERR_INVALID_PARAMETER); 1325 1325 1326 size_t cbBuf = obt.samples * PDMAUDIOSTREAMCFG_ S2B(pCfgAcq, 1);1326 size_t cbBuf = obt.samples * PDMAUDIOSTREAMCFG_F2B(pCfgAcq, 1); 1327 1327 AssertBreakStmt(cbBuf, rc = VERR_INVALID_PARAMETER); 1328 1328 … … 1375 1375 break; 1376 1376 1377 pCfgAcq->c SampleBufferHint = obt.samples;1377 pCfgAcq->cFrameBufferHint = obt.samples; 1378 1378 1379 1379 AssertBreakStmt(obt.samples, rc = VERR_INVALID_PARAMETER); 1380 1380 1381 size_t cbBuf = obt.samples * PDMAUDIOSTREAMCFG_ S2B(pCfgAcq, 1);1381 size_t cbBuf = obt.samples * PDMAUDIOSTREAMCFG_F2B(pCfgAcq, 1); 1382 1382 AssertBreakStmt(cbBuf, rc = VERR_INVALID_PARAMETER); 1383 1383 … … 1644 1644 int rc = alsaStreamGetAvail(pStreamALSA->phPCM, &cFramesAvail); 1645 1645 if (RT_SUCCESS(rc)) 1646 cbAvail = PDMAUDIOSTREAMCFG_ S2B(pStreamALSA->pCfg, cFramesAvail);1646 cbAvail = PDMAUDIOSTREAMCFG_F2B(pStreamALSA->pCfg, cFramesAvail); 1647 1647 1648 1648 return cbAvail; … … 1666 1666 && (uint32_t)cFramesAvail >= pStreamALSA->Out.cSamplesMin) 1667 1667 { 1668 cbAvail = PDMAUDIOSTREAMCFG_ S2B(pStreamALSA->pCfg, cFramesAvail);1668 cbAvail = PDMAUDIOSTREAMCFG_F2B(pStreamALSA->pCfg, cFramesAvail); 1669 1669 } 1670 1670 -
trunk/src/VBox/Devices/Audio/DrvHostCoreAudio.cpp
r68085 r68132 1591 1591 } 1592 1592 1593 rc = RTCircBufCreate(&pCAStream->pCircBuf, PDMAUDIOSTREAMCFG_ S2B(pCfgReq, 4096)); /** @todo Make this configurable. */1593 rc = RTCircBufCreate(&pCAStream->pCircBuf, PDMAUDIOSTREAMCFG_F2B(pCfgReq, 4096)); /** @todo Make this configurable. */ 1594 1594 if (RT_FAILURE(rc)) 1595 1595 return rc; … … 2308 2308 if (RT_SUCCESS(rc)) 2309 2309 { 2310 pCfgAcq->c SampleBufferHint = _4K; /** @todo Make this configurable. */2310 pCfgAcq->cFrameBufferHint = _4K; /** @todo Make this configurable. */ 2311 2311 } 2312 2312 if (RT_SUCCESS(rc)) -
trunk/src/VBox/Devices/Audio/DrvHostDSound.cpp
r68085 r68132 733 733 #endif /* VBOX_WITH_AUDIO_DEVICE_CALLBACKS */ 734 734 735 pCfgAcq->c SampleBufferHint = PDMAUDIOSTREAMCFG_B2S(pCfgAcq, pThis->cfg.cbBufferOut);735 pCfgAcq->cFrameBufferHint = PDMAUDIOSTREAMCFG_B2F(pCfgAcq, pThis->cfg.cbBufferOut); 736 736 737 737 } while (0); … … 758 758 if (SUCCEEDED(hr)) 759 759 { 760 DWORD len1 = PDMAUDIOPCMPROPS_B2 S(pProps, cb1);761 DWORD len2 = PDMAUDIOPCMPROPS_B2 S(pProps, cb2);760 DWORD len1 = PDMAUDIOPCMPROPS_B2F(pProps, cb1); 761 DWORD len2 = PDMAUDIOPCMPROPS_B2F(pProps, cb2); 762 762 763 763 if (pv1 && len1) … … 1170 1170 pStreamDS->In.offCaptureBufRead, pStreamDS->In.cbCaptureBuf)); 1171 1171 1172 pCfgAcq->c SampleBufferHint = PDMAUDIOSTREAMCFG_B2S(pCfgAcq, pThis->cfg.cbBufferIn);1172 pCfgAcq->cFrameBufferHint = PDMAUDIOSTREAMCFG_B2F(pCfgAcq, pThis->cfg.cbBufferIn); 1173 1173 1174 1174 } while (0); … … 1582 1582 * i.e. always leave a free space for 1 audio sample. 1583 1583 */ 1584 const DWORD cbSample = PDMAUDIOPCMPROPS_ S2B(pProps, 1);1584 const DWORD cbSample = PDMAUDIOPCMPROPS_F2B(pProps, 1); 1585 1585 if (cbFree <= cbSample) 1586 1586 break; -
trunk/src/VBox/Devices/Audio/DrvHostDebugAudio.cpp
r68085 r68132 125 125 126 126 if (pCfgAcq) 127 pCfgAcq->c SampleBufferHint = _1K;127 pCfgAcq->cFrameBufferHint = _1K; 128 128 129 129 return VINF_SUCCESS; … … 138 138 int rc = VINF_SUCCESS; 139 139 140 pStreamDbg->Out.cbPlayBuffer = _1K * PDMAUDIOSTREAMCFG_ S2B(pCfgReq, 1); /** @todo Make this configurable? */140 pStreamDbg->Out.cbPlayBuffer = _1K * PDMAUDIOSTREAMCFG_F2B(pCfgReq, 1); /** @todo Make this configurable? */ 141 141 pStreamDbg->Out.auPlayBuffer = (uint8_t *)RTMemAlloc(pStreamDbg->Out.cbPlayBuffer); 142 142 if (!pStreamDbg->Out.auPlayBuffer) … … 170 170 { 171 171 if (pCfgAcq) 172 pCfgAcq->c SampleBufferHint = PDMAUDIOSTREAMCFG_B2S(pCfgAcq, pStreamDbg->Out.cbPlayBuffer);172 pCfgAcq->cFrameBufferHint = PDMAUDIOSTREAMCFG_B2F(pCfgAcq, pStreamDbg->Out.cbPlayBuffer); 173 173 } 174 174 -
trunk/src/VBox/Devices/Audio/DrvHostNullAudio.cpp
r68085 r68132 176 176 177 177 if (pCfgAcq) 178 pCfgAcq->c SampleBufferHint = _1K;178 pCfgAcq->cFrameBufferHint = _1K; 179 179 180 180 return VINF_SUCCESS; … … 187 187 188 188 if (pCfgAcq) 189 pCfgAcq->c SampleBufferHint = _1K; /** @todo Make this configurable. */189 pCfgAcq->cFrameBufferHint = _1K; /** @todo Make this configurable. */ 190 190 191 191 return VINF_SUCCESS; -
trunk/src/VBox/Devices/Audio/DrvHostOSSAudio.cpp
r68085 r68132 360 360 { 361 361 DrvAudioHlpClearBuf(&pStreamOSS->pCfg->Props, pStreamOSS->pvBuf, pStreamOSS->cbBuf, 362 PDMAUDIOPCMPROPS_B2 S(&pStreamOSS->pCfg->Props, pStreamOSS->cbBuf));362 PDMAUDIOPCMPROPS_B2F(&pStreamOSS->pCfg->Props, pStreamOSS->cbBuf)); 363 363 364 364 int mask = PCM_ENABLE_OUTPUT; … … 647 647 } 648 648 649 uint32_t cSamples = PDMAUDIOSTREAMCFG_B2 S(pCfgAcq, ossAcq.cFragments * ossAcq.cbFragmentSize);649 uint32_t cSamples = PDMAUDIOSTREAMCFG_B2F(pCfgAcq, ossAcq.cFragments * ossAcq.cbFragmentSize); 650 650 if (!cSamples) 651 651 rc = VERR_INVALID_PARAMETER; … … 653 653 if (RT_SUCCESS(rc)) 654 654 { 655 size_t cbBuf = PDMAUDIOSTREAMCFG_ S2B(pCfgAcq, cSamples);655 size_t cbBuf = PDMAUDIOSTREAMCFG_F2B(pCfgAcq, cSamples); 656 656 void *pvBuf = RTMemAlloc(cbBuf); 657 657 if (!pvBuf) … … 665 665 pStreamOSS->cbBuf = cbBuf; 666 666 667 pCfgAcq->c SampleBufferHint = cSamples;667 pCfgAcq->cFrameBufferHint = cSamples; 668 668 } 669 669 } … … 700 700 memcpy(&pCfgAcq->Props, &obtStream.Props, sizeof(PDMAUDIOPCMPROPS)); 701 701 702 cSamples = PDMAUDIOSTREAMCFG_B2 S(pCfgAcq, obtStream.cFragments * obtStream.cbFragmentSize);702 cSamples = PDMAUDIOSTREAMCFG_B2F(pCfgAcq, obtStream.cFragments * obtStream.cbFragmentSize); 703 703 704 704 if (obtStream.cFragments * obtStream.cbFragmentSize & pStreamOSS->uAlign) … … 713 713 pStreamOSS->Out.fMMIO = false; 714 714 715 size_t cbBuf = PDMAUDIOSTREAMCFG_ S2B(pCfgAcq, cSamples);715 size_t cbBuf = PDMAUDIOSTREAMCFG_F2B(pCfgAcq, cSamples); 716 716 Assert(cbBuf); 717 717 … … 781 781 } 782 782 #endif 783 pCfgAcq->c SampleBufferHint = cSamples;783 pCfgAcq->cFrameBufferHint = cSamples; 784 784 } 785 785 -
trunk/src/VBox/Devices/Audio/DrvHostPulseAudio.cpp
r68085 r68132 776 776 if (cbBuf) 777 777 { 778 pCfgAcq->c SampleBufferHint = PDMAUDIOSTREAMCFG_B2S(pCfgAcq, cbBuf);778 pCfgAcq->cFrameBufferHint = PDMAUDIOSTREAMCFG_B2F(pCfgAcq, cbBuf); 779 779 780 780 pStreamPA->pDrv = pThis; … … 815 815 pCfgAcq->Props.uHz = pStreamPA->SampleSpec.rate; 816 816 pCfgAcq->Props.cChannels = pStreamPA->SampleSpec.channels; 817 pCfgAcq->c SampleBufferHint = PDMAUDIOSTREAMCFG_B2S(pCfgAcq,817 pCfgAcq->cFrameBufferHint = PDMAUDIOSTREAMCFG_B2F(pCfgAcq, 818 818 RT_MIN(pStreamPA->BufAttr.fragsize * 10, pStreamPA->BufAttr.maxlength)); 819 819 -
trunk/src/VBox/Devices/Audio/DrvHostValidationKit.cpp
r68085 r68132 132 132 133 133 if (pCfgAcq) 134 pCfgAcq->c SampleBufferHint = _1K;134 pCfgAcq->cFrameBufferHint = _1K; 135 135 136 136 return VINF_SUCCESS; … … 148 148 pStreamDbg->uSamplesSinceStarted = 0; 149 149 pStreamDbg->Out.tsLastPlayed = 0; 150 pStreamDbg->Out.cbPlayBuffer = 16 * _1K * PDMAUDIOSTREAMCFG_ S2B(pCfgReq, 1); /** @todo Make this configurable? */150 pStreamDbg->Out.cbPlayBuffer = 16 * _1K * PDMAUDIOSTREAMCFG_F2B(pCfgReq, 1); /** @todo Make this configurable? */ 151 151 pStreamDbg->Out.pu8PlayBuffer = (uint8_t *)RTMemAlloc(pStreamDbg->Out.cbPlayBuffer); 152 152 if (!pStreamDbg->Out.pu8PlayBuffer) … … 200 200 { 201 201 if (pCfgAcq) 202 pCfgAcq->c SampleBufferHint = PDMAUDIOSTREAMCFG_B2S(pCfgAcq, pStreamDbg->Out.cbPlayBuffer);202 pCfgAcq->cFrameBufferHint = PDMAUDIOSTREAMCFG_B2F(pCfgAcq, pStreamDbg->Out.cbPlayBuffer); 203 203 } 204 204 -
trunk/src/VBox/Devices/Audio/testcase/tstAudioMixBuffer.cpp
r67697 r68132 62 62 RTTESTI_CHECK_RC_OK(AudioMixBufInit(&mb, "Single", &config, cBufSize)); 63 63 RTTESTI_CHECK(AudioMixBufSize(&mb) == cBufSize); 64 RTTESTI_CHECK(AUDIOMIXBUF_B2 S(&mb, AudioMixBufSizeBytes(&mb)) == cBufSize);65 RTTESTI_CHECK(AUDIOMIXBUF_ S2B(&mb, AudioMixBufSize(&mb)) == AudioMixBufSizeBytes(&mb));64 RTTESTI_CHECK(AUDIOMIXBUF_B2F(&mb, AudioMixBufSizeBytes(&mb)) == cBufSize); 65 RTTESTI_CHECK(AUDIOMIXBUF_F2B(&mb, AudioMixBufSize(&mb)) == AudioMixBufSizeBytes(&mb)); 66 66 RTTESTI_CHECK(AudioMixBufFree(&mb) == cBufSize); 67 RTTESTI_CHECK(AUDIOMIXBUF_ S2B(&mb, AudioMixBufFree(&mb)) == AudioMixBufFreeBytes(&mb));67 RTTESTI_CHECK(AUDIOMIXBUF_F2B(&mb, AudioMixBufFree(&mb)) == AudioMixBufFreeBytes(&mb)); 68 68 69 69 /* 70 70 * Absolute writes. 71 71 */ 72 uint32_t cSamplesRead = 0, cSamplesWritten = 0, cSamplesWrittenAbs = 0; 73 int8_t samples8 [2] = { 0x12, 0x34 }; 74 int16_t samples16[2] = { 0xAA, 0xBB }; 75 int32_t samples32[2] = { 0xCC, 0xDD }; 76 /* int64_t samples64[2] = { 0xEE, 0xFF }; - unused */ 77 78 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 0 /* Offset */, &samples8, sizeof(samples8), &cSamplesWritten)); 79 RTTESTI_CHECK(cSamplesWritten == 0 /* Samples */); 72 uint32_t cFramesRead = 0, cFramesWritten = 0, cFramesWrittenAbs = 0; 73 int8_t aFrames8 [2] = { 0x12, 0x34 }; 74 int16_t aFrames16[2] = { 0xAA, 0xBB }; 75 int32_t aFrames32[2] = { 0xCC, 0xDD }; 76 77 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 0 /* Offset */, &aFrames8, sizeof(aFrames8), &cFramesWritten)); 78 RTTESTI_CHECK(cFramesWritten == 0 /* Frames */); 80 79 RTTESTI_CHECK(AudioMixBufUsed(&mb) == 0); 81 80 82 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 0 /* Offset */, & samples16, sizeof(samples16), &cSamplesWritten));83 RTTESTI_CHECK(c SamplesWritten == 1 /* Samples */);81 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 0 /* Offset */, &aFrames16, sizeof(aFrames16), &cFramesWritten)); 82 RTTESTI_CHECK(cFramesWritten == 1 /* Frames */); 84 83 RTTESTI_CHECK(AudioMixBufUsed(&mb) == 1); 85 84 86 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 2 /* Offset */, & samples32, sizeof(samples32), &cSamplesWritten));87 RTTESTI_CHECK(c SamplesWritten == 2 /* Samples */);85 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 2 /* Offset */, &aFrames32, sizeof(aFrames32), &cFramesWritten)); 86 RTTESTI_CHECK(cFramesWritten == 2 /* Frames */); 88 87 RTTESTI_CHECK(AudioMixBufUsed(&mb) == 2); 89 88 90 89 /* Beyond buffer. */ 91 RTTESTI_CHECK_RC(AudioMixBufWriteAt(&mb, AudioMixBufSize(&mb) + 1, & samples16, sizeof(samples16),92 &c SamplesWritten), VERR_BUFFER_OVERFLOW);93 94 /* Offset wrap-around: When writing as much (or more) samples the mixing buffer can hold. */90 RTTESTI_CHECK_RC(AudioMixBufWriteAt(&mb, AudioMixBufSize(&mb) + 1, &aFrames16, sizeof(aFrames16), 91 &cFramesWritten), VERR_BUFFER_OVERFLOW); 92 93 /* Offset wrap-around: When writing as much (or more) frames the mixing buffer can hold. */ 95 94 uint32_t cbSamples = cBufSize * sizeof(int16_t) * 2 /* Channels */; 96 95 RTTESTI_CHECK(cbSamples); 97 96 uint16_t *paSamples = (uint16_t *)RTMemAlloc(cbSamples); 98 97 RTTESTI_CHECK(paSamples); 99 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 0 /* Offset */, paSamples, cbSamples, &c SamplesWritten));100 RTTESTI_CHECK(c SamplesWritten == cBufSize /* Samples */);98 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 0 /* Offset */, paSamples, cbSamples, &cFramesWritten)); 99 RTTESTI_CHECK(cFramesWritten == cBufSize /* Frames */); 101 100 RTTESTI_CHECK(AudioMixBufUsed(&mb) == cBufSize); 102 101 RTTESTI_CHECK(AudioMixBufReadPos(&mb) == 0); … … 110 109 AudioMixBufReset(&mb); 111 110 112 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 2 /* Offset */, & samples32, sizeof(samples32), &cSamplesWritten));113 RTTESTI_CHECK(c SamplesWritten == 2 /* Samples */);111 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 2 /* Offset */, &aFrames32, sizeof(aFrames32), &cFramesWritten)); 112 RTTESTI_CHECK(cFramesWritten == 2 /* Frames */); 114 113 RTTESTI_CHECK(AudioMixBufUsed(&mb) == 2); 115 114 116 c SamplesWrittenAbs = AudioMixBufUsed(&mb);117 118 uint32_t cToWrite = AudioMixBufSize(&mb) - c SamplesWrittenAbs - 1; /* -1 as padding plus -2 samples for above. */115 cFramesWrittenAbs = AudioMixBufUsed(&mb); 116 117 uint32_t cToWrite = AudioMixBufSize(&mb) - cFramesWrittenAbs - 1; /* -1 as padding plus -2 frames for above. */ 119 118 for (uint32_t i = 0; i < cToWrite; i++) 120 119 { 121 RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&mb, & samples16, sizeof(samples16), &cSamplesWritten));122 RTTESTI_CHECK(c SamplesWritten == 1);120 RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&mb, &aFrames16, sizeof(aFrames16), &cFramesWritten)); 121 RTTESTI_CHECK(cFramesWritten == 1); 123 122 } 124 123 RTTESTI_CHECK(!AudioMixBufIsEmpty(&mb)); 125 124 RTTESTI_CHECK(AudioMixBufFree(&mb) == 1); 126 RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_ S2B(&mb, 1U));127 RTTESTI_CHECK(AudioMixBufUsed(&mb) == cToWrite + c SamplesWrittenAbs /* + last absolute write */);128 129 RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&mb, & samples16, sizeof(samples16), &cSamplesWritten));130 RTTESTI_CHECK(c SamplesWritten == 1);125 RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_F2B(&mb, 1U)); 126 RTTESTI_CHECK(AudioMixBufUsed(&mb) == cToWrite + cFramesWrittenAbs /* + last absolute write */); 127 128 RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&mb, &aFrames16, sizeof(aFrames16), &cFramesWritten)); 129 RTTESTI_CHECK(cFramesWritten == 1); 131 130 RTTESTI_CHECK(AudioMixBufFree(&mb) == 0); 132 RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_ S2B(&mb, 0U));131 RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_F2B(&mb, 0U)); 133 132 RTTESTI_CHECK(AudioMixBufUsed(&mb) == cBufSize); 134 133 135 134 /* Circular reads. */ 136 uint32_t cToRead = AudioMixBufSize(&mb) - c SamplesWrittenAbs - 1;135 uint32_t cToRead = AudioMixBufSize(&mb) - cFramesWrittenAbs - 1; 137 136 for (uint32_t i = 0; i < cToRead; i++) 138 137 { 139 RTTESTI_CHECK_RC_OK(AudioMixBufReadCirc(&mb, & samples16, sizeof(samples16), &cSamplesRead));140 RTTESTI_CHECK(c SamplesRead == 1);141 AudioMixBufFinish(&mb, c SamplesRead);138 RTTESTI_CHECK_RC_OK(AudioMixBufReadCirc(&mb, &aFrames16, sizeof(aFrames16), &cFramesRead)); 139 RTTESTI_CHECK(cFramesRead == 1); 140 AudioMixBufFinish(&mb, cFramesRead); 142 141 } 143 142 RTTESTI_CHECK(!AudioMixBufIsEmpty(&mb)); 144 RTTESTI_CHECK(AudioMixBufFree(&mb) == AudioMixBufSize(&mb) - c SamplesWrittenAbs - 1);145 RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_ S2B(&mb, cBufSize - cSamplesWrittenAbs - 1));143 RTTESTI_CHECK(AudioMixBufFree(&mb) == AudioMixBufSize(&mb) - cFramesWrittenAbs - 1); 144 RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_F2B(&mb, cBufSize - cFramesWrittenAbs - 1)); 146 145 RTTESTI_CHECK(AudioMixBufUsed(&mb) == cBufSize - cToRead); 147 146 148 RTTESTI_CHECK_RC_OK(AudioMixBufReadCirc(&mb, & samples16, sizeof(samples16), &cSamplesRead));149 RTTESTI_CHECK(c SamplesRead == 1);150 AudioMixBufFinish(&mb, c SamplesRead);151 RTTESTI_CHECK(AudioMixBufFree(&mb) == cBufSize - c SamplesWrittenAbs);152 RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_ S2B(&mb, cBufSize - cSamplesWrittenAbs));153 RTTESTI_CHECK(AudioMixBufUsed(&mb) == c SamplesWrittenAbs);147 RTTESTI_CHECK_RC_OK(AudioMixBufReadCirc(&mb, &aFrames16, sizeof(aFrames16), &cFramesRead)); 148 RTTESTI_CHECK(cFramesRead == 1); 149 AudioMixBufFinish(&mb, cFramesRead); 150 RTTESTI_CHECK(AudioMixBufFree(&mb) == cBufSize - cFramesWrittenAbs); 151 RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_F2B(&mb, cBufSize - cFramesWrittenAbs)); 152 RTTESTI_CHECK(AudioMixBufUsed(&mb) == cFramesWrittenAbs); 154 153 155 154 AudioMixBufDestroy(&mb); … … 191 190 RTTESTI_CHECK(DrvAudioHlpPCMPropsAreValid(&cfg_c1)); 192 191 193 uint32_t c Samples = 16;194 uint32_t cChildBufSize = RTRandU32Ex(c Samples /* Min */, 64 /* Max */);192 uint32_t cFrames = 16; 193 uint32_t cChildBufSize = RTRandU32Ex(cFrames /* Min */, 64 /* Max */); 195 194 196 195 PDMAUDIOMIXBUF child1; … … 220 219 uint32_t cbBuf = _1K; 221 220 char pvBuf[_1K]; 222 int16_t samples[32] = { 0xAA, 0xBB };223 uint32_t c SamplesRead, cSamplesWritten, cSamplesMixed;224 225 uint32_t c SamplesChild1 = cSamples;226 uint32_t c SamplesChild2 = cSamples;221 int16_t aFrames16[32] = { 0xAA, 0xBB }; 222 uint32_t cFramesRead, cFramesWritten, cFramesMixed; 223 224 uint32_t cFramesChild1 = cFrames; 225 uint32_t cFramesChild2 = cFrames; 227 226 228 227 uint32_t t = RTRandU32() % 32; 229 228 230 229 RTTestPrintf(hTest, RTTESTLVL_DEBUG, 231 "cParentBufSize=%RU32, cChildBufSize=%RU32, %RU32 samples -> %RU32 iterations total\n",232 cParentBufSize, cChildBufSize, c Samples, t);230 "cParentBufSize=%RU32, cChildBufSize=%RU32, %RU32 frames -> %RU32 iterations total\n", 231 cParentBufSize, cChildBufSize, cFrames, t); 233 232 234 233 /* … … 248 247 { 249 248 /* Child 1. */ 250 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufWriteAt(&child1, 0, & samples, sizeof(samples), &cSamplesWritten));251 RTTESTI_CHECK_MSG_BREAK(c SamplesWritten == cSamplesChild1, ("Child1: Expected %RU32 written samples, got %RU32\n", cSamplesChild1, cSamplesWritten));252 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufMixToParent(&child1, c SamplesWritten, &cSamplesMixed));253 254 cChildrenSamplesMixedTotal += c SamplesMixed;255 256 RTTESTI_CHECK_MSG_BREAK(c SamplesWritten == cSamplesMixed, ("Child1: Expected %RU32 mixed samples, got %RU32\n", cSamplesWritten, cSamplesMixed));257 RTTESTI_CHECK_MSG_BREAK(AudioMixBufUsed(&child1) == 0, ("Child1: Expected %RU32 used samples, got %RU32\n", 0, AudioMixBufUsed(&child1)));249 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufWriteAt(&child1, 0, &aFrames16, sizeof(aFrames16), &cFramesWritten)); 250 RTTESTI_CHECK_MSG_BREAK(cFramesWritten == cFramesChild1, ("Child1: Expected %RU32 written frames, got %RU32\n", cFramesChild1, cFramesWritten)); 251 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufMixToParent(&child1, cFramesWritten, &cFramesMixed)); 252 253 cChildrenSamplesMixedTotal += cFramesMixed; 254 255 RTTESTI_CHECK_MSG_BREAK(cFramesWritten == cFramesMixed, ("Child1: Expected %RU32 mixed frames, got %RU32\n", cFramesWritten, cFramesMixed)); 256 RTTESTI_CHECK_MSG_BREAK(AudioMixBufUsed(&child1) == 0, ("Child1: Expected %RU32 used frames, got %RU32\n", 0, AudioMixBufUsed(&child1))); 258 257 } 259 258 … … 263 262 { 264 263 /* Child 2. */ 265 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufWriteAt(&child2, 0, & samples, sizeof(samples), &cSamplesWritten));266 RTTESTI_CHECK_MSG_BREAK(c SamplesWritten == cSamplesChild2, ("Child2: Expected %RU32 written samples, got %RU32\n", cSamplesChild2, cSamplesWritten));267 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufMixToParent(&child2, c SamplesWritten, &cSamplesMixed));268 269 cChildrenSamplesMixedTotal += c SamplesMixed;270 271 RTTESTI_CHECK_MSG_BREAK(c SamplesWritten == cSamplesMixed, ("Child2: Expected %RU32 mixed samples, got %RU32\n", cSamplesWritten, cSamplesMixed));272 RTTESTI_CHECK_MSG_BREAK(AudioMixBufUsed(&child2) == 0, ("Child2: Expected %RU32 used samples, got %RU32\n", 0, AudioMixBufUsed(&child2)));264 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufWriteAt(&child2, 0, &aFrames16, sizeof(aFrames16), &cFramesWritten)); 265 RTTESTI_CHECK_MSG_BREAK(cFramesWritten == cFramesChild2, ("Child2: Expected %RU32 written frames, got %RU32\n", cFramesChild2, cFramesWritten)); 266 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufMixToParent(&child2, cFramesWritten, &cFramesMixed)); 267 268 cChildrenSamplesMixedTotal += cFramesMixed; 269 270 RTTESTI_CHECK_MSG_BREAK(cFramesWritten == cFramesMixed, ("Child2: Expected %RU32 mixed frames, got %RU32\n", cFramesWritten, cFramesMixed)); 271 RTTESTI_CHECK_MSG_BREAK(AudioMixBufUsed(&child2) == 0, ("Child2: Expected %RU32 used frames, got %RU32\n", 0, AudioMixBufUsed(&child2))); 273 272 } 274 273 275 274 /* 276 * Read out all samples from the parent buffer and also mark the just-read samples as finished275 * Read out all frames from the parent buffer and also mark the just-read frames as finished 277 276 * so that both connected children buffers can keep track of their stuff. 278 277 */ … … 280 279 while (cParentSamples) 281 280 { 282 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, pvBuf, cbBuf, &c SamplesRead));283 if (!c SamplesRead)281 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, pvBuf, cbBuf, &cFramesRead)); 282 if (!cFramesRead) 284 283 break; 285 284 286 AudioMixBufFinish(&parent, c SamplesRead);287 288 RTTESTI_CHECK(cParentSamples >= c SamplesRead);289 cParentSamples -= c SamplesRead;285 AudioMixBufFinish(&parent, cFramesRead); 286 287 RTTESTI_CHECK(cParentSamples >= cFramesRead); 288 cParentSamples -= cFramesRead; 290 289 } 291 290 … … 331 330 * take shortcuts and performs conversion. Because conversion to double 332 331 * the sample rate effectively inserts one additional sample between every 333 * two source samples, N source samples will be converted to N * 2 - 1334 * samples. However, the last source sample will be saved for later332 * two source frames, N source frames will be converted to N * 2 - 1 333 * frames. However, the last source sample will be saved for later 335 334 * interpolation and not immediately output. 336 335 */ … … 353 352 RTTESTI_CHECK_RC_OK(AudioMixBufLinkTo(&child, &parent)); 354 353 355 /* 8-bit unsigned samples. Often used with SB16 device. */356 uint8_t samples[16] = { 0xAA, 0xBB, 0, 1, 43, 125, 126, 127,357 128, 129, 130, 131, 132, UINT8_MAX - 1, UINT8_MAX, 0 };354 /* 8-bit unsigned frames. Often used with SB16 device. */ 355 uint8_t aFrames8U[16] = { 0xAA, 0xBB, 0, 1, 43, 125, 126, 127, 356 128, 129, 130, 131, 132, UINT8_MAX - 1, UINT8_MAX, 0 }; 358 357 359 358 /* … … 362 361 uint32_t cbBuf = 256; 363 362 char achBuf[256]; 364 uint32_t c SamplesRead, cSamplesWritten, cSamplesMixed;365 366 uint32_t c SamplesChild = 16;367 uint32_t c SamplesParent = cSamplesChild * 2 - 2;368 uint32_t c SamplesTotalRead = 0;363 uint32_t cFramesRead, cFramesWritten, cFramesMixed; 364 365 uint32_t cFramesChild = 16; 366 uint32_t cFramesParent = cFramesChild * 2 - 2; 367 uint32_t cFramesTotalRead = 0; 369 368 370 369 /**** 8-bit unsigned samples ****/ 371 370 RTTestPrintf(hTest, RTTESTLVL_DEBUG, "Conversion test %uHz %uch 8-bit\n", cfg_c.uHz, cfg_c.cChannels); 372 RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&child, & samples, sizeof(samples), &cSamplesWritten));373 RTTESTI_CHECK_MSG(c SamplesWritten == cSamplesChild, ("Child: Expected %RU32 written samples, got %RU32\n", cSamplesChild, cSamplesWritten));374 RTTESTI_CHECK_RC_OK(AudioMixBufMixToParent(&child, c SamplesWritten, &cSamplesMixed));375 uint32_t c Samples = AudioMixBufUsed(&parent);376 RTTESTI_CHECK_MSG(AudioMixBufLive(&child) == c Samples, ("Child: Expected %RU32 mixed samples, got %RU32\n", AudioMixBufLive(&child), cSamples));371 RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&child, &aFrames8U, sizeof(aFrames8U), &cFramesWritten)); 372 RTTESTI_CHECK_MSG(cFramesWritten == cFramesChild, ("Child: Expected %RU32 written frames, got %RU32\n", cFramesChild, cFramesWritten)); 373 RTTESTI_CHECK_RC_OK(AudioMixBufMixToParent(&child, cFramesWritten, &cFramesMixed)); 374 uint32_t cFrames = AudioMixBufUsed(&parent); 375 RTTESTI_CHECK_MSG(AudioMixBufLive(&child) == cFrames, ("Child: Expected %RU32 mixed frames, got %RU32\n", AudioMixBufLive(&child), cFrames)); 377 376 378 377 RTTESTI_CHECK(AudioMixBufUsed(&parent) == AudioMixBufLive(&child)); … … 380 379 for (;;) 381 380 { 382 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, achBuf, cbBuf, &c SamplesRead));383 if (!c SamplesRead)381 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, achBuf, cbBuf, &cFramesRead)); 382 if (!cFramesRead) 384 383 break; 385 c SamplesTotalRead += cSamplesRead;386 AudioMixBufFinish(&parent, c SamplesRead);387 } 388 389 RTTESTI_CHECK_MSG(c SamplesTotalRead == cSamplesParent, ("Parent: Expected %RU32 mixed samples, got %RU32\n", cSamplesParent, cSamplesTotalRead));390 391 /* Check that the samples came out unharmed. Every other sample is interpolated and we ignore it. */384 cFramesTotalRead += cFramesRead; 385 AudioMixBufFinish(&parent, cFramesRead); 386 } 387 388 RTTESTI_CHECK_MSG(cFramesTotalRead == cFramesParent, ("Parent: Expected %RU32 mixed frames, got %RU32\n", cFramesParent, cFramesTotalRead)); 389 390 /* Check that the frames came out unharmed. Every other sample is interpolated and we ignore it. */ 392 391 /* NB: This also checks that the default volume setting is 0dB attenuation. */ 393 uint8_t *pSrc8 = & samples[0];392 uint8_t *pSrc8 = &aFrames8U[0]; 394 393 uint8_t *pDst8 = (uint8_t *)achBuf; 395 394 396 for (i = 0; i < c SamplesChild - 1; ++i)395 for (i = 0; i < cFramesChild - 1; ++i) 397 396 { 398 397 RTTESTI_CHECK_MSG(*pSrc8 == *pDst8, ("index %u: Dst=%d, Src=%d\n", i, *pDst8, *pSrc8)); … … 452 451 453 452 /* 16-bit signed. More or less exclusively used as output, and usually as input, too. */ 454 int16_t samples[16] = { 0xAA, 0xBB, INT16_MIN, INT16_MIN + 1, INT16_MIN / 2, -3, -2, -1,455 0, 1, 2, 3, INT16_MAX / 2, INT16_MAX - 1, INT16_MAX, 0 };453 int16_t aFrames16S[16] = { 0xAA, 0xBB, INT16_MIN, INT16_MIN + 1, INT16_MIN / 2, -3, -2, -1, 454 0, 1, 2, 3, INT16_MAX / 2, INT16_MAX - 1, INT16_MAX, 0 }; 456 455 457 456 /* … … 460 459 uint32_t cbBuf = 256; 461 460 char achBuf[256]; 462 uint32_t c SamplesRead, cSamplesWritten, cSamplesMixed;463 464 uint32_t c SamplesChild = 16;465 uint32_t c SamplesParent = cSamplesChild * 2 - 2;466 uint32_t c SamplesTotalRead = 0;461 uint32_t cFramesRead, cFramesWritten, cFramesMixed; 462 463 uint32_t cFramesChild = 16; 464 uint32_t cFramesParent = cFramesChild * 2 - 2; 465 uint32_t cFramesTotalRead = 0; 467 466 468 467 /**** 16-bit signed samples ****/ 469 468 RTTestPrintf(hTest, RTTESTLVL_DEBUG, "Conversion test %uHz %uch 16-bit\n", cfg_c.uHz, cfg_c.cChannels); 470 RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&child, & samples, sizeof(samples), &cSamplesWritten));471 RTTESTI_CHECK_MSG(c SamplesWritten == cSamplesChild, ("Child: Expected %RU32 written samples, got %RU32\n", cSamplesChild, cSamplesWritten));472 RTTESTI_CHECK_RC_OK(AudioMixBufMixToParent(&child, c SamplesWritten, &cSamplesMixed));473 uint32_t c Samples = AudioMixBufUsed(&parent);474 RTTESTI_CHECK_MSG(AudioMixBufLive(&child) == c Samples, ("Child: Expected %RU32 mixed samples, got %RU32\n", AudioMixBufLive(&child), cSamples));469 RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&child, &aFrames16S, sizeof(aFrames16S), &cFramesWritten)); 470 RTTESTI_CHECK_MSG(cFramesWritten == cFramesChild, ("Child: Expected %RU32 written frames, got %RU32\n", cFramesChild, cFramesWritten)); 471 RTTESTI_CHECK_RC_OK(AudioMixBufMixToParent(&child, cFramesWritten, &cFramesMixed)); 472 uint32_t cFrames = AudioMixBufUsed(&parent); 473 RTTESTI_CHECK_MSG(AudioMixBufLive(&child) == cFrames, ("Child: Expected %RU32 mixed frames, got %RU32\n", AudioMixBufLive(&child), cFrames)); 475 474 476 475 RTTESTI_CHECK(AudioMixBufUsed(&parent) == AudioMixBufLive(&child)); … … 478 477 for (;;) 479 478 { 480 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, achBuf, cbBuf, &c SamplesRead));481 if (!c SamplesRead)479 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, achBuf, cbBuf, &cFramesRead)); 480 if (!cFramesRead) 482 481 break; 483 c SamplesTotalRead += cSamplesRead;484 AudioMixBufFinish(&parent, c SamplesRead);485 } 486 RTTESTI_CHECK_MSG(c SamplesTotalRead == cSamplesParent, ("Parent: Expected %RU32 mixed samples, got %RU32\n", cSamplesParent, cSamplesTotalRead));487 488 /* Check that the samples came out unharmed. Every other sample is interpolated and we ignore it. */482 cFramesTotalRead += cFramesRead; 483 AudioMixBufFinish(&parent, cFramesRead); 484 } 485 RTTESTI_CHECK_MSG(cFramesTotalRead == cFramesParent, ("Parent: Expected %RU32 mixed frames, got %RU32\n", cFramesParent, cFramesTotalRead)); 486 487 /* Check that the frames came out unharmed. Every other sample is interpolated and we ignore it. */ 489 488 /* NB: This also checks that the default volume setting is 0dB attenuation. */ 490 int16_t *pSrc16 = & samples[0];489 int16_t *pSrc16 = &aFrames16S[0]; 491 490 int16_t *pDst16 = (int16_t *)achBuf; 492 491 493 for (i = 0; i < c SamplesChild - 1; ++i)492 for (i = 0; i < cFramesChild - 1; ++i) 494 493 { 495 494 RTTESTI_CHECK_MSG(*pSrc16 == *pDst16, ("index %u: Dst=%d, Src=%d\n", i, *pDst16, *pSrc16)); … … 538 537 539 538 /* A few 16-bit signed samples. */ 540 int16_t samples[16] = { INT16_MIN, INT16_MIN + 1, -128, -64, -4, -1, 0, 1,541 2, 255, 256, INT16_MAX / 2, INT16_MAX - 2, INT16_MAX - 1, INT16_MAX, 0 };539 int16_t aFrames16S[16] = { INT16_MIN, INT16_MIN + 1, -128, -64, -4, -1, 0, 1, 540 2, 255, 256, INT16_MAX / 2, INT16_MAX - 2, INT16_MAX - 1, INT16_MAX, 0 }; 542 541 543 542 /* … … 546 545 uint32_t cbBuf = 256; 547 546 char achBuf[256]; 548 uint32_t c SamplesRead, cSamplesWritten, cSamplesMixed;549 550 uint32_t c SamplesChild = 8;551 uint32_t c SamplesParent = cSamplesChild;552 uint32_t c SamplesTotalRead;547 uint32_t cFramesRead, cFramesWritten, cFramesMixed; 548 549 uint32_t cFramesChild = 8; 550 uint32_t cFramesParent = cFramesChild; 551 uint32_t cFramesTotalRead; 553 552 int16_t *pSrc16; 554 553 int16_t *pDst16; … … 561 560 AudioMixBufSetVolume(&child, &vol); 562 561 563 RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&child, & samples, sizeof(samples), &cSamplesWritten));564 RTTESTI_CHECK_MSG(c SamplesWritten == cSamplesChild, ("Child: Expected %RU32 written samples, got %RU32\n", cSamplesChild, cSamplesWritten));565 RTTESTI_CHECK_RC_OK(AudioMixBufMixToParent(&child, c SamplesWritten, &cSamplesMixed));566 567 c SamplesTotalRead = 0;562 RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&child, &aFrames16S, sizeof(aFrames16S), &cFramesWritten)); 563 RTTESTI_CHECK_MSG(cFramesWritten == cFramesChild, ("Child: Expected %RU32 written frames, got %RU32\n", cFramesChild, cFramesWritten)); 564 RTTESTI_CHECK_RC_OK(AudioMixBufMixToParent(&child, cFramesWritten, &cFramesMixed)); 565 566 cFramesTotalRead = 0; 568 567 for (;;) 569 568 { 570 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, achBuf, cbBuf, &c SamplesRead));571 if (!c SamplesRead)569 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, achBuf, cbBuf, &cFramesRead)); 570 if (!cFramesRead) 572 571 break; 573 c SamplesTotalRead += cSamplesRead;574 AudioMixBufFinish(&parent, c SamplesRead);575 } 576 RTTESTI_CHECK_MSG(c SamplesTotalRead == cSamplesParent, ("Parent: Expected %RU32 mixed samples, got %RU32\n", cSamplesParent, cSamplesTotalRead));577 578 /* Check that at 0dB the samples came out unharmed. */579 pSrc16 = & samples[0];572 cFramesTotalRead += cFramesRead; 573 AudioMixBufFinish(&parent, cFramesRead); 574 } 575 RTTESTI_CHECK_MSG(cFramesTotalRead == cFramesParent, ("Parent: Expected %RU32 mixed frames, got %RU32\n", cFramesParent, cFramesTotalRead)); 576 577 /* Check that at 0dB the frames came out unharmed. */ 578 pSrc16 = &aFrames16S[0]; 580 579 pDst16 = (int16_t *)achBuf; 581 580 582 for (i = 0; i < c SamplesParent * 2 /* stereo */; ++i)581 for (i = 0; i < cFramesParent * 2 /* stereo */; ++i) 583 582 { 584 583 RTTESTI_CHECK_MSG(*pSrc16 == *pDst16, ("index %u: Dst=%d, Src=%d\n", i, *pDst16, *pSrc16)); … … 592 591 AudioMixBufSetVolume(&child, &vol); 593 592 594 RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&child, & samples, sizeof(samples), &cSamplesWritten));595 RTTESTI_CHECK_MSG(c SamplesWritten == cSamplesChild, ("Child: Expected %RU32 written samples, got %RU32\n", cSamplesChild, cSamplesWritten));596 RTTESTI_CHECK_RC_OK(AudioMixBufMixToParent(&child, c SamplesWritten, &cSamplesMixed));597 598 c SamplesTotalRead = 0;593 RTTESTI_CHECK_RC_OK(AudioMixBufWriteCirc(&child, &aFrames16S, sizeof(aFrames16S), &cFramesWritten)); 594 RTTESTI_CHECK_MSG(cFramesWritten == cFramesChild, ("Child: Expected %RU32 written frames, got %RU32\n", cFramesChild, cFramesWritten)); 595 RTTESTI_CHECK_RC_OK(AudioMixBufMixToParent(&child, cFramesWritten, &cFramesMixed)); 596 597 cFramesTotalRead = 0; 599 598 for (;;) 600 599 { 601 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, achBuf, cbBuf, &c SamplesRead));602 if (!c SamplesRead)600 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, achBuf, cbBuf, &cFramesRead)); 601 if (!cFramesRead) 603 602 break; 604 c SamplesTotalRead += cSamplesRead;605 AudioMixBufFinish(&parent, c SamplesRead);606 } 607 RTTESTI_CHECK_MSG(c SamplesTotalRead == cSamplesParent, ("Parent: Expected %RU32 mixed samples, got %RU32\n", cSamplesParent, cSamplesTotalRead));603 cFramesTotalRead += cFramesRead; 604 AudioMixBufFinish(&parent, cFramesRead); 605 } 606 RTTESTI_CHECK_MSG(cFramesTotalRead == cFramesParent, ("Parent: Expected %RU32 mixed frames, got %RU32\n", cFramesParent, cFramesTotalRead)); 608 607 609 608 /* Check that at -6dB the sample values are halved. */ 610 pSrc16 = & samples[0];609 pSrc16 = &aFrames16S[0]; 611 610 pDst16 = (int16_t *)achBuf; 612 611 613 for (i = 0; i < c SamplesParent * 2 /* stereo */; ++i)612 for (i = 0; i < cFramesParent * 2 /* stereo */; ++i) 614 613 { 615 614 /* Watch out! For negative values, x >> 1 is not the same as x / 2. */
Note:
See TracChangeset
for help on using the changeset viewer.