kopia lustrzana https://github.com/jameshball/osci-render
Further code clean-up
rodzic
b00734fb15
commit
9ce17334c3
|
@ -11,15 +11,15 @@ import shapes.Shapes;
|
||||||
import shapes.Vector2;
|
import shapes.Vector2;
|
||||||
|
|
||||||
public class AudioClient {
|
public class AudioClient {
|
||||||
public static final int SAMPLE_RATE = 192000;
|
|
||||||
public static final double TARGET_FRAMERATE = 30;
|
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 / 100;
|
||||||
private static final float ROTATE_SPEED = 0;
|
private static final float ROTATE_SPEED = 0;
|
||||||
private static final float TRANSLATION_SPEED = 0;
|
private static final float TRANSLATION_SPEED = 0;
|
||||||
private static final Vector2 TRANSLATION = new Vector2(1, 1);
|
private static final Vector2 TRANSLATION = new Vector2(1, 1);
|
||||||
private static final float SCALE = 2;
|
private static final float SCALE = 1;
|
||||||
private static final float WEIGHT = 100;
|
private static final float WEIGHT = 80;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO: Calculate weight of lines using depth.
|
// TODO: Calculate weight of lines using depth.
|
||||||
|
@ -53,6 +53,8 @@ public class AudioClient {
|
||||||
player.setRotateSpeed(ROTATE_SPEED);
|
player.setRotateSpeed(ROTATE_SPEED);
|
||||||
player.setTranslation(TRANSLATION_SPEED, TRANSLATION);
|
player.setTranslation(TRANSLATION_SPEED, TRANSLATION);
|
||||||
player.setScale(SCALE);
|
player.setScale(SCALE);
|
||||||
|
player.setWeight(WEIGHT);
|
||||||
|
|
||||||
player.start();
|
player.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,28 +8,28 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AudioPlayer extends Thread {
|
public class AudioPlayer extends Thread {
|
||||||
private static XtFormat FORMAT;
|
private final XtFormat FORMAT;
|
||||||
|
|
||||||
private static List<List<? extends Shape>> frames = new ArrayList<>();
|
private final List<List<? extends Shape>> frames;
|
||||||
private static int currentFrame = 0;
|
private int currentFrame = 0;
|
||||||
private static int currentShape = 0;
|
private int currentShape = 0;
|
||||||
private static long timeOfLastFrame;
|
private long timeOfLastFrame;
|
||||||
private static int audioFramesDrawn = 0;
|
private int audioFramesDrawn = 0;
|
||||||
|
|
||||||
private double translateSpeed = 0;
|
private double translateSpeed = 0;
|
||||||
private Vector2 translateVector = new Vector2();
|
private Vector2 translateVector = new Vector2();
|
||||||
private Phase translatePhase = new Phase();
|
private final Phase translatePhase = new Phase();
|
||||||
private double rotateSpeed = 0;
|
private double rotateSpeed = 0;
|
||||||
private Phase rotatePhase = new Phase();
|
private final Phase rotatePhase = new Phase();
|
||||||
private double scale = 1;
|
private double scale = 1;
|
||||||
private double weight = 100;
|
private double weight = 100;
|
||||||
|
|
||||||
private volatile boolean stopped;
|
private volatile boolean stopped;
|
||||||
|
|
||||||
public AudioPlayer(int sampleRate, List<List<? extends Shape>> frames) {
|
public AudioPlayer(int sampleRate, List<List<? extends Shape>> frames) {
|
||||||
AudioPlayer.FORMAT = new XtFormat(new XtMix(sampleRate, XtSample.FLOAT32), 0, 0, 2, 0);
|
this.FORMAT = new XtFormat(new XtMix(sampleRate, XtSample.FLOAT32), 0, 0, 2, 0);
|
||||||
AudioPlayer.frames = frames;
|
this.frames = frames;
|
||||||
AudioPlayer.timeOfLastFrame = System.currentTimeMillis();
|
this.timeOfLastFrame = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void render(XtStream stream, Object input, Object output, int audioFrames,
|
private void render(XtStream stream, Object input, Object output, int audioFrames,
|
||||||
|
@ -54,12 +54,12 @@ public class AudioPlayer extends Thread {
|
||||||
|
|
||||||
if (audioFramesDrawn > totalAudioFrames) {
|
if (audioFramesDrawn > totalAudioFrames) {
|
||||||
audioFramesDrawn = 0;
|
audioFramesDrawn = 0;
|
||||||
currentShape = ++currentShape % AudioPlayer.frames.get(currentFrame).size();
|
currentShape = ++currentShape % frames.get(currentFrame).size();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (System.currentTimeMillis() - timeOfLastFrame > (float) 1000 / AudioClient.TARGET_FRAMERATE) {
|
if (System.currentTimeMillis() - timeOfLastFrame > (float) 1000 / AudioClient.TARGET_FRAMERATE) {
|
||||||
currentShape = 0;
|
currentShape = 0;
|
||||||
currentFrame = ++currentFrame % AudioPlayer.frames.size();
|
currentFrame = ++currentFrame % frames.size();
|
||||||
timeOfLastFrame = System.currentTimeMillis();
|
timeOfLastFrame = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue