wip: adsr with ramp
This commit is contained in:
29
src/Ramp.cpp
Normal file
29
src/Ramp.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user