public interface AudioProcessor
Call configure(int, int, int) to configure the processor to receive input audio, then
call isActive() to determine whether the processor is active. queueInput(ByteBuffer), queueEndOfStream(), getOutput(), isEnded(),
getOutputChannelCount(), getOutputEncoding() and getOutputSampleRateHz() may only be called if the processor is active. Call reset() to
reset the processor to its unconfigured state and release any resources.
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.
| Modifier and Type | Interface and Description |
|---|---|
static class |
AudioProcessor.UnhandledFormatException
Exception thrown when a processor can't be configured for a given input audio format.
|
| Modifier and Type | Field and Description |
|---|---|
static java.nio.ByteBuffer |
EMPTY_BUFFER
An empty, direct
ByteBuffer. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
configure(int sampleRateHz,
int channelCount,
int encoding)
Configures the processor to process input audio with the specified format and returns whether
to
flush() it. |
void |
flush()
Clears any state in preparation for receiving a new stream of input buffers.
|
java.nio.ByteBuffer |
getOutput()
Returns a buffer containing processed output data between its position and limit.
|
int |
getOutputChannelCount()
Returns the number of audio channels in the data output by the processor.
|
int |
getOutputEncoding()
Returns the audio encoding used in the data output by the processor.
|
int |
getOutputSampleRateHz()
Returns the sample rate of audio output by the processor, in hertz.
|
boolean |
isActive()
Returns whether the processor is configured and will process input buffers.
|
boolean |
isEnded()
Returns whether this processor will return no more output from
getOutput() until it
has been flush()ed and more input has been queued. |
void |
queueEndOfStream()
Queues an end of stream signal.
|
void |
queueInput(java.nio.ByteBuffer buffer)
Queues audio data between the position and limit of the input
buffer for processing. |
void |
reset()
Resets the processor to its unconfigured state.
|
static final java.nio.ByteBuffer EMPTY_BUFFER
ByteBuffer.boolean configure(int sampleRateHz,
int channelCount,
@C.Encoding
int encoding)
throws AudioProcessor.UnhandledFormatException
flush() it. After calling this method, if the processor is active, getOutputSampleRateHz(), getOutputChannelCount() and getOutputEncoding()
return its output format.sampleRateHz - The sample rate of input audio in Hz.channelCount - The number of interleaved channels in input audio.encoding - The encoding of input audio.flush() the processor.AudioProcessor.UnhandledFormatException - Thrown if the specified format can't be handled as input.boolean isActive()
int getOutputChannelCount()
configure(int, int, int) and is undefined if the instance is
not active.@C.Encoding int getOutputEncoding()
configure(int, int, int) and is undefined if the instance is not
active.int getOutputSampleRateHz()
configure(int, int, int) and is undefined if the instance is not
active.void queueInput(java.nio.ByteBuffer buffer)
buffer for processing.
buffer 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. Calling this method invalidates any
previous buffer returned by getOutput().buffer - The input buffer to process.void queueEndOfStream()
queueInput(ByteBuffer) 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.java.nio.ByteBuffer getOutput()
boolean isEnded()
getOutput() until it
has been flush()ed and more input has been queued.void flush()
void reset()