Correctly drew a square

pull/35/head
James Ball 2020-01-26 21:50:25 +00:00
rodzic 505da0ddf1
commit 895c49b9f5
2 zmienionych plików z 25 dodań i 9 usunięć

Wyświetl plik

@ -5,36 +5,48 @@ import java.util.List;
public class AudioPlayer extends Thread {
public static XtFormat FORMAT;
private static int count = 0;
private static volatile boolean stopped = false;
private static List<Line> lines = new ArrayList<>();
private static int currentLine = 0;
private static float FREQUENCY = 440;
private static int framesDrawn = 0;
static void render(XtStream stream, Object input, Object output, int frames,
double time, long position, boolean timeValid, long error, Object user) {
XtFormat format = stream.getFormat();
Line line = lines.get(count % lines.size());
int neg = line.getX1() < line.getX2() || line.getY1() < line.getY2() ? 1 : -1;
for (int f = 0; f < frames; f++) {
Line line = currentLine();
int framesToDraw = (int) (line.length() * 100);
int neg = line.getX1() < line.getX2() || line.getY1() < line.getY2() ? 1 : -1;
for (int c = 0; c < format.outputs; c++) {
((float[]) output)[f * format.outputs] = line.getX1() + Math.abs(line.getX2() - line.getX1()) * (float) (neg * f) / frames;
((float[]) output)[f * format.outputs + 1] = line.getY1() + Math.abs(line.getY2() - line.getY1()) * (float) (neg * f) / frames;
((float[]) output)[f * format.outputs] = line.getX1() + Math.abs(line.getX2() - line.getX1()) * (float) (neg * framesDrawn) / framesToDraw;
((float[]) output)[f * format.outputs + 1] = line.getY1() + Math.abs(line.getY2() - line.getY1()) * (float) (neg * framesDrawn) / framesToDraw;
}
framesDrawn++;
if (framesDrawn > framesToDraw) {
framesDrawn = 0;
currentLine++;
}
}
count++;
}
public static void addLine(Line line) {
AudioPlayer.lines.add(line);
}
private static Line currentLine() {
return lines.get(currentLine % lines.size());
}
@Override
public void run() {
try (XtAudio audio = new XtAudio(null, null, null, null)) {
XtService service = XtAudio.getServiceBySetup(XtSetup.CONSUMER_AUDIO);
try (XtDevice device = service.openDefaultDevice(true)) {
if (device != null && device.supportsFormat(FORMAT)) {

Wyświetl plik

@ -12,6 +12,10 @@ public class Line {
this.b = new Point(x2, y2);
}
public float length() {
return (float) Math.sqrt(Math.pow(getX1() - getX2(), 2) + Math.pow(getY1() - getY2(), 2));
}
public Point getA() {
return a;
}