Skip to content

Commit 752a47e

Browse files
authored
Add side stick sound (midi note 37) (#81)
* first draft of side stick * Modifications to side stick code * change side stick to use additive synthesis * Feed in noise to side stick sound
1 parent cecb02a commit 752a47e

File tree

4 files changed

+67
-32
lines changed

4 files changed

+67
-32
lines changed

dsp/Params.cmajor

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ namespace Percupuff
4343
float crash1Midi;
4444
float crash2Midi;
4545
float crash3Midi;
46+
float rideBellLevel;
47+
float rideBellPanning;
48+
float rideBellVelocity;
49+
float rideBellMidi;
4650
float bongoLevel;
4751
float bongoPanning;
4852
float bongoVelocity;
@@ -82,10 +86,6 @@ namespace Percupuff
8286
float cowbellPanning;
8387
float cowbellVelocity;
8488
float cowbellMidi;
85-
float rideBellLevel;
86-
float rideBellPanning;
87-
float rideBellVelocity;
88-
float rideBellMidi;
8989
float sideStickLevel;
9090
float sideStickPanning;
9191
float sideStickVelocity;
@@ -130,6 +130,10 @@ namespace Percupuff
130130
p.crash1Midi = 49.0f;
131131
p.crash2Midi = 57.0f;
132132
p.crash3Midi = 52.0f;
133+
p.rideBellLevel = 50.0f;
134+
p.rideBellPanning = 0.0f;
135+
p.rideBellVelocity = 100.0f;
136+
p.rideBellMidi = 53.0f;
133137
p.bongoLevel = 50.0f;
134138
p.bongoPanning = 0.0f;
135139
p.bongoVelocity = 100.0f;
@@ -169,10 +173,6 @@ namespace Percupuff
169173
p.cowbellPanning = 0.0f;
170174
p.cowbellVelocity = 100.0f;
171175
p.cowbellMidi = 56.0f;
172-
p.rideBellLevel = 50.0f;
173-
p.rideBellPanning = 0.0f;
174-
p.rideBellVelocity = 100.0f;
175-
p.rideBellMidi = 53.0f;
176176
p.sideStickLevel = 50.0f;
177177
p.sideStickPanning = 0.0f;
178178
p.sideStickVelocity = 100.0f;
@@ -217,6 +217,10 @@ namespace Percupuff
217217
input event float crash1Midi [[ name: "crash1Midi", min: 0, max: 127, init: 49, step: 1 ]];
218218
input event float crash2Midi [[ name: "crash2Midi", min: 0, max: 127, init: 57, step: 1 ]];
219219
input event float crash3Midi [[ name: "crash3Midi", min: 0, max: 127, init: 52, step: 1 ]];
220+
input event float rideBellLevel [[ name: "rideBellLevel", min: 0, max: 100, init: 50, step: 1 ]];
221+
input event float rideBellPanning [[ name: "rideBellPanning", min: -100, max: 100, init: 0, step: 5 ]];
222+
input event float rideBellVelocity [[ name: "rideBellVelocity", min: 0, max: 100, init: 100, step: 1 ]];
223+
input event float rideBellMidi [[ name: "rideBellMidi", min: 0, max: 127, init: 53, step: 1 ]];
220224
input event float bongoLevel [[ name: "bongoLevel", min: 0, max: 100, init: 50, step: 1 ]];
221225
input event float bongoPanning [[ name: "bongoPanning", min: -100, max: 100, init: 0, step: 5 ]];
222226
input event float bongoVelocity [[ name: "bongoVelocity", min: 0, max: 100, init: 100, step: 1 ]];
@@ -256,10 +260,6 @@ namespace Percupuff
256260
input event float cowbellPanning [[ name: "cowbellPanning", min: -100, max: 100, init: 0, step: 5 ]];
257261
input event float cowbellVelocity [[ name: "cowbellVelocity", min: 0, max: 100, init: 100, step: 1 ]];
258262
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 ]];
263263
input event float sideStickLevel [[ name: "sideStickLevel", min: 0, max: 100, init: 50, step: 1 ]];
264264
input event float sideStickPanning [[ name: "sideStickPanning", min: -100, max: 100, init: 0, step: 5 ]];
265265
input event float sideStickVelocity [[ name: "sideStickVelocity", min: 0, max: 100, init: 100, step: 1 ]];
@@ -307,6 +307,10 @@ namespace Percupuff
307307
event crash1Midi (float f) { params.crash1Midi = f; update(); }
308308
event crash2Midi (float f) { params.crash2Midi = f; update(); }
309309
event crash3Midi (float f) { params.crash3Midi = f; update(); }
310+
event rideBellLevel (float f) { params.rideBellLevel = f; update(); }
311+
event rideBellPanning (float f) { params.rideBellPanning = f; update(); }
312+
event rideBellVelocity (float f) { params.rideBellVelocity = f; update(); }
313+
event rideBellMidi (float f) { params.rideBellMidi = f; update(); }
310314
event bongoLevel (float f) { params.bongoLevel = f; update(); }
311315
event bongoPanning (float f) { params.bongoPanning = f; update(); }
312316
event bongoVelocity (float f) { params.bongoVelocity = f; update(); }
@@ -346,10 +350,6 @@ namespace Percupuff
346350
event cowbellPanning (float f) { params.cowbellPanning = f; update(); }
347351
event cowbellVelocity (float f) { params.cowbellVelocity = f; update(); }
348352
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(); }
353353
event sideStickLevel (float f) { params.sideStickLevel = f; update(); }
354354
event sideStickPanning (float f) { params.sideStickPanning = f; update(); }
355355
event sideStickVelocity (float f) { params.sideStickVelocity = f; update(); }

dsp/Percupuff.cmajor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ namespace Percupuff
8080
noise -> clap.noiseIn;
8181
noise -> crash.noiseIn;
8282
noise -> claves.noiseIn;
83+
noise -> sideStick.noiseIn;
8384

8485
// Take the output from all of our sounds, mix it together and put
8586
// it into the gain limiter to adjust how loud they are.

dsp/drums/SideStick.cmajor

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1+
// sound inspired by https://www.youtube.com/watch?v=cs9wltg-Nmo
2+
13
namespace Percupuff
24
{
35
namespace Drums
46
{
7+
// This processor tries to create a realistic side stick sound.
8+
// Additive synthesis is used to create the initial impact of the stick on the rim of the snare,
9+
// with filtered white noise mixed in for more brightness.
510
processor SideStick {
611
input event (std::notes::NoteOn) eventIn;
7-
output stream float<2> out;
812
input event Params paramsIn;
13+
input stream float noiseIn;
14+
output stream float<2> out;
915

1016
float triggerVelocity = 0.0f;
1117
int midiNotePitch = 0;
1218
float outputLevel = 0.5f;
1319
float panning = 0.0f;
1420

15-
// Velocity sensitivity is not implemented yet
16-
float velocitySensitivity = 1.0f;
17-
1821
event paramsIn(Params p) {
1922
midiNotePitch = int(p.sideStickMidi);
2023
outputLevel = p.sideStickLevel * 0.01f;
2124
panning = p.sideStickPanning;
22-
velocitySensitivity = p.sideStickVelocity;
2325
}
2426

2527
event eventIn(std::notes::NoteOn n) {
@@ -29,13 +31,41 @@ namespace Percupuff
2931
}
3032

3133
node envelope = Envelope;
32-
node osc1 = Oscillator(OscillatorShape::triangle);
33-
34+
node osc = OscillatorBank(OscillatorShape::triangle);
35+
36+
// Filters that shape the white noise.
37+
Lpf lpf = (0.0f, 0.0f);
38+
NotchFilter notch;
39+
3440
void main()
3541
{
36-
envelope.attackIn <- .001f;
37-
osc1.frequencyIn <- 587.0f;
38-
42+
envelope.releaseIn <- .25f;
43+
44+
osc.frequencyIn <- float<8>(
45+
676.0f,
46+
724.0f,
47+
987.0f,
48+
1030.0f,
49+
1170.0f,
50+
1224.0f,
51+
1380.0f,
52+
1436.0f
53+
);
54+
55+
osc.levelIn <- float<8>(
56+
0.8f,
57+
0.7f,
58+
0.6f,
59+
0.9f,
60+
0.9f,
61+
0.4f,
62+
0.3f,
63+
0.2f
64+
);
65+
66+
let invSampleRate = 1.0f / float(processor.frequency);
67+
notch.setCoefficients(8000.0f, 0.9f, float(processor.frequency));
68+
3969
loop
4070
{
4171
while (triggerVelocity == 0) {
@@ -44,21 +74,24 @@ namespace Percupuff
4474

4575
let vel = triggerVelocity;
4676
triggerVelocity = 0.0f;
47-
48-
envelope.releaseIn <- .2f + vel * 0.4f;
4977
envelope.triggerIn <- void;
5078
envelope.advance();
5179
float gain = envelope.gainOut;
80+
5281
while (gain > 0.0f && triggerVelocity == 0.0f) {
53-
osc1.frequencyModIn <- gain * 0.1f;
54-
let outSample = osc1.out * gain * 0.5f * vel * outputLevel;
82+
osc.frequencyModIn <- gain * 0.01f;
83+
84+
float lpSample = lpf.getSample(noiseIn, 4000.0f + vel * 10000.0f, invSampleRate);
85+
float filteredLpSample = notch.getSample(lpSample);
86+
87+
let outSample = ((sin(osc.out * (1.0f + vel * 0.5f)) + filteredLpSample * 0.4f) * gain * (0.5f + vel * 0.5f)) * outputLevel;
5588

5689
float pan = panning * 0.01f;
5790
float leftGain = 0.5f * (1.0f - pan);
5891
float rightGain = 0.5f * (1.0f + pan);
5992
out <- (outSample * leftGain, outSample * rightGain);
6093

61-
osc1.advance();
94+
osc.advance();
6295

6396
gain = envelope.gainOut;
6497
envelope.advance();
@@ -68,4 +101,4 @@ namespace Percupuff
68101
}
69102
}
70103
}
71-
}
104+
}

view/src/params.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const instruments = {
88
snare2: { name: "Electric Snare", group: "Snares", midi: 40 },
99
clap1: { name: "Clap", group: "Snares", midi: 39 },
1010

11+
1112
hihat1: { name: "Closed Hihat", group: "Hihats", midi: 42 },
1213
hihat2: { name: "Pedal Hihat", group: "Hihats", midi: 44 },
1314
hihat3: { name: "Open Hihat", group: "Hihats", midi: 46 },

0 commit comments

Comments
 (0)