Top Description Inners Fields Constructors Methods
jogamp.opengl.openal.av

public Class ALAudioSink

extends Object
implements AudioSink
Class Inheritance
All Implemented Interfaces
com.jogamp.opengl.util.av.AudioSink
Imports
java.nio.ByteBuffer, java.util.Arrays, jogamp.opengl.Debug, com.jogamp.common.ExceptionUtils, com.jogamp.common.util.LFRingbuffer, .PropertyAccess, .Ringbuffer, com.jogamp.common.util.locks.LockFactory, .RecursiveLock, com.jogamp.openal.AL, .ALC, .ALCConstants, .ALCcontext, .ALCdevice, .ALConstants, .ALExt, .ALFactory, com.jogamp.openal.util.ALHelpers, com.jogamp.opengl.util.av.AudioSink

OpenAL Audio Sink

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static final AL
private static final String
private volatile int
private int[]
private static final ALC
private static final String
private int
private static final ALExt
private int
private Ringbuffer<ALAudioSink.ALAudioFrame>
private Ringbuffer<ALAudioSink.ALAudioFrame>
private int
private int[]
private AudioSink.AudioFormat
private ALCcontext
private static final boolean
private ALCdevice
private String
private volatile int
private int
private int
private boolean
private boolean
private boolean
private final RecursiveLock
private volatile int
private volatile boolean
private float
playSpeed

Playback speed, range [0.5 - 2.0], default 1.0.

private AudioSink.AudioFormat
private static final boolean
private float

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private boolean
checkALError(final String prefix)

private void
clearPreALError(final String prefix)

private static int[]
concat(final int[] first, final int[] second)

private final int
dequeueBuffer(final boolean wait, final boolean ignoreBufferInconsistency)

private final int
dequeueBuffer(final boolean wait, final int inPTS, final int inDuration)

private final void
public final void
destroy()

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

Destroys this instance, i.e. closes all streams and devices allocated.
private void
private final void
public final AudioSink.AudioFrame
enqueueData(final int pts, final ByteBuffer bytes, 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 final 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 final 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 final 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 String
public final float
getPlaySpeed()

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

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

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

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

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

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

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

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

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

Returns the current queued frame time in milliseconds for playing.
private final int
getSourceState(final boolean ignoreError)

private static final String
public final float
private boolean
growBuffers()

private static <t> T[] concat(T[] first, T[] second) { final T[] result = Arrays.copyOf(first, first.length + second.length); System.arraycopy(second, 0, result, first.length, second.length); return result; }

public final 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 final boolean
isInitialized()

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

Returns the initialized state of this instance.
public final 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.
private final boolean
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.
private final void
public final void
pause()

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

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

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

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

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

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

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

Sets the volume [0f..1f].
private final String
private final void
stopImpl(final boolean ignoreError)

private static final String
toHexString(final int v)

public final String
toString()

Overrides java.lang.Object.toString.

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

Field Detail

alback to summary
private static final AL al
AL_SOFT_buffer_samplesback to summary
private static final String AL_SOFT_buffer_samples
alBufferBytesQueuedback to summary
private volatile int alBufferBytesQueued
alBufferNamesback to summary
private int[] alBufferNames
alcback to summary
private static final ALC alc
ALC_EXT_thread_local_contextback to summary
private static final String ALC_EXT_thread_local_context
alChannelLayoutback to summary
private int alChannelLayout
alExtback to summary
private static final ALExt alExt
alFormatback to summary
private int alFormat
alFramesAvailback to summary
private Ringbuffer<ALAudioSink.ALAudioFrame> alFramesAvail
alFramesPlayingback to summary
private Ringbuffer<ALAudioSink.ALAudioFrame> alFramesPlaying
alSampleTypeback to summary
private int alSampleType
alSourceback to summary
private int[] alSource
chosenFormatback to summary
private AudioSink.AudioFormat chosenFormat
contextback to summary
private ALCcontext context
DEBUG_TRACEback to summary
private static final boolean DEBUG_TRACE
deviceback to summary
private ALCdevice device
deviceSpecifierback to summary
private String deviceSpecifier
enqueuedFrameCountback to summary
private volatile int enqueuedFrameCount
frameGrowAmountback to summary
private int frameGrowAmount
frameLimitback to summary
private int frameLimit
hasALC_thread_local_contextback to summary
private boolean hasALC_thread_local_context
hasSOFTBufferSamplesback to summary
private boolean hasSOFTBufferSamples
initializedback to summary
private boolean initialized
lockback to summary
private final RecursiveLock lock
playingPTSback to summary
private volatile int playingPTS
playRequestedback to summary
private volatile boolean playRequested
playSpeedback to summary
private float playSpeed

Playback speed, range [0.5 - 2.0], default 1.0.

preferredAudioFormatback to summary
private AudioSink.AudioFormat preferredAudioFormat
staticAvailableback to summary
private static final boolean staticAvailable
volumeback to summary
private float volume

Constructor Detail

ALAudioSinkback to summary
public ALAudioSink()

Method Detail

checkALErrorback to summary
private boolean checkALError(final String prefix)
clearPreALErrorback to summary
private void clearPreALError(final String prefix)
concatback to summary
private static int[] concat(final int[] first, final int[] second)
dequeueBufferback to summary
private final int dequeueBuffer(final boolean wait, final boolean ignoreBufferInconsistency)
dequeueBufferback to summary
private final int dequeueBuffer(final boolean wait, final int inPTS, final int inDuration)
dequeueForceAllback to summary
private final void dequeueForceAll()
destroyback to summary
public final 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
destroyBuffersback to summary
private void destroyBuffers()
destroyContextback to summary
private final void destroyContext()
enqueueDataback to summary
public final AudioSink.AudioFrame enqueueData(final int pts, final ByteBuffer bytes, 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 final 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 final 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 final 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
getPerfStringback to summary
public final String getPerfString()
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 final 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 final 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 final 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 final 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
getSourceStateback to summary
private final int getSourceState(final boolean ignoreError)
getThreadNameback to summary
private static final String getThreadName()
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
growBuffersback to summary
private boolean growBuffers()

private static T[] concat(T[] first, T[] second) { final T[] result = Arrays.copyOf(first, first.length + second.length); System.arraycopy(second, 0, result, first.length, second.length); return result; }

initback to summary
public final 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 final 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 final 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
isPlayingImpl0back to summary
private final boolean isPlayingImpl0()
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
lockContextback to summary
private final void lockContext()
pauseback to summary
public final 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
pauseImplback to summary
private final void pauseImpl()
playback to summary
public final 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 final void playImpl()
querySampleRateback to summary
private final int querySampleRate()
setPlaySpeedback to summary
public final boolean setPlaySpeed(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(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
shortStringback to summary
private final String shortString()
stopImplback to summary
private final void stopImpl(final boolean ignoreError)
toHexStringback to summary
private static final String toHexString(final int v)
toStringback to summary
public final 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
unlockContextback to summary
private final void unlockContext()
jogamp.opengl.openal.av back to summary

pack-priv Class ALAudioSink.ALAudioFrame

extends AudioFrame
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final int
Inherited from com.jogamp.opengl.util.av.AudioSink.AudioFrame:
byteSize

Constructor Summary

AccessConstructor and Description
pack-priv
ALAudioFrame(final int alBuffer)

public
ALAudioFrame(final int alBuffer, final int pts, final int duration, final int dataSize)

Method Summary

Modifier and TypeMethod and Description
public final int
getALBuffer()

Get this frame's OpenAL buffer name

public String
toString()

Overrides com.jogamp.opengl.util.av.AudioSink.AudioFrame.toString.

Returns a string representation of the object.
Inherited from com.jogamp.opengl.util.av.AudioSink.AudioFrame:
getByteSizesetByteSize

Field Detail

alBufferback to summary
private final int alBuffer

Constructor Detail

ALAudioFrameback to summary
pack-priv ALAudioFrame(final int alBuffer)
ALAudioFrameback to summary
public ALAudioFrame(final int alBuffer, final int pts, final int duration, final int dataSize)

Method Detail

getALBufferback to summary
public final int getALBuffer()

Get this frame's OpenAL buffer name

toStringback to summary
public String toString()

Overrides com.jogamp.opengl.util.av.AudioSink.AudioFrame.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object