Interface AudioSink

All Superinterfaces:
AutoCloseable
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface AudioSink extends AutoCloseable
Receives interleaved, signed 16-bit little-endian PCM frames. Producers may reuse the input buffer after accept(byte[], int) returns.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final AudioSink
    Discards all audio, for headless execution or unavailable audio devices.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    accept(byte[] pcmSamples, int length)
    Accepts length valid bytes from the start of the buffer.
    default void
    Releases output resources.
    default void
    Discards queued audio and flushes the host line, rather than waiting for playback.
    static AudioSink
    open(int sampleRate, int channels)
    Opens a Java Sound output with a bounded queue and a dedicated writer thread.
  • Field Details

    • NULL

      static final AudioSink NULL
      Discards all audio, for headless execution or unavailable audio devices.
  • Method Details

    • open

      static AudioSink open(int sampleRate, int channels) throws LineUnavailableException
      Opens a Java Sound output with a bounded queue and a dedicated writer thread. Playback does not block the producer; a full queue drops the newest batch.
      Parameters:
      sampleRate - frames per second
      channels - number of interleaved channels
      Returns:
      an open sink owned by the caller
      Throws:
      IllegalArgumentException - if the format is invalid or unsupported
      LineUnavailableException - if no audio device can be opened
    • accept

      void accept(byte[] pcmSamples, int length)
      Accepts length valid bytes from the start of the buffer. The bytes must contain complete PCM frames. Writes after close are discarded.
      Parameters:
      pcmSamples - PCM buffer
      length - number of valid bytes
    • flushAudio

      default void flushAudio()
      Discards queued audio and flushes the host line, rather than waiting for playback.
    • close

      default void close()
      Releases output resources. Closing an output repeatedly is safe.
      Specified by:
      close in interface AutoCloseable