> ## 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 概述](/build/console-features/audio/overviews/xma2-overview)。有关 XBOX One 音频架构的概述，请参阅**未来之声**：[XBOX One 中的音频架构](/build/console-features/audio/overviews/xbox-one-audio-architecture)。

## 要求

**头文件：** xma2defs.h

**支持的平台：** XBOX One 系列主机和 XBOX Series 主机

## 另请参阅

[xma2defs](/reference/audio/xma2defs/xma2defs_members)


## Related topics

- [XMA2Defs](/zh-CN/reference/audio/xma2defs/xma2defs_members.md)
- [GetXmaFrameBitPosition](/zh-CN/reference/audio/xma2defs/functions/getxmaframebitposition.md)
- [GetLastXmaFrameBitPosition](/zh-CN/reference/audio/xma2defs/functions/getlastxmaframebitposition.md)
- [GetXmaPacketFirstFrameOffsetInBits](/zh-CN/reference/audio/xma2defs/functions/getxmapacketfirstframeoffsetinbits.md)
- [GetXmaDecodePositionForSample](/zh-CN/reference/audio/xma2defs/functions/getxmadecodepositionforsample.md)
