Top Description Fields Constructors Methods
jogamp.opengl.util.av

public Class JavaSoundAudioSink

extends Object
implements AudioSink
Class Inheritance
All Implemented Interfaces
com.jogamp.opengl.util.av.AudioSink
Imports
java.nio.ByteBuffer, java.util.Arrays, javax.sound.sampled.AudioSystem, .DataLine, .SourceDataLine, com.jogamp.opengl.util.av.AudioSink

JavaSound Audio Sink

FIXME: Parameterize .. all configs .. best via an init-method, passing requested audio capabilities

Field Summary

Modifier and TypeField and Description
private SourceDataLine
public static final int
private int
private AudioSink.AudioFormat
private AudioFormat
private DataLine.Info
private boolean
private volatile boolean
private final byte[]
public static final int
private static final boolean
private float

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
destroy()

Implements com.jogamp.opengl.util.av.AudioSink.destroy.

Destroys this instance, i.e. closes all streams and devices allocated.
public AudioSink.AudioFrame
enqueueData(final int pts, final ByteBuffer byteBuffer, final int byteCount)

Implements com.jogamp.opengl.util.av.AudioSink.enqueueData.

Enqueue byteCount bytes of the remaining bytes of the given NIO ByteBuffer to this sink.
public void
flush()

Implements com.jogamp.opengl.util.av.AudioSink.flush.

Flush all queued buffers, implies pause().
public final AudioSink.AudioFormat
getChosenFormat()

Implements com.jogamp.opengl.util.av.AudioSink.getChosenFormat.

Returns the AudioFormat as chosen by init(AudioFormat, float, int, int, int), i.e. it shall match the requestedFormat.
public final int
public int
getFrameCount()

Implements com.jogamp.opengl.util.av.AudioSink.getFrameCount.

Returns the number of allocated buffers as requested by init(AudioFormat, float, int, int, int).
public int
getFreeFrameCount()

Implements com.jogamp.opengl.util.av.AudioSink.getFreeFrameCount.

Returns the current number of frames in the sink available for writing.
public final int
getMaxSupportedChannels()

Implements com.jogamp.opengl.util.av.AudioSink.getMaxSupportedChannels.

Return the maximum number of supported channels.
public final float
getPlaySpeed()

Implements com.jogamp.opengl.util.av.AudioSink.getPlaySpeed.

Returns the playback speed.
public AudioSink.AudioFormat
public final int
getPTS()

Implements com.jogamp.opengl.util.av.AudioSink.getPTS.

Return the current audio presentation timestamp (PTS) in milliseconds.
public int
getQueuedByteCount()

Implements com.jogamp.opengl.util.av.AudioSink.getQueuedByteCount.

Returns the current number of bytes queued for playing.
public int
getQueuedFrameCount()

Implements com.jogamp.opengl.util.av.AudioSink.getQueuedFrameCount.

Returns the current number of frames queued for playing.
public int
getQueuedTime()

Implements com.jogamp.opengl.util.av.AudioSink.getQueuedTime.

Returns the current queued frame time in milliseconds for playing.
private final int
getQueuedTimeImpl(final int byteCount)

public final float
public boolean
init(final AudioSink.AudioFormat
the requested AudioFormat.
requestedFormat
,
final float
average or fixed frame duration in milliseconds helping a caching AudioFrame based implementation to determine the frame count in the queue. See DefaultFrameDuration.
frameDuration
,
final int
initial time in milliseconds to queue in this sink, see DefaultInitialQueueSize.
initialQueueSize
,
final int
time in milliseconds to grow queue if full, see DefaultQueueGrowAmount.
queueGrowAmount
,
final int
maximum time in milliseconds the queue can hold (and grow), see DefaultQueueLimitWithVideo and DefaultQueueLimitAudioOnly.
queueLimit
)

Implements com.jogamp.opengl.util.av.AudioSink.init.

Initializes the sink.
public boolean
isInitialized()

Implements com.jogamp.opengl.util.av.AudioSink.isInitialized.

Returns the initialized state of this instance.
public boolean
isPlaying()

Implements com.jogamp.opengl.util.av.AudioSink.isPlaying.

Returns true, if play() has been requested and the sink is still playing, otherwise false.
public final boolean
isSupported(final AudioSink.AudioFormat format)

Implements com.jogamp.opengl.util.av.AudioSink.isSupported.

Returns true if the given format is supported by the sink, otherwise false.
public void
pause()

Implements com.jogamp.opengl.util.av.AudioSink.pause.

Pause playing buffers while keeping enqueued data incl.
public void
play()

Implements com.jogamp.opengl.util.av.AudioSink.play.

Play buffers queued via enqueueData(AudioFrame) from current internal position.
private void
public final boolean
setPlaySpeed(final float rate)

Implements com.jogamp.opengl.util.av.AudioSink.setPlaySpeed.

Sets the playback speed.
public final boolean
setVolume(final float v)

Implements com.jogamp.opengl.util.av.AudioSink.setVolume.

Sets the volume [0f..1f].
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

aulineback to summary
private SourceDataLine auline
BUFFER_SIZEback to summary
public static final int BUFFER_SIZE
bufferCountback to summary
private int bufferCount
chosenFormatback to summary
private AudioSink.AudioFormat chosenFormat
formatback to summary
private AudioFormat format
infoback to summary
private DataLine.Info info
initializedback to summary
private boolean initialized
playRequestedback to summary
private volatile boolean playRequested
sampleDataback to summary
private final byte[] sampleData
SAMPLES_PER_BUFFERback to summary
public static final int SAMPLES_PER_BUFFER
staticAvailableback to summary
private static final boolean staticAvailable
volumeback to summary
private float volume

Constructor Detail

JavaSoundAudioSinkback to summary
public JavaSoundAudioSink()

Method Detail

destroyback to summary
public void destroy()

Implements com.jogamp.opengl.util.av.AudioSink.destroy.

Doc from com.jogamp.opengl.util.av.AudioSink.destroy.

Destroys this instance, i.e. closes all streams and devices allocated.

Annotations
@Override
enqueueDataback to summary
public AudioSink.AudioFrame enqueueData(final int pts, final ByteBuffer byteBuffer, final int byteCount)

Implements com.jogamp.opengl.util.av.AudioSink.enqueueData.

Doc from com.jogamp.opengl.util.av.AudioSink.enqueueData.

Enqueue byteCount bytes of the remaining bytes of the given NIO ByteBuffer to this sink.

The data must comply with the chosen AudioFormat as returned by initSink(AudioFormat).

init(AudioFormat, float, int, int, int) must be called first.

Returns:AudioSink.AudioFrame

the enqueued internal AudioFrame.

Annotations
@Override
flushback to summary
public void flush()

Implements com.jogamp.opengl.util.av.AudioSink.flush.

Doc from com.jogamp.opengl.util.av.AudioSink.flush.

Flush all queued buffers, implies pause().

init(AudioFormat, float, int, int, int) must be called first.

Annotations
@Override
getChosenFormatback to summary
public final AudioSink.AudioFormat getChosenFormat()

Implements com.jogamp.opengl.util.av.AudioSink.getChosenFormat.

Doc from com.jogamp.opengl.util.av.AudioSink.getChosenFormat.

Returns the AudioFormat as chosen by init(AudioFormat, float, int, int, int), i.e. it shall match the requestedFormat.

Annotations
@Override
getEnqueuedFrameCountback to summary
public final int getEnqueuedFrameCount()

Implements com.jogamp.opengl.util.av.AudioSink.getEnqueuedFrameCount.

Returns:int

Doc from com.jogamp.opengl.util.av.AudioSink.getEnqueuedFrameCount.

the current enqueued frames count since init(AudioFormat, float, int, int, int).

Annotations
@Override
getFrameCountback to summary
public int getFrameCount()

Implements com.jogamp.opengl.util.av.AudioSink.getFrameCount.

Doc from com.jogamp.opengl.util.av.AudioSink.getFrameCount.

Returns the number of allocated buffers as requested by init(AudioFormat, float, int, int, int).

Annotations
@Override
getFreeFrameCountback to summary
public int getFreeFrameCount()

Implements com.jogamp.opengl.util.av.AudioSink.getFreeFrameCount.

Doc from com.jogamp.opengl.util.av.AudioSink.getFreeFrameCount.

Returns the current number of frames in the sink available for writing.

init(AudioFormat, float, int, int, int) must be called first.

Annotations
@Override
getMaxSupportedChannelsback to summary
public final int getMaxSupportedChannels()

Implements com.jogamp.opengl.util.av.AudioSink.getMaxSupportedChannels.

Doc from com.jogamp.opengl.util.av.AudioSink.getMaxSupportedChannels.

Return the maximum number of supported channels.

Annotations
@Override
getPlaySpeedback to summary
public final float getPlaySpeed()

Implements com.jogamp.opengl.util.av.AudioSink.getPlaySpeed.

Doc from com.jogamp.opengl.util.av.AudioSink.getPlaySpeed.

Returns the playback speed.

Annotations
@Override
getPreferredFormatback to summary
public AudioSink.AudioFormat getPreferredFormat()

Implements com.jogamp.opengl.util.av.AudioSink.getPreferredFormat.

Doc from com.jogamp.opengl.util.av.AudioSink.getPreferredFormat.

Returns the preferred AudioFormat by this sink.

The preferred format is guaranteed to be supported and shall reflect this sinks most native format, i.e. best performance w/o data conversion.

Known AudioFormat attributes considered by implementations:

Annotations
@Override
getPTSback to summary
public final int getPTS()

Implements com.jogamp.opengl.util.av.AudioSink.getPTS.

Doc from com.jogamp.opengl.util.av.AudioSink.getPTS.

Return the current audio presentation timestamp (PTS) in milliseconds.

Annotations
@Override
getQueuedByteCountback to summary
public int getQueuedByteCount()

Implements com.jogamp.opengl.util.av.AudioSink.getQueuedByteCount.

Doc from com.jogamp.opengl.util.av.AudioSink.getQueuedByteCount.

Returns the current number of bytes queued for playing.

init(AudioFormat, float, int, int, int) must be called first.

Annotations
@Override
getQueuedFrameCountback to summary
public int getQueuedFrameCount()

Implements com.jogamp.opengl.util.av.AudioSink.getQueuedFrameCount.

Doc from com.jogamp.opengl.util.av.AudioSink.getQueuedFrameCount.

Returns the current number of frames queued for playing.

init(AudioFormat, float, int, int, int) must be called first.

Annotations
@Override
getQueuedTimeback to summary
public int getQueuedTime()

Implements com.jogamp.opengl.util.av.AudioSink.getQueuedTime.

Doc from com.jogamp.opengl.util.av.AudioSink.getQueuedTime.

Returns the current queued frame time in milliseconds for playing.

init(AudioFormat, float, int, int, int) must be called first.

Annotations
@Override
getQueuedTimeImplback to summary
private final int getQueuedTimeImpl(final int byteCount)
getVolumeback to summary
public final float getVolume()

Implements com.jogamp.opengl.util.av.AudioSink.getVolume.

Doc from com.jogamp.opengl.util.av.AudioSink.getVolume.

Returns the volume.

Annotations
@Override
initback to summary
public boolean init(final AudioSink.AudioFormat requestedFormat, final float frameDuration, final int initialQueueSize, final int queueGrowAmount, final int queueLimit)

Implements com.jogamp.opengl.util.av.AudioSink.init.

Doc from com.jogamp.opengl.util.av.AudioSink.init.

Initializes the sink.

Implementation must match the given requestedFormat AudioFormat.

Caller shall validate requestedFormat via isSupported(AudioFormat) beforehand and try to find a suitable supported one. getPreferredFormat() and getMaxSupportedChannels() may help.

Parameters
requestedFormat:AudioSink.AudioFormat

the requested AudioFormat.

frameDuration:float

average or fixed frame duration in milliseconds helping a caching AudioFrame based implementation to determine the frame count in the queue. See DefaultFrameDuration.

initialQueueSize:int

initial time in milliseconds to queue in this sink, see DefaultInitialQueueSize.

queueGrowAmount:int

time in milliseconds to grow queue if full, see DefaultQueueGrowAmount.

queueLimit:int

maximum time in milliseconds the queue can hold (and grow), see DefaultQueueLimitWithVideo and DefaultQueueLimitAudioOnly.

Returns:boolean

true if successful, otherwise false

Annotations
@Override
isInitializedback to summary
public boolean isInitialized()

Implements com.jogamp.opengl.util.av.AudioSink.isInitialized.

Doc from com.jogamp.opengl.util.av.AudioSink.isInitialized.

Returns the initialized state of this instance.

The initialized state is affected by this instance overall availability, i.e. after instantiation, as well as by destroy().

Annotations
@Override
isPlayingback to summary
public boolean isPlaying()

Implements com.jogamp.opengl.util.av.AudioSink.isPlaying.

Doc from com.jogamp.opengl.util.av.AudioSink.isPlaying.

Returns true, if play() has been requested and the sink is still playing, otherwise false.

Annotations
@Override
isSupportedback to summary
public final boolean isSupported(final AudioSink.AudioFormat format)

Implements com.jogamp.opengl.util.av.AudioSink.isSupported.

Doc from com.jogamp.opengl.util.av.AudioSink.isSupported.

Returns true if the given format is supported by the sink, otherwise false.

Annotations
@Override
pauseback to summary
public void pause()

Implements com.jogamp.opengl.util.av.AudioSink.pause.

Doc from com.jogamp.opengl.util.av.AudioSink.pause.

Pause playing buffers while keeping enqueued data incl. it's internal position.

Annotations
@Override
playback to summary
public void play()

Implements com.jogamp.opengl.util.av.AudioSink.play.

Doc from com.jogamp.opengl.util.av.AudioSink.play.

Play buffers queued via enqueueData(AudioFrame) from current internal position. If no buffers are yet queued or the queue runs empty, playback is being continued when buffers are enqueued later on.

Annotations
@Override
playImplback to summary
private void playImpl()
setPlaySpeedback to summary
public final boolean setPlaySpeed(final float rate)

Implements com.jogamp.opengl.util.av.AudioSink.setPlaySpeed.

Doc from com.jogamp.opengl.util.av.AudioSink.setPlaySpeed.

Sets the playback speed.

To simplify test, play speed is normalized, i.e.

  • 1.0f: if Math.abs(1.0f - rate) < 0.01f

Returns:boolean

true if successful, otherwise false, i.e. due to unsupported value range of implementation.

Annotations
@Override
setVolumeback to summary
public final boolean setVolume(final float v)

Implements com.jogamp.opengl.util.av.AudioSink.setVolume.

Doc from com.jogamp.opengl.util.av.AudioSink.setVolume.

Sets the volume [0f..1f].

To simplify test, volume is normalized, i.e.

  • 0.0f: if Math.abs(v) < 0.01f
  • 1.0f: if Math.abs(1.0f - v) < 0.01f

Returns:boolean

true if successful, otherwise false, i.e. due to unsupported value range of implementation.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override