Language Guide / Signal Modifiers
Modal
klang::Modifiers::Modal
A resonator tuned to a single mode.
Modal synthesis models the sound of a resonating object as a set of modes, each with its own frequency and decay. Excite several resonators together and sum their outputs to model a struck or plucked object.
Set the mode’s frequency in Hz and its decay time in seconds. Feed it an impulse to start a ringing response. Reading the resonator advances the decay, so read it on every sample while the mode is sounding.
Example · Excite a 440 Hz mode
Call the sound’s trigger() method when an event should excite the resonator.
struct Ring : Sound {
Modal mode;
Ring() {
mode.set(440, 0.8);
}
void trigger() {
1 >> mode;
}
void process() {
mode >> out;
}
};
Modal resonator.
More...
#include <klang.h>
Definition at line 7753 of file klang.h.
◆ input() [1/3]
◆ input() [2/3]
◆ input() [3/3]
| void klang::Modifiers::Modal::input |
( |
| ) |
|
|
inlinevirtual |
◆ operator const signal &() [1/2]
|
|
inlineoverridevirtualinherited |
◆ operator const signal &() [2/2]
|
|
inlineoverridevirtualinherited |
◆ operator()()
Definition at line 3098 of file klang.h.
3098 {
3099 set(std::forward<params>(p)...); return *this;
3100 }
◆ operator*()
◆ operator+()
◆ operator-()
◆ operator/()
◆ operator<<()
◆ operator>>()
◆ output()
◆ process()
| void klang::Modifiers::Modal::process |
( |
| ) |
|
|
inlinevirtual |
◆ reset()
◆ set() [1/2]
| void klang::Modifiers::Modal::set |
( |
param | f, |
|
|
param | decay ) |
|
inline |
Definition at line 7765 of file klang.h.
7765 {
7767
7768 constexpr float min_d = 1e-6f;
7769 constexpr float max_d = 0.9999f;
7770
7771 const float w = f.value *
fs.w;
7772 const float d = std::clamp(std::exp(-
pi / (decay *
fs)), min_d, max_d);
7773
7774 a1 = 2.f * d * std::clamp(std::cos(w), -0.9999f, 0.9999f);
7776
7781 }
constexpr constant pi
The mathematical constant, pi (and it's inverse).
References klang::fs, and klang::pi.
◆ set() [2/2]
Definition at line 7760 of file klang.h.
7760 {
7762 this->
gain = std::clamp(
gain.value * 0.05f, -0.05f, 0.05f);
7763 }
void set(param f, param decay, param gain)
References klang::signal::value.
◆ a1
| float klang::Modifiers::Modal::a1 = 0 |
◆ a2
| float klang::Modifiers::Modal::a2 = 0 |
◆ gain
| float klang::Modifiers::Modal::gain = 0.05f |
◆ in
◆ out
◆ y1
| float klang::Modifiers::Modal::y1 = 0 |
◆ y2
| float klang::Modifiers::Modal::y2 = 0 |