From 3eda3a44ef7134b1a84efe9d4d7f1be0a0aadd05 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Fri, 19 Apr 2024 20:36:50 +0200 Subject: [PATCH] prepare for PD modes, which give us two lines per sync pulse --- app/src/main/java/xdsopl/robot36/Decoder.java | 27 ++++++++++++------- app/src/main/java/xdsopl/robot36/Martin.java | 12 ++++----- app/src/main/java/xdsopl/robot36/Mode.java | 2 +- app/src/main/java/xdsopl/robot36/PaulDon.java | 12 ++++----- app/src/main/java/xdsopl/robot36/Raw.java | 12 ++++----- .../java/xdsopl/robot36/Robot_36_Color.java | 12 ++++----- .../java/xdsopl/robot36/Robot_72_Color.java | 12 ++++----- app/src/main/java/xdsopl/robot36/Scottie.java | 12 ++++----- .../java/xdsopl/robot36/Wraase_SC2_180.java | 12 ++++----- 9 files changed, 60 insertions(+), 53 deletions(-) diff --git a/app/src/main/java/xdsopl/robot36/Decoder.java b/app/src/main/java/xdsopl/robot36/Decoder.java index f03eae7..09abe39 100644 --- a/app/src/main/java/xdsopl/robot36/Decoder.java +++ b/app/src/main/java/xdsopl/robot36/Decoder.java @@ -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 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); diff --git a/app/src/main/java/xdsopl/robot36/Martin.java b/app/src/main/java/xdsopl/robot36/Martin.java index b8de05e..13eecd0 100644 --- a/app/src/main/java/xdsopl/robot36/Martin.java +++ b/app/src/main/java/xdsopl/robot36/Martin.java @@ -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; } } diff --git a/app/src/main/java/xdsopl/robot36/Mode.java b/app/src/main/java/xdsopl/robot36/Mode.java index d726b50..3df04d6 100644 --- a/app/src/main/java/xdsopl/robot36/Mode.java +++ b/app/src/main/java/xdsopl/robot36/Mode.java @@ -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); } diff --git a/app/src/main/java/xdsopl/robot36/PaulDon.java b/app/src/main/java/xdsopl/robot36/PaulDon.java index a25e02d..3863e05 100644 --- a/app/src/main/java/xdsopl/robot36/PaulDon.java +++ b/app/src/main/java/xdsopl/robot36/PaulDon.java @@ -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; } } diff --git a/app/src/main/java/xdsopl/robot36/Raw.java b/app/src/main/java/xdsopl/robot36/Raw.java index c5a03df..fa3c6a6 100644 --- a/app/src/main/java/xdsopl/robot36/Raw.java +++ b/app/src/main/java/xdsopl/robot36/Raw.java @@ -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; } } diff --git a/app/src/main/java/xdsopl/robot36/Robot_36_Color.java b/app/src/main/java/xdsopl/robot36/Robot_36_Color.java index 9bd91f2..3ea3437 100644 --- a/app/src/main/java/xdsopl/robot36/Robot_36_Color.java +++ b/app/src/main/java/xdsopl/robot36/Robot_36_Color.java @@ -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; } } diff --git a/app/src/main/java/xdsopl/robot36/Robot_72_Color.java b/app/src/main/java/xdsopl/robot36/Robot_72_Color.java index 303a1fe..14d9049 100644 --- a/app/src/main/java/xdsopl/robot36/Robot_72_Color.java +++ b/app/src/main/java/xdsopl/robot36/Robot_72_Color.java @@ -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; } } diff --git a/app/src/main/java/xdsopl/robot36/Scottie.java b/app/src/main/java/xdsopl/robot36/Scottie.java index 05b9730..839d162 100644 --- a/app/src/main/java/xdsopl/robot36/Scottie.java +++ b/app/src/main/java/xdsopl/robot36/Scottie.java @@ -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; } } diff --git a/app/src/main/java/xdsopl/robot36/Wraase_SC2_180.java b/app/src/main/java/xdsopl/robot36/Wraase_SC2_180.java index e4a90e1..ff5556b 100644 --- a/app/src/main/java/xdsopl/robot36/Wraase_SC2_180.java +++ b/app/src/main/java/xdsopl/robot36/Wraase_SC2_180.java @@ -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; } }