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.
Receives interleaved, signed 16-bit little-endian PCM frames.
Producers may reuse the input buffer after
accept(byte[], int) returns.-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(byte[] pcmSamples, int length) Acceptslengthvalid bytes from the start of the buffer.default voidclose()Releases output resources.default voidDiscards queued audio and flushes the host line, rather than waiting for playback.static AudioSinkopen(int sampleRate, int channels) Opens a Java Sound output with a bounded queue and a dedicated writer thread.
-
Field Details
-
NULL
Discards all audio, for headless execution or unavailable audio devices.
-
-
Method Details
-
open
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 secondchannels- number of interleaved channels- Returns:
- an open sink owned by the caller
- Throws:
IllegalArgumentException- if the format is invalid or unsupportedLineUnavailableException- if no audio device can be opened
-
accept
void accept(byte[] pcmSamples, int length) Acceptslengthvalid bytes from the start of the buffer. The bytes must contain complete PCM frames. Writes after close are discarded.- Parameters:
pcmSamples- PCM bufferlength- 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:
closein interfaceAutoCloseable
-