Clean up recording code

pull/35/head
James Ball 2021-05-19 22:40:17 +01:00
rodzic daa0d04d57
commit 727f49ca76
1 zmienionych plików z 17 dodań i 13 usunięć

Wyświetl plik

@ -66,22 +66,14 @@ public class AudioPlayer implements Renderer<List<Shape>, AudioInputStream> {
double drawingProgress = totalAudioFrames == 0 ? 1 : audioFramesDrawn / totalAudioFrames;
Vector2 nextVector = applyEffects(f, shape.nextVector(drawingProgress));
float nextX = cutoff((float) nextVector.getX());
float nextY = cutoff((float) nextVector.getY());
float leftChannel = cutoff((float) nextVector.getX());
float rightChannel = cutoff((float) nextVector.getY());
output[f * format.channels.outputs] = nextX;
output[f * format.channels.outputs + 1] = nextY;
output[f * format.channels.outputs] = leftChannel;
output[f * format.channels.outputs + 1] = rightChannel;
if (recording) {
int left = (int)(nextX * Short.MAX_VALUE);
int right = (int)(nextY * Short.MAX_VALUE);
outputStream.write((byte) left);
outputStream.write((byte)(left >> 8));
outputStream.write((byte) right);
outputStream.write((byte)(right >> 8));
framesRecorded++;
writeVector(leftChannel, rightChannel);
}
audioFramesDrawn++;
@ -100,6 +92,18 @@ public class AudioPlayer implements Renderer<List<Shape>, AudioInputStream> {
return 0;
}
private void writeVector(float leftChannel, float rightChannel) {
int left = (int)(leftChannel * Short.MAX_VALUE);
int right = (int)(rightChannel * Short.MAX_VALUE);
outputStream.write((byte) left);
outputStream.write((byte)(left >> 8));
outputStream.write((byte) right);
outputStream.write((byte)(right >> 8));
framesRecorded++;
}
private float cutoff(float value) {
if (value < -1) {
return -1;