Klang C++
Language Reference (draft)
Loading...
Searching...
No Matches
klang::Generic::Oscillator< SIGNAL >abstract

Audio oscillator object (output) More...

#include <klang.h>

+ Inheritance diagram for klang::Generic::Oscillator< SIGNAL >:

Public Member Functions

virtual ~Oscillator ()
 
virtual void reset ()
 
virtual void set (param frequency)
 
virtual void set (param frequency, param phase)
 
virtual void set (param frequency, relative phase)
 
virtual void set (relative phase)
 
template<typename... params>
Output< SIGNAL > & operator() (params... p)
 
 operator const SIGNAL & () override
 
 operator const SIGNAL & () const override
 
virtual const SIGNAL & output () const
 
template<typename TYPE >
TYPE & operator>> (TYPE &destination)
 
template<typename TYPE >
SIGNAL operator+ (TYPE &other)
 
template<typename TYPE >
SIGNAL operator* (TYPE &other)
 
template<typename TYPE >
SIGNAL operator- (TYPE &other)
 
template<typename TYPE >
SIGNAL operator/ (TYPE &other)
 

Public Attributes

Frequency frequency = 1000.f
 
Phase offset = 0
 
SIGNAL out = { 0.f }
 

Protected Attributes

Phase increment
 
Phase position = 0
 

Detailed Description

template<typename SIGNAL>
struct klang::Generic::Oscillator< SIGNAL >

Definition at line 1948 of file klang.h.

Constructor & Destructor Documentation

◆ ~Oscillator()

template<typename SIGNAL >
virtual klang::Generic::Oscillator< SIGNAL >::~Oscillator ( )
inlinevirtual

Reimplemented in klang::Stereo::Oscillator.

Definition at line 1956 of file klang.h.

1956{ }

Member Function Documentation

◆ operator const SIGNAL &() [1/2]

template<typename SIGNAL >
klang::Generic::Generator< SIGNAL >::operator const SIGNAL & ( ) const
inlineoverridevirtualinherited

Reimplemented from klang::Generic::Output< SIGNAL >.

Definition at line 1416 of file klang.h.

1416{ return out; } // return last output

◆ operator const SIGNAL &() [2/2]

template<typename SIGNAL >
klang::Generic::Generator< SIGNAL >::operator const SIGNAL & ( )
inlineoverridevirtualinherited

Reimplemented from klang::Generic::Output< SIGNAL >.

Definition at line 1415 of file klang.h.

1415{ process(); return out; } // return processed output
virtual void process()=0

◆ operator()()

template<typename SIGNAL >
template<typename... params>
Output< SIGNAL > & klang::Generic::Generator< SIGNAL >::operator() ( params... p)
inlineinherited

Definition at line 1409 of file klang.h.

1409 {
1410 set(p...); return *this;
1411 }

◆ operator*()

template<typename SIGNAL >
template<typename TYPE >
SIGNAL klang::Generic::Output< SIGNAL >::operator* ( TYPE & other)
inlineinherited

Definition at line 1372 of file klang.h.

1372{ process(); return out * (other); }

◆ operator+()

template<typename SIGNAL >
template<typename TYPE >
SIGNAL klang::Generic::Output< SIGNAL >::operator+ ( TYPE & other)
inlineinherited

Definition at line 1371 of file klang.h.

1371{ process(); return out + (other); }

◆ operator-()

template<typename SIGNAL >
template<typename TYPE >
SIGNAL klang::Generic::Output< SIGNAL >::operator- ( TYPE & other)
inlineinherited

Definition at line 1373 of file klang.h.

1373{ process(); return out - (other); }

◆ operator/()

template<typename SIGNAL >
template<typename TYPE >
SIGNAL klang::Generic::Output< SIGNAL >::operator/ ( TYPE & other)
inlineinherited

Definition at line 1374 of file klang.h.

1374{ process(); return out / (other); }

◆ operator>>()

template<typename SIGNAL >
template<typename TYPE >
TYPE & klang::Generic::Output< SIGNAL >::operator>> ( TYPE & destination)
inlineinherited

Definition at line 1364 of file klang.h.

1364{ process(); return destination = out; }

References klang::Generic::Output< SIGNAL >::out, and klang::Generic::Output< SIGNAL >::process().

◆ output()

template<typename SIGNAL >
virtual const SIGNAL & klang::Generic::Output< SIGNAL >::output ( ) const
inlinevirtualinherited

Definition at line 1360 of file klang.h.

1360{ return out; }

References klang::Generic::Output< SIGNAL >::out.

◆ process()

◆ reset()

template<typename SIGNAL >
virtual void klang::Generic::Oscillator< SIGNAL >::reset ( )
inlinevirtual

Reimplemented in klang::Generators::Fast::Sine.

Definition at line 1957 of file klang.h.

1957{ position = 0; }

References klang::Generic::Oscillator< SIGNAL >::position.

◆ set() [1/4]

template<typename SIGNAL >
virtual void klang::Generic::Oscillator< SIGNAL >::set ( param frequency)
inlinevirtual

Reimplemented in klang::Generators::Fast::Sine, and klang::Wavetable.

Definition at line 1960 of file klang.h.

1960 {
1962 increment = frequency * 2.f * pi.f / fs;
1963 }
constexpr constant pi
The mathematical constant, pi (and it's inverse).
Definition klang.h:218
klang::dB fs
const float f
Constant as float.
Definition klang.h:95

References klang::constant::f, klang::Generic::Oscillator< SIGNAL >::frequency, klang::Generic::Oscillator< SIGNAL >::increment, klang::signal::operator*(), klang::signal::operator/(), and klang::pi.

◆ set() [2/4]

template<typename SIGNAL >
virtual void klang::Generic::Oscillator< SIGNAL >::set ( param frequency,
param phase )
inlinevirtual

Reimplemented in klang::Generators::Fast::Sine, and klang::Wavetable.

Definition at line 1965 of file klang.h.

1965 {
1966 position = phase;
1967 set(frequency);
1968 }
virtual void set(param frequency)
Definition klang.h:1960

References klang::Generic::Oscillator< SIGNAL >::position.

Referenced by klang::Generators::Basic::Pulse::set().

◆ set() [3/4]

template<typename SIGNAL >
virtual void klang::Generic::Oscillator< SIGNAL >::set ( param frequency,
relative phase )
inlinevirtual

Reimplemented in klang::Generators::Fast::Sine, and klang::Wavetable.

Definition at line 1970 of file klang.h.

1970 {
1971 set(frequency);
1972 set(phase);
1973 }

◆ set() [4/4]

template<typename SIGNAL >
virtual void klang::Generic::Oscillator< SIGNAL >::set ( relative phase)
inlinevirtual

Reimplemented in klang::Generators::Fast::Sine, and klang::Wavetable.

Definition at line 1975 of file klang.h.

1975 {
1976 offset = phase * (2 * pi);
1977 }

References klang::Generic::Oscillator< SIGNAL >::offset, klang::signal::operator*(), and klang::pi.

Member Data Documentation

◆ frequency

template<typename SIGNAL >
Frequency klang::Generic::Oscillator< SIGNAL >::frequency = 1000.f

Definition at line 1953 of file klang.h.

Referenced by klang::Generic::Oscillator< SIGNAL >::set().

◆ increment

template<typename SIGNAL >
Phase klang::Generic::Oscillator< SIGNAL >::increment
protected

Definition at line 1950 of file klang.h.

Referenced by klang::Generic::Oscillator< SIGNAL >::set().

◆ offset

template<typename SIGNAL >
Phase klang::Generic::Oscillator< SIGNAL >::offset = 0

Definition at line 1954 of file klang.h.

Referenced by klang::Generic::Oscillator< SIGNAL >::set().

◆ out

◆ position

template<typename SIGNAL >
Phase klang::Generic::Oscillator< SIGNAL >::position = 0
protected