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

# XApuConnect

> XApuConnect

# XApuConnect

Establishes a connection and allocate the necessary resources for an Audio Processing Unit (XAPU).

## Syntax

```cpp theme={null}
HRESULT XApuConnect(  
         XApuConnectInputParameters* params,  
         XApuConnectOutputParameters* data,  
         XApuHandle* handle  
)  
```

### Parameters

*params*   \_In\_\
Type: [XApuConnectInputParameters\*](/reference/audio/xapu/structs/xapuconnectinputparameters)

Parameters passed to XApuConnect to allocated resources.

*data*   \_Out\_\
Type: [XApuConnectOutputParameters\*](/reference/audio/xapu/structs/xapuconnectoutputparameters)

Parameters returned by XApuConnect.

*handle*   \_Outptr\_\
Type: XApuHandle\*

Pointer to an XAPU handle returned. This handle is used to indicate which XAPU instance to manipulate when calling other XAPU APIs.

### Return value

Type: HRESULT

Returns S\_OK if successful; otherwise, returns an error code.

## Remarks

The caller must specify an [XApuProcessType](/reference/audio/xapu/enums/xapuprocesstype) for the XAPU client to perform. An instance of an XAPU can work with one type of process during its lifetime. To perform two or more different processes, two or more XAPU instances must be instantiated.

Inside the [XApuConnectInputParameters](/reference/audio/xapu/structs/xapuconnectinputparameters), the caller must specify the following:

* Maximum number of streams the XAPU is expected to process simultaneously.
* Maximum number of queued commands for each stream.
* Total required memory allocation for all commands and streams. This includes total allocations for input, output and processing data across the maximum number of streams times queued commands per stream.

If the call succeeded, the [XApuConnectOutputParameters::baseData](/reference/audio/xapu/structs/xapuconnectoutputparameters) parameter will point to a memory chunk that the caller should use to pass input data and retrieve the output data of the streams. It is up to the caller to partition and recycle this memory chunk. The allocation will be freed upon [XApuDisconnect](/reference/audio/xapu/functions/xapudisconnect) call.

[XApuConnectOutputParameters::resultReadyEvent](/reference/audio/xapu/structs/xapuconnectoutputparameters) will contain a Win32 event handle when [XApuConnectOptions::EnableResultReadyEvent](/reference/audio/xapu/enums/xapuconnectoptions) is set. This handle will be closed upon an [XApuDisconnect](/reference/audio/xapu/functions/xapudisconnect) call.

This handle will be closed upon a [XApuDisconnect](/reference/audio/xapu/functions/xapudisconnect) call.

It is not recommended to call [XapuConnect](/reference/audio/xapu/functions/xapuconnect) and [XApuDisconnect](/reference/audio/xapu/functions/xapudisconnect) often to start and stop streams as those calls are time consuming and could also lead to resource losses due to memory fragmentation. Instead [XapuConnect](/reference/audio/xapu/functions/xapuconnect) should be called once upon initialization of the streaming session, then [XApuCommandType::Activate](/reference/audio/xapu/enums/xapucommandtype) and [XApuCommandType::Deactivate](/reference/audio/xapu/enums/xapucommandtype) should be used to start and stop streams during streaming. At the end of the streaming session, [XApuDisconnect](/reference/audio/xapu/functions/xapudisconnect) should be called. This is true for all XAPU clients.

## Requirements

**Header:** xapu.h

**Library:** xapu.lib

**Supported platforms:** XBOX Series X|S

## Conceptual documentation

* [XAPU overview](/build/console-features/audio/overviews/xapu-overview)

## See also

[XAPU](/reference/audio/xapu/xapu_members)\
[XApuDecodeConvertCommand](/reference/audio/xapu/structs/xapudecodeconvertcommand)\
[XApuDequeueResult](/reference/audio/xapu/functions/xapudequeueresult)\
[XApuEnqueueCommand](/reference/audio/xapu/functions/xapuenqueuecommand)\
[XApuGetResultCount](/reference/audio/xapu/functions/xapugetresultcount)


## Related topics

- [XApuConnectOutputParameters](/reference/audio/xapu/structs/xapuconnectoutputparameters.md)
- [XApuConnectInputParameters](/reference/audio/xapu/structs/xapuconnectinputparameters.md)
- [XApuConnectOptions](/reference/audio/xapu/enums/xapuconnectoptions.md)
- [XApuDisconnect](/reference/audio/xapu/functions/xapudisconnect.md)
- [XApuProcessType](/reference/audio/xapu/enums/xapuprocesstype.md)
