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

Namespaces

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

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  ControlEntry
 Construction-time entry: temporary controls are owned; mutable lvalues are borrowed. More...
 
struct  Controller
 Base class for UI / MIDI controll. More...
 
struct  ControlMap
 Mapped UI control. More...
 
struct  Controls
 
struct  dB
 Control parameter (idecibels) More...
 
struct  Debug
 The Klang debug interface. More...
 
struct  Delay
 Audio delay object (fixed size) More...
 
struct  Delay< 0 >
 Audio delay object (resizable) More...
 
struct  Effect
 Effect mini-plugin (mono) More...
 
class  Envelope
 Envelope object. More...
 
struct  File
 
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  Group
 Optional presentation grouping, independent of value ownership. More...
 
struct  increment
 A phase or wavetable increment. More...
 
struct  Input
 Audio input object (mono) More...
 
struct  Matrix
 Matrix processor. More...
 
struct  Memory
 
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...
 
class  Sample
 Sample-based signal generator with variable-rate playback. 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  Sound
 
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

typedef unsigned char byte
 
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.
 
using UnaryFunction = float(float)
 A stateless unary C/C++ function that maps one float sample to another.
 
using Hz = Frequency
 Frequency in hertz.
 
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 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).
 
template<typename TYPE , std::enable_if_t< std::is_arithmetic_v< TYPE >, int > = 0>
signal & operator>> (TYPE input, signal &destination)
 Stream a built-in arithmetic value into a signal, narrowing at the signal boundary.
 
signal & operator>> (const constant &input, signal &destination)
 Stream a Klang constant into a signal.
 
signal operator>> (signal input, UnaryFunction &function)
 Apply an ordinary unary function within a signal-flow expression.
 
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 param & operator>> (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)
 
template<int CHANNELS = 2>
signals< CHANNELS > operator+ (const Control &x, const signals< CHANNELS > &y)
 Return a copy of the signal with each channel offset by x.
 
template<int CHANNELS = 2>
signals< CHANNELS > operator- (const Control &x, const signals< CHANNELS > &y)
 Return a copy of the signal with each channel subtracted from x.
 
template<int CHANNELS = 2>
signals< CHANNELS > operator* (const Control &x, const signals< CHANNELS > &y)
 Return a copy of the signal with each channel scaled by x.
 
template<int CHANNELS = 2>
signals< CHANNELS > operator/ (const Control &x, const signals< CHANNELS > &y)
 Return a copy of the signal with each channel divided into x.
 
 IS_SIMPLE_TYPE (Control)
 
static Control Dial (const char *name, float min=0.f, float max=1.f, float initial=0.f, Control::Size size=Automatic)
 
static Control Button (const char *name, Control::Size size=Automatic)
 
static Control Toggle (const char *name, bool initial=false, Control::Size size=Automatic)
 
static Control Slider (const char *name, float min=0.f, float max=1.f, float initial=0.f, Control::Size size=Automatic)
 
template<typename... Options>
static Control Menu (const char *name, const Options... options)
 
template<typename... Options>
static Control Menu (const char *name, Control::Size size, const Options... options)
 
static Control Meter (const char *name, float min=0.f, float max=1.f, float initial=0.f, Control::Size size=Automatic)
 
static Control PitchBend (Control::Size size=Automatic)
 
static Control ModWheel (Control::Size size=Automatic)
 
template<typename... Args>
 Function (float(*)(Args...)) -> Function< Args... >
 
static GraphPtr & operator>> (UnaryFunction &function, klang::GraphPtr &graph)
 
template<typename TYPE >
static GraphPtr & operator>> (TYPE(*function)(TYPE), klang::GraphPtr &graph)
 
static Graph & operator>> (UnaryFunction &function, Graph &graph)
 
template<typename TYPE >
static Graph & operator>> (TYPE(*function)(TYPE), Graph &graph)
 
template<typename LEFT , typename RIGHT , std::enable_if_t< std::is_arithmetic_v< LEFT > &&std::is_arithmetic_v< RIGHT >, int > = 0>
auto mod (LEFT left, RIGHT right)
 Return the C++ remainder for integers and the floating-point remainder otherwise.
 
float truncate (float input)
 Alias for trunc, including signal-flow use.
 
template<typename TYPE , std::enable_if_t< std::is_arithmetic_v< TYPE >, int > = 0>
auto truncate (TYPE input)
 
template<typename... ARGS>
auto clip (ARGS &&... args) -> decltype(clamp(std::forward< ARGS >(args)...))
 Alias clamp as clip for signal-flow terminology.
 
template<typename TYPE , std::enable_if_t< std::is_arithmetic_v< TYPE >, int > = 0>
TYPE sqr (TYPE input)
 Stateless square and cube functions preserve Klang signals in audio expressions.
 
template<typename TYPE , std::enable_if_t< std::is_arithmetic_v< TYPE >, int > = 0>
TYPE cube (TYPE input)
 
template<class OSCILLATOR >
const signal & operator>> (klang::signal modulator, Operator< OSCILLATOR > &carrier)
 
template<typename SOURCE , typename DESTINATION , class = decltype( detail::flow_destination<SOURCE&, DESTINATION>(std::bool_constant< is_derived_from<Input, DESTINATION>() || is_derived_from<Stereo::Input, DESTINATION>()>{}))>
DESTINATION & operator>> (SOURCE &source, DESTINATION &destination)
 Feed audio source to destination (with source processing)
 
template<typename SOURCE , typename DESTINATION , class = decltype( detail::flow_destination<const SOURCE&, DESTINATION>(std::bool_constant< is_derived_from<Input, DESTINATION>() || is_derived_from<Stereo::Input, DESTINATION>()>{}))>
DESTINATION & operator>> (const SOURCE &source, DESTINATION &destination)
 Feed audio source to destination (no source processing)
 

Variables

struct klang::Version version = { 0, 7, 15, 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
 
constexpr Sample::Mode OneShot = Sample::OneShot
 
constexpr Sample::Mode Looped = Sample::Looped
 

Class Documentation

◆ klang::Preset

struct klang::Preset

Definition at line 2556 of file klang.h.

Class Members
Caption name = { 0 }
Values values

Typedef Documentation

◆ byte

typedef unsigned char klang::byte

Definition at line 135 of file klang.h.

◆ Caption

typedef Text<32> klang::Caption

Definition at line 1116 of file klang.h.

◆ event

typedef void klang::event

Definition at line 303 of file klang.h.

◆ Hz

Definition at line 1740 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 212 of file klang.h.

◆ UnaryFunction

using klang::UnaryFunction = float(float)

Definition at line 1268 of file klang.h.

◆ Values

typedef Array<float, 128> klang::Values

Definition at line 2553 of file klang.h.

◆ Velocity

Definition at line 1802 of file klang.h.

Enumeration Type Documentation

◆ Mode

Values
Peak 
RMS 
Mean 

Definition at line 149 of file klang.h.

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

Function Documentation

◆ are_scalars()

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

Definition at line 192 of file klang.h.

192 {
193 using T = std::decay_t<decltype(head)>;
194 return std::is_scalar_v<T> && ((sizeof... (Tail)) == 0 || are_scalars(std::forward<decltype(tail)>(tail)...));
195 }
constexpr bool are_scalars(Head &&head, Tail &&... tail)
Definition klang.h:192

References are_scalars().

Referenced by are_scalars().

◆ Button()

static Control klang::Button ( const char * name,
Control::Size size = Automatic )
inlinestatic

Definition at line 1967 of file klang.h.

1968 {
1969 return { Caption::from(name), Control::BUTTON, 0, 1, 0.f, size, NoOptions, 0.f };
1970 }
const Control::Options NoOptions
Definition klang.h:1915

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

◆ clip()

template<typename... ARGS>
auto klang::clip ( ARGS &&... args) -> decltype(clamp(std::forward<ARGS>(args)...))
inline

Definition at line 4184 of file klang.h.

4184 {
4185 return clamp(std::forward<ARGS>(args)...);
4186 }

◆ cube()

template<typename TYPE , std::enable_if_t< std::is_arithmetic_v< TYPE >, int > = 0>
TYPE klang::cube ( TYPE input)
inline

Definition at line 4201 of file klang.h.

4201{ return input * input * input; }

◆ Dial()

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

Definition at line 1962 of file klang.h.

1963 {
1964 return { Caption::from(name), Control::ROTARY, min, max, initial, size, NoOptions, initial };
1965 }

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

◆ fast_mod() [1/2]

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

Definition at line 1537 of file klang.h.

1537 {
1538 const unsigned long long i = (((unsigned long long)(x * (double(ULLONG_MAX) + 1.0) / y)) >> 12ULL) | 0x7FF0000000000000ULL;
1539 return (*(const double*)&i - 1.0) * y;
1540 }

References fast_mod().

◆ fast_mod() [2/2]

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

Definition at line 1532 of file klang.h.

1532 {
1533 const unsigned int i = (((unsigned int)(x * (float(UINT_MAX) + 1.f) / y)) >> 9) | 0x3f800000;
1534 return (*(const float*)&i - 1.f) * y;
1535 }

References fast_mod().

Referenced by fast_mod(), fast_mod(), and klang::Phase::operator%().

◆ fast_mod1() [1/2]

double klang::fast_mod1 ( double x)
inline

Definition at line 1547 of file klang.h.

1547 {
1548 const unsigned long long i = (((unsigned long long)(x * (double(ULLONG_MAX) + 1.0))) >> 12ULL) | 0x7FF0000000000000ULL;
1549 return (*(const double*)&i - 1.0);
1550 }

References fast_mod1().

◆ fast_mod1() [2/2]

float klang::fast_mod1 ( float x)
inline

Definition at line 1542 of file klang.h.

1542 {
1543 const unsigned int i = ((unsigned int)(x * (float(UINT_MAX) + 1.f)) >> 9) | 0x3f800000;
1544 return *(const float*)&i - 1.f;
1545 }

References fast_mod1().

Referenced by fast_mod1(), and fast_mod1().

◆ fast_mod2pi() [1/2]

double klang::fast_mod2pi ( double x)
inline

Definition at line 1564 of file klang.h.

1564 {
1565 constexpr double twoPi = (2.0 * 3.1415926535897932384626433832795);
1566 const unsigned long long i = (((unsigned long long)(x * (double(ULLONG_MAX) + 1.0) / twoPi)) >> 12ULL) | 0x7FF0000000000000ULL;
1567 return (*(const double*)&i - 1.0) * twoPi;
1568 }

References fast_mod2pi().

◆ fast_mod2pi() [2/2]

float klang::fast_mod2pi ( float x)
inline

Definition at line 1552 of file klang.h.

1552 {
1553 constexpr float twoPi = float(2.0 * 3.1415926535897932384626433832795);
1554 const unsigned int i = (((unsigned int)(x * (float(UINT_MAX) + 1.f) / twoPi)) >> 9) | 0x3f800000;
1555 return (*(const float*)&i - 1.f) * twoPi;
1556 }

References fast_mod2pi().

Referenced by klang::fast::cos(), fast_mod2pi(), fast_mod2pi(), and klang::fast::sin().

◆ fast_modi()

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

Definition at line 1571 of file klang.h.

1571 {
1572 constexpr double size = double(SIZE);
1573 constexpr double sizeInv = 1.0 / double(SIZE);
1574 const unsigned long long i = (((unsigned long long)(x * (double(ULLONG_MAX) + 1.0) * sizeInv)) >> 12ULL) | 0x7FF0000000000000ULL;
1575 return (*(const double*)&i - 1.0) * size;
1576 }

References fast_modi().

Referenced by fast_modi().

◆ fast_modp()

float klang::fast_modp ( unsigned int x)
inline

Definition at line 1558 of file klang.h.

1558 {
1559 constexpr float twoPi = float(2.0 * 3.1415926535897932384626433832795);
1560 const unsigned int i = (x >> 9) | 0x3f800000;
1561 return (*(const float*)&i - 1.f) * twoPi;
1562 }

References fast_modp().

Referenced by klang::fast::cosp(), fast_modp(), and klang::fast::sinp().

◆ 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 187 of file klang.h.

187 {
188 return std::is_base_of_v<Base, Derived>;
189 }

Referenced by operator>>(), and operator>>().

◆ IS_SIMPLE_TYPE()

klang::IS_SIMPLE_TYPE ( Control )

◆ Menu() [1/2]

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

Definition at line 1983 of file klang.h.

1984 {
1985 Control::Options menu;
1986 const char* strings[] = { options... };
1987 int nbValues = sizeof...(options);
1988 for (int p = 0; p < nbValues; p++)
1989 menu.add(Caption::from(strings[p]));
1990 return { Caption::from(name), Control::MENU, 0, menu.size() - 1.f, 0, Automatic, menu, 0 };
1991 }
unsigned int size() const
The current number of items in the array.
Definition klang.h:315
void add(const TYPE &item)
Add the specified item to the end of the array.
Definition klang.h:318

References klang::Array< TYPE, CAPACITY >::add(), Automatic, klang::Text< 32 >::from(), klang::Control::MENU, and klang::Array< TYPE, CAPACITY >::size().

◆ Menu() [2/2]

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

Definition at line 1994 of file klang.h.

1995 {
1996 Control::Options menu;
1997 const char* strings[] = { options... };
1998 int nbValues = sizeof...(options);
1999 for (int p = 0; p < nbValues; p++)
2000 menu.add(Caption::from(strings[p]));
2001 return { Caption::from(name), Control::MENU, 0, menu.size() - 1.f, 0, size, menu, 0 };
2002 }

References klang::Array< TYPE, CAPACITY >::add(), klang::Text< 32 >::from(), klang::Control::MENU, and klang::Array< TYPE, CAPACITY >::size().

◆ Meter()

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

Definition at line 2004 of file klang.h.

2005 {
2006 return { Caption::from(name), Control::METER, min, max, initial, size, NoOptions, initial };
2007 }

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

◆ mod()

template<typename LEFT , typename RIGHT , std::enable_if_t< std::is_arithmetic_v< LEFT > &&std::is_arithmetic_v< RIGHT >, int > = 0>
auto klang::mod ( LEFT left,
RIGHT right )
inline

Definition at line 3881 of file klang.h.

3881 {
3882 if constexpr (std::is_integral_v<LEFT> && std::is_integral_v<RIGHT>)
3883 return left % right;
3884 else {
3885 using Float = std::conditional_t<
3886 std::is_same_v<LEFT, long double> || std::is_same_v<RIGHT, long double>, long double,
3887 std::conditional_t<std::is_same_v<LEFT, double> || std::is_same_v<RIGHT, double>, double, float>>;
3888 return std::fmod(Float(left), Float(right));
3889 }
3890 }

◆ ModWheel()

static Control klang::ModWheel ( Control::Size size = Automatic)
inlinestatic

Definition at line 2014 of file klang.h.

2015 {
2016 return { { "MOD\nWHEEL" }, Control::WHEEL, 0.f, 127.f, 0.f, size, NoOptions, 0.f };
2017 }

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

◆ operator*() [1/3]

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

Definition at line 1922 of file klang.h.

1922{ return y * x.value; }
signal value
Definition klang.h:1857

References operator*(), and klang::Control::value.

◆ operator*() [2/3]

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

Definition at line 1597 of file klang.h.

1597 {
1598 return { m[0][0] * in[0] + m[0][1] * in[1] + m[0][2] * in[2] + m[0][3] * in[3],
1599 m[1][0] * in[0] + m[1][1] * in[1] + m[1][2] * in[2] + m[1][3] * in[3],
1600 m[2][0] * in[0] + m[2][1] * in[1] + m[2][2] * in[2] + m[2][3] * in[3],
1601 m[3][0] * in[0] + m[3][1] * in[1] + m[3][2] * in[2] + m[3][3] * in[3] };
1602 }

References operator*().

◆ operator*() [3/3]

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

Definition at line 1450 of file klang.h.

1450{ return y * x; }

References operator*().

Referenced by operator*(), operator*(), operator*(), and operator>>().

◆ operator+() [1/2]

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

Definition at line 1918 of file klang.h.

1918{ return y + x.value; }

References operator+(), and klang::Control::value.

◆ operator+() [2/2]

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

Definition at line 1446 of file klang.h.

1446{ return y + x; }

References operator+().

Referenced by operator+(), and operator+().

◆ operator-() [1/2]

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

Definition at line 1920 of file klang.h.

1920{ return -y + x.value; }

References operator-(), and klang::Control::value.

◆ operator-() [2/2]

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

Definition at line 1448 of file klang.h.

1448{ return -y + x; }

References operator-().

Referenced by operator-(), and operator-().

◆ operator/() [1/2]

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

Definition at line 1924 of file klang.h.

1924 {
1925 signals<CHANNELS> s = { 0.f };
1926 for (int c = 0; c < CHANNELS; c++)
1927 s[c] = x.value / y[c];
1928 return std::move(s);
1929 }
A multi-channel audio signal (e.g. stereo).
Definition klang.h:1278

References operator/(), and klang::Control::value.

◆ operator/() [2/2]

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

Definition at line 1452 of file klang.h.

1452 {
1453 signals<CHANNELS> s = { 0.f };
1454 for (int c = 0; c < CHANNELS; c++)
1455 s[c] = x / y[c];
1456 return std::move(s);
1457 }

References operator/().

Referenced by operator/(), and operator/().

◆ operator>>() [1/12]

signal & klang::operator>> ( const constant & input,
signal & destination )
inline

Definition at line 1262 of file klang.h.

1262 {
1263 destination << signal(input.f);
1264 return destination;
1265 }
const float f
Constant as float.
Definition klang.h:162
A mono audio signal (equivalent to a float).
Definition klang.h:1123

References klang::constant::f.

◆ operator>>() [2/12]

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

Definition at line 1604 of file klang.h.

1604{ 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:1450

References operator*(), and operator>>().

◆ operator>>() [3/12]

template<typename SOURCE , typename DESTINATION , class = decltype( detail::flow_destination<const SOURCE&, DESTINATION>(std::bool_constant< is_derived_from<Input, DESTINATION>() || is_derived_from<Stereo::Input, DESTINATION>()>{}))>
DESTINATION & klang::operator>> ( const SOURCE & source,
DESTINATION & destination )
inline

Definition at line 6283 of file klang.h.

6283 {
6284 if constexpr (is_derived_from<Input, DESTINATION>())
6285 destination.input(source); // input to destination (enables overriding of <<)
6286 else if constexpr (is_derived_from<Stereo::Input, DESTINATION>())
6287 destination.input(source); // input to destination (enables overriding of <<)
6288 else
6289 destination << source; // copy to destination
6290 return destination;
6291 }

References is_derived_from().

◆ operator>>() [4/12]

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

Definition at line 5501 of file klang.h.

5501 {
5502 carrier << modulator;
5503 return carrier;
5504 }

◆ operator>>() [5/12]

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

Definition at line 1511 of file klang.h.

1511 {
1512 to << from;
1513 return to;
1514 }

References operator>>().

◆ operator>>() [6/12]

signal klang::operator>> ( signal input,
UnaryFunction & function )
inline

Definition at line 1271 of file klang.h.

1271 {
1272 return function(float(input));
1273 }

◆ operator>>() [7/12]

template<typename SOURCE , typename DESTINATION , class = decltype( detail::flow_destination<SOURCE&, DESTINATION>(std::bool_constant< is_derived_from<Input, DESTINATION>() || is_derived_from<Stereo::Input, DESTINATION>()>{}))>
DESTINATION & klang::operator>> ( SOURCE & source,
DESTINATION & destination )
inline

Definition at line 6268 of file klang.h.

6268 {
6269 if constexpr (is_derived_from<Input, DESTINATION>())
6270 destination.input(source); // input to destination (enables overriding of <<)
6271 else if constexpr (is_derived_from<Stereo::Input, DESTINATION>())
6272 destination.input(source); // input to destination (enables overriding of <<)
6273 else
6274 destination << source; // copy to destination
6275 return destination;
6276 }

References is_derived_from().

◆ operator>>() [8/12]

template<typename TYPE , std::enable_if_t< std::is_arithmetic_v< TYPE >, int > = 0>
signal & klang::operator>> ( TYPE input,
signal & destination )
inline

Definition at line 1257 of file klang.h.

1257 {
1258 destination << signal(static_cast<float>(input));
1259 return destination;
1260 }

Referenced by operator>>(), and operator>>().

◆ operator>>() [9/12]

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

Definition at line 3860 of file klang.h.

3860 {
3861 graph.plot(function);
3862 return graph;
3863 }
static THREAD_LOCAL GraphPtr graph
Definition klang.h:3829

References graph.

◆ operator>>() [10/12]

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

Definition at line 3843 of file klang.h.

3843 {
3844 graph->plot(function);
3845 return graph;
3846 }

References graph.

◆ operator>>() [11/12]

static Graph & klang::operator>> ( UnaryFunction & function,
Graph & graph )
inlinestatic

Definition at line 3854 of file klang.h.

3854 {
3855 graph.plot(static_cast<float(*)(float)>(function));
3856 return graph;
3857 }

References graph.

◆ operator>>() [12/12]

static GraphPtr & klang::operator>> ( UnaryFunction & function,
klang::GraphPtr & graph )
inlinestatic

Definition at line 3837 of file klang.h.

3837 {
3838 graph->plot(static_cast<float(*)(float)>(function));
3839 return graph;
3840 }

References graph.

◆ PitchBend()

static Control klang::PitchBend ( Control::Size size = Automatic)
inlinestatic

Definition at line 2009 of file klang.h.

2010 {
2011 return { { "PITCH\nBEND" }, Control::WHEEL, 0.f, 16384.f, 8192.f, size, NoOptions, 8192.f };
2012 }

References 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 216 of file klang.h.

216 {
217 if constexpr (std::is_integral_v<EXP>) {
218 switch (exp) {
219 case 0: return (BASE)1;
220 case 1: return base;
221 case 2: return base * base;
222 case 3: return base * base * base;
223 case 4: return base * base * base * base;
224 case -1: return (BASE)1 / base;
225 case -2: return (BASE)1 / (base * base);
226 case -3: return (BASE)1 / (base * base * base);
227 case -4: return (BASE)1 / (base * base * base * base);
228 default:
229 return poweri<BASE, exp>(base);
230 }
231 }
232 else if constexpr (std::is_floating_point_v<EXP>) {
233 if constexpr (exp == (EXP)0) return 1;
234 else if constexpr (exp == (EXP)1) return base;
235 else if constexpr (exp == (EXP)2) return base * base;
236 else if constexpr (exp == (EXP)3) return base * base * base;
237 else if constexpr (exp == (EXP)4) return base * base * base * base;
238 else if constexpr (exp == (EXP)-1) return 1 / base;
239 else if constexpr (exp == (EXP)-2) return 1 / (base * base);
240 else if constexpr (exp == (EXP)-3) return 1 / (base * base * base);
241 else if constexpr (exp == (EXP)-4) return 1 / (base * base * base * base);
242 }
243 return (BASE)std::pow(base, exp);;
244 }

References poweri().

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

◆ power() [2/2]

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

Definition at line 248 of file klang.h.

248 {
249 if constexpr (std::is_integral_v<BASE>) {
250 return power(float(base), exp);
251 }
252 else if constexpr (std::is_integral_v<EXP>) {
253 switch (exp) {
254 case 0: return (BASE)1;
255 case 1: return base;
256 case 2: return base * base;
257 case 3: return base * base * base;
258 case 4: return base * base * base * base;
259 case -1: return (BASE)1 / base;
260 case -2: return (BASE)1 / (base * base);
261 case -3: return (BASE)1 / (base * base * base);
262 case -4: return (BASE)1 / (base * base * base * base);
263 }
264 }
265 else if constexpr (std::is_floating_point_v<EXP>) {
266 if (base == (BASE)10) return (power_t<BASE, EXP>)::exp(exp * (EXP)2.3025850929940456840179914546843642076011014886287729760333279009);
267 else if (exp == (EXP)0) return (power_t<BASE, EXP>)1;
268 else if (exp == (EXP)1) return base;
269 else if (exp == (EXP)2) return base * base;
270 else if (exp == (EXP)3) return base * base * base;
271 else if (exp == (EXP)4) return base * base * base * base;
272 else if (exp == (EXP)-1) return (power_t<BASE, EXP>)1 / base;
273 else if (exp == (EXP)-2) return (power_t<BASE, EXP>)1 / (base * base);
274 else if (exp == (EXP)-3) return (power_t<BASE, EXP>)1 / (base * base * base);
275 else if (exp == (EXP)-4) return (power_t<BASE, EXP>)1 / (base * base * base * base);
276 }
277 return power_t<BASE, EXP>(std::pow(base, exp));
278 }
constexpr power_t< BASE, EXP > power(BASE base, EXP exp)
Raise base to the power exp.
Definition klang.h:216

References power().

◆ poweri()

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

Definition at line 198 of file klang.h.

198 {
199 BASE result = 1;
200 constexpr bool negative = EXP < 0;
201 int exp = negative ? -EXP : EXP;
202 while (exp > 0) {
203 if (exp % 2 == 1)
204 result *= base;
205 base *= base;
206 exp >>= 1;
207 }
208 return negative ? 1 / result : result;
209 }

Referenced by power().

◆ random() [1/2]

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

Definition at line 297 of file klang.h.

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

◆ random() [2/2]

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

Definition at line 300 of file klang.h.

300{ srand(seed); }

◆ Slider()

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

Definition at line 1977 of file klang.h.

1978 {
1979 return { Caption::from(name), Control::SLIDER, min, max, initial, size, NoOptions, initial };
1980 }

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

◆ sqr()

template<typename TYPE , std::enable_if_t< std::is_arithmetic_v< TYPE >, int > = 0>
TYPE klang::sqr ( TYPE input)
inline

Definition at line 4199 of file klang.h.

4199{ return input * input; }

◆ Toggle()

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

Definition at line 1972 of file klang.h.

1973 {
1974 return { Caption::from(name), Control::TOGGLE, 0, 1, initial ? 1.f : 0.f, size, NoOptions, initial ? 1.f : 0.f };
1975 }

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

◆ truncate() [1/2]

float klang::truncate ( float input)
inline

Definition at line 4115 of file klang.h.

4115{ return std::trunc(input); }

◆ truncate() [2/2]

template<typename TYPE , std::enable_if_t< std::is_arithmetic_v< TYPE >, int > = 0>
auto klang::truncate ( TYPE input)
inline

Definition at line 4117 of file klang.h.

4117{ return std::trunc(input); }

Variable Documentation

◆ Automatic

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

Definition at line 1914 of file klang.h.

1914{ -1, -1, -1, -1 };

Referenced by Menu().

◆ debug

◆ fs

◆ graph

◆ 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 183 of file klang.h.

◆ ln2

constant klang::ln2 = { 0.6931471805599453094172321214581 }
constexpr

Definition at line 290 of file klang.h.

290{ 0.6931471805599453094172321214581 };

◆ Looped

Sample::Mode klang::Looped = Sample::Looped
inlineconstexpr

Definition at line 5038 of file klang.h.

◆ NoOptions

const Control::Options klang::NoOptions

Definition at line 1915 of file klang.h.

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

◆ OneShot

Sample::Mode klang::OneShot = Sample::OneShot
inlineconstexpr

Definition at line 5037 of file klang.h.

◆ pi

◆ root2

constant klang::root2 = { 1.4142135623730950488016887242097 }
constexpr

Definition at line 293 of file klang.h.

293{ 1.4142135623730950488016887242097 };

Referenced by klang::Filters::Biquad::Filter::set().

◆ version

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