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

Audio delay object (stereo) More...

#include <klang.h>

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

Public Member Functions

void clear ()
 
 Delay ()
 
signal tap (int delay) const
 
signal tap (float delay) const
 
virtual void process () override
 
template<typename TIME >
signal operator() (const TIME &delay)
 
unsigned int max () const
 
klang::Delay< SIZE > & operator[] (int index)
 
const klang::Delay< SIZE > & operator[] (int index) const
 
void set (Args... args)
 
void input () override
 

Public Attributes

klang::Delay< SIZE > & l
 
klang::Delay< SIZE > & r
 
klang::Delay< SIZE > items [COUNT]
 

Detailed Description

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

Definition at line 3472 of file klang.h.

Constructor & Destructor Documentation

◆ Delay()

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

Definition at line 3482 of file klang.h.

3483: l(items[0]), r(items[1]) { }
klang::Delay< SIZE > items[COUNT]
Definition klang.h:2004
klang::Delay< SIZE > & r
Definition klang.h:3482
klang::Delay< SIZE > & l
Definition klang.h:3482

Member Function Documentation

◆ clear()

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

Definition at line 3477 of file klang.h.

3477 {
3478 items[0].clear();
3479 items[1].clear();
3480 }

◆ input()

void klang::Bank< klang::Delay< SIZE >, COUNT >::input ( )
inlineoverrideinherited

Definition at line 2015 of file klang.h.

2015 {
2016 for (int n = 0; n < COUNT; n++)
2017 in[n] >> items[n];
2018 }

◆ max()

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

Definition at line 3523 of file klang.h.

3523{ return SIZE; }

◆ operator()()

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

Definition at line 3512 of file klang.h.

3512 {
3513 if constexpr (std::is_integral_v<TIME>)
3514 return tap((int)delay);
3515 else if constexpr (std::is_floating_point_v<TIME>)
3516 return tap((float)delay);
3517 else if constexpr (std::is_same_v<TIME, signal>) // stereo signal (use for l/r delay times)
3518 return { items[0].tap(delay.l), items[1].tap(delay.r) };
3519 else
3520 return tap((klang::signal)delay); // else treat as single signal
3521 }
signal tap(int delay) const
Definition klang.h:3485
A mono audio signal (equivalent to a float).
Definition klang.h:362

◆ operator[]() [1/2]

klang::Delay< SIZE > & klang::Bank< klang::Delay< SIZE >, COUNT >::operator[] ( int index)
inlineinherited

Definition at line 2006 of file klang.h.

2006{ return items[index]; }

◆ operator[]() [2/2]

const klang::Delay< SIZE > & klang::Bank< klang::Delay< SIZE >, COUNT >::operator[] ( int index) const
inlineinherited

Definition at line 2007 of file klang.h.

2007{ return items[index]; }

◆ process()

template<int SIZE>
virtual void klang::Stereo::Delay< SIZE >::process ( )
inlineoverridevirtual

Definition at line 3507 of file klang.h.

3507 {
3508 out = tap(items[0].time);
3509 }

◆ set()

void klang::Bank< klang::Delay< SIZE >, COUNT >::set ( Args... args)
inlineinherited

Definition at line 2010 of file klang.h.

2010 {
2011 for (int n = 0; n < COUNT; n++)
2012 items[n].set(args...);
2013 }

◆ tap() [1/2]

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

Definition at line 3492 of file klang.h.

3492 {
3493 float read = (float)(items[0].position - 1) - delay;
3494 if (read < 0.f)
3495 read += SIZE;
3496
3497 const float f = floor(read);
3498 delay = read - f;
3499
3500 const int i = (int)read;
3501 const int j = (i == (SIZE - 1)) ? 0 : (i + 1);
3502
3503 return { items[0].buffer[i] * (1.f - delay) + items[0].buffer[j] * delay,
3504 items[1].buffer[i] * (1.f - delay) + items[1].buffer[j] * delay };
3505 }

◆ tap() [2/2]

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

Definition at line 3485 of file klang.h.

3485 {
3486 int read = (items[0].position - 1) - delay;
3487 if (read < 0)
3488 read += SIZE;
3489 return { items[0].buffer[read], items[1].buffer[read] };
3490 }

Member Data Documentation

◆ items

klang::Delay< SIZE > klang::Bank< klang::Delay< SIZE >, COUNT >::items[COUNT]
inherited

Definition at line 2004 of file klang.h.

◆ l

template<int SIZE>
klang::Delay<SIZE>& klang::Stereo::Delay< SIZE >::l

Definition at line 3482 of file klang.h.

◆ r

template<int SIZE>
klang::Delay<SIZE> & klang::Stereo::Delay< SIZE >::r

Definition at line 3482 of file klang.h.