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

# XAudio2CreateWithSharedContexts

> XAudio2CreateWithSharedContexts

# XAudio2CreateWithSharedContexts

Creates a new XAudio2 object and returns a pointer to its IXAudio2 interface.

## Syntax

```cpp theme={null}
XAUDIO2_STDAPI XAudio2CreateWithSharedContexts(  
         IXAudio2** ppXAudio2,  
         UINT32 Flags,  
         XAUDIO2_PROCESSOR XAudio2Processor,  
         const PXAUDIO2_SHARED_SHAPE_CONTEXTS SharedShapeContexts  
)  
```

### Parameters

*ppXAudio2*   \_Outptr\_\
Type: IXAudio2\*\*

If the operation is successful, it returns a pointer to an IXAudio2 object.

*Flags*   \_In\_\
Type: UINT32

Flags that specify the behavior of the IXAudio2 object.

| Flag                                     | Description                                                                                                                            |
| ---------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| XAUDIO2\_DO\_NOT\_USE\_SHAPE             | Used to prevent the engine or voice from using the Scalable Hardware Audio Processing Engine (SHAPE) including XBOX Media Audio (XMA). |
| XAUDIO2\_DO\_NOT\_SHARE\_SHAPE\_CONTEXTS | Used to force exclusive use of the SHAPE contexts provided. No other engine instance will share the contexts.                          |

*XAudio2Processor*   \_In\_\
Type: XAUDIO2\_PROCESSOR

An XAUDIO2\_PROCESSOR type value that specifies which CPU to use. Passing XAUDIO2\_USE\_DEFAULT\_PROCESSOR allows XAudio2 to choose the ideal processor at runtime.

Specifying a processor might interfere with the scheduler's ability to schedule threads effectively across processors. Instead, pass the XAUDIO2\_USE\_DEFAULT\_PROCESSOR value.

*SharedShapeContexts*   \_In\_\
Type: PXAUDIO2\_SHARED\_SHAPE\_CONTEXTS

Pointer to SHARED\_SHAPE\_CONTEXTS. This parameter is specific to XBOX One and allows a title to share SHAPE and XMA resources with XAudio2. The default is NULL.

### Return value

Type: XAUDIO2\_STDAPI

If the function succeeds, it returns `S_OK`.  If one or more of the arguments are invalid, the function returns an error code.

## Remarks

`XAudio2CreateWithSharedContexts` works the same way as the `XAudio2Create` function. It takes one extra parameter to allow state for the Scalable Hardware Audio Processing Engine (SHAPE) on XBOX One to be shared across multiple IXAudio2 instances. `PXAUDIO2_SHARED_SHAPE_CONTEXTS` is a pointer to the shared state. XAudio2 uses SHAPE contexts for XMA playback. As a feature, XMA was introduced with XBOX 360. If you use XAudio2 to play XMA audio in the XBOX 360 version of your game, or in an XBOX One game based on the older XBOX One Software Development Kit, it is essential to know that the Microsoft Game Development Kit (GDK) continues to support XMA and SHAPE contexts.

To play XMA-format audio, your app does not have to use the `XAudio2CreateWithSharedContexts` flag because the XAudio2 instance creates its own SHAPE contexts. `XAudio2CreateWithSharedContexts` is optimized for apps that have multiple XAudio2 instances. It allows the app to allocate a single set of SHAPE contexts and efficiently share them across instances.

<Note>The `XAudio2Processor` parameter should use the `XAUDIO2_USE_DEFAULT_PROCESSOR` pointer to allow the system to make the appropriate processor selection, unless the app is designed to select a specific processor.</Note>

The `XAudio2Create` parameter and `XAudio2CreateWithSharedContexts` function use flags that are applicable to games that only play XMA format audio. An app fails to play XMA content if the `XAUDIO2_DO_NOT_USE_SHAPE` flag is used. With XBOX 360, XMA audio is decoded in the software or hardware, which requires SHAPE contexts. The new version of the Microsoft Game Development Kit (GDK) supports XMA decoding in hardware. Specifying this flag will effectively break the XMA playback.

If the function calls its own SHAPE contexts, it uses the `XAUDIO2_DO_NOT_SHARE_SHAPE_CONTEXTS` flag to specify that the SHAPE contexts are for exclusive use by this XAudio2 instance. It is not recommended to specify this flag when not providing SHAPE contexts (for example, by invoking `XAudio2Create`) because when XAudio2 creates its own SHAPE contexts, they are shared.

You can also use the flag `XAUDIO2_EXCLUDE_FROM_GAME_DVR_CAPTURE`. Setting this flag prevents the game DVR from recording the audio from the mastering voice.

The header also defines the `AUDCLNT_STREAMFLAGS_EXCLUDE_FROM_GAME_DVR_CAPTURE` flag. Pass this flag to `IAudioClient::Initialize` to disable the game DVR from recording audio played by that *IAudioClient*. If your game uses XAudio2, use the `XAUDIO2_EXCLUDE_FROM_GAME_DVR_CAPTURE` flag instead for this purpose.

For more information, see [Getting started with XAudio2](https://learn.microsoft.com/windows/win32/xaudio2/getting-started?redirectedfrom=MSDN).

## Requirements

**Header:** xaudio2Xbox.h

**Library:** xaudio2.lib

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

## Conceptual documentation

* [Comparison of XBOX One Software Development Kit and Microsoft Game Development Kit (GDK) audio API](/build/console-features/audio/overviews/comparison-of-xdk-and-gdk-audio-api)

## See also

[Overview of XAudio2](/build/console-features/audio/overviews/xaudio2-overview)\
[XAudio2 Key Concepts](https://learn.microsoft.com/windows/win32/xaudio2/xaudio2-key-concepts)\
[xaudio2xbox](/reference/audio/xaudio2xbox/xaudio2xbox_members)


## Related topics

- [SHARED_SHAPE_CONTEXTS](/reference/audio/acphal/structs/shared_shape_contexts.md)
- [XDK vs GDK audio API comparison](/build/console-features/audio/overviews/comparison-of-xdk-and-gdk-audio-api.md)
- [Use XAudio2 to play a sound](/build/console-features/audio/overviews/xaudio2-play-sound.md)
- [OpenSharedHandleByName](/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_opensharedhandlebyname_public.md)
- [OpenSharedHandle](/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_opensharedhandle_public.md)
