AudioProcessor
@UnstableApi
public interface AudioProcessor
BaseAudioProcessor |
Base class for audio processors that keep an output buffer and an internal buffer that is reused whenever input is queued. |
SonicAudioProcessor |
An |
SpeedChangingAudioProcessor |
An |
ChannelMappingAudioProcessor |
An |
ChannelMixingAudioProcessor |
An |
GainProcessor |
Applies |
PassthroughAudioProcessor |
A |
SilenceSkippingAudioProcessor |
An |
TeeAudioProcessor |
Audio processor that outputs its input unmodified and also outputs its input to a given sink. |
ToFloatPcmAudioProcessor |
An |
ToInt16PcmAudioProcessor |
An |
TrimmingAudioProcessor |
Audio processor for trimming samples from the start/end of data. |
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.AudioFormatPCM audio format that may be handled by an audio processor. |
public final class AudioProcessor.StreamMetadataRecord class that holds information about the underlying stream being processed by an |
public final class AudioProcessor.UnhandledAudioFormatException extends ExceptionException thrown when the given |
Constants |
|
|---|---|
default static final ByteBuffer |
An empty, direct |
Public methods |
|
|---|---|
abstract AudioProcessor.AudioFormat |
configure(AudioProcessor.AudioFormat inputAudioFormat)Configures the processor to process input audio with the specified format. |
default void |
This method is deprecated. Use |
default void |
flush(AudioProcessor.StreamMetadata streamMetadata)Prepares the audio processor to receive a new stream of input in the last |
default long |
getDurationAfterProcessorApplied(long durationUs)Returns the expected duration of the output stream when the processor is applied given a input |
abstract ByteBuffer |
Returns a buffer containing processed output data between its position and limit. |
abstract boolean |
isActive()Returns whether the processor is configured and will process input buffers. |
abstract boolean |
isEnded()Returns whether this processor will return no more output from |
abstract void |
Queues an end of stream signal. |
abstract void |
queueInput(ByteBuffer inputBuffer)Queues audio data between the position and limit of the |
abstract void |
reset()Resets the processor to its unconfigured state, releasing any resources. |
Constants
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 |
| Returns | |
|---|---|
AudioProcessor.AudioFormat |
The configured output audio format if this instance is |
| Throws | |
|---|---|
androidx.media3.common.audio.AudioProcessor.UnhandledAudioFormatException |
Thrown if the specified format can't be handled as input. |
flush
default 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.
This is equivalent to flush(new StreamMetadata(C.TIME_UNSET)).
flush
default void flush(AudioProcessor.StreamMetadata streamMetadata)
Prepares the audio processor to receive a new stream of input in the last configured format and clears any buffered data and pending output.
This method is a no-op if the processor is not active.
getDurationAfterProcessorApplied
default long getDurationAfterProcessorApplied(long durationUs)
Returns the expected duration of the output stream when the processor is applied given a input durationUs.
This method assumes durationUs of input is applied from the beginning of the stream (i.e. after a flush(StreamMetadata.DEFAULT) call).
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.