# AudioMixingUtil

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

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/common/audio/AudioMixingUtil "View this page in Java")

<br />

```
@UnstableApi
class AudioMixingUtil
```

<br />

*** ** * ** ***

Utility for mixing audio buffers.

## Summary

|                                       ### Public functions                                        |
|---------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [canMix](https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioMixingUtil#canMix(androidx.media3.common.audio.AudioProcessor.AudioFormat))`(audioFormat: `[AudioProcessor.AudioFormat](https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioProcessor.AudioFormat)`!)`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `java-static `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [canMix](https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioMixingUtil#canMix(androidx.media3.common.audio.AudioProcessor.AudioFormat,androidx.media3.common.audio.AudioProcessor.AudioFormat))`(` ` inputAudioFormat: `[AudioProcessor.AudioFormat](https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioProcessor.AudioFormat)`!,` ` outputAudioFormat: `[AudioProcessor.AudioFormat](https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioProcessor.AudioFormat)`!` `)`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `java-static `[ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html)`!`   | [mix](https://developer.android.com/reference/kotlin/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))`(` ` inputBuffer: `[ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html)`!,` ` inputAudioFormat: `[AudioProcessor.AudioFormat](https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioProcessor.AudioFormat)`!,` ` mixingBuffer: `[ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html)`!,` ` mixingAudioFormat: `[AudioProcessor.AudioFormat](https://developer.android.com/reference/kotlin/androidx/media3/common/audio/AudioProcessor.AudioFormat)`!,` ` matrix: `[ChannelMixingMatrix](https://developer.android.com/reference/kotlin/androidx/media3/common/audio/ChannelMixingMatrix)`!,` ` framesToMix: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` accumulate: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`,` ` clipFloatOutput: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) `)` Mixes audio from the input buffer into the mixing buffer. |

## Public functions

### canMix

```
java-static fun canMix(audioFormat: AudioProcessor.AudioFormat!): Boolean
```  

### canMix

```
java-static fun canMix(
    inputAudioFormat: AudioProcessor.AudioFormat!,
    outputAudioFormat: AudioProcessor.AudioFormat!
): Boolean
```  

### mix

```
java-static fun mix(
    inputBuffer: ByteBuffer!,
    inputAudioFormat: AudioProcessor.AudioFormat!,
    mixingBuffer: ByteBuffer!,
    mixingAudioFormat: AudioProcessor.AudioFormat!,
    matrix: ChannelMixingMatrix!,
    framesToMix: Int,
    accumulate: Boolean,
    clipFloatOutput: Boolean
): ByteBuffer!
```

Mixes audio from the input buffer into the mixing buffer.

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

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