kopia lustrzana https://github.com/jameshball/osci-render
Interesting rotation effect
rodzic
cfb32a065a
commit
9131c5618a
|
@ -1,8 +1,6 @@
|
|||
import com.xtaudio.xt.*;
|
||||
|
||||
public class AudioClient {
|
||||
private static double phase;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
int sampleRate = 192000;
|
||||
|
||||
|
@ -20,31 +18,9 @@ public class AudioClient {
|
|||
AudioPlayer.addLine(l3);
|
||||
AudioPlayer.addLine(l4);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
player.start();
|
||||
while (true) {
|
||||
if (System.currentTimeMillis() - startTime > 1) {
|
||||
float diff = nextSine(sampleRate, 100) / 1000f;
|
||||
|
||||
l1.setX1(l1.getX1() - diff);
|
||||
l1.setX2(l1.getX2() + diff);
|
||||
l2.setX1(l2.getX1() + diff);
|
||||
l2.setX2(l2.getX2() + diff);
|
||||
l3.setX1(l3.getX1() + diff);
|
||||
l3.setX2(l3.getX2() - diff);
|
||||
l4.setX1(l4.getX1() - diff);
|
||||
l4.setX2(l4.getX2() - diff);
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static float nextSine(double sampleRate, double frequency) {
|
||||
phase += frequency / sampleRate;
|
||||
if (phase >= 1.0)
|
||||
phase = -1.0;
|
||||
return (float) Math.sin(phase * Math.PI);
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ public class AudioPlayer extends Thread {
|
|||
private static int currentLine = 0;
|
||||
private static float FREQUENCY = 440;
|
||||
private static int framesDrawn = 0;
|
||||
private static double phase = 0;
|
||||
|
||||
static void render(XtStream stream, Object input, Object output, int frames,
|
||||
double time, long position, boolean timeValid, long error, Object user) {
|
||||
|
@ -17,6 +18,8 @@ public class AudioPlayer extends Thread {
|
|||
|
||||
for (int f = 0; f < frames; f++) {
|
||||
Line line = currentLine();
|
||||
line.rotate(nextTheta(stream.getFormat().mix.rate, 0.000001));
|
||||
|
||||
int framesToDraw = (int) (line.length() * 100);
|
||||
int neg = line.getX1() < line.getX2() || line.getY1() < line.getY2() ? 1 : -1;
|
||||
|
||||
|
@ -34,6 +37,13 @@ public class AudioPlayer extends Thread {
|
|||
}
|
||||
}
|
||||
|
||||
static float nextTheta(double sampleRate, double frequency) {
|
||||
phase += frequency / sampleRate;
|
||||
if (phase >= 1.0)
|
||||
phase = -1.0;
|
||||
return (float) (phase * Math.PI);
|
||||
}
|
||||
|
||||
public static void addLine(Line line) {
|
||||
AudioPlayer.lines.add(line);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,13 @@ public class Line {
|
|||
return (float) Math.sqrt(Math.pow(getX1() - getX2(), 2) + Math.pow(getY1() - getY2(), 2));
|
||||
}
|
||||
|
||||
public void rotate(double theta) {
|
||||
setX1((float) (getX1() * Math.cos(theta) - getY1() * Math.sin(theta)));
|
||||
setY1((float) (getX1() * Math.sin(theta) + getY1() * Math.cos(theta)));
|
||||
setX2((float) (getX2() * Math.cos(theta) - getY2() * Math.sin(theta)));
|
||||
setY2((float) (getX2() * Math.sin(theta) + getY2() * Math.cos(theta)));
|
||||
}
|
||||
|
||||
public Point getA() {
|
||||
return a;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue