Skip to content

Commit

Permalink
set current scan line samples when forcing mode
Browse files Browse the repository at this point in the history
  • Loading branch information
xdsopl committed May 5, 2024
1 parent 1f67e18 commit 73b8e10
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions app/src/main/java/xdsopl/robot36/Decoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class Decoder {
private int currentSample;
private int leaderBreakIndex;
private int lastSyncPulseIndex;
private int lastScanLineSamples;
private int currentScanLineSamples;
private float lastFrequencyOffset;

Decoder(PixelBuffer scopeBuffer, PixelBuffer imageBuffer, int sampleRate) {
Expand Down Expand Up @@ -97,7 +97,7 @@ public class Decoder {
rawMode = new RawDecoder(sampleRate);
Mode robot36 = new Robot_36_Color(sampleRate);
currentMode = robot36;
lastScanLineSamples = robot36.getScanLineSamples();
currentScanLineSamples = robot36.getScanLineSamples();
syncPulse5msModes = new ArrayList<>();
syncPulse5msModes.add(RGBModes.Wraase_SC2_180(sampleRate));
syncPulse5msModes.add(RGBModes.Martin("1", 44, 0.146432, sampleRate));
Expand Down Expand Up @@ -336,14 +336,14 @@ private boolean handleHeader() {
imageBuffer.line = 0;
currentMode = mode;
lastSyncPulseIndex = syncPulseIndex + mode.getFirstSyncPulseIndex();
lastScanLineSamples = mode.getScanLineSamples();
currentScanLineSamples = mode.getScanLineSamples();
lastFrequencyOffset = leaderFreqOffset;
int oldestSyncPulseIndex = lastSyncPulseIndex - (pulses.length - 1) * lastScanLineSamples;
int oldestSyncPulseIndex = lastSyncPulseIndex - (pulses.length - 1) * currentScanLineSamples;
if (mode.getFirstSyncPulseIndex() > 0)
oldestSyncPulseIndex -= lastScanLineSamples;
oldestSyncPulseIndex -= currentScanLineSamples;
for (int i = 0; i < pulses.length; ++i)
pulses[i] = oldestSyncPulseIndex + i * lastScanLineSamples;
Arrays.fill(lines, lastScanLineSamples);
pulses[i] = oldestSyncPulseIndex + i * currentScanLineSamples;
Arrays.fill(lines, currentScanLineSamples);
shiftSamples(lastSyncPulseIndex + mode.getBegin());
drawLines(0xff00ff00, 8);
drawLines(0xff000000, 10);
Expand Down Expand Up @@ -376,7 +376,7 @@ private boolean processSyncPulse(ArrayList<Mode> modes, float[] freqOffs, int[]
Mode prevMode = currentMode;
currentMode = detectMode(modes, scanLineSamples);
pictureChanged = currentMode != prevMode
|| Math.abs(lastScanLineSamples - scanLineSamples) > scanLineToleranceSamples
|| Math.abs(currentScanLineSamples - scanLineSamples) > scanLineToleranceSamples
|| Math.abs(lastSyncPulseIndex + scanLineSamples - pulses[pulses.length - 1]) > syncPulseToleranceSamples;
}
if (pictureChanged) {
Expand All @@ -395,7 +395,7 @@ private boolean processSyncPulse(ArrayList<Mode> modes, float[] freqOffs, int[]
for (int i = pictureChanged ? 0 : lines.length - 1; i < lines.length; ++i)
copyLines(currentMode.decodeScanLine(pixelBuffer, scratchBuffer, scanLineBuffer, scopeBuffer.width, pulses[i], lines[i], frequencyOffset));
lastSyncPulseIndex = pulses[pulses.length - 1];
lastScanLineSamples = scanLineSamples;
currentScanLineSamples = scanLineSamples;
lastFrequencyOffset = frequencyOffset;
shiftSamples(lastSyncPulseIndex + currentMode.getBegin());
return true;
Expand All @@ -408,8 +408,8 @@ public boolean process(float[] recordBuffer, int channelSelect) {
for (int j = 0; j < recordBuffer.length / channels; ++j) {
scanLineBuffer[currentSample++] = recordBuffer[j];
if (currentSample >= scanLineBuffer.length) {
shiftSamples(lastScanLineSamples);
syncPulseIndex -= lastScanLineSamples;
shiftSamples(currentScanLineSamples);
syncPulseIndex -= currentScanLineSamples;
}
}
if (syncPulseDetected) {
Expand All @@ -428,9 +428,9 @@ public boolean process(float[] recordBuffer, int channelSelect) {
}
if (handleHeader())
return true;
if (currentSample > lastSyncPulseIndex + (lastScanLineSamples * 5) / 4) {
copyLines(currentMode.decodeScanLine(pixelBuffer, scratchBuffer, scanLineBuffer, scopeBuffer.width, lastSyncPulseIndex, lastScanLineSamples, lastFrequencyOffset));
lastSyncPulseIndex += lastScanLineSamples;
if (currentSample > lastSyncPulseIndex + (currentScanLineSamples * 5) / 4) {
copyLines(currentMode.decodeScanLine(pixelBuffer, scratchBuffer, scanLineBuffer, scopeBuffer.width, lastSyncPulseIndex, currentScanLineSamples, lastFrequencyOffset));
lastSyncPulseIndex += currentScanLineSamples;
return true;
}
return false;
Expand All @@ -448,6 +448,8 @@ public void forceMode(String name) {
imageBuffer.line = -1;
if (mode == null)
mode = rawMode;
else
currentScanLineSamples = mode.getScanLineSamples();
currentMode = mode;
}

Expand Down

0 comments on commit 73b8e10

Please sign in to comment.