Debian Codegraph @

lib-src/libnyquist/nyquist/nyqstk/src/Chorus.cpp

raw
1 /***************************************************/
2 /*! \class Chorus
3 \brief STK chorus effect class.
4
5 This class implements a chorus effect.
6
7 by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
8 */
9 /***************************************************/
10
11 #include "Chorus.h"
12 #include <iostream>
13
14 using namespace Nyq;
15
16 Chorus :: Chorus(StkFloat baseDelay)
17 {
18 delayLine_[0].setMaximumDelay( (unsigned long) (baseDelay * 1.414) + 2);
19 delayLine_[0].setDelay( baseDelay );
20 delayLine_[1].setMaximumDelay( (unsigned long) (baseDelay * 1.414) + 2);
21 delayLine_[1].setDelay( baseDelay );
22 baseLength_ = baseDelay;
23
24 mods_[0].setFrequency(0.2);
25 mods_[1].setFrequency(0.222222);
26 modDepth_ = 0.05;
27 effectMix_ = 0.5;
28 this->clear();
29 }
30
31 Chorus :: ~Chorus()
32 {
33 }
34
35 void Chorus :: clear()
36 {
37 delayLine_[0].clear();
38 delayLine_[1].clear();
39 lastOutput_[0] = 0.0;
40 lastOutput_[1] = 0.0;
41 }
42
43 void Chorus :: setModDepth(StkFloat depth)
44 {
45 modDepth_ = depth;
46 }
47
48 void Chorus :: setModFrequency(StkFloat frequency)
49 {
50 mods_[0].setFrequency(frequency);
51 mods_[1].setFrequency(frequency * 1.1111);
52 }
53
54 StkFloat Chorus :: computeSample(StkFloat input)
55 {
56 delayLine_[0].setDelay( baseLength_ * 0.707 * (1.0 + modDepth_ * mods_[0].tick()) );
57 delayLine_[1].setDelay( baseLength_ * 0.5 * (1.0 - modDepth_ * mods_[1].tick()) );
58 lastOutput_[0] = input * (1.0 - effectMix_);
59 lastOutput_[0] += effectMix_ * delayLine_[0].tick(input);
60 lastOutput_[1] = input * (1.0 - effectMix_);
61 lastOutput_[1] += effectMix_ * delayLine_[1].tick(input);
62 return Effect::lastOut();
63 }