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

Language Guide / Signal Flow

param

klang::param

A numeric DSP parameter.

Use param for stored values such as frequency, gain and delay time. It is also the parameter type for virtual set() overloads. Implement the matching overload so the object’s inline call syntax can configure it.

For audio quantities, use types such as Frequency, dB, and Amplitude to make the units explicit. See Frequency and dB for conversion examples.

Example · Cache gain in a modifier

struct LevelStage : Modifier {
    param gain = 1;

    void set(param value) { gain = value; }
    void process() { in * gain >> out; }
};

A signal used as a control parameter. More...

#include <klang.h>

+ Inheritance diagram for klang::param:

Public Member Functions

 param (constant in)
 
 param (const float initial=0.f)
 
 param (const signal &in)
 
 param (signal &in)
 
 param (Control &in)
 
template<typename SOURCE , std::enable_if_t<!std::is_arithmetic_v< std::decay_t< SOURCE > > &&!std::is_base_of_v< signal, std::decay_t< SOURCE > > &&!std::is_same_v< std::decay_t< SOURCE >, Control > &&std::is_convertible_v< SOURCE &&, const signal & >, int > = 0>
 param (SOURCE &&source)
 
param & operator+= (const increment &increment)
 
const signal & operator<< (const signal &input)
 Feedback operator (prevents further processing of returned value).
 
signal & operator>> (signal &destination) const
 Stream operator (feedforward; allows further processing)
 
signal & operator+= (Output &in)
 Adds processed output of in to signal.
 
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)
 Add the specified amount to the signal.
 
signal & operator+= (int x)
 Add the specified amount to the signal.
 
signal & operator-= (const signal &x)
 Subtract another signal from the signal.
 
signal & operator-= (float x)
 Subtract the specified amount from the signal.
 
signal & operator-= (double x)
 Subtract the specified amount from the signal.
 
signal & operator-= (int x)
 Subtract the specified amount from the signal.
 
signal & operator*= (const signal &x)
 Multiply (modulate) signal by another signal.
 
signal & operator*= (float x)
 Multiply signal by the specified amount.
 
signal & operator*= (double x)
 Multiply signal by the specified amount.
 
signal & operator*= (int x)
 Multiply signal by the specified amount.
 
signal & operator/= (const signal &x)
 Divide signal by another signal.
 
signal & operator/= (float x)
 Divide signal by the specified amount.
 
signal & operator/= (double x)
 Divide signal by the specified amount.
 
signal & operator/= (int x)
 Divide signal by the specified amount.
 
signal operator+ (float x) const
 Add two signals together.
 
signal operator+ (double x) const
 Return a copy of the signal offset by x.
 
signal operator+ (int x) const
 Return a copy of the signal offset by x.
 
relative operator+ () const
 Returns a copy of the signal to treat as a relative offset (e.g. for phase modulation).
 
signal operator- (float x) const
 Subtract one signal from another.
 
signal operator- (double x) const
 Return a copy of the signal offset by -x.
 
signal operator- (int x) const
 Return a copy of the signal offset by -x.
 
signal operator* (float x) const
 Multiply (modulate) two signals.
 
signal operator* (double x) const
 Return a copy of the signal scaled by x.
 
signal operator* (int x) const
 Return a copy of the signal scaled by x.
 
signal operator/ (float x) const
 Divide one signal by another.
 
signal operator/ (double x) const
 Return a copy of the signal divided by.
 
signal operator/ (int x) const
 Return a copy of the signal divided by x.
 
signal operator^ (float x) const
 Return a copy of the signal raised to the power of x.
 
signal operator^ (double x) const
 Return a copy of the signal raised to the power of x.
 
signal operator^ (int x) const
 Return a copy of the signal raised to the power of x.
 
 operator const float () const
 
 operator float & ()
 
bool isDenormal () const
 Check if the signal contains a denormal value.
 
int channels () const
 Returns the number of channels (1 = mono).
 
relative relative () const
 Returns a copy of the signal to treat as a relative offset (e.g. for phase modulation).
 

Public Attributes

float value
 

Detailed Description

Definition at line 1486 of file klang.h.

Constructor & Destructor Documentation

◆ param() [1/6]

klang::param::param ( constant in)
inline

Definition at line 1487 of file klang.h.

1487: signal(in.f) {}
signal(constant initial)
Create signal from a constant.
Definition klang.h:1127

◆ param() [2/6]

klang::param::param ( const float initial = 0.f)
inline

Definition at line 1488 of file klang.h.

1488: signal(initial) {}

◆ param() [3/6]

klang::param::param ( const signal & in)
inline

Definition at line 1489 of file klang.h.

1489: signal(in) {}

◆ param() [4/6]

klang::param::param ( signal & in)
inline

Definition at line 1490 of file klang.h.

1490: signal(in) {}

◆ param() [5/6]

klang::param::param ( Control & in)
inline

Definition at line 1960 of file klang.h.

1960: signal(in.value) {}

◆ param() [6/6]

template<typename SOURCE , std::enable_if_t<!std::is_arithmetic_v< std::decay_t< SOURCE > > &&!std::is_base_of_v< signal, std::decay_t< SOURCE > > &&!std::is_same_v< std::decay_t< SOURCE >, Control > &&std::is_convertible_v< SOURCE &&, const signal & >, int > = 0>
klang::param::param ( SOURCE && source)
inline

Definition at line 1496 of file klang.h.

1497 : signal(static_cast<const signal&>(std::forward<SOURCE>(source))) {}

Member Function Documentation

◆ channels()

int klang::signal::channels ( ) const
inlineinherited

Definition at line 1235 of file klang.h.

1235{ return 1; }

◆ isDenormal()

bool klang::signal::isDenormal ( ) const
inlineinherited

Definition at line 1229 of file klang.h.

1229 {
1230 const unsigned int bits = *(const unsigned int*)&value;
1231 return !(bits & 0x7F800000) && (bits & 0x007FFFFF);
1232 }
float value
Definition klang.h:1124

References klang::signal::value.

◆ operator const float()

klang::signal::operator const float ( ) const
inlineinherited

Definition at line 1225 of file klang.h.

1225{ return value; }

References klang::signal::value.

◆ operator float &()

klang::signal::operator float & ( )
inlineinherited

Definition at line 1226 of file klang.h.

1226{ return value; }

References klang::signal::value.

◆ operator*() [1/3]

signal klang::signal::operator* ( double x) const
inlineinherited

Definition at line 1205 of file klang.h.

1205{ return value * (float)x; }

References klang::signal::value.

◆ operator*() [2/3]

signal klang::signal::operator* ( float x) const
inlineinherited

Definition at line 1196 of file klang.h.

1196{ return value * x; }

References klang::signal::value.

◆ operator*() [3/3]

signal klang::signal::operator* ( int x) const
inlineinherited

Definition at line 1214 of file klang.h.

1214{ return value * (float)x; }

References klang::signal::value.

◆ operator*=() [1/4]

signal & klang::signal::operator*= ( const signal & x)
inlineinherited

Definition at line 1160 of file klang.h.

1160{ value *= x.value; return *this; }

References klang::signal::value.

◆ operator*=() [2/4]

signal & klang::signal::operator*= ( double x)
inlineinherited

Definition at line 1178 of file klang.h.

1178{ value *= (float)x; return *this; }

References klang::signal::value.

◆ operator*=() [3/4]

signal & klang::signal::operator*= ( float x)
inlineinherited

Definition at line 1169 of file klang.h.

1169{ value *= x; return *this; }

References klang::signal::value.

◆ operator*=() [4/4]

signal & klang::signal::operator*= ( int x)
inlineinherited

Definition at line 1187 of file klang.h.

1187{ value *= (float)x; return *this; }

References klang::signal::value.

◆ operator+() [1/4]

relative klang::signal::operator+ ( ) const
inlineinherited

Definition at line 1251 of file klang.h.

1251{ return { value }; }

References klang::signal::value.

◆ operator+() [2/4]

signal klang::signal::operator+ ( double x) const
inlineinherited

Definition at line 1201 of file klang.h.

1201{ return value + (float)x; }

References klang::signal::value.

◆ operator+() [3/4]

signal klang::signal::operator+ ( float x) const
inlineinherited

Definition at line 1192 of file klang.h.

1192{ return value + x; }

References klang::signal::value.

◆ operator+() [4/4]

signal klang::signal::operator+ ( int x) const
inlineinherited

Definition at line 1210 of file klang.h.

1210{ return value + (float)x; }

References klang::signal::value.

◆ operator+=() [1/6]

param & klang::param::operator+= ( const increment & increment)
inline

Definition at line 1499 of file klang.h.

1499 {
1500 value += increment.amount;
1501 if (value >= increment.size)
1502 value -= increment.size;
1503 return *this;
1504 }

References klang::increment::amount, and klang::increment::size.

◆ operator+=() [2/6]

signal & klang::signal::operator+= ( const signal & x)
inlineinherited

Definition at line 1156 of file klang.h.

1156{ value += x.value; return *this; }

References klang::signal::value.

◆ operator+=() [3/6]

signal & klang::signal::operator+= ( double x)
inlineinherited

Definition at line 1174 of file klang.h.

1174{ value += (float)x; return *this; }

References klang::signal::value.

◆ operator+=() [4/6]

signal & klang::signal::operator+= ( float x)
inlineinherited

Definition at line 1165 of file klang.h.

1165{ value += x; return *this; }

References klang::signal::value.

◆ operator+=() [5/6]

signal & klang::signal::operator+= ( int x)
inlineinherited

Definition at line 1183 of file klang.h.

1183{ value += (float)x; return *this; }

References klang::signal::value.

◆ operator+=() [6/6]

signal & klang::signal::operator+= ( Output & in)
inlineinherited

Definition at line 3872 of file klang.h.

3872 { // e.g. out += osc;
3873 value += signal(in);
3874 return *this;
3875 }

◆ operator-() [1/3]

signal klang::signal::operator- ( double x) const
inlineinherited

Definition at line 1203 of file klang.h.

1203{ return value - (float)x; }

References klang::signal::value.

◆ operator-() [2/3]

signal klang::signal::operator- ( float x) const
inlineinherited

Definition at line 1194 of file klang.h.

1194{ return value - x; }

References klang::signal::value.

◆ operator-() [3/3]

signal klang::signal::operator- ( int x) const
inlineinherited

Definition at line 1212 of file klang.h.

1212{ return value - (float)x; }

References klang::signal::value.

◆ operator-=() [1/4]

signal & klang::signal::operator-= ( const signal & x)
inlineinherited

Definition at line 1158 of file klang.h.

1158{ value -= x.value; return *this; }

References klang::signal::value.

◆ operator-=() [2/4]

signal & klang::signal::operator-= ( double x)
inlineinherited

Definition at line 1176 of file klang.h.

1176{ value -= (float)x; return *this; }

References klang::signal::value.

◆ operator-=() [3/4]

signal & klang::signal::operator-= ( float x)
inlineinherited

Definition at line 1167 of file klang.h.

1167{ value -= x; return *this; }

References klang::signal::value.

◆ operator-=() [4/4]

signal & klang::signal::operator-= ( int x)
inlineinherited

Definition at line 1185 of file klang.h.

1185{ value -= (float)x; return *this; }

References klang::signal::value.

◆ operator/() [1/3]

signal klang::signal::operator/ ( double x) const
inlineinherited

Definition at line 1207 of file klang.h.

1207{ return value / (float)x; }

References klang::signal::value.

◆ operator/() [2/3]

signal klang::signal::operator/ ( float x) const
inlineinherited

Definition at line 1198 of file klang.h.

1198{ return value / x; }

References klang::signal::value.

◆ operator/() [3/3]

signal klang::signal::operator/ ( int x) const
inlineinherited

Definition at line 1216 of file klang.h.

1216{ return value / (float)x; }

References klang::signal::value.

◆ operator/=() [1/4]

signal & klang::signal::operator/= ( const signal & x)
inlineinherited

Definition at line 1162 of file klang.h.

1162{ value /= x.value; return *this; }

References klang::signal::value.

◆ operator/=() [2/4]

signal & klang::signal::operator/= ( double x)
inlineinherited

Definition at line 1180 of file klang.h.

1180{ value /= (float)x; return *this; }

References klang::signal::value.

◆ operator/=() [3/4]

signal & klang::signal::operator/= ( float x)
inlineinherited

Definition at line 1171 of file klang.h.

1171{ value /= x; return *this; }

References klang::signal::value.

◆ operator/=() [4/4]

signal & klang::signal::operator/= ( int x)
inlineinherited

Definition at line 1189 of file klang.h.

1189{ value /= (float)x; return *this; }

References klang::signal::value.

◆ operator<<()

const signal & klang::signal::operator<< ( const signal & input)
inlineinherited

Definition at line 1139 of file klang.h.

1139 {
1140 value = input;
1141 return *this;
1142 }

References klang::signal::value.

◆ operator>>()

signal & klang::signal::operator>> ( signal & destination) const
inlineinherited

Definition at line 1145 of file klang.h.

1145 {
1146 destination.value = value;
1147 return destination;
1148 }

References klang::signal::value.

◆ operator^() [1/3]

signal klang::signal::operator^ ( double x) const
inlineinherited

Definition at line 1221 of file klang.h.

1221{ return power(value, x); }
constexpr power_t< BASE, EXP > power(BASE base, EXP exp)
Raise base to the power exp.
Definition klang.h:216

References klang::power(), and klang::signal::value.

◆ operator^() [2/3]

signal klang::signal::operator^ ( float x) const
inlineinherited

Definition at line 1219 of file klang.h.

1219{ return power(value, x); }

References klang::power(), and klang::signal::value.

◆ operator^() [3/3]

signal klang::signal::operator^ ( int x) const
inlineinherited

Definition at line 1223 of file klang.h.

1223{ return power(value, x); }

References klang::power(), and klang::signal::value.

◆ relative()

relative klang::signal::relative ( ) const
inlineinherited

Definition at line 1253 of file klang.h.

1253{ return { value }; }

References klang::signal::value.

Member Data Documentation

◆ value