wip: adsr with ramp

This commit is contained in:
2023-09-04 22:30:37 +04:00
parent 73aae9a490
commit d883bbbf12
13 changed files with 204 additions and 77 deletions

29
src/Ramp.cpp Normal file
View File

@@ -0,0 +1,29 @@
#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 value, float time) {
m_increment = (value - m_level) / (m_sample_rate * time);
m_counter = (int)(m_sample_rate * time);
write_log("Ramping from: %.1f to: %.1f by: %.1f for: %d\n", m_level, value, 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;
}