summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/av
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-05-19 07:47:19 +0200
committerSven Gothel <[email protected]>2023-05-19 07:47:19 +0200
commitb7e6bee3deba4d79cab7d4d82288cf632907faf8 (patch)
treebc63f5f2291771b833c4e2e8cf97c75e58f9b009 /src/java/com/jogamp/common/av
parent2b339721a4d6dd4f3af129a4654375b15c7ea340 (diff)
AudioFormat: Fix rounding/int-truncate errors, all millisecond params use type int
Diffstat (limited to 'src/java/com/jogamp/common/av')
-rw-r--r--src/java/com/jogamp/common/av/AudioFormat.java14
1 files 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.
* <pre>
- * ( 1000f * sampleCount ) / sampleRate
+ * round( ( 1000f * sampleCount ) / sampleRate )
* </pre>
* <p>
* Sample Count -> Time
* </p>
* @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 ));
}
/**