/*
* LowFrequencyOscillator.cpp
*
* Created on: October 12, 2018
* Author: Steve Lascos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include "Audio.h"
#include "LibBasicFunctions.h"
namespace BALibrary {
template
void LowFrequencyOscillatorVector::m_initPhase(T radiansPerSample)
{
// Initialize the phase vector starting at 0 radians, and incrementing
// by radiansPerSample for each element in the vector.
T initialPhase[AUDIO_BLOCK_SAMPLES];
for (auto i=0; i
void LowFrequencyOscillatorVector::setRateAudio(float frequencyHz)
{
T radiansPerSample;
if (frequencyHz == 0) {
radiansPerSample = 0;
} else {
T periodSamples = AUDIO_SAMPLE_RATE_EXACT / frequencyHz;
radiansPerSample = (T)TWO_PI_F / periodSamples;
}
m_initPhase(radiansPerSample);
}
// This function is used when the LFO is being called at some rate other than
// the audio rate. Here you can manually set the radians per sample as a fraction
// of 2*PI
template
void LowFrequencyOscillatorVector::setRateRatio(float ratio)
{
T radiansPerSample;
if (ratio == 0) {
radiansPerSample = 0;
} else {
radiansPerSample = (T)TWO_PI_F * ratio;
}
m_initPhase(radiansPerSample);
}
// When this function is called, it will update the phase vector by incrementing by
// radians per block which is radians per sample * block size.
template
inline void LowFrequencyOscillatorVector::m_updatePhase()
{
if (m_phaseLock.test_and_set()) { return; }
if (m_phaseVec[0] > TWO_PI_F) {
arm_offset_f32(m_phaseVec, -TWO_PI_F + m_radiansPerBlock, m_phaseVec, AUDIO_BLOCK_SAMPLES);
} else {
arm_offset_f32(m_phaseVec, m_radiansPerBlock, m_phaseVec, AUDIO_BLOCK_SAMPLES);
}
m_phaseLock.clear();
}
// This function will compute the vector of samples for the output waveform using
// the current phase vector.
template
T *LowFrequencyOscillatorVector::getNextVector()
{
switch(m_waveform) {
case Waveform::SINE :
for (auto i=0; i;
} // namespace BALibrary