mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-17 13:51:47 -05:00
ATV demod: use common code for horizontal sync and different vertical sync detections for HSkip and standard
This commit is contained in:
parent
432d6ed8fd
commit
8ae95f2e85
@ -325,11 +325,7 @@ void ATVDemodSink::demod(Complex& c)
|
|||||||
|
|
||||||
if (m_registeredTVScreen) // can process only if the screen is available (set via the GUI)
|
if (m_registeredTVScreen) // can process only if the screen is available (set via the GUI)
|
||||||
{
|
{
|
||||||
if (m_settings.m_atvStd == ATVDemodSettings::ATVStdHSkip) {
|
processSample(sample, sampleVideo);
|
||||||
processHSkip(sample, sampleVideo);
|
|
||||||
} else {
|
|
||||||
processClassic(sample, sampleVideo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ private:
|
|||||||
void demod(Complex& c);
|
void demod(Complex& c);
|
||||||
void applyStandard(int sampleRate, const ATVDemodSettings& settings, float lineDuration);
|
void applyStandard(int sampleRate, const ATVDemodSettings& settings, float lineDuration);
|
||||||
|
|
||||||
inline void processClassic(float& sample, int& sampleVideo)
|
inline void processSample(float& sample, int& sampleVideo)
|
||||||
{
|
{
|
||||||
// Filling pixel on the current line - reference index 0 at start of sync pulse
|
// Filling pixel on the current line - reference index 0 at start of sync pulse
|
||||||
m_registeredTVScreen->setDataColor(m_sampleIndex - m_numberSamplesPerHSync, sampleVideo, sampleVideo, sampleVideo);
|
m_registeredTVScreen->setDataColor(m_sampleIndex - m_numberSamplesPerHSync, sampleVideo, sampleVideo, sampleVideo);
|
||||||
@ -257,6 +257,20 @@ private:
|
|||||||
if (m_sampleIndex >= m_samplesPerLine)
|
if (m_sampleIndex >= m_samplesPerLine)
|
||||||
{
|
{
|
||||||
m_sampleIndex = 0;
|
m_sampleIndex = 0;
|
||||||
|
|
||||||
|
if (m_settings.m_atvStd == ATVDemodSettings::ATVStdHSkip) {
|
||||||
|
processEOLHSkip();
|
||||||
|
} else {
|
||||||
|
processEOLClassic();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prevSample = sample;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Standard vertical sync
|
||||||
|
inline void processEOLClassic()
|
||||||
|
{
|
||||||
m_lineIndex++;
|
m_lineIndex++;
|
||||||
|
|
||||||
if (m_lineIndex == m_numberOfVSyncLines + 3 && m_fieldIndex == 0)
|
if (m_lineIndex == m_numberOfVSyncLines + 3 && m_fieldIndex == 0)
|
||||||
@ -308,65 +322,9 @@ private:
|
|||||||
m_registeredTVScreen->selectRow(rowIndex);
|
m_registeredTVScreen->selectRow(rowIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
prevSample = sample;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Vertical sync is obtained by skipping horizontal sync on the line that triggers vertical sync (new frame)
|
// Vertical sync is obtained by skipping horizontal sync on the line that triggers vertical sync (new frame)
|
||||||
inline void processHSkip(float& sample, int& sampleVideo)
|
inline void processEOLHSkip()
|
||||||
{
|
{
|
||||||
// Filling pixel on the current line - reference index 0 at start of sync pulse
|
|
||||||
m_registeredTVScreen->setDataColor(m_sampleIndex - m_numberSamplesPerHSync, sampleVideo, sampleVideo, sampleVideo);
|
|
||||||
|
|
||||||
if (m_settings.m_hSync)
|
|
||||||
{
|
|
||||||
// Horizontal Synchro detection
|
|
||||||
if ((prevSample >= m_settings.m_levelSynchroTop &&
|
|
||||||
sample < m_settings.m_levelSynchroTop) // horizontal synchro detected
|
|
||||||
&& (m_sampleIndexDetected > m_samplesPerLine - m_numberSamplesPerHTopNom))
|
|
||||||
{
|
|
||||||
double sampleIndexDetectedFrac =
|
|
||||||
(sample - m_settings.m_levelSynchroTop) / (prevSample - sample);
|
|
||||||
double hSyncShift = -m_sampleIndex - sampleIndexDetectedFrac;
|
|
||||||
if (hSyncShift > m_samplesPerLine / 2)
|
|
||||||
hSyncShift -= m_samplesPerLine;
|
|
||||||
else if (hSyncShift < -m_samplesPerLine / 2)
|
|
||||||
hSyncShift += m_samplesPerLine;
|
|
||||||
|
|
||||||
if (fabs(hSyncShift) > m_numberSamplesPerHTopNom)
|
|
||||||
{
|
|
||||||
m_hSyncErrorCount++;
|
|
||||||
if (m_hSyncErrorCount >= 8)
|
|
||||||
{
|
|
||||||
// Fast sync: shift is too large, needs to be fixed ASAP
|
|
||||||
m_sampleIndex = 0;
|
|
||||||
m_hSyncShiftSum = 0.0;
|
|
||||||
m_hSyncShiftCount = 0;
|
|
||||||
m_hSyncErrorCount = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_hSyncShiftSum += hSyncShift;
|
|
||||||
m_hSyncShiftCount++;
|
|
||||||
m_hSyncErrorCount = 0;
|
|
||||||
}
|
|
||||||
m_sampleIndexDetected = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
m_sampleIndexDetected++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_hSyncShiftSum = 0.0f;
|
|
||||||
m_hSyncShiftCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_sampleIndex++;
|
|
||||||
|
|
||||||
// end of line
|
|
||||||
if (m_sampleIndex >= m_samplesPerLine)
|
|
||||||
{
|
|
||||||
m_sampleIndex = 0;
|
|
||||||
m_lineIndex++;
|
m_lineIndex++;
|
||||||
m_rowIndex++;
|
m_rowIndex++;
|
||||||
|
|
||||||
@ -392,9 +350,6 @@ private:
|
|||||||
|
|
||||||
m_registeredTVScreen->selectRow(m_rowIndex);
|
m_registeredTVScreen->selectRow(m_rowIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
prevSample = sample;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user