Interface AudioSink
-
public interface AudioSink
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classAudioSink.AudioDataFramestatic classAudioSink.AudioFormatSpecifies the linear audio PCM format.static classAudioSink.AudioFrame
-
Field Summary
Fields Modifier and Type Field Description static booleanDEBUGstatic AudioSink.AudioFormatDefaultFormatDefaultAudioSink.AudioFormat, [type PCM, sampleRate 44100, sampleSize 16, channelCount 2, signed, fixedP, !planar, littleEndian].static intDefaultFrameDurationDefault frame duration in millisecond, i.e.static intDefaultInitialQueueSizeInitial audio queue size in milliseconds.static intDefaultQueueGrowAmountAudio queue grow size in milliseconds.static intDefaultQueueLimitAudioOnlyAudio queue limit w/o video in milliseconds.static intDefaultQueueLimitWithVideoAudio queue limit w/ video in milliseconds.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voiddestroy()Destroys this instance, i.e.AudioSink.AudioFrameenqueueData(int pts, ByteBuffer bytes, int byteCount)EnqueuebyteCountbytes of the remaining bytes of the given NIOByteBufferto this sink.voidflush()Flush all queued buffers, impliespause().AudioSink.AudioFormatgetChosenFormat()Returns theAudioSink.AudioFormatas chosen byinit(AudioFormat, float, int, int, int), i.e.intgetEnqueuedFrameCount()intgetFrameCount()Returns the number of allocated buffers as requested byinit(AudioFormat, float, int, int, int).intgetFreeFrameCount()Returns the current number of frames in the sink available for writing.intgetMaxSupportedChannels()Return the maximum number of supported channels.floatgetPlaySpeed()Returns the playback speed.AudioSink.AudioFormatgetPreferredFormat()Returns the preferredAudioSink.AudioFormatby this sink.intgetPTS()Return the current audio presentation timestamp (PTS) in milliseconds.intgetQueuedByteCount()Returns the current number of bytes queued for playing.intgetQueuedFrameCount()Returns the current number of frames queued for playing.intgetQueuedTime()Returns the current queued frame time in milliseconds for playing.floatgetVolume()Returns the volume.booleaninit(AudioSink.AudioFormat requestedFormat, float frameDuration, int initialQueueSize, int queueGrowAmount, int queueLimit)Initializes the sink.booleanisInitialized()Returns theinitialized stateof this instance.booleanisPlaying()Returns true, ifplay()has been requested and the sink is still playing, otherwise false.booleanisSupported(AudioSink.AudioFormat format)Returns true if the given format is supported by the sink, otherwise false.voidpause()Pause playing buffers while keeping enqueued data incl.voidplay()Play buffers queued via#enqueueData(AudioFrame)from current internal position.booleansetPlaySpeed(float s)Sets the playback speed.booleansetVolume(float v)Sets the volume [0f..1f].
-
-
-
Field Detail
-
DEBUG
static final boolean DEBUG
-
DefaultFrameDuration
static final int DefaultFrameDuration
Default frame duration in millisecond, i.e. 1 frame per 32 ms.- See Also:
- Constant Field Values
-
DefaultInitialQueueSize
static final int DefaultInitialQueueSize
Initial audio queue size in milliseconds. 512 ms, i.e. 16 frames per 32 ms. Seeinit(AudioFormat, float, int, int, int).- See Also:
- Constant Field Values
-
DefaultQueueGrowAmount
static final int DefaultQueueGrowAmount
Audio queue grow size in milliseconds. 512 ms, i.e. 16 frames per 32 ms. Seeinit(AudioFormat, float, int, int, int).- See Also:
- Constant Field Values
-
DefaultQueueLimitWithVideo
static final int DefaultQueueLimitWithVideo
Audio queue limit w/ video in milliseconds. 3072 ms, i.e. 96 frames per 32 ms. Seeinit(AudioFormat, float, int, int, int).- See Also:
- Constant Field Values
-
DefaultQueueLimitAudioOnly
static final int DefaultQueueLimitAudioOnly
Audio queue limit w/o video in milliseconds. 1024 ms, i.e. 32 frames per 32 ms. Seeinit(AudioFormat, float, int, int, int).- See Also:
- Constant Field Values
-
DefaultFormat
static final AudioSink.AudioFormat DefaultFormat
DefaultAudioSink.AudioFormat, [type PCM, sampleRate 44100, sampleSize 16, channelCount 2, signed, fixedP, !planar, littleEndian].
-
-
Method Detail
-
isInitialized
boolean isInitialized()
Returns theinitialized stateof this instance.The
initialized stateis affected by this instance overall availability, i.e. after instantiation, as well as bydestroy().
-
getPlaySpeed
float getPlaySpeed()
Returns the playback speed.
-
setPlaySpeed
boolean setPlaySpeed(float s)
Sets the playback speed.To simplify test, play speed is normalized, i.e.
1.0f: ifMath.abs(1.0f - rate) < 0.01f
- Returns:
- true if successful, otherwise false, i.e. due to unsupported value range of implementation.
-
getVolume
float getVolume()
Returns the volume.
-
setVolume
boolean setVolume(float v)
Sets the volume [0f..1f].To simplify test, volume is normalized, i.e.
0.0f: ifMath.abs(v) < 0.01f1.0f: ifMath.abs(1.0f - v) < 0.01f
- Returns:
- true if successful, otherwise false, i.e. due to unsupported value range of implementation.
-
getPreferredFormat
AudioSink.AudioFormat getPreferredFormat()
Returns the preferredAudioSink.AudioFormatby 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
#AudioFormatattributes considered by implementations:- ALAudioSink:
AudioSink.AudioFormat.sampleRate.
- See Also:
#initSink(AudioFormat),isSupported(AudioFormat)
- ALAudioSink:
-
getMaxSupportedChannels
int getMaxSupportedChannels()
Return the maximum number of supported channels.
-
isSupported
boolean isSupported(AudioSink.AudioFormat format)
Returns true if the given format is supported by the sink, otherwise false.- See Also:
#initSink(AudioFormat),getPreferredFormat()
-
init
boolean init(AudioSink.AudioFormat requestedFormat, float frameDuration, int initialQueueSize, int queueGrowAmount, int queueLimit)
Initializes the sink.Implementation must match the given
requestedFormatAudioSink.AudioFormat.Caller shall validate
requestedFormatviaisSupported(AudioFormat)beforehand and try to find a suitable supported one.getPreferredFormat()andgetMaxSupportedChannels()may help.- Parameters:
requestedFormat- the requestedAudioSink.AudioFormat.frameDuration- average or fixed frame duration in milliseconds helping a cachingAudioSink.AudioFramebased implementation to determine the frame count in the queue. SeeDefaultFrameDuration.initialQueueSize- initial time in milliseconds to queue in this sink, seeDefaultInitialQueueSize.queueGrowAmount- time in milliseconds to grow queue if full, seeDefaultQueueGrowAmount.queueLimit- maximum time in milliseconds the queue can hold (and grow), seeDefaultQueueLimitWithVideoandDefaultQueueLimitAudioOnly.- Returns:
- true if successful, otherwise false
-
getChosenFormat
AudioSink.AudioFormat getChosenFormat()
Returns theAudioSink.AudioFormatas chosen byinit(AudioFormat, float, int, int, int), i.e. it shall match the requestedFormat.
-
isPlaying
boolean isPlaying()
Returns true, ifplay()has been requested and the sink is still playing, otherwise false.
-
play
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()
-
pause
void pause()
Pause playing buffers while keeping enqueued data incl. it's internal position.
-
flush
void flush()
Flush all queued buffers, impliespause().init(AudioFormat, float, int, int, int)must be called first.
-
destroy
void destroy()
Destroys this instance, i.e. closes all streams and devices allocated.
-
getFrameCount
int getFrameCount()
Returns the number of allocated buffers as requested byinit(AudioFormat, float, int, int, int).
-
getEnqueuedFrameCount
int getEnqueuedFrameCount()
- Returns:
- the current enqueued frames count since
init(AudioFormat, float, int, int, int).
-
getQueuedFrameCount
int getQueuedFrameCount()
Returns the current number of frames queued for playing.init(AudioFormat, float, int, int, int)must be called first.
-
getQueuedByteCount
int getQueuedByteCount()
Returns the current number of bytes queued for playing.init(AudioFormat, float, int, int, int)must be called first.
-
getQueuedTime
int getQueuedTime()
Returns the current queued frame time in milliseconds for playing.init(AudioFormat, float, int, int, int)must be called first.
-
getPTS
int getPTS()
Return the current audio presentation timestamp (PTS) in milliseconds.
-
getFreeFrameCount
int getFreeFrameCount()
Returns the current number of frames in the sink available for writing.init(AudioFormat, float, int, int, int)must be called first.
-
enqueueData
AudioSink.AudioFrame enqueueData(int pts, ByteBuffer bytes, int byteCount)
EnqueuebyteCountbytes of the remaining bytes of the given NIOByteBufferto this sink.The data must comply with the chosen
AudioSink.AudioFormatas returned by#initSink(AudioFormat).init(AudioFormat, float, int, int, int)must be called first.
-
-