diff --git a/app/src/main/java/xdsopl/robot36/Decoder.java b/app/src/main/java/xdsopl/robot36/Decoder.java index b3b98b5..c74f9f3 100644 --- a/app/src/main/java/xdsopl/robot36/Decoder.java +++ b/app/src/main/java/xdsopl/robot36/Decoder.java @@ -66,7 +66,7 @@ public class Decoder { double scanLineToleranceSeconds = 0.001; scanLineToleranceSamples = (int) Math.round(scanLineToleranceSeconds * sampleRate); scanLineReserveSamples = sampleRate; - rawMode = new RawDecoder(); + rawMode = new RawDecoder(sampleRate); lastMode = rawMode; lastScanLineSamples = (int) Math.round(0.150 * sampleRate); syncPulse5msModes = new ArrayList<>(); diff --git a/app/src/main/java/xdsopl/robot36/RawDecoder.java b/app/src/main/java/xdsopl/robot36/RawDecoder.java index 294b019..90109c7 100644 --- a/app/src/main/java/xdsopl/robot36/RawDecoder.java +++ b/app/src/main/java/xdsopl/robot36/RawDecoder.java @@ -8,8 +8,12 @@ package xdsopl.robot36; public class RawDecoder implements Mode { private final ExponentialMovingAverage lowPassFilter; + private final int smallPictureMaxSamples; + private final int mediumPictureMaxSamples; - RawDecoder() { + RawDecoder(int sampleRate) { + smallPictureMaxSamples = (int) Math.round(0.125 * sampleRate); + mediumPictureMaxSamples = (int) Math.round(0.175 * sampleRate); lowPassFilter = new ExponentialMovingAverage(); } @@ -32,6 +36,10 @@ public class RawDecoder implements Mode { if (syncPulseIndex < 0 || syncPulseIndex + scanLineSamples > scanLineBuffer.length) return false; int horizontalPixels = pixelBuffer.width; + if (scanLineSamples < smallPictureMaxSamples) + horizontalPixels /= 2; + if (scanLineSamples < mediumPictureMaxSamples) + horizontalPixels /= 2; lowPassFilter.cutoff(horizontalPixels, 2 * scanLineSamples, 2); lowPassFilter.reset(); for (int i = 0; i < scanLineSamples; ++i) @@ -43,6 +51,7 @@ public class RawDecoder implements Mode { int position = (i * scanLineSamples) / horizontalPixels; pixelBuffer.pixels[i] = ColorConverter.GRAY(scratchBuffer[position]); } + pixelBuffer.width = horizontalPixels; pixelBuffer.height = 1; return true; }