From 742cf0cd053f968cbf291ed367d4568c12d8bde2 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 21 May 2023 16:44:17 +0200 Subject: AudioFormat/AudioSink: Use float in seconds for duration to avoid losing precision when dealing with stats, averages etc --- src/java/com/jogamp/common/av/AudioSink.java | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/java/com/jogamp/common/av/AudioSink.java') diff --git a/src/java/com/jogamp/common/av/AudioSink.java b/src/java/com/jogamp/common/av/AudioSink.java index 704c2a6..b4738b3 100644 --- a/src/java/com/jogamp/common/av/AudioSink.java +++ b/src/java/com/jogamp/common/av/AudioSink.java @@ -65,9 +65,18 @@ public interface AudioSink { public static abstract class AudioFrame extends TimeFrameI { protected int byteSize; + /** + * Ctor w/ zero duration, {@link #INVALID_PTS} and zero byte size + */ public AudioFrame() { this.byteSize = 0; } + /** + * Create a new instance + * @param pts frame pts in milliseconds + * @param duration frame duration in milliseconds + * @param byteCount size in bytes + */ public AudioFrame(final int pts, final int duration, final int byteCount) { super(pts, duration); this.byteSize=byteCount; @@ -89,6 +98,13 @@ public interface AudioSink { public static class AudioDataFrame extends AudioFrame { protected final ByteBuffer data; + /** + * Create a new instance + * @param pts frame pts in milliseconds + * @param duration frame duration in milliseconds + * @param bytes audio data + * @param byteCount size in bytes + */ public AudioDataFrame(final int pts, final int duration, final ByteBuffer bytes, final int byteCount) { super(pts, duration, byteCount); if( byteCount > bytes.remaining() ) { @@ -343,13 +359,13 @@ public interface AudioSink { public int getQueuedByteCount(); /** - * Returns the current queued frame time in milliseconds for playing. + * Returns the current queued frame time in seconds for playing. *

* {@link #init(AudioFormat, float, int, int, int)} must be called first. *

* @see #init(AudioFormat, float, int, int, int) */ - public int getQueuedTime(); + public float getQueuedTime(); /** * Returns average frame duration last assessed @ {@link #enqueueData(int, ByteBuffer, int)} when queue was full. @@ -357,7 +373,7 @@ public interface AudioSink { * avgFrameDuration = {@link #getQueuedTime()} / {@link #getQueuedFrameCount()} * */ - public int getAvgFrameDuration(); + public float getAvgFrameDuration(); /** * Return the current audio presentation timestamp (PTS) in milliseconds. @@ -381,7 +397,7 @@ public interface AudioSink { *

* {@link #init(AudioFormat, float, int, int, int)} must be called first. *

- * @param pts presentation time stamp for the newly enqueued {@link AudioFrame} + * @param pts presentation time stamp in milliseconds for the newly enqueued {@link AudioFrame} * @param bytes audio data for the newly enqueued {@link AudioFrame} * @returns the enqueued internal {@link AudioFrame}. * @see #init(AudioFormat, float, int, int, int) -- cgit v1.2.3