public final class TeeAudioProcessor extends java.lang.Object implements AudioProcessor
This audio processor can be inserted into the audio processor chain to access audio data
before/after particular processing steps have been applied. For example, to get audio output
after playback speed adjustment and silence skipping have been applied it is necessary to pass a
custom DefaultAudioSink.AudioProcessorChain when
creating the audio sink, and include this audio processor after all other audio processors.
| Modifier and Type | Class and Description |
|---|---|
static interface |
TeeAudioProcessor.AudioBufferSink
A sink for audio buffers handled by the audio processor.
|
static class |
TeeAudioProcessor.WavFileAudioBufferSink
A sink for audio buffers that writes output audio as .wav files with a given path prefix.
|
AudioProcessor.UnhandledFormatExceptionEMPTY_BUFFER| Constructor and Description |
|---|
TeeAudioProcessor(TeeAudioProcessor.AudioBufferSink audioBufferSink)
Creates a new tee audio processor, sending incoming data to the given
TeeAudioProcessor.AudioBufferSink. |
| 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
AudioProcessor.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
AudioProcessor.getOutput() until it
has been AudioProcessor.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.
|
public TeeAudioProcessor(TeeAudioProcessor.AudioBufferSink audioBufferSink)
TeeAudioProcessor.AudioBufferSink.audioBufferSink - The audio buffer sink that will receive input queued to this audio
processor.public boolean configure(int sampleRateHz,
int channelCount,
@C.Encoding
int encoding)
throws AudioProcessor.UnhandledFormatException
AudioProcessorAudioProcessor.flush() it. After calling this method, if the processor is active, AudioProcessor.getOutputSampleRateHz(), AudioProcessor.getOutputChannelCount() and AudioProcessor.getOutputEncoding()
return its output format.configure in interface AudioProcessorsampleRateHz - The sample rate of input audio in Hz.channelCount - The number of interleaved channels in input audio.encoding - The encoding of input audio.AudioProcessor.flush() the processor.AudioProcessor.UnhandledFormatException - Thrown if the specified format can't be handled as input.public boolean isActive()
AudioProcessorisActive in interface AudioProcessorpublic int getOutputChannelCount()
AudioProcessorAudioProcessor.configure(int, int, int) and is undefined if the instance is
not active.getOutputChannelCount in interface AudioProcessorpublic int getOutputEncoding()
AudioProcessorAudioProcessor.configure(int, int, int) and is undefined if the instance is not
active.getOutputEncoding in interface AudioProcessorpublic int getOutputSampleRateHz()
AudioProcessorAudioProcessor.configure(int, int, int) and is undefined if the instance is not
active.getOutputSampleRateHz in interface AudioProcessorpublic void queueInput(java.nio.ByteBuffer buffer)
AudioProcessorbuffer 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 AudioProcessor.getOutput().queueInput in interface AudioProcessorbuffer - The input buffer to process.public void queueEndOfStream()
AudioProcessorAudioProcessor.queueInput(ByteBuffer) may not be called until after the next call to
AudioProcessor.flush(). Calling AudioProcessor.getOutput() will return any remaining output data. Multiple
calls may be required to read all of the remaining output data. AudioProcessor.isEnded() will return
true once all remaining output data has been read.queueEndOfStream in interface AudioProcessorpublic java.nio.ByteBuffer getOutput()
AudioProcessorgetOutput in interface AudioProcessorpublic boolean isEnded()
AudioProcessorAudioProcessor.getOutput() until it
has been AudioProcessor.flush()ed and more input has been queued.isEnded in interface AudioProcessorpublic void flush()
AudioProcessorflush in interface AudioProcessorpublic void reset()
AudioProcessorreset in interface AudioProcessor