kopia lustrzana https://github.com/jameshball/osci-render
Added adaptive weights
rodzic
50113368f9
commit
208bbecf13
|
@ -3,15 +3,17 @@ package audio;
|
||||||
import engine.Camera;
|
import engine.Camera;
|
||||||
import engine.Vector3;
|
import engine.Vector3;
|
||||||
import engine.WorldObject;
|
import engine.WorldObject;
|
||||||
|
import shapes.Shape;
|
||||||
import shapes.Shapes;
|
import shapes.Shapes;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class AudioClient {
|
public class AudioClient {
|
||||||
private static final int SAMPLE_RATE = 192000;
|
private static final int SAMPLE_RATE = 192000;
|
||||||
private static final double FRAMERATE = 30;
|
private static final double FRAMERATE = 30;
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
// TODO: Implement adaptive default weight (i.e. the more things drawn, the lower the weight of lines)
|
// TODO: Calculate weight of lines using depth.
|
||||||
// Calculate weight of lines using depth.
|
|
||||||
// Reduce weight of lines drawn multiple times.
|
// Reduce weight of lines drawn multiple times.
|
||||||
// Find intersections of lines to (possibly) improve line cleanup.
|
// Find intersections of lines to (possibly) improve line cleanup.
|
||||||
// Improve performance of line cleanup with a heuristic.
|
// Improve performance of line cleanup with a heuristic.
|
||||||
|
|
|
@ -2,6 +2,7 @@ package audio;
|
||||||
|
|
||||||
import com.xtaudio.xt.*;
|
import com.xtaudio.xt.*;
|
||||||
import shapes.Shape;
|
import shapes.Shape;
|
||||||
|
import shapes.Shapes;
|
||||||
import shapes.Vector2;
|
import shapes.Vector2;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -24,6 +25,7 @@ public class AudioPlayer extends Thread {
|
||||||
private static double ROTATE_SPEED = 0;
|
private static double ROTATE_SPEED = 0;
|
||||||
private static final int ROTATE_PHASE_INDEX = 1;
|
private static final int ROTATE_PHASE_INDEX = 1;
|
||||||
private static double SCALE = 1;
|
private static double SCALE = 1;
|
||||||
|
private static double WEIGHT = 100;
|
||||||
|
|
||||||
private boolean stopped;
|
private boolean stopped;
|
||||||
|
|
||||||
|
@ -37,6 +39,7 @@ public class AudioPlayer extends Thread {
|
||||||
for (int f = 0; f < frames; f++) {
|
for (int f = 0; f < frames; f++) {
|
||||||
Shape shape = getCurrentShape();
|
Shape shape = getCurrentShape();
|
||||||
|
|
||||||
|
shape = shape.setWeight(WEIGHT);
|
||||||
shape = scale(shape);
|
shape = scale(shape);
|
||||||
shape = rotate(shape, FORMAT.mix.rate);
|
shape = rotate(shape, FORMAT.mix.rate);
|
||||||
shape = translate(shape, FORMAT.mix.rate);
|
shape = translate(shape, FORMAT.mix.rate);
|
||||||
|
@ -123,6 +126,7 @@ public class AudioPlayer extends Thread {
|
||||||
currentShape = 0;
|
currentShape = 0;
|
||||||
shapes = new ArrayList<>();
|
shapes = new ArrayList<>();
|
||||||
shapes.addAll(frame);
|
shapes.addAll(frame);
|
||||||
|
AudioPlayer.WEIGHT = 200 * Math.exp(-0.017 * Shapes.totalLength(frame));
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,4 +56,9 @@ public class Ellipse extends Shape {
|
||||||
public Ellipse translate(Vector2 vector) {
|
public Ellipse translate(Vector2 vector) {
|
||||||
return new Ellipse(a, b, weight, rotation, position.translate(vector));
|
return new Ellipse(a, b, weight, rotation, position.translate(vector));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Ellipse setWeight(double weight) {
|
||||||
|
return new Ellipse(a, b, weight, rotation, position);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,7 @@ public class Line extends Shape {
|
||||||
return new Line(getX1(), getY1(), getX2(), y2);
|
return new Line(getX1(), getY1(), getX2(), y2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Line setWeight(double weight) {
|
public Line setWeight(double weight) {
|
||||||
return new Line(getX1(), getY1(), getX2(), getY2(), weight);
|
return new Line(getX1(), getY1(), getX2(), getY2(), weight);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package shapes;
|
package shapes;
|
||||||
|
|
||||||
public abstract class Shape {
|
public abstract class Shape {
|
||||||
public static final int DEFAULT_WEIGHT = 80;
|
public static final int DEFAULT_WEIGHT = 1;
|
||||||
|
|
||||||
protected double weight;
|
protected double weight;
|
||||||
protected double length;
|
protected double length;
|
||||||
|
@ -11,6 +11,7 @@ public abstract class Shape {
|
||||||
public abstract Shape rotate(double theta);
|
public abstract Shape rotate(double theta);
|
||||||
public abstract Shape scale(double factor);
|
public abstract Shape scale(double factor);
|
||||||
public abstract Shape translate(Vector2 vector);
|
public abstract Shape translate(Vector2 vector);
|
||||||
|
public abstract Shape setWeight(double weight);
|
||||||
|
|
||||||
public double getWeight() {
|
public double getWeight() {
|
||||||
return weight;
|
return weight;
|
||||||
|
|
|
@ -57,6 +57,14 @@ public class Shapes {
|
||||||
return generatePolygon(sides, new Vector2(scale, scale));
|
return generatePolygon(sides, new Vector2(scale, scale));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static double totalLength(List<Shape> shapes) {
|
||||||
|
return shapes
|
||||||
|
.stream()
|
||||||
|
.map(Shape::getLength)
|
||||||
|
.reduce(Double::sum)
|
||||||
|
.orElse(0d);
|
||||||
|
}
|
||||||
|
|
||||||
public static List<Shape> sortLines(List<Line> lines) {
|
public static List<Shape> sortLines(List<Line> lines) {
|
||||||
Graph<Vector2, DefaultWeightedEdge> graph = new DefaultUndirectedWeightedGraph<>(DefaultWeightedEdge.class);
|
Graph<Vector2, DefaultWeightedEdge> graph = new DefaultUndirectedWeightedGraph<>(DefaultWeightedEdge.class);
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,14 @@ public class Vector2 extends Shape{
|
||||||
|
|
||||||
private static final double EPSILON = 0.001;
|
private static final double EPSILON = 0.001;
|
||||||
|
|
||||||
public Vector2(double x, double y) {
|
public Vector2(double x, double y, double weight) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.weight = Shape.DEFAULT_WEIGHT;
|
this.weight = weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector2(double x, double y) {
|
||||||
|
this(x, y, Shape.DEFAULT_WEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2() {
|
public Vector2() {
|
||||||
|
@ -66,6 +70,11 @@ public class Vector2 extends Shape{
|
||||||
return new Vector2(getX() + vector.getX(), getY() + vector.getY());
|
return new Vector2(getX() + vector.getX(), getY() + vector.getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vector2 setWeight(double weight) {
|
||||||
|
return new Vector2(x, y, weight);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
|
|
Ładowanie…
Reference in New Issue