Klang C++
Language Reference (draft)
Loading...
Searching...
No Matches
klang::Envelope::Follower::Window< WINDOW >

Window-based envelope follower. More...

#include <klang.h>

+ Inheritance diagram for klang::Envelope::Follower::Window< WINDOW >:

Public Types

using Process = void(Window::*)()
 

Public Member Functions

 Window ()
 
void set (param attack, param release)
 
Windowoperator= (klang::Mode mode)
 
void process ()
 
void mean ()
 
void rms ()
 
 operator const signal & () override
 
 operator const signal & () const override
 
Modifier< signal > & operator() (params... p)
 
virtual const signalinput () const
 
virtual void input (const signal &source)
 
virtual void operator<< (const signal &source)
 
virtual const signaloutput () const
 
TYPE & operator>> (TYPE &destination)
 
signal operator+ (TYPE &other)
 
signal operator* (TYPE &other)
 
signal operator- (TYPE &other)
 
signal operator/ (TYPE &other)
 

Public Attributes

AR ar
 
buffer buffer
 
double sum = 0
 
Process _process = &Window::rms
 
signal in
 
signal out
 

Static Public Attributes

static constexpr constant window = { WINDOW }
 

Detailed Description

template<int WINDOW>
struct klang::Envelope::Follower::Window< WINDOW >

Definition at line 4427 of file klang.h.

Member Typedef Documentation

◆ Process

template<int WINDOW>
using klang::Envelope::Follower::Window< WINDOW >::Process = void(Window::*)()

Definition at line 4447 of file klang.h.

Constructor & Destructor Documentation

◆ Window()

template<int WINDOW>
klang::Envelope::Follower::Window< WINDOW >::Window ( )
inline

Definition at line 4434 of file klang.h.

4434 : buffer(WINDOW, 0) {
4435 set(0.01f, 0.1f);
4436 }
void set(param attack, param release)
Definition klang.h:4438

Member Function Documentation

◆ input() [1/3]

virtual void klang::Generic::Input< signal >::input ( )
inlineprotectedvirtualinherited

◆ input() [2/3]

virtual const signal & klang::Generic::Input< signal >::input ( ) const
inlinevirtualinherited

Reimplemented in klang::Generic::Graph< SIZE >::Series.

Definition at line 1343 of file klang.h.

1343{ return in; }

◆ input() [3/3]

virtual void klang::Generic::Input< signal >::input ( const signal & source)
inlinevirtualinherited

Definition at line 1347 of file klang.h.

1347{ in = source; input(); }
virtual const signal & input() const
Definition klang.h:1343

◆ mean()

template<int WINDOW>
void klang::Envelope::Follower::Window< WINDOW >::mean ( )
inline

Definition at line 4452 of file klang.h.

4452 {
4453 sum -= double(buffer);
4454 abs(in) >> buffer;
4455 sum += double(buffer++);
4456 if (buffer.finished())
4457 buffer.rewind();
4458 sum * window.inv >> ar >> out;
4459 }
bool finished() const
Definition klang.h:1294
void rewind(int offset=0)
Definition klang.h:1233
static constexpr constant window
Definition klang.h:4432
const float inv
Inverse of constant.
Definition klang.h:97

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

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

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

Definition at line 1450 of file klang.h.

1450{ return out; } // return last output

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

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

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

Definition at line 1449 of file klang.h.

1449{ process(); return out; } // return processed output
virtual void process() override
Definition klang.h:1453

◆ operator()()

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

Definition at line 1457 of file klang.h.

1457 {
1458 set(p...); return *this;
1459 }

◆ operator*()

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

Definition at line 1372 of file klang.h.

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

◆ operator+()

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

Definition at line 1371 of file klang.h.

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

◆ operator-()

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

Definition at line 1373 of file klang.h.

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

◆ operator/()

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

Definition at line 1374 of file klang.h.

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

◆ operator<<()

virtual void klang::Generic::Input< signal >::operator<< ( const signal & source)
inlinevirtualinherited

Definition at line 1346 of file klang.h.

1346{ in = source; input(); }

◆ operator=()

template<int WINDOW>
Window & klang::Envelope::Follower::Window< WINDOW >::operator= ( klang::Mode mode)
inline

Definition at line 4442 of file klang.h.

4442 {
4443 _process = (mode == RMS) ? &Window::rms : &Window::mean;
4444 return *this;
4445 }
Mode mode() const
Definition klang.h:2955
@ RMS
Definition klang.h:83

◆ operator>>()

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

Definition at line 1364 of file klang.h.

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

◆ output()

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

Definition at line 1360 of file klang.h.

1360{ return out; }

◆ process()

template<int WINDOW>
void klang::Envelope::Follower::Window< WINDOW >::process ( )
inlinevirtual

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

Definition at line 4450 of file klang.h.

4450{ (this->*_process)(); }

◆ rms()

template<int WINDOW>
void klang::Envelope::Follower::Window< WINDOW >::rms ( )
inline

Definition at line 4460 of file klang.h.

4460 {
4461 sum -= double(buffer);
4462 (in * in) >> buffer;
4463 sum += double(buffer++);
4464 if (buffer.finished())
4465 buffer.rewind();
4466 sum* window.inv >> sqrt >> ar >> out;
4467 }

◆ set()

template<int WINDOW>
void klang::Envelope::Follower::Window< WINDOW >::set ( param attack,
param release )
inline

Definition at line 4438 of file klang.h.

4438 {
4439 ar.set(attack, release);
4440 }
virtual void release(float time, float level=0.f)
Definition klang.h:2847
void set(param attack, param release)
Definition klang.h:4391

Member Data Documentation

◆ _process

template<int WINDOW>
Process klang::Envelope::Follower::Window< WINDOW >::_process = &Window::rms

Definition at line 4448 of file klang.h.

◆ ar

template<int WINDOW>
AR klang::Envelope::Follower::Window< WINDOW >::ar

Definition at line 4429 of file klang.h.

◆ buffer

template<int WINDOW>
buffer klang::Envelope::Follower::Window< WINDOW >::buffer

Definition at line 4430 of file klang.h.

◆ in

Definition at line 1340 of file klang.h.

1340{ 0.f };

◆ out

Definition at line 1357 of file klang.h.

1357{ 0.f };

◆ sum

template<int WINDOW>
double klang::Envelope::Follower::Window< WINDOW >::sum = 0

Definition at line 4431 of file klang.h.

◆ window

template<int WINDOW>
constant klang::Envelope::Follower::Window< WINDOW >::window = { WINDOW }
staticconstexpr

Definition at line 4432 of file klang.h.

4432{ WINDOW };