Class AudioProcessingPipeline

    • Constructor Detail

      • AudioProcessingPipeline

        public AudioProcessingPipeline​(ImmutableList<AudioProcessor> audioProcessors)
        Creates an instance.
        audioProcessors - The AudioProcessor instances to be used for processing buffers.
    • Method Detail

      • configure

        public AudioProcessor.AudioFormat configure​(AudioProcessor.AudioFormat inputAudioFormat)
                                             throws AudioProcessor.UnhandledAudioFormatException
        Configures the pipeline to process input audio with the specified format. Returns the configured output audio format.

        To apply the new configuration for use, the pipeline must be flushed. Before applying the new configuration, it is safe to queue input and get output in the old input/output formats/configuration. Call queueEndOfStream() when no more input will be supplied for processing in the old configuration.

        inputAudioFormat - The format of audio that will be queued after the next call to flush().
        The configured output audio format.
        AudioProcessor.UnhandledAudioFormatException - If the specified format is not supported by the pipeline.
      • flush

        public void flush()
        Clears any buffered data and pending output. If any underlying audio processors are active, this also prepares them to receive a new stream of input in the last configured (pending) format.

        configure(AudioFormat) must have been called at least once since the last call to reset() before calling this.

      • isOperational

        public boolean isOperational()
        Whether the pipeline can be used for processing buffers.

        For this to happen the pipeline must be configured, flushed and have active underlying audio processors that are ready to process buffers with the current configuration.

      • queueInput

        public 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().
        inputBuffer - The input buffer to process. It must be a direct ByteBuffer 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.
      • getOutput

        public ByteBuffer getOutput()
        Returns a ByteBuffer containing processed output data between its position and limit. The buffer will be empty if no output is available.

        Buffers returned from this method are retained by pipeline, and it is necessary to consume the data (or copy it into another buffer) to allow the pipeline to progress.

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

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

        public boolean isEnded()
        Returns whether the pipeline has ended.

        The pipeline is considered ended when:

      • reset

        public void reset()
        Resets the pipeline and its underlying AudioProcessor instances to their unconfigured state, releasing any resources.
      • equals

        public boolean equals​(@Nullable
                              Object o)
        Indicates whether some other object is "equal to" this one.

        Two instances of AudioProcessingPipeline are considered equal if they have the same underlying AudioProcessor references in the same order.

        equals in class Object
      • hashCode

        public int hashCode()
        hashCode in class Object