Klang C++
Language Reference (draft)
Loading...
Searching...
No Matches
klang::signals< CHANNELS >

A multi-channel audio signal (e.g. stereo). More...

#include <klang.h>

Public Member Functions

signal mono () const
 Return the mono mix of a stereo channel.
 
signaloperator[] (int index)
 Return a reference to the signal at the specified index (0 = left, 1 = right).
 
const signaloperator[] (int index) const
 Return a read-only reference to the signal at the specified index (0 = left, 1 = right).
 
 signals (float initial=0.f)
 Create a stereo signal with the given value.
 
 signals (double initial)
 Create a stereo signal with the given value.
 
 signals (int initial)
 Create a stereo signal with the given value.
 
 signals (float left, float right)
 Create a stereo signal with the given left and right value.
 
 signals (double left, double right)
 Create a stereo signal with the given left and right value.
 
 signals (int left, int right)
 Create a stereo signal with the given left and right value.
 
template<typename... Args, typename = std::enable_if_t<(std::is_convertible_v<Args, signal> && ...)>>
 signals (Args &... initial)
 Create a multi-channel signal with the given channel values.
 
template<typename... Args, typename = std::enable_if_t<(std::is_scalar_v<Args> && ...)>>
 signals (Args... initial)
 Create a multi-channel signal with the given channel values.
 
int channels () const
 Returns the number of channels in the signal.
 
const signalsoperator<< (const signals &input)
 Feedback operator (prevents further processing of returned value).
 
signalsoperator>> (signals &destination) const
 Stream operator (feedforward; allows further processing).
 
signalsoperator+= (const signals x)
 Add (mix) another signal to the signal.
 
signalsoperator-= (const signals x)
 Subtract another signal from the signal.
 
signalsoperator*= (const signals x)
 Multiply (modulate) signal by another signal.
 
signalsoperator/= (const signals x)
 Divide signal by another signal.
 
signals operator+ (const signals x) const
 Add two multi-channel signals together.
 
signals operator- (const signals x) const
 Subtract one multi-channel signal from another.
 
signals operator* (const signals x) const
 Multiply (modulate) two multi-channel signals.
 
signals operator/ (const signals x) const
 Divide one multi-channel signal by another.
 
signals operator+ (const signal x) const
 Return a copy of the multi-channel signal, adding a mono signal to each channel.
 
signals operator- (const signal x) const
 Return a copy of the multi-channel signal, subtracting a mono signal from each channel.
 
signals operator* (const signal x) const
 Return a copy of the multi-channel signal, multiplying (modulating) each channel by a mono signal.
 
signals operator/ (const signal x) const
 Return a copy of the multi-channel signal, dividing each channel by a mono signal.
 
signals operator+ (float x) const
 Return a copy of the signal with each channel offset by x.
 
signals operator- (float x) const
 Return a copy of the signal with each channel offset by -x.
 
signals operator* (float x) const
 Return a copy of the signal with each channel scaled by x.
 
signals operator/ (float x) const
 Return a copy of the signal with each channel divided by x.
 
signals operator+ (double x) const
 Return a copy of the signal with each channel offset by x.
 
signals operator- (double x) const
 Return a copy of the signal with each channel offset by -x.
 
signals operator* (double x) const
 Return a copy of the signal with each channel scaled by x.
 
signals operator/ (double x) const
 Return a copy of the signal with each channel divided by x.
 
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 offset by -x.
 
signals operator* (int x) const
 Return a copy of the signal with each channel scaled by x.
 
signals operator/ (int x) const
 Return a copy of the signal with each channel divided by x.
 

Detailed Description

template<int CHANNELS = 2>
struct klang::signals< CHANNELS >

Definition at line 502 of file klang.h.

Constructor & Destructor Documentation

◆ signals() [1/8]

template<int CHANNELS = 2>
klang::signals< CHANNELS >::signals ( float initial = 0.f)
inline

Definition at line 522 of file klang.h.

522: l(initial), r(initial) { }

References klang::signal::signal().

◆ signals() [2/8]

template<int CHANNELS = 2>
klang::signals< CHANNELS >::signals ( double initial)
inline

Definition at line 524 of file klang.h.

524: l((float)initial), r((float)initial) { }

◆ signals() [3/8]

template<int CHANNELS = 2>
klang::signals< CHANNELS >::signals ( int initial)
inline

Definition at line 526 of file klang.h.

526: l((float)initial), r((float)initial) { }

◆ signals() [4/8]

◆ signals() [5/8]

template<int CHANNELS = 2>
klang::signals< CHANNELS >::signals ( double left,
double right )
inline

Definition at line 531 of file klang.h.

531: l((float)left), r((float)right) { }

◆ signals() [6/8]

template<int CHANNELS = 2>
klang::signals< CHANNELS >::signals ( int left,
int right )
inline

Definition at line 533 of file klang.h.

533: l((float)left), r((float)right) { }

◆ signals() [7/8]

template<int CHANNELS = 2>
template<typename... Args, typename = std::enable_if_t<(std::is_convertible_v<Args, signal> && ...)>>
klang::signals< CHANNELS >::signals ( Args &... initial)
inline

Definition at line 537 of file klang.h.

537: value{ initial... } { }

◆ signals() [8/8]

template<int CHANNELS = 2>
template<typename... Args, typename = std::enable_if_t<(std::is_scalar_v<Args> && ...)>>
klang::signals< CHANNELS >::signals ( Args... initial)
inline

Definition at line 540 of file klang.h.

540: value { initial... } { }

Member Function Documentation

◆ channels()

template<int CHANNELS = 2>
int klang::signals< CHANNELS >::channels ( ) const
inline

Definition at line 543 of file klang.h.

543{ return CHANNELS; }

◆ mono()

template<int CHANNELS = 2>
signal klang::signals< CHANNELS >::mono ( ) const
inline

Definition at line 514 of file klang.h.

514{ return (l + r) * 0.5f; }

◆ operator*() [1/5]

template<int CHANNELS = 2>
signals klang::signals< CHANNELS >::operator* ( const signal x) const
inline

Definition at line 584 of file klang.h.

584{ signals s = *this; for (int v = 0; v < CHANNELS; v++) s[v] *= x; return s; }
signals(float initial=0.f)
Create a stereo signal with the given value.
Definition klang.h:522

◆ operator*() [2/5]

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

Definition at line 570 of file klang.h.

570{ signals s = *this; for (int v = 0; v < CHANNELS; v++) s[v] *= x[v]; return s; }

◆ operator*() [3/5]

template<int CHANNELS = 2>
signals klang::signals< CHANNELS >::operator* ( double x) const
inline

Definition at line 602 of file klang.h.

602{ signals s = *this; for (int v = 0; v < CHANNELS; v++) s[v] *= x; return s; }

◆ operator*() [4/5]

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

Definition at line 593 of file klang.h.

593{ signals s = *this; for(int v = 0; v < CHANNELS; v++) s[v] *= x; return s; }

◆ operator*() [5/5]

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

Definition at line 611 of file klang.h.

611{ signals s = *this; for (int v = 0; v < CHANNELS; v++) s[v] *= x; return s; }

◆ operator*=()

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

Definition at line 561 of file klang.h.

561{ for (int v = 0; v < CHANNELS; v++) value[v] *= x[v]; return *this; }

◆ operator+() [1/5]

template<int CHANNELS = 2>
signals klang::signals< CHANNELS >::operator+ ( const signal x) const
inline

Definition at line 580 of file klang.h.

580{ signals s = *this; for (int v = 0; v < CHANNELS; v++) s[v] += x; return s; }

◆ operator+() [2/5]

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

Definition at line 566 of file klang.h.

566{ signals s = *this; for (int v = 0; v < CHANNELS; v++) s[v] += x[v]; return s; }

◆ operator+() [3/5]

template<int CHANNELS = 2>
signals klang::signals< CHANNELS >::operator+ ( double x) const
inline

Definition at line 598 of file klang.h.

598{ signals s = *this; for (int v = 0; v < CHANNELS; v++) s[v] += x; return s; }

◆ operator+() [4/5]

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

Definition at line 589 of file klang.h.

589{ signals s = *this; for(int v = 0; v < CHANNELS; v++) s[v] += x; return s; }

◆ operator+() [5/5]

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

Definition at line 607 of file klang.h.

607{ signals s = *this; for (int v = 0; v < CHANNELS; v++) s[v] += x; return s; }

◆ operator+=()

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

Definition at line 557 of file klang.h.

557{ for (int v = 0; v < CHANNELS; v++) value[v] += x[v]; return *this; }

◆ operator-() [1/5]

template<int CHANNELS = 2>
signals klang::signals< CHANNELS >::operator- ( const signal x) const
inline

Definition at line 582 of file klang.h.

582{ signals s = *this; for (int v = 0; v < CHANNELS; v++) s[v] -= x; return s; }

◆ operator-() [2/5]

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

Definition at line 568 of file klang.h.

568{ signals s = *this; for (int v = 0; v < CHANNELS; v++) s[v] -= x[v]; return s; }

◆ operator-() [3/5]

template<int CHANNELS = 2>
signals klang::signals< CHANNELS >::operator- ( double x) const
inline

Definition at line 600 of file klang.h.

600{ signals s = *this; for (int v = 0; v < CHANNELS; v++) s[v] -= x; return s; }

◆ operator-() [4/5]

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

Definition at line 591 of file klang.h.

591{ signals s = *this; for(int v = 0; v < CHANNELS; v++) s[v] -= x; return s; }

◆ operator-() [5/5]

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

Definition at line 609 of file klang.h.

609{ signals s = *this; for (int v = 0; v < CHANNELS; v++) s[v] -= x; return s; }

◆ operator-=()

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

Definition at line 559 of file klang.h.

559{ for (int v = 0; v < CHANNELS; v++) value[v] -= x[v]; return *this; }

◆ operator/() [1/5]

template<int CHANNELS = 2>
signals klang::signals< CHANNELS >::operator/ ( const signal x) const
inline

Definition at line 586 of file klang.h.

586{ signals s = *this; for (int v = 0; v < CHANNELS; v++) s[v] /= x; return s; }

◆ operator/() [2/5]

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

Definition at line 572 of file klang.h.

572{ signals s = *this; for (int v = 0; v < CHANNELS; v++) s[v] /= x[v]; return s; }

◆ operator/() [3/5]

template<int CHANNELS = 2>
signals klang::signals< CHANNELS >::operator/ ( double x) const
inline

Definition at line 604 of file klang.h.

604{ signals s = *this; for (int v = 0; v < CHANNELS; v++) s[v] /= x; return s; }

◆ operator/() [4/5]

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

Definition at line 595 of file klang.h.

595{ signals s = *this; for(int v = 0; v < CHANNELS; v++) s[v] /= x; return s; }

◆ operator/() [5/5]

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

Definition at line 613 of file klang.h.

613{ signals s = *this; for (int v = 0; v < CHANNELS; v++) s[v] /= x; return s; }

◆ operator/=()

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

Definition at line 563 of file klang.h.

563{ for (int v = 0; v < CHANNELS; v++) value[v] /= x[v]; return *this; }

◆ operator<<()

template<int CHANNELS = 2>
const signals & klang::signals< CHANNELS >::operator<< ( const signals< CHANNELS > & input)
inline

Definition at line 546 of file klang.h.

546 {
547 return this->operator=(input);
548 }

◆ operator>>()

template<int CHANNELS = 2>
signals & klang::signals< CHANNELS >::operator>> ( signals< CHANNELS > & destination) const
inline

Definition at line 551 of file klang.h.

551 {
552 destination = *this;
553 return destination;
554 }

◆ operator[]() [1/2]

template<int CHANNELS = 2>
signal & klang::signals< CHANNELS >::operator[] ( int index)
inline

Definition at line 517 of file klang.h.

517{ return value[index]; }

◆ operator[]() [2/2]

template<int CHANNELS = 2>
const signal & klang::signals< CHANNELS >::operator[] ( int index) const
inline

Definition at line 519 of file klang.h.

519{ return value[index]; }

Referenced by klang::operator*().