From b7e6bee3deba4d79cab7d4d82288cf632907faf8 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 19 May 2023 07:47:19 +0200 Subject: AudioFormat: Fix rounding/int-truncate errors, all millisecond params use type int --- src/java/com/jogamp/common/av/AudioFormat.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/java/com/jogamp/common/av/AudioFormat.java b/src/java/com/jogamp/common/av/AudioFormat.java index db23021..de7824c 100644 --- a/src/java/com/jogamp/common/av/AudioFormat.java +++ b/src/java/com/jogamp/common/av/AudioFormat.java @@ -85,7 +85,7 @@ public class AudioFormat { */ public final int getDurationsByteSize(final int millisecs) { final int bytesPerSample = sampleSize >>> 3; // /8 - return millisecs * ( channelCount * bytesPerSample * ( sampleRate / 1000 ) ); + return Math.round( millisecs * ( (float)channelCount * (float)bytesPerSample * ( sampleRate / 1000f ) ) ); } /** @@ -97,22 +97,22 @@ public class AudioFormat { */ public final int getBytesDuration(final int byteCount) { final int bytesPerSample = sampleSize >>> 3; // /8 - return byteCount / ( channelCount * bytesPerSample * ( sampleRate / 1000 ) ); + return Math.round( byteCount / ( (float)channelCount * (float)bytesPerSample * ( sampleRate / 1000f ) ) ); } /** * Returns the duration in milliseconds of the given sample count per frame and channel * according to the {@link #sampleRate}, i.e. *
-     *    ( 1000f * sampleCount ) / sampleRate
+     *    round( ( 1000f * sampleCount ) / sampleRate )
      * 
*

* Sample Count -> Time *

* @param sampleCount sample count per frame and channel */ - public final float getSamplesDuration(final int sampleCount) { - return ( 1000f * sampleCount ) / sampleRate; + public final int getSamplesDuration(final int sampleCount) { + return Math.round( ( 1000f * sampleCount ) / sampleRate ); } /** @@ -130,8 +130,8 @@ public class AudioFormat { * @param millisecs time in milliseconds * @param frameDuration duration per frame in milliseconds. */ - public final int getFrameCount(final int millisecs, final float frameDuration) { - return Math.max(1, (int) ( millisecs / frameDuration + 0.5f )); + public final int getFrameCount(final int millisecs, final int frameDuration) { + return Math.max(1, (int) ( (float)millisecs / (float)frameDuration + 0.5f )); } /** -- cgit v1.2.3