kopia lustrzana https://github.com/jameshball/osci-render
Further experimenting with interesting shapes
rodzic
121ac72307
commit
402fc909fc
|
@ -10,6 +10,11 @@ public class AudioClient {
|
||||||
player.start();
|
player.start();
|
||||||
while (true) {
|
while (true) {
|
||||||
float currentTime = System.nanoTime() - startTime;
|
float currentTime = System.nanoTime() - startTime;
|
||||||
|
|
||||||
|
if (currentTime > 100000) {
|
||||||
|
startTime = System.nanoTime();
|
||||||
|
}
|
||||||
|
AudioPlayer.setFrequency(0.1f);
|
||||||
AudioPlayer.drawLine(0, 0, 0.5f * (float) Math.sin(2 * Math.PI * (currentTime / 100000f)), 0.5f * (float) Math.cos(2 * Math.PI * (currentTime / 100000f)));
|
AudioPlayer.drawLine(0, 0, 0.5f * (float) Math.sin(2 * Math.PI * (currentTime / 100000f)), 0.5f * (float) Math.cos(2 * Math.PI * (currentTime / 100000f)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,12 @@ public class AudioPlayer extends Thread {
|
||||||
private static float count = 1;
|
private static float count = 1;
|
||||||
private static volatile boolean stopped = false;
|
private static volatile boolean stopped = false;
|
||||||
|
|
||||||
public static float x1;
|
private static float x1;
|
||||||
public static float y1;
|
private static float y1;
|
||||||
public static float x2;
|
private static float x2;
|
||||||
public static float y2;
|
private static float y2;
|
||||||
|
|
||||||
|
private static float FREQUENCY = 440f;
|
||||||
|
|
||||||
static void render(XtStream stream, Object input, Object output, int frames,
|
static void render(XtStream stream, Object input, Object output, int frames,
|
||||||
double time, long position, boolean timeValid, long error, Object user) {
|
double time, long position, boolean timeValid, long error, Object user) {
|
||||||
|
@ -18,15 +20,12 @@ public class AudioPlayer extends Thread {
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
for (int f = 0; f < frames; f++) {
|
for (int f = 0; f < frames; f++) {
|
||||||
float sine = nextSine(format.mix.rate, 440);
|
|
||||||
float cos = nextCos(format.mix.rate, 440);
|
|
||||||
|
|
||||||
for (int c = 0; c < format.outputs; c++) {
|
for (int c = 0; c < format.outputs; c++) {
|
||||||
float xMid = (x1 + x2) / 2f;
|
float xMid = (x1 + x2) / 2f;
|
||||||
float yMid = (y1 + y2) / 2f;
|
float yMid = (y1 + y2) / 2f;
|
||||||
|
|
||||||
((float[]) output)[f * format.outputs] = xMid + (Math.abs(x2 - x1) / 2f) * sine;
|
((float[]) output)[f * format.outputs] = xMid + (Math.abs(x2 - x1) / 2f) * nextSine(FREQUENCY);
|
||||||
((float[]) output)[f * format.outputs + 1] = yMid + (Math.abs(y2 - y1) / 2f) * sine;
|
((float[]) output)[f * format.outputs + 1] = yMid + (Math.abs(y2 - y1) / 2f) * nextSine(FREQUENCY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,15 +37,19 @@ public class AudioPlayer extends Thread {
|
||||||
AudioPlayer.y2 = y2;
|
AudioPlayer.y2 = y2;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static float nextSine(double sampleRate, double frequency) {
|
public static void setFrequency(float frequency) {
|
||||||
phase += frequency / sampleRate;
|
AudioPlayer.FREQUENCY = frequency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float nextSine(double frequency) {
|
||||||
|
phase += frequency / FORMAT.mix.rate;
|
||||||
if (phase >= 1.0)
|
if (phase >= 1.0)
|
||||||
phase = -1.0;
|
phase = -1.0;
|
||||||
return (float) Math.sin(phase * Math.PI);
|
return (float) Math.sin(phase * Math.PI);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static float nextCos(double sampleRate, double frequency) {
|
public static float nextCos(double frequency) {
|
||||||
phase += frequency / sampleRate;
|
phase += frequency / FORMAT.mix.rate;
|
||||||
if (phase >= 1.0)
|
if (phase >= 1.0)
|
||||||
phase = -1.0;
|
phase = -1.0;
|
||||||
return (float) Math.cos(phase * Math.PI);
|
return (float) Math.cos(phase * Math.PI);
|
||||||
|
|
Ładowanie…
Reference in New Issue