sfizz/sources/ADSREnvelope.h
2019-08-25 14:01:03 +02:00

42 lines
No EOL
994 B
C++

#pragma once
#include "Helpers.h"
#include <absl/types/span.h>
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;
bool isSmoothing() noexcept;
private:
enum class State {
Delay,
Attack,
Hold,
Decay,
Sustain,
Release,
Done
};
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 };
LEAK_DETECTOR(ADSREnvelope);
};
}