diff --git a/sdrbase/dsp/ncof.cpp b/sdrbase/dsp/ncof.cpp index 59ff93b9c..f2cea8296 100644 --- a/sdrbase/dsp/ncof.cpp +++ b/sdrbase/dsp/ncof.cpp @@ -23,16 +23,19 @@ #undef M_PI #define M_PI 3.14159265358979323846 -Real NCOF::m_table[NCOF::TableSize]; +Real NCOF::m_table[NCOF::TableSize+1]; bool NCOF::m_tableInitialized = false; +float NCOF::m_tableSizeLimit = (float) NCOF::TableSize; void NCOF::initTable() { - if(m_tableInitialized) + if(m_tableInitialized) { return; + } - for(int i = 0; i < TableSize; i++) + for(int i = 0; i <= TableSize; i++) { m_table[i] = cos((2.0 * M_PI * i) / TableSize); + } m_tableInitialized = true; } diff --git a/sdrbase/dsp/ncof.h b/sdrbase/dsp/ncof.h index 6c4217565..57fa4258f 100644 --- a/sdrbase/dsp/ncof.h +++ b/sdrbase/dsp/ncof.h @@ -25,8 +25,9 @@ private: enum { TableSize = (1 << 12), }; - static Real m_table[TableSize]; + static Real m_table[TableSize+1]; static bool m_tableInitialized; + static float m_tableSizeLimit; static void initTable(); @@ -42,10 +43,12 @@ public: int nextPhase() //!< Increment phase and return its integer value { m_phase += m_phaseIncrement; - while(m_phase >= TableSize) + while(m_phase >= m_tableSizeLimit) { m_phase -= TableSize; - while(m_phase < 0) + } + while(m_phase < 0.0) { m_phase += TableSize; + } return (int) m_phase; }