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

Language Guide / Samples and Wavetables

Wavetable

klang::Wavetable

An oscillator that plays a repeating table.

Fill the table with one cycle, or construct it from an oscillator to sample a cycle into the table. Set the playback frequency in Hz after building the table. The table holds the waveform at a fixed resolution, so its harmonic content matters when playing it back at higher pitches.

Example ยท Capture a sine cycle

Sine sine;
Wavetable table(sine, 2048);

Wavetable-based oscillator. More...

#include <klang.h>

+ Inheritance diagram for klang::Wavetable:

Public Member Functions

 Wavetable (int size=2048)
 
template<typename TYPE >
 Wavetable (TYPE oscillator, int size=2048)
 
signal & operator[] (int index)
 
template<typename TYPE >
Wavetable & operator= (TYPE &oscillator)
 
virtual void set (param frequency) override
 
virtual void set (param frequency, param phase) override
 
virtual void set (relative phase) override
 
virtual void set (param frequency, relative phase) override
 
void process () override
 
virtual void reset ()
 
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)
 

Public Attributes

Frequency frequency
 
Phase offset
 
signal out
 

Protected Attributes

buffer buffer
 
const int size
 
Phase increment
 
Phase position
 

Detailed Description

Definition at line 4844 of file klang.h.

Constructor & Destructor Documentation

◆ Wavetable() [1/2]

klang::Wavetable::Wavetable ( int size = 2048)
inline

Definition at line 4850 of file klang.h.

4850: buffer(size), size(size) {}
const int size
Definition klang.h:4848
buffer buffer
Definition klang.h:4847

◆ Wavetable() [2/2]

template<typename TYPE >
klang::Wavetable::Wavetable ( TYPE oscillator,
int size = 2048 )
inline

Definition at line 4853 of file klang.h.

4853 : buffer(size), size(size) {
4854 operator=(oscillator);
4855 }
Wavetable & operator=(TYPE &oscillator)
Definition klang.h:4862

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=()

template<typename TYPE >
Wavetable & klang::Wavetable::operator= ( TYPE & oscillator)
inline

Definition at line 4862 of file klang.h.

4862 {
4863 oscillator.set(fs / size);
4864 for (int s = 0; s < size; s++)
4865 buffer[s] = oscillator;
4866 return *this;
4867 }
klang::dB fs

◆ operator>>()

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

Definition at line 2969 of file klang.h.

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

◆ operator[]()

signal & klang::Wavetable::operator[] ( int index)
inline

Definition at line 4857 of file klang.h.

4857 {
4858 return buffer[index];
4859 }

◆ output()

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

Definition at line 2964 of file klang.h.

2964{ return out; }

◆ process()

void klang::Wavetable::process ( )
inlineoverridevirtual

Implements klang::Generic::Output< signal >.

Definition at line 4889 of file klang.h.

4889 {
4890 position += { increment, size };
4891 out = buffer[position + offset /*klang::increment(offset, size)*/];
4892 }

◆ reset()

virtual void klang::Generic::Oscillator< signal >::reset ( )
inlinevirtualinherited

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

Definition at line 3651 of file klang.h.

3651{ position = 0; }

◆ set() [1/4]

virtual void klang::Wavetable::set ( param frequency)
inlineoverridevirtual

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

Definition at line 4869 of file klang.h.

◆ set() [2/4]

virtual void klang::Wavetable::set ( param frequency,
param phase )
inlineoverridevirtual

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

Definition at line 4874 of file klang.h.

4874 {
4875 position = phase * float(size);
4876 set(frequency);
4877 }
virtual void set(param frequency) override
Definition klang.h:4869

◆ set() [3/4]

virtual void klang::Wavetable::set ( param frequency,
relative phase )
inlineoverridevirtual

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

Definition at line 4884 of file klang.h.

4884 {
4885 set(frequency);
4886 set(phase);
4887 }

◆ set() [4/4]

virtual void klang::Wavetable::set ( relative phase)
inlineoverridevirtual

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

Definition at line 4879 of file klang.h.

4879 {
4880
4881 offset = phase * float(size);
4882 }

Member Data Documentation

◆ buffer

buffer klang::Wavetable::buffer
protected

Definition at line 4847 of file klang.h.

◆ frequency

Frequency klang::Generic::Oscillator< signal >::frequency
inherited

Definition at line 3647 of file klang.h.

◆ increment

Phase klang::Generic::Oscillator< signal >::increment
protectedinherited

Definition at line 3644 of file klang.h.

◆ offset

Phase klang::Generic::Oscillator< signal >::offset
inherited

Definition at line 3648 of file klang.h.

◆ out

Definition at line 2961 of file klang.h.

2961{ 0.f };

◆ position

Phase klang::Generic::Oscillator< signal >::position
protectedinherited

Definition at line 3645 of file klang.h.

◆ size

const int klang::Wavetable::size
protected

Definition at line 4848 of file klang.h.