VirtualBox

Ignore:
Timestamp:
Jun 13, 2016 7:35:56 AM (9 years ago)
Author:
vboxsync
Message:

Audio: Update.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Audio/DevIchAc97.cpp

    r61613 r61668  
    6060#endif /* DEBUG_andy */
    6161
    62 #define AC97_SSM_VERSION 1
    63 
    64 #define AC97_TIMER_HZ 50
     62/** Current saved state version. */
     63#define AC97_SSM_VERSION    1
     64
     65/** Timer frequency (in Hz) */
     66#define AC97_TIMER_HZ       200
    6567
    6668/** @todo Use AC97_ prefixes! */
     
    536538    bool fActive = RT_BOOL(AudioMixerSinkGetStatus(pSink) & AUDMIXSINK_STS_RUNNING);
    537539
    538     LogFlowFunc(("SD=%RU8, fActive=%RTbool\n", pStream->u8Strm, fActive));
     540    LogFlowFunc(("[SD%RU8] fActive=%RTbool\n", pStream->u8Strm, fActive));
    539541    return fActive;
    540542}
     
    565567                               fActive ? AUDMIXSINKCMD_ENABLE : AUDMIXSINKCMD_DISABLE);
    566568
    567     LogFlowFunc(("SD=%RU8, fActive=%RTbool, cStreamsActive=%RU8, rc=%Rrc\n",
     569    LogFlowFunc(("[SD%RU8] fActive=%RTbool, cStreamsActive=%RU8, rc=%Rrc\n",
    568570                 pStream->u8Strm, fActive, pThis->cStreamsActive, rc));
    569571
     
    576578    AssertPtrReturnVoid(pStream);
    577579
    578     LogFlowFuncEnter();
     580    LogFlowFunc(("[SD%RU8]\n", pStream->u8Strm));
    579581
    580582    PAC97BMREGS pRegs = &pStream->Regs;
     
    598600static void ichac97StreamDestroy(PAC97STREAM pStream)
    599601{
    600     LogFlowFunc(("SD=%RU8\n", pStream->u8Strm));
     602    LogFlowFunc(("[SD%RU8]\n", pStream->u8Strm));
    601603
    602604    if (pStream->State.au8FIFOW)
     
    926928    }
    927929
    928     LogFlowFunc(("SD=%RU8, rc=%Rrc\n", u8Strm, rc));
     930    LogFlowFunc(("[SD%RU8] rc=%Rrc\n", u8Strm, rc));
    929931    return rc;
    930932}
     
    940942    AssertPtrReturnVoid(pStrm);
    941943
    942     LogFlowFunc(("SD=%RU8\n", pStrm->u8Strm));
     944    LogFlowFunc(("[SD%RU8]\n", pStrm->u8Strm));
    943945
    944946    if (pStrm->State.au8FIFOW)
     
    11531155    PAC97BMREGS pRegs   = &pStream->Regs;
    11541156
    1155     uint32_t    addr           = pRegs->bd.addr;
     1157    uint32_t    uAddr   = pRegs->bd.addr;
     1158
    11561159    uint32_t    cbWrittenTotal = 0;
    11571160
    1158     Log3Func(("PICB=%RU16, cbMax=%RU32\n", pRegs->picb, cbToWrite));
    1159 
    1160     cbToWrite = RT_MIN((uint32_t)(pRegs->picb << 1), cbToWrite); /** @todo r=andy Assumes 16bit sample size. */
    1161     if (!cbToWrite)
     1161    Log3Func(("PICB=%RU16, cbToWrite=%RU32\n", pRegs->picb, cbToWrite));
     1162
     1163    uint32_t cbLeft = RT_MIN((uint32_t)(pRegs->picb << 1), cbToWrite); /** @todo r=andy Assumes 16bit sample size. */
     1164    if (!cbLeft)
    11621165    {
    11631166        if (pcbWritten)
     
    11681171    int rc = VINF_SUCCESS;
    11691172
    1170     LogFlowFunc(("pRegs=%p, cbMax=%RU32, cbToWrite=%RU32\n", pRegs, cbToWrite, cbToWrite));
    1171 
    11721173    Assert(pStream->State.offFIFOW <= pStream->State.cbFIFOW);
    11731174    uint32_t  cbFIFOW  = pStream->State.cbFIFOW - pStream->State.offFIFOW;
    11741175    uint8_t  *pu8FIFOW = &pStream->State.au8FIFOW[pStream->State.offFIFOW];
    11751176
    1176     uint32_t cbToRead;
    1177     while (cbToWrite)
    1178     {
    1179         cbToRead = RT_MIN(cbToWrite, cbFIFOW);
    1180         PDMDevHlpPhysRead(pDevIns, addr, pu8FIFOW, cbToRead); /** @todo r=andy Check rc? */
     1177    uint32_t cbWritten = 0;
     1178
     1179    while (cbLeft)
     1180    {
     1181        uint32_t cbToRead = RT_MIN(cbLeft, cbFIFOW);
     1182
     1183        PDMDevHlpPhysRead(pDevIns, uAddr, pu8FIFOW, cbToRead); /** @todo r=andy Check rc? */
    11811184
    11821185#ifdef AC97_DEBUG_DUMP_PCM_DATA
     
    11901193         * Write data to the mixer sink.
    11911194         */
    1192         uint32_t cbWritten;
    11931195        rc = AudioMixerSinkWrite(pThis->pSinkOutput, AUDMIXOP_COPY, pu8FIFOW, cbToRead, &cbWritten);
    1194 
    1195         LogFlowFunc(("\tcbToRead=%RU32, cbToWrite=%RU32, cbWritten=%RU32, cbLeft=%RU32, rc=%Rrc\n",
    1196                      cbToRead, cbToWrite, cbWritten, cbToWrite - cbWrittenTotal, rc));
    1197 
    11981196        if (RT_FAILURE(rc))
    11991197            break;
    12001198
    12011199        /* Advance. */
    1202         Assert(cbToWrite >= cbToRead);
    1203         cbToWrite      -= cbToRead;
    1204         addr           += cbToRead;
    1205         cbWrittenTotal += cbToRead;
     1200        Assert(cbLeft >= cbWritten);
     1201        cbLeft         -= cbWritten;
     1202        cbWrittenTotal += cbWritten;
     1203        uAddr          += cbWritten;
     1204        Assert(cbWrittenTotal <= cbToWrite);
     1205
     1206        LogFlowFunc(("%RU32 / %RU32\n", cbWrittenTotal, cbToWrite));
    12061207    }
    12071208
    12081209    /* Set new buffer descriptor address. */
    1209     pRegs->bd.addr = addr;
     1210    pRegs->bd.addr = uAddr;
    12101211
    12111212    if (RT_SUCCESS(rc))
    12121213    {
    1213         if (!cbToWrite) /* All data written? */
    1214         {
    1215             if (cbToRead < 4)
     1214        if (!cbLeft) /* All data written? */
     1215        {
     1216            if (cbWritten < 4)
    12161217            {
    1217                 AssertMsgFailed(("Unable to save last written sample, cbToRead < 4 (is %RU32)\n", cbToRead));
     1218                AssertMsgFailed(("Unable to save last written sample, cbWritten < 4 (is %RU32)\n", cbWritten));
    12181219                pThis->last_samp = 0;
    12191220            }
    12201221            else
    1221                 pThis->last_samp = *(uint32_t *)&pStream->State.au8FIFOW[pStream->State.offFIFOW + cbToRead - 4];
     1222                pThis->last_samp = *(uint32_t *)&pStream->State.au8FIFOW[pStream->State.offFIFOW + cbWritten - 4];
    12221223        }
    12231224
     
    12261227    }
    12271228
    1228     LogFlowFunc(("cbWrittenTotal=%RU32, rc=%Rrc\n", cbWrittenTotal, rc));
     1229    if (RT_FAILURE(rc))
     1230        LogFlowFunc(("Failed with %Rrc\n", rc));
     1231
    12291232    return rc;
    12301233}
     
    13281331        return;
    13291332
     1333    if (ASMAtomicReadBool(&pThis->fTimerActive) == true) /* Alredy started? */
     1334        return;
     1335
    13301336    LogFlowFunc(("Starting timer\n"));
    13311337
     
    13461352
    13471353    if (!pThis->pTimer)
     1354        return;
     1355
     1356    if (ASMAtomicReadBool(&pThis->fTimerActive) == false) /* Already stopped? */
    13481357        return;
    13491358
     
    13821391        cbToProcess = AudioMixerSinkGetReadable(pThis->pSinkLineIn);
    13831392        if (cbToProcess)
    1384         {
    13851393            rc = ichac97TransferAudio(pThis, &pThis->StreamLineIn, cbToProcess, NULL /* pcbProcessed */);
    1386             fKickTimer |= RT_SUCCESS(rc);
    1387         }
     1394
     1395        fKickTimer |= AudioMixerSinkGetStatus(pThis->pSinkLineIn) & AUDMIXSINK_STS_DIRTY;
    13881396    }
    13891397
     
    13931401        cbToProcess = AudioMixerSinkGetReadable(pThis->pSinkMicIn);
    13941402        if (cbToProcess)
    1395         {
    13961403            rc = ichac97TransferAudio(pThis, &pThis->StreamMicIn, cbToProcess, NULL /* pcbProcessed */);
    1397             fKickTimer |= RT_SUCCESS(rc);
    1398         }
     1404
     1405        fKickTimer |= AudioMixerSinkGetStatus(pThis->pSinkMicIn) & AUDMIXSINK_STS_DIRTY;
    13991406    }
    14001407
     
    14041411        cbToProcess = AudioMixerSinkGetWritable(pThis->pSinkOutput);
    14051412        if (cbToProcess)
    1406         {
    14071413            rc = ichac97TransferAudio(pThis, &pThis->StreamOut, cbToProcess, NULL /* pcbProcessed */);
    1408             fKickTimer |= RT_SUCCESS(rc);
    1409         }
     1414
     1415        fKickTimer |= AudioMixerSinkGetStatus(pThis->pSinkOutput) & AUDMIXSINK_STS_DIRTY;
    14101416    }
    14111417
     
    14301436    /* pcbProcessed is optional. */
    14311437
    1432     Log3Func(("SD=%RU8\n", pStream->u8Strm));
     1438    Log3Func(("[SD%RU8] cbToProcess=%RU32\n", pStream->u8Strm, cbToProcess));
    14331439
    14341440    PAC97BMREGS pRegs = &pStream->Regs;
     
    14571463    if (pRegs->sr & SR_BCIS)
    14581464    {
     1465        Log3Func(("[SD%RU8] BCIS set\n", pStream->u8Strm));
    14591466        if (pcbProcessed)
    14601467            *pcbProcessed = 0;
     
    14641471    int rc = VINF_SUCCESS;
    14651472
    1466     uint32_t cbLeft  = cbToProcess;
     1473    uint32_t cbLeft  = RT_MIN((uint32_t)(pRegs->picb << 1), cbToProcess);
    14671474    uint32_t cbTotal = 0;
     1475
     1476    Log3Func(("[SD%RU8] cbLeft=%RU32\n", pStream->u8Strm, cbLeft));
    14681477
    14691478    while (cbLeft)
     
    15011510            case PO_INDEX:
    15021511            {
    1503                 cbToTransfer = (uint32_t)(pRegs->picb << 1);
     1512                cbToTransfer = RT_MIN((uint32_t)(pRegs->picb << 1), cbLeft); /** @todo r=andy Assumes 16bit samples. */
    15041513
    15051514                rc = ichac97WriteAudio(pThis, pStream, cbToTransfer, &cbTransferred);
     
    15191528            case MC_INDEX:
    15201529            {
    1521                 cbToTransfer = (uint32_t)(pRegs->picb << 1);
     1530                cbToTransfer = RT_MIN((uint32_t)(pRegs->picb << 1), cbLeft); /** @todo r=andy Assumes 16bit samples. */
    15221531
    15231532                rc = ichac97ReadAudio(pThis, pStream, cbToTransfer, &cbTransferred);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette