2026-11-12 22:37:00 +06:00
|
|
|
#ifndef ENVELOPE
|
|
|
|
|
#define ENVELOPE
|
|
|
|
|
|
2026-11-13 02:02:50 +06:00
|
|
|
#include <cstdint>
|
2026-11-12 22:37:00 +06:00
|
|
|
|
|
|
|
|
enum class Condition{
|
|
|
|
|
Idle,
|
|
|
|
|
Attack,
|
|
|
|
|
Decay,
|
|
|
|
|
Sustain,
|
|
|
|
|
Release
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Envelope{
|
|
|
|
|
|
|
|
|
|
public:
|
2026-11-13 02:02:50 +06:00
|
|
|
Envelope(){
|
2026-11-12 22:37:00 +06:00
|
|
|
condition = Condition::Idle;
|
2026-11-13 02:02:50 +06:00
|
|
|
attack_time = 0.8;
|
|
|
|
|
decay_time = 1.0;
|
|
|
|
|
sustain_level = 0.7;
|
|
|
|
|
release_time = 0.2;
|
|
|
|
|
currnet_amplitude = 0.0;
|
|
|
|
|
rate = 0.0;
|
|
|
|
|
sample_rate = 48000;
|
|
|
|
|
note_is_pressed = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Envelope(double attack, double decay, double sustain, double release){
|
|
|
|
|
condition = Condition::Idle;
|
|
|
|
|
attack_time = attack;
|
|
|
|
|
decay_time = decay;
|
|
|
|
|
sustain_level = sustain;
|
|
|
|
|
release_time = release;
|
|
|
|
|
currnet_amplitude = 0.0;
|
|
|
|
|
rate = 0.0;
|
|
|
|
|
sample_rate = 48000;
|
|
|
|
|
note_is_pressed = false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-12 22:37:00 +06:00
|
|
|
void note_on();
|
|
|
|
|
void note_off();
|
|
|
|
|
double process();
|
|
|
|
|
|
2026-11-14 20:37:48 +06:00
|
|
|
bool is_idle() const;
|
|
|
|
|
|
2026-11-12 22:37:00 +06:00
|
|
|
private:
|
|
|
|
|
Condition condition;
|
2026-11-13 02:02:50 +06:00
|
|
|
|
|
|
|
|
double attack_time;
|
|
|
|
|
|
|
|
|
|
double decay_time;
|
|
|
|
|
|
|
|
|
|
double sustain_level;
|
|
|
|
|
|
|
|
|
|
double release_time;
|
|
|
|
|
|
|
|
|
|
double currnet_amplitude;
|
|
|
|
|
double rate;
|
|
|
|
|
|
|
|
|
|
uint32_t sample_rate;
|
|
|
|
|
|
|
|
|
|
bool note_is_pressed;
|
2026-11-12 22:37:00 +06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|