mirror of
https://github.com/xdsopl/robot36.git
synced 2026-04-21 06:03:41 +00:00
align sync pulses with scan line
This commit is contained in:
parent
3ae7e18df3
commit
fee4012c6a
1 changed files with 12 additions and 8 deletions
|
|
@ -37,7 +37,8 @@ public class MainActivity extends AppCompatActivity {
|
||||||
private float[] recordBuffer;
|
private float[] recordBuffer;
|
||||||
private AudioRecord audioRecord;
|
private AudioRecord audioRecord;
|
||||||
private TextView status;
|
private TextView status;
|
||||||
private Delay powerDelay;
|
private Delay syncPulseDelay;
|
||||||
|
private Delay scanLineDelay;
|
||||||
private SimpleMovingAverage powerAvg;
|
private SimpleMovingAverage powerAvg;
|
||||||
private ComplexMovingAverage syncPulseFilter;
|
private ComplexMovingAverage syncPulseFilter;
|
||||||
private ComplexMovingAverage scanLineFilter;
|
private ComplexMovingAverage scanLineFilter;
|
||||||
|
|
@ -74,8 +75,8 @@ public class MainActivity extends AppCompatActivity {
|
||||||
baseBand = baseBandLowPass.avg(baseBand.set(v).mul(baseBandOscillator.rotate()));
|
baseBand = baseBandLowPass.avg(baseBand.set(v).mul(baseBandOscillator.rotate()));
|
||||||
syncPulse = syncPulseFilter.avg(syncPulse.set(baseBand).mul(syncPulseOscillator.rotate()));
|
syncPulse = syncPulseFilter.avg(syncPulse.set(baseBand).mul(syncPulseOscillator.rotate()));
|
||||||
scanLine = scanLineFilter.avg(scanLine.set(baseBand).mul(scanLineOscillator.rotate()));
|
scanLine = scanLineFilter.avg(scanLine.set(baseBand).mul(scanLineOscillator.rotate()));
|
||||||
float syncPulseValue = powerDelay.push(syncPulse.norm()) / powerAvg.avg(baseBand.norm());
|
float syncPulseValue = syncPulseDelay.push(syncPulse.norm()) / powerAvg.avg(baseBand.norm());
|
||||||
float scanLineValue = scanLineDemod.demod(scanLine);
|
float scanLineValue = scanLineDelay.push(scanLineDemod.demod(scanLine));
|
||||||
float syncPulseLevel = Math.min(Math.max(syncPulseValue, 0), 1);
|
float syncPulseLevel = Math.min(Math.max(syncPulseValue, 0), 1);
|
||||||
float scanLineLevel = Math.min(Math.max(0.5f * (scanLineValue + 1), 0), 1);
|
float scanLineLevel = Math.min(Math.max(0.5f * (scanLineValue + 1), 0), 1);
|
||||||
int syncPulseIntensity = (int) Math.round(255 * Math.sqrt(syncPulseLevel));
|
int syncPulseIntensity = (int) Math.round(255 * Math.sqrt(syncPulseLevel));
|
||||||
|
|
@ -103,17 +104,16 @@ public class MainActivity extends AppCompatActivity {
|
||||||
double powerWindowSeconds = 0.5;
|
double powerWindowSeconds = 0.5;
|
||||||
int powerWindowSamples = (int) Math.round(powerWindowSeconds * sampleRate) | 1;
|
int powerWindowSamples = (int) Math.round(powerWindowSeconds * sampleRate) | 1;
|
||||||
powerAvg = new SimpleMovingAverage(powerWindowSamples);
|
powerAvg = new SimpleMovingAverage(powerWindowSamples);
|
||||||
powerDelay = new Delay((powerWindowSamples - 1) / 2);
|
|
||||||
float blackFrequency = 1500;
|
float blackFrequency = 1500;
|
||||||
float whiteFrequency = 2300;
|
float whiteFrequency = 2300;
|
||||||
float scanLineBandwidth = whiteFrequency - blackFrequency;
|
float scanLineBandwidth = whiteFrequency - blackFrequency;
|
||||||
scanLineDemod = new FrequencyModulation(scanLineBandwidth, sampleRate);
|
scanLineDemod = new FrequencyModulation(scanLineBandwidth, sampleRate);
|
||||||
float scanLineCutoff = scanLineBandwidth / 2;
|
float scanLineCutoff = scanLineBandwidth / 2;
|
||||||
int scanLineSamples = (int) Math.round(0.443 * sampleRate / scanLineCutoff) | 1;
|
int scanLineFilterSamples = (int) Math.round(0.443 * sampleRate / scanLineCutoff) | 1;
|
||||||
scanLineFilter = new ComplexMovingAverage(scanLineSamples);
|
scanLineFilter = new ComplexMovingAverage(scanLineFilterSamples);
|
||||||
double syncPulseSeconds = 0.009;
|
double syncPulseSeconds = 0.009;
|
||||||
int syncPulseSamples = (int) Math.round(syncPulseSeconds * sampleRate);
|
int syncPulseFilterSamples = (int) Math.round(syncPulseSeconds * sampleRate) | 1;
|
||||||
syncPulseFilter = new ComplexMovingAverage(syncPulseSamples);
|
syncPulseFilter = new ComplexMovingAverage(syncPulseFilterSamples);
|
||||||
float lowestFrequency = 1100;
|
float lowestFrequency = 1100;
|
||||||
float highestFrequency = 2300;
|
float highestFrequency = 2300;
|
||||||
float cutoffFrequency = (highestFrequency - lowestFrequency) / 2;
|
float cutoffFrequency = (highestFrequency - lowestFrequency) / 2;
|
||||||
|
|
@ -125,6 +125,10 @@ public class MainActivity extends AppCompatActivity {
|
||||||
syncPulseOscillator = new Phasor(-(syncPulseFrequency - centerFrequency), sampleRate);
|
syncPulseOscillator = new Phasor(-(syncPulseFrequency - centerFrequency), sampleRate);
|
||||||
float grayFrequency = (blackFrequency + whiteFrequency) / 2;
|
float grayFrequency = (blackFrequency + whiteFrequency) / 2;
|
||||||
scanLineOscillator = new Phasor(-(grayFrequency - centerFrequency), sampleRate);
|
scanLineOscillator = new Phasor(-(grayFrequency - centerFrequency), sampleRate);
|
||||||
|
int syncPulseDelaySamples = (powerWindowSamples - 1) / 2;
|
||||||
|
syncPulseDelay = new Delay(syncPulseDelaySamples);
|
||||||
|
int scanLineDelaySamples = (powerWindowSamples - 1) / 2 + (syncPulseFilterSamples - 1) / 2 - (scanLineFilterSamples - 1) / 2;
|
||||||
|
scanLineDelay = new Delay(scanLineDelaySamples);
|
||||||
baseBand = new Complex();
|
baseBand = new Complex();
|
||||||
syncPulse = new Complex();
|
syncPulse = new Complex();
|
||||||
scanLine = new Complex();
|
scanLine = new Complex();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue