Klang C++
Language Reference (draft)
Loading...
Searching...
No Matches
klang Namespace Reference

Namespaces

namespace  basic
 
namespace  Filters
 Common audio filters.
 
namespace  Generators
 Common audio generators / oscillators.
 
namespace  Generic
 Templates supporting common audio functionality.
 
namespace  minimal
 
namespace  Mono
 
namespace  mono
 
namespace  optimised
 
namespace  Stereo
 Objects supporting stereo audio functionality.
 

Classes

struct  ADSR
 Attack-Decay-Sustain-Release Envelope. More...
 
struct  Amplitude
 Control parameter (linear amplitude) More...
 
struct  Array
 Variable-sized array, pre-allocated to a max. capacity. More...
 
struct  Bank
 A parallel bank of multiple audio objects. More...
 
class  buffer
 Audio buffer (mono) More...
 
struct  Console
 Debug text output. More...
 
struct  constant
 Constant scalar (pre-converted to double, float and int). More...
 
struct  Control
 UI control / parameter. More...
 
struct  Controller
 Base class for UI / MIDI controll. More...
 
struct  ControlMap
 Mapped UI control. More...
 
struct  Controls
 Plugin UI controls. More...
 
struct  dB
 Control parameter (idecibels) More...
 
struct  Debug
 The Klang debug interface. More...
 
struct  Delay
 Audio delay object. More...
 
struct  Effect
 Effect mini-plugin (mono) More...
 
class  Envelope
 Envelope object. More...
 
struct  Frequency
 Control parameter (frequency) More...
 
struct  Function
 Applies a function to a signal (input-output) More...
 
struct  Generator
 Signal generator object (mono) More...
 
struct  Graph
 A line graph plotter. More...
 
struct  increment
 A phase or wavetable increment. More...
 
struct  Input
 Audio input object (mono) More...
 
struct  Matrix
 Matrix processor. More...
 
struct  Modifier
 Signal modifier object (mono input-output) More...
 
struct  Note
 Synthesiser note (mono) More...
 
class  NoteBase
 Base class for synthesiser notes. More...
 
struct  Notes
 Synthesiser note array. More...
 
struct  Operator
 FM operator. More...
 
struct  Oscillator
 Audio oscillator object (mono output) More...
 
struct  Output
 Audio output object (mono) More...
 
struct  param
 A signal used as a control parameter. More...
 
struct  Phase
 Control parameter (phase) More...
 
struct  Pitch
 Control parameter (pitch) More...
 
struct  Plugin
 Base class for mini-plugin. More...
 
struct  Preset
 Factory preset. More...
 
struct  Presets
 Factory presets. More...
 
struct  relative
 A signal used as an offset relative to another signal. More...
 
struct  SampleRate
 Sample rate constants. More...
 
struct  signal
 A mono audio signal (equivalent to a float). More...
 
struct  signals
 A multi-channel audio signal (e.g. stereo). More...
 
struct  Synth
 Synthesiser object (mono) More...
 
struct  Table
 Lookup table object. More...
 
struct  Text
 String of characters representing text. More...
 
struct  Version
 Klang language version (major.minor.build.debug) More...
 
class  Wavetable
 Wavetable-based oscillator. More...
 

Typedefs

template<typename BASE , typename EXP >
using power_t = typename std::conditional_t<std::is_integral_v<BASE>, float, BASE>
 
typedef void event
 A function that handles an event.
 
typedef Text< 32 > Caption
 A short Text object used to label controls.
 
typedef Amplitude Velocity
 Control parameter (velocity)
 
typedef Array< float, 128 > Values
 

Enums

enum  Mode { Peak , RMS , Mean }
 Klang mode identifiers (e.g. averages, level following) More...
 

Functions

template<typename Base , typename Derived >
constexpr bool is_derived_from ()
 
template<typename Head , typename... Tail>
constexpr bool are_scalars (Head &&head, Tail &&... tail)
 
template<typename BASE , int EXP>
constexpr BASE poweri (BASE base)
 
template<typename BASE , typename EXP , std::enable_if_t< is_literal< EXP >, bool > >
constexpr power_t< BASE, EXP > power (BASE base, EXP exp)
 Raise base to the power exp.
 
template<typename BASE , typename EXP >
constexpr power_t< BASE, EXP > power (BASE base, EXP exp)
 Raise base to the power exp.
 
template<typename TYPE1 , typename TYPE2 >
TYPE1 min (TYPE1 a, TYPE2 b)
 Return the minimum of two values.
 
template<typename TYPE1 , typename TYPE2 >
TYPE1 max (TYPE1 a, TYPE2 b)
 Return the minimum of two values.
 
template<typename TYPE >
static TYPE random (const TYPE min, const TYPE max)
 Generates a random number between min and max. Use an integer types for whole numbers.
 
static void random (const unsigned int seed)
 Set the random seed (to allow repeatable random generation).
 
static signaloperator>> (float input, signal &destination)
 Stream a literal / constant / scalar type into a signal.
 
template<int CHANNELS = 2>
signals< CHANNELS > operator+ (float x, const signals< CHANNELS > &y)
 Return a copy of the signal with each channel offset by x.
 
template<int CHANNELS = 2>
signals< CHANNELS > operator- (float x, const signals< CHANNELS > &y)
 Return a copy of the signal with each channel subtracted from x.
 
template<int CHANNELS = 2>
signals< CHANNELS > operator* (float x, const signals< CHANNELS > &y)
 Return a copy of the signal with each channel scaled by x.
 
template<int CHANNELS = 2>
signals< CHANNELS > operator/ (float x, const signals< CHANNELS > &y)
 Return a copy of the signal with each channel divided into x.
 
static paramoperator>> (param &from, param &to)
 
float fast_mod (float x, float y)
 
double fast_mod (double x, double y)
 
float fast_mod1 (float x)
 
double fast_mod1 (double x)
 
float fast_mod2pi (float x)
 
float fast_modp (unsigned int x)
 
double fast_mod2pi (double x)
 
template<int SIZE>
double fast_modi (double x)
 
signals< 4 > operator* (const signals< 4 > &in, const Matrix &m)
 
signals< 4 > operator>> (const signals< 4 > &in, const Matrix &m)
 
static struct klang::SampleRate fs (44100)
 
 IS_SIMPLE_TYPE (Control)
 
static Control Dial (const char *name, float min=0.f, float max=1.f, float initial=0.f)
 
static Control Button (const char *name)
 
static Control Toggle (const char *name, bool initial=false)
 
static Control Slider (const char *name, float min=0.f, float max=1.f, float initial=0.f)
 
template<typename... Options>
static Control Menu (const char *name, const Options... options)
 
static Control Meter (const char *name, float min=0.f, float max=1.f, float initial=0.f)
 
static Control PitchBend ()
 
static Control ModWheel ()
 
template<typename... Args>
 Function (float(*)(Args...)) -> Function< Args... >
 
template<typename TYPE >
static GraphPtr & operator>> (TYPE(*function)(TYPE), klang::GraphPtr &graph)
 
template<typename TYPE >
static Graphoperator>> (TYPE(*function)(TYPE), Graph &graph)
 
static Function< float > sqrt (SQRTF)
 Square root function (audio object)
 
static Function< float > abs (FABS)
 Absolute/rectify function (audio object)
 
static Function< float > sqr ([](float x) -> float { return x *x;})
 Square function (audio object)
 
static Function< float > cube ([](float x) -> float { return x *x *x;})
 Cube function (audio object)
 
template<class OSCILLATOR >
const signaloperator>> (klang::signal modulator, Operator< OSCILLATOR > &carrier)
 
template<typename SOURCE , typename DESTINATION >
DESTINATION & operator>> (SOURCE &source, DESTINATION &destination)
 Feed audio source to destination (with source processing)
 
template<typename SOURCE , typename DESTINATION >
DESTINATION & operator>> (const SOURCE &source, DESTINATION &destination)
 Feed audio source to destination (no source processing)
 

Variables

struct klang::Version version = { 0, 7, 0, KLANG_DEBUG }
 
template<typename T >
constexpr bool is_literal = std::is_trivially_constructible_v<T> && std::is_trivially_copyable_v<T> && std::is_trivially_destructible_v<T>
 
constexpr constant pi = { 3.1415926535897932384626433832795 }
 The mathematical constant, pi (and it's inverse).
 
constexpr constant ln2 = { 0.6931471805599453094172321214581 }
 The natural logorithm of 2 (and it's inverse).
 
constexpr constant root2 = { 1.4142135623730950488016887242097 }
 The square root of 2 (and it's inverse).
 
klang::dB fs
 
const Control::Size Automatic = { -1, -1, -1, -1 }
 
const Control::Options NoOptions
 
static THREAD_LOCAL GraphPtr graph
 
static Debug debug
 

Class Documentation

◆ klang::Preset

struct klang::Preset

Definition at line 1144 of file klang.h.

Class Members
Caption name = { 0 }
Values values

Typedef Documentation

◆ Caption

typedef Text<32> klang::Caption

Definition at line 355 of file klang.h.

◆ event

typedef void klang::event

Definition at line 234 of file klang.h.

◆ power_t

template<typename BASE , typename EXP >
using klang::power_t = typename std::conditional_t<std::is_integral_v<BASE>, float, BASE>

Definition at line 146 of file klang.h.

◆ Values

typedef Array<float, 128> klang::Values

Definition at line 1141 of file klang.h.

◆ Velocity

Definition at line 950 of file klang.h.

Enumeration Type Documentation

◆ Mode

Values
Peak 
RMS 
Mean 

Definition at line 83 of file klang.h.

83{ Peak, RMS, Mean };
@ Peak
Definition klang.h:83
@ RMS
Definition klang.h:83
@ Mean
Definition klang.h:83

Function Documentation

◆ abs()

static Function< float > klang::abs ( FABS )
inlinestatic

◆ are_scalars()

template<typename Head , typename... Tail>
bool klang::are_scalars ( Head && head,
Tail &&... tail )
constexpr

Definition at line 126 of file klang.h.

126 {
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)...));
129 }
constexpr bool are_scalars(Head &&head, Tail &&... tail)
Definition klang.h:126

◆ Button()

static Control klang::Button ( const char * name)
inlinestatic

Definition at line 1066 of file klang.h.

1067 { return { Caption::from(name), Control::BUTTON, 0, 1, 0.f, Automatic, NoOptions, 0.f }; }
const Control::Options NoOptions
Definition klang.h:1039
const Control::Size Automatic
Definition klang.h:1038

References Automatic, klang::Control::BUTTON, klang::Text< SIZE >::from(), and NoOptions.

◆ cube()

static Function< float > klang::cube ( [] (float x) -> float { return x *x *x;} )
inlinestatic

◆ Dial()

static Control klang::Dial ( const char * name,
float min = 0.f,
float max = 1.f,
float initial = 0.f )
inlinestatic

Definition at line 1063 of file klang.h.

1064 { return { Caption::from(name), Control::ROTARY, min, max, initial, Automatic, NoOptions, initial }; }
TYPE1 max(TYPE1 a, TYPE2 b)
Return the minimum of two values.
Definition klang.h:215
TYPE1 min(TYPE1 a, TYPE2 b)
Return the minimum of two values.
Definition klang.h:212

References Automatic, klang::Text< SIZE >::from(), NoOptions, and klang::Control::ROTARY.

◆ fast_mod() [1/2]

double klang::fast_mod ( double x,
double y )
inline

Definition at line 702 of file klang.h.

702 {
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;
705 }

◆ fast_mod() [2/2]

float klang::fast_mod ( float x,
float y )
inline

Definition at line 697 of file klang.h.

697 {
698 const unsigned int i = (((unsigned int)(x * (float(UINT_MAX) + 1.f) / y)) >> 9) | 0x3f800000;
699 return (*(const float*)&i - 1.f) * y;
700 }

Referenced by klang::Phase::operator%().

◆ fast_mod1() [1/2]

double klang::fast_mod1 ( double x)
inline

Definition at line 712 of file klang.h.

712 {
713 const unsigned long long i = (((unsigned long long)(x * (double(ULLONG_MAX) + 1.0))) >> 12ULL) | 0x7FF0000000000000ULL;
714 return (*(const double*)&i - 1.0);
715 }

◆ fast_mod1() [2/2]

float klang::fast_mod1 ( float x)
inline

Definition at line 707 of file klang.h.

707 {
708 const unsigned int i = ((unsigned int)(x * (float(UINT_MAX) + 1.f)) >> 9) | 0x3f800000;
709 return *(const float*)&i - 1.f;
710 }

◆ fast_mod2pi() [1/2]

double klang::fast_mod2pi ( double x)
inline

Definition at line 729 of file klang.h.

729 {
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;
733 }

◆ fast_mod2pi() [2/2]

float klang::fast_mod2pi ( float x)
inline

Definition at line 717 of file klang.h.

717 {
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;
721 }

Referenced by klang::Generators::Fast::fastsin().

◆ fast_modi()

template<int SIZE>
double klang::fast_modi ( double x)
inline

Definition at line 736 of file klang.h.

736 {
737 constexpr double size = double(SIZE);
738 constexpr double sizeInv = 1.0 / 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;
741 }

◆ fast_modp()

float klang::fast_modp ( unsigned int x)
inline

Definition at line 723 of file klang.h.

723 {
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;
727 }

Referenced by klang::Generators::Fast::fastsinp().

◆ fs()

static struct klang::SampleRate klang::fs ( 44100 )
static

◆ Function()

template<typename... Args>
klang::Function ( float(*  )(Args...)) -> Function< Args... >

◆ is_derived_from()

template<typename Base , typename Derived >
bool klang::is_derived_from ( )
constexpr

Definition at line 121 of file klang.h.

121 {
122 return std::is_base_of_v<Base, Derived>;
123 }

◆ IS_SIMPLE_TYPE()

klang::IS_SIMPLE_TYPE ( Control )

◆ max()

template<typename TYPE1 , typename TYPE2 >
TYPE1 klang::max ( TYPE1 a,
TYPE2 b )
inline

Definition at line 215 of file klang.h.

215{ return a > b ? a : (TYPE1)b; };

◆ Menu()

template<typename... Options>
static Control klang::Menu ( const char * name,
const Options... options )
static

Definition at line 1076 of file klang.h.

1077 { Control::Options menu;
1078 const char* strings[] = { options... };
1079 int nbValues = sizeof...(options);
1080 for(int p=0; p<nbValues; p++)
1081 menu.add(Caption::from(strings[p]));
1082 return { Caption::from(name), Control::MENU, 0, menu.size() - 1.f, 0, Automatic, menu, 0 };
1083 }
unsigned int size() const
The current number of items in the array.
Definition klang.h:246
void add(const TYPE &item)
Add the specified item to the end of the array.
Definition klang.h:249

◆ Meter()

static Control klang::Meter ( const char * name,
float min = 0.f,
float max = 1.f,
float initial = 0.f )
inlinestatic

Definition at line 1085 of file klang.h.

1086 { return { Caption::from(name), Control::METER, min, max, initial, Automatic, NoOptions, initial }; }

References Automatic, klang::Text< SIZE >::from(), klang::Control::METER, and NoOptions.

◆ min()

template<typename TYPE1 , typename TYPE2 >
TYPE1 klang::min ( TYPE1 a,
TYPE2 b )
inline

Definition at line 212 of file klang.h.

212{ return a < b ? a : (TYPE1)b; };

◆ ModWheel()

static Control klang::ModWheel ( )
inlinestatic

Definition at line 1091 of file klang.h.

1092 { return { { "MOD\nWHEEL" }, Control::WHEEL, 0.f, 127.f, 0.f, Automatic, NoOptions, 0.f }; }

References Automatic, NoOptions, and klang::Control::WHEEL.

◆ operator*() [1/2]

signals< 4 > klang::operator* ( const signals< 4 > & in,
const Matrix & m )
inline

Definition at line 762 of file klang.h.

762 {
763 return { m[0][0] * in[0] + m[0][1] * in[1] + m[0][2] * in[2] + m[0][3] * in[3],
764 m[1][0] * in[0] + m[1][1] * in[1] + m[1][2] * in[2] + m[1][3] * in[3],
765 m[2][0] * in[0] + m[2][1] * in[1] + m[2][2] * in[2] + m[2][3] * in[3],
766 m[3][0] * in[0] + m[3][1] * in[1] + m[3][2] * in[2] + m[3][3] * in[3] };
767 }

References klang::Matrix::operator[](), and klang::signals< CHANNELS >::operator[]().

Referenced by operator>>().

◆ operator*() [2/2]

template<int CHANNELS = 2>
signals< CHANNELS > klang::operator* ( float x,
const signals< CHANNELS > & y )
inline

Definition at line 621 of file klang.h.

621{ return y * x; }

◆ operator+()

template<int CHANNELS = 2>
signals< CHANNELS > klang::operator+ ( float x,
const signals< CHANNELS > & y )
inline

Definition at line 617 of file klang.h.

617{ return y + x; }

◆ operator-()

template<int CHANNELS = 2>
signals< CHANNELS > klang::operator- ( float x,
const signals< CHANNELS > & y )
inline

Definition at line 619 of file klang.h.

619{ return -y + x; }

◆ operator/()

template<int CHANNELS = 2>
signals< CHANNELS > klang::operator/ ( float x,
const signals< CHANNELS > & y )
inline

Definition at line 623 of file klang.h.

623 {
624 signals<CHANNELS> s = { 0.f };
625 for(int c=0; c<CHANNELS; c++)
626 s[c] = x / y[c];
627 return std::move(s);
628 }
A multi-channel audio signal (e.g. stereo).
Definition klang.h:502

◆ operator>>() [1/8]

signals< 4 > klang::operator>> ( const signals< 4 > & in,
const Matrix & m )
inline

Definition at line 769 of file klang.h.

769{ return operator*(in, m); }
signals< CHANNELS > operator*(float x, const signals< CHANNELS > &y)
Return a copy of the signal with each channel scaled by x.
Definition klang.h:621

References operator*().

◆ operator>>() [2/8]

template<typename SOURCE , typename DESTINATION >
DESTINATION & klang::operator>> ( const SOURCE & source,
DESTINATION & destination )
inline

Definition at line 3613 of file klang.h.

3613 {
3614 if constexpr (is_derived_from<Input, DESTINATION>())
3615 destination.input(source); // input to destination (enables overriding of <<)
3616 else if constexpr (is_derived_from<Stereo::Input, DESTINATION>())
3617 destination.input(source); // input to destination (enables overriding of <<)
3618 else
3619 destination << source; // copy to destination
3620 return destination;
3621 }

Referenced by klang::Envelope::Follower::rms().

◆ operator>>() [3/8]

static signal & klang::operator>> ( float input,
signal & destination )
inlinestatic

Definition at line 495 of file klang.h.

495 { // CHECK: should this be signal, rather than float?
496 destination << signal(input);
497 return destination;
498 }
A mono audio signal (equivalent to a float).
Definition klang.h:362

References klang::signal::signal().

◆ operator>>() [4/8]

template<class OSCILLATOR >
const signal & klang::operator>> ( klang::signal modulator,
Operator< OSCILLATOR > & carrier )
inline

Definition at line 3060 of file klang.h.

3060 {
3061 carrier << modulator;
3062 return carrier;
3063 }

◆ operator>>() [5/8]

static param & klang::operator>> ( param & from,
param & to )
inlinestatic

Definition at line 676 of file klang.h.

676 {
677 to << from;
678 return to;
679 }

◆ operator>>() [6/8]

template<typename SOURCE , typename DESTINATION >
DESTINATION & klang::operator>> ( SOURCE & source,
DESTINATION & destination )
inline

Definition at line 3601 of file klang.h.

3601 {
3602 if constexpr (is_derived_from<Input, DESTINATION>())
3603 destination.input(source); // input to destination (enables overriding of <<)
3604 else if constexpr (is_derived_from<Stereo::Input, DESTINATION>())
3605 destination.input(source); // input to destination (enables overriding of <<)
3606 else
3607 destination << source; // copy to destination
3608 return destination;
3609 }

Referenced by klang::Envelope::Follower::peak(), and klang::Envelope::Follower::rms().

◆ operator>>() [7/8]

template<typename TYPE >
static Graph & klang::operator>> ( TYPE(* function )(TYPE),
Graph & graph )
static

Definition at line 2143 of file klang.h.

2143 {
2144 graph.plot(function);
2145 return graph;
2146 }
static THREAD_LOCAL GraphPtr graph
Definition klang.h:2122

◆ operator>>() [8/8]

template<typename TYPE >
static GraphPtr & klang::operator>> ( TYPE(* function )(TYPE),
klang::GraphPtr & graph )
static

Definition at line 2131 of file klang.h.

2131 {
2132 graph->plot(function);
2133 return graph;
2134 }

◆ PitchBend()

static Control klang::PitchBend ( )
inlinestatic

Definition at line 1088 of file klang.h.

1089 { return { { "PITCH\nBEND" }, Control::WHEEL, 0.f, 16384.f, 8192.f, Automatic, NoOptions, 8192.f }; }

References Automatic, NoOptions, and klang::Control::WHEEL.

◆ power() [1/2]

template<typename BASE , typename EXP , std::enable_if_t< is_literal< EXP >, bool > >
power_t< BASE, EXP > klang::power ( BASE base,
EXP exp )
inlineconstexpr

Definition at line 150 of file klang.h.

150 {
151 if constexpr (std::is_integral_v<EXP>) {
152 switch (exp) {
153 case 0: return (BASE)1;
154 case 1: return base;
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);
162 default:
163 return poweri<BASE, exp>(base);
164 }
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);
175 }
176 return (BASE)std::pow(base, exp);;
177 }

◆ power() [2/2]

template<typename BASE , typename EXP >
power_t< BASE, EXP > klang::power ( BASE base,
EXP exp )
inlineconstexpr

Definition at line 181 of file klang.h.

181 {
182 if constexpr (std::is_integral_v<BASE>) {
183 return power(float(base), exp);
184 } else if constexpr (std::is_integral_v<EXP>) {
185 switch (exp) {
186 case 0: return (BASE)1;
187 case 1: return base;
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);
195 }
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);
207 }
208 return power_t<BASE, EXP>(std::pow(base, exp));
209 }
constexpr power_t< BASE, EXP > power(BASE base, EXP exp)
Raise base to the power exp.
Definition klang.h:150

Referenced by klang::Amplitude::Amplitude(), klang::dB::operator->(), klang::Pitch::operator->(), klang::signal::operator^(), klang::signal::operator^(), and klang::signal::operator^().

◆ poweri()

template<typename BASE , int EXP>
BASE klang::poweri ( BASE base)
inlineconstexpr

Definition at line 132 of file klang.h.

132 {
133 BASE result = 1;
134 constexpr bool negative = EXP < 0;
135 int exp = negative ? -EXP : EXP;
136 while (exp > 0) {
137 if (exp % 2 == 1)
138 result *= base;
139 base *= base;
140 exp >>= 1;
141 }
142 return negative ? 1 / result : result;
143 }

◆ random() [1/2]

template<typename TYPE >
static TYPE klang::random ( const TYPE min,
const TYPE max )
inlinestatic

Definition at line 228 of file klang.h.

228{ return rand() * ((max - min) / (TYPE)RAND_MAX) + min; }

◆ random() [2/2]

static void klang::random ( const unsigned int seed)
inlinestatic

Definition at line 231 of file klang.h.

231{ srand(seed); }

◆ Slider()

static Control klang::Slider ( const char * name,
float min = 0.f,
float max = 1.f,
float initial = 0.f )
inlinestatic

Definition at line 1072 of file klang.h.

1073 { return { Caption::from(name), Control::SLIDER, min, max, initial, Automatic, NoOptions, initial }; }

References Automatic, klang::Text< SIZE >::from(), NoOptions, and klang::Control::SLIDER.

◆ sqr()

static Function< float > klang::sqr ( [] (float x) -> float { return x *x;} )
inlinestatic

◆ sqrt()

static Function< float > klang::sqrt ( SQRTF )
inlinestatic

◆ Toggle()

static Control klang::Toggle ( const char * name,
bool initial = false )
inlinestatic

Definition at line 1069 of file klang.h.

1070 { return { Caption::from(name), Control::TOGGLE, 0, 1, initial ? 1.f : 0.f, Automatic, NoOptions, initial ? 1.f : 0.f}; }

References Automatic, klang::Text< SIZE >::from(), NoOptions, and klang::Control::TOGGLE.

Variable Documentation

◆ Automatic

const Control::Size klang::Automatic = { -1, -1, -1, -1 }

Definition at line 1038 of file klang.h.

1038{ -1, -1, -1, -1 };

Referenced by Button(), Dial(), Meter(), ModWheel(), PitchBend(), Slider(), and Toggle().

◆ debug

Debug klang::debug
static

◆ fs

klang::dB klang::fs

◆ graph

THREAD_LOCAL GraphPtr klang::graph
static

Definition at line 2122 of file klang.h.

◆ is_literal

template<typename T >
bool klang::is_literal = std::is_trivially_constructible_v<T> && std::is_trivially_copyable_v<T> && std::is_trivially_destructible_v<T>
inlineconstexpr

Definition at line 117 of file klang.h.

◆ ln2

constant klang::ln2 = { 0.6931471805599453094172321214581 }
constexpr

Definition at line 221 of file klang.h.

221{ 0.6931471805599453094172321214581 };

◆ NoOptions

const Control::Options klang::NoOptions

Definition at line 1039 of file klang.h.

Referenced by Button(), Dial(), Meter(), ModWheel(), PitchBend(), Slider(), and Toggle().

◆ pi

◆ root2

constant klang::root2 = { 1.4142135623730950488016887242097 }
constexpr

Definition at line 224 of file klang.h.

224{ 1.4142135623730950488016887242097 };

◆ version

struct klang::Version klang::version = { 0, 7, 0, KLANG_DEBUG }