|
hydrogen 1.2.3
|
Attack Decay Sustain Release envelope. More...
#include <Adsr.h>
Public Types | |
| enum class | State { Attack = 0 , Decay , Sustain , Release , Idle } |
| possible states More... | |
Public Member Functions | |
| ADSR (const std::shared_ptr< ADSR > other) | |
| copy constructor | |
| ADSR (unsigned int attack=0, unsigned int decay=0, float sustain=1.0, unsigned int release=1000) | |
| constructor | |
| ~ADSR () | |
| destructor | |
| bool | applyADSR (float *pLeft, float *pRight, int nFinalBufferPos, int nReleaseFrame, float fStep) |
| Compute and apply successive ADSR values to stereo buffers. | |
| void | attack () |
| Sets m_state to State::Attack. | |
| unsigned int | getAttack () |
| unsigned int | getDecay () |
| unsigned int | getRelease () |
| State | getState () const |
| float | getSustain () |
| float | release () |
| Sets m_state to State::Release and return the current m_fReleaseValue. | |
| void | setAttack (unsigned int value) |
| void | setDecay (unsigned int value) |
| void | setRelease (unsigned int value) |
| void | setSustain (float value) |
| QString | toQString (const QString &sPrefix="", bool bShort=true) const override |
| Formatted string version for debugging purposes. | |
Public Member Functions inherited from Object< ADSR > | |
| Object () | |
| Object (const Object< ADSR > &other) | |
Public Member Functions inherited from Base | |
| Base () | |
| Base (const Base &other) | |
| virtual const char * | class_name () const |
| void | Print (bool bShort=true) const |
| Prints content of toQString() via DEBUGLOG. | |
Static Public Member Functions | |
| static QString | StateToQString (State state) |
Static Public Member Functions inherited from Base | |
| static const char * | _class_name () |
| return the class name | |
| static QString | base_clock (const QString &sMsg) |
| Measures the current time and stores it in __last_clock. | |
| static QString | base_clock_in (const QString &sMsg) |
| static int | bootstrap (Logger *logger, bool count=false) |
| must be called before any Object instantiation ! | |
| static bool | count_active () |
| static int | getAliveObjectCount () |
| static object_map_t | getObjectMap () |
| static Logger * | logger () |
| return the logger instance | |
| static int | objects_count () |
| static void | printObjectMapDiff (object_map_t map) |
| Creates the difference between a snapshot of the object map and its current state and prints it to std::cout. | |
| static void | set_count (bool flag) |
| enable/disable class instances counting | |
| static void | write_objects_map_to (std::ostream &out, object_map_t *map=nullptr) |
| output the full objects map to a given ostream | |
| static void | write_objects_map_to_cerr () |
| output objects map to stderr | |
Private Member Functions | |
| void | normalise () |
Private Attributes | |
| float | m_fFramesInState |
| Tracks the number of frames passed in the current m_state. | |
| double | m_fQ |
| exponential decay state | |
| float | m_fReleaseValue |
| value when the release state was entered | |
| float | m_fSustain |
| Sustain level. | |
| float | m_fValue |
| current value | |
| unsigned int | m_nAttack |
| Attack phase duration in frames. | |
| unsigned int | m_nDecay |
| Decay phase duration in frames. | |
| unsigned int | m_nRelease |
| Release phase duration in frames. | |
| State | m_state |
| current state | |
Additional Inherited Members | |
Static Public Attributes inherited from Base | |
| static QString | sPrintIndention = " " |
| String used to format the debugging string output of some core classes. | |
Protected Member Functions inherited from Object< ADSR > | |
| ~Object () | |
Protected Member Functions inherited from Base | |
| ~Base () | |
Static Protected Member Functions inherited from Base | |
| static void | registerClass (const char *name, const atomic_obj_cpt_t *counters) |
Static Protected Attributes inherited from Base | |
| static bool | __count = false |
| should we count class instances | |
| static timeval | __last_clock = { 0, 0 } |
| static Logger * | __logger = nullptr |
|
strong |
| ADSR | ( | unsigned int | attack = 0, |
| unsigned int | decay = 0, | ||
| float | sustain = 1.0, | ||
| unsigned int | release = 1000 ) |
| bool applyADSR | ( | float * | pLeft, |
| float * | pRight, | ||
| int | nFinalBufferPos, | ||
| int | nReleaseFrame, | ||
| float | fStep ) |
Compute and apply successive ADSR values to stereo buffers.
Apply ADSR envelope to stereo pair sample fragments.
In case the ADSR still hold its default values, the provided buffers aren't altered.
Conceptionally it multiplies the first m_nAttack frames of a sample with a rising attack exponential, the successive m_nDecay frames with a falling decay exponential, and remaining frames with m_fSustain. Which of these steps are covered in a run of applyADSR() depends on m_state.
If no note length was specified by the user in the GUI, m_fSustain will be applied till the end of the corresponding sample and ADSR application won't enter release phase which would apply a falling exponential for m_nRelease frames and zero all following frames.
| pLeft | left-channel audio buffer |
| pRight | right-channel audio buffer |
| nFinalBufferPos | Up to which frame pLeft and pRight will be processed. |
| nReleaseFrame | Frame number indicating the end of the note or sample at which ADSR processing will enter the release phase. |
| fStep | the increment to be added to m_fFramesInState. |
This function manages the current state of the ADSR state machine, and applies envelope calculations appropriate to each phase.
| void attack | ( | ) |
Sets m_state to State::Attack.
|
inline |
| float release | ( | ) |
Sets m_state to State::Release and return the current m_fReleaseValue.
State setting is only applied if the ADSR is not in State::Idle.
|
overridevirtual |
Formatted string version for debugging purposes.
| sPrefix | String prefix which will be added in front of every new line |
| bShort | Instead of the whole content of all classes stored as members just a single unique identifier will be displayed without line breaks. |
Reimplemented from Base.
|
private |
Tracks the number of frames passed in the current m_state.
It is used to determine whether ADSR processing should proceed into the next state and required if multiple process cycles of the H2Core::Sampler render the same state.
Note that it is given in float instead of integer (the basic unit for frames in the H2Core::AudioEngine) in order to account for processing while resampling the original audio.
|
private |
|
private |
|
private |
|
private |