VirtualBox

Changeset 89347 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 28, 2021 11:10:11 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
144696
Message:

DevSB16: Fixed a whole bunch of illegal PDMAUDIOPCMPROPS accesss - use the getters and setters, duh. Untested. bugref:9890

File:
1 edited

Legend:

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

    r89341 r89347  
    412412    }
    413413
    414     unsigned cShiftChannels = pStream->Cfg.Props.cChannelsX >= 2 ? 1 : 0;
     414    /** @todo r=bird: Use '(pThis->mixer_regs[0x0e] & 2) == 0 ? 1 : 2' like below? */
     415    unsigned cShiftChannels = PDMAudioPropsChannels(&pStream->Cfg.Props) >= 2 ? 1 : 0;
    415416
    416417    if (dma_len != -1)
     
    455456    pStream->dma_auto   = (cmd >> 2) & 1;
    456457
    457     pStream->Cfg.Props.fSigned    = RT_BOOL((d0 >> 4) & 1); /** @todo Use RT_BIT? */
    458     pStream->Cfg.Props.cChannelsX = (d0 >> 5) & 1 ? 2 : 1;
     458    pStream->Cfg.Props.fSigned = RT_BOOL(d0 & RT_BIT_32(4));
     459    PDMAudioPropsSetChannels(&pStream->Cfg.Props, 1 + ((d0 >> 5) & 1));
    459460
    460461    switch (cmd >> 4)
    461462    {
    462463        case 11:
    463             pStream->Cfg.Props.cbSampleX = 2 /* 16 bit */;
     464            PDMAudioPropsSetSampleSize(&pStream->Cfg.Props, 2 /*16-bit*/);
    464465            break;
    465466
    466467        case 12:
    467             pStream->Cfg.Props.cbSampleX = 1 /* 8 bit */;
     468            PDMAudioPropsSetSampleSize(&pStream->Cfg.Props, 1 /*8-bit*/);
    468469            break;
    469470
     
    486487
    487488    pStream->cbDmaBlockSize = dma_len + 1;
    488     pStream->cbDmaBlockSize <<= ((pStream->Cfg.Props.cbSampleX == 2) ? 1 : 0);
     489    pStream->cbDmaBlockSize <<= PDMAudioPropsSampleSize(&pStream->Cfg.Props) == 2 ? 1 : 0;
    489490    if (!pStream->dma_auto)
    490491    {
     
    495496         * wonders of SB16 yet again.
    496497         */
    497         pStream->cbDmaBlockSize <<= pStream->Cfg.Props.cChannelsX == 2 ? 1 : 0;
     498        pStream->cbDmaBlockSize <<= PDMAudioPropsSampleSize(&pStream->Cfg.Props) == 2 ? 1 : 0;
    498499    }
    499500
     
    823824        {
    824825            case 0x04:
    825             {
    826826                pThis->csp_mode = sb16DspGetData(pThis);
    827827                pThis->csp_reg83r = 0;
     
    829829                LogFlowFunc(("CSP command 0x04: mode=%#x\n", pThis->csp_mode));
    830830                break;
    831             }
    832831
    833832            case 0x05:
    834             {
    835833                pThis->csp_param = sb16DspGetData(pThis);
    836834                pThis->csp_value = sb16DspGetData(pThis);
    837835                LogFlowFunc(("CSP command 0x05: param=%#x value=%#x\n", pThis->csp_param, pThis->csp_value));
    838836                break;
    839             }
    840837
    841838            case 0x0e:
    842             {
    843839                v0 = sb16DspGetData(pThis);
    844840                v1 = sb16DspGetData(pThis);
     
    853849                    pThis->csp_regs[v1] = v0;
    854850                break;
    855             }
    856851
    857852            case 0x0f:
    858             {
    859853                v0 = sb16DspGetData(pThis);
    860854                LogFlowFunc(("read CSP register %#x -> %#x, mode=%#x\n", v0, pThis->csp_regs[v0], pThis->csp_mode));
     
    868862                    sb16DspSeData(pThis, pThis->csp_regs[v0]);
    869863                break;
    870             }
    871864
    872865            case 0x10:
     
    895888
    896889            case 0x41: /* Sets the output rate (in Hz). */
    897             {
    898890                pStream->Cfg.Props.uHz = sb16DspGetHiLo(pThis);
    899891                LogFlowFunc(("set freq to %RU16Hz\n", pStream->Cfg.Props.uHz));
    900892                break;
    901             }
    902893
    903894            case 0x48:
    904             {
    905895                pStream->cbDmaBlockSize = sb16DspGetLoHi(pThis) + 1;
    906896                LogFlowFunc(("set dma block len %d\n", pStream->cbDmaBlockSize));
    907897                break;
    908             }
    909898
    910899            case 0x74:
    911                 RT_FALL_THROUGH();
    912900            case 0x75:
    913                 RT_FALL_THROUGH();
    914901            case 0x76:
    915                 RT_FALL_THROUGH();
    916902            case 0x77:
    917903                /* ADPCM stuff, ignore. */
     
    919905
    920906            case 0x80: /* Sets the IRQ. */
    921             {
    922907                sb16StreamTransferScheduleNext(pThis, pStream, sb16DspGetLoHi(pThis) + 1);
    923908                break;
    924             }
    925909
    926910            case 0xe0:
    927             {
    928911                v0 = sb16DspGetData(pThis);
    929912                pThis->dsp_out_data_len = 0;
     
    931914                sb16DspSeData(pThis, ~v0);
    932915                break;
    933             }
    934916
    935917            case 0xe2:
    936             {
    937918                v0 = sb16DspGetData(pThis);
    938919                LogFlowFunc(("E2=%#x\n", v0));
    939920                break;
    940             }
    941921
    942922            case 0xe4:
     
    22092189            PDMAudioPropsInit(&pStream->Cfg.Props, 1 /* 8-bit */, false /* fSigned */, 1 /* Mono */, 11025 /* uHz */);
    22102190            RTStrCopy(pStream->Cfg.szName, sizeof(pStream->Cfg.szName), "Output");
    2211 
    22122191            break;
    22132192        }
     
    22382217{
    22392218    LogFlowFuncEnter();
    2240 
    2241     PDMAudioPropsInit(&pStream->Cfg.Props,
    2242                       pStream->Cfg.Props.cbSampleX,
    2243                       pStream->Cfg.Props.fSigned,
    2244                       pStream->Cfg.Props.cChannelsX,
    2245                       pStream->Cfg.Props.uHz);
    2246 
    2247     AssertReturn(PDMAudioPropsAreValid(&pStream->Cfg.Props), VERR_INVALID_PARAMETER);
     2219    AssertLogRelReturn(PDMAudioPropsAreValid(&pStream->Cfg.Props), VERR_INTERNAL_ERROR_5);
    22482220
    22492221    switch (pStream->uIdx)
     
    24382410static int sb16Save(PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM, PSB16STATE pThis)
    24392411{
    2440     /** Currently the saved state only contains the one-and-only output stream. */
     2412    /* The saved state only contains the one-and-only output stream. */
    24412413    PSB16STREAM pStream = &pThis->aStreams[SB16_IDX_OUT];
    24422414
     
    24492421    pHlp->pfnSSMPutS32(pSSM, pThis->dsp_out_data_len);
    24502422
    2451     /** Currently the saved state only contains the one-and-only output stream. */
    2452     pHlp->pfnSSMPutS32(pSSM, pStream->Cfg.Props.cChannelsX >= 2 ? 1 : 0);
    2453     pHlp->pfnSSMPutS32(pSSM, pStream->Cfg.Props.fSigned         ? 1 : 0);
    2454     pHlp->pfnSSMPutS32(pSSM, pStream->Cfg.Props.cbSampleX * 8 /* Convert bytes to bits */);
     2423    pHlp->pfnSSMPutS32(pSSM, PDMAudioPropsChannels(&pStream->Cfg.Props) >= 2 ? 1 : 0);
     2424    pHlp->pfnSSMPutS32(pSSM, PDMAudioPropsIsSigned(&pStream->Cfg.Props)      ? 1 : 0);
     2425    pHlp->pfnSSMPutS32(pSSM, PDMAudioPropsSampleBits(&pStream->Cfg.Props));
    24552426    pHlp->pfnSSMPutU32(pSSM, 0); /* Legacy; was PDMAUDIOFMT, unused now. */
    24562427
     
    24582429    pHlp->pfnSSMPutS32(pSSM, pStream->cbDmaBlockSize);
    24592430    pHlp->pfnSSMPutS32(pSSM, pStream->fifo);
    2460     pHlp->pfnSSMPutS32(pSSM, pStream->Cfg.Props.uHz);
     2431    pHlp->pfnSSMPutS32(pSSM, PDMAudioPropsHz(&pStream->Cfg.Props));
    24612432    pHlp->pfnSSMPutS32(pSSM, pStream->time_const);
    24622433    pHlp->pfnSSMPutS32(pSSM, 0); /* Legacy; was speaker control (on/off) for output stream. */
     
    24872458    pHlp->pfnSSMPutS32(pSSM, pStream->State.fEnabled ? 1 : 0);
    24882459    /* The stream's bitrate. Needed for backwards (legacy) compatibility. */
    2489     pHlp->pfnSSMPutS32(pSSM, AudioHlpCalcBitrate(pThis->aStreams[SB16_IDX_OUT].Cfg.Props.cbSampleX * 8,
    2490                                                  pThis->aStreams[SB16_IDX_OUT].Cfg.Props.uHz,
    2491                                                  pThis->aStreams[SB16_IDX_OUT].Cfg.Props.cChannelsX));
     2460    pHlp->pfnSSMPutS32(pSSM, AudioHlpCalcBitrate(PDMAudioPropsSampleBits(&pThis->aStreams[SB16_IDX_OUT].Cfg.Props),
     2461                                                 PDMAudioPropsHz(&pThis->aStreams[SB16_IDX_OUT].Cfg.Props),
     2462                                                 PDMAudioPropsChannels(&pThis->aStreams[SB16_IDX_OUT].Cfg.Props)));
    24922463    /* Block size alignment, superfluous and thus not saved anymore. Needed for backwards (legacy) compatibility. */
    24932464    pHlp->pfnSSMPutS32(pSSM, 0);
     
    25152486{
    25162487    PCPDMDEVHLPR3 pHlp  = pDevIns->pHlpR3;
    2517 
    2518     /** Currently the saved state only contains the one-and-only output stream. */
    2519     PSB16STREAM pStream = &pThis->aStreams[SB16_IDX_OUT];
    2520 
    2521     int32_t s32Tmp;
    2522     pHlp->pfnSSMGetS32(pSSM, &s32Tmp);
    2523     pStream->HwCfgRuntime.uIrq = s32Tmp;                        /* IRQ. */
    2524     pHlp->pfnSSMGetS32(pSSM, &s32Tmp);
    2525     pStream->HwCfgRuntime.uDmaChanLow = s32Tmp;                 /* Low (8-bit) DMA channel. */
    2526     pHlp->pfnSSMGetS32(pSSM, &s32Tmp);
    2527     pStream->HwCfgRuntime.uDmaChanHigh = s32Tmp;                /* High (16-bit) DMA channel. */
    2528     pHlp->pfnSSMGetS32(pSSM, &s32Tmp);                          /* Used I/O port. */
    2529     pStream->HwCfgRuntime.uPort = s32Tmp;
    2530     pHlp->pfnSSMGetS32(pSSM, &s32Tmp);                          /* DSP version running. */
    2531     pStream->HwCfgRuntime.uVer  = s32Tmp;
     2488    PSB16STREAM pStream = &pThis->aStreams[SB16_IDX_OUT]; /* The saved state only contains the one-and-only output stream. */
     2489    int rc;
     2490
     2491    int32_t i32Tmp;
     2492    pHlp->pfnSSMGetS32(pSSM, &i32Tmp);
     2493    pStream->HwCfgRuntime.uIrq = i32Tmp;                        /* IRQ. */
     2494    pHlp->pfnSSMGetS32(pSSM, &i32Tmp);
     2495    pStream->HwCfgRuntime.uDmaChanLow = i32Tmp;                 /* Low (8-bit) DMA channel. */
     2496    pHlp->pfnSSMGetS32(pSSM, &i32Tmp);
     2497    pStream->HwCfgRuntime.uDmaChanHigh = i32Tmp;                /* High (16-bit) DMA channel. */
     2498    pHlp->pfnSSMGetS32(pSSM, &i32Tmp);                          /* Used I/O port. */
     2499    pStream->HwCfgRuntime.uPort = i32Tmp;
     2500    pHlp->pfnSSMGetS32(pSSM, &i32Tmp);                          /* DSP version running. */
     2501    pStream->HwCfgRuntime.uVer  = i32Tmp;
    25322502    pHlp->pfnSSMGetS32(pSSM, &pThis->dsp_in_idx);
    25332503    pHlp->pfnSSMGetS32(pSSM, &pThis->dsp_out_data_len);
    2534     pHlp->pfnSSMGetS32(pSSM, &s32Tmp);                          /* Output stream: Numer of channels. */
    2535     pStream->Cfg.Props.cChannelsX = (uint8_t)s32Tmp;
    2536     pHlp->pfnSSMGetS32(pSSM, &s32Tmp);                          /* Output stream: Signed format bit. */
    2537     pStream->Cfg.Props.fSigned    = s32Tmp == 0 ? false : true;
    2538     pHlp->pfnSSMGetS32(pSSM, &s32Tmp);
    2539     pStream->Cfg.Props.cbSampleX  = s32Tmp / 8;                 /* Convert bits to bytes. */
     2504
     2505    rc = pHlp->pfnSSMGetS32(pSSM, &i32Tmp);                     /* Output stream: Numer of channels. */
     2506    AssertRCReturn(rc, rc);
     2507    PDMAudioPropsSetChannels(&pStream->Cfg.Props, i32Tmp);
     2508    pHlp->pfnSSMGetS32(pSSM, &i32Tmp);                          /* Output stream: Signed format bit. */
     2509    pStream->Cfg.Props.fSigned = i32Tmp != 0;
     2510    rc = pHlp->pfnSSMGetS32(pSSM, &i32Tmp);                     /* Output stream: Sample size in bits. */
     2511    AssertRCReturn(rc, rc);
     2512    PDMAudioPropsSetSampleSize(&pStream->Cfg.Props, i32Tmp / 8);
     2513
    25402514    pHlp->pfnSSMSkip  (pSSM, sizeof(int32_t));                  /* Legacy; was PDMAUDIOFMT, unused now. */
    25412515    pHlp->pfnSSMGetS32(pSSM, &pStream->dma_auto);
    25422516    pHlp->pfnSSMGetS32(pSSM, &pThis->aStreams[SB16_IDX_OUT].cbDmaBlockSize);
    25432517    pHlp->pfnSSMGetS32(pSSM, &pStream->fifo);
    2544     pHlp->pfnSSMGetS32(pSSM, &s32Tmp); pStream->Cfg.Props.uHz = s32Tmp;
     2518    pHlp->pfnSSMGetS32(pSSM, &i32Tmp); pStream->Cfg.Props.uHz = i32Tmp;
    25452519    pHlp->pfnSSMGetS32(pSSM, &pStream->time_const);
    25462520    pHlp->pfnSSMSkip  (pSSM, sizeof(int32_t));                  /* Legacy; was speaker (on / off) for output stream. */
     
    25692543    pHlp->pfnSSMGetS32(pSSM, &pThis->nzero);
    25702544    pHlp->pfnSSMGetS32(pSSM, &pStream->cbDmaLeft);
    2571     pHlp->pfnSSMGetS32(pSSM, &s32Tmp);                          /* Output stream: DMA currently running bit. */
    2572     const bool fStreamEnabled = s32Tmp == 0 ? false: true;
     2545    pHlp->pfnSSMGetS32(pSSM, &i32Tmp);                          /* Output stream: DMA currently running bit. */
     2546    const bool fStreamEnabled = i32Tmp != 0;
    25732547    pHlp->pfnSSMSkip  (pSSM, sizeof(int32_t));                  /* Legacy; was the output stream's current bitrate (in bytes). */
    25742548    pHlp->pfnSSMSkip  (pSSM, sizeof(int32_t));                  /* Legacy; was the output stream's DMA block alignment. */
    25752549
    25762550    int32_t mixer_nreg = 0;
    2577     int rc = pHlp->pfnSSMGetS32(pSSM, &mixer_nreg);
     2551    rc = pHlp->pfnSSMGetS32(pSSM, &mixer_nreg);
    25782552    AssertRCReturn(rc, rc);
    25792553    pThis->mixer_nreg = (uint8_t)mixer_nreg;
Note: See TracChangeset for help on using the changeset viewer.

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