diff --git a/app/src/main/java/xdsopl/robot36/Decoder.java b/app/src/main/java/xdsopl/robot36/Decoder.java index c5ec49e..c7ed696 100644 --- a/app/src/main/java/xdsopl/robot36/Decoder.java +++ b/app/src/main/java/xdsopl/robot36/Decoder.java @@ -53,17 +53,17 @@ public class Decoder { last20msSyncPulses = new int[syncPulseCount]; double scanLineToleranceSeconds = 0.001; scanLineToleranceSamples = (int) Math.round(scanLineToleranceSeconds * sampleRate); - rawMode = new Raw(); + rawMode = new RawDecoder(); syncPulse5msModes = new ArrayList<>(); - syncPulse5msModes.add(new Wraase_SC2_180(sampleRate)); - syncPulse5msModes.add(new Martin("1", 0.146432, sampleRate)); - syncPulse5msModes.add(new Martin("2", 0.073216, sampleRate)); + syncPulse5msModes.add(RGBModes.Wraase_SC2_180(sampleRate)); + syncPulse5msModes.add(RGBModes.Martin("1", 0.146432, sampleRate)); + syncPulse5msModes.add(RGBModes.Martin("2", 0.073216, sampleRate)); syncPulse9msModes = new ArrayList<>(); syncPulse9msModes.add(new Robot_36_Color(sampleRate)); syncPulse9msModes.add(new Robot_72_Color(sampleRate)); - syncPulse9msModes.add(new Scottie("1", 0.138240, sampleRate)); - syncPulse9msModes.add(new Scottie("2", 0.088064, sampleRate)); - syncPulse9msModes.add(new Scottie("DX", 0.3456, sampleRate)); + syncPulse9msModes.add(RGBModes.Scottie("1", 0.138240, sampleRate)); + syncPulse9msModes.add(RGBModes.Scottie("2", 0.088064, sampleRate)); + syncPulse9msModes.add(RGBModes.Scottie("DX", 0.3456, sampleRate)); syncPulse20msModes = new ArrayList<>(); syncPulse20msModes.add(new PaulDon("50", 0.09152, sampleRate)); syncPulse20msModes.add(new PaulDon("90", 0.17024, sampleRate)); diff --git a/app/src/main/java/xdsopl/robot36/Martin.java b/app/src/main/java/xdsopl/robot36/Martin.java deleted file mode 100644 index 8c7bf52..0000000 --- a/app/src/main/java/xdsopl/robot36/Martin.java +++ /dev/null @@ -1,60 +0,0 @@ -/* -Martin modes - -Copyright 2024 Ahmet Inan -*/ - -package xdsopl.robot36; - -public class Martin implements Mode { - private final int scanLineSamples; - private final int channelSamples; - private final int greenBeginSamples; - private final int blueBeginSamples; - private final int redBeginSamples; - private final int redEndSamples; - private final String name; - - Martin(String name, double channelSeconds, int sampleRate) { - this.name = "Martin " + name; - double syncPulseSeconds = 0.004862; - double separatorSeconds = 0.000572; - double scanLineSeconds = syncPulseSeconds + separatorSeconds + 3 * (channelSeconds + separatorSeconds); - scanLineSamples = (int) Math.round(scanLineSeconds * sampleRate); - channelSamples = (int) Math.round(channelSeconds * sampleRate); - double greenBeginSeconds = syncPulseSeconds / 2 + separatorSeconds; - greenBeginSamples = (int) Math.round(greenBeginSeconds * sampleRate); - double greenEndSeconds = greenBeginSeconds + channelSeconds; - double blueBeginSeconds = greenEndSeconds + separatorSeconds; - blueBeginSamples = (int) Math.round(blueBeginSeconds * sampleRate); - double blueEndSeconds = blueBeginSeconds + channelSeconds; - double redBeginSeconds = blueEndSeconds + separatorSeconds; - redBeginSamples = (int) Math.round(redBeginSeconds * sampleRate); - double redEndSeconds = redBeginSeconds + channelSeconds; - redEndSamples = (int) Math.round(redEndSeconds * sampleRate); - } - - @Override - public String getName() { - return name; - } - - @Override - public int getScanLineSamples() { - return scanLineSamples; - } - - @Override - public int decodeScanLine(int[] evenBuffer, int[] oddBuffer, float[] scanLineBuffer, int prevPulseIndex, int scanLineSamples) { - if (prevPulseIndex + greenBeginSamples < 0 || prevPulseIndex + redEndSamples > scanLineBuffer.length) - 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; - evenBuffer[i] = ColorConverter.RGB(scanLineBuffer[redPos], scanLineBuffer[greenPos], scanLineBuffer[bluePos]); - } - return 1; - } -} diff --git a/app/src/main/java/xdsopl/robot36/RGBDecoder.java b/app/src/main/java/xdsopl/robot36/RGBDecoder.java new file mode 100644 index 0000000..cf384b4 --- /dev/null +++ b/app/src/main/java/xdsopl/robot36/RGBDecoder.java @@ -0,0 +1,56 @@ +/* +Decoder for RGB modes + +Copyright 2024 Ahmet Inan +*/ + +package xdsopl.robot36; + +public class RGBDecoder implements Mode { + private final int scanLineSamples; + private final int beginSamples; + private final int redBeginSamples; + private final int redSamples; + private final int greenBeginSamples; + private final int greenSamples; + private final int blueBeginSamples; + private final int blueSamples; + private final int endSamples; + private final String name; + + RGBDecoder(String name, double scanLineSeconds, double beginSeconds, double redBeginSeconds, double redEndSeconds, double greenBeginSeconds, double greenEndSeconds, double blueBeginSeconds, double blueEndSeconds, double endSeconds, int sampleRate) { + this.name = name; + scanLineSamples = (int) Math.round(scanLineSeconds * sampleRate); + beginSamples = (int) Math.round(beginSeconds * sampleRate); + redBeginSamples = (int) Math.round(redBeginSeconds * sampleRate); + redSamples = (int) Math.round((redEndSeconds - redBeginSeconds) * sampleRate); + greenBeginSamples = (int) Math.round(greenBeginSeconds * sampleRate); + greenSamples = (int) Math.round((greenEndSeconds - greenBeginSeconds) * sampleRate); + blueBeginSamples = (int) Math.round(blueBeginSeconds * sampleRate); + blueSamples = (int) Math.round((blueEndSeconds - blueBeginSeconds) * sampleRate); + endSamples = (int) Math.round(endSeconds * sampleRate); + } + + @Override + public String getName() { + return name; + } + + @Override + public int getScanLineSamples() { + return scanLineSamples; + } + + @Override + public int decodeScanLine(int[] evenBuffer, int[] oddBuffer, float[] scanLineBuffer, int prevPulseIndex, int scanLineSamples) { + if (prevPulseIndex + beginSamples < 0 || prevPulseIndex + endSamples > scanLineBuffer.length) + return 0; + for (int i = 0; i < evenBuffer.length; ++i) { + int redPos = redBeginSamples + (i * redSamples) / evenBuffer.length + prevPulseIndex; + int greenPos = greenBeginSamples + (i * greenSamples) / evenBuffer.length + prevPulseIndex; + int bluePos = blueBeginSamples + (i * blueSamples) / evenBuffer.length + prevPulseIndex; + evenBuffer[i] = ColorConverter.RGB(scanLineBuffer[redPos], scanLineBuffer[greenPos], scanLineBuffer[bluePos]); + } + return 1; + } +} diff --git a/app/src/main/java/xdsopl/robot36/RGBModes.java b/app/src/main/java/xdsopl/robot36/RGBModes.java new file mode 100644 index 0000000..4fe3380 --- /dev/null +++ b/app/src/main/java/xdsopl/robot36/RGBModes.java @@ -0,0 +1,50 @@ +/* +RGB modes + +Copyright 2024 Ahmet Inan +*/ + +package xdsopl.robot36; + +public final class RGBModes { + + public static RGBDecoder Martin(String name, double channelSeconds, int sampleRate) { + double syncPulseSeconds = 0.004862; + double separatorSeconds = 0.000572; + double scanLineSeconds = syncPulseSeconds + separatorSeconds + 3 * (channelSeconds + separatorSeconds); + double greenBeginSeconds = syncPulseSeconds / 2 + separatorSeconds; + double greenEndSeconds = greenBeginSeconds + channelSeconds; + double blueBeginSeconds = greenEndSeconds + separatorSeconds; + double blueEndSeconds = blueBeginSeconds + channelSeconds; + double redBeginSeconds = blueEndSeconds + separatorSeconds; + double redEndSeconds = redBeginSeconds + channelSeconds; + return new RGBDecoder("Martin " + name, scanLineSeconds, greenBeginSeconds, redBeginSeconds, redEndSeconds, greenBeginSeconds, greenEndSeconds, blueBeginSeconds, blueEndSeconds, redEndSeconds, sampleRate); + } + + public static RGBDecoder Scottie(String name, double channelSeconds, int sampleRate) { + double syncPulseSeconds = 0.009; + double separatorSeconds = 0.0015; + double scanLineSeconds = syncPulseSeconds + 3 * (channelSeconds + separatorSeconds); + double blueEndSeconds = -syncPulseSeconds / 2; + double blueBeginSeconds = blueEndSeconds - channelSeconds; + double greenEndSeconds = blueBeginSeconds - separatorSeconds; + double greenBeginSeconds = greenEndSeconds - channelSeconds; + double redBeginSeconds = syncPulseSeconds / 2 + separatorSeconds; + double redEndSeconds = redBeginSeconds + channelSeconds; + return new RGBDecoder("Scottie " + name, scanLineSeconds, greenBeginSeconds, redBeginSeconds, redEndSeconds, greenBeginSeconds, greenEndSeconds, blueBeginSeconds, blueEndSeconds, redEndSeconds, sampleRate); + } + + public static RGBDecoder Wraase_SC2_180(int sampleRate) { + double syncPulseSeconds = 0.0055225; + double syncPorchSeconds = 0.0005; + double channelSeconds = 0.235; + double scanLineSeconds = syncPulseSeconds + syncPorchSeconds + 3 * channelSeconds; + double redBeginSeconds = syncPulseSeconds / 2 + syncPorchSeconds; + double redEndSeconds = redBeginSeconds + channelSeconds; + double greenBeginSeconds = redEndSeconds; + double greenEndSeconds = greenBeginSeconds + channelSeconds; + double blueBeginSeconds = greenEndSeconds; + double blueEndSeconds = blueBeginSeconds + channelSeconds; + return new RGBDecoder("Wraase SC2-180", scanLineSeconds, redBeginSeconds, redBeginSeconds, redEndSeconds, greenBeginSeconds, greenEndSeconds, blueBeginSeconds, blueEndSeconds, blueEndSeconds, sampleRate); + } +} diff --git a/app/src/main/java/xdsopl/robot36/Raw.java b/app/src/main/java/xdsopl/robot36/RawDecoder.java similarity index 90% rename from app/src/main/java/xdsopl/robot36/Raw.java rename to app/src/main/java/xdsopl/robot36/RawDecoder.java index 6bad08e..f997c56 100644 --- a/app/src/main/java/xdsopl/robot36/Raw.java +++ b/app/src/main/java/xdsopl/robot36/RawDecoder.java @@ -1,14 +1,14 @@ /* -Raw mode +Raw decoder Copyright 2024 Ahmet Inan */ package xdsopl.robot36; -public class Raw implements Mode { +public class RawDecoder implements Mode { - Raw() { + RawDecoder() { } @Override diff --git a/app/src/main/java/xdsopl/robot36/Scottie.java b/app/src/main/java/xdsopl/robot36/Scottie.java deleted file mode 100644 index 4220166..0000000 --- a/app/src/main/java/xdsopl/robot36/Scottie.java +++ /dev/null @@ -1,58 +0,0 @@ -/* -Scottie modes - -Copyright 2024 Ahmet Inan -*/ - -package xdsopl.robot36; - -public class Scottie implements Mode { - private final int scanLineSamples; - private final int channelSamples; - private final int greenBeginSamples; - private final int blueBeginSamples; - private final int redBeginSamples; - private final int redEndSamples; - private final String name; - - Scottie(String name, double channelSeconds, int sampleRate) { - this.name = "Scottie " + name; - double syncPulseSeconds = 0.009; - double separatorSeconds = 0.0015; - double scanLineSeconds = syncPulseSeconds + 3 * (channelSeconds + separatorSeconds); - scanLineSamples = (int) Math.round(scanLineSeconds * sampleRate); - channelSamples = (int) Math.round(channelSeconds * sampleRate); - double blueBeginSeconds = -(syncPulseSeconds / 2 + channelSeconds); - blueBeginSamples = (int) Math.round(blueBeginSeconds * sampleRate); - double greenBeginSeconds = blueBeginSeconds - (separatorSeconds + channelSeconds); - greenBeginSamples = (int) Math.round(greenBeginSeconds * sampleRate); - double redBeginSeconds = syncPulseSeconds / 2 + separatorSeconds; - redBeginSamples = (int) Math.round(redBeginSeconds * sampleRate); - double redEndSeconds = redBeginSeconds + channelSeconds; - redEndSamples = (int) Math.round(redEndSeconds * sampleRate); - } - - @Override - public String getName() { - return name; - } - - @Override - public int getScanLineSamples() { - return scanLineSamples; - } - - @Override - public int decodeScanLine(int[] evenBuffer, int[] oddBuffer, float[] scanLineBuffer, int prevPulseIndex, int scanLineSamples) { - if (prevPulseIndex + greenBeginSamples < 0 || prevPulseIndex + redEndSamples > scanLineBuffer.length) - 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; - evenBuffer[i] = ColorConverter.RGB(scanLineBuffer[redPos], scanLineBuffer[greenPos], scanLineBuffer[bluePos]); - } - 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 deleted file mode 100644 index e61313d..0000000 --- a/app/src/main/java/xdsopl/robot36/Wraase_SC2_180.java +++ /dev/null @@ -1,57 +0,0 @@ -/* -Wraase SC2-180 - -Copyright 2024 Ahmet Inan -*/ - -package xdsopl.robot36; - -public class Wraase_SC2_180 implements Mode { - private final int scanLineSamples; - private final int channelSamples; - private final int redBeginSamples; - private final int greenBeginSamples; - private final int blueBeginSamples; - private final int blueEndSamples; - - Wraase_SC2_180(int sampleRate) { - double syncPulseSeconds = 0.0055225; - double syncPorchSeconds = 0.0005; - double channelSeconds = 0.235; - double scanLineSeconds = syncPulseSeconds + syncPorchSeconds + 3 * channelSeconds; - scanLineSamples = (int) Math.round(scanLineSeconds * sampleRate); - channelSamples = (int) Math.round(channelSeconds * sampleRate); - double redBeginSeconds = syncPulseSeconds / 2 + syncPorchSeconds; - redBeginSamples = (int) Math.round(redBeginSeconds * sampleRate); - double greenBeginSeconds = redBeginSeconds + channelSeconds; - greenBeginSamples = (int) Math.round(greenBeginSeconds * sampleRate); - double blueBeginSeconds = greenBeginSeconds + channelSeconds; - blueBeginSamples = (int) Math.round(blueBeginSeconds * sampleRate); - double blueEndSeconds = blueBeginSeconds + channelSeconds; - blueEndSamples = (int) Math.round(blueEndSeconds * sampleRate); - } - - @Override - public String getName() { - return "Wraase SC2-180"; - } - - @Override - public int getScanLineSamples() { - return scanLineSamples; - } - - @Override - public int decodeScanLine(int[] evenBuffer, int[] oddBuffer, float[] scanLineBuffer, int prevPulseIndex, int scanLineSamples) { - if (prevPulseIndex + redBeginSamples < 0 || prevPulseIndex + blueEndSamples > scanLineBuffer.length) - 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; - evenBuffer[i] = ColorConverter.RGB(scanLineBuffer[redPos], scanLineBuffer[greenPos], scanLineBuffer[bluePos]); - } - return 1; - } -}