kopia lustrzana https://github.com/xdsopl/robot36
First version of HF Fax mode (copied from raw mode)
rodzic
1a722d5289
commit
e8be1f9600
|
@ -38,6 +38,7 @@ public class Decoder {
|
|||
private final int visCodeBitSamples;
|
||||
private final int visCodeSamples;
|
||||
private final Mode rawMode;
|
||||
private final Mode hffaxMode;
|
||||
private final ArrayList<Mode> syncPulse5msModes;
|
||||
private final ArrayList<Mode> syncPulse9msModes;
|
||||
private final ArrayList<Mode> syncPulse20msModes;
|
||||
|
@ -95,6 +96,7 @@ public class Decoder {
|
|||
double scanLineToleranceSeconds = 0.001;
|
||||
scanLineToleranceSamples = (int) Math.round(scanLineToleranceSeconds * sampleRate);
|
||||
rawMode = new RawDecoder(rawName, sampleRate);
|
||||
hffaxMode = new HFFax("HF Fax", sampleRate);
|
||||
Mode robot36 = new Robot_36_Color(sampleRate);
|
||||
currentMode = robot36;
|
||||
currentScanLineSamples = robot36.getScanLineSamples();
|
||||
|
@ -450,6 +452,8 @@ public class Decoder {
|
|||
mode = findMode(syncPulse9msModes, name);
|
||||
if (mode == null)
|
||||
mode = findMode(syncPulse20msModes, name);
|
||||
if (mode == null && hffaxMode.getName().equals(name))
|
||||
mode = hffaxMode;
|
||||
if (mode == currentMode) {
|
||||
lockMode = true;
|
||||
return;
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
package xdsopl.robot36;
|
||||
|
||||
public class HFFax implements Mode {
|
||||
private final ExponentialMovingAverage lowPassFilter;
|
||||
private final int smallPictureMaxSamples;
|
||||
private final int mediumPictureMaxSamples;
|
||||
private final String name;
|
||||
|
||||
private final int sr;
|
||||
|
||||
HFFax(String name, int sampleRate) {
|
||||
this.name = name;
|
||||
smallPictureMaxSamples = (int) Math.round(0.125 * sampleRate);
|
||||
mediumPictureMaxSamples = (int) Math.round(0.175 * sampleRate);
|
||||
lowPassFilter = new ExponentialMovingAverage();
|
||||
this.sr = sampleRate;
|
||||
}
|
||||
|
||||
private float freqToLevel(float frequency, float offset) {
|
||||
return 0.5f * (frequency - offset + 1.f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCode() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBegin() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFirstSyncPulseIndex() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScanLineSamples() {
|
||||
return sr / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean decodeScanLine(PixelBuffer pixelBuffer, float[] scratchBuffer, float[] scanLineBuffer, int scopeBufferWidth, int syncPulseIndex, int scanLineSamples, float frequencyOffset) {
|
||||
if (syncPulseIndex < 0 || syncPulseIndex + scanLineSamples > scanLineBuffer.length)
|
||||
return false;
|
||||
int horizontalPixels = scopeBufferWidth;
|
||||
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)
|
||||
scratchBuffer[i] = lowPassFilter.avg(scanLineBuffer[syncPulseIndex + i]);
|
||||
lowPassFilter.reset();
|
||||
for (int i = scanLineSamples - 1; i >= 0; --i)
|
||||
scratchBuffer[i] = freqToLevel(lowPassFilter.avg(scratchBuffer[i]), frequencyOffset);
|
||||
for (int i = 0; i < horizontalPixels; ++i) {
|
||||
int position = (i * scanLineSamples) / horizontalPixels;
|
||||
pixelBuffer.pixels[i] = ColorConverter.GRAY(scratchBuffer[position]);
|
||||
}
|
||||
pixelBuffer.width = horizontalPixels;
|
||||
pixelBuffer.height = 1;
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -612,6 +612,10 @@ public class MainActivity extends AppCompatActivity {
|
|||
setMode(R.string.raw_mode);
|
||||
return true;
|
||||
}
|
||||
if (id == R.id.action_force_hffax_mode) {
|
||||
setMode("HF Fax");
|
||||
return true;
|
||||
}
|
||||
if (id == R.id.action_force_robot36_color) {
|
||||
setMode(R.string.robot36_color);
|
||||
return true;
|
||||
|
|
|
@ -102,6 +102,11 @@
|
|||
android:icon="@drawable/baseline_image_not_supported_24"
|
||||
android:title="@string/raw_mode"
|
||||
app:iconTint="@color/tint" />
|
||||
<item
|
||||
android:id="@+id/action_force_hffax_mode"
|
||||
android:icon="@drawable/baseline_image_not_supported_24"
|
||||
android:title="@string/hffax_mode"
|
||||
app:iconTint="@color/tint" />
|
||||
<item
|
||||
android:id="@+id/action_auto_mode"
|
||||
android:icon="@drawable/baseline_auto_mode_24"
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
<string name="auto_mode">Auto Mode</string>
|
||||
<string name="lock_mode">Lock Mode</string>
|
||||
<string name="raw_mode">Raw Mode</string>
|
||||
<string name="hffax_mode">HF Fax Mode</string>
|
||||
<string name="listening">Listening</string>
|
||||
<string name="audio_settings">Audio Settings</string>
|
||||
<string name="sample_rate">Sample Rate</string>
|
||||
|
|
Ładowanie…
Reference in New Issue