Further code clean-up

pull/35/head
James Ball 2020-10-01 12:30:09 +01:00
rodzic b00734fb15
commit 9ce17334c3
2 zmienionych plików z 19 dodań i 17 usunięć

Wyświetl plik

@ -11,15 +11,15 @@ import shapes.Shapes;
import shapes.Vector2;
public class AudioClient {
public static final int SAMPLE_RATE = 192000;
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 float ROTATE_SPEED = 0;
private static final float TRANSLATION_SPEED = 0;
private static final Vector2 TRANSLATION = new Vector2(1, 1);
private static final float SCALE = 2;
private static final float WEIGHT = 100;
private static final float SCALE = 1;
private static final float WEIGHT = 80;
public static void main(String[] args) {
// TODO: Calculate weight of lines using depth.
@ -42,7 +42,7 @@ public class AudioClient {
for (int i = 0; i < numFrames; i++) {
preRenderedFrames.add(new ArrayList<>());
}
IntStream.range(0, numFrames).parallel().forEach((frameNum) -> {
WorldObject clone = object.clone();
clone.rotate(rotation.scale(frameNum));
@ -53,6 +53,8 @@ public class AudioClient {
player.setRotateSpeed(ROTATE_SPEED);
player.setTranslation(TRANSLATION_SPEED, TRANSLATION);
player.setScale(SCALE);
player.setWeight(WEIGHT);
player.start();
}
}

Wyświetl plik

@ -8,28 +8,28 @@ import java.util.ArrayList;
import java.util.List;
public class AudioPlayer extends Thread {
private static XtFormat FORMAT;
private final XtFormat FORMAT;
private static List<List<? extends Shape>> frames = new ArrayList<>();
private static int currentFrame = 0;
private static int currentShape = 0;
private static long timeOfLastFrame;
private static int audioFramesDrawn = 0;
private final List<List<? extends Shape>> frames;
private int currentFrame = 0;
private int currentShape = 0;
private long timeOfLastFrame;
private int audioFramesDrawn = 0;
private double translateSpeed = 0;
private Vector2 translateVector = new Vector2();
private Phase translatePhase = new Phase();
private final Phase translatePhase = new Phase();
private double rotateSpeed = 0;
private Phase rotatePhase = new Phase();
private final Phase rotatePhase = new Phase();
private double scale = 1;
private double weight = 100;
private volatile boolean stopped;
public AudioPlayer(int sampleRate, List<List<? extends Shape>> frames) {
AudioPlayer.FORMAT = new XtFormat(new XtMix(sampleRate, XtSample.FLOAT32), 0, 0, 2, 0);
AudioPlayer.frames = frames;
AudioPlayer.timeOfLastFrame = System.currentTimeMillis();
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,
@ -54,12 +54,12 @@ public class AudioPlayer extends Thread {
if (audioFramesDrawn > totalAudioFrames) {
audioFramesDrawn = 0;
currentShape = ++currentShape % AudioPlayer.frames.get(currentFrame).size();
currentShape = ++currentShape % frames.get(currentFrame).size();
}
if (System.currentTimeMillis() - timeOfLastFrame > (float) 1000 / AudioClient.TARGET_FRAMERATE) {
currentShape = 0;
currentFrame = ++currentFrame % AudioPlayer.frames.size();
currentFrame = ++currentFrame % frames.size();
timeOfLastFrame = System.currentTimeMillis();
}
}