From ca9cf4c97bc99d313ddc6e4884fd6c5bfc51368c Mon Sep 17 00:00:00 2001 From: James Ball Date: Thu, 1 Oct 2020 13:41:32 +0100 Subject: [PATCH] Remove framerate cap for MUCH better performance --- .idea/osci-render.iml | 1 - src/audio/AudioClient.java | 6 ++---- src/audio/AudioPlayer.java | 9 ++++----- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.idea/osci-render.iml b/.idea/osci-render.iml index abe7be2..a37195d 100644 --- a/.idea/osci-render.iml +++ b/.idea/osci-render.iml @@ -5,7 +5,6 @@ - diff --git a/src/audio/AudioClient.java b/src/audio/AudioClient.java index 996e05e..9c8a010 100644 --- a/src/audio/AudioClient.java +++ b/src/audio/AudioClient.java @@ -11,10 +11,8 @@ import shapes.Shapes; import shapes.Vector2; public class AudioClient { - public static final double TARGET_FRAMERATE = 30; - private static final int SAMPLE_RATE = 192000; - private static final double OBJ_ROTATE = Math.PI / 100; + private static final double OBJ_ROTATE = Math.PI / 1000; private static final float ROTATE_SPEED = 0; private static final float TRANSLATION_SPEED = 0; private static final Vector2 TRANSLATION = new Vector2(1, 1); @@ -28,7 +26,7 @@ public class AudioClient { // Improve performance of line cleanup with a heuristic. String objFilePath = args[0]; - int numFrames = (int) (Float.parseFloat(args[1]) * TARGET_FRAMERATE); + int numFrames = Integer.parseInt(args[1]); float focalLength = Float.parseFloat(args[2]); float cameraX = Float.parseFloat(args[3]); float cameraY = Float.parseFloat(args[4]); diff --git a/src/audio/AudioPlayer.java b/src/audio/AudioPlayer.java index 7a61483..ac20d5a 100644 --- a/src/audio/AudioPlayer.java +++ b/src/audio/AudioPlayer.java @@ -1,6 +1,8 @@ package audio; import com.xtaudio.xt.*; +import java.time.Duration; +import java.time.Instant; import shapes.Shape; import shapes.Vector2; @@ -12,7 +14,6 @@ public class AudioPlayer extends Thread { private final List> frames; private int currentFrame = 0; private int currentShape = 0; - private long timeOfLastFrame; private int audioFramesDrawn = 0; private double translateSpeed = 0; @@ -28,7 +29,6 @@ public class AudioPlayer extends Thread { public AudioPlayer(int sampleRate, List> frames) { this.FORMAT = new XtFormat(new XtMix(sampleRate, XtSample.FLOAT32), 0, 0, 2, 0); this.frames = frames; - this.timeOfLastFrame = System.currentTimeMillis(); } private void render(XtStream stream, Object input, Object output, int audioFrames, @@ -53,13 +53,12 @@ public class AudioPlayer extends Thread { if (audioFramesDrawn > totalAudioFrames) { audioFramesDrawn = 0; - currentShape = ++currentShape % frames.get(currentFrame).size(); + currentShape++; } - if (System.currentTimeMillis() - timeOfLastFrame > (float) 1000 / AudioClient.TARGET_FRAMERATE) { + if (currentShape >= frames.get(currentFrame).size()) { currentShape = 0; currentFrame = ++currentFrame % frames.size(); - timeOfLastFrame = System.currentTimeMillis(); } } }