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

Language Guide / Signal Generators

Generator

klang::Generator

Base class for mono signal sources.

A generator has an output and no audio input. Derive from Generator when the source does not need the frequency and phase handling of Oscillator. Implement process() to produce one sample in out.

Read or route a sample

Assign the generator to a signal to run it once, or route it directly with generator >> out. Store the sample if it needs to go to more than one destination. Calling output() reads the last sample without running the generator again.

Example ยท Emit a trigger

Call trigger() when an event should emit an impulse. The next read returns 1 and clears the trigger. Subsequent reads return 0 until the next event.

struct Trigger : Generator {
    bool pending = false;

    void trigger() { pending = true; }

    void process() {
        out = pending ? 1 : 0;
        pending = false;
    }
};

Signal generator object (mono) More...

#include <klang.h>

+ Inheritance diagram for klang::Generator:

Public Member Functions

Output< signal > & operator() (params &&... p)
 
 operator const signal & () override
 
 operator const signal & () const override
 
virtual const signal & output () const
 
TYPE & operator>> (TYPE &destination)
 
signal operator+ (TYPE &other)
 
signal operator* (TYPE &other)
 
signal operator- (TYPE &other)
 
signal operator/ (TYPE &other)
 
void reset ()
 

Public Attributes

signal out
 

Detailed Description

Definition at line 3680 of file klang.h.

Member Function Documentation

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

klang::Generic::Generator< signal >::operator const signal & ( ) const
inlineoverridevirtualinherited

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

Definition at line 3057 of file klang.h.

3057{ return out; } // return last output

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

klang::Generic::Generator< signal >::operator const signal & ( )
inlineoverridevirtualinherited

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

Definition at line 3056 of file klang.h.

3056{ this->process(); return out; } // return processed output

◆ operator()()

Output< signal > & klang::Generic::Generator< signal >::operator() ( params &&... p)
inlineinherited

Definition at line 3050 of file klang.h.

3050 {
3051 set(std::forward<params>(p)...); return *this;
3052 }

◆ operator*()

signal klang::Generic::Output< signal >::operator* ( TYPE & other)
inlineinherited

Definition at line 2977 of file klang.h.

2977{ this->process(); return out * SIGNAL(other); }

◆ operator+()

signal klang::Generic::Output< signal >::operator+ ( TYPE & other)
inlineinherited

Definition at line 2976 of file klang.h.

2976{ this->process(); return out + SIGNAL(other); }

◆ operator-()

signal klang::Generic::Output< signal >::operator- ( TYPE & other)
inlineinherited

Definition at line 2978 of file klang.h.

2978{ this->process(); return out - SIGNAL(other); }

◆ operator/()

signal klang::Generic::Output< signal >::operator/ ( TYPE & other)
inlineinherited

Definition at line 2979 of file klang.h.

2979{ this->process(); return out / SIGNAL(other); }

◆ operator>>()

TYPE & klang::Generic::Output< signal >::operator>> ( TYPE & destination)
inlineinherited

Definition at line 2969 of file klang.h.

2969{ this->process(); return destination = out; }

◆ output()

virtual const signal & klang::Generic::Output< signal >::output ( ) const
inlinevirtualinherited

Definition at line 2964 of file klang.h.

2964{ return out; }

◆ process()

◆ reset()

void klang::Generic::Output< signal >::reset ( )
inlineinherited

Definition at line 2981 of file klang.h.

2981{ out = 0; }

Member Data Documentation

◆ out

Definition at line 2961 of file klang.h.

2961{ 0.f };