Language Guide / DSP and Analysis
Envelope
klang::Envelope
A generator defined by time and level breakpoints.
Each point gives an absolute time in seconds from the start of the envelope and an output level. The default interpolation moves linearly between successive points. Call restart() to return to the first point while keeping the configured loop. Use it to shape amplitude or drive another parameter, and read it once per sample when used in the audio path.
Example · Shape a short burst
Envelope shape = { {0, 0}, {0.01, 1}, {0.2, 0} };
Example · Shape a linear envelope with a curve
Keep the envelope in the range 0 to 1 and map its output to a curve. Cubing the value makes the lower part of the range change more gently while preserving the endpoints.
in * cube(signal(shape)) >> out;
Envelope object.
More...
#include <klang.h>
Definition at line 5041 of file klang.h.
◆ Mode
◆ Stage
| Values |
|---|
| Sustain | |
| Release | |
| Off | |
Definition at line 5128 of file klang.h.
◆ Envelope() [1/4]
| klang::Envelope::Envelope |
( |
| ) |
|
|
inline |
Definition at line 5185 of file klang.h.
5185:
ramp(
new Linear()) {
set(Points(0.f, 1.f)); }
std::shared_ptr< Ramp > ramp
void set(const std::vector< Point > &points)
◆ Envelope() [2/4]
| klang::Envelope::Envelope |
( |
const Points & | points | ) |
|
|
inline |
Definition at line 5188 of file klang.h.
std::vector< Point > points
◆ Envelope() [3/4]
| klang::Envelope::Envelope |
( |
std::initializer_list< Point > | points | ) |
|
|
inline |
◆ Envelope() [4/4]
| klang::Envelope::Envelope |
( |
const Envelope & | in | ) |
|
|
inline |
◆ ~Envelope()
| virtual klang::Envelope::~Envelope |
( |
| ) |
|
|
inlinevirtual |
◆ at()
Definition at line 5247 of file klang.h.
5247 {
5248 if (
points.empty())
return 0;
5249 Point last = { 0,
points[0].y };
5252 const float dx =
point.x - last.x;
5253 const float dy =
point.y - last.y;
5254 const float x =
time - last.x;
5255 return dx == 0 ? last.y : (last.y + x * dy / dx);
5256 }
5258 }
5260 }
◆ finished()
| bool klang::Envelope::finished |
( |
| ) |
const |
|
inline |
Definition at line 5287 of file klang.h.
5287 {
5289 }
const Stage getStage() const
◆ getLength()
| float klang::Envelope::getLength |
( |
| ) |
const |
|
inline |
◆ getStage()
| const Stage klang::Envelope::getStage |
( |
| ) |
const |
|
inline |
◆ initialise()
| void klang::Envelope::initialise |
( |
| ) |
|
|
inline |
Definition at line 5292 of file klang.h.
5292 {
5295 }
void restart()
Restart from the first point, preserving the configured loop.
◆ mode()
| Mode klang::Envelope::mode |
( |
| ) |
const |
|
inline |
Definition at line 5395 of file klang.h.
void setTargetTime(const Point &point, float time=0.0)
void(Envelope::* setTargetFunction)(const Point &point, float time)
◆ operator const signal &() [1/2]
|
|
inlineoverridevirtualinherited |
◆ operator const signal &() [2/2]
|
|
inlineoverridevirtualinherited |
◆ operator!=()
| bool klang::Envelope::operator!= |
( |
Stage | stage | ) |
const |
|
inline |
◆ operator()()
Definition at line 3050 of file klang.h.
3050 {
3051 set(std::forward<params>(p)...); return *this;
3052 }
◆ operator*()
◆ operator+()
◆ operator++()
| signal & klang::Envelope::operator++ |
( |
int | | ) |
|
|
inline |
◆ operator-()
◆ operator/()
◆ operator=()
| Envelope & klang::Envelope::operator= |
( |
std::initializer_list< Point > | points | ) |
|
|
inline |
Definition at line 5205 of file klang.h.
5205 {
5207 return *this;
5208 }
◆ operator==()
| bool klang::Envelope::operator== |
( |
Stage | stage | ) |
const |
|
inline |
◆ operator>>()
◆ operator[]()
| const Point & klang::Envelope::operator[] |
( |
int | point | ) |
const |
|
inline |
◆ output()
◆ process()
| void klang::Envelope::process |
( |
| ) |
|
|
inlinevirtual |
Implements klang::Generic::Output< signal >.
Definition at line 5342 of file klang.h.
5342 {
5344
5348 if (!
ramp->isActive()) {
5354 }
5359
5362 }
5363 }
5364 else {
5366 }
5367 } break;
5369 if (!
ramp->isActive())
5371 break;
5373 break;
5374 }
5375 }
void setTarget(const Point &point, float time=0.0)
◆ release()
| virtual void klang::Envelope::release |
( |
float | time, |
|
|
float | level = 0.f ) |
|
inlinevirtual |
◆ reset()
◆ resetLoop()
| void klang::Envelope::resetLoop |
( |
| ) |
|
|
inline |
◆ resize()
| void klang::Envelope::resize |
( |
float | length | ) |
|
|
inline |
Definition at line 5316 of file klang.h.
5316 {
5318 if (old_length == 0.0)
5319 return;
5320
5321 const float multiplier = length / (
fs * old_length);
5322 std::vector<Point>::iterator
point =
points.begin();
5324 point->x *= multiplier;
5326 }
5327
5329 }
◆ restart()
| void klang::Envelope::restart |
( |
| ) |
|
|
inline |
Definition at line 5298 of file klang.h.
5298 {
5308 }
5309 else {
5311 ramp->setValue(1.0f);
5312 }
5313 }
◆ sequence()
| void klang::Envelope::sequence |
( |
| ) |
|
|
inline |
Definition at line 5230 of file klang.h.
5230 {
5233 const float delta =
point.x;
5234 time += delta + 0.00001f;
5236 }
5238 }
◆ set() [1/3]
| void klang::Envelope::set |
( |
const Points & | point | ) |
|
|
inline |
Definition at line 5217 of file klang.h.
5217 {
5219
5220 const Points* pPoint = &
point;
5221 while (pPoint) {
5222 points.push_back(*pPoint);
5223 pPoint = pPoint->next;
5224 }
5225
5227 }
◆ set() [2/3]
| void klang::Envelope::set |
( |
const std::vector< Point > & | points | ) |
|
|
inline |
◆ set() [3/3]
| void klang::Envelope::set |
( |
Ramp * | ramp | ) |
|
|
inline |
◆ setLoop()
| void klang::Envelope::setLoop |
( |
int | startPoint, |
|
|
int | endPoint ) |
|
inline |
Definition at line 5241 of file klang.h.
5241 {
5242 if (startPoint >= 0 && endPoint <
points.size())
5243 loop.
set(startPoint, endPoint);
5244 }
void set(int from, int to)
◆ setMode()
| void klang::Envelope::setMode |
( |
Mode | mode | ) |
|
|
inline |
Definition at line 5388 of file klang.h.
5388 {
5391 else
5393 }
void setTargetRate(const Point &point, float rate=0.0)
◆ setStage()
| void klang::Envelope::setStage |
( |
Stage | stage | ) |
|
|
inline |
◆ setTarget()
| void klang::Envelope::setTarget |
( |
const Point & | point, |
|
|
float | time = 0.0 ) |
|
inline |
◆ setTargetRate()
| void klang::Envelope::setTargetRate |
( |
const Point & | point, |
|
|
float | rate = 0.0 ) |
|
inlineprotected |
Definition at line 5407 of file klang.h.
5407 {
5411 }
5412 else {
5415 }
5416 }
◆ setTargetTime()
| void klang::Envelope::setTargetTime |
( |
const Point & | point, |
|
|
float | time = 0.0 ) |
|
inlineprotected |
◆ loop
| Loop klang::Envelope::loop |
|
protected |
◆ out
◆ point
| int klang::Envelope::point |
|
protected |
◆ points
| std::vector<Point> klang::Envelope::points |
|
protected |
◆ ramp
| std::shared_ptr<Ramp> klang::Envelope::ramp |
|
protected |
◆ setTargetFunction
◆ stage
| Stage klang::Envelope::stage |
|
protected |
◆ time
| float klang::Envelope::time |
|
protected |
◆ timeInc
| float klang::Envelope::timeInc |
|
protected |