sfizz/sources/ADSREnvelope.h

36 lines
888 B
C
Raw Normal View History

2019-08-22 23:39:26 +02:00
#pragma once
#include <absl/types/span.h>
2019-08-21 01:00:07 +02:00
namespace sfz
{
template<class Type>
class ADSREnvelope
{
public:
ADSREnvelope() = default;
void reset(int attack, int release, Type sustain=1.0, int delay = 0, int decay = 0, int hold = 0, Type start=0.0, Type depth=1) noexcept;
Type getNextValue() noexcept;
void getBlock(absl::Span<Type> output) noexcept;
void startRelease(int releaseDelay) noexcept;
2019-08-24 15:32:06 +02:00
bool isSmoothing() noexcept;
2019-08-21 01:00:07 +02:00
private:
enum class State
{
Delay, Attack, Hold, Decay, Sustain, Release, Done
2019-08-21 01:00:07 +02:00
};
State currentState { State::Done };
Type currentValue { 0.0 };
Type step { 0.0 };
int delay { 0 };
int attack { 0 };
int decay { 0 };
int release { 0 };
int hold { 0 };
Type start { 0 };
Type peak { 0 };
Type sustain { 0 };
int releaseDelay { 0 };
bool shouldRelease { false };
2019-08-21 01:00:07 +02:00
};
}