FastLFO fixes

pull/495/head
abscisys 2 years ago
parent 7e18647a53
commit 6dd6d18009
  1. 39
      src/fx_components.cpp
  2. 2
      src/fx_components.h
  3. 2
      src/test/cppcheck-suppression-list.txt
  4. 2
      src/test/test_cpp_performance.cpp

@ -29,6 +29,8 @@ FastLFO::FastLFO(float32_t sampling_rate, float32_t min_frequency, float32_t max
max_frequency_(max_frequency),
centered_(centered),
frequency_(0.0f),
nb_sub_increment_(1),
sub_increment_(0),
y0_(0.0f),
y1_(0.0f),
iir_coefficient_(0.0f),
@ -54,6 +56,9 @@ void FastLFO::setNormalizedFrequency(float32_t normalized_frequency)
this->frequency_ = frequency;
this->unitary_frequency_ = this->frequency_ / this->getSamplingRate();
this->nb_sub_increment_ = (frequency >= 3.0f ? 1 : 300);
this->unitary_frequency_ *= this->nb_sub_increment_;
this->updateCoefficient();
}
}
@ -73,6 +78,9 @@ void FastLFO::setFrequency(float32_t frequency)
this->frequency_ = frequency;
this->unitary_frequency_ = this->frequency_ / this->getSamplingRate();
this->nb_sub_increment_ = (frequency >= 3.0f ? 1 : 300);
this->unitary_frequency_ *= this->nb_sub_increment_;
this->updateCoefficient();
}
}
@ -84,7 +92,7 @@ float32_t FastLFO::getFrequency() const
void FastLFO::updateCoefficient()
{
float32_t frequency = this->unitary_frequency_;
float32_t frequency = this->unitary_frequency_ * 268.0f / 240.0f;
float32_t sign = 16.0f;
frequency -= 0.25f;
@ -112,6 +120,8 @@ void FastLFO::updateCoefficient()
void FastLFO::reset()
{
this->sub_increment_ = 0.0f;
// computing cos(0) = sin(-PI/2)
this->y1_ = this->initial_amplitude_;
this->y0_ = 0.5f;
@ -121,12 +131,12 @@ void FastLFO::reset()
return;
}
float32_t p_i = Constants::M2PI * this->unitary_frequency_;
float32_t p = 0.0f;
float32_t t_p = this->InitialPhase - Constants::MPI_2;
if(t_p < 0.0f)
float32_t p_i = Constants::M2PI * this->unitary_frequency_ / static_cast<float32_t>(this->nb_sub_increment_);
float32_t p = Constants::MPI_2;
float32_t t_p = this->InitialPhase;
if(t_p < p)
{
t_p += Constants::M2PI;
p -= Constants::M2PI;
}
while(p < t_p)
{
@ -138,18 +148,23 @@ void FastLFO::reset()
float32_t FastLFO::process()
{
float32_t temp = this->y0_;
this->y0_ = this->iir_coefficient_ * this->y0_ - this->y1_;
this->y1_ = temp;
float32_t current = temp + 0.5f;
if(this->centered_)
{
this->current_ = (temp + 0.5f) * 2.0f - 1.0f;
current = current * 2.0f - 1.0f;
}
else
this->sub_increment_++;
if(this->sub_increment_ >= this->nb_sub_increment_)
{
this->current_ = temp + 0.5f;
this->sub_increment_ = 0;
this->y0_ = this->iir_coefficient_ * this->y0_ - this->y1_;
this->y1_ = temp;
this->current_ = current;
return current;
}
return this->current_;
return mapfloat(this->sub_increment_, 0, this->nb_sub_increment_, this->current_, current);
}
float32_t FastLFO::current() const

@ -72,6 +72,8 @@ private:
float32_t frequency_;
float32_t normalized_frequency_;
float32_t unitary_frequency_;
size_t nb_sub_increment_;
size_t sub_increment_;
float32_t y0_;
float32_t y1_;

@ -4,8 +4,10 @@ noExplicitConstructor:*
unusedFunction:*
missingIncludeSystem:*
unmatchedSuppression:*
unreadVariable:test*.cpp
// unexplained exceptions
syntaxError:beta.cpp:52
syntaxError:test_fx_mixing_console.cpp:207
internalAstError:test_cpp_performance.cpp:22
unpreciseMathCall:*

@ -67,7 +67,7 @@ TEST(CppPerformance, FastLFOTuning)
full_test_name += test_info->name();
size_t NB = static_cast<size_t>(1.0f * SAMPLING_FREQUENCY);
float32_t freq = 0.5f;
float32_t freq = 1.5f;
FastLFO lfo1(SAMPLING_FREQUENCY, freq, 440.0f);
lfo1.setFrequency(freq);

Loading…
Cancel
Save