-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathElectricSnare.cmajor
More file actions
84 lines (70 loc) · 3.02 KB
/
Copy pathElectricSnare.cmajor
File metadata and controls
84 lines (70 loc) · 3.02 KB
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
// Reference videos:
// https://www.youtube.com/watch?v=Fks15MXxwas
// https://www.youtube.com/watch?v=NifOAvu7KQk
namespace Percupuff
{
namespace Drums
{
// This processor tries to create a electric snare drum sound.
// An oscillator with a triangle waveform is used to create the initial impact of the snare,
// with filtered white noise mixed in for more brightness.
processor ElectricSnare {
input event (std::notes::NoteOn) eventIn;
output stream float<2> out;
input stream float noiseIn;
input event Params paramsIn;
float triggerVelocity = 0.0f;
int midiNotePitch = 0;
float outputLevel = 0.5f;
float panning = 0.0f;
float velocitySensitivity = 1.0f;
event paramsIn(Params p) {
midiNotePitch = int(p.snare2Midi);
outputLevel = p.snare2Level * 0.01f;
panning = p.snare2Panning;
velocitySensitivity = p.snare2Velocity;
}
event eventIn(std::notes::NoteOn n) {
if (int (n.pitch) == midiNotePitch) {
triggerVelocity = sqrt(n.velocity);
}
}
node envelope = Envelope;
node osc1 = Oscillator(OscillatorShape::triangle);
// Filters that shape the white noise.
// Use LpfResonant to add resonance for brightness
LpfResonant lowpass = (0.0f, 0.0f);
void main()
{
osc1.frequencyIn <- 160.0f;
let invSampleRate = 1.0f / float(processor.frequency);
loop
{
while (triggerVelocity == 0) {
advance();
}
let vel = triggerVelocity;
triggerVelocity = 0.0f;
envelope.attackIn <- 0.001f;
envelope.releaseIn <- .2f + vel * 0.1f;
envelope.triggerIn <- void;
envelope.advance();
float gain = envelope.gainOut;
while (gain > 0.0f && triggerVelocity == 0.0f) {
osc1.frequencyModIn <- gain * 0.03f;
float lpSample = lowpass.getSample(noiseIn, 15000.0f, 0.7f, invSampleRate);
let outSample = (sin(osc1.out * (1.0f + vel * 0.5f)) + lpSample * 0.6f) * gain * 0.5f * vel * outputLevel;
float pan = panning * 0.01f;
float leftGain = 0.5f * (1.0f - pan);
float rightGain = 0.5f * (1.0f + pan);
out <- (outSample * leftGain, outSample * rightGain);
osc1.advance();
gain = envelope.gainOut;
envelope.advance();
advance();
}
}
}
}
}
}