mirror of
https://github.com/Fihdi/Eurorack.git
synced 2026-04-12 15:56:04 +00:00
46 lines
2.0 KiB
C++
46 lines
2.0 KiB
C++
#ifndef SynthClave_DecayEnvelope_h
|
|
#define SynthClave_DecayEnvelope_h
|
|
|
|
|
|
//▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
|
|
class DecayEnvelope {
|
|
private:
|
|
bool _stopped = true;
|
|
size_t _length = 100;
|
|
size_t _head;
|
|
float _value;
|
|
|
|
public:
|
|
|
|
//▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
|
|
void SetLengthMs (float length) {
|
|
_length = (size_t)(length * 48.0f);
|
|
}
|
|
|
|
//▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
|
|
void Trigger () {
|
|
_head = 0;
|
|
_stopped = false;
|
|
}
|
|
|
|
//▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
|
|
float GetValue () {
|
|
return _value;
|
|
}
|
|
|
|
//▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
|
|
float Process () {
|
|
if (_stopped) return 0.0f;
|
|
if (++_head >= _length) {
|
|
_stopped = true;
|
|
return 0.0f;
|
|
};
|
|
_value = 1.0f - (float)(_head) / (float)(_length);
|
|
return _value * _value * _value;
|
|
}
|
|
};
|
|
|
|
|
|
//▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
|
|
#endif // SynthClave_DecayEnvelope_h
|