kopia lustrzana https://github.com/xdsopl/robot36
prepare for PD modes, which give us two lines per sync pulse
rodzic
e18988f76a
commit
3eda3a44ef
|
@ -12,7 +12,8 @@ public class Decoder {
|
|||
|
||||
private final Demodulator demodulator;
|
||||
private final float[] scanLineBuffer;
|
||||
private final int[] pixelBuffer;
|
||||
private final int[] evenBuffer;
|
||||
private final int[] oddBuffer;
|
||||
private final int[] scopePixels;
|
||||
private final int[] last5msSyncPulses;
|
||||
private final int[] last9msSyncPulses;
|
||||
|
@ -36,7 +37,8 @@ public class Decoder {
|
|||
this.scopePixels = scopePixels;
|
||||
this.scopeWidth = scopeWidth;
|
||||
this.scopeHeight = scopeHeight;
|
||||
pixelBuffer = new int[scopeWidth];
|
||||
evenBuffer = new int[scopeWidth];
|
||||
oddBuffer = new int[scopeWidth];
|
||||
demodulator = new Demodulator(sampleRate);
|
||||
double scanLineMaxSeconds = 5;
|
||||
int scanLineMaxSamples = (int) Math.round(scanLineMaxSeconds * sampleRate);
|
||||
|
@ -107,10 +109,17 @@ public class Decoder {
|
|||
return bestMode;
|
||||
}
|
||||
|
||||
private void slideOneLine() {
|
||||
System.arraycopy(pixelBuffer, 0, scopePixels, scopeWidth * curLine, scopeWidth);
|
||||
System.arraycopy(pixelBuffer, 0, scopePixels, scopeWidth * (curLine + scopeHeight), scopeWidth);
|
||||
curLine = (curLine + 1) % scopeHeight;
|
||||
private void copyLines(int lines) {
|
||||
if (lines > 0) {
|
||||
System.arraycopy(evenBuffer, 0, scopePixels, scopeWidth * curLine, scopeWidth);
|
||||
System.arraycopy(evenBuffer, 0, scopePixels, scopeWidth * (curLine + scopeHeight), scopeWidth);
|
||||
curLine = (curLine + 1) % scopeHeight;
|
||||
}
|
||||
if (lines == 2) {
|
||||
System.arraycopy(oddBuffer, 0, scopePixels, scopeWidth * curLine, scopeWidth);
|
||||
System.arraycopy(oddBuffer, 0, scopePixels, scopeWidth * (curLine + scopeHeight), scopeWidth);
|
||||
curLine = (curLine + 1) % scopeHeight;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean processSyncPulse(ArrayList<Mode> modes, int[] pulses, int[] lines, int index) {
|
||||
|
@ -132,12 +141,10 @@ public class Decoder {
|
|||
int extrapolate = endPulse / meanSamples;
|
||||
int firstPulse = endPulse - extrapolate * meanSamples;
|
||||
for (int pulseIndex = firstPulse; pulseIndex < endPulse; pulseIndex += meanSamples)
|
||||
if (mode.decodeScanLine(pixelBuffer, scanLineBuffer, pulseIndex, meanSamples))
|
||||
slideOneLine();
|
||||
copyLines(mode.decodeScanLine(evenBuffer, oddBuffer, scanLineBuffer, pulseIndex, meanSamples));
|
||||
}
|
||||
for (int i = 0; i < lines.length; ++i)
|
||||
if (mode.decodeScanLine(pixelBuffer, scanLineBuffer, pulses[i], lines[i]))
|
||||
slideOneLine();
|
||||
copyLines(mode.decodeScanLine(evenBuffer, oddBuffer, scanLineBuffer, pulses[i], lines[i]));
|
||||
int shift = pulses[pulses.length - 1];
|
||||
adjustSyncPulses(last5msSyncPulses, shift);
|
||||
adjustSyncPulses(last9msSyncPulses, shift);
|
||||
|
|
|
@ -45,11 +45,11 @@ public class Martin implements Mode {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean decodeScanLine(int[] pixelBuffer, float[] scanLineBuffer, int prevPulseIndex, int ignore) {
|
||||
public int decodeScanLine(int[] evenBuffer, int[] oddBuffer, float[] scanLineBuffer, int prevPulseIndex, int ignore) {
|
||||
if (prevPulseIndex + greenBeginSamples < 0 || prevPulseIndex + redEndSamples > scanLineBuffer.length)
|
||||
return false;
|
||||
for (int i = 0; i < pixelBuffer.length; ++i) {
|
||||
int position = (i * channelSamples) / pixelBuffer.length + prevPulseIndex;
|
||||
return 0;
|
||||
for (int i = 0; i < evenBuffer.length; ++i) {
|
||||
int position = (i * channelSamples) / evenBuffer.length + prevPulseIndex;
|
||||
int greenPos = position + greenBeginSamples;
|
||||
int bluePos = position + blueBeginSamples;
|
||||
int redPos = position + redBeginSamples;
|
||||
|
@ -57,8 +57,8 @@ public class Martin implements Mode {
|
|||
int blue = Math.round(255 * scanLineBuffer[bluePos]);
|
||||
int red = Math.round(255 * scanLineBuffer[redPos]);
|
||||
int pixelColor = 0xff000000 | (red << 16) | (green << 8) | blue;
|
||||
pixelBuffer[i] = pixelColor;
|
||||
evenBuffer[i] = pixelColor;
|
||||
}
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,5 +11,5 @@ public interface Mode {
|
|||
|
||||
int getScanLineSamples();
|
||||
|
||||
boolean decodeScanLine(int[] pixelBuffer, float[] scanLineBuffer, int prevPulseIndex, int scanLineSamples);
|
||||
int decodeScanLine(int[] evenBuffer, int[] oddBuffer, float[] scanLineBuffer, int prevPulseIndex, int scanLineSamples);
|
||||
}
|
||||
|
|
|
@ -29,15 +29,15 @@ public class PaulDon implements Mode {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean decodeScanLine(int[] pixelBuffer, float[] scanLineBuffer, int prevPulseIndex, int scanLineSamples) {
|
||||
public int decodeScanLine(int[] evenBuffer, int[] oddBuffer, float[] scanLineBuffer, int prevPulseIndex, int scanLineSamples) {
|
||||
if (prevPulseIndex < 0 || prevPulseIndex + scanLineSamples >= scanLineBuffer.length)
|
||||
return false;
|
||||
for (int i = 0; i < pixelBuffer.length; ++i) {
|
||||
int position = (i * scanLineSamples) / pixelBuffer.length + prevPulseIndex;
|
||||
return 0;
|
||||
for (int i = 0; i < evenBuffer.length; ++i) {
|
||||
int position = (i * scanLineSamples) / evenBuffer.length + prevPulseIndex;
|
||||
int intensity = (int) Math.round(255 * Math.sqrt(scanLineBuffer[position]));
|
||||
int pixelColor = 0xff000000 | 0x00010101 * intensity;
|
||||
pixelBuffer[i] = pixelColor;
|
||||
evenBuffer[i] = pixelColor;
|
||||
}
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,15 +22,15 @@ public class Raw implements Mode {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean decodeScanLine(int[] pixelBuffer, float[] scanLineBuffer, int prevPulseIndex, int scanLineSamples) {
|
||||
public int decodeScanLine(int[] evenBuffer, int[] oddBuffer, float[] scanLineBuffer, int prevPulseIndex, int scanLineSamples) {
|
||||
if (prevPulseIndex < 0 || prevPulseIndex + scanLineSamples >= scanLineBuffer.length)
|
||||
return false;
|
||||
for (int i = 0; i < pixelBuffer.length; ++i) {
|
||||
int position = (i * scanLineSamples) / pixelBuffer.length + prevPulseIndex;
|
||||
return 0;
|
||||
for (int i = 0; i < evenBuffer.length; ++i) {
|
||||
int position = (i * scanLineSamples) / evenBuffer.length + prevPulseIndex;
|
||||
int intensity = (int) Math.round(255 * Math.sqrt(scanLineBuffer[position]));
|
||||
int pixelColor = 0xff000000 | 0x00010101 * intensity;
|
||||
pixelBuffer[i] = pixelColor;
|
||||
evenBuffer[i] = pixelColor;
|
||||
}
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,15 +31,15 @@ public class Robot_36_Color implements Mode {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean decodeScanLine(int[] pixelBuffer, float[] scanLineBuffer, int prevPulseIndex, int scanLineSamples) {
|
||||
public int decodeScanLine(int[] evenBuffer, int[] oddBuffer, float[] scanLineBuffer, int prevPulseIndex, int scanLineSamples) {
|
||||
if (prevPulseIndex < 0 || prevPulseIndex + scanLineSamples >= scanLineBuffer.length)
|
||||
return false;
|
||||
for (int i = 0; i < pixelBuffer.length; ++i) {
|
||||
int position = (i * scanLineSamples) / pixelBuffer.length + prevPulseIndex;
|
||||
return 0;
|
||||
for (int i = 0; i < evenBuffer.length; ++i) {
|
||||
int position = (i * scanLineSamples) / evenBuffer.length + prevPulseIndex;
|
||||
int intensity = (int) Math.round(255 * Math.sqrt(scanLineBuffer[position]));
|
||||
int pixelColor = 0xff000000 | 0x00010101 * intensity;
|
||||
pixelBuffer[i] = pixelColor;
|
||||
evenBuffer[i] = pixelColor;
|
||||
}
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,15 +31,15 @@ public class Robot_72_Color implements Mode {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean decodeScanLine(int[] pixelBuffer, float[] scanLineBuffer, int prevPulseIndex, int scanLineSamples) {
|
||||
public int decodeScanLine(int[] evenBuffer, int[] oddBuffer, float[] scanLineBuffer, int prevPulseIndex, int scanLineSamples) {
|
||||
if (prevPulseIndex < 0 || prevPulseIndex + scanLineSamples >= scanLineBuffer.length)
|
||||
return false;
|
||||
for (int i = 0; i < pixelBuffer.length; ++i) {
|
||||
int position = (i * scanLineSamples) / pixelBuffer.length + prevPulseIndex;
|
||||
return 0;
|
||||
for (int i = 0; i < evenBuffer.length; ++i) {
|
||||
int position = (i * scanLineSamples) / evenBuffer.length + prevPulseIndex;
|
||||
int intensity = (int) Math.round(255 * Math.sqrt(scanLineBuffer[position]));
|
||||
int pixelColor = 0xff000000 | 0x00010101 * intensity;
|
||||
pixelBuffer[i] = pixelColor;
|
||||
evenBuffer[i] = pixelColor;
|
||||
}
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,15 +29,15 @@ public class Scottie implements Mode {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean decodeScanLine(int[] pixelBuffer, float[] scanLineBuffer, int prevPulseIndex, int scanLineSamples) {
|
||||
public int decodeScanLine(int[] evenBuffer, int[] oddBuffer, float[] scanLineBuffer, int prevPulseIndex, int scanLineSamples) {
|
||||
if (prevPulseIndex < 0 || prevPulseIndex + scanLineSamples >= scanLineBuffer.length)
|
||||
return false;
|
||||
for (int i = 0; i < pixelBuffer.length; ++i) {
|
||||
int position = (i * scanLineSamples) / pixelBuffer.length + prevPulseIndex;
|
||||
return 0;
|
||||
for (int i = 0; i < evenBuffer.length; ++i) {
|
||||
int position = (i * scanLineSamples) / evenBuffer.length + prevPulseIndex;
|
||||
int intensity = (int) Math.round(255 * Math.sqrt(scanLineBuffer[position]));
|
||||
int pixelColor = 0xff000000 | 0x00010101 * intensity;
|
||||
pixelBuffer[i] = pixelColor;
|
||||
evenBuffer[i] = pixelColor;
|
||||
}
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,11 +42,11 @@ public class Wraase_SC2_180 implements Mode {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean decodeScanLine(int[] pixelBuffer, float[] scanLineBuffer, int prevPulseIndex, int ignore) {
|
||||
public int decodeScanLine(int[] evenBuffer, int[] oddBuffer, float[] scanLineBuffer, int prevPulseIndex, int ignore) {
|
||||
if (prevPulseIndex + redBeginSamples < 0 || prevPulseIndex + blueEndSamples > scanLineBuffer.length)
|
||||
return false;
|
||||
for (int i = 0; i < pixelBuffer.length; ++i) {
|
||||
int position = (i * channelSamples) / pixelBuffer.length + prevPulseIndex;
|
||||
return 0;
|
||||
for (int i = 0; i < evenBuffer.length; ++i) {
|
||||
int position = (i * channelSamples) / evenBuffer.length + prevPulseIndex;
|
||||
int redPos = position + redBeginSamples;
|
||||
int greenPos = position + greenBeginSamples;
|
||||
int bluePos = position + blueBeginSamples;
|
||||
|
@ -54,8 +54,8 @@ public class Wraase_SC2_180 implements Mode {
|
|||
int green = Math.round(255 * scanLineBuffer[greenPos]);
|
||||
int blue = Math.round(255 * scanLineBuffer[bluePos]);
|
||||
int pixelColor = 0xff000000 | (red << 16) | (green << 8) | blue;
|
||||
pixelBuffer[i] = pixelColor;
|
||||
evenBuffer[i] = pixelColor;
|
||||
}
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue