Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Echo.h
1#ifndef STK_ECHO_H
2#define STK_ECHO_H
3
4#include "Effect.h"
5#include "Delay.h"
6
7 namespace stk {
8
9/***************************************************/
17/***************************************************/
18
19 class Echo : public Effect
20{
21 public:
23
26 Echo( unsigned long maximumDelay = (unsigned long) Stk::sampleRate() );
27
29 void clear();
30
32 void setMaximumDelay( unsigned long delay );
33
35 void setDelay( unsigned long delay );
36
38 StkFloat lastOut( void ) const { return lastFrame_[0]; };
39
41 StkFloat tick( StkFloat input );
42
44
52 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
53
55
63 StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
64
65 protected:
66
67 Delay delayLine_;
68 unsigned long length_;
69
70};
71
72 inline StkFloat Echo :: tick( StkFloat input )
73{
74 lastFrame_[0] = effectMix_ * ( delayLine_.tick( input ) - input ) + input;
75 return lastFrame_[0];
76}
77
78 inline StkFrames& Echo :: tick( StkFrames& frames, unsigned int channel )
79{
80#if defined(_STK_DEBUG_)
81 if ( channel >= frames.channels() ) {
82 oStream_ << "Echo::tick(): channel and StkFrames arguments are incompatible!";
83 handleError( StkError::FUNCTION_ARGUMENT );
84 }
85#endif
86
87 StkFloat *samples = &frames[channel];
88 unsigned int hop = frames.channels();
89 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
90 *samples = effectMix_ * ( delayLine_.tick( *samples ) - *samples ) + *samples;
91 }
92
93 lastFrame_[0] = *(samples-hop);
94 return frames;
95}
96
97 inline StkFrames& Echo :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
98{
99#if defined(_STK_DEBUG_)
100 if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
101 oStream_ << "Echo::tick(): channel and StkFrames arguments are incompatible!";
102 handleError( StkError::FUNCTION_ARGUMENT );
103 }
104#endif
105
106 StkFloat *iSamples = &iFrames[iChannel];
107 StkFloat *oSamples = &oFrames[oChannel];
108 unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
109 for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
110 *oSamples = effectMix_ * ( delayLine_.tick( *iSamples ) - *iSamples ) + *iSamples;
111 }
112
113 lastFrame_[0] = *(oSamples-oHop);
114 return iFrames;
115}
116
117} // stk namespace
118
119#endif
120
stk::Delay
STK non-interpolating delay line class.
Definition Delay.h:25
stk::Echo
STK echo effect class.
Definition Echo.h:20
stk::Echo::clear
void clear()
Reset and clear all internal state.
stk::Echo::lastOut
StkFloat lastOut(void) const
Return the last computed output value.
Definition Echo.h:38
stk::Echo::setMaximumDelay
void setMaximumDelay(unsigned long delay)
Set the maximum delay line length in samples.
stk::Echo::tick
StkFloat tick(StkFloat input)
Input one sample to the effect and return one output.
Definition Echo.h:72
stk::Echo::Echo
Echo(unsigned long maximumDelay=(unsigned long) Stk::sampleRate())
Class constructor, taking the longest desired delay length (one second default value).
stk::Echo::setDelay
void setDelay(unsigned long delay)
Set the delay line length in samples.
stk::Effect
STK abstract effects parent class.
Definition Effect.h:22
stk::StkFrames
An STK class to handle vectorized audio data.
Definition Stk.h:279
stk::StkFrames::channels
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition Stk.h:416
stk::StkFrames::frames
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition Stk.h:419
stk::Stk::sampleRate
static StkFloat sampleRate(void)
Static method that returns the current STK sample rate.
Definition Stk.h:148
stk
The STK namespace.
Definition ADSR.h:6

The Synthesis ToolKit in C++ (STK)
©1995--2023 Perry R. Cook and Gary P. Scavone. All Rights Reserved.