VirtualBox

Changeset 89381 in vbox for trunk/include


Ignore:
Timestamp:
May 30, 2021 8:58:13 PM (4 years ago)
Author:
vboxsync
Message:

Audio: Extended PDMAUDIOPCMPROPS with a channel map. Renamed PDMAUDIOSTREAMCHANNELID to PDMAUDIOCHANNELID and added a few items. PDMAudioPropsInit, PDMAudioPropsInitEx and (to a lesser degree) PDMAUDIOPCMPROPS_INITIALIZER will provide sensible default mappings. bugref:9890

Location:
trunk/include/VBox/vmm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/pdmaudioifs.h

    r89379 r89381  
    525525/**
    526526 * Standard speaker channel IDs.
    527  *
    528  * This can cover up to 11.0 surround sound.
    529  *
    530  * @note Any of those channels can be marked / used as the LFE channel (played
    531  *       through the subwoofer).
    532  */
    533 typedef enum PDMAUDIOSTREAMCHANNELID
     527 */
     528typedef enum PDMAUDIOCHANNELID
    534529{
    535530    /** Invalid zero value as per usual (guards against using unintialized values). */
    536     PDMAUDIOSTREAMCHANNELID_INVALID = 0,
    537     /** Unknown / not set channel ID. */
    538     PDMAUDIOSTREAMCHANNELID_UNKNOWN,
     531    PDMAUDIOCHANNELID_INVALID = 0,
     532
     533    /** Unused channel - fill with zero when encoding, ignore when decoding. */
     534    PDMAUDIOCHANNELID_UNUSED_ZERO,
     535    /** Unused channel - fill with silence when encoding, ignore when decoding. */
     536    PDMAUDIOCHANNELID_UNUSED_SILENCE,
     537
     538    /** Unknown channel ID (unable to map to PDM terms). */
     539    PDMAUDIOCHANNELID_UNKNOWN,
     540
    539541    /** Front left channel. */
    540     PDMAUDIOSTREAMCHANNELID_FRONT_LEFT,
     542    PDMAUDIOCHANNELID_FRONT_LEFT,
    541543    /** Front right channel. */
    542     PDMAUDIOSTREAMCHANNELID_FRONT_RIGHT,
     544    PDMAUDIOCHANNELID_FRONT_RIGHT,
    543545    /** Front center channel. */
    544     PDMAUDIOSTREAMCHANNELID_FRONT_CENTER,
     546    PDMAUDIOCHANNELID_FRONT_CENTER,
     547    /** Mono channel (alias for front center). */
     548    PDMAUDIOCHANNELID_MONO = PDMAUDIOCHANNELID_FRONT_CENTER,
    545549    /** Low frequency effects (subwoofer) channel. */
    546     PDMAUDIOSTREAMCHANNELID_LFE,
     550    PDMAUDIOCHANNELID_LFE,
    547551    /** Rear left channel. */
    548     PDMAUDIOSTREAMCHANNELID_REAR_LEFT,
     552    PDMAUDIOCHANNELID_REAR_LEFT,
    549553    /** Rear right channel. */
    550     PDMAUDIOSTREAMCHANNELID_REAR_RIGHT,
     554    PDMAUDIOCHANNELID_REAR_RIGHT,
    551555    /** Front left of center channel. */
    552     PDMAUDIOSTREAMCHANNELID_FRONT_LEFT_OF_CENTER,
     556    PDMAUDIOCHANNELID_FRONT_LEFT_OF_CENTER,
    553557    /** Front right of center channel. */
    554     PDMAUDIOSTREAMCHANNELID_FRONT_RIGHT_OF_CENTER,
     558    PDMAUDIOCHANNELID_FRONT_RIGHT_OF_CENTER,
    555559    /** Rear center channel. */
    556     PDMAUDIOSTREAMCHANNELID_REAR_CENTER,
     560    PDMAUDIOCHANNELID_REAR_CENTER,
    557561    /** Side left channel. */
    558     PDMAUDIOSTREAMCHANNELID_SIDE_LEFT,
     562    PDMAUDIOCHANNELID_SIDE_LEFT,
    559563    /** Side right channel. */
    560     PDMAUDIOSTREAMCHANNELID_SIDE_RIGHT,
    561     /** Left height channel. */
    562     PDMAUDIOSTREAMCHANNELID_LEFT_HEIGHT,
    563     /** Right height channel. */
    564     PDMAUDIOSTREAMCHANNELID_RIGHT_HEIGHT,
     564    PDMAUDIOCHANNELID_SIDE_RIGHT,
     565    /** Front left height channel. */
     566    PDMAUDIOCHANNELID_FRONT_LEFT_HEIGHT,
     567    /** Front center height channel. */
     568    PDMAUDIOCHANNELID_FRONT_CENTER_HEIGHT,
     569    /** Front right height channel. */
     570    PDMAUDIOCHANNELID_FRONT_RIGHT_HEIGHT,
     571    /** Rear left height channel. */
     572    PDMAUDIOCHANNELID_REAR_LEFT_HEIGHT,
     573    /** Rear center height channel. */
     574    PDMAUDIOCHANNELID_REAR_CENTER_HEIGHT,
     575    /** Rear right height channel. */
     576    PDMAUDIOCHANNELID_REAR_RIGHT_HEIGHT,
     577
    565578    /** End of valid values. */
    566     PDMAUDIOSTREAMCHANNELID_END,
     579    PDMAUDIOCHANNELID_END,
    567580    /** Hack to blow the type up to 32-bit. */
    568     PDMAUDIOSTREAMCHANNELID_32BIT_HACK = 0x7fffffff
    569 } PDMAUDIOSTREAMCHANNELID;
     581    PDMAUDIOCHANNELID_32BIT_HACK = 0x7fffffff
     582} PDMAUDIOCHANNELID;
    570583
    571584/**
     
    581594    /** Array of channel IDs being handled.
    582595     * @note The first (zero-based) index specifies the leftmost channel. */
    583     PDMAUDIOSTREAMCHANNELID     aenmIDs[2];
     596    PDMAUDIOCHANNELID           aenmIDs[2];
    584597    /** Step size (in bytes) to the channel's next frame. */
    585598    uint32_t                    cbStep;
     
    599612     * {
    600613     *     uint8_t      off;    //< Stream offset in bytes.
    601      *     uint8_t      id;     //< PDMAUDIOSTREAMCHANNELID
     614     *     uint8_t      id;     //< PDMAUDIOCHANNELID
    602615     * };
    603616     *
     
    639652    /** Sample frequency in Hertz (Hz). */
    640653    uint32_t    uHz;
     654    /** PDMAUDIOCHANNELID mappings for each channel.
     655     * This ASSUMES all channels uses the same sample size. */
     656    uint8_t     aidChannels[PDMAUDIO_MAX_CHANNELS];
     657    /** Padding the structure up to 32 bytes. */
     658    uint32_t    auPadding[3];
    641659} PDMAUDIOPCMPROPS;
    642 AssertCompileSize(PDMAUDIOPCMPROPS, 8);
     660AssertCompileSize(PDMAUDIOPCMPROPS, 32);
    643661AssertCompileSizeAlignment(PDMAUDIOPCMPROPS, 8);
    644662/** Pointer to audio stream properties. */
     
    649667/** @name Macros for use with PDMAUDIOPCMPROPS
    650668 * @{ */
    651 /** Initializer for PDMAUDIOPCMPROPS. */
     669/** Initializer for PDMAUDIOPCMPROPS.
     670 * @note The default channel mapping here is very simple and doesn't always
     671 *       match that of PDMAudioPropsInit and PDMAudioPropsInitEx. */
    652672#define PDMAUDIOPCMPROPS_INITIALIZER(a_cbSample, a_fSigned, a_cChannels, a_uHz, a_fSwapEndian) \
    653     { (uint8_t)((a_cbSample) * (a_cChannels)), PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(a_cbSample, a_cChannels), \
    654       (uint8_t)(a_cbSample), (uint8_t)(a_cChannels), a_fSigned, a_fSwapEndian, false /*fRaw*/, a_uHz }
     673    { \
     674        (uint8_t)((a_cbSample) * (a_cChannels)), PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(a_cbSample, a_cChannels), \
     675        (uint8_t)(a_cbSample), (uint8_t)(a_cChannels), a_fSigned, a_fSwapEndian, false /*fRaw*/, a_uHz, \
     676        /*aidChannels =*/ { \
     677            (a_cChannels) >   1 ? PDMAUDIOCHANNELID_FRONT_LEFT              : PDMAUDIOCHANNELID_MONO, \
     678            (a_cChannels) >=  2 ? PDMAUDIOCHANNELID_FRONT_RIGHT             : PDMAUDIOCHANNELID_INVALID, \
     679            (a_cChannels) >=  3 ? PDMAUDIOCHANNELID_FRONT_CENTER            : PDMAUDIOCHANNELID_INVALID, \
     680            (a_cChannels) >=  4 ? PDMAUDIOCHANNELID_LFE                     : PDMAUDIOCHANNELID_INVALID, \
     681            (a_cChannels) >=  5 ? PDMAUDIOCHANNELID_REAR_LEFT               : PDMAUDIOCHANNELID_INVALID, \
     682            (a_cChannels) >=  6 ? PDMAUDIOCHANNELID_REAR_RIGHT              : PDMAUDIOCHANNELID_INVALID, \
     683            (a_cChannels) >=  7 ? PDMAUDIOCHANNELID_FRONT_LEFT_OF_CENTER    : PDMAUDIOCHANNELID_INVALID, \
     684            (a_cChannels) >=  8 ? PDMAUDIOCHANNELID_FRONT_RIGHT_OF_CENTER   : PDMAUDIOCHANNELID_INVALID, \
     685            (a_cChannels) >=  9 ? PDMAUDIOCHANNELID_REAR_CENTER             : PDMAUDIOCHANNELID_INVALID, \
     686            (a_cChannels) >= 10 ? PDMAUDIOCHANNELID_SIDE_LEFT               : PDMAUDIOCHANNELID_INVALID, \
     687            (a_cChannels) >= 11 ? PDMAUDIOCHANNELID_SIDE_RIGHT              : PDMAUDIOCHANNELID_INVALID, \
     688            (a_cChannels) >= 12 ? PDMAUDIOCHANNELID_UNKNOWN                 : PDMAUDIOCHANNELID_INVALID, \
     689         }, \
     690         /* auPadding = */ { 0, 0, 0 } \
     691    }
     692
    655693/** Calculates the cShift value of given sample bits and audio channels.
    656694 * @note Does only support mono/stereo channels for now, for non-stereo/mono we
  • trunk/include/VBox/vmm/pdmaudioinline.h

    r89379 r89381  
    144144
    145145/**
     146 * Assigns default channel IDs according to the channel count.
     147 *
     148 * The assignments are taken from the standard speaker channel layouts table
     149 * in the wikipedia article on surround sound:
     150 *      https://en.wikipedia.org/wiki/Surround_sound#Standard_speaker_channels
     151 */
     152DECLINLINE(void) PDMAudioPropsSetDefaultChannelIds(PPDMAUDIOPCMPROPS pProps)
     153{
     154    unsigned cChannels = pProps->cChannelsX;
     155    switch (cChannels)
     156    {
     157        case 1:
     158            pProps->aidChannels[0] = PDMAUDIOCHANNELID_MONO;
     159            break;
     160        case 2:
     161            pProps->aidChannels[0] = PDMAUDIOCHANNELID_FRONT_LEFT;
     162            pProps->aidChannels[1] = PDMAUDIOCHANNELID_FRONT_RIGHT;
     163            break;
     164        case 3: /* 2.1 */
     165            pProps->aidChannels[0] = PDMAUDIOCHANNELID_FRONT_LEFT;
     166            pProps->aidChannels[1] = PDMAUDIOCHANNELID_FRONT_RIGHT;
     167            pProps->aidChannels[2] = PDMAUDIOCHANNELID_LFE;
     168            break;
     169        case 4: /* 4.0 */
     170            pProps->aidChannels[0] = PDMAUDIOCHANNELID_FRONT_LEFT;
     171            pProps->aidChannels[1] = PDMAUDIOCHANNELID_FRONT_RIGHT;
     172            pProps->aidChannels[2] = PDMAUDIOCHANNELID_REAR_LEFT;
     173            pProps->aidChannels[3] = PDMAUDIOCHANNELID_REAR_RIGHT;
     174            break;
     175        case 5: /* 4.1 */
     176            pProps->aidChannels[0] = PDMAUDIOCHANNELID_FRONT_LEFT;
     177            pProps->aidChannels[1] = PDMAUDIOCHANNELID_FRONT_RIGHT;
     178            pProps->aidChannels[2] = PDMAUDIOCHANNELID_FRONT_CENTER;
     179            pProps->aidChannels[3] = PDMAUDIOCHANNELID_LFE;
     180            pProps->aidChannels[4] = PDMAUDIOCHANNELID_REAR_CENTER;
     181            break;
     182        case 6: /* 5.1 */
     183            pProps->aidChannels[0] = PDMAUDIOCHANNELID_FRONT_LEFT;
     184            pProps->aidChannels[1] = PDMAUDIOCHANNELID_FRONT_RIGHT;
     185            pProps->aidChannels[2] = PDMAUDIOCHANNELID_FRONT_CENTER;
     186            pProps->aidChannels[3] = PDMAUDIOCHANNELID_LFE;
     187            pProps->aidChannels[4] = PDMAUDIOCHANNELID_REAR_LEFT;
     188            pProps->aidChannels[5] = PDMAUDIOCHANNELID_REAR_RIGHT;
     189            break;
     190        case 7: /* 6.1 */
     191            pProps->aidChannels[0] = PDMAUDIOCHANNELID_FRONT_LEFT;
     192            pProps->aidChannels[1] = PDMAUDIOCHANNELID_FRONT_RIGHT;
     193            pProps->aidChannels[2] = PDMAUDIOCHANNELID_FRONT_CENTER;
     194            pProps->aidChannels[3] = PDMAUDIOCHANNELID_LFE;
     195            pProps->aidChannels[4] = PDMAUDIOCHANNELID_REAR_LEFT;
     196            pProps->aidChannels[5] = PDMAUDIOCHANNELID_REAR_RIGHT;
     197            pProps->aidChannels[6] = PDMAUDIOCHANNELID_REAR_CENTER;
     198            break;
     199        case 8: /* 7.1 */
     200            pProps->aidChannels[0] = PDMAUDIOCHANNELID_FRONT_LEFT;
     201            pProps->aidChannels[1] = PDMAUDIOCHANNELID_FRONT_RIGHT;
     202            pProps->aidChannels[2] = PDMAUDIOCHANNELID_FRONT_CENTER;
     203            pProps->aidChannels[3] = PDMAUDIOCHANNELID_LFE;
     204            pProps->aidChannels[4] = PDMAUDIOCHANNELID_REAR_LEFT;
     205            pProps->aidChannels[5] = PDMAUDIOCHANNELID_REAR_RIGHT;
     206            pProps->aidChannels[6] = PDMAUDIOCHANNELID_FRONT_LEFT_OF_CENTER;
     207            pProps->aidChannels[7] = PDMAUDIOCHANNELID_FRONT_RIGHT_OF_CENTER;
     208            break;
     209        case 9: /* 9.0 */
     210            pProps->aidChannels[0] = PDMAUDIOCHANNELID_FRONT_LEFT;
     211            pProps->aidChannels[1] = PDMAUDIOCHANNELID_FRONT_RIGHT;
     212            pProps->aidChannels[2] = PDMAUDIOCHANNELID_FRONT_CENTER;
     213            pProps->aidChannels[3] = PDMAUDIOCHANNELID_REAR_LEFT;
     214            pProps->aidChannels[4] = PDMAUDIOCHANNELID_REAR_RIGHT;
     215            pProps->aidChannels[5] = PDMAUDIOCHANNELID_SIDE_LEFT;
     216            pProps->aidChannels[6] = PDMAUDIOCHANNELID_SIDE_RIGHT;
     217            pProps->aidChannels[7] = PDMAUDIOCHANNELID_FRONT_LEFT_HEIGHT;
     218            pProps->aidChannels[8] = PDMAUDIOCHANNELID_FRONT_RIGHT_HEIGHT;
     219            break;
     220        case 10: /* 9.1 */
     221            pProps->aidChannels[0] = PDMAUDIOCHANNELID_FRONT_LEFT;
     222            pProps->aidChannels[1] = PDMAUDIOCHANNELID_FRONT_RIGHT;
     223            pProps->aidChannels[2] = PDMAUDIOCHANNELID_FRONT_CENTER;
     224            pProps->aidChannels[3] = PDMAUDIOCHANNELID_LFE;
     225            pProps->aidChannels[4] = PDMAUDIOCHANNELID_REAR_LEFT;
     226            pProps->aidChannels[5] = PDMAUDIOCHANNELID_REAR_RIGHT;
     227            pProps->aidChannels[6] = PDMAUDIOCHANNELID_SIDE_LEFT;
     228            pProps->aidChannels[7] = PDMAUDIOCHANNELID_SIDE_RIGHT;
     229            pProps->aidChannels[8] = PDMAUDIOCHANNELID_FRONT_LEFT_HEIGHT;
     230            pProps->aidChannels[9] = PDMAUDIOCHANNELID_FRONT_RIGHT_HEIGHT;
     231            break;
     232        case 11: /* 11.0 */
     233            pProps->aidChannels[0] = PDMAUDIOCHANNELID_FRONT_LEFT;
     234            pProps->aidChannels[1] = PDMAUDIOCHANNELID_FRONT_RIGHT;
     235            pProps->aidChannels[2] = PDMAUDIOCHANNELID_FRONT_CENTER;
     236            pProps->aidChannels[3] = PDMAUDIOCHANNELID_REAR_LEFT;
     237            pProps->aidChannels[4] = PDMAUDIOCHANNELID_REAR_RIGHT;
     238            pProps->aidChannels[5] = PDMAUDIOCHANNELID_FRONT_LEFT_OF_CENTER;
     239            pProps->aidChannels[6] = PDMAUDIOCHANNELID_FRONT_RIGHT_OF_CENTER;
     240            pProps->aidChannels[7] = PDMAUDIOCHANNELID_SIDE_LEFT;
     241            pProps->aidChannels[8] = PDMAUDIOCHANNELID_SIDE_RIGHT;
     242            pProps->aidChannels[9] = PDMAUDIOCHANNELID_FRONT_LEFT_HEIGHT;
     243            pProps->aidChannels[10]= PDMAUDIOCHANNELID_FRONT_RIGHT_HEIGHT;
     244            break;
     245        default:
     246            AssertFailed();
     247            cChannels = 12;
     248            RT_FALL_THROUGH();
     249        case 12: /* 11.1 */
     250            pProps->aidChannels[0] = PDMAUDIOCHANNELID_FRONT_LEFT;
     251            pProps->aidChannels[1] = PDMAUDIOCHANNELID_FRONT_RIGHT;
     252            pProps->aidChannels[2] = PDMAUDIOCHANNELID_FRONT_CENTER;
     253            pProps->aidChannels[3] = PDMAUDIOCHANNELID_LFE;
     254            pProps->aidChannels[4] = PDMAUDIOCHANNELID_REAR_LEFT;
     255            pProps->aidChannels[5] = PDMAUDIOCHANNELID_REAR_RIGHT;
     256            pProps->aidChannels[6] = PDMAUDIOCHANNELID_FRONT_LEFT_OF_CENTER;
     257            pProps->aidChannels[7] = PDMAUDIOCHANNELID_FRONT_RIGHT_OF_CENTER;
     258            pProps->aidChannels[8] = PDMAUDIOCHANNELID_SIDE_LEFT;
     259            pProps->aidChannels[9] = PDMAUDIOCHANNELID_SIDE_RIGHT;
     260            pProps->aidChannels[10]= PDMAUDIOCHANNELID_FRONT_LEFT_HEIGHT;
     261            pProps->aidChannels[11]= PDMAUDIOCHANNELID_FRONT_RIGHT_HEIGHT;
     262            break;
     263        case 0:
     264            break;
     265    }
     266    AssertCompile(RT_ELEMENTS(pProps->aidChannels) >= 12);
     267
     268    while (cChannels < RT_ELEMENTS(pProps->aidChannels))
     269        pProps->aidChannels[cChannels++] = PDMAUDIOCHANNELID_INVALID;
     270}
     271
     272
     273/**
    146274 * Initialize PCM audio properties.
    147275 */
     
    160288    Assert(pProps->cbSampleX  == cbSample);
    161289    Assert(pProps->cChannelsX == cChannels);
     290
     291    PDMAudioPropsSetDefaultChannelIds(pProps);
    162292}
    163293
     
    185315    Assert(pProps->cbSampleX  == cbSample);
    186316    Assert(pProps->cChannelsX == cChannels);
     317
     318    PDMAudioPropsSetDefaultChannelIds(pProps);
    187319}
    188320
    189321/**
    190322 * Modifies the channel count.
     323 *
     324 * @note    This will reset the channel IDs to defaults.
    191325 *
    192326 * @param   pProps              The PCM properties to update.
     
    199333    pProps->cbFrame     = pProps->cbSampleX * cChannels;
    200334    pProps->cShiftX     = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(pProps->cbSampleX, cChannels);
     335
     336    PDMAudioPropsSetDefaultChannelIds(pProps);
    201337}
    202338
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