> ## 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.

# GetShapeDmaMixBufferPeakMagnitude

> GetShapeDmaMixBufferPeakMagnitude

# GetShapeDmaMixBufferPeakMagnitude

Gets the peak magnitude of the Direct Memory Access (DMA) mix buffer.

## Syntax

```cpp theme={null}
float GetShapeDmaMixBufferPeakMagnitude(  
         const SHAPE_DMA_CONTEXT* context  
)  
```

### Parameters

*context*   \_In\_\
Type: [SHAPE\_DMA\_CONTEXT\*](/reference/audio/shapedmacontext/structs/shape_dma_context)

Pointer to a [SHAPE\_DMA\_CONTEXT](/reference/audio/shapedmacontext/structs/shape_dma_context) structure.

### Return value

Type: float

The peak magnitude.

## Remarks

In a title audio engine, managing headroom can be very difficult. For this reason, each [SHAPE](/build/console-features/audio/overviews/shape-overview) block maintains state associated with signal overhead and gain. Each block (except the Sample Rate Convertor \[SRC] blocks) records whether internal saturation occurred during processing.

In addition to the internal saturation flag, each hardware block also maintains two 4-bit numbers representing the magnitude of the output of the hardware block. The magnitude is calculated by determining the peak output during the audio frame, and counting the leading zeros of the absolute value of the peak. One 4-bit number is maintained with the persistent peak magnitude; the other is reset by the hardware each audio frame.

In addition to monitoring the peak magnitude of each individual hardware block, the peak magnitude of the mix buffers is also maintained. As the output of a hardware block is added to a mix buffer, the peak magnitude is calculated in the same manner (counting leading zeros). Each hardware block state maintains an additional pair of 4-bit peak magnitude values. These values represent the peak magnitude of the mix buffer after the output of the hardware block is accumulated into the mix buffer. One 4-bit number represents the ongoing, persistent peak magnitude; the other is updated every audio frame. The peak magnitude values are saved in the context of the SHAPE blocks, even though the mix-buffer state is actually being represented.

Peak magnitude is encoded according to the following table.

| Binary Value     | Description                                                                                                                                                                                                                                                                                                    |
| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 0B0000           | Saturation: a value from a calculation to produce an output has overflowed the signed 24-bit range and was replaced with the nearest extreme. Specifically, a value greater than 8,388,607 (0x7F\_FFFF) was replaced with 8,388,607 or a value less than -8,388,608 (0x80\_0000) was replaced with -8,388,608. |
| 0B0001           | Absolute value of the peak was greater than MAX >> 1 (0x3F\_FFFF).                                                                                                                                                                                                                                             |
| 0B0010           | Absolute value of the peak was greater than MAX >> 2 (0x1F\_FFFF).                                                                                                                                                                                                                                             |
| 0B0011           | Absolute value of the peak was greater than MAX >> 3.                                                                                                                                                                                                                                                          |
| 0B0100           | Absolute value of the peak was greater than MAX >> 4.                                                                                                                                                                                                                                                          |
| 0B0101           | Absolute value of the peak was greater than MAX >> 5.                                                                                                                                                                                                                                                          |
| 0B0110 to 0B1101 | Similar to the above descriptions, but when absolute value of the peak was greater than MAX >> 6 to 13.                                                                                                                                                                                                        |
| 0B1110           | Absolute value of the peak was greater than MAX >> 14.                                                                                                                                                                                                                                                         |
| 0B1111           | Absolute value of the peak was less than or equal to MAX >> 14.                                                                                                                                                                                                                                                |

To help manage overhead and avoid overflow and saturation, in addition to fine grain gain settings, a 0 to 7-bit right shift can be performed on the output of a hardware block prior to accumulation into the output mix buffer. This is designated in the context of each SHAPE hardware block.

## Requirements

**Header:** shapedmacontext.h

**Supported platforms:** XBOX One family consoles and XBOX Series consoles

## See also

[Overview of SHAPE](/build/console-features/audio/overviews/shape-overview)\
[ShapeDmaContext](/reference/audio/shapedmacontext/shapedmacontext_members)


## Related topics

- [ShapeDmaContext](/reference/audio/shapedmacontext/shapedmacontext_members.md)
- [GetShapeDmaPeakMagnitude](/reference/audio/shapedmacontext/functions/getshapedmapeakmagnitude.md)
- [GetShapeFiltVolMixBufferPeakMagnitude](/reference/audio/shapefiltvolcontext/functions/getshapefiltvolmixbufferpeakmagnitude.md)
- [GetShapeEqCompMixBufferPeakMagnitude](/reference/audio/shapeeqcompcontext/functions/getshapeeqcompmixbufferpeakmagnitude.md)
- [GetShapeSrcMixBufferPeakMagnitude1](/reference/audio/shapesrccontext/functions/getshapesrcmixbufferpeakmagnitude1.md)
