VirtualBox

Ignore:
Timestamp:
May 12, 2021 12:52:13 PM (4 years ago)
Author:
vboxsync
Message:

Audio/ValKit: First tones can be played back by VKAT now. bugref:10008

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/utils/audio/vkat.cpp

    r88997 r89010  
    112112typedef FNAUDIOTESTDESTROY *PFNAUDIOTESTDESTROY;
    113113
     114/** Maximum audio streams a test environment can handle. */
     115#define AUDIOTESTENV_MAX_STREAMS 8
     116
    114117/**
    115118 * Audio test environment parameters.
     
    119122{
    120123    /** The host (backend) driver to use. */
    121     PPDMIHOSTAUDIO   pDrvAudio;
     124    PPDMIHOSTAUDIO        pDrvAudio;
    122125    /** The current (last) audio device enumeration to use. */
    123     PDMAUDIOHOSTENUM DevEnm;
     126    PDMAUDIOHOSTENUM      DevEnm;
     127    PDMAUDIOBACKENDSTREAM aStreams[AUDIOTESTENV_MAX_STREAMS];
    124128    /** The audio test set to use. */
    125     AUDIOTESTSET     Set;
     129    AUDIOTESTSET          Set;
    126130} AUDIOTESTENV;
    127131/** Pointer a audio test environment. */
     
    152156*********************************************************************************************************************************/
    153157static int audioTestCombineParms(PAUDIOTESTPARMS pBaseParms, PAUDIOTESTPARMS pOverrideParms);
     158static int audioTestPlayTone(PAUDIOTESTENV pTstEnv, PPDMAUDIOBACKENDSTREAM pStream, PAUDIOTESTTONEPARMS pParms);
    154159
    155160
     
    239244static DECLCALLBACK(int) audioTestPlayToneSetup(PAUDIOTESTENV pTstEnv, PAUDIOTESTDESC pTstDesc, PAUDIOTESTPARMS pTstParmsAcq, void **ppvCtx)
    240245{
    241     RT_NOREF(pTstEnv, pTstDesc, pTstParmsAcq, ppvCtx);
    242 
    243 //    PDMAudioPropsInit(&Props, 16 /* bit */ / 8, true /* fSigned */, 2 /* Channels */, 44100 /* Hz */);
    244 
    245     //AudioTestToneParamsInitRandom(&pTstParms->ToneParms, &pTstParms->ToneParms.Props);
     246    RT_NOREF(pTstEnv, pTstDesc, ppvCtx);
     247
     248    PDMAudioPropsInit(&pTstParmsAcq->ToneParms.Props, 16 /* bit */ / 8, true /* fSigned */, 2 /* Channels */, 44100 /* Hz */);
     249
     250    AudioTestToneParamsInitRandom(&pTstParmsAcq->ToneParms, &pTstParmsAcq->ToneParms.Props);
    246251
    247252    return VINF_SUCCESS;
     
    250255static DECLCALLBACK(int) audioTestPlayToneExec(PAUDIOTESTENV pTstEnv, void *pvCtx, PAUDIOTESTPARMS pTstParms)
    251256{
    252     RT_NOREF(pTstEnv, pvCtx, pTstParms);
    253 
    254     return VINF_SUCCESS;
     257    RT_NOREF(pvCtx);
     258
     259    return audioTestPlayTone(pTstEnv, &pTstEnv->aStreams[0], &pTstParms->ToneParms);
    255260}
    256261
     
    543548
    544549    return rc;
     550}
     551
     552static int audioTestPlayTone(PAUDIOTESTENV pTstEnv, PPDMAUDIOBACKENDSTREAM pStream, PAUDIOTESTTONEPARMS pParms)
     553{
     554    PDMAUDIOSTREAMCFG CfgReq;
     555    PDMAUDIOSTREAMCFG CfgAcq;
     556
     557    int rc = PDMAudioStrmCfgInitWithProps(&CfgReq, &pParms->Props);
     558    AssertRC(rc); /* Cannot fail. */
     559
     560    CfgReq.enmDir      = PDMAUDIODIR_OUT;
     561    CfgReq.u.enmDst    = PDMAUDIOPLAYBACKDST_FRONT;
     562    CfgReq.enmLayout   = PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED;
     563
     564    rc = PDMAudioStrmCfgCopy(&CfgAcq, &CfgReq);
     565    AssertRC(rc); /* Ditto. */
     566
     567    rc = pTstEnv->pDrvAudio->pfnStreamCreate(pTstEnv->pDrvAudio, pStream, &CfgReq, &CfgAcq);
     568    if (RT_FAILURE(rc))
     569        return rc;
     570
     571    /* Do the async init in a synchronous way for now here. */
     572    if (rc == VINF_AUDIO_STREAM_ASYNC_INIT_NEEDED)
     573        rc = pTstEnv->pDrvAudio->pfnStreamInitAsync(pTstEnv->pDrvAudio, pStream, false /* fDestroyed */);
     574
     575    AUDIOTESTTONE TstTone;
     576    AudioTestToneInitRandom(&TstTone, &pParms->Props);
     577
     578    PDMHOSTAUDIOSTREAMSTATE enmState = pTstEnv->pDrvAudio->pfnStreamGetState(pTstEnv->pDrvAudio, pStream);
     579    if (enmState == PDMHOSTAUDIOSTREAMSTATE_OKAY)
     580    {
     581        uint32_t cbBuf;
     582        uint8_t  abBuf[_4K];
     583
     584        const uint64_t tsStartMs     = RTTimeMilliTS();
     585        const unsigned cSchedulingMs = 10;
     586        const uint32_t cbPerMs       = PDMAudioPropsMilliToBytes(&CfgAcq.Props, cSchedulingMs);
     587
     588        do
     589        {
     590            rc = AudioTestToneWrite(&TstTone, abBuf, RT_MIN(cbPerMs, sizeof(abBuf)), &cbBuf);
     591            if (RT_SUCCESS(rc))
     592            {
     593                uint32_t cbWritten;
     594                rc = pTstEnv->pDrvAudio->pfnStreamPlay(pTstEnv->pDrvAudio, pStream, abBuf, cbBuf, &cbWritten);
     595            }
     596
     597            if (RTTimeMilliTS() - tsStartMs >= pParms->msDuration)
     598                break;
     599
     600            RTThreadSleep(cSchedulingMs);
     601
     602        } while (RT_SUCCESS(rc));
     603    }
     604
     605    int rc2 = pTstEnv->pDrvAudio->pfnStreamDestroy(pTstEnv->pDrvAudio, pStream);
     606    if (RT_SUCCESS(rc))
     607        rc = rc2;
     608
     609    return VINF_SUCCESS;
    545610}
    546611
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