[feature]: ADSR (#15)

closes #14

Reviewed-on: #15
This commit is contained in:
2023-09-06 11:29:46 +03:00
parent 64fa6396bc
commit c50a8335d7
20 changed files with 444 additions and 140 deletions

27
src/Ramp.cpp Normal file
View File

@@ -0,0 +1,27 @@
#include "Ramp.h"
#include "Logger.h"
Ramp::Ramp(float starting_level, float sample_rate) {
m_level = starting_level;
m_sample_rate = sample_rate;
}
Ramp::~Ramp() {}
void Ramp::RampTo(float val, float time) {
m_increment = (val - m_level) / (m_sample_rate * time);
m_counter = (int)(m_sample_rate * time);
write_log("Ramping from: %.1f to: %.1f by: %lf for: %d\n", m_level, val,
m_increment, m_counter);
}
float Ramp::Process() {
if (m_counter > 0) {
m_counter--;
m_level += m_increment;
}
return m_level;
}
bool Ramp::IsCompleted() { return m_counter == 0; }