tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_Envelope.cpp
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2018
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7*/
8
9
10namespace tracktion { inline namespace engine
11{
12
13//==============================================================================
14ExpEnvelope::ExpEnvelope()
15{
16 calculateAttackTime();
17 calculateDecayTime();
18 calculateReleaseTime();
19}
20
21void ExpEnvelope::calculateAttackTime()
22{
23 float samples = float (sampleRate * attackTime);
24
25 attackCoeff = std::exp (-std::log ((1.0f + attackTCO) / attackTCO) / float (samples));
26 attackOffset = (1.0f + attackTCO) * (1.0f - attackCoeff);
27}
28
29void ExpEnvelope::calculateDecayTime()
30{
31 float samples = float (sampleRate * decayTime);
32
33 decayCoeff = std::exp (-std::log ((1.0f + decayTCO) / decayTCO) / samples);
34 decayOffset = (sustainLevel - decayTCO) * (1.0f - decayCoeff);
35}
36
37void ExpEnvelope::calculateReleaseTime()
38{
39 float samples = float (sampleRate * releaseTime);
40
41 releaseCoeff = std::exp (-std::log ((1.0f + releaseTCO) / releaseTCO) / samples);
42 releaseOffset = -releaseTCO * (1.0f - releaseCoeff);
43}
44
45}} // namespace tracktion { inline namespace engine
T exp(T... args)
T log(T... args)
typedef float