# ChannelMixingMatrix

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/ChannelMixingMatrix.java+class:androidx.media3.common.audio.ChannelMixingMatrix)

*** ** * ** ***

<br />

```
@UnstableApi
class ChannelMixingMatrix
```

<br />

*** ** * ** ***

An immutable matrix that describes the mapping of input channels to output channels.

The matrix coefficients define the scaling factor to use when mixing samples from the input channel (row) to the output channel (column).

Examples:

- Stereo to mono with each channel at half volume:

  ```kotlin
  [0.5 0.5]
  ```
- Stereo to stereo with no mixing or scaling:

  ```kotlin
          [1 0
  0 1]
  ```
- Stereo to stereo with 0.7 volume:

  ```kotlin
          [0.7 0
  0 0.7]
  ```

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/ChannelMixingMatrix#ChannelMixingMatrix(int,int,float[])( inputChannelCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, outputChannelCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, coefficients: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>! )` Creates a matrix with the given coefficients in row-major order. |

| ### Public functions |
|---|---|
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/common/audio/ChannelMixingMatrix!` | `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/ChannelMixingMatrix#createForConstantGain(int,int)( inputChannelCount: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1, to = 2) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, outputChannelCount: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1, to = 2) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Returns a default constant gain channel mixing matrix that mixes `inputChannelCount` channels into `outputChannelCount` channels. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/common/audio/ChannelMixingMatrix!` | `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/ChannelMixingMatrix#createForConstantPower(int,int)( inputChannelCount: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1, to = 6) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, outputChannelCount: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1, to = 2) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Returns a default constant power channel mixing matrix that mixes `inputChannelCount` channels into `outputChannelCount` channels. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/ChannelMixingMatrix#getMixingCoefficient(int,int)(inputChannel: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, outputChannel: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Gets the scaling factor for the given input and output channel. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/ChannelMixingMatrix#isSquare()()` Returns whether the input and output channel count is the same. |
| `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/ChannelMixingMatrix!` | `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/ChannelMixingMatrix#scaleBy(float)(scale: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Returns a new matrix with the given scaling factor applied to all coefficients. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/ChannelMixingMatrix#inputChannelCount()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/ChannelMixingMatrix#isDiagonal()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/ChannelMixingMatrix#isIdentity()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/ChannelMixingMatrix#isZero()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/ChannelMixingMatrix#outputChannelCount()` |

## Public constructors

### ChannelMixingMatrix

```
ChannelMixingMatrix(
    inputChannelCount: Int,
    outputChannelCount: Int,
    coefficients: FloatArray<Float>!
)
```

Creates a matrix with the given coefficients in row-major order.

| Parameters |
|---|---|
| `inputChannelCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Number of input channels (rows in the matrix). |
| `outputChannelCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Number of output channels (columns in the matrix). |
| `coefficients: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>!` | Non-negative matrix coefficients in row-major order. |

## Public functions

### createForConstantGain

```
java-static fun createForConstantGain(
    inputChannelCount: @IntRange(from = 1, to = 2) Int,
    outputChannelCount: @IntRange(from = 1, to = 2) Int
): ChannelMixingMatrix!
```

Returns a default constant gain channel mixing matrix that mixes `inputChannelCount` channels into `outputChannelCount` channels.

This method returns an identity matrix if `inputChannelCount` and ` outputChannelCount` are equal.

| Parameters |
|---|---|
| `inputChannelCount: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1, to = 2) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Number of input channels. |
| `outputChannelCount: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1, to = 2) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Number of output channels. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` | If no default coefficients are available for the given input and output channel counts. |

### createForConstantPower

```
java-static fun createForConstantPower(
    inputChannelCount: @IntRange(from = 1, to = 6) Int,
    outputChannelCount: @IntRange(from = 1, to = 2) Int
): ChannelMixingMatrix!
```

Returns a default constant power channel mixing matrix that mixes `inputChannelCount` channels into `outputChannelCount` channels.

This method returns an identity matrix if `inputChannelCount` and ` outputChannelCount` are equal.

Channel counts map to the following layouts:

1. \[MONO\]
2. \[FRONT_LEFT, FRONT_RIGHT\]
3. \[FRONT_LEFT, FRONT_RIGHT, FRONT_CENTER\]
4. \[FRONT_LEFT, FRONT_RIGHT, BACK_LEFT, BACK_RIGHT\]
5. \[FRONT_LEFT, FRONT_RIGHT, FRONT_CENTER, BACK_LEFT, BACK_RIGHT\]
6. \[FRONT_LEFT, FRONT_RIGHT, FRONT_CENTER, LOW_FREQUENCY, BACK_LEFT, BACK_RIGHT\]

| Parameters |
|---|---|
| `inputChannelCount: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1, to = 6) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Number of input channels. |
| `outputChannelCount: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1, to = 2) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Number of output channels. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` | If no default matrix coefficients are implemented for the given input and output channel counts. |

### getMixingCoefficient

```
fun getMixingCoefficient(inputChannel: Int, outputChannel: Int): Float
```

Gets the scaling factor for the given input and output channel.

### isSquare

```
fun isSquare(): Boolean
```

Returns whether the input and output channel count is the same.

### scaleBy

```
fun scaleBy(scale: Float): ChannelMixingMatrix!
```

Returns a new matrix with the given scaling factor applied to all coefficients.

## Public properties

### inputChannelCount

```
val inputChannelCount: Int
```

### isDiagonal

```
val isDiagonal: Boolean
```

### isIdentity

```
val isIdentity: Boolean
```

### isZero

```
val isZero: Boolean
```

### outputChannelCount

```
val outputChannelCount: Int
```