Changeset 65699 in vbox for trunk/src/VBox/Devices/Audio
- Timestamp:
- Feb 9, 2017 1:25:02 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 113407
- Location:
- trunk/src/VBox/Devices/Audio
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvAudio.cpp
r65694 r65699 1281 1281 int rc = VINF_SUCCESS; 1282 1282 1283 uint32_t csPlayed = 0;1283 uint32_t csPlayedTotal = 0; 1284 1284 1285 1285 AssertPtr(pThis->pHostDrvAudio->pfnStreamGetWritable); … … 1292 1292 if (csToPlay) 1293 1293 { 1294 uint8_t u8Buf[_4K]; /** @todo Get rid of this here. */ 1295 AssertReleaseReturn(sizeof(u8Buf) >= AUDIOMIXBUF_S2B(&pHstStream->MixBuf, csToPlay), /** @todo Get rid of this here. */ 1296 VERR_BUFFER_OVERFLOW); 1297 1298 uint32_t csRead = 0; 1299 rc = AudioMixBufReadCirc(&pHstStream->MixBuf, u8Buf, AUDIOMIXBUF_S2B(&pHstStream->MixBuf, csToPlay), &csRead); 1300 if (RT_SUCCESS(rc)) 1294 uint8_t auBuf[256]; /** @todo Get rid of this here. */ 1295 1296 uint32_t cbLeft = AUDIOMIXBUF_S2B(&pHstStream->MixBuf, csToPlay); 1297 uint32_t cbChunk = sizeof(auBuf); 1298 1299 while (cbLeft) 1301 1300 { 1302 uint32_t cbPlayed; 1303 1304 AssertPtr(pThis->pHostDrvAudio->pfnStreamPlay); 1301 uint32_t csRead = 0; 1302 rc = AudioMixBufReadCirc(&pHstStream->MixBuf, auBuf, RT_MIN(cbChunk, cbLeft), &csRead); 1303 if ( !csRead 1304 || RT_FAILURE(rc)) 1305 { 1306 break; 1307 } 1308 1309 uint32_t cbRead = AUDIOMIXBUF_S2B(&pHstStream->MixBuf, csRead); 1310 Assert(cbRead <= cbChunk); 1311 1312 uint32_t cbPlayed = 0; 1305 1313 rc = pThis->pHostDrvAudio->pfnStreamPlay(pThis->pHostDrvAudio, pHstStream->pvBackend, 1306 u8Buf, AUDIOMIXBUF_S2B(&pHstStream->MixBuf, csRead), 1307 &cbPlayed); 1308 if (RT_SUCCESS(rc)) 1309 { 1310 AssertMsg(cbPlayed % 2 == 0, 1311 ("Backend for stream '%s' returned uneven played bytes count (csRead=%RU32, cbPlayed=%RU32)\n", 1312 pHstStream->szName, csRead, cbPlayed)); 1313 1314 csPlayed = AUDIOMIXBUF_B2S(&pHstStream->MixBuf, cbPlayed); 1315 } 1314 auBuf, cbRead, &cbPlayed); 1315 if (RT_FAILURE(rc)) 1316 break; 1317 1318 Assert(cbPlayed <= cbRead); 1319 AssertMsg(cbPlayed % 2 == 0, 1320 ("Backend for stream '%s' returned uneven played bytes count (csRead=%RU32, cbPlayed=%RU32)\n", 1321 pHstStream->szName, csRead, cbPlayed)); 1322 1323 csPlayedTotal += AUDIOMIXBUF_B2S(&pHstStream->MixBuf, cbPlayed); 1324 Assert(cbLeft >= cbPlayed); 1325 cbLeft -= cbPlayed; 1316 1326 } 1317 1327 } 1318 1328 } 1319 1329 1320 Log3Func(("Played %RU32/%RU32 samples, rc=%Rrc\n", csPlayed, csToPlay, rc)); 1321 1322 if (pcsPlayed) 1323 *pcsPlayed = csPlayed; 1330 Log3Func(("[%s] Played %RU32/%RU32 samples, rc=%Rrc\n", pHstStream->szName, csPlayedTotal, csToPlay, rc)); 1331 1332 if (RT_SUCCESS(rc)) 1333 { 1334 if (pcsPlayed) 1335 *pcsPlayed = csPlayedTotal; 1336 } 1324 1337 1325 1338 return rc; … … 1356 1369 int rc = VINF_SUCCESS; 1357 1370 1358 uint32_t csPlayed = 0;1371 uint32_t csPlayedTotal = 0; 1359 1372 1360 1373 AssertPtr(pThis->pHostDrvAudio->pfnStreamGetWritable); … … 1385 1398 break; 1386 1399 1387 csPlayed += csPlayedChunk;1388 Assert(csPlayed <= csToPlay);1400 csPlayedTotal += csPlayedChunk; 1401 Assert(csPlayedTotal <= csToPlay); 1389 1402 1390 1403 Assert(csLeft >= csRead); … … 1396 1409 } 1397 1410 1398 Log3Func(("Played %RU32/%RU32 samples, rc=%Rrc\n", csPlayed, csToPlay, rc)); 1399 1400 if (pcsPlayed) 1401 *pcsPlayed = csPlayed; 1411 Log3Func(("[%s] Played %RU32/%RU32 samples, rc=%Rrc\n", pHstStream->szName, csPlayedTotal, csToPlay, rc)); 1412 1413 if (RT_SUCCESS(rc)) 1414 { 1415 if (pcsPlayed) 1416 *pcsPlayed = csPlayedTotal; 1417 1418 } 1402 1419 1403 1420 return rc; -
trunk/src/VBox/Devices/Audio/DrvHostDebugAudio.cpp
r65694 r65699 47 47 struct 48 48 { 49 /** Timestamp of last played samples. */ 50 uint64_t tsLastPlayed; 51 uint8_t *pu8PlayBuffer; 49 uint8_t *auPlayBuffer; 52 50 uint32_t cbPlayBuffer; 53 51 } Out; … … 140 138 int rc = VINF_SUCCESS; 141 139 142 pStreamDbg->Out.tsLastPlayed = 0;143 140 pStreamDbg->Out.cbPlayBuffer = _1K * PDMAUDIOSTREAMCFG_S2B(pCfgReq, 1); /** @todo Make this configurable? */ 144 pStreamDbg->Out. pu8PlayBuffer= (uint8_t *)RTMemAlloc(pStreamDbg->Out.cbPlayBuffer);145 if (!pStreamDbg->Out. pu8PlayBuffer)141 pStreamDbg->Out.auPlayBuffer = (uint8_t *)RTMemAlloc(pStreamDbg->Out.cbPlayBuffer); 142 if (!pStreamDbg->Out.auPlayBuffer) 146 143 rc = VERR_NO_MEMORY; 147 144 … … 219 216 uint32_t *pcbWritten) 220 217 { 221 RT_NOREF(pvBuf, cbBuf); 222 223 PDRVHOSTDEBUGAUDIO pDrv = RT_FROM_MEMBER(pInterface, DRVHOSTDEBUGAUDIO, IHostAudio); 218 RT_NOREF(pInterface); 224 219 PDEBUGAUDIOSTREAM pStreamDbg = (PDEBUGAUDIOSTREAM)pStream; 225 220 226 /* Consume as many samples as would be played at the current frequency since last call. */ 227 /*uint32_t cLive = AudioMixBufLive(&pStream->MixBuf);*/ 228 229 uint64_t u64TicksNow = PDMDrvHlpTMGetVirtualTime(pDrv->pDrvIns); 230 // uint64_t u64TicksElapsed = u64TicksNow - pStreamDbg->Out.tsLastPlayed; 231 // uint64_t u64TicksFreq = PDMDrvHlpTMGetVirtualFreq(pDrv->pDrvIns); 232 233 /* 234 * Minimize the rounding error by adding 0.5: samples = int((u64TicksElapsed * samplesFreq) / u64TicksFreq + 0.5). 235 * If rounding is not taken into account then the playback rate will be consistently lower that expected. 236 */ 237 // uint64_t cSamplesPlayed = (2 * u64TicksElapsed * pStream->Props.uHz + u64TicksFreq) / u64TicksFreq / 2; 238 239 /* Don't play more than available. */ 240 /*if (cSamplesPlayed > cLive) 241 cSamplesPlayed = cLive;*/ 242 243 uint32_t cbWritten = 0; 244 245 uint32_t cbAvail = RT_MIN(cbBuf, pStreamDbg->Out.cbPlayBuffer); 221 uint32_t cbWrittenTotal = 0; 222 223 uint32_t cbAvail = cbBuf; 246 224 while (cbAvail) 247 225 { 248 uint32_t cbChunk = cbAvail; /** @todo Use chunks? */249 250 memcpy(pStreamDbg->Out. pu8PlayBuffer, pvBuf, cbChunk);226 uint32_t cbChunk = RT_MIN(cbAvail, pStreamDbg->Out.cbPlayBuffer); 227 228 memcpy(pStreamDbg->Out.auPlayBuffer, (uint8_t *)pvBuf + cbWrittenTotal, cbChunk); 251 229 #if 0 252 230 RTFILE fh; … … 257 235 #endif 258 236 int rc2 = DrvAudioHlpWAVFileWrite(&pStreamDbg->File, 259 pStreamDbg->Out. pu8PlayBuffer, cbChunk, 0 /* fFlags */);237 pStreamDbg->Out.auPlayBuffer, cbChunk, 0 /* fFlags */); 260 238 if (RT_FAILURE(rc2)) 261 239 { … … 265 243 266 244 Assert(cbAvail >= cbAvail); 267 cbAvail -= cbChunk; 268 269 cbWritten += cbChunk; 270 } 271 272 /* Remember when samples were consumed. */ 273 pStreamDbg->Out.tsLastPlayed = u64TicksNow; 245 cbAvail -= cbChunk; 246 247 cbWrittenTotal += cbChunk; 248 } 274 249 275 250 if (pcbWritten) 276 *pcbWritten = cbWritten ;251 *pcbWritten = cbWrittenTotal; 277 252 278 253 return VINF_SUCCESS; … … 307 282 RT_NOREF(pDrv); 308 283 309 if (pStreamDbg->Out. pu8PlayBuffer)310 { 311 RTMemFree(pStreamDbg->Out. pu8PlayBuffer);312 pStreamDbg->Out. pu8PlayBuffer = NULL;284 if (pStreamDbg->Out.auPlayBuffer) 285 { 286 RTMemFree(pStreamDbg->Out.auPlayBuffer); 287 pStreamDbg->Out.auPlayBuffer = NULL; 313 288 } 314 289
Note:
See TracChangeset
for help on using the changeset viewer.