diff options
author | Sven Gothel <[email protected]> | 2023-05-21 16:44:17 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-05-21 16:44:17 +0200 |
commit | 742cf0cd053f968cbf291ed367d4568c12d8bde2 (patch) | |
tree | 6036ad8cdabf04ebf90988eb81a466c39d6b7d9c /src/java/jogamp/common | |
parent | 5c33470aea6b30c81681992567d7c92e100bdab3 (diff) |
AudioFormat/AudioSink: Use float in seconds for duration to avoid losing precision when dealing with stats, averages etc
Diffstat (limited to 'src/java/jogamp/common')
-rw-r--r-- | src/java/jogamp/common/av/JavaSoundAudioSink.java | 14 | ||||
-rw-r--r-- | src/java/jogamp/common/av/NullAudioSink.java | 8 |
2 files changed, 9 insertions, 13 deletions
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 |