-
Notifications
You must be signed in to change notification settings - Fork 0
/
chorus.cmajor
126 lines (99 loc) · 2.84 KB
/
chorus.cmajor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
graph Chorus [[ main ]]
{
input value bool bypass [[ name: "Bypass", boolean ]];
input stream float in;
output stream float<2> out;
input value float rate [[ name: "Rate", min: 0.01, max: 20.0, init: 0.5]];
input value float depth [[ name: "Depth", min: 0.0, max: 20.0, init: 0.5]];
input value float shape [[ name: "Shape", min: 0.0, max: 1.0, init: 0.0 ]];
node mix = std::mixers::Interpolator(float<2>, 100.0f);
node monoToStereo = std::mixers::MonoToStereo(float);
node chorus1 = ChorusProcessor (0.0f, -1.0f);
node chorus2 = ChorusProcessor (0.5f, 1.0f);
connection
{
rate -> chorus1.rate, chorus2.rate;
depth -> chorus1.depth, chorus2.depth;
shape -> chorus1.shape, chorus2.shape;
in -> monoToStereo.in;
monoToStereo.out -> mix.in1;
in -> chorus1.in, chorus2.in;
chorus1.out, chorus2.out -> mix.in2;
bypass ? 0.0f : 100.0f -> mix.mix;
mix.out -> out;
}
}
processor Oscillator (float initialPhase)
{
input stream float rate;
input stream float depth;
input stream float shape;
output stream float out;
void main()
{
float phase = initialPhase;
loop
{
let value = (shape < 0.5f) ? std::oscillators::waveshape::sine(phase * 2.0f) : 2.0f * (std::oscillators::waveshape::triangle(phase) - 0.5f);
out <- depth * 0.01f * value;
phase = fmod (phase + rate * float (processor.period), 1.0f);
advance();
}
}
}
processor StereoPan (float pan)
{
input stream float in;
output stream float<2> out;
void main()
{
let gains = std::pan_law::linear(pan);
loop
{
out <- gains * float<2>(in, in);
advance();
}
}
}
processor Delay
{
input stream float in, modIn;
output stream float out;
const float delayTime = 1.0;
float[48] buf;
void main()
{
let samplesPerMs = float (processor.frequency / 1000.0);
wrap<buf.size> writePos;
loop
{
let delayMs = delayTime * samplesPerMs * (1.0f + modIn) + 1.0f;
let delayedVal = readLinearInterpolated(buf, float(writePos) - delayMs);
buf[writePos] = in;
out <- delayedVal;
writePos++;
advance();
}
}
}
graph ChorusProcessor (float initialPhase, float pan)
{
input value float rate;
input value float depth;
input value float shape;
input stream float in;
output stream float<2> out;
node osc = Oscillator(initialPhase);
node panner = StereoPan(pan);
node delay = Delay;
connection
{
rate -> osc.rate;
depth -> osc.depth;
shape -> osc.shape;
in -> delay.in;
osc.out -> delay.modIn;
delay.out -> panner.in;
panner.out -> out;
}
}