diff --git a/plugins/channelrx/demodatv/atvdemod.cpp b/plugins/channelrx/demodatv/atvdemod.cpp index 77fe6c82f..92f5ae45e 100644 --- a/plugins/channelrx/demodatv/atvdemod.cpp +++ b/plugins/channelrx/demodatv/atvdemod.cpp @@ -446,7 +446,7 @@ void ATVDemod::demod(Complex& c) if (blnComputeImage) { - m_objRegisteredATVScreen->setDataColor(m_intColIndex - m_intNumberSamplePerTop, intVal, intVal, intVal); + m_objRegisteredATVScreen->setDataColor(m_intColIndex - m_intNumberSamplePerTop, intVal, intVal, intVal); // TODO: the subtraction should be made with back porch number of samples } m_intColIndex++; @@ -454,6 +454,7 @@ void ATVDemod::demod(Complex& c) ////////////////////// m_blnSynchroDetected=false; + if((m_objRunning.m_blnHSync) && (m_intRowIndex>1)) { //********** Line Synchro 0-0-0 -> 0.3-0.3 0.3 ********** @@ -518,6 +519,8 @@ void ATVDemod::demod(Complex& c) } } + // TODO: stabilize horizontal sync by (exponential) averaging the column index at sync detection. + // Then on the next block trigger on this column index average. //Horizontal Synchro if((m_intColIndex>=m_intNumberSamplePerLine) diff --git a/plugins/channelrx/demodatv/atvdemod.h b/plugins/channelrx/demodatv/atvdemod.h index 3b1b7551c..d3bba4965 100644 --- a/plugins/channelrx/demodatv/atvdemod.h +++ b/plugins/channelrx/demodatv/atvdemod.h @@ -297,6 +297,36 @@ private: } }; + /** + * Exponential average using integers and alpha as the inverse of a power of two + */ + class AvgExpInt + { + public: + AvgExpInt(int log2Alpha) : m_log2Alpha(log2Alpha), m_m1(0), m_start(true) {} + void reset() { m_start = true; } + + int run(int m0) + { + if (m_start) + { + m_m1 = m0; + m_start = false; + return m0; + } + else + { + m_m1 = m0 + m_m1 - (m_m1>>m_log2Alpha); + return m_m1>>m_log2Alpha; + } + } + + private: + int m_log2Alpha; + int m_m1; + bool m_start; + }; + //*************** SCOPE *************** BasebandSampleSink* m_objScopeSink;