diff --git a/app/src/main/java/xdsopl/robot36/Decoder.java b/app/src/main/java/xdsopl/robot36/Decoder.java index c7ed696..aee26d5 100644 --- a/app/src/main/java/xdsopl/robot36/Decoder.java +++ b/app/src/main/java/xdsopl/robot36/Decoder.java @@ -145,14 +145,17 @@ public class Decoder { } for (int i = 0; i < lines.length; ++i) copyLines(mode.decodeScanLine(evenBuffer, oddBuffer, scanLineBuffer, pulses[i], lines[i])); - int shift = pulses[pulses.length - 1] - (meanSamples * 3) / 4; - adjustSyncPulses(last5msSyncPulses, shift); - adjustSyncPulses(last9msSyncPulses, shift); - adjustSyncPulses(last20msSyncPulses, shift); - int endSample = curSample; - curSample = 0; - for (int i = shift; i < endSample; ++i) - scanLineBuffer[curSample++] = scanLineBuffer[i]; + int reserve = (meanSamples * 3) / 4; + int shift = pulses[pulses.length - 1] - reserve; + if (shift > reserve) { + adjustSyncPulses(last5msSyncPulses, shift); + adjustSyncPulses(last9msSyncPulses, shift); + adjustSyncPulses(last20msSyncPulses, shift); + int endSample = curSample; + curSample = 0; + for (int i = shift; i < endSample; ++i) + scanLineBuffer[curSample++] = scanLineBuffer[i]; + } return true; }