Skip to content

Commit 56eda81

Browse files
authored
Implement dsp cmajor code for ride bell (#79)
* Add ride bell parameters and instrument definition * Add Ride Bell instrument and integrate into synthesizer * Format the code * Update Ride Bell parameters and add instrument to the UI
1 parent 0a35e7c commit 56eda81

File tree

5 files changed

+142
-0
lines changed

5 files changed

+142
-0
lines changed

dsp/Params.cmajor

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ namespace Percupuff
8282
float cowbellPanning;
8383
float cowbellVelocity;
8484
float cowbellMidi;
85+
float rideBellLevel;
86+
float rideBellPanning;
87+
float rideBellVelocity;
88+
float rideBellMidi;
8589
float sideStickLevel;
8690
float sideStickPanning;
8791
float sideStickVelocity;
@@ -165,6 +169,10 @@ namespace Percupuff
165169
p.cowbellPanning = 0.0f;
166170
p.cowbellVelocity = 100.0f;
167171
p.cowbellMidi = 56.0f;
172+
p.rideBellLevel = 50.0f;
173+
p.rideBellPanning = 0.0f;
174+
p.rideBellVelocity = 100.0f;
175+
p.rideBellMidi = 53.0f;
168176
p.sideStickLevel = 50.0f;
169177
p.sideStickPanning = 0.0f;
170178
p.sideStickVelocity = 100.0f;
@@ -248,6 +256,10 @@ namespace Percupuff
248256
input event float cowbellPanning [[ name: "cowbellPanning", min: -100, max: 100, init: 0, step: 5 ]];
249257
input event float cowbellVelocity [[ name: "cowbellVelocity", min: 0, max: 100, init: 100, step: 1 ]];
250258
input event float cowbellMidi [[ name: "cowbellMidi", min: 0, max: 127, init: 56, step: 1 ]];
259+
input event float rideBellLevel [[ name: "rideBellLevel", min: 0, max: 100, init: 50, step: 1 ]];
260+
input event float rideBellPanning [[ name: "rideBellPanning", min: -100, max: 100, init: 0, step: 5 ]];
261+
input event float rideBellVelocity [[ name: "rideBellVelocity", min: 0, max: 100, init: 100, step: 1 ]];
262+
input event float rideBellMidi [[ name: "rideBellMidi", min: 0, max: 127, init: 53, step: 1 ]];
251263
input event float sideStickLevel [[ name: "sideStickLevel", min: 0, max: 100, init: 50, step: 1 ]];
252264
input event float sideStickPanning [[ name: "sideStickPanning", min: -100, max: 100, init: 0, step: 5 ]];
253265
input event float sideStickVelocity [[ name: "sideStickVelocity", min: 0, max: 100, init: 100, step: 1 ]];
@@ -334,6 +346,10 @@ namespace Percupuff
334346
event cowbellPanning (float f) { params.cowbellPanning = f; update(); }
335347
event cowbellVelocity (float f) { params.cowbellVelocity = f; update(); }
336348
event cowbellMidi (float f) { params.cowbellMidi = f; update(); }
349+
event rideBellLevel (float f) { params.rideBellLevel = f; update(); }
350+
event rideBellPanning (float f) { params.rideBellPanning = f; update(); }
351+
event rideBellVelocity (float f) { params.rideBellVelocity = f; update(); }
352+
event rideBellMidi (float f) { params.rideBellMidi = f; update(); }
337353
event sideStickLevel (float f) { params.sideStickLevel = f; update(); }
338354
event sideStickPanning (float f) { params.sideStickPanning = f; update(); }
339355
event sideStickVelocity (float f) { params.sideStickVelocity = f; update(); }

dsp/Percupuff.cmajor

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ namespace Percupuff
3838
claves = Drums::Claves;
3939
bongos = Drums::Bongos;
4040
sideStick = Drums::SideStick;
41+
rideBell = Drums::RideBell;
4142
gainLimiter = std::levels::ConstantGain (float<2>, 1.0f);
4243
mpe = std::midi::MPEConverter;
4344
}
@@ -55,6 +56,7 @@ namespace Percupuff
5556
p.paramsOut -> snare.paramsIn;
5657
p.paramsOut -> electricSnare.paramsIn;
5758
p.paramsOut -> sideStick.paramsIn;
59+
p.paramsOut -> rideBell.paramsIn;
5860

5961
// Send the midi events so the sound processors know when to start playing.
6062
midiIn -> mpe;
@@ -68,6 +70,7 @@ namespace Percupuff
6870
mpe -> claves.eventIn;
6971
mpe -> bongos.eventIn;
7072
mpe -> sideStick.eventIn;
73+
mpe -> rideBell.eventIn;
7174
mpe -> noteOn;
7275

7376
// Some sounds use noise.
@@ -90,6 +93,7 @@ namespace Percupuff
9093
claves -> gainLimiter;
9194
bongos -> gainLimiter;
9295
sideStick -> gainLimiter;
96+
rideBell -> gainLimiter;
9397

9498
// Output the result.
9599
gainLimiter -> out;

dsp/drums/RideBell.cmajor

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
namespace Percupuff
2+
{
3+
namespace Drums
4+
{
5+
processor RideBell {
6+
input event (std::notes::NoteOn) eventIn;
7+
output stream float<2> out;
8+
input event Params paramsIn;
9+
10+
float triggerVelocity = 0.0f;
11+
int midiNotePitch = 0;
12+
float outputLevel = 0.5f;
13+
float panning = 0.0f;
14+
15+
// Velocity sensitivity is not implemented yet
16+
float velocitySensitivity = 1.0f;
17+
18+
event paramsIn(Params p) {
19+
midiNotePitch = int(p.rideBellMidi);
20+
outputLevel = p.rideBellLevel * 0.01f;
21+
panning = p.rideBellPanning;
22+
velocitySensitivity = p.rideBellVelocity;
23+
}
24+
25+
event eventIn(std::notes::NoteOn n) {
26+
if (int (n.pitch) == midiNotePitch) {
27+
triggerVelocity = sqrt(n.velocity);
28+
}
29+
}
30+
31+
node envelope = Envelope;
32+
node osc1 = Oscillator(OscillatorShape::sine);
33+
node osc2 = Oscillator(OscillatorShape::sine);
34+
node osc3 = Oscillator(OscillatorShape::sine);
35+
node osc4 = Oscillator(OscillatorShape::sine);
36+
37+
const float highPassCutoff = 1400.0f;
38+
node highpass = std::filters::butterworth::Processor(
39+
std::filters::butterworth::Mode::highPass, highPassCutoff
40+
);
41+
42+
const float lowPassCutoff = 12000.0f;
43+
node lowpass = std::filters::butterworth::Processor(
44+
std::filters::butterworth::Mode::lowPass, lowPassCutoff
45+
);
46+
47+
void main()
48+
{
49+
envelope.attackIn <- 0.001f;
50+
envelope.releaseIn <- 1.0f;
51+
52+
loop
53+
{
54+
while (triggerVelocity == 0) {
55+
advance();
56+
}
57+
58+
let vel = triggerVelocity;
59+
triggerVelocity = 0.0f;
60+
61+
envelope.triggerIn <- void;
62+
envelope.releaseIn <- 0.8f + vel * 0.4f;
63+
envelope.advance();
64+
65+
// Base frequency and inharmonic ratios
66+
float baseFreq = 1040.0f;
67+
float ratio1 = 1.0f;
68+
float ratio2 = 1.52f;
69+
float ratio3 = 2.03f;
70+
float ratio4 = 2.87f;
71+
72+
osc1.frequencyIn <- baseFreq * ratio1;
73+
osc2.frequencyIn <- baseFreq * ratio2;
74+
osc3.frequencyIn <- baseFreq * ratio3;
75+
osc4.frequencyIn <- baseFreq * ratio4;
76+
77+
// Slight detuning
78+
osc2.frequencyModIn <- 0.3f;
79+
osc3.frequencyModIn <- -0.2f;
80+
81+
float gain = envelope.gainOut;
82+
83+
while (gain > 0.001f && triggerVelocity == 0.0f)
84+
{
85+
// Mix oscillators into a temporary variable
86+
let sample = (osc1.out * 0.4f +
87+
osc2.out * 0.3f +
88+
osc3.out * 0.2f +
89+
osc4.out * 0.1f) * gain * vel * outputLevel;
90+
91+
// Apply highpass and lowpass filtering
92+
highpass.in <- sample;
93+
lowpass.in <- highpass.out;
94+
95+
let filtered = lowpass.out;
96+
97+
float pan = panning * 0.01f;
98+
float leftGain = 0.5f * (1.0f - pan);
99+
float rightGain = 0.5f * (1.0f + pan);
100+
out <- (filtered * leftGain, filtered * rightGain);
101+
102+
osc1.advance();
103+
osc2.advance();
104+
osc3.advance();
105+
osc4.advance();
106+
highpass.advance();
107+
lowpass.advance();
108+
envelope.advance();
109+
advance();
110+
111+
gain = envelope.gainOut;
112+
}
113+
}
114+
}
115+
116+
}
117+
}
118+
}

percupuff.cmajorpatch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"dsp/drums/Claves.cmajor",
2929
"dsp/drums/Bongos.cmajor",
3030
"dsp/drums/SideStick.cmajor",
31+
"dsp/drums/RideBell.cmajor",
3132
"dsp/Percupuff.cmajor"
3233
],
3334
"view": {

view/src/params.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export const instruments = {
1616
crash2: { name: "Crash Cymbal 2", group: "Crash Cymbals", midi: 57 },
1717
crash3: { name: "Crash Cymbal 3", group: "Crash Cymbals", midi: 52 },
1818

19+
rideBell: { name: "Ride Bell", group: "🔔", midi: 53 },
20+
1921
bongo1: { name: "High Bongo", group: "Bongos", midi: 60 },
2022
bongo2: { name: "Low Bongo", group: "Bongos", midi: 61 },
2123

@@ -47,6 +49,7 @@ export const groupColors: Record<InstrumentGroup, HSL> = {
4749
Snares: HSL(60, 80, 40),
4850
Hihats: HSL(120, 58, 41),
4951
["Crash Cymbals"]: HSL(60, 80, 40),
52+
["🔔"]: HSL(10, 50, 45),
5053
Bongos: HSL(60, 80, 40),
5154
["Wood Sounds"]: HSL(120, 58, 41),
5255
Toms: HSL(10, 50, 45),

0 commit comments

Comments
 (0)