wip: adsr with ramp
This commit is contained in:
18
inc/ADSR.h
18
inc/ADSR.h
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "Effect.h"
|
||||
#include <cstddef>
|
||||
#include "Ramp.h"
|
||||
|
||||
struct ADSRParameters {
|
||||
float attack_time; // Attack time in seconds
|
||||
@@ -9,23 +10,26 @@ struct ADSRParameters {
|
||||
float release_time;
|
||||
};
|
||||
|
||||
enum ADSRState { Attack, Decay, Sustain, Release };
|
||||
enum ADSRState { Off, Attack, Decay, Sustain, Release };
|
||||
|
||||
class ADSR : public Effect {
|
||||
private:
|
||||
ADSRParameters m_parameters;
|
||||
ADSRState m_state;
|
||||
std::size_t m_counter;
|
||||
void set_state(std::size_t attack_samples, std::size_t decay_samples,
|
||||
std::size_t release_samples);
|
||||
void process_sample(float* sample, std::size_t attack_samples,
|
||||
std::size_t decay_samples, std::size_t release_samples);
|
||||
Ramp *m_ramp;
|
||||
|
||||
void process_sample(float* sample);
|
||||
bool is_attack_elapsed();
|
||||
bool is_decay_elapsed();
|
||||
bool is_release_elapsed();
|
||||
void recheck_state();
|
||||
public:
|
||||
ADSR(/* args */);
|
||||
ADSR(ADSRParameters param);
|
||||
~ADSR();
|
||||
void RetriggerState() override;
|
||||
void OnSetNote() override;
|
||||
void OnUnsetNote() override;
|
||||
//void RetriggerState() override;
|
||||
void Process(std::vector<float>& samples) override;
|
||||
void Reset();
|
||||
};
|
||||
|
||||
@@ -6,6 +6,8 @@ class Effect {
|
||||
public:
|
||||
Effect(/* args */){};
|
||||
~Effect(){};
|
||||
virtual void RetriggerState(){};
|
||||
virtual void OnSetNote(){};
|
||||
virtual void OnUnsetNote(){};
|
||||
//virtual void RetriggerState(){};
|
||||
virtual void Process(std::vector<float>& samples){};
|
||||
};
|
||||
|
||||
17
inc/Ramp.h
Normal file
17
inc/Ramp.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
class Ramp
|
||||
{
|
||||
private:
|
||||
float m_level;
|
||||
float m_sample_rate;
|
||||
float m_increment;
|
||||
int m_counter;
|
||||
public:
|
||||
Ramp(float starting_level, float sample_rate);
|
||||
~Ramp();
|
||||
void RampTo(float value, float time);
|
||||
float Process();
|
||||
bool IsCompleted();
|
||||
};
|
||||
|
||||
@@ -11,12 +11,14 @@ class Synth {
|
||||
private:
|
||||
bool is_note_triggered;
|
||||
std::vector<Oscillator*> m_oscillators;
|
||||
Adder m_adder;
|
||||
std::vector<Effect*> m_effects;
|
||||
// OscillatorUI* ui_oscillators;
|
||||
// Note m_current_note;
|
||||
std::vector<float> m_out_signal;
|
||||
void zero_signal();
|
||||
void get_note();
|
||||
void trigger_note_on_effects();
|
||||
void untrigger_note_on_effects();
|
||||
void apply_effects();
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user