# AudioMixingUtil

Artifact: [androidx.media3:media3-common](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/common/audio/AudioMixingUtil.java+class:androidx.media3.common.audio.AudioMixingUtil)

*** ** * ** ***


```
@UnstableApi
public final class AudioMixingUtil
```

<br />

*** ** * ** ***

Utility for mixing audio buffers.

## Summary

| ### Public methods |
|---|---|
| `static boolean` | `https://developer.android.com/reference/androidx/media3/common/audio/AudioMixingUtil#canMix(androidx.media3.common.audio.AudioProcessor.AudioFormat)(https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat audioFormat)` |
| `static boolean` | `https://developer.android.com/reference/androidx/media3/common/audio/AudioMixingUtil#canMix(androidx.media3.common.audio.AudioProcessor.AudioFormat,androidx.media3.common.audio.AudioProcessor.AudioFormat)( https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat inputAudioFormat, https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat outputAudioFormat )` |
| `static https://developer.android.com/reference/java/nio/ByteBuffer.html` | `https://developer.android.com/reference/androidx/media3/common/audio/AudioMixingUtil#mix(java.nio.ByteBuffer,androidx.media3.common.audio.AudioProcessor.AudioFormat,java.nio.ByteBuffer,androidx.media3.common.audio.AudioProcessor.AudioFormat,androidx.media3.common.audio.ChannelMixingMatrix,int,boolean,boolean)( https://developer.android.com/reference/java/nio/ByteBuffer.html inputBuffer, https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat inputAudioFormat, https://developer.android.com/reference/java/nio/ByteBuffer.html mixingBuffer, https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat mixingAudioFormat, https://developer.android.com/reference/androidx/media3/common/audio/ChannelMixingMatrix matrix, int framesToMix, boolean accumulate, boolean clipFloatOutput )` Mixes audio from the input buffer into the mixing buffer. |

## Public methods

### canMix

```
public static boolean canMix(AudioProcessor.AudioFormat audioFormat)
```

### canMix

```
public static boolean canMix(
    AudioProcessor.AudioFormat inputAudioFormat,
    AudioProcessor.AudioFormat outputAudioFormat
)
```

### mix

```
public static ByteBuffer mix(
    ByteBuffer inputBuffer,
    AudioProcessor.AudioFormat inputAudioFormat,
    ByteBuffer mixingBuffer,
    AudioProcessor.AudioFormat mixingAudioFormat,
    ChannelMixingMatrix matrix,
    int framesToMix,
    boolean accumulate,
    boolean clipFloatOutput
)
```

Mixes audio from the input buffer into the mixing buffer.

`https://developer.android.com/reference/androidx/media3/common/audio/AudioMixingUtil#canMix(androidx.media3.common.audio.AudioProcessor.AudioFormat,androidx.media3.common.audio.AudioProcessor.AudioFormat)` must return `true` for the formats.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/nio/ByteBuffer.html inputBuffer` | Input audio `https://developer.android.com/reference/java/nio/ByteBuffer.html`, the position is advanced by the amount of bytes read and mixed. |
| `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat inputAudioFormat` | `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat` of the `inputBuffer`. |
| `https://developer.android.com/reference/java/nio/ByteBuffer.html mixingBuffer` | Mixing audio `https://developer.android.com/reference/java/nio/ByteBuffer.html`, the position is advanced by the amount of bytes written. |
| `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat mixingAudioFormat` | `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat` of the `mixingBuffer`. |
| `https://developer.android.com/reference/androidx/media3/common/audio/ChannelMixingMatrix matrix` | Scaled channel mapping from input to output. |
| `int framesToMix` | Number of audio frames to mix. Must be within the bounds of both buffers. |
| `boolean accumulate` | Whether to accumulate with the existing samples in the mixing buffer. |
| `boolean clipFloatOutput` | Whether to clip the output signal to be in the \[-1.0, 1.0\] range if the output encoding is `https://developer.android.com/reference/androidx/media3/common/C#ENCODING_PCM_FLOAT()`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/java/nio/ByteBuffer.html` | The `mixingBuffer`, for convenience. |