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

Audio delay object. More...

#include <klang.h>

+ Inheritance diagram for klang::Delay< SIZE >:

Public Member Functions

 Delay ()
 
void clear ()
 
void input () override
 
signal tap (int delay) const
 
signal tap (float delay) const
 
virtual void process () override
 
virtual void set (param delay) override
 
template<typename TIME >
signal operator() (TIME &delay)
 
template<typename TIME >
signal operator() (const TIME &delay)
 
unsigned int max () const
 
 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

buffer buffer
 
float time = 1
 
int position = 0
 
signal in
 
signal out
 

Detailed Description

template<int SIZE>
struct klang::Delay< SIZE >

Definition at line 2480 of file klang.h.

Constructor & Destructor Documentation

◆ Delay()

template<int SIZE>
klang::Delay< SIZE >::Delay ( )
inline

Definition at line 2488 of file klang.h.

2488: buffer(SIZE + 1, 0) { clear(); }
void clear()
Definition klang.h:2490
buffer buffer
Definition klang.h:2484

Member Function Documentation

◆ clear()

template<int SIZE>
void klang::Delay< SIZE >::clear ( )
inline

Definition at line 2490 of file klang.h.

2490 {
2491 buffer.clear();
2492 }
void clear()
Definition klang.h:1241

◆ input() [1/3]

template<int SIZE>
void klang::Delay< SIZE >::input ( )
inlineoverridevirtual

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

Definition at line 2495 of file klang.h.

2495 {
2496 buffer++ = in;
2497 position++;
2498 if (buffer.finished()) {
2499 buffer.rewind();
2500 position = 0;
2501 }
2502 }
bool finished() const
Definition klang.h:1294
void rewind(int offset=0)
Definition klang.h:1233
int position
Definition klang.h:2486

◆ 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

◆ max()

template<int SIZE>
unsigned int klang::Delay< SIZE >::max ( ) const
inline

Definition at line 2553 of file klang.h.

2553{ return SIZE; }

◆ 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()() [1/3]

template<int SIZE>
template<typename TIME >
signal klang::Delay< SIZE >::operator() ( const TIME & delay)
inline

Definition at line 2544 of file klang.h.

2544 {
2545 if constexpr (std::is_integral_v<TIME>)
2546 return tap((int)delay);
2547 else if constexpr (std::is_floating_point_v<TIME>)
2548 return tap((float)delay);
2549 else
2550 return tap((signal)delay);
2551 }
signal tap(int delay) const
Definition klang.h:2504

◆ operator()() [2/3]

template<int SIZE>
template<typename TIME >
signal klang::Delay< SIZE >::operator() ( TIME & delay)
inline

Definition at line 2534 of file klang.h.

2534 {
2535 if constexpr (std::is_integral_v<TIME>)
2536 return tap((int)delay);
2537 else if constexpr (std::is_floating_point_v<TIME>)
2538 return tap((float)delay);
2539 else
2540 return tap((signal)delay);
2541 }

◆ operator()() [3/3]

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

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 SIZE>
virtual void klang::Delay< SIZE >::process ( )
inlineoverridevirtual

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

Definition at line 2525 of file klang.h.

2525 {
2526 out = tap(time);
2527 }
float time
Definition klang.h:2485

◆ set()

template<int SIZE>
virtual void klang::Delay< SIZE >::set ( param delay)
inlineoverridevirtual

Definition at line 2529 of file klang.h.

2529 {
2530 Delay::time = delay <= SIZE ? (float)delay : SIZE;
2531 }

◆ tap() [1/2]

template<int SIZE>
signal klang::Delay< SIZE >::tap ( float delay) const
inline

Definition at line 2511 of file klang.h.

2511 {
2512 float read = (float)(position - 1) - delay;
2513 if (read < 0.f)
2514 read += SIZE;
2515
2516 const float f = floor(read);
2517 delay = read - f;
2518
2519 const int i = (int)read;
2520 const int j = (i == (SIZE - 1)) ? 0 : (i + 1);
2521
2522 return buffer[i] * (1.f - delay) + buffer[j] * delay;
2523 }

◆ tap() [2/2]

template<int SIZE>
signal klang::Delay< SIZE >::tap ( int delay) const
inline

Definition at line 2504 of file klang.h.

2504 {
2505 int read = (position - 1) - delay;
2506 if (read < 0)
2507 read += SIZE;
2508 return buffer[read];
2509 }

Member Data Documentation

◆ buffer

template<int SIZE>
buffer klang::Delay< SIZE >::buffer

Definition at line 2484 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 };

◆ position

template<int SIZE>
int klang::Delay< SIZE >::position = 0

Definition at line 2486 of file klang.h.

◆ time

template<int SIZE>
float klang::Delay< SIZE >::time = 1

Definition at line 2485 of file klang.h.