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

Language Guide / Signal Flow

signal

klang::signal

The fundamental type for audio samples in Klang.

A signal holds one 32-bit float. The compiler can optimise its wrapper away, leaving ordinary float operations. Use signals to hold samples, scale or mix them with arithmetic, and express routing with >>.

Example · Scale and route a sample

const signal sample = in * 0.5;
sample >> out;

Example · Route one sample twice

A generator advances when read as a signal. Store the result to send that same sample down multiple paths.

const signal sample = sine;
sample >> out.l;
sample * 0.5 >> out.r;

A mono audio signal (equivalent to a float). More...

#include <klang.h>

+ Inheritance diagram for klang::signal:

Public Member Functions

 signal (constant initial)
 Create signal from a constant.
 
 signal (const float initial=0.f)
 Create signal from a 32-bit float..
 
 signal (const double initial)
 Create signal from a 64-bit double.
 
 signal (const int value)
 Create signal from an 32-bit signed integer.
 
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)
 Assign processed output of in to signal.
 
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-= (const signal &x)
 Subtract another signal from the signal.
 
signal & operator*= (const signal &x)
 Multiply (modulate) signal by another signal.
 
signal & operator/= (const signal &x)
 Divide signal by another signal.
 
signal & operator+= (float x)
 Add the specified amount to the signal.
 
signal & operator-= (float x)
 Subtract the specified amount from the signal.
 
signal & operator*= (float x)
 Multiply signal by the specified amount.
 
signal & operator/= (float x)
 Divide signal by the specified amount.
 
signal & operator+= (double x)
 Add the specified amount to the signal.
 
signal & operator-= (double x)
 Subtract the specified amount from the signal.
 
signal & operator*= (double x)
 Multiply signal by the specified amount.
 
signal & operator/= (double x)
 Divide signal by the specified amount.
 
signal & operator+= (int x)
 Add the specified amount to the signal.
 
signal & operator-= (int x)
 Subtract the specified amount from the signal.
 
signal & operator*= (int x)
 Multiply 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- (float x) const
 Subtract one signal from another.
 
signal operator* (float x) const
 Multiply (modulate) two signals.
 
signal operator/ (float x) const
 Divide one signal by another.
 
signal operator+ (double x) const
 Return a copy of the signal offset by x.
 
signal operator- (double x) const
 Return a copy of the signal offset by -x.
 
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 divided by.
 
signal operator+ (int 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* (int x) const
 Return a copy of the signal scaled by x.
 
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 operator+ () const
 Returns a copy of the signal to treat as a relative offset (e.g. for phase modulation).
 
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 1123 of file klang.h.

Constructor & Destructor Documentation

◆ signal() [1/4]

klang::signal::signal ( constant initial)
inline

Definition at line 1127 of file klang.h.

1127: value(initial.f) {}
float value
Definition klang.h:1124

◆ signal() [2/4]

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

Definition at line 1130 of file klang.h.

1130: value(initial) {}

◆ signal() [3/4]

klang::signal::signal ( const double initial)
inline

Definition at line 1133 of file klang.h.

1133: value((const float)initial) {}

◆ signal() [4/4]

klang::signal::signal ( const int value)
inline

Definition at line 1136 of file klang.h.

1136: value((const float)value) {}

Member Function Documentation

◆ channels()

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

Definition at line 1235 of file klang.h.

1235{ return 1; }

◆ isDenormal()

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

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 }

References value.

◆ operator const float()

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

Definition at line 1225 of file klang.h.

1225{ return value; }

References value.

◆ operator float &()

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

Definition at line 1226 of file klang.h.

1226{ return value; }

References value.

◆ operator*() [1/3]

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

Definition at line 1205 of file klang.h.

1205{ return value * (float)x; }

References value.

◆ operator*() [2/3]

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

Definition at line 1196 of file klang.h.

1196{ return value * x; }

References value.

◆ operator*() [3/3]

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

Definition at line 1214 of file klang.h.

1214{ return value * (float)x; }

References value.

◆ operator*=() [1/4]

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

Definition at line 1160 of file klang.h.

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

References value.

◆ operator*=() [2/4]

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

Definition at line 1178 of file klang.h.

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

References value.

◆ operator*=() [3/4]

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

Definition at line 1169 of file klang.h.

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

References value.

◆ operator*=() [4/4]

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

Definition at line 1187 of file klang.h.

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

References value.

◆ operator+() [1/4]

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

Definition at line 1251 of file klang.h.

1251{ return { value }; }

References value.

◆ operator+() [2/4]

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

Definition at line 1201 of file klang.h.

1201{ return value + (float)x; }

References value.

◆ operator+() [3/4]

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

Definition at line 1192 of file klang.h.

1192{ return value + x; }

References value.

◆ operator+() [4/4]

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

Definition at line 1210 of file klang.h.

1210{ return value + (float)x; }

References value.

◆ operator+=() [1/5]

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

Definition at line 1156 of file klang.h.

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

References value.

◆ operator+=() [2/5]

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

Definition at line 1174 of file klang.h.

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

References value.

◆ operator+=() [3/5]

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

Definition at line 1165 of file klang.h.

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

References value.

◆ operator+=() [4/5]

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

Definition at line 1183 of file klang.h.

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

References value.

◆ operator+=() [5/5]

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

Definition at line 3872 of file klang.h.

3872 { // e.g. out += osc;
3873 value += signal(in);
3874 return *this;
3875 }
signal(constant initial)
Create signal from a constant.
Definition klang.h:1127

◆ operator-() [1/3]

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

Definition at line 1203 of file klang.h.

1203{ return value - (float)x; }

References value.

◆ operator-() [2/3]

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

Definition at line 1194 of file klang.h.

1194{ return value - x; }

References value.

◆ operator-() [3/3]

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

Definition at line 1212 of file klang.h.

1212{ return value - (float)x; }

References value.

◆ operator-=() [1/4]

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

Definition at line 1158 of file klang.h.

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

References value.

◆ operator-=() [2/4]

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

Definition at line 1176 of file klang.h.

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

References value.

◆ operator-=() [3/4]

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

Definition at line 1167 of file klang.h.

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

References value.

◆ operator-=() [4/4]

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

Definition at line 1185 of file klang.h.

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

References value.

◆ operator/() [1/3]

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

Definition at line 1207 of file klang.h.

1207{ return value / (float)x; }

References value.

◆ operator/() [2/3]

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

Definition at line 1198 of file klang.h.

1198{ return value / x; }

References value.

◆ operator/() [3/3]

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

Definition at line 1216 of file klang.h.

1216{ return value / (float)x; }

References value.

◆ operator/=() [1/4]

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

Definition at line 1162 of file klang.h.

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

References value.

◆ operator/=() [2/4]

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

Definition at line 1180 of file klang.h.

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

References value.

◆ operator/=() [3/4]

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

Definition at line 1171 of file klang.h.

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

References value.

◆ operator/=() [4/4]

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

Definition at line 1189 of file klang.h.

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

References value.

◆ operator<<()

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

Definition at line 1139 of file klang.h.

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

References value.

◆ operator=()

signal & klang::signal::operator= ( Output & in)
inline

Definition at line 3866 of file klang.h.

3866 {
3867 b >> *this;
3868 return *this;
3869 }

◆ operator>>()

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

Definition at line 1145 of file klang.h.

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

References value.

◆ operator^() [1/3]

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

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 value.

◆ operator^() [2/3]

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

Definition at line 1219 of file klang.h.

1219{ return power(value, x); }

References klang::power(), and value.

◆ operator^() [3/3]

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

Definition at line 1223 of file klang.h.

1223{ return power(value, x); }

References klang::power(), and value.

◆ relative()

relative klang::signal::relative ( ) const
inline

Definition at line 1253 of file klang.h.

1253{ return { value }; }

References value.

Member Data Documentation

◆ value