VirtualBox

Ignore:
Timestamp:
Mar 12, 2021 8:41:05 PM (4 years ago)
Author:
vboxsync
Message:

Audio,DevHDA: Made PDMAUDIOPCMPROPS_F2B and PDMAUDIOPCMPROPS_B2F work for 5.1 and other frame sizes that aren't a power of two. Rewrote hdaR3StreamDoDmaOutput. Mapping is now done using converter functions rather than the complexity in hdaR3StreamTransfer. Probably fixes some recent goofs in the DMA period heuristics for non-stereo guest streams, I've renamed the members to make it clear what's what. bugref:9890

File:
1 edited

Legend:

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

    r88028 r88112  
    3838    RTTestSub(hTest, "Basics");
    3939
    40     static const PDMAUDIOPCMPROPS s_Cfg441StereoS16 = PDMAUDIOPCMPROPS_INITIALIZOR(
     40    const PDMAUDIOPCMPROPS Cfg441StereoS16 = PDMAUDIOPCMPROPS_INITIALIZOR(
    4141        /* a_cb: */             2,
    4242        /* a_fSigned: */        true,
     
    4646        /* a_fSwapEndian: */    false
    4747    );
    48     static const PDMAUDIOPCMPROPS s_Cfg441StereoU16 = PDMAUDIOPCMPROPS_INITIALIZOR(
     48    const PDMAUDIOPCMPROPS Cfg441StereoU16 = PDMAUDIOPCMPROPS_INITIALIZOR(
    4949        /* a_cb: */             2,
    5050        /* a_fSigned: */        false,
     
    5454        /* a_fSwapEndian: */    false
    5555    );
    56     static const PDMAUDIOPCMPROPS s_Cfg441StereoU32 = PDMAUDIOPCMPROPS_INITIALIZOR(
     56    const PDMAUDIOPCMPROPS Cfg441StereoU32 = PDMAUDIOPCMPROPS_INITIALIZOR(
    5757        /* a_cb: */             4,
    5858        /* a_fSigned: */        false,
     
    6363    );
    6464
    65     RTTESTI_CHECK(PDMAudioPropsGetBitrate(&s_Cfg441StereoS16) == 44100*4*8);
    66     RTTESTI_CHECK(PDMAudioPropsGetBitrate(&s_Cfg441StereoU16) == 44100*4*8);
    67     RTTESTI_CHECK(PDMAudioPropsGetBitrate(&s_Cfg441StereoU32) == 44100*8*8);
    68 
    69     RTTESTI_CHECK(DrvAudioHlpPcmPropsAreValid(&s_Cfg441StereoS16));
    70     RTTESTI_CHECK(DrvAudioHlpPcmPropsAreValid(&s_Cfg441StereoU16) == false); /* go figure */
    71     RTTESTI_CHECK(DrvAudioHlpPcmPropsAreValid(&s_Cfg441StereoU32) == false); /* go figure */
    72 
    73 
    74     RTTESTI_CHECK_MSG(PDMAUDIOPCMPROPS_F2B(&s_Cfg441StereoS16, 1) == 4,
    75                       ("got %x, expected 4\n", PDMAUDIOPCMPROPS_F2B(&s_Cfg441StereoS16, 1)));
    76     RTTESTI_CHECK_MSG(PDMAUDIOPCMPROPS_F2B(&s_Cfg441StereoU16, 1) == 4,
    77                       ("got %x, expected 4\n", PDMAUDIOPCMPROPS_F2B(&s_Cfg441StereoU16, 1)));
    78     RTTESTI_CHECK_MSG(PDMAUDIOPCMPROPS_F2B(&s_Cfg441StereoU32, 1) == 8,
    79                       ("got %x, expected 4\n", PDMAUDIOPCMPROPS_F2B(&s_Cfg441StereoU32, 1)));
    80 
    81     RTTESTI_CHECK_MSG(PDMAudioPropsBytesPerFrame(&s_Cfg441StereoS16) == 4,
    82                       ("got %x, expected 4\n", PDMAudioPropsBytesPerFrame(&s_Cfg441StereoS16)));
    83     RTTESTI_CHECK_MSG(PDMAudioPropsBytesPerFrame(&s_Cfg441StereoU16) == 4,
    84                       ("got %x, expected 4\n", PDMAudioPropsBytesPerFrame(&s_Cfg441StereoU16)));
    85     RTTESTI_CHECK_MSG(PDMAudioPropsBytesPerFrame(&s_Cfg441StereoU32) == 8,
    86                       ("got %x, expected 4\n", PDMAudioPropsBytesPerFrame(&s_Cfg441StereoU32)));
     65    RTTESTI_CHECK(PDMAudioPropsGetBitrate(&Cfg441StereoS16) == 44100*4*8);
     66    RTTESTI_CHECK(PDMAudioPropsGetBitrate(&Cfg441StereoU16) == 44100*4*8);
     67    RTTESTI_CHECK(PDMAudioPropsGetBitrate(&Cfg441StereoU32) == 44100*8*8);
     68
     69    RTTESTI_CHECK(DrvAudioHlpPcmPropsAreValid(&Cfg441StereoS16));
     70    RTTESTI_CHECK(DrvAudioHlpPcmPropsAreValid(&Cfg441StereoU16) == false); /* go figure */
     71    RTTESTI_CHECK(DrvAudioHlpPcmPropsAreValid(&Cfg441StereoU32) == false); /* go figure */
     72
     73
     74    RTTESTI_CHECK_MSG(PDMAUDIOPCMPROPS_F2B(&Cfg441StereoS16, 1) == 4,
     75                      ("got %x, expected 4\n", PDMAUDIOPCMPROPS_F2B(&Cfg441StereoS16, 1)));
     76    RTTESTI_CHECK_MSG(PDMAUDIOPCMPROPS_F2B(&Cfg441StereoU16, 1) == 4,
     77                      ("got %x, expected 4\n", PDMAUDIOPCMPROPS_F2B(&Cfg441StereoU16, 1)));
     78    RTTESTI_CHECK_MSG(PDMAUDIOPCMPROPS_F2B(&Cfg441StereoU32, 1) == 8,
     79                      ("got %x, expected 4\n", PDMAUDIOPCMPROPS_F2B(&Cfg441StereoU32, 1)));
     80
     81    RTTESTI_CHECK_MSG(PDMAudioPropsBytesPerFrame(&Cfg441StereoS16) == 4,
     82                      ("got %x, expected 4\n", PDMAudioPropsBytesPerFrame(&Cfg441StereoS16)));
     83    RTTESTI_CHECK_MSG(PDMAudioPropsBytesPerFrame(&Cfg441StereoU16) == 4,
     84                      ("got %x, expected 4\n", PDMAudioPropsBytesPerFrame(&Cfg441StereoU16)));
     85    RTTESTI_CHECK_MSG(PDMAudioPropsBytesPerFrame(&Cfg441StereoU32) == 8,
     86                      ("got %x, expected 4\n", PDMAudioPropsBytesPerFrame(&Cfg441StereoU32)));
    8787
    8888    uint32_t u32;
    8989    for (uint32_t i = 0; i < 256; i += 8)
    9090    {
    91         RTTESTI_CHECK(PDMAudioPropsIsSizeAligned(&s_Cfg441StereoU32, i) == true);
     91        RTTESTI_CHECK(PDMAudioPropsIsSizeAligned(&Cfg441StereoU32, i) == true);
    9292        for (uint32_t j = 1; j < 8; j++)
    93             RTTESTI_CHECK(PDMAudioPropsIsSizeAligned(&s_Cfg441StereoU32, i + j) == false);
     93            RTTESTI_CHECK(PDMAudioPropsIsSizeAligned(&Cfg441StereoU32, i + j) == false);
    9494        for (uint32_t j = 0; j < 8; j++)
    95             RTTESTI_CHECK(PDMAudioPropsFloorBytesToFrame(&s_Cfg441StereoU32, i + j) == i);
     95            RTTESTI_CHECK(PDMAudioPropsFloorBytesToFrame(&Cfg441StereoU32, i + j) == i);
    9696    }
    9797    for (uint32_t i = 0; i < 4096; i += 4)
    9898    {
    99         RTTESTI_CHECK(PDMAudioPropsIsSizeAligned(&s_Cfg441StereoS16, i) == true);
     99        RTTESTI_CHECK(PDMAudioPropsIsSizeAligned(&Cfg441StereoS16, i) == true);
    100100        for (uint32_t j = 1; j < 4; j++)
    101             RTTESTI_CHECK(PDMAudioPropsIsSizeAligned(&s_Cfg441StereoS16, i + j) == false);
     101            RTTESTI_CHECK(PDMAudioPropsIsSizeAligned(&Cfg441StereoS16, i + j) == false);
    102102        for (uint32_t j = 0; j < 4; j++)
    103             RTTESTI_CHECK(PDMAudioPropsFloorBytesToFrame(&s_Cfg441StereoS16, i + j) == i);
    104     }
    105 
    106     RTTESTI_CHECK_MSG((u32 = PDMAudioPropsFramesToBytes(&s_Cfg441StereoS16, 44100)) == 44100 * 2 * 2,
     103            RTTESTI_CHECK(PDMAudioPropsFloorBytesToFrame(&Cfg441StereoS16, i + j) == i);
     104    }
     105
     106    RTTESTI_CHECK_MSG((u32 = PDMAudioPropsFramesToBytes(&Cfg441StereoS16, 44100)) == 44100 * 2 * 2,
    107107                      ("cb=%RU32\n", u32));
    108     RTTESTI_CHECK_MSG((u32 = PDMAudioPropsFramesToBytes(&s_Cfg441StereoS16, 2)) == 2 * 2 * 2,
     108    RTTESTI_CHECK_MSG((u32 = PDMAudioPropsFramesToBytes(&Cfg441StereoS16, 2)) == 2 * 2 * 2,
    109109                      ("cb=%RU32\n", u32));
    110     RTTESTI_CHECK_MSG((u32 = PDMAudioPropsFramesToBytes(&s_Cfg441StereoS16, 1)) == 4,
     110    RTTESTI_CHECK_MSG((u32 = PDMAudioPropsFramesToBytes(&Cfg441StereoS16, 1)) == 4,
    111111                      ("cb=%RU32\n", u32));
    112     RTTESTI_CHECK_MSG((u32 = PDMAudioPropsFramesToBytes(&s_Cfg441StereoU16, 1)) == 4,
     112    RTTESTI_CHECK_MSG((u32 = PDMAudioPropsFramesToBytes(&Cfg441StereoU16, 1)) == 4,
    113113                      ("cb=%RU32\n", u32));
    114     RTTESTI_CHECK_MSG((u32 = PDMAudioPropsFramesToBytes(&s_Cfg441StereoU32, 1)) == 8,
     114    RTTESTI_CHECK_MSG((u32 = PDMAudioPropsFramesToBytes(&Cfg441StereoU32, 1)) == 8,
    115115                      ("cb=%RU32\n", u32));
    116116
    117     RTTESTI_CHECK_MSG((u32 = PDMAudioPropsBytesToFrames(&s_Cfg441StereoS16, 4)) == 1, ("cb=%RU32\n", u32));
    118     RTTESTI_CHECK_MSG((u32 = PDMAudioPropsBytesToFrames(&s_Cfg441StereoU16, 4)) == 1, ("cb=%RU32\n", u32));
    119     RTTESTI_CHECK_MSG((u32 = PDMAudioPropsBytesToFrames(&s_Cfg441StereoU32, 8)) == 1, ("cb=%RU32\n", u32));
     117    RTTESTI_CHECK_MSG((u32 = PDMAudioPropsBytesToFrames(&Cfg441StereoS16, 4)) == 1, ("cb=%RU32\n", u32));
     118    RTTESTI_CHECK_MSG((u32 = PDMAudioPropsBytesToFrames(&Cfg441StereoU16, 4)) == 1, ("cb=%RU32\n", u32));
     119    RTTESTI_CHECK_MSG((u32 = PDMAudioPropsBytesToFrames(&Cfg441StereoU32, 8)) == 1, ("cb=%RU32\n", u32));
    120120
    121121    uint64_t u64;
    122     RTTESTI_CHECK_MSG((u64 = PDMAudioPropsBytesToNano(&s_Cfg441StereoS16, 44100 * 2 * 2)) == RT_NS_1SEC,
     122    RTTESTI_CHECK_MSG((u64 = PDMAudioPropsBytesToNano(&Cfg441StereoS16, 44100 * 2 * 2)) == RT_NS_1SEC,
    123123                      ("ns=%RU64\n", u64));
    124     RTTESTI_CHECK_MSG((u64 = PDMAudioPropsBytesToMicro(&s_Cfg441StereoS16, 44100 * 2 * 2)) == RT_US_1SEC,
     124    RTTESTI_CHECK_MSG((u64 = PDMAudioPropsBytesToMicro(&Cfg441StereoS16, 44100 * 2 * 2)) == RT_US_1SEC,
    125125                      ("us=%RU64\n", u64));
    126     RTTESTI_CHECK_MSG((u64 = PDMAudioPropsBytesToMilli(&s_Cfg441StereoS16, 44100 * 2 * 2)) == RT_MS_1SEC,
     126    RTTESTI_CHECK_MSG((u64 = PDMAudioPropsBytesToMilli(&Cfg441StereoS16, 44100 * 2 * 2)) == RT_MS_1SEC,
    127127                      ("ms=%RU64\n", u64));
    128128
    129     RTTESTI_CHECK_MSG((u64 = PDMAudioPropsFramesToNano(&s_Cfg441StereoS16, 44100)) == RT_NS_1SEC, ("ns=%RU64\n", u64));
    130     RTTESTI_CHECK_MSG((u64 = PDMAudioPropsFramesToNano(&s_Cfg441StereoS16,     1)) == 22675,      ("ns=%RU64\n", u64));
    131     RTTESTI_CHECK_MSG((u64 = PDMAudioPropsFramesToNano(&s_Cfg441StereoS16,    31)) == 702947,     ("ns=%RU64\n", u64));
    132     RTTESTI_CHECK_MSG((u64 = PDMAudioPropsFramesToNano(&s_Cfg441StereoS16,   255)) == 5782312,    ("ns=%RU64\n", u64));
    133     //RTTESTI_CHECK_MSG((u64 = DrvAudioHlpFramesToMicro(&s_Cfg441StereoS16, 44100)) == RT_US_1SEC,
     129    RTTESTI_CHECK_MSG((u64 = PDMAudioPropsFramesToNano(&Cfg441StereoS16, 44100)) == RT_NS_1SEC, ("ns=%RU64\n", u64));
     130    RTTESTI_CHECK_MSG((u64 = PDMAudioPropsFramesToNano(&Cfg441StereoS16,     1)) == 22675,      ("ns=%RU64\n", u64));
     131    RTTESTI_CHECK_MSG((u64 = PDMAudioPropsFramesToNano(&Cfg441StereoS16,    31)) == 702947,     ("ns=%RU64\n", u64));
     132    RTTESTI_CHECK_MSG((u64 = PDMAudioPropsFramesToNano(&Cfg441StereoS16,   255)) == 5782312,    ("ns=%RU64\n", u64));
     133    //RTTESTI_CHECK_MSG((u64 = DrvAudioHlpFramesToMicro(&Cfg441StereoS16, 44100)) == RT_US_1SEC,
    134134    //                  ("us=%RU64\n", u64));
    135     RTTESTI_CHECK_MSG((u64 = PDMAudioPropsFramesToMilli(&s_Cfg441StereoS16, 44100)) == RT_MS_1SEC, ("ms=%RU64\n", u64));
    136     RTTESTI_CHECK_MSG((u64 = PDMAudioPropsFramesToMilli(&s_Cfg441StereoS16,   255)) == 5,          ("ms=%RU64\n", u64));
    137 
    138     RTTESTI_CHECK_MSG((u32 = PDMAudioPropsNanoToFrames(&s_Cfg441StereoS16,  RT_NS_1SEC)) == 44100, ("cb=%RU32\n", u32));
    139     RTTESTI_CHECK_MSG((u32 = PDMAudioPropsNanoToFrames(&s_Cfg441StereoS16,      215876)) == 10,    ("cb=%RU32\n", u32));
    140     RTTESTI_CHECK_MSG((u32 = PDMAudioPropsMilliToFrames(&s_Cfg441StereoS16, RT_MS_1SEC)) == 44100, ("cb=%RU32\n", u32));
    141     RTTESTI_CHECK_MSG((u32 = PDMAudioPropsMilliToFrames(&s_Cfg441StereoU32,          6)) == 265,   ("cb=%RU32\n", u32));
    142 
    143     RTTESTI_CHECK_MSG((u32 = PDMAudioPropsNanoToBytes(&s_Cfg441StereoS16,  RT_NS_1SEC)) == 44100*2*2, ("cb=%RU32\n", u32));
    144     RTTESTI_CHECK_MSG((u32 = PDMAudioPropsNanoToBytes(&s_Cfg441StereoS16,      702947)) == 31*2*2,    ("cb=%RU32\n", u32));
    145     RTTESTI_CHECK_MSG((u32 = PDMAudioPropsMilliToBytes(&s_Cfg441StereoS16, RT_MS_1SEC)) == 44100*2*2, ("cb=%RU32\n", u32));
    146     RTTESTI_CHECK_MSG((u32 = PDMAudioPropsMilliToBytes(&s_Cfg441StereoS16,          5)) == 884,       ("cb=%RU32\n", u32));
     135    RTTESTI_CHECK_MSG((u64 = PDMAudioPropsFramesToMilli(&Cfg441StereoS16, 44100)) == RT_MS_1SEC, ("ms=%RU64\n", u64));
     136    RTTESTI_CHECK_MSG((u64 = PDMAudioPropsFramesToMilli(&Cfg441StereoS16,   255)) == 5,          ("ms=%RU64\n", u64));
     137
     138    RTTESTI_CHECK_MSG((u32 = PDMAudioPropsNanoToFrames(&Cfg441StereoS16,  RT_NS_1SEC)) == 44100, ("cb=%RU32\n", u32));
     139    RTTESTI_CHECK_MSG((u32 = PDMAudioPropsNanoToFrames(&Cfg441StereoS16,      215876)) == 10,    ("cb=%RU32\n", u32));
     140    RTTESTI_CHECK_MSG((u32 = PDMAudioPropsMilliToFrames(&Cfg441StereoS16, RT_MS_1SEC)) == 44100, ("cb=%RU32\n", u32));
     141    RTTESTI_CHECK_MSG((u32 = PDMAudioPropsMilliToFrames(&Cfg441StereoU32,          6)) == 265,   ("cb=%RU32\n", u32));
     142
     143    RTTESTI_CHECK_MSG((u32 = PDMAudioPropsNanoToBytes(&Cfg441StereoS16,  RT_NS_1SEC)) == 44100*2*2, ("cb=%RU32\n", u32));
     144    RTTESTI_CHECK_MSG((u32 = PDMAudioPropsNanoToBytes(&Cfg441StereoS16,      702947)) == 31*2*2,    ("cb=%RU32\n", u32));
     145    RTTESTI_CHECK_MSG((u32 = PDMAudioPropsMilliToBytes(&Cfg441StereoS16, RT_MS_1SEC)) == 44100*2*2, ("cb=%RU32\n", u32));
     146    RTTESTI_CHECK_MSG((u32 = PDMAudioPropsMilliToBytes(&Cfg441StereoS16,          5)) == 884,       ("cb=%RU32\n", u32));
    147147
    148148    /* DrvAudioHlpClearBuf: */
     
    152152
    153153    memset(pbPage, 0x42, PAGE_SIZE);
    154     PDMAudioPropsClearBuffer(&s_Cfg441StereoS16, pbPage, PAGE_SIZE, PAGE_SIZE / 4);
     154    PDMAudioPropsClearBuffer(&Cfg441StereoS16, pbPage, PAGE_SIZE, PAGE_SIZE / 4);
    155155    RTTESTI_CHECK(ASMMemIsZero(pbPage, PAGE_SIZE));
    156156
    157157    memset(pbPage, 0x42, PAGE_SIZE);
    158     PDMAudioPropsClearBuffer(&s_Cfg441StereoU16, pbPage, PAGE_SIZE, PAGE_SIZE / 4);
     158    PDMAudioPropsClearBuffer(&Cfg441StereoU16, pbPage, PAGE_SIZE, PAGE_SIZE / 4);
    159159    for (uint32_t off = 0; off < PAGE_SIZE; off += 2)
    160160        RTTESTI_CHECK_MSG(pbPage[off] == 0x80 && pbPage[off + 1] == 0, ("off=%#x: %#x %x\n", off, pbPage[off], pbPage[off + 1]));
    161161
    162162    memset(pbPage, 0x42, PAGE_SIZE);
    163     PDMAudioPropsClearBuffer(&s_Cfg441StereoU32, pbPage, PAGE_SIZE, PAGE_SIZE / 8);
     163    PDMAudioPropsClearBuffer(&Cfg441StereoU32, pbPage, PAGE_SIZE, PAGE_SIZE / 8);
    164164    for (uint32_t off = 0; off < PAGE_SIZE; off += 4)
    165165        RTTESTI_CHECK(pbPage[off] == 0x80 && pbPage[off + 1] == 0 && pbPage[off + 2] == 0 && pbPage[off + 3] == 0);
     
    168168    RTTestDisableAssertions(hTest);
    169169    memset(pbPage, 0x42, PAGE_SIZE);
    170     PDMAudioPropsClearBuffer(&s_Cfg441StereoS16, pbPage, PAGE_SIZE, PAGE_SIZE); /* should adjust down the frame count. */
     170    PDMAudioPropsClearBuffer(&Cfg441StereoS16, pbPage, PAGE_SIZE, PAGE_SIZE); /* should adjust down the frame count. */
    171171    RTTESTI_CHECK(ASMMemIsZero(pbPage, PAGE_SIZE));
    172172
    173173    memset(pbPage, 0x42, PAGE_SIZE);
    174     PDMAudioPropsClearBuffer(&s_Cfg441StereoU16, pbPage, PAGE_SIZE, PAGE_SIZE); /* should adjust down the frame count. */
     174    PDMAudioPropsClearBuffer(&Cfg441StereoU16, pbPage, PAGE_SIZE, PAGE_SIZE); /* should adjust down the frame count. */
    175175    for (uint32_t off = 0; off < PAGE_SIZE; off += 2)
    176176        RTTESTI_CHECK_MSG(pbPage[off] == 0x80 && pbPage[off + 1] == 0, ("off=%#x: %#x %x\n", off, pbPage[off], pbPage[off + 1]));
    177177
    178178    memset(pbPage, 0x42, PAGE_SIZE);
    179     PDMAudioPropsClearBuffer(&s_Cfg441StereoU32, pbPage, PAGE_SIZE, PAGE_SIZE); /* should adjust down the frame count. */
     179    PDMAudioPropsClearBuffer(&Cfg441StereoU32, pbPage, PAGE_SIZE, PAGE_SIZE); /* should adjust down the frame count. */
    180180    for (uint32_t off = 0; off < PAGE_SIZE; off += 4)
    181181        RTTESTI_CHECK(pbPage[off] == 0x80 && pbPage[off + 1] == 0 && pbPage[off + 2] == 0 && pbPage[off + 3] == 0);
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