From d954f0aced72e86a2f1179a492f79df6b5c72103 Mon Sep 17 00:00:00 2001 From: Steve Lascos Date: Sat, 26 Jan 2019 16:07:32 -0500 Subject: [PATCH] LFO: square and triangle wave now working --- src/LibBasicFunctions.h | 3 ++ src/common/LowFrequencyOscillator.cpp | 42 ++++++++++++--------------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/LibBasicFunctions.h b/src/LibBasicFunctions.h index a75a164..7a7469e 100644 --- a/src/LibBasicFunctions.h +++ b/src/LibBasicFunctions.h @@ -476,6 +476,9 @@ private: const T PI_F = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899; ///< 2*PI const T TWO_PI_F = 2.0 * 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899; ///< 2*PI const T PI_DIV2_F = 0.5 * 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899; ///< PI/2 + const T THREE_PI_DIV2_F = 1.5 * 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899; ///< 3*PI/2 + const float TRIANGE_POS_SLOPE = 2.0f/PI_F; + const float TRIANGE_NEG_SLOPE = -2.0f/PI_F; }; } // BALibrary diff --git a/src/common/LowFrequencyOscillator.cpp b/src/common/LowFrequencyOscillator.cpp index 44924f3..d293816 100644 --- a/src/common/LowFrequencyOscillator.cpp +++ b/src/common/LowFrequencyOscillator.cpp @@ -101,33 +101,27 @@ T *LowFrequencyOscillatorVector::getNextVector() break; case Waveform::SQUARE : for (auto i=0; i 3*PI_F) { - m_outputVec[i] = 0.0f; - } - else if (m_phaseVec[i] > 2*PI_F) { - m_outputVec[i] = 1.0f; - } - else if (m_phaseVec[i] > PI_F) { - m_outputVec[i] = 0.0f; - } else { - m_outputVec[i] = 1.0f; - } + + if (m_phaseVec[i] < PI_F) { + m_outputVec[i] = -1.0f; + } else { + m_outputVec[i] = 1.0f; + } } break; case Waveform::TRIANGLE : -// for (auto i=0; i 3*PI_F) { -// m_outputVec[i] = ; -// } -// else if (m_phaseVec[i] > 2*PI_F) { -// m_outputVec[i] = 1.0f; -// } -// else if (m_phaseVec[i] > PI_F) { -// m_outputVec[i] = 0.0f; -// } else { -// m_outputVec[i] = 1.0f; -// } -// } + // A triangle is made up from two different line equations of form y=mx+b + // where m = +2/pi or -2/pi. A "Triangle Cos" starts at +1.0 and moves to + // -1.0 from angles 0 to PI radians. + for (auto i=0; i