Skip to content

Commit 93be6dd

Browse files
committed
Basic effects controls
1 parent 5f2e096 commit 93be6dd

File tree

1 file changed

+47
-22
lines changed

1 file changed

+47
-22
lines changed

circuitpython/perc/code.py

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,73 +14,77 @@
1414
import audiocore
1515
import os
1616
import audiomixer
17+
import audiofilters
18+
import synthio
19+
import audiofreeverb
1720

1821
# Settings
1922

20-
LEVEL = 0.25 # Use `SAMPLES[notenum]["level"]` to override
23+
LEVEL = 0.25 # Use `SAMPLES[notenum]["level"]` to override
24+
FILTER_MAX = 20000.0
25+
FILTER_MIN = 50.0
2126

22-
## Velocity is 0->127
23-
HARD = 100
24-
SOFT = 0 # Adjust to act as gate
27+
VELOCITY_HARD = 100 # Velocity is 0->127
28+
VELOCITY_SOFT = 0 # Adjust to act as gate
2529

2630
SAMPLES = {
2731
36: {
2832
"samples": {
29-
HARD: "kick_hard",
30-
SOFT: "kick_soft"
33+
VELOCITY_HARD: "kick_hard",
34+
VELOCITY_SOFT: "kick_soft"
3135
},
3236
"level": 0.3
3337
},
3438
38: {
3539
"samples": {
36-
HARD: "snare_hard",
37-
SOFT: "snare_soft"
40+
VELOCITY_HARD: "snare_hard",
41+
VELOCITY_SOFT: "snare_soft"
3842
},
3943
"level": 0.3
4044
},
4145
41: {
4246
"samples": {
43-
HARD: "tom_lo_hard",
44-
SOFT: "tom_lo_soft"
47+
VELOCITY_HARD: "tom_lo_hard",
48+
VELOCITY_SOFT: "tom_lo_soft"
4549
}
4650
},
4751
42: {
4852
"samples": {
49-
SOFT: "hihat_closed"
53+
VELOCITY_SOFT: "hihat_closed"
5054
}
5155
},
5256
43: {
5357
"samples": {
54-
HARD: "tom_mid_hard",
55-
SOFT: "tom_mid_soft"
58+
VELOCITY_HARD: "tom_mid_hard",
59+
VELOCITY_SOFT: "tom_mid_soft"
5660
}
5761
},
5862
44: {
5963
"samples": {
60-
SOFT: "hihat_pedal"
64+
VELOCITY_SOFT: "hihat_pedal"
6165
}
6266
},
6367
45: {
6468
"samples": {
65-
HARD: "tom_hi_hard",
66-
SOFT: "tom_hi_soft"
69+
VELOCITY_HARD: "tom_hi_hard",
70+
VELOCITY_SOFT: "tom_hi_soft"
6771
}
6872
},
6973
46: {
7074
"samples": {
71-
SOFT: "hihat_open"
75+
VELOCITY_SOFT: "hihat_open"
7276
}
7377
},
7478
49: {
7579
"samples": {
76-
HARD: "crash_hard",
77-
SOFT: "crash_soft"
80+
VELOCITY_HARD: "crash_hard",
81+
VELOCITY_SOFT: "crash_soft"
7882
}
7983
},
8084
51: {
8185
"samples": {
82-
HARD: "ride_hard",
83-
SOFT: "ride_soft"
86+
VELOCITY_HARD: "ride_hard",
87+
VELOCITY_SOFT: "ride_soft"
8488
}
8589
}
8690
}
@@ -100,7 +104,24 @@
100104
voice_count=len(samples),
101105
)
102106

103-
hardware.audio.play(mixer)
107+
effect_filter = audiofilters.Filter(
108+
filter=synthio.Biquad(synthio.FilterMode.LOW_PASS, FILTER_MAX, 1.2),
109+
sample_rate=hardware.SAMPLE_RATE,
110+
channel_count=hardware.CHANNEL_COUNT,
111+
buffer_size=hardware.BUFFER_SIZE,
112+
)
113+
114+
effect_reverb = audiofreeverb.Freeverb(
115+
mix=0.0,
116+
sample_rate=hardware.SAMPLE_RATE,
117+
channel_count=hardware.CHANNEL_COUNT,
118+
buffer_size=hardware.BUFFER_SIZE,
119+
)
120+
121+
hardware.audio.play(effect_reverb)
122+
effect_reverb.play(effect_filter)
123+
effect_filter.play(mixer)
124+
104125
for i, wav in enumerate(samples.values()):
105126
mixer.voice[i].play(wav)
106127
mixer.voice[i].level = 0.0
@@ -169,7 +190,11 @@ async def controls_handler():
169190
while True:
170191
for event in hardware.check_buttons():
171192
pass
193+
172194
knobA, knobB = hardware.knobA.value, hardware.knobB.value
195+
effect_filter.filter.frequency = ((knobA / 65535.0) ** 2) * (FILTER_MAX - FILTER_MIN) + FILTER_MIN
196+
effect_reverb.mix = knobB / 65535.0
197+
173198
await asyncio.sleep(0.005)
174199

175200
async def main():

0 commit comments

Comments
 (0)