kopia lustrzana https://github.com/jameshball/osci-render
Correctly drew a square
rodzic
505da0ddf1
commit
895c49b9f5
|
@ -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)) {
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue