Top Inners Fields Methods
com.jogamp.opengl.util.av

public Interface AudioSink

Known Direct Implementers
jogamp.opengl.openal.av.ALAudioSink, jogamp.opengl.util.av.JavaSoundAudioSink, jogamp.opengl.util.av.NullAudioSink
Imports
java.nio.ByteBuffer, com.jogamp.opengl.util.TimeFrameI, jogamp.opengl.Debug

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static class
AudioSink.AudioFormat

Specifies the linear audio PCM format.

public abstract static class

Field Summary

Modifier and TypeField and Description
public static final boolean
public static final AudioSink.AudioFormat
DefaultFormat

Default AudioFormat, [type PCM, sampleRate 44100, sampleSize 16, channelCount 2, signed, fixedP, !planar, littleEndian].

public static final int
DefaultFrameDuration

Default frame duration in millisecond, i.e. 1 frame per ms.

public static final int
DefaultInitialQueueSize

Initial audio queue size in milliseconds.

public static final int
DefaultQueueGrowAmount

Audio queue grow size in milliseconds.

public static final int
DefaultQueueLimitAudioOnly

Audio queue limit w/o video in milliseconds.

public static final int
DefaultQueueLimitWithVideo

Audio queue limit w/ video in milliseconds.

Method Summary

Modifier and TypeMethod and Description
public void
destroy()

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

public AudioSink.AudioFrame

Returns:

the enqueued internal AudioFrame.
enqueueData
(int pts, ByteBuffer bytes, int byteCount)

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

public void
flush()

Flush all queued buffers, implies pause().

public AudioSink.AudioFormat
getChosenFormat()

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

public int

Returns:

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

public int
getFrameCount()

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

public int
getFreeFrameCount()

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

public int
getMaxSupportedChannels()

Return the maximum number of supported channels.

public float
getPlaySpeed()

Returns the playback speed.

public AudioSink.AudioFormat
getPreferredFormat()

Returns the preferred AudioFormat by this sink.

public int
getPTS()

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

public int
getQueuedByteCount()

Returns the current number of bytes queued for playing.

public int
getQueuedFrameCount()

Returns the current number of frames queued for playing.

public int
getQueuedTime()

Returns the current queued frame time in milliseconds for playing.

public float
getVolume()

Returns the volume.

public boolean

Returns:

true if successful, otherwise false
init
(AudioSink.AudioFormat
the requested AudioFormat.
requestedFormat
,
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
,
int
initial time in milliseconds to queue in this sink, see DefaultInitialQueueSize.
initialQueueSize
,
int
time in milliseconds to grow queue if full, see DefaultQueueGrowAmount.
queueGrowAmount
,
int
maximum time in milliseconds the queue can hold (and grow), see DefaultQueueLimitWithVideo and DefaultQueueLimitAudioOnly.
queueLimit
)

Initializes the sink.

public boolean
isInitialized()

Returns the initialized state of this instance.

public boolean
isPlaying()

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

public boolean
isSupported(AudioSink.AudioFormat format)

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

public void
pause()

Pause playing buffers while keeping enqueued data incl.

public void
play()

Play buffers queued via enqueueData(AudioFrame) from current internal position.

public boolean

Returns:

true if successful, otherwise false, i.e. due to unsupported value range of implementation.
setPlaySpeed
(float s)

Sets the playback speed.

public boolean

Returns:

true if successful, otherwise false, i.e. due to unsupported value range of implementation.
setVolume
(float v)

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

Field Detail

DEBUGback to summary
public static final boolean DEBUG
DefaultFormatback to summary
public static final AudioSink.AudioFormat DefaultFormat

Default AudioFormat, [type PCM, sampleRate 44100, sampleSize 16, channelCount 2, signed, fixedP, !planar, littleEndian].

DefaultFrameDurationback to summary
public static final int DefaultFrameDuration

Default frame duration in millisecond, i.e. 1 frame per ms.

DefaultInitialQueueSizeback to summary
public static final int DefaultInitialQueueSize

Initial audio queue size in milliseconds. ms, i.e. 16 frames per 32 ms. See init(AudioFormat, float, int, int, int).

DefaultQueueGrowAmountback to summary
public static final int DefaultQueueGrowAmount

Audio queue grow size in milliseconds. ms, i.e. 16 frames per 32 ms. See init(AudioFormat, float, int, int, int).

DefaultQueueLimitAudioOnlyback to summary
public static final int DefaultQueueLimitAudioOnly

Audio queue limit w/o video in milliseconds. ms, i.e. 32 frames per 32 ms. See init(AudioFormat, float, int, int, int).

DefaultQueueLimitWithVideoback to summary
public static final int DefaultQueueLimitWithVideo

Audio queue limit w/ video in milliseconds. ms, i.e. 96 frames per 32 ms. See init(AudioFormat, float, int, int, int).

Method Detail

destroyback to summary
public void destroy()

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

enqueueDataback to summary
public AudioSink.AudioFrame enqueueData(int pts, ByteBuffer bytes, int byteCount)

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.

flushback to summary
public void flush()

Flush all queued buffers, implies pause().

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

See Also
play(), pause(), enqueueData(AudioFrame)
getChosenFormatback to summary
public AudioSink.AudioFormat getChosenFormat()

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

getEnqueuedFrameCountback to summary
public int getEnqueuedFrameCount()
Returns:int

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

getFrameCountback to summary
public int getFrameCount()

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

getFreeFrameCountback to summary
public int getFreeFrameCount()

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

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

getMaxSupportedChannelsback to summary
public int getMaxSupportedChannels()

Return the maximum number of supported channels.

getPlaySpeedback to summary
public float getPlaySpeed()

Returns the playback speed.

getPreferredFormatback to summary
public AudioSink.AudioFormat 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:

See Also
initSink(AudioFormat), isSupported(AudioFormat)
getPTSback to summary
public int getPTS()

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

getQueuedByteCountback to summary
public int getQueuedByteCount()

Returns the current number of bytes queued for playing.

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

getQueuedFrameCountback to summary
public int getQueuedFrameCount()

Returns the current number of frames queued for playing.

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

getQueuedTimeback to summary
public int getQueuedTime()

Returns the current queued frame time in milliseconds for playing.

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

getVolumeback to summary
public float getVolume()

Returns the volume.

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

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

isInitializedback to summary
public boolean 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().

isPlayingback to summary
public boolean isPlaying()

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

isSupportedback to summary
public boolean isSupported(AudioSink.AudioFormat format)

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

See Also
initSink(AudioFormat), getPreferredFormat()
pauseback to summary
public void pause()

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

See Also
play(), flush(), enqueueData(AudioFrame)
playback to summary
public void 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.

See Also
enqueueData(AudioFrame), pause()
setPlaySpeedback to summary
public boolean setPlaySpeed(float s)

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.

setVolumeback to summary
public boolean setVolume(float v)

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.

com.jogamp.opengl.util.av back to summary

public Class AudioSink.AudioDataFrame

extends AudioFrame
Class Inheritance

Field Summary

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

Constructor Summary

AccessConstructor and Description
public
AudioDataFrame(final int pts, final int duration, final ByteBuffer bytes, final int byteCount)

Method Summary

Modifier and TypeMethod and Description
public final ByteBuffer
getData()

Get this frame's data.

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

databack to summary
protected final ByteBuffer data

Constructor Detail

AudioDataFrameback to summary
public AudioDataFrame(final int pts, final int duration, final ByteBuffer bytes, final int byteCount)

Method Detail

getDataback to summary
public final ByteBuffer getData()

Get this frame's data.

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

Annotations
@Override
com.jogamp.opengl.util.av back to summary

public Class AudioSink.AudioFormat

extends Object
Class Inheritance

Specifies the linear audio PCM format.

Field Summary

Modifier and TypeField and Description
public final int
channelCount

Number of channels.

public final boolean
fixedP

Fixed or floating point values.

public final boolean
public final boolean
planar

Planar or packed samples.

public final int
sampleRate

Sample rate in Hz (1/s).

public final int
sampleSize

Sample size in bits.

public final boolean

Constructor Summary

AccessConstructor and Description
public
AudioFormat(final int
sample rate in Hz (1/s)
sampleRate
,
final int
sample size in bits
sampleSize
,
final int
number of channels
channelCount
,
final boolean
true if signed number, false for unsigned
signed
,
final boolean
true for fixed point value, false for unsigned floating point value with a sampleSize of 32 (float) or 64 (double)
fixedP
,
final boolean
true for planar data package (each channel in own data buffer), false for packed data channels interleaved in one buffer.
planar
,
final boolean
true for little-endian, false for big endian
littleEndian
)

Method Summary

Modifier and TypeMethod and Description
public final int
getBytesDuration(final int byteCount)

Returns the duration in milliseconds of the given byte count according to sampleSize, channelCount and sampleRate.

public final int
getBytesSampleCount(final int
number of bytes
byteCount
)

Returns the sample count of given byte count according to the sampleSize, i.e.:

 ( byteCount * 8 ) / sampleSize
public final int
getDurationsByteSize(final int millisecs)

Returns the byte size of the given milliseconds according to sampleSize, channelCount and sampleRate.

public final int
getFrameCount(final int
time in milliseconds
millisecs
,
final float
duration per frame in milliseconds.
frameDuration
)

Returns the rounded frame count of the given milliseconds and frame duration.

public final int
getSamplesByteCount(final int
sample count
sampleCount
)

Returns the byte size of given sample count according to the sampleSize, i.e.:

 sampleCount * ( sampleSize / 8 )
public final float
getSamplesDuration(final int
sample count per frame and channel
sampleCount
)

Returns the duration in milliseconds of the given sample count per frame and channel according to the sampleRate, i.e.

   ( 1000f * sampleCount ) / sampleRate
public String
toString()

Overrides java.lang.Object.toString.

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

Field Detail

channelCountback to summary
public final int channelCount

Number of channels.

fixedPback to summary
public final boolean fixedP

Fixed or floating point values. Floating point 'float' has sampleSize 32, 'double' has sampleSize 64.

littleEndianback to summary
public final boolean littleEndian
planarback to summary
public final boolean planar

Planar or packed samples. If planar, each channel has their own data buffer. If packed, channel data is interleaved in one buffer.

sampleRateback to summary
public final int sampleRate

Sample rate in Hz (1/s).

sampleSizeback to summary
public final int sampleSize

Sample size in bits.

signedback to summary
public final boolean signed

Constructor Detail

AudioFormatback to summary
public AudioFormat(final int sampleRate, final int sampleSize, final int channelCount, final boolean signed, final boolean fixedP, final boolean planar, final boolean littleEndian)
Parameters
sampleRate:int

sample rate in Hz (1/s)

sampleSize:int

sample size in bits

channelCount:int

number of channels

signed:boolean

true if signed number, false for unsigned

fixedP:boolean

true for fixed point value, false for unsigned floating point value with a sampleSize of 32 (float) or 64 (double)

planar:boolean

true for planar data package (each channel in own data buffer), false for packed data channels interleaved in one buffer.

littleEndian:boolean

true for little-endian, false for big endian

Method Detail

getBytesDurationback to summary
public final int getBytesDuration(final int byteCount)

Returns the duration in milliseconds of the given byte count according to sampleSize, channelCount and sampleRate.

Byte Count -> Time

getBytesSampleCountback to summary
public final int getBytesSampleCount(final int byteCount)

Returns the sample count of given byte count according to the sampleSize, i.e.:

 ( byteCount * 8 ) / sampleSize

Note

If byteCount covers all channels and you request the sample size per channel, you need to divide the result by sampleCount by channelCount.

Byte Count -> Sample Count

Parameters
byteCount:int

number of bytes

getDurationsByteSizeback to summary
public final int getDurationsByteSize(final int millisecs)

Returns the byte size of the given milliseconds according to sampleSize, channelCount and sampleRate.

Time -> Byte Count

getFrameCountback to summary
public final int getFrameCount(final int millisecs, final float frameDuration)

Returns the rounded frame count of the given milliseconds and frame duration.

    Math.max( 1, millisecs / frameDuration + 0.5f )

Note

frameDuration can be derived by sample count per frame and channel via getSamplesDuration(int).

Frame Time -> Frame Count

Parameters
millisecs:int

time in milliseconds

frameDuration:float

duration per frame in milliseconds.

getSamplesByteCountback to summary
public final int getSamplesByteCount(final int sampleCount)

Returns the byte size of given sample count according to the sampleSize, i.e.:

 sampleCount * ( sampleSize / 8 )

Note

To retrieve the byte size for all channels, you need to pre-multiply sampleCount with channelCount.

Sample Count -> Byte Count

Parameters
sampleCount:int

sample count

getSamplesDurationback to summary
public final float getSamplesDuration(final int sampleCount)

Returns the duration in milliseconds of the given sample count per frame and channel according to the sampleRate, i.e.

   ( 1000f * sampleCount ) / sampleRate

Sample Count -> Time

Parameters
sampleCount:int

sample count per frame and channel

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
com.jogamp.opengl.util.av back to summary

public abstract Class AudioSink.AudioFrame

extends TimeFrameI
Class Inheritance
Known Direct Subclasses
com.jogamp.opengl.util.av.AudioSink.AudioDataFrame, jogamp.opengl.openal.av.ALAudioSink.ALAudioFrame

Field Summary

Modifier and TypeField and Description
protected int
Inherited from com.jogamp.opengl.util.TimeFrameI:
durationEND_OF_STREAM_PTSINVALID_PTSpts

Constructor Summary

AccessConstructor and Description
public
public
AudioFrame(final int pts, final int duration, final int byteCount)

Method Summary

Modifier and TypeMethod and Description
public final int
getByteSize()

Get this frame's size in bytes.

public final void
setByteSize(final int size)

Set this frame's size in bytes.

public String
toString()

Overrides com.jogamp.opengl.util.TimeFrameI.toString.

Returns a string representation of the object.
Inherited from com.jogamp.opengl.util.TimeFrameI:
getDurationgetPTSsetDurationsetPTS

Field Detail

byteSizeback to summary
protected int byteSize

Constructor Detail

AudioFrameback to summary
public AudioFrame()
AudioFrameback to summary
public AudioFrame(final int pts, final int duration, final int byteCount)

Method Detail

getByteSizeback to summary
public final int getByteSize()

Get this frame's size in bytes.

setByteSizeback to summary
public final void setByteSize(final int size)

Set this frame's size in bytes.

toStringback to summary
public String toString()

Overrides com.jogamp.opengl.util.TimeFrameI.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override