fsh::stk
fantastic spatial holophonic synthesis toolkit
Loading...
Searching...
No Matches
ADSR.h
1/***************************************************************************************************
2 ██████ █████ █████ █████
3 ███░░███ ░░███ ░░███ ░░███
4 ░███ ░░░ █████ ░███████ ██ ██ █████ ███████ ░███ █████
5 ███████ ███░░ ░███░░███ ░░ ░░ ███░░ ░░░███░ ░███░░███
6 ░░░███░ ░░█████ ░███ ░███ ░░█████ ░███ ░██████░
7 ░███ ░░░░███ ░███ ░███ ░░░░███ ░███ ███ ░███░░███
8 █████ ██████ ████ █████ ██ ██ ██████ ░░█████ ████ █████
9 ░░░░░ ░░░░░░ ░░░░ ░░░░░ ░░ ░░ ░░░░░░ ░░░░░ ░░░░ ░░░░░
10
11 fantastic spatial holophonic synthesis tool kit
12
13 copyright (c) fabian hummel
14 www.github.com/fshstk
15 www.fshstk.com
16
17 this file is part of the fantastic spatial holophonic synthesis toolkit (fsh::stk)
18 fsh::stk is free software: it is provided under the terms of the gnu general public license v3.0
19 www.gnu.org/licenses/gpl-3.0
20***************************************************************************************************/
21
22#pragma once
23#include "EnvelopeFollower.h"
24
25namespace fsh::synth
26{
39class ADSR
40{
41public:
43 struct Params
44 {
45 double attack;
46 double decay;
47 double sustain;
48 double release;
49 };
50
52 void setSampleRate(double);
53
55 void setParams(const Params&);
56
58 auto isActive() const -> bool;
59
61 auto getNextValue() -> double;
62
64 void noteOn();
65
67 void noteOff();
68
70 void reset();
71
72private:
73 enum class Phase
74 {
75 Idle,
76 Attack,
77 Decay,
78 Sustain,
79 Release,
80 };
81
82 Params _params;
83 Phase _phase;
85
86 void updateEnvelope();
87};
88} // namespace fsh::synth
ADSR envelope.
Definition ADSR.h:40
auto isActive() const -> bool
Returns true if the envelope is currently in a non-idle state.
Definition ADSR.cpp:27
void setSampleRate(double)
Set the sample rate in Hz.
Definition ADSR.cpp:103
auto getNextValue() -> double
Compute the envelope's next value.
Definition ADSR.cpp:32
void noteOn()
Start the envelope's attack phase.
Definition ADSR.cpp:85
void noteOff()
Trigger the envelope's release phase.
Definition ADSR.cpp:91
void reset()
Reset the envelope to its idle state.
Definition ADSR.cpp:97
void setParams(const Params &)
Set the envelope's parameters.
Definition ADSR.cpp:108
Smoothed value tracking with separate attack/decay times.
Definition EnvelopeFollower.h:44
Envelope parameters.
Definition ADSR.h:44
double attack
attack time in milliseconds
Definition ADSR.h:45
double sustain
sustain level in [0, 1]
Definition ADSR.h:47
double release
release time in milliseconds
Definition ADSR.h:48
double decay
decay time in milliseconds
Definition ADSR.h:46