DrKLO/Telegram · warning · UnhandledAudioFormatException
Unhandled format: {inputAudioFormat}
Error message
Unhandled format: {inputAudioFormat} What it means
SonicAudioProcessor.configure throws UnhandledAudioFormatException when the input encoding is not C.ENCODING_PCM_16BIT. Sonic (used for speed/pitch/time-stretch and sample-rate conversion via the Sonic library) operates internally on 16-bit PCM samples; non-16-bit encodings cannot be processed directly and are rejected at configuration so the pipeline can convert or bypass.
Source
Thrown at TMessagesProj/src/main/java/com/google/android/exoplayer2/audio/SonicAudioProcessor.java:147
public long getMediaDuration(long playoutDuration) {
if (outputBytes >= MIN_BYTES_FOR_DURATION_SCALING_CALCULATION) {
long processedInputBytes = inputBytes - checkNotNull(sonic).getPendingInputBytes();
return outputAudioFormat.sampleRate == inputAudioFormat.sampleRate
? Util.scaleLargeTimestamp(playoutDuration, processedInputBytes, outputBytes)
: Util.scaleLargeTimestamp(
playoutDuration,
processedInputBytes * outputAudioFormat.sampleRate,
outputBytes * inputAudioFormat.sampleRate);
} else {
return (long) ((double) speed * playoutDuration);
}
}
@Override
@CanIgnoreReturnValue
public AudioFormat configure(AudioFormat inputAudioFormat) throws UnhandledAudioFormatException {
if (inputAudioFormat.encoding != C.ENCODING_PCM_16BIT) {
throw new UnhandledAudioFormatException(inputAudioFormat);
}
int outputSampleRateHz =
pendingOutputSampleRate == SAMPLE_RATE_NO_CHANGE
? inputAudioFormat.sampleRate
: pendingOutputSampleRate;
pendingInputAudioFormat = inputAudioFormat;
pendingOutputAudioFormat =
new AudioFormat(outputSampleRateHz, inputAudioFormat.channelCount, C.ENCODING_PCM_16BIT);
pendingSonicRecreation = true;
return pendingOutputAudioFormat;
}
@Override
public boolean isActive() {
return pendingOutputAudioFormat.sampleRate != Format.NO_VALUE
&& (Math.abs(speed - 1f) >= CLOSE_THRESHOLD
|| Math.abs(pitch - 1f) >= CLOSE_THRESHOLD
|| pendingOutputAudioFormat.sampleRate != pendingInputAudioFormat.sampleRate);View on GitHub (pinned to 45ab8f4308)
Solutions
- Place a ResamplingAudioProcessor (or FloatResamplingAudioProcessor then a down-converter) upstream so input to Sonic is 16-bit PCM.
- Only activate Sonic (set pending output sample rate / speed) when the source is 16-bit PCM; otherwise bypass by leaving speed at 1.0 and sample rate at SAMPLE_RATE_NO_CHANGE.
- Configure DefaultAudioSink with an audio processor chain order that converts to 16-bit before Sonic.
Example fix
// before
sonicProcessor.setOutputSampleRate(48000);
sonicProcessor.setSpeed(1.5f); // 24-bit source -> configure throws
// after: resample to 16-bit first, then Sonic
AudioProcessor[] chain = { resamplingTo16BitProcessor, sonicProcessor };
sink = new DefaultAudioSink(..., new DefaultAudioSink.DefaultAudioProcessorChain(chain)); Defensive patterns
Strategy: validation
Validate before calling
if (inputAudioFormat.encoding == C.ENCODING_PCM_16BIT) {
sonicProcessor.setOutputSampleRate(48000);
sonicProcessor.setSpeed(1.5f);
} else {
// resample to 16-bit upstream, or leave Sonic inactive
} Try / catch
try {
sonicProcessor.configure(inputAudioFormat);
} catch (UnhandledAudioFormatException e) {
sonicProcessor.setSpeed(1.0f); // disable, or resample input to 16-bit first
} Prevention
- Order the processor chain so input to Sonic is 16-bit PCM (resampler before Sonic).
- Only activate speed/pitch/sample-rate overrides when the source is 16-bit.
- Re-assert the chain order whenever the source encoding changes.
When it happens
Trigger: Setting playback speed/pitch or an output sample rate on SonicAudioProcessor while the input is non-16-bit PCM (24-bit, 32-bit, float, compressed); a hi-res source routed through the default speed-adjustment chain; toggling playback speed on a float-PCM decoder output.
Common situations: Variable-speed playback enabled app-wide; hi-res FLAC or float-decoded audio reaching the Sonic processor; a custom audio sink that always includes Sonic for speed control regardless of encoding.
Related errors
- Unhandled format: {inputAudioFormat}
- Unhandled format: {inputAudioFormat}
- Unhandled format: {inputAudioFormat}
- Unhandled format: {inputAudioFormat}
- Invalid output encoding (mode={outputMode}) for: {inputForma
AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14).
Data as JSON: /api/errors/c252ae9d07b843e5.
Report an issue: GitHub.