Language Guide / Signal Modifiers
Delay
klang::Delay
A delay line with independently readable taps.
For a fixed-capacity Delay<N>, choose the capacity in samples. Writing an input advances the write position. Calling tap() reads the stored history without writing a new sample. Use a tap within the configured capacity.
Example · Read a 100 ms tap at 48 kHz
Declare Delay<48000> delay; and run this once per input sample.
in >> delay;
delay.tap(4800) >> out;
Example · Allocate a variable-size delay
Use Delay<0> when the capacity is known only at runtime. Declare Delay<0> delay; as a member. In setup, call resize() to allocate the delay line in samples. The tap offset is still in samples and must fit within the allocated capacity.
delay.resize(48000);
In process(), use the configured object for each sample.
in >> delay;
delay.tap(4800) >> out;
Example · Feed an echo back into the delay
Read the delayed sample, mix it with the new input, and use << to write the result back into the delay line. A feedback gain below one makes the repeats decay.
struct FeedbackEcho : Effect {
Delay<48000> delay;
void process() {
in + delay(4800) * 0.4 >> out;
delay << out;
}
};
Audio delay object (fixed size)
More...
#include <klang.h>
template<int SIZE>
struct klang::Delay< SIZE >
Definition at line 4599 of file klang.h.
◆ klang::Delay::Tap
template<int SIZE>
struct klang::Delay< SIZE >::Tap
Definition at line 4692 of file klang.h.
| Class Members |
|
float |
fraction |
|
|
int |
position |
|
◆ Delay()
◆ clear()
◆ input() [1/3]
◆ input() [2/3]
◆ input() [3/3]
◆ lagrange()
Definition at line 4646 of file klang.h.
4646 {
4647
4648 float read =
static_cast<float>(
position - 1) - delay;
4649 if (read < 0.f)
4650 read += SIZE;
4651
4652
4653 int i = static_cast<int>(read);
4654 float x = read - i;
4655
4656
4657 int i0 = (i - 1 + SIZE) % SIZE;
4658 int i1 = i;
4659 int i2 = (i + 1) % SIZE;
4660 int i3 = (i + 2) % SIZE;
4661
4662
4667
4668
4669 float c0 = (-x * (x - 1) * (x - 2)) / 6.0f;
4670 float c1 = ((x + 1) * (x - 1) * (x - 2)) / 2.0f;
4671 float c2 = (-x * (x + 1) * (x - 2)) / 2.0f;
4672 float c3 = (x * (x + 1) * (x - 1)) / 6.0f;
4673
4674 return c0 * y0 + c1 * y1 + c2 * y2 + c3 * y3;
4675 }
◆ max()
◆ operator const signal &() [1/2]
|
|
inlineoverridevirtualinherited |
◆ operator const signal &() [2/2]
|
|
inlineoverridevirtualinherited |
◆ operator()() [1/3]
template<int SIZE>
template<typename TIME >
Definition at line 4719 of file klang.h.
4719 {
4720 if constexpr (std::is_integral_v<TIME>)
4721 return tap((
int)delay);
4722 else if constexpr (std::is_floating_point_v<TIME>)
4723 return tap((
float)delay);
4724 else
4725 return tap((signal)delay);
4726 }
◆ operator()() [2/3]
template<int SIZE>
template<typename TIME >
Definition at line 4709 of file klang.h.
4709 {
4710 if constexpr (std::is_integral_v<TIME>)
4711 return tap((
int)delay);
4712 else if constexpr (std::is_floating_point_v<TIME>)
4713 return tap((
float)delay);
4714 else
4715 return tap((signal)delay);
4716 }
◆ operator()() [3/3]
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()
◆ reset()
◆ set()
Definition at line 4697 of file klang.h.
4697 {
4698 time = samples < SIZE ? (float)samples : SIZE;
4699
4701 if (read < 0.f)
4702 read += SIZE;
4703
4706 }
◆ tap() [1/3]
Definition at line 4678 of file klang.h.
4678 {
4679
4681 const int j = (i + 1) % SIZE;
4682
4683
4685 }
◆ tap() [2/3]
Definition at line 4629 of file klang.h.
4629 {
4630
4631 float read =
static_cast<float>(
position - 1) - delay;
4632 if (read < 0.f)
4633 read += SIZE;
4634
4635
4636 const int i = static_cast<int>(read);
4637 const float fraction = read - i;
4638
4639
4640 const int j = (i + 1) % SIZE;
4641
4642
4644 }
◆ tap() [3/3]
Definition at line 4622 of file klang.h.
4622 {
4624 if (read < 0)
4625 read += SIZE;
4627 }
◆ buffer
◆ in
◆ last
◆ out
◆ position
◆ time