Interface AudioProcessor

  • All Known Implementing Classes:
    BaseAudioProcessor, GvrAudioProcessor, SilenceSkippingAudioProcessor, SonicAudioProcessor, TeeAudioProcessor

    public interface AudioProcessor
    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.

    • Method Detail

      • configure

        AudioProcessor.AudioFormat configure​(AudioProcessor.AudioFormat inputAudioFormat)
                                      throws AudioProcessor.UnhandledAudioFormatException
        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:
        inputAudioFormat - The format of audio that will be queued after the next call to flush().
        Returns:
        The configured output audio format if this instance is active.
        Throws:
        AudioProcessor.UnhandledAudioFormatException - Thrown if the specified format can't be handled as input.
      • isActive

        boolean isActive()
        Returns whether the processor is configured and will process input buffers.
      • queueInput

        void queueInput​(ByteBuffer buffer)
        Queues audio data between the position and limit of the input 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().
        Parameters:
        buffer - The input buffer to process.
      • queueEndOfStream

        void queueEndOfStream()
        Queues an end of stream signal. After this method has been called, 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.
      • getOutput

        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:
        A buffer containing processed output data between its position and limit.
      • isEnded

        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.
      • flush

        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.
      • reset

        void reset()
        Resets the processor to its unconfigured state, releasing any resources.