22static inline float _sqrt(
float x) {
return __builtin_sqrtf(x); }
23static inline float _abs(
float x) {
return __builtin_fabsf(x); }
36#if defined(__WIN32__) || defined(WIN32)
37#define THREAD_LOCAL thread_local
44#if defined(DEBUG) || defined(_DEBUG)
51#define GRAPH_SIZE 44100
59 template<
typename TYPE> TYPE
sqrt(TYPE x) {
return SQRT(
x); }
60 template<
typename TYPE> TYPE
abs(TYPE x) {
return ABS(
x); }
64#define IS_SIMPLE_TYPE(type)
65 static_assert(!std::is_polymorphic_v<type>, "signal has virtual table");
66 static_assert(!std::has_virtual_destructor_v<type>, "signal has virtual destructor");
67 static_assert(std::is_trivially_copyable_v<type>, "signal is not trivially copyable");
68 static_assert(std::is_trivially_copy_assignable_v<type>, "signal is not trivially copy assignable");
69 static_assert(std::is_trivially_copy_constructible_v<type>, "signal is not trivially copy assignable");
70 static_assert(std::is_trivially_destructible_v<type>, "signal is not trivially copy assignable");
71 static_assert(std::is_trivially_move_assignable_v<type>, "signal is not trivially copy assignable");
72 static_assert(std::is_trivially_move_constructible_v<type>, "signal is not trivially copy assignable");
85 #define DENORMALISE 1.175494e-38f
92 :
d(value),
f(
static_cast<
float>(value)),
i(
static_cast<
int>(value)),
inv(value == 0.0f ? 0.0f :
static_cast<
float>(1.0 / value)) { }
99 constexpr operator float()
const noexcept {
return f; }
102 float operator^(
float x)
const {
return std::pow(
f, x); }
103 float operator^(
int x)
const {
return static_cast<
float>(std::pow(
d, x)); }
104 float operator^(
double x)
const {
return static_cast<
float>(std::pow(
d, x)); }
107 #define CONSTANT constexpr constant
109#if __cplusplus
== 201703L
110 #pragma warning(disable:4996
)
112 template <
typename T>
113 inline constexpr bool is_literal = std::is_literal_type_v<T>;
116 template <
typename T>
120 template<
typename Base,
typename Derived>
122 return std::is_base_of_v<Base, Derived>;
125 template<
typename Head,
typename... Tail>
127 using T = std::decay_t<
decltype(head)>;
128 return std::is_scalar_v<T> && ((
sizeof... (Tail)) == 0 || are_scalars(std::forward<
decltype(tail)>(tail)...));
131 template <
typename BASE,
int EXP>
132 inline constexpr BASE
poweri(BASE base) {
134 constexpr bool negative = EXP < 0;
135 int exp = negative ? -EXP : EXP;
142 return negative ? 1 / result : result;
145 template <
typename BASE,
typename EXP>
146 using power_t =
typename std::conditional_t<std::is_integral_v<BASE>,
float, BASE>;
149 template <
typename BASE,
typename EXP, std::enable_if_t < is_literal<EXP>,
bool>>
150 inline constexpr power_t<BASE, EXP>
power(BASE base, EXP exp) {
151 if constexpr (std::is_integral_v<EXP>) {
153 case 0:
return (BASE)1;
155 case 2:
return base * base;
156 case 3:
return base * base * base;
157 case 4:
return base * base * base * base;
158 case -1:
return (BASE)1 / base;
159 case -2:
return (BASE)1 / (base * base);
160 case -3:
return (BASE)1 / (base * base * base);
161 case -4:
return (BASE)1 / (base * base * base * base);
163 return poweri<BASE, exp>(base);
165 }
else if constexpr (std::is_floating_point_v<EXP>) {
166 if constexpr (exp == (EXP)0)
return 1;
167 else if constexpr (exp == (EXP)1)
return base;
168 else if constexpr (exp == (EXP)2)
return base * base;
169 else if constexpr (exp == (EXP)3)
return base * base * base;
170 else if constexpr (exp == (EXP)4)
return base * base * base * base;
171 else if constexpr (exp == (EXP)-1)
return 1 / base;
172 else if constexpr (exp == (EXP)-2)
return 1 / (base * base);
173 else if constexpr (exp == (EXP)-3)
return 1 / (base * base * base);
174 else if constexpr (exp == (EXP)-4)
return 1 / (base * base * base * base);
176 return (BASE)std::pow(base, exp);;
180 template <
typename BASE,
typename EXP>
181 inline constexpr power_t<BASE, EXP>
power(BASE base, EXP exp) {
182 if constexpr (std::is_integral_v<BASE>) {
183 return power(
float(base), exp);
184 }
else if constexpr (std::is_integral_v<EXP>) {
186 case 0:
return (BASE)1;
188 case 2:
return base * base;
189 case 3:
return base * base * base;
190 case 4:
return base * base * base * base;
191 case -1:
return (BASE)1 / base;
192 case -2:
return (BASE)1 / (base * base);
193 case -3:
return (BASE)1 / (base * base * base);
194 case -4:
return (BASE)1 / (base * base * base * base);
196 }
else if constexpr (std::is_floating_point_v<EXP>) {
197 if (base == (BASE)10)
return (power_t<BASE, EXP>)::exp(exp * (EXP)2.3025850929940456840179914546843642076011014886287729760333279009);
198 else if (exp == (EXP)0)
return (power_t<BASE, EXP>)1;
199 else if (exp == (EXP)1)
return base;
200 else if (exp == (EXP)2)
return base * base;
201 else if (exp == (EXP)3)
return base * base * base;
202 else if (exp == (EXP)4)
return base * base * base * base;
203 else if (exp == (EXP)-1)
return (power_t<BASE, EXP>)1 / base;
204 else if (exp == (EXP)-2)
return (power_t<BASE, EXP>)1 / (base * base);
205 else if (exp == (EXP)-3)
return (power_t<BASE, EXP>)1 / (base * base * base);
206 else if (exp == (EXP)-4)
return (power_t<BASE, EXP>)1 / (base * base * base * base);
208 return power_t<BASE, EXP>(std::pow(base, exp));
212 template<
typename TYPE1,
typename TYPE2>
inline TYPE1
min(TYPE1 a, TYPE2 b) {
return a <
b ?
a : (
TYPE1)
b; };
215 template<
typename TYPE1,
typename TYPE2>
inline TYPE1
max(TYPE1 a, TYPE2 b) {
return a >
b ?
a : (
TYPE1)
b; };
227 template<
typename TYPE>
231 inline static void random(
const unsigned int seed) { srand(seed); }
237 template<
typename TYPE,
int CAPACITY>
249 void add(
const TYPE& item) {
267 for (
unsigned int i = 0;
i <
count;
i++)
276 for (
unsigned int i = 0;
i <
count;
i++)
284 for (
unsigned int i = 0;
i <
count;
i++)
306 Array(std::initializer_list<TYPE> init_list) {
345 return strcmp(
string, in) == 0;
469 const unsigned int bits = *(
const unsigned int*)&
value;
470 return !(bits & 0x7F800000) && (bits & 0x007FFFFF);
483 static_assert(
sizeof(
signal) ==
sizeof(
float),
"signal != float");
501 template<
int CHANNELS = 2>
536 template <
typename... Args,
typename = std::enable_if_t<(std::is_convertible_v<Args,
signal> && ...)>>
537 signals(Args&... initial) : value{ initial... } { }
539 template <
typename... Args,
typename = std::enable_if_t<(std::is_scalar_v<Args> && ...)>>
540 signals(Args... initial) : value { initial... } { }
632 struct Conversion :
public signal {
673 static_assert(
sizeof(
param) ==
sizeof(
float),
"param != float");
686 params(
param p) : parameters(
new param[1]), size(1) { parameters[0] = p; }
687 params(std::initializer_list<
param> params) : parameters(
new param[params.size()]), size((
int)params.size()) {
689 for(
param p : params)
690 parameters[index++] = p;
693 param& operator[](
int index) {
return parameters[index]; }
698 const unsigned int i = (((
unsigned int)(x * (
float(UINT_MAX) + 1.f) / y)) >> 9) | 0x3f800000;
699 return (*(
const float*)&i - 1.f) * y;
703 const unsigned long long i = (((
unsigned long long)(x * (
double(ULLONG_MAX) + 1.0) / y)) >> 12ULL) | 0x7FF0000000000000ULL;
704 return (*(
const double*)&i - 1.0) * y;
708 const unsigned int i = ((
unsigned int)(x * (
float(UINT_MAX) + 1.f)) >> 9) | 0x3f800000;
709 return *(
const float*)&i - 1.f;
713 const unsigned long long i = (((
unsigned long long)(x * (
double(ULLONG_MAX) + 1.0))) >> 12ULL) | 0x7FF0000000000000ULL;
714 return (*(
const double*)&i - 1.0);
718 constexpr float twoPi =
float(2.0 * 3.1415926535897932384626433832795);
719 const unsigned int i = (((
unsigned int)(x * (
float(UINT_MAX) + 1.f) / twoPi)) >> 9) | 0x3f800000;
720 return (*(
const float*)&i - 1.f) * twoPi;
724 constexpr float twoPi =
float(2.0 * 3.1415926535897932384626433832795);
725 const unsigned int i = (x >> 9) | 0x3f800000;
726 return (*(
const float*)&i - 1.f) * twoPi;
730 constexpr double twoPi = (2.0 * 3.1415926535897932384626433832795);
731 const unsigned long long i = (((
unsigned long long)(x * (
double(ULLONG_MAX) + 1.0) / twoPi)) >> 12ULL) | 0x7FF0000000000000ULL;
732 return (*(
const double*)&i - 1.0) * twoPi;
737 constexpr double size =
double(
SIZE);
739 const unsigned long long i = (((
unsigned long long)(
x * (
double(ULLONG_MAX) + 1.0) *
sizeInv)) >> 12ULL) | 0x7FF0000000000000ULL;
740 return (*(
const double*)&
i - 1.0) *
size;
746 float v[4][4] = { 0 };
749 const float*
operator[](
int col)
const {
return v[col]; }
751 float&
operator()(
int col,
int row) {
return v[col][row]; }
752 float operator()(
int col,
int row)
const {
return v[col][row]; }
755 return {
v[0][0] * in
[0
] +
v[0][1] * in
[1
] +
v[0][2] * in
[2
] +
v[0][3] * in
[3
],
756 v[1][0] * in
[0
] +
v[1][1] * in
[1
] +
v[1][2] * in
[2
] +
v[1][3] * in
[3
],
757 v[2][0] * in
[0
] +
v[2][1] * in
[1
] +
v[2][2] * in
[2
] +
v[2][3] * in
[3
],
758 v[3][0] * in
[0
] +
v[3][1] * in
[1
] +
v[3][2] * in
[2
] +
v[3][3] * in
[3
] };
763 return { m
[0
][0] * in
[0
] + m
[0
][1] * in
[1
] + m
[0
][2] * in
[2
] + m
[0
][3] * in
[3
],
772 template<
typename TYPE,
typename _TYPE>
774 static constexpr TYPE twoPi = TYPE(2.0 * 3.1415926535897932384626433832795);
781 phase(TYPE phase = 0) {
782 if constexpr (std::is_same<TYPE,
double>()) {
783 constexpr TYPE FUINTMAX = TYPE(ULLONG_MAX + 1.0) / twoPi;
786 }
else if constexpr (std::is_same<TYPE,
float>()) {
787 constexpr TYPE FUINTMAX = TYPE(UINT_MAX + 1.0) / twoPi;
794 operator TYPE()
const {
795 const _TYPE phase = (i >> 12ULL) | 0x3FF0000000000000ULL;
796 return (*(
const TYPE*)&phase - TYPE(1.0)) * twoPi;
817 if (increment >= (2 *
pi))
838 if (value > increment
.size)
860 THREAD_LOCAL
static char buffer[32] = { 0 };
861 const char*
const notes[12] = {
"C",
"C#/Db",
"D",
"D#/Eb",
"E",
"F",
"F#/Gb",
"G",
"G#/Ab",
"A",
"A#/Bb",
"B" };
862 snprintf(buffer, 32,
"%s%d", notes[(
int)
value % 12], (
int)
value / 12);
943 THREAD_LOCAL
static Conversion
dB;
970 Size(
int x = -1,
int y = -1,
int width = -1,
int height = -1)
1032 template<
typename TYPE>
Control& operator<<(
const TYPE& in) {
value =
in;
return *
this; }
1063 inline static Control Dial(
const char* name,
float min = 0.f,
float max = 1.f,
float initial = 0.f)
1072 inline static Control Slider(
const char* name,
float min = 0.f,
float max = 1.f,
float initial = 0.f)
1075 template<
typename... Options>
1085 inline static Control Meter(
const char* name,
float min = 0.f,
float max = 1.f,
float initial = 0.f)
1100 items[count++] = control;
1109 for(
auto control : controls)
1114 items[count]
.name = name;
1115 items[count]
.type = type;
1116 items[count]
.min = min;
1117 items[count]
.max = max;
1119 items[count]
.size = size;
1120 items[count++]
.value = initial;
1124 bool changed =
false;
1125 for (
unsigned int c = 0; c < count; c++) {
1162 items[count++] = preset;
1166 for (
int p = 0; p < 128 && presets
[p
].name[0]; p++)
1171 for(
auto preset : presets)
1175 template<
typename... Values>
1176 void add(
const char* name,
const Values... values) {
1202 const unsigned int mask = 0xFFFFFFFF;
1216 buffer(
float* buffer,
int size,
float initial)
1235 _controlfp_s(
nullptr, _DN_FLUSH, _MCW_DN);
1256 else for (
int s = 0; s <
size; s++)
1269 const float f = floorf(offset);
1270 const float frac = offset - f;
1272 const int i = (
int)offset;
1273 const int j = (i == (
size - 1)) ? 0 : (i + 1);
1279 return *(
const signal*)&
samples[index];
1337 template<
typename SIGNAL>
1343 virtual const SIGNAL&
input()
const {
return in; }
1346 virtual void operator<<(
const SIGNAL& source) {
in = source; input(); }
1347 virtual void input(
const SIGNAL& source) {
in = source; input(); }
1355 template<
typename SIGNAL>
1363 template<
typename TYPE>
1394 template<
typename SIGNAL>
inline SIGNAL
operator-(
Output<SIGNAL>& output,
float other) {
return SIGNAL(output) - other; }
1395 template<
typename SIGNAL>
inline SIGNAL
operator/(
Output<SIGNAL>& output,
float other) {
return SIGNAL(output) / other; }
1403 template<
typename SIGNAL>
1405 using Output<SIGNAL>::out;
1408 template<
typename... params>
1410 set(
p...);
return *
this;
1413 using Output<SIGNAL>::operator>>;
1414 using Output<SIGNAL>::process;
1415 operator const SIGNAL& ()
override { process();
return out; }
1416 operator const SIGNAL& ()
const override {
return out; }
1421 virtual void set(
param) { };
1441 template<
typename SIGNAL>
1443 using Input<SIGNAL>::in;
1444 using Output<SIGNAL>::out;
1450 operator const SIGNAL&()
const override {
return out; }
1452 using Input<SIGNAL>::input;
1456 template<
typename... params>
1458 set(
p...);
return *
this;
1463 virtual void set(
param) { };
1475 template<
typename SIGNAL,
typename... Args>
1496 template <
typename T>
1497 inline void hash_combine(std::size_t& seed,
const T& value)
const {
1503 template <
typename Tuple, std::size_t Index = 0>
1504 std::size_t hash_tuple(
const Tuple& tuple)
const {
1514 operator
void*() {
return this; }
1518 std::function<
float(Args...)> function;
1520 static constexpr unsigned int ARGS =
sizeof...(Args);
1526 template <
typename First,
typename... Rest>
1527 std::tuple<Rest...>
tail(
const std::tuple<First, Rest...>& t)
const {
1531 template<
typename FunctionPtr>
1534 template<
typename FunctionPtr>
1536 : function(std::forward<FunctionPtr>(function)) {}
1538 template<
typename FunctionPtr,
typename... OtherArgs>
1545 std::get<0>(
inputs) = in.value;
1549 template <
typename First,
typename... Rest>
1550 First
first(First first, Rest...) {
return first; }
1553 template<
typename... FuncArgs>
1555 if constexpr (
ARGS > 1 &&
sizeof...(FuncArgs) == 1){
1556 in = first(args...);
1557 std::get<0>(
inputs) = in.value;
1559 }
else if constexpr (
ARGS ==
sizeof...(FuncArgs)){
1560 in = first(args...);
1561 inputs = std::tuple<Args...>(args...);
1563 }
else if constexpr (
sizeof...(FuncArgs) == (
ARGS - 1)){
1564 inputs = std::tuple<Args...>(in.value, args...);
1567 in = first(args...);
1568 std::get<0>(
inputs) = in.value;
1574 template<
typename... FuncArgs>
1575 const float operator()(
const FuncArgs&... args)
const {
1586 }
else if constexpr (
sizeof...(
FuncArgs) == (
ARGS - 1)) {
1594 if constexpr (
ARGS > 1)
1600 template<
typename... FuncArgs>
1602 static_assert(
sizeof...(
FuncArgs) == (
ARGS - 1),
"with() arguments must have all but first argument.");
1611 if constexpr (
ARGS > 1)
1612 return std::apply(function,
inputs);
1614 return function(in);
1626 template <
typename... Args>
1629 template <
typename... Args>
1644 bool valid()
const {
return !::isnan(
x) && !::isinf(
x) && !::isnan(
y); }
1664 add({ (
double)Array::size(), y });
1667 template<
typename SIGNAL,
typename... Args>
1677 for (
int i = 0;
i <=
size;
i++) {
1684 template<
typename RETURN,
typename ARG>
1694 for (
int i = 0;
i <=
size;
i++) {
1703 for (
unsigned int i = 0;
i <
count;
i++)
1733 if (!series.count)
return;
1735 for (
unsigned int p = 0; p < series.count; p++) {
1736 const Point& pt = series[p];
1737 if (pt.valid() && !::isinf(pt.*axis)) {
1738 if (!points || pt.*axis <
min)
min = pt.*axis;
1739 if (!points || pt.*axis >
max)
max = pt.*axis;
1743 if (std::abs(
max) < 0.0000000001)
max = 0;
1744 if (std::abs(
min) < 0.0000000001)
min = 0;
1745 if (std::abs(
max) > 1000000000.0)
max = 0;
1746 if (std::abs(
min) > 1000000000.0)
min = 0;
1768 bool isActive()
const {
1792 axes.x.min = min;
axes.x.max = max;
1807 axes.x.min = x_min;
axes.x.max = x_max;
1808 axes.y.min = y_min;
axes.y.max = y_max;
1818 template<
typename SIGNAL,
typename... Args>
1832 template<
typename TYPE>
1846 template<
typename FUNCTION,
typename... VALUES>
1847 void plot(FUNCTION f, VALUES... values) {
1861 template<
typename TYPE>
1867 template<
typename TYPE>
1873 template<
typename TYPE>
1881 clear();
return operator+=(values);
1886 for (
const auto& value : values)
1897 template<
typename TYPE>
Graph& operator<<(TYPE& in) {
add(
in);
return *
this; }
1898 template<
typename TYPE>
Graph& operator<<(
const TYPE& in) {
add(
in);
return *
this; }
1905 if (!axes.x.valid()) {
1909 if (!axes.y.valid() && axes.y.max != 0)
1912 if (!axes.y.valid()) {
1916 if (!axes.y.valid() && axes.y.max != 0)
1926 if (count <
data.count)
1930 if (count <
data[s].count)
1931 data[s].count = count;
1947 template<
typename SIGNAL>
1993 template <
typename TYPE,
typename SIGNAL>
1994 using GeneratorOrModifier =
typename std::conditional<std::is_base_of<
Generator, TYPE>::value,
Generic::
Generator<SIGNAL>,
1995 typename std::conditional<std::is_base_of<
Modifier, TYPE>::value,
Generic::
Modifier<SIGNAL>,
void>::type>::type;
1999 template<
typename TYPE,
int COUNT>
2001 using GeneratorOrModifier<TYPE,
signals<COUNT>>::in;
2002 using GeneratorOrModifier<TYPE,
signals<COUNT>>::out;
2009 template<
typename... Args>
2027 template<
typename... Args>
2055 std::unique_ptr<
Graph> ptr;
2058 if (ptr.get() ==
nullptr)
2059 ptr = std::make_unique<
Graph>();
2066 void clear() { check(); ptr->
clear(); }
2067 bool isActive()
const {
return ptr ? ptr->isActive() :
false; }
2074 Graph& operator()(
double x_min,
double x_max,
double y_min,
double y_max) { check();
return (
Graph&)ptr->
operator()(x_min
, x_max
, y_min
, y_max
); }
2078 template<
typename SIGNAL,
typename... Args>
2079 void plot(
Generic::
Function<SIGNAL, Args...>& function) { check(); ((Graph*)(ptr.get()))->plot(function); }
2081 template<
typename TYPE>
2082 void plot(TYPE(*function)(TYPE)) { check(); ((Graph*)(ptr.get()))->plot(function); }
2084 template<
typename FUNCTION,
typename... VALUES>
2085 void plot(FUNCTION f, VALUES... values) { check(); ((Graph*)(ptr.get()))->plot(f, values...); }
2087 template<
typename TYPE>
void add(TYPE y) { check(); ptr->add(y); }
2090 template<
typename TYPE>
Graph& operator+=(TYPE y) { check();
return ptr->operator+=(y); }
2093 template<
typename TYPE>
Graph& operator=(TYPE(*function)(TYPE)) { check();
return (Graph&)ptr->operator=(function); }
2098 template<
typename... Args>
Graph& operator<<(
Generic::
Function<Args...>& function) { plot(function.with());
return *
this; }
2099 template<
typename TYPE>
Graph& operator<<(TYPE& in) { add(in);
return *
this; }
2100 template<
typename TYPE>
Graph& operator<<(
const TYPE& in) { add(in);
return *
this; }
2106 bool isDirty()
const {
return ptr ? ptr->
isDirty() :
false; }
2107 void setDirty(
bool dirty) {
if (ptr) ptr->
setDirty(dirty
); }
2109 void truncate(
unsigned int count) { check(); ptr->
truncate(count
); }
2116 template <
typename... Args>
2124 template<
typename SIGNAL,
typename... Args>
2130 template<
typename TYPE>
2136 template<
typename SIGNAL,
typename... Args>
2142 template<
typename TYPE>
2169 #define sqrt klang::sqrt
2170 #define abs klang::abs
2184 std::lock_guard<std::mutex> lock(
_lock);
2186 memcpy(string, in,
length);
2192 std::lock_guard<std::mutex> lock(
_lock);
2194 memcpy(string, in.string,
length);
2200 std::lock_guard<std::mutex> lock(
_lock);
2201 const int len = std::max(0, std::min(
capacity() -
length, (
int)strlen(in)));
2202 memcpy(&string[
length], in, len);
2205 memcpy(&
last, in, len);
2206 last.string[len] = 0;
2216 std::lock_guard<std::mutex> lock(
_lock);
2217 const int _length =
length;
2218 memcpy(buffer, string,
length);
2227#define PROFILE(func, ...) debug.print("%-16s = %fns\n", #func "(" #__VA_ARGS__ ")", debug.profile(1000
, func, __VA_ARGS__));
2236 using buffer::operator++;
2237 using buffer::operator signal&;
2249
2250
2251
2252
2253
2254
2255
2256
2277 template<
typename TYPE>
2285 destination << *
ptr;
2299 template <
typename Func,
typename... Args>
2300 inline static double profile(Func func, Args... args) {
2311 template <
typename Func,
typename... Args>
2312 inline static double profile(
int times, Func func, Args... args) {
2317 return sum / 1000000.0;
2327 buffer.content = content;
2335 bool hasAudio()
const {
2338 const float* getAudio()
const {
2346 THREAD_LOCAL
static char string[1024] = { 0 };
2349 va_start(args, format);
2350 vsnprintf(string, 1024, format, args);
2358 THREAD_LOCAL
static char string[1024] = { 0 };
2361 va_start(args, format);
2362 vsnprintf(string, 1024, format, args);
2401#define FUNCTION(type) (void(*)(type, Result<type>&))[](type x, Result<type>& y)
2404 template <
typename TYPE>
2410 Result(TYPE* array,
int index) : y(&array[index]), i(index) { }
2412 TYPE& operator[](
int index) {
2413 return *(y + index);
2416 operator TYPE
const () {
return *y; }
2418 Result& operator=(
const TYPE& in) {
2423 TYPE& operator++(
int) { i++;
return *++y; }
2428 template<
typename TYPE,
int SIZE>
2431 typedef Result<TYPE> Result;
2437 for (
int x = 0;
x <
SIZE;
x++)
2442 Table(
void(*function)(TYPE, TYPE), TYPE arg) {
2444 for (
int x = 0;
x <
SIZE;
x++)
2449 Table(
void(*function)(TYPE x, Result& y)) {
2452 for (
int x = 0;
x <
SIZE;
x++) {
2459 Table(std::initializer_list<TYPE> values) {
2464 using Array::operator[];
2470 const int i =
int(
x);
2519 const int i = (
int)
read;
2520 const int j = (
i == (
SIZE - 1)) ? 0 : (
i + 1);
2533 template<
typename TIME>
2543 template<
typename TIME>
2565 template<
typename TYPE>
2567 operator=(oscillator);
2571 return buffer
[index
];
2574 template<
typename TYPE>
2576 oscillator.set(fs /
size);
2577 for (
int s = 0; s <
size; s++)
2578 buffer
[s
] = oscillator;
2584 increment = frequency
* (
size / fs);
2588 position = phase
* float(
size);
2594 offset = phase
* float(
size);
2604 out = buffer
[position + offset
];
2629 Ramp(
float start,
float target,
float time) {
2645 active = (out != target);
2672 const signal output = out;
2706 template<
typename T1,
typename T2>
2712 struct Points :
public Point {
2713 Points(
float x,
float y) {
2722 Points& operator()(
float x,
float y) {
2723 last().next =
new Points(x, y);
2728 return next ? next->last() : *
this;
2732 return next ? 1 + next->count() : 1;
2785 void set(
const Points& point){
2788 const Points* pPoint = &point;
2790 points.push_back(*pPoint);
2791 pPoint = pPoint->next;
2801 const float delta = point
.x;
2802 time += delta + 0.00001f;
2810 if(startPoint >= 0 && endPoint <
points.size())
2816 if (
points.empty())
return 0;
2819 if (point
.x >= time) {
2820 const float dx = point
.x - last
.x;
2821 const float dy = point
.y - last
.y;
2822 const float x = time
- last
.x;
2823 return dx == 0 ? last
.y : (last
.y + x * dy / dx);
2847 virtual void release(
float time,
float level = 0.f){
2879 if(old_length == 0.0)
2882 const float multiplier = length / (fs * old_length);
2883 std::vector<
Point>::iterator point =
points.begin();
2884 while(point !=
points.end()){
2885 point->
x *= multiplier;
2999 A = attack
+ 0.005f;
3002 R = release
+ 0.005f;
3013 void release(
float time = 0.f,
float level = 0.f)
override {
3023 template<
class OSCILLATOR>
3059 template<
class OSCILLATOR>
3074 virtual void onMIDI(
int status,
int byte1,
int byte2) {
midi(status
, byte1
, byte2
); }
3103 template<
class SYNTH>
3110 Controls& operator=(
klang::
Controls& controls) { Controls::controls = &controls;
return *
this; }
3111 signal& operator[](
int index) {
return controls->operator[](index).operator signal&(); }
3112 const signal& operator[](
int index)
const {
return controls->operator[](index).operator
const signal&(); }
3113 unsigned int size() {
return controls ? controls->size() : 0; }
3154 return stage ==
Off;
3190 template<
class SYNTH,
class NOTE =
Note>
3198 for (
int n = 0; n < 128; n++)
3203 template<
class TYPE>
3270 for (
const auto* n :
notes.items) {
3281 for (
unsigned int n = 0; n <
notes.count; n++)
3288 for (
unsigned int n = 0; n <
notes.count; n++)
3293 template<
class SYNTH,
class NOTE>
3295 for (
unsigned int n = 0; n < count; n++) {
3296 NOTE* tmp = items[n];
3380 return (
l + r)
* 0.5f;
3467 template<
class TYPE>
3500 const int i = (
int)
read;
3501 const int j = (
i == (
SIZE - 1)) ? 0 : (
i + 1);
3511 template<
typename TIME>
3560 buffer buffer =
{ buffers[0]
, buffers[1]
};
3583 for (
const auto* n : notes.items) {
3584 if (note == n)
return
3600 template<
typename SOURCE,
typename DESTINATION>
3601 inline DESTINATION&
operator>>(SOURCE& source, DESTINATION& destination) {
3602 if constexpr (is_derived_from<
Input, DESTINATION>())
3603 destination.input(source);
3604 else if constexpr (is_derived_from<
Stereo::
Input, DESTINATION>())
3605 destination.input(source);
3607 destination << source;
3612 template<
typename SOURCE,
typename DESTINATION>
3613 inline DESTINATION&
operator>>(
const SOURCE& source, DESTINATION& destination) {
3614 if constexpr (is_derived_from<
Input, DESTINATION>())
3615 destination.input(source);
3616 else if constexpr (is_derived_from<
Stereo::
Input, DESTINATION>())
3617 destination.input(source);
3619 destination << source;
3625 using namespace klang;
3632 out = sin(position + offset);
3633 position
+= increment;
3641 position
+= increment;
3648 out =
abs(2.f * position *
pi.inv - 2)
- 1.f;
3649 position
+= increment;
3656 out = position >
pi ? 1.f : -1.f;
3657 position
+= increment;
3672 out = position > (
duty * pi) ? 1.f : -1.f;
3673 position
+= increment;
3680 out = rand() * 2.f/(
const float)RAND_MAX - 1.f;
3687 constexpr float twoPi =
float(2.0 * 3.1415926535897932384626433832795);
3700 constexpr float FC4 =
float(261.62556530059862);
3701 constexpr float FC4_FINTMAX =
float(261.62556530059862 * 2147483648.0);
3702 const float FBASE = (FC4_FINTMAX) /
klang::fs;
3703 amount = 2u * (
signed int)(FBASE / FC4 * f);
3708 const unsigned int i = (
amount >> 9) | 0x3f800000;
3709 return *(
const float*)&i - 1.f;
3725 constexpr float FINTMAX = 2147483648.0f;
3726 phase = phase
* FINTMAX
/ (2.f *
pi);
3736 const unsigned int i = (
position >> 9) | 0x3f800000;
3737 return (*(
const float*)&i - 1.f);
3756 if (phase & 0x80000000)
3760 phase = (phase >> 8) | 0x3f800000;
3761 return *(
float*)&phase *
pi - 3.f / 2.f *
pi;
3825 const float x2 = x * x;
3826 return (((-0.00018542f * x2 + 0.0083143f) * x2 - 0.16666f) * x2 + 1.0f) * x;
3857 if (x > 3.f/2.f *
pi)
3859 else if (x >
pi/2.f)
3907 using Waveform =
float(OSM::*)();
3945 c2 = -1.f / (1.0f -
col);
3996 inline static float sqr(
float x) {
return x * x; }
4022 inline float saw(
const float p,
const State state)
const {
4025 case Up:
return c1 * (p + p -
f) + 1.f;
break;
4026 case Down:
return c2 * (p + p -
f) + 1.f;
break;
4031 default:
return 0.f;
4039 case Up:
return 1.f;
break;
4040 case Down:
return -1.f;
break;
4054 Osm(
OSM::Waveform waveform,
float duty = 0.f) : _Duty(duty), osm
(waveform
) { osm
.setDuty(_Duty
); }
4056 void set(
param frequency) {
4089 static constexpr unsigned int bias = 0b1000011100000000000000000000000;
4091 union {
unsigned int i;
float f; };
4094 i = ((rand() & 0b111111111111111UL) << 1) |
bias;
4131 out = (
a * in) + (
b * out);
4179 const float exp0 = expf(-
f * fs
.w);
4194 const float exp0 = expf(-
f * fs
.w);
4195 b0 = 0.5f * (1.f + exp0);
4209 const float c = 1.f / tanf(
pi *
f * fs
.inv);
4215 out =
b0 * (in
+ z) -
a1 * out;
4255 const float w = f
* fs
.w;
4259 if (Q < 0.5) Q = 0.5;
4260 a =
sin0 / (2.f * Q);
4269 const float z0 =
z[0];
4270 const float z1 =
z[1];
4271 const float y =
b0 * in + z0;
4272 z[0] =
b1 * in -
a1 * y + z1;
4273 z[1] =
b2 * in -
a2 * y;
4327 using Init =
void(BPF::*)(
void);
4395 A = 1.f - (attack == 0.f ? 0.f : expf(-1.0f / (fs * attack)));
4396 R = 1.f - (release == 0.f ? 0.f : expf(-1.0f / (fs * release)));
4401 const float smoothing = in > out ?
A :
R;
4402 (out
+ smoothing * (in
- out))
>> out;
4417 using Process =
void(Follower::*)();
4426 template<
int WINDOW>
4447 using Process =
void(Window::*)();
4472 using namespace klang;
4480 using namespace klang;
4488 using namespace klang;
std::shared_ptr< Ramp > ramp
virtual void release(float time, float level=0.f)
const Stage getStage() const
std::vector< Point > points
void setTargetRate(const Point &point, float rate=0.0)
const Point & operator[](int point) const
void setStage(Stage stage)
signal at(param time) const
bool operator==(Stage stage) const
void set(const std::vector< Point > &points)
void resize(float length)
void setLoop(int startPoint, int endPoint)
bool operator!=(Stage stage) const
Envelope(const Points &points)
void setTargetTime(const Point &point, float time=0.0)
void set(const Points &point)
Envelope & operator=(std::initializer_list< Point > points)
void(Envelope::* setTargetFunction)(const Point &point, float time)
Envelope(std::initializer_list< Point > points)
void setTarget(const Point &point, float time=0.0)
Envelope(const Envelope &in)
Base class for synthesiser notes.
virtual event on(Pitch p, Velocity v)
virtual bool stop(Velocity v=0)
void attach(SYNTH *synth)
virtual void controlChange(int controller, int value)
virtual void start(Pitch p, Velocity v)
virtual event off(Velocity v=0)
virtual bool release(Velocity v=0)
Wavetable-based oscillator.
virtual void set(param frequency, param phase) override
virtual void set(param frequency, relative phase) override
virtual void set(param frequency) override
signal & operator[](int index)
virtual void set(relative phase) override
Wavetable(TYPE oscillator, int size=2048)
Wavetable & operator=(TYPE &oscillator)
constexpr unsigned int capacity(unsigned int n)
signal operator[](float offset)
signal & operator*=(const signal &in)
signal & operator[](int offset)
buffer(float *buffer, int size)
const signal & operator[](int index) const
buffer(int size, float initial=0)
buffer & operator=(const buffer &in)
signal & operator=(const signal &in)
signal operator[](float offset) const
signal & operator+=(const signal &in)
void rewind(int offset=0)
const float * data() const
buffer(float *buffer, int size, float initial)
operator const signal &() const
#define IS_SIMPLE_TYPE(type)
Transposed Direct Form II Biquadratic Filter.
BRF BSF
Band-stop filter (BSF)
LPF HCF
High-cut filter (HCF)
LPF HRF
High-reject filter (HRF)
HPF LCF
Low-cut filter (LCF)
HPF LRF
Low-reject filter (LRF)
One-pole Butterworth filter.
Single-pole (one-pole, one-zero) First Order Filters.
Performance-optimised oscillators.
static float fastsin(float x)
fast sine (based on V2/Farbrausch; using polysin)
static float fastsinp(unsigned int p)
fast sine (using polysin and integer math)
static float polysin(float x)
sin approximation [-pi/2, pi/2] using odd minimax polynomial (Robin Green)
Wavetable-based oscillators.
Common audio generators / oscillators.
Templates supporting common audio functionality.
SIGNAL operator*(Output< SIGNAL > &output, float other)
SIGNAL operator-(Output< SIGNAL > &output, float other)
SIGNAL operator+(float other, Output< SIGNAL > &output)
SIGNAL operator+(Output< SIGNAL > &output, float other)
SIGNAL operator*(float other, Output< SIGNAL > &output)
SIGNAL operator/(Output< SIGNAL > &output, float other)
Function() -> Function< signal, Args... >
SIGNAL operator/(float other, Output< SIGNAL > &output)
Function(float(*)(Args...)) -> Function< signal, Args... >
SIGNAL operator-(float other, Output< SIGNAL > &output)
Objects supporting stereo audio functionality.
signals< 2 > signal
Stereo audio signal.
static Function< float > abs(FABS)
Absolute/rectify function (audio object)
static Control Slider(const char *name, float min=0.f, float max=1.f, float initial=0.f)
static GraphPtr & operator>>(TYPE(*function)(TYPE), klang::GraphPtr &graph)
static TYPE random(const TYPE min, const TYPE max)
Generates a random number between min and max. Use an integer types for whole numbers.
float fast_mod(float x, float y)
double fast_mod2pi(double x)
static THREAD_LOCAL GraphPtr graph
Amplitude Velocity
Control parameter (velocity)
signals< 4 > operator>>(const signals< 4 > &in, const Matrix &m)
const signal & operator>>(klang::signal modulator, Operator< OSCILLATOR > &carrier)
float fast_mod2pi(float x)
constexpr constant ln2
The natural logorithm of 2 (and it's inverse).
static Graph & operator>>(TYPE(*function)(TYPE), Graph &graph)
constexpr constant pi
The mathematical constant, pi (and it's inverse).
Function(float(*)(Args...)) -> Function< Args... >
const Control::Options NoOptions
signals< CHANNELS > operator/(float x, const signals< CHANNELS > &y)
Return a copy of the signal with each channel divided into x.
static Control PitchBend()
Mode
Klang mode identifiers (e.g. averages, level following)
double fast_mod(double x, double y)
static void random(const unsigned int seed)
Set the random seed (to allow repeatable random generation).
static Function< float > sqrt(SQRTF)
Square root function (audio object)
static Control Dial(const char *name, float min=0.f, float max=1.f, float initial=0.f)
DESTINATION & operator>>(const SOURCE &source, DESTINATION &destination)
Feed audio source to destination (no source processing)
double fast_modi(double x)
static param & operator>>(param &from, param &to)
TYPE1 max(TYPE1 a, TYPE2 b)
Return the minimum of two values.
static signal & operator>>(float input, signal &destination)
Stream a literal / constant / scalar type into a signal.
static Control Toggle(const char *name, bool initial=false)
static Control Meter(const char *name, float min=0.f, float max=1.f, float initial=0.f)
TYPE1 min(TYPE1 a, TYPE2 b)
Return the minimum of two values.
static Control Menu(const char *name, const Options... options)
constexpr bool are_scalars(Head &&head, Tail &&... tail)
signals< CHANNELS > operator-(float x, const signals< CHANNELS > &y)
Return a copy of the signal with each channel subtracted from x.
const Control::Size Automatic
signals< CHANNELS > operator*(float x, const signals< CHANNELS > &y)
Return a copy of the signal with each channel scaled by x.
float fast_modp(unsigned int x)
DESTINATION & operator>>(SOURCE &source, DESTINATION &destination)
Feed audio source to destination (with source processing)
signals< 4 > operator*(const signals< 4 > &in, const Matrix &m)
Array< float, 128 > Values
static Function< float > cube([](float x) -> float { return x *x *x;})
Cube function (audio object)
constexpr BASE poweri(BASE base)
signals< CHANNELS > operator+(float x, const signals< CHANNELS > &y)
Return a copy of the signal with each channel offset by x.
static Function< float > sqr([](float x) -> float { return x *x;})
Square function (audio object)
constexpr power_t< BASE, EXP > power(BASE base, EXP exp)
Raise base to the power exp.
constexpr constant root2
The square root of 2 (and it's inverse).
static Control ModWheel()
double fast_mod1(double x)
Text< 32 > Caption
A short Text object used to label controls.
static Control Button(const char *name)
void event
A function that handles an event.
constexpr bool is_derived_from()
constexpr power_t< BASE, EXP > power(BASE base, EXP exp)
Raise base to the power exp.
Attack-Decay-Sustain-Release Envelope.
bool operator==(Envelope::Stage stage) const
void release(float time=0.f, float level=0.f) override
void set(param attack, param decay, param sustain, param release) override
Control parameter (linear amplitude)
static THREAD_LOCAL Conversion dB
const Amplitude * operator->() const
Variable-sized array, pre-allocated to a max. capacity.
unsigned int size() const
The current number of items in the array.
Array(std::initializer_list< TYPE > init_list)
Construct an array given the specified values.
float max() const
Find the maximum value in the array.
Array()=default
Construct an empty array.
void add(const TYPE &item)
Add the specified item to the end of the array.
float mean() const
Find the mean average of values in the array.
void normalise(float target=1.f, int mode=Peak)
Normalises values in the array to the specified target, based on peak, mean, or RMS value;.
float rms() const
Find the root mean squared (RMS) average of values in the array.
void clear()
Clear the array contents. Only resets the item count, without wiping memory.
const TYPE & operator[](int index) const
Returns a read-only reference to the array item at the given index.
static int capacity()
The maximum capacity of the array.
TYPE * add()
Add a blank item to the end of the array, returning a pointer that allows the item to be modified.
TYPE & operator[](int index)
Returns a reference to the array item at the given index.
A parallel bank of multiple audio objects.
TYPE & operator[](int index)
const TYPE & operator[](int index) const
Console & operator=(const char *in)
int getText(char *buffer)
static THREAD_LOCAL Text< 16384 > last
Console & operator=(const Console &in)
Console & operator+=(const char *in)
Size(int x=-1, int y=-1, int width=-1, int height=-1)
float operator+(TYPE x) const
float operator-(TYPE x) const
signal operator*(const Control &x) const
Array< Caption, 128 > Options
Control & operator*=(float x)
float operator/(TYPE x) const
Control & operator-=(float x)
const TYPE & operator>>(const TYPE &in)
float operator*(TYPE x) const
Control & operator+=(float x)
signal operator-(const Control &x) const
signal operator+(const Control &x) const
static constexpr float smoothing
Control & operator/=(float x)
operator const signal &() const
signal operator/(const Control &x) const
TYPE & operator>>(TYPE &in)
operator const signal &() const
ControlMap(Control &control)
Base class for UI / MIDI controll.
virtual void onMIDI(int status, int byte1, int byte2)
virtual void onPreset(int index)
virtual void onControl(int index, float value)
virtual event midi(int status, int byte1, int byte2)
virtual event control(int index, float value)
virtual event preset(int index)
void operator+=(const Control &control)
void operator=(const Controls &controls)
void operator=(std::initializer_list< Control > controls)
void add(const char *name, Control::Type type=Control::ROTARY, float min=0.f, float max=1.f, float initial=0.f, Control::Size size=Automatic)
Audio buffer for debug output.
Buffer & operator+=(const signal in)
operator const signal &() const
Buffer & operator+=(TYPE &in)
signal & operator>>(signal &destination) const
The Klang debug interface.
void print(const char *format,...)
static double profile(int times, Func func, Args... args)
int getText(char *buffer)
void printOnce(const char *format,...)
Console console
Debug console output.
operator const signal &() const
static THREAD_LOCAL Buffer buffer
static double profile(Func func, Args... args)
virtual void set(param delay) override
signal tap(float delay) const
signal tap(int delay) const
signal operator()(TIME &delay)
signal operator()(const TIME &delay)
virtual void process() override
Effect mini-plugin (mono)
virtual void process(buffer buffer)
Attack / Release IIR Filter (~Butterworth when attack == release)
void set(param attack, param release)
Window-based envelope follower.
Window & operator=(klang::Mode mode)
static constexpr constant window
void set(param attack, param release)
Envelope follower (Peak / RMS)
void set(param attack, param release)
Follower & operator=(klang::Mode mode)
Linear envelope ramp (default)
signal operator++(int) override
void set(int from, int to)
Loop(int from=-1, int to=-1)
Abstract envelope ramp type.
virtual void setRate(float rate)
virtual void setTime(float time)
virtual signal operator++(int)=0
Ramp(float start, float target, float time)
virtual void setTarget(float target)
virtual void setValue(float value)
BPF & operator=(Gain gain)
Set the constant gain mode.
@ ConstantSkirtGain
Constant Skirt Gain.
@ ConstantPeakGain
Constant Peak Gain.
void process() noexcept
Apply the biquad filter (Transposed Direct Form II)
void set(param f, param Q=root2.inv)
Set the filter cutoff (and Q)
void reset()
Reset filter state.
Basic one-pole IIR filter.
Control parameter (frequency)
Frequency(float f=1000.f)
Applies a function to a signal (input-output)
Function(std::function< float(Args...)> function)
Signal generator object (mono)
Pulse wave oscillator (aliased)
void set(param frequency, param phase, param duty)
Saw wave oscillator (aliased)
Square wave oscillator (aliased)
Triangle wave oscillator (aliased)
Phase increment (optimised)
Increment operator+(const Increment &in) const
White noise generator (optimised)
static constexpr unsigned int bias
Oscillator State Machine.
Fast::Increment increment
void set(param frequency)
void set(param frequency, param phase)
static float sqr(float x)
float saw(const float p, const State state) const
float pulse(const float p, const State state) const
void set(param frequency, param phase, param duty)
Oscillator phase (optimised)
float operator+(const Phase &offset) const
Phase & operator=(klang::Phase phase)
Phase & operator+=(const Increment i)
Pulse wave oscillator (band-limited, optimised)
Saw wave oscillator (band-limited, optimised)
Sine wave oscillator (band-limited, optimised)
Fast::Increment increment
void set(relative phase) override
void set(param frequency, param phase) override
void set(param frequency) override
void set(param frequency, relative phase) override
Square wave oscillator (band-limited, optimised)
Triangle wave oscillator (band-limited, optimised)
Saw wave oscillator (wavetable)
Sine wave oscillator (wavetable)
Applies a function to a signal (input-output)
Function< SIGNAL, Args... > & operator()(const FuncArgs &... args)
klang::GraphPtr & operator>>(klang::GraphPtr &graph)
virtual void process() override
unsigned int args() const
Function(FunctionPtr function)
std::tuple< Args... > inputs
const float operator()(const FuncArgs &... args) const
static constexpr unsigned int ARGS
klang::Graph & operator>>(klang::Graph &graph)
Function< SIGNAL, Args... > & with(FuncArgs... args)
First first(First first, Rest...)
Function(FunctionPtr function, OtherArgs... args)
std::tuple< Rest... > tail(const std::tuple< First, Rest... > &t) const
Signal generator object (output only)
operator const SIGNAL &() const override
operator const SIGNAL &() override
Output< SIGNAL > & operator()(params... p)
bool contains(const Point &pt) const
void from(const Series &series, double Point::*axis)
bool contains(double value) const
Series * find(void *function)
Series & operator>>(Series &series)
bool operator==(const Series &in) const
bool operator!=(const Series &in) const
void plot(Generic::Function< SIGNAL, Args... > &f, const Axis &x_axis)
void plot(RETURN(*f)(ARG), const Axis &x_axis)
void setDirty(bool dirty)
Graph & operator=(TYPE(*function)(TYPE))
Plot the given function of x.
Graph & operator+=(TYPE y)
Add a data point (incrementing x)
Graph & operator()(double min, double max)
void truncate(unsigned int count)
Graph & operator=(std::initializer_list< Point > values)
Plot the given data points.
void add(const Point pt)
Add a data point.
void plot(FUNCTION f, VALUES... values)
Plot the given function for x plus additional arguments.
Graph::Series & operator[](int index)
const Graph::Series & operator[](int index) const
void getAxes(Axes &axes) const
void plot(Generic::Function< SIGNAL, Args... > &function)
Plot the given Function.
const Data & getData() const
Graph & operator+=(const Point pt)
Add a data point.
const Axes & getAxes() const
Graph & operator+=(std::initializer_list< Point > values)
Plot the given data points.
void add(TYPE y)
Add a data point (incrementing x)
void plot(TYPE(*function)(TYPE))
Plot the given function of x.
Graph & operator()(double x_min, double x_max, double y_min, double y_max)
Signal modifier object (input-output)
virtual void process() override
Modifier< SIGNAL > & operator()(params... p)
operator const SIGNAL &() const override
operator const SIGNAL &() override
Audio oscillator object (output)
virtual void set(param frequency, relative phase)
virtual void set(param frequency)
virtual void set(relative phase)
virtual void set(param frequency, param phase)
SIGNAL operator+(TYPE &other)
SIGNAL operator/(TYPE &other)
virtual operator const SIGNAL &() const
virtual const SIGNAL & output() const
virtual operator const SIGNAL &()
SIGNAL operator*(TYPE &other)
SIGNAL operator-(TYPE &other)
TYPE & operator>>(TYPE &destination)
float operator()(int col, int row) const
const float * operator[](int col) const
float * operator[](int col)
float & operator()(int col, int row)
Signal modifier object (mono input-output)
virtual bool process(buffer buffer)
virtual void process() override=0
virtual bool process(buffer *buffer)
unsigned int noteStart[128]
Operator & operator*(float amp)
Operator & operator>>(Operator &carrier)
Operator & operator()(param f, relative phase)
virtual Operator & operator=(const Envelope &points)
virtual Operator & operator=(const Envelope::Points &points)
Operator & operator()(relative phase)
virtual void process() override
Operator & operator()(param f)
Audio oscillator object (mono output)
Audio output object (mono)
Control parameter (phase)
Phase operator%(float modulus)
param & operator+=(const increment &increment)
Phase operator+(const increment &increment) const
param & operator+=(float increment)
Control parameter (pitch)
const Pitch * operator->()
static THREAD_LOCAL Conversion Frequency
const char * text() const
Base class for mini-plugin.
void operator+=(const Preset &preset)
void operator=(const Presets &presets)
void add(const char *name, const Values... values)
void operator=(std::initializer_list< Preset > presets)
float w
angular frequency (omega)
float nyquist
nyquist frequency (f / 2)
int i
sample rate (integer)
float f
sample rate (float)
double d
sample rate (double)
float inv
1 / sample rate (inverse)
Stereo audio object adapter.
Audio delay object (stereo)
signal operator()(const TIME &delay)
signal tap(float delay) const
virtual void process() override
signal tap(int delay) const
Stereo effect mini-plugin.
virtual void process(Stereo::buffer buffer)
Signal generator object (stereo output)
Signal modifier object (stereo, input-output)
Base class for stereo synthesiser note.
virtual bool process(Stereo::buffer buffer)
virtual void process() override=0
virtual bool process(mono::buffer *buffers)
Audio oscillator object (stereo, output)
Audio output object (stereo)
Synthesiser note array (stereo)
Synthesier mini-plugin (stereo)
int indexOf(Note *note) const
virtual void presetLoaded(int preset)
virtual void optionChanged(int param, int item)
virtual void buttonPressed(int param)
buffer & operator=(const buffer &in)
buffer(mono::buffer &left, mono::buffer &right)
buffer & operator=(const mono::signal in)
buffer & operator*=(const frame &in)
frame operator=(const signal &in)
operator const signal() const
frame operator[](int index)
buffer & operator=(const frame &in)
buffer & operator+=(const frame &in)
signal operator[](int index) const
buffer(const buffer &buffer)
buffer & operator*=(const mono::signal in)
buffer & operator+=(const mono::signal in)
mono::buffer & channel(int index)
buffer & operator+=(const signal &in)
frame & operator*=(float x)
signal operator*(const mono::signal x) const
frame & operator+=(const mono::signal x)
frame & operator-=(int x)
signal operator*(int x) const
signal operator-(double x) const
frame & operator/=(int x)
signal operator*(const signal x) const
signal operator+(const mono::signal x) const
signal operator+(float x) const
signal operator-(float x) const
frame & operator+=(double x)
frame & operator*=(const signal x)
signal operator-(const mono::signal x) const
signal operator/(double x) const
frame & operator+=(const frame &x)
frame & operator*=(const mono::signal x)
frame & operator*=(int x)
signal operator-(const signal x) const
frame & operator-=(double x)
signal operator-(int x) const
frame & operator/=(const frame &x)
frame & operator-=(const mono::signal x)
frame & operator*=(const frame &x)
frame & operator=(const signal &signal)
frame & operator-=(const frame &x)
signal operator/(int x) const
frame & operator*=(double x)
signal operator+(int x) const
signal operator/(const mono::signal x) const
frame & operator+=(int x)
signal operator*(double x) const
signal operator+(double x) const
frame & operator/=(const mono::signal x)
frame & operator+=(const signal x)
signal operator+(const signal x) const
frame & operator/=(const signal x)
frame & operator+=(float x)
frame & operator/=(float x)
signal operator*(float x) const
signal operator/(float x) const
frame(mono::signal &left, mono::signal &right)
frame & operator/=(double x)
frame & operator-=(float x)
frame & operator-=(const signal x)
signal operator/(const signal x) const
Synthesiser object (mono)
Notes< Synth, Note > notes
int indexOf(Note *note) const
virtual event onPreset(int index) override
virtual event onControl(int index, float value) override
Table(std::initializer_list< TYPE > values)
Table(TYPE(*function)(TYPE))
Table(void(*function)(TYPE, TYPE), TYPE arg)
TYPE operator[](float index)
Table(void(*function)(TYPE x, Result &y))
String of characters representing text.
static Text from(const char *in)
Create a new Text object from a C-string.
operator const char *() const
Automatic cast to constant C-string.
int capacity() const
Maximum size of the string.
bool operator==(const char *in) const
Returns true if Text matches the given C-string.
char string[SIZE+1]
The character buffer.
const char * c_str() const
Return constant C-string.
bool operator!=(const char *in) const
Returns true if Text does not matches the given C-string.
void operator=(const char *in)
Assign C-String to Text object.
Klang language version (major.minor.build.debug)
Constant scalar (pre-converted to double, float and int).
float operator^(int x) const
const float inv
Inverse of constant.
const double d
Constant as double.
const float f
Constant as float.
float operator^(double x) const
float operator^(float x) const
Constant raised to the power, x.
constexpr constant(double value) noexcept
Create a constant from the given value.
constexpr operator float() const noexcept
const int i
Constant as integer.
Control parameter (idecibels)
static THREAD_LOCAL Conversion Amplitude
A phase or wavetable increment.
increment(float amount, const float size=2 *pi)
Create a phase increment (default to radians).
float amount
The current phase.
increment(float amount, double size)
Create a phase increment.
increment & operator=(float in)
Set current phase.
increment(float amount, int size)
Create a phase increment (wavetable size).
const float size
The length of a a full cycle (e.g. 2 pi or wavetable size)
A signal used as a control parameter.
param(const float initial=0.f)
param & operator+=(const increment &increment)
A signal used as an offset relative to another signal.
A mono audio signal (equivalent to a float).
signal & operator*=(const signal &x)
Multiply (modulate) signal by another signal.
signal operator^(int x) const
Return a copy of the signal raised to the power of x.
operator const float() const
signal & operator=(Output &in)
Assign processed output of in to signal.
signal(const double initial)
Create signal from a 64-bit double.
relative operator+() const
Returns a copy of the signal to treat as a relative offset (e.g. for phase modulation).
signal operator*(double x) const
Return a copy of the signal scaled by x.
signal operator^(double x) const
Return a copy of the signal raised to the power of x.
signal operator*(float x) const
Multiply (modulate) two signals.
bool isDenormal() const
Check if the signal contains a denormal value.
signal operator^(float x) const
Return a copy of the signal raised to the power of x.
signal & operator-=(float x)
Subtract the specified amount from the signal.
signal & operator/=(double x)
Divide signal by the specified amount.
signal & operator>>(signal &destination) const
Stream operator (feedforward; allows further processing)
signal & operator+=(const signal &x)
Add (mix) another signal to the signal.
signal & operator+=(float x)
Add the specified amount to the signal.
signal operator-(double x) const
Return a copy of the signal offset by -x.
signal & operator-=(double x)
Subtract the specified amount from the signal.
int channels() const
Returns the number of channels (1 = mono).
signal & operator/=(int x)
Divide signal by the specified amount.
signal & operator-=(int x)
Subtract the specified amount from the signal.
signal operator-(float x) const
Subtract one signal from another.
signal operator*(int x) const
Return a copy of the signal scaled by x.
signal & operator+=(double x)
Add the specified amount to the signal.
signal & operator+=(int x)
Add the specified amount to the signal.
signal(const float initial=0.f)
Create signal from a 32-bit float..
signal operator/(int x) const
Return a copy of the signal divided by x.
signal & operator+=(Output &in)
Adds processed output of in to signal.
signal operator+(float x) const
Add two signals together.
signal & operator*=(double x)
Multiply signal by the specified amount.
signal & operator-=(const signal &x)
Subtract another signal from the signal.
signal & operator/=(float x)
Divide signal by the specified amount.
signal operator+(double x) const
Return a copy of the signal offset by x.
signal operator/(float x) const
Divide one signal by another.
signal & operator*=(int x)
Multiply signal by the specified amount.
signal operator-(int x) const
Return a copy of the signal offset by -x.
signal(constant initial)
Create signal from a constant.
signal(const int value)
Create signal from an 32-bit signed integer.
signal operator/(double x) const
Return a copy of the signal divided by.
signal & operator/=(const signal &x)
Divide signal by another signal.
signal operator+(int x) const
Return a copy of the signal offset by x.
signal & operator*=(float x)
Multiply signal by the specified amount.
A multi-channel audio signal (e.g. stereo).
signals operator-(float x) const
Return a copy of the signal with each channel offset by -x.
const signal & operator[](int index) const
Return a read-only reference to the signal at the specified index (0 = left, 1 = right).
signals operator/(double x) const
Return a copy of the signal with each channel divided by x.
signal mono() const
Return the mono mix of a stereo channel.
signals operator-(const signal x) const
Return a copy of the multi-channel signal, subtracting a mono signal from each channel.
signals operator+(float x) const
Return a copy of the signal with each channel offset by x.
signals(Args... initial)
Create a multi-channel signal with the given channel values.
signals operator*(const signals x) const
Multiply (modulate) two multi-channel signals.
signals(float initial=0.f)
Create a stereo signal with the given value.
signals operator+(const signals x) const
Add two multi-channel signals together.
signals operator/(const signals x) const
Divide one multi-channel signal by another.
signals operator*(double x) const
Return a copy of the signal with each channel scaled by x.
signals & operator>>(signals &destination) const
Stream operator (feedforward; allows further processing).
signals operator+(double x) const
Return a copy of the signal with each channel offset by x.
signals operator*(const signal x) const
Return a copy of the multi-channel signal, multiplying (modulating) each channel by a mono signal.
signals operator/(float x) const
Return a copy of the signal with each channel divided by x.
signals operator*(float x) const
Return a copy of the signal with each channel scaled by x.
signals(int left, int right)
Create a stereo signal with the given left and right value.
signals operator-(int x) const
Return a copy of the signal with each channel offset by -x.
signals & operator+=(const signals x)
Add (mix) another signal to the signal.
signals(double left, double right)
Create a stereo signal with the given left and right value.
signals & operator/=(const signals x)
Divide signal by another signal.
signals & operator*=(const signals x)
Multiply (modulate) signal by another signal.
int channels() const
Returns the number of channels in the signal.
signals operator/(int x) const
Return a copy of the signal with each channel divided by x.
signals(float left, float right)
Create a stereo signal with the given left and right value.
signals operator-(double x) const
Return a copy of the signal with each channel offset by -x.
signals operator-(const signals x) const
Subtract one multi-channel signal from another.
signals & operator-=(const signals x)
Subtract another signal from the signal.
signals operator+(const signal x) const
Return a copy of the multi-channel signal, adding a mono signal to each channel.
signals(double initial)
Create a stereo signal with the given value.
signals operator/(const signal x) const
Return a copy of the multi-channel signal, dividing each channel by a mono signal.
signals operator+(int x) const
Return a copy of the signal with each channel offset by x.
signals operator*(int x) const
Return a copy of the signal with each channel scaled by x.
signals(int initial)
Create a stereo signal with the given value.
signal & operator[](int index)
Return a reference to the signal at the specified index (0 = left, 1 = right).
signals(Args &... initial)
Create a multi-channel signal with the given channel values.