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

# XAudio2XMAEncoder

> XAudio2XMAEncoder

Encodes the input streams into XMA format.

<a id="syntaxSection" />

## Syntax

```cpp theme={null}
HRESULT XAudio2XMAEncoder(
         DWORD InputStreamCount,
         const XMAENCODERSTREAM *pStreams,
         DWORD Compression,
         DWORD Flags,
         DWORD BlockSizeInKbytes,
         VOID **ppEncodedBuffer,
         DWORD *pEncodedBufferSize,
         XMA2WAVEFORMATEX **ppEncodedBufferFormat,
         DWORD *pEncodedBufferFormatSize,
         DWORD **ppSeekTable,
         DWORD *pSeekTableSize)  
```

<a id="ID4EG" />

### Parameters

*InputStreamCount*
Type: DWORD

Number of input streams.

*pStreams*
Type: XMAENCODERSTREAM \*

Pointer to the input streams.

*Compression*
Type: DWORD

XMA2 compression quality level to use (1 to 100).

*Flags*
Type: DWORD

Zero, or one or more of the following flags.

| Flag                      | Value      | Description                                                                                                                                                                                                                                                                      |
| ------------------------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| XMAENCODER\_LOOP          | 0x00000001 | Use loop points if present, resampling the wave to make the loop points align to 128 sample boundaries. If loop points aren't present, loop the wave from start to finish and resample the wave so that the loop end \[full length] of the wave aligns to a 128 sample boundary. |
| XMAENCODER\_NOFILTER      | 0x00000002 | Set no filtering.                                                                                                                                                                                                                                                                |
| XMAENCODER\_DECODEFROMXMA | 0x00000004 | Not supported for in-memory encoder.                                                                                                                                                                                                                                             |
| XMAENCODER\_VERBOSE       | 0x00000008 | Enable debug output.                                                                                                                                                                                                                                                             |
| XMAENCODER\_PACKSTREAMS   | 0x00000010 | Pack channels into the fewest streams possible.                                                                                                                                                                                                                                  |

*BlockSizeInKbytes*
Type: DWORD

XMA2 compression block size to use in KB (2 to 8190). This can't be zero.

*ppEncodedBuffer*
Type: VOID \*\*

Pointer to a pointer to the buffer to contain the encoded data.

*pEncodedBufferSize*
Type: DWORD \*

Pointer to a DWORD to contain the encoded buffer size.

*ppEncodedBufferFormat*
Type: XMA2WAVEFORMATEX \*\*

Pointer to a pointer to a structure to contain the format details of the encoded streams.

*pEncodedBufferFormatSize*
Type: DWORD \*

Pointer to a DWORD to contain the size of the format structure.

*ppSeekTable*
Type: DWORD \*\*

Pointer to a pointer to contain the seek table.

*pSeekTableSize*
Type: DWORD \*

Pointer to a DWORD to contain the seek table size.

<a id="ID4EO" />

### Return value

Type: HRESULT

Returns S\_OK if successful; otherwise, returns an error code from the following table.

| Error code                       | Implementation         | Description                      |
| -------------------------------- | ---------------------- | -------------------------------- |
| XMAENCODER\_E\_OUTOFMEMORY       | E\_OUTOFMEMORY         | Out of memory.                   |
| XMAENCODER\_E\_INVALIDARG        | E\_INVALIDARG          | Invalid arg.                     |
| XMAENCODER\_E\_NOTIMPL           | E\_NOTIMPL             | Not implemented.                 |
| XMAENCODER\_E\_FAIL              | E\_FAIL                | Unknown error.                   |
| XMAENCODER\_E\_INVALIDLOOP       | XMAENCODERERROR(0x001) | The loop points are invalid.     |
| XMAENCODER\_E\_UNSUPPORTEDFORMAT | XMAENCODERERROR(0x002) | Format is invalid.               |
| XMAENCODER\_E\_OUTOFRANGE        | XMAENCODERERROR(0x003) | Parameter is out of valid range. |
| XMAENCODER\_E\_READFAILED        | XMAENCODERERROR(0x004) | Read operation failed.           |
| XMAENCODER\_E\_INVALIDFRAME      | XMAENCODERERROR(0x005) | Invalid XMA frame.               |
| XMAENCODER\_E\_INCOMPLETEFRAME   | XMAENCODERERROR(0x006) | Incomplete XMA frame.            |
| XMAENCODER\_E\_ZEROSTUFFINGBIT   | XMAENCODERERROR(0x007) | Stuffing bit is zero.            |
| XMAENCODER\_E\_GETDATAFAILED     | XMAENCODERERROR(0x008) | Data fetch failed.               |

<a id="requirements" />

## Requirements

**Header:** xmaencoder.h

**Library:** xmaencoder.lib

## See also

[XMA2 encoder tool](/build/console-features/audio/tools/xma2encodertool)


## Related topics

- [XMA2 Encoder reference information](/build/console-features/audio/tools/xma2encoder/atoc-xmaencoder.md)
- [XMA2encoder functions](/build/console-features/audio/tools/xma2encoder/tech-xmaencoder-funcs.md)
- [XMA2 encoder tool](/build/console-features/audio/tools/xma2encodertool.md)
- [ADPCM command-line encoder](/build/console-features/audio/tools/adpcmencoder-tools.md)
- [Use XAudio2 to play a sound](/build/console-features/audio/overviews/xaudio2-play-sound.md)
