LFO: square and triangle wave now working

pull/6/head
Steve Lascos 6 years ago
parent 618d23922e
commit d954f0aced
  1. 3
      src/LibBasicFunctions.h
  2. 36
      src/common/LowFrequencyOscillator.cpp

@ -476,6 +476,9 @@ private:
const T PI_F = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899; ///< 2*PI const T PI_F = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899; ///< 2*PI
const T TWO_PI_F = 2.0 * 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 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 } // BALibrary

@ -101,33 +101,27 @@ T *LowFrequencyOscillatorVector<T>::getNextVector()
break; break;
case Waveform::SQUARE : case Waveform::SQUARE :
for (auto i=0; i<AUDIO_BLOCK_SAMPLES; i++) { for (auto i=0; i<AUDIO_BLOCK_SAMPLES; i++) {
if (m_phaseVec[i] > 3*PI_F) {
m_outputVec[i] = 0.0f; if (m_phaseVec[i] < PI_F) {
} m_outputVec[i] = -1.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 { } else {
m_outputVec[i] = 1.0f; m_outputVec[i] = 1.0f;
} }
} }
break; break;
case Waveform::TRIANGLE : case Waveform::TRIANGLE :
// for (auto i=0; i<AUDIO_BLOCK_SAMPLES; i++) { // A triangle is made up from two different line equations of form y=mx+b
// if (m_phaseVec[i] > 3*PI_F) { // where m = +2/pi or -2/pi. A "Triangle Cos" starts at +1.0 and moves to
// m_outputVec[i] = ; // -1.0 from angles 0 to PI radians.
// } for (auto i=0; i<AUDIO_BLOCK_SAMPLES; i++) {
// else if (m_phaseVec[i] > 2*PI_F) { if (m_phaseVec[i] < PI_F) {
// m_outputVec[i] = 1.0f; // y = (-2/pi)*x + 1.0
// } m_outputVec[i] = TRIANGE_NEG_SLOPE * m_phaseVec[i] + 1.0f;
// else if (m_phaseVec[i] > PI_F) { } else {
// m_outputVec[i] = 0.0f; // y = (2/pi)*x -1.0
// } else { m_outputVec[i] = TRIANGE_POS_SLOPE * (m_phaseVec[i]-PI_F) - 1.0f;
// m_outputVec[i] = 1.0f; }
// } }
// }
break; break;
case Waveform::RANDOM : case Waveform::RANDOM :
break; break;

Loading…
Cancel
Save