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

# XDspConnectWithMaximumStreamLimit

> XDspConnectWithMaximumStreamLimit

# XDspConnectWithMaximumStreamLimit

Establishes a connection with the hardware server, creates an XDSP client instance, and allocates the necessary resources for processing. This is similar to XDspConnect API except that it takes two additional parameters maximumStreamCount and maximumChannelCount to help reduce the overall memory used by the API. There is a global limit of 8 active XDSP clients simultaneously.

## Syntax

```cpp theme={null}
HRESULT XDspConnectWithMaximumStreamLimit(  
         float* baseBuffer,  
         uint32_t baseBufferLength,  
         uint32_t aggregateImpulseResponseInSeconds,
         uint32_t maximumStreamCount,
         uint32_t maximumChannelCount,  
         XDspClientHandle* handle  
)  
```

### Parameters

*baseBuffer*   \_In\_\
Type: float\*

Contiguous buffer that is allocated by an XDSP caller to be used to pass input data and retrieve the output data. For additional details, see the **Remarks** section below.

*baseBufferLength*   \_In\_\
Type: uint32\_t

Length of the *baseBuffer*, in bytes. This length must be at least 64 KB and no more than 500 MB.

*aggregateImpulseResponseInSeconds*   \_In\_\
Type: uint32\_t

Represents the overall duration of all the individual impulse responses duration that will be activated simultaneously on this client. *aggregateImpulseResponseInSeconds*, must be set to a value larger than zero for [XDspProcessType::Convolution](/reference/audio/xdspaudio/enums/xdspprocesstype), otherwise it must be zero. There is a global limit of 128 seconds of aggregate impulse response across all XDSP clients.

*maximumStreamCount*   \_In\_\
Type: uint32\_t

Maximum number of streams that can be active at any given point in time for this XDspClientHandle. This count may not exceed 256. XDspActivate returns XDSP\_E\_NO\_DEVICE\_RESOURCES if this count is exceeded.

*maximumChannelCount*   \_In\_\
Type: uint32\_t

This can be either 1 (for mono streams) or 2 (for stereo streams). This API returns E\_INVALIDARG if anything else is used.

*handle*   \_Outptr\_\
Type: [XDspClientHandle\*](/reference/audio/xdspaudio/handles/xdspclienthandle)

Handle to an XDSP client that should be used to activate streams via [XDspActivate](/reference/audio/xdspaudio/functions/xdspactivate) and disconnect the client from the hardware sever via [XDspDisconnect](/reference/audio/xdspaudio/functions/xdspdisconnect).

### Return value

Type: HRESULT

If the method succeeds, it returns S\_OK. If the method fails, it returns one of the following codes (partial list):

| Return code                                          | Description                                                                                                                                                                                   |
| ---------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| E\_INVALIDARG                                        | One or more of the arguments are invalid.                                                                                                                                                     |
| E\_OUTOFMEMORY                                       | Memory allocation failed.                                                                                                                                                                     |
| XDSP\_E\_MAX\_CLIENTS\_EXCEEDED                      | The maximum number of XDspClients have already been created.                                                                                                                                  |
| XDSP\_E\_MAX\_AGGREGATE\_IMPULSE\_RESPONSE\_EXCEEDED | The current [XDspConnect](/reference/audio/xdspaudio/functions/xdspconnect) call will cause XDSP to exceed the maximum supported aggregate impulse response length, and is therefore invalid. |

## Remarks

If the call succeeds, the *baseBuffer* can be used by the caller to pass input data and retrieve the output data of the stream via [XDspCommand](/reference/audio/xdspaudio/structs/xdspcommand) parameters. If enveloping is used, this buffer should also account for the buffers for storing envelope parameters. Please see [Overview of Enveloping using XDSP API](/build/console-features/audio/overviews/xdsp-overview-enveloping) for more information on enveloping.

This function must be called before activating XDSP streams to register one large memory chunk enough to hold multiple complete audio streams for use as input, multiple output buffers for all the XDSP streams that will be activated via [XDspActivate](/reference/audio/xdspaudio/functions/xdspactivate), and multiple block multiplier buffers that may be used as part of the [XDspCommand](/reference/audio/xdspaudio/structs/xdspcommand) for the [XDspProcessType::ForwardFourierTransform](/reference/audio/xdspaudio/enums/xdspprocesstype) processing type. Please be aware of the minimum and maximum size requirements for this buffer, as noted above. If this call succeeds, all XDSP streams can access any part of this memory chunk.

This memory should be allocated via XMemAlloc() with these attributes: **XALLOC\_MEMTYPE\_PHYSICAL\_CACHEABLE**, **XALLOC\_PAGESIZE\_64KB**, **XALLOC\_ALIGNMENT\_64K**

These attributes should be set using **MAKE\_XALLOC\_ATTRIBUTES()**.

An example of this is as follows:

```cpp theme={null}
static const ULONGLONG XMemAllocAttributes = MAKE_XALLOC_ATTRIBUTES(allocatorId,
   0,
   XALLOC_MEMTYPE_PHYSICAL_CACHEABLE,
   XALLOC_PAGESIZE_64KB,
   XALLOC_ALIGNMENT_64K,
   FALSE);
```

*allocatorId* in the above example should be replaced with the correct allocator id used by the title.

It is up to the caller to partition and recycle *baseBuffer* to hold different input streams and output buffers for multiple streams. The *impulseResponse* need not be from this *baseBuffer* and it can be from any memory allocated by the caller.

The memory pointed to by *baseBuffer* should not be freed until [XDspConnect](/reference/audio/xdspaudio/functions/xdspconnect) is called.

All memory pointers that are passed to [XDSP API](/reference/audio/xdspaudio/xdspaudio_members) must be 16-byte aligned.

If the call succeeds, a valid [XDspClientHandle](/reference/audio/xdspaudio/handles/xdspclienthandle) will be returned to be used with [XDspActivate](/reference/audio/xdspaudio/functions/xdspactivate) and [XDspDisconnect](/reference/audio/xdspaudio/functions/xdspdisconnect) calls.

## Requirements

**Header:** XDspAudio.h

**Library:** Chad.lib

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

## Conceptual documentation

* [Overview of XDSP Enveloping](/build/console-features/audio/overviews/xdsp-overview-enveloping)
* [Overview of a single stream Convolution with Envelope using the XDSP API](/build/console-features/audio/overviews/xdsp-overview-single-stream-convolution-with-envelope)
* [Overview of a single stream Convolution using the XDSP API](/build/console-features/audio/overviews/xdsp-overview-single-stream-convolution)
* [XDSP overview](/build/console-features/audio/overviews/xdsp-overview)

## See also

[XDSP](/reference/audio/xdspaudio/xdspaudio_members)\
[XDSPConnect](/reference/audio/xdspaudio/functions/xdspconnect)\
[XDspDisconnect](/reference/audio/xdspaudio/functions/xdspdisconnect)\
[XDSP Errors](/reference/audio/xdspaudio/enums/xdsperrors)\
[Overview of a single stream Convolution using the XDSP API](/build/console-features/audio/overviews/xdsp-overview-single-stream-convolution)\
[Overview of a single stream FFT/IFFT using the XDSP API](/build/console-features/audio/overviews/xdsp-overview-single-stream-fft-ifft)\
[Overview of a single stream Convolution with Envelope using the XDSP API](/build/console-features/audio/overviews/xdsp-overview-single-stream-convolution-with-envelope)


## Related topics

- [XDspConnect](/reference/audio/xdspaudio/functions/xdspconnect.md)
- [XDSP overview](/build/console-features/audio/overviews/xdsp-overview.md)
- [Overview of a single stream Convolution using the XDSP API](/build/console-features/audio/overviews/xdsp-overview-single-stream-convolution.md)
- [Single-stream convolution with envelope using the XDSP API](/build/console-features/audio/overviews/xdsp-overview-single-stream-convolution-with-envelope.md)
- [XDSP Enveloping Overview](/build/console-features/audio/overviews/xdsp-overview-enveloping.md)
