google/ExoPlayer · error · IllegalArgumentException
Coefficient at index {i} is negative.
Error message
Coefficient at index {i} is negative. What it means
ChannelMixingMatrix validates user-supplied coefficient arrays with checkCoefficientsValid and throws IllegalArgumentException for any negative value — every coefficient must be >= 0f. The restriction exists because the mixing implementation assumes non-negative gains (it cannot express phase inversion); negative gains such as the -0.707 used in some surround-downmix recipes are rejected.
Source
Thrown at library/common/src/main/java/com/google/android/exoplayer2/audio/ChannelMixingMatrix.java:192
"Default channel mixing coefficients for "
+ inputChannelCount
+ "->"
+ outputChannelCount
+ " are not yet implemented.");
}
private static float[] initializeIdentityMatrix(int channelCount) {
float[] coefficients = new float[channelCount * channelCount];
for (int c = 0; c < channelCount; c++) {
coefficients[channelCount * c + c] = 1f;
}
return coefficients;
}
private static float[] checkCoefficientsValid(float[] coefficients) {
for (int i = 0; i < coefficients.length; i++) {
if (coefficients[i] < 0f) {
throw new IllegalArgumentException("Coefficient at index " + i + " is negative.");
}
}
return coefficients;
}
}
View on GitHub (pinned to dd430f7053)
Solutions
- Clamp or zero out negative coefficients: use Math.abs(coef) only if phase truly does not matter for your use, otherwise set surround contributions to 0f or +gain.
- Do phase inversion in a different processor that supports it (e.g. a custom AudioProcessor), keeping the ChannelMixingMatrix coefficients non-negative.
- Validate the array yourself before construction to fail with a clearer message.
Example fix
// before
float[] bs775 = {1,0, 0,1, .707f,.707f, 0,0, -.707f,0, 0,-.707f};
ChannelMixingMatrix.create(6, 2, bs775); // throws IllegalArgumentException at index 8
// after
float[] nonNeg = new float[bs775.length];
for (int i = 0; i < bs775.length; i++) nonNeg[i] = Math.max(0f, bs775[i]);
ChannelMixingMatrix.create(6, 2, nonNeg); Defensive patterns
Strategy: validation
Validate before calling
private static float[] requireNonNegative(float[] coefficients) {
for (int i = 0; i < coefficients.length; i++) {
if (coefficients[i] < 0f) {
throw new IllegalArgumentException("Coefficient[" + i + "]=" + coefficients[i] + " must be >= 0");
}
}
return coefficients;
}
float[] safe = requireNonNegative(coeffs);
ChannelMixingMatrix.create(in, out, safe); Prevention
- ChannelMixingMatrix cannot express phase inversion — clamp or drop negative gains before construction.
- Sanitize ported coefficient tables from other DSP libraries (BS.775 uses -0.7071 for surrounds).
- Validate array length (in*out) and finiteness (no NaN/Inf) alongside non-negativity.
When it happens
Trigger: Passing a float[] containing any value < 0f to the ChannelMixingMatrix constructor (create(input, output, coefficients)) — most commonly a copy of ITU-R BS.775 downmix coefficients that use -0.7071 for surround channels.
Common situations: Porting a downmix matrix from another DSP library that permits negative (phase-inverting) gains; typo'd or wrap-around index math producing spurious negative floats.
Related errors
- Unhandled input format: {audioFormat}
- No mixing matrix for input channel count {audioFormat}
- Default channel mixing coefficients for {inputChannelCount}-
- Unhandled input format: ${audioFormat}
- Unhandled input format: {audioFormat}
AI-assisted analysis of google/ExoPlayer@dd430f7053 (2026-08-14).
Data as JSON: /api/errors/8be513e17a97dfb4.
Report an issue: GitHub.