> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# GetXmaFrameLengthInBits

> GetXmaFrameLengthInBits

# GetXmaFrameLengthInBits

讀取指定框架的 `LengthInBits` 欄位。

## 語法

```cpp theme={null}
DWORD GetXmaFrameLengthInBits(  
         const BYTE* pPacket,  
         DWORD nBitPosition  
)  
```

### 參數

*pPacket*   \_In\_\
類型：BYTE\*

指向包含該框架之 XMA 封包的指標。

*nBitPosition*   \
類型：DWORD

框架在此封包內的位元位移。

### 傳回值

類型：DWORD

長度 (以位元為單位)。

## 備註

如下列程式碼範例所示，此函式會讀取指定框架的 `LengthInBits` 欄位。

```cpp theme={null}

__inline DWORD GetXmaFrameLengthInBits
(
    __in_bcount(nBitPosition / 8 + 3)
    __in const BYTE* pPacket,  // Pointer to XMA packet[s] containing the frame
    DWORD nBitPosition         // Bit offset of the frame within this packet
)
{
    DWORD nRegion;
    DWORD nBytePosition = nBitPosition / 8;
    DWORD nBitOffset = nBitPosition % 8;

    if (nBitOffset < 2) // Only need to read 2 bytes (and might not be safe to read more)
    {
        nRegion = (DWORD)(pPacket[nBytePosition+0]) << 8 |
                  (DWORD)(pPacket[nBytePosition+1]);
        return (nRegion >> (1 - nBitOffset)) & 0x7FFF;  // Last 15 bits
    }
    else // Need to read 3 bytes
    {
        nRegion = (DWORD)(pPacket[nBytePosition+0]) << 16 |
                  (DWORD)(pPacket[nBytePosition+1]) << 8 |
                  (DWORD)(pPacket[nBytePosition+2]);
        return (nRegion >> (9 - nBitOffset)) & 0x7FFF;  // Last 15 bits
    }
}
```

如需 XMA2 的詳細資訊，請參閱 [XMA2 概觀](/zh-TW/build/console-features/audio/overviews/xma2-overview)。如需 XBOX One 音訊架構的概觀，請參閱**未來之聲**：[XBOX One 的音訊架構](/zh-TW/build/console-features/audio/overviews/xbox-one-audio-architecture)。

## 需求

**標頭：** xma2defs.h

**支援的平台：** XBOX One 系列主機和 XBOX Series 主機

## 另請參閱

[xma2defs](/zh-TW/reference/audio/xma2defs/xma2defs_members)


## Related topics

- [GetXmaFrameLengthInBits](/reference/audio/xma2defs/functions/getxmaframelengthinbits.md)
- [XMA2Defs](/reference/audio/xma2defs/xma2defs_members.md)
