Interface AudioSink


  • public interface AudioSink
    • 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. See #init(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. See #init(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. See #init(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. See #init(AudioFormat, float, int, int, int).
        See Also:
        Constant Field Values
      • DefaultFormat

        static final AudioFormat DefaultFormat
        Default AudioFormat, [type PCM, sampleRate 44100, sampleSize 16, channelCount 2, signed, fixedP, !planar, littleEndian].
    • Method Detail

      • lockExclusive

        void lockExclusive()
        Exclusively locks this instance for the calling thread, if implementation utilizes locking.
        See Also:
        unlockExclusive()
      • unlockExclusive

        void unlockExclusive()
        Releases the exclusive lock for the calling thread, if implementation utilizes locking.
        See Also:
        lockExclusive()
      • isAvailable

        boolean isAvailable()
        Returns the available state of this instance.

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

      • 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: if Math.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: if Math.abs(v) < 0.01f
        • 1.0f: if Math.abs(1.0f - v) < 0.01f

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

        int getPreferredSampleRate()
        Returns the preferred sample-rate of this sink, i.e. mixer frequency in Hz, e.g. 41000 or 48000.

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

        May return DefaultFormat's 44100 default if undefined.

        See Also:
        #init(AudioFormat, float, int, int, int), isSupported(AudioFormat)
      • getSourceCount

        int getSourceCount()
        Returns the number of sources the used device is capable to mix.

        This device attribute is only formally exposed and not used, since an audio sink is only utilizing one source.

        May return -1 if undefined.

        Returns:
      • getDefaultLatency

        float getDefaultLatency()
        Returns the default (minimum) latency in seconds

        Latency might be the reciprocal mixer-refresh-interval [Hz], e.g. 50 Hz refresh-rate = 20ms minimum latency.

        May return 20ms for a 50 Hz refresh rate if undefined.

      • getMaxSupportedChannels

        int getMaxSupportedChannels()
        Return the maximum number of supported channels, e.g. 1 for mono, 2 for stereo, etc.
      • isSupported

        boolean isSupported​(AudioFormat format)
        Returns true if the given format is supported by the sink, otherwise false.
        See Also:
        #init(AudioFormat, float, int, int, int), getPreferredFormat()
      • getChosenFormat

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

        float getLatency()
        Returns the (minimum) latency in seconds of this sink as set by #init(AudioFormat, float, int, int, int), see getDefaultLatency().

        Latency might be the reciprocal mixer-refresh-interval [Hz], e.g. 50 Hz refresh-rate = 20ms minimum latency.

        See Also:
        #init(AudioFormat, float, int, int, int)
      • isPlaying

        boolean isPlaying()
        Returns true, if play() 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.
        See Also:
        play(), flush(), #enqueueData(AudioFrame)
      • flush

        void flush()
        Flush all queued buffers, implies pause().

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

        See Also:
        play(), pause(), #enqueueData(AudioFrame), #init(AudioFormat, float, int, int, int)
      • 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 by #init(AudioFormat, float, int, int, int).
        See Also:
        #init(AudioFormat, float, int, int, int)
      • getEnqueuedFrameCount

        int getEnqueuedFrameCount()
        Returns the current enqueued frames count since #init(AudioFormat, float, int, int, int).
        See Also:
        #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.

        See Also:
        #init(AudioFormat, float, int, int, int)
      • getQueuedByteCount

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

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

        See Also:
        #init(AudioFormat, float, int, int, int)
      • getQueuedTime

        int getQueuedTime()
        Returns the current queued frame time in milliseconds for playing.

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

        See Also:
        #init(AudioFormat, float, int, int, int)
      • 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.

        See Also:
        #init(AudioFormat, float, int, int, int)
      • enqueueData

        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 set via #init(AudioFormat, float, int, int, int).

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

        See Also:
        #init(AudioFormat, float, int, int, int)