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/jogamp/common/av/JavaSoundAudioSink.java | 14 +++++--------- src/java/jogamp/common/av/NullAudioSink.java | 8 ++++---- 2 files changed, 9 insertions(+), 13 deletions(-) (limited to 'src/java/jogamp') diff --git a/src/java/jogamp/common/av/JavaSoundAudioSink.java b/src/java/jogamp/common/av/JavaSoundAudioSink.java index bdf4e22..7cd4310 100644 --- a/src/java/jogamp/common/av/JavaSoundAudioSink.java +++ b/src/java/jogamp/common/av/JavaSoundAudioSink.java @@ -262,7 +262,7 @@ public class JavaSoundAudioSink implements AudioSink { written += len; } playImpl(); - return new AudioDataFrame(pts, chosenFormat.getBytesDuration(byteCount), byteBuffer, byteCount); + return new AudioDataFrame(pts, Math.round(1000f*chosenFormat.getBytesDuration(byteCount)), byteBuffer, byteCount); } @Override @@ -276,17 +276,13 @@ public class JavaSoundAudioSink implements AudioSink { } @Override - public int getQueuedTime() { - return getQueuedTimeImpl( getQueuedByteCount() ); - } - private final int getQueuedTimeImpl(final int byteCount) { - final int bytesPerSample = chosenFormat.sampleSize >>> 3; // /8 - return byteCount / ( chosenFormat.channelCount * bytesPerSample * ( chosenFormat.sampleRate / 1000 ) ); + public float getQueuedTime() { + return chosenFormat.getBytesDuration( getQueuedByteCount() ); } @Override - public int getAvgFrameDuration() { - return 0; + public float getAvgFrameDuration() { + return 0f; } @Override diff --git a/src/java/jogamp/common/av/NullAudioSink.java b/src/java/jogamp/common/av/NullAudioSink.java index 58f4b0d..ca5e2f4 100644 --- a/src/java/jogamp/common/av/NullAudioSink.java +++ b/src/java/jogamp/common/av/NullAudioSink.java @@ -185,13 +185,13 @@ public class NullAudioSink implements AudioSink { } @Override - public int getQueuedTime() { - return 0; + public float getQueuedTime() { + return 0f; } @Override - public int getAvgFrameDuration() { - return 0; + public float getAvgFrameDuration() { + return 0f; } @Override -- cgit v1.2.3