ChannelMixingMatrix


@UnstableApi
public final class ChannelMixingMatrix


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:
    [0.5 0.5]
  • Stereo to stereo with no mixing or scaling:
            [1 0
    0 1]
  • Stereo to stereo with 0.7 volume:
            [0.7 0
    0 0.7]

Summary

Public fields

final int
final boolean
final boolean
final boolean
final int

Public constructors

ChannelMixingMatrix(
    int inputChannelCount,
    int outputChannelCount,
    float[] coefficients
)

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

Public methods

static ChannelMixingMatrix
create(int inputChannelCount, int outputChannelCount)

Creates a standard channel mixing matrix that converts from inputChannelCount channels to outputChannelCount channels.

int
float
getMixingCoefficient(int inputChannel, int outputChannel)

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

int
boolean

Returns whether the matrix is square and all non-diagonal coefficients are zero.

boolean

Returns whether this is an identity matrix.

boolean

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

boolean

Returns whether all mixing coefficients are zero.

ChannelMixingMatrix
scaleBy(float scale)

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

Public fields

inputChannelCount

public final int inputChannelCount

isDiagonal

public final boolean isDiagonal

isIdentity

public final boolean isIdentity

isZero

public final boolean isZero

outputChannelCount

public final int outputChannelCount

Public constructors

ChannelMixingMatrix

public ChannelMixingMatrix(
    int inputChannelCount,
    int outputChannelCount,
    float[] coefficients
)

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

Parameters
int inputChannelCount

Number of input channels (rows in the matrix).

int outputChannelCount

Number of output channels (columns in the matrix).

float[] coefficients

Non-negative matrix coefficients in row-major order.

Public methods

create

public static ChannelMixingMatrix create(int inputChannelCount, int outputChannelCount)

Creates a standard channel mixing matrix that converts from inputChannelCount channels to outputChannelCount channels.

If the input and output channel counts match then a simple identity matrix will be returned. Otherwise, default matrix coefficients will be used to best match channel locations and overall power level.

Parameters
int inputChannelCount

Number of input channels.

int outputChannelCount

Number of output channels.

Returns
ChannelMixingMatrix

New channel mixing matrix.

Throws
java.lang.UnsupportedOperationException

If no default matrix coefficients are implemented for the given input and output channel counts.

getInputChannelCount

public int getInputChannelCount()

getMixingCoefficient

public float getMixingCoefficient(int inputChannel, int outputChannel)

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

getOutputChannelCount

public int getOutputChannelCount()

isDiagonal

public boolean isDiagonal()

Returns whether the matrix is square and all non-diagonal coefficients are zero.

isIdentity

public boolean isIdentity()

Returns whether this is an identity matrix.

isSquare

public boolean isSquare()

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

isZero

public boolean isZero()

Returns whether all mixing coefficients are zero.

scaleBy

public ChannelMixingMatrix scaleBy(float scale)

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