{"record":{"id":"c252ae9d07b843e5","repo":"DrKLO/Telegram","slug":"unhandled-format-inputaudioformat-c252ae","errorCode":null,"errorMessage":"Unhandled format: {inputAudioFormat}","messagePattern":"Unhandled format: (.+?)","errorType":"exception","errorClass":"UnhandledAudioFormatException","httpStatus":null,"severity":"warning","filePath":"TMessagesProj/src/main/java/com/google/android/exoplayer2/audio/SonicAudioProcessor.java","lineNumber":147,"sourceCode":"  public long getMediaDuration(long playoutDuration) {\n    if (outputBytes >= MIN_BYTES_FOR_DURATION_SCALING_CALCULATION) {\n      long processedInputBytes = inputBytes - checkNotNull(sonic).getPendingInputBytes();\n      return outputAudioFormat.sampleRate == inputAudioFormat.sampleRate\n          ? Util.scaleLargeTimestamp(playoutDuration, processedInputBytes, outputBytes)\n          : Util.scaleLargeTimestamp(\n              playoutDuration,\n              processedInputBytes * outputAudioFormat.sampleRate,\n              outputBytes * inputAudioFormat.sampleRate);\n    } else {\n      return (long) ((double) speed * playoutDuration);\n    }\n  }\n\n  @Override\n  @CanIgnoreReturnValue\n  public AudioFormat configure(AudioFormat inputAudioFormat) throws UnhandledAudioFormatException {\n    if (inputAudioFormat.encoding != C.ENCODING_PCM_16BIT) {\n      throw new UnhandledAudioFormatException(inputAudioFormat);\n    }\n    int outputSampleRateHz =\n        pendingOutputSampleRate == SAMPLE_RATE_NO_CHANGE\n            ? inputAudioFormat.sampleRate\n            : pendingOutputSampleRate;\n    pendingInputAudioFormat = inputAudioFormat;\n    pendingOutputAudioFormat =\n        new AudioFormat(outputSampleRateHz, inputAudioFormat.channelCount, C.ENCODING_PCM_16BIT);\n    pendingSonicRecreation = true;\n    return pendingOutputAudioFormat;\n  }\n\n  @Override\n  public boolean isActive() {\n    return pendingOutputAudioFormat.sampleRate != Format.NO_VALUE\n        && (Math.abs(speed - 1f) >= CLOSE_THRESHOLD\n            || Math.abs(pitch - 1f) >= CLOSE_THRESHOLD\n            || pendingOutputAudioFormat.sampleRate != pendingInputAudioFormat.sampleRate);","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/src/main/java/com/google/android/exoplayer2/audio/SonicAudioProcessor.java#L129-L165","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nsonicProcessor.setOutputSampleRate(48000);\nsonicProcessor.setSpeed(1.5f); // 24-bit source -> configure throws\n// after: resample to 16-bit first, then Sonic\nAudioProcessor[] chain = { resamplingTo16BitProcessor, sonicProcessor };\nsink = new DefaultAudioSink(..., new DefaultAudioSink.DefaultAudioProcessorChain(chain));","handlingStrategy":"validation","validationCode":"if (inputAudioFormat.encoding == C.ENCODING_PCM_16BIT) {\n  sonicProcessor.setOutputSampleRate(48000);\n  sonicProcessor.setSpeed(1.5f);\n} else {\n  // resample to 16-bit upstream, or leave Sonic inactive\n}","typeGuard":null,"tryCatchPattern":"try {\n  sonicProcessor.configure(inputAudioFormat);\n} catch (UnhandledAudioFormatException e) {\n  sonicProcessor.setSpeed(1.0f); // disable, or resample input to 16-bit first\n}","preventionTips":["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."],"tags":["exoplayer","audio","pcm","sonic","speed","encoding"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}