AudioProcessor


@UnstableApi
public interface AudioProcessor

Known direct subclasses
BaseAudioProcessor

Base class for audio processors that keep an output buffer and an internal buffer that is reused whenever input is queued.

SonicAudioProcessor

An AudioProcessor that uses the Sonic library to modify audio speed/pitch/sample rate.

Known indirect subclasses
BaseAudioProcessor

This class is deprecated.

Use androidx.media3.common.audio.BaseAudioProcessor.

ChannelMixingAudioProcessor

An AudioProcessor that handles mixing and scaling audio channels.

SilenceSkippingAudioProcessor

An AudioProcessor that skips silence in the input stream.

SonicAudioProcessor

This class is deprecated.

Use androidx.media3.common.audio.SonicAudioProcessor.

SpeedChangingAudioProcessor

An AudioProcessor that changes the speed of audio samples depending on their timestamp.

TeeAudioProcessor

Audio processor that outputs its input unmodified and also outputs its input to a given sink.

ToInt16PcmAudioProcessor

An AudioProcessor that converts different PCM audio encodings to 16-bit integer PCM.


Interface for audio processors, which take audio data as input and transform it, potentially modifying its channel count, encoding and/or sample rate.

In addition to being able to modify the format of audio, implementations may allow parameters to be set that affect the output audio and whether the processor is active/inactive.

Summary

Nested types

public final class AudioProcessor.AudioFormat

PCM audio format that may be handled by an audio processor.

Exception thrown when the given AudioFormat can not be handled.

Constants

default static final ByteBuffer

An empty, direct ByteBuffer.

Public methods

abstract AudioProcessor.AudioFormat

Configures the processor to process input audio with the specified format.

abstract void

Clears any buffered data and pending output.

default long

Returns the expected duration of the output stream when the processor is applied given a input durationUs.

abstract ByteBuffer

Returns a buffer containing processed output data between its position and limit.

abstract boolean

Returns whether the processor is configured and will process input buffers.

abstract boolean

Returns whether this processor will return no more output from getOutput until flush has been called and more input has been queued.

abstract void

Queues an end of stream signal.

abstract void
queueInput(ByteBuffer inputBuffer)

Queues audio data between the position and limit of the inputBuffer for processing.

abstract void

Resets the processor to its unconfigured state, releasing any resources.

Constants

EMPTY_BUFFER

default static final ByteBuffer EMPTY_BUFFER

An empty, direct ByteBuffer.

Public methods

configure

abstract AudioProcessor.AudioFormat configure(AudioProcessor.AudioFormat inputAudioFormat)

Configures the processor to process input audio with the specified format. After calling this method, call isActive to determine whether the audio processor is active. Returns the configured output audio format if this instance is active.

After calling this method, it is necessary to flush the processor to apply the new configuration. Before applying the new configuration, it is safe to queue input and get output in the old input/output formats. Call queueEndOfStream when no more input will be supplied in the old input format.

Parameters
AudioProcessor.AudioFormat inputAudioFormat

The format of audio that will be queued after the next call to flush.

Returns
AudioProcessor.AudioFormat

The configured output audio format if this instance is active.

Throws
androidx.media3.common.audio.AudioProcessor.UnhandledAudioFormatException

Thrown if the specified format can't be handled as input.

flush

abstract void flush()

Clears any buffered data and pending output. If the audio processor is active, also prepares the audio processor to receive a new stream of input in the last configured (pending) format.

getDurationAfterProcessorApplied

default long getDurationAfterProcessorApplied(long durationUs)

Returns the expected duration of the output stream when the processor is applied given a input durationUs.

getOutput

abstract ByteBuffer getOutput()

Returns a buffer containing processed output data between its position and limit. The buffer will always be a direct byte buffer with native byte order. Calling this method invalidates any previously returned buffer. The buffer will be empty if no output is available.

Returns
ByteBuffer

A buffer containing processed output data between its position and limit.

isActive

abstract boolean isActive()

Returns whether the processor is configured and will process input buffers.

isEnded

abstract boolean isEnded()

Returns whether this processor will return no more output from getOutput until flush has been called and more input has been queued.

queueEndOfStream

abstract void queueEndOfStream()

Queues an end of stream signal. After this method has been called, queueInput may not be called until after the next call to flush. Calling getOutput will return any remaining output data. Multiple calls may be required to read all of the remaining output data. isEnded will return true once all remaining output data has been read.

queueInput

abstract void queueInput(ByteBuffer inputBuffer)

Queues audio data between the position and limit of the inputBuffer for processing. After calling this method, processed output may be available via getOutput. Calling queueInput(ByteBuffer) again invalidates any pending output.

Parameters
ByteBuffer inputBuffer

The input buffer to process. It must be a direct byte buffer with native byte order. Its contents are treated as read-only. Its position will be advanced by the number of bytes consumed (which may be zero). The caller retains ownership of the provided buffer.

reset

abstract void reset()

Resets the processor to its unconfigured state, releasing any resources.