Skip to content

Commit 54dd414

Browse files
committed
Panning support (requires adafruit/circuitpython#10529)
1 parent c25983d commit 54dd414

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

circuitpython/perc/code.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
# Settings
2626

2727
LEVEL = 0.25 # Use `SAMPLES[notenum]["level"]` to override
28-
FILTER_MAX = 20000.0
28+
FILTER_MAX = min(20000.0, hardware.SAMPLE_RATE / 2.0)
2929
FILTER_MIN = 50.0
30+
WIDTH = 1.0 # 0.0->1.0
3031

3132
VELOCITY_HARD = 100 # Velocity is 0->127
3233
VELOCITY_SOFT = 0 # Adjust to act as gate
@@ -44,52 +45,61 @@
4445
VELOCITY_HARD: "snare_hard",
4546
VELOCITY_SOFT: "snare_soft"
4647
},
47-
"level": 0.3
48+
"level": 0.3,
49+
"panning": -0.3 * WIDTH
4850
},
4951
41: {
5052
"samples": {
5153
VELOCITY_HARD: "tom_lo_hard",
5254
VELOCITY_SOFT: "tom_lo_soft"
53-
}
55+
},
56+
"panning": 1.0 * WIDTH
5457
},
5558
42: {
5659
"samples": {
5760
VELOCITY_SOFT: "hihat_closed"
58-
}
61+
},
62+
"panning": -1.0 * WIDTH
5963
},
6064
43: {
6165
"samples": {
6266
VELOCITY_HARD: "tom_mid_hard",
6367
VELOCITY_SOFT: "tom_mid_soft"
64-
}
68+
},
69+
"panning": 0.4 * WIDTH
6570
},
6671
44: {
6772
"samples": {
6873
VELOCITY_SOFT: "hihat_pedal"
69-
}
74+
},
75+
"panning": -1.0 * WIDTH
7076
},
7177
45: {
7278
"samples": {
7379
VELOCITY_HARD: "tom_hi_hard",
7480
VELOCITY_SOFT: "tom_hi_soft"
75-
}
81+
},
82+
"panning": -0.4 * WIDTH
7683
},
7784
46: {
7885
"samples": {
7986
VELOCITY_SOFT: "hihat_open"
80-
}
87+
},
88+
"panning": -1.0 * WIDTH
8189
},
8290
49: {
8391
"samples": {
8492
VELOCITY_HARD: "crash_hard",
8593
VELOCITY_SOFT: "crash_soft"
86-
}
94+
},
95+
"panning": -0.6 * WIDTH
8796
},
8897
51: {
8998
"samples": {
9099
VELOCITY_HARD: "ride_hard",
91100
VELOCITY_SOFT: "ride_soft"
92-
}
101+
},
102+
"panning": 0.6 * WIDTH
93103
}
94104
}
95105

@@ -125,10 +135,6 @@
125135
effect_reverb.play(effect_filter)
126136
effect_filter.play(mixer)
127137

128-
for i, wav in enumerate(samples.values()):
129-
mixer.voice[i].play(wav)
130-
mixer.voice[i].level = 0.0
131-
132138
def get_sample(notenum:int, velocity:int = 127) -> tuple[str, float]|None:
133139
if notenum in SAMPLES:
134140
sample = SAMPLES[notenum].copy()
@@ -151,6 +157,7 @@ def play_sample(sample:dict) -> None:
151157
i = get_sample_index(sample["name"])
152158
wav = samples[sample["name"]]
153159
mixer.voice[i].level = sample.get("level", LEVEL)
160+
mixer.voice[i].panning = sample.get("panning", 0.0)
154161
mixer.voice[i].loop = sample.get("loop", False)
155162
mixer.voice[i].play(wav)
156163

@@ -244,7 +251,7 @@ async def controls_handler():
244251
ui.setA(hardware.knobA.value >> 8)
245252
ui.setB(hardware.knobB.value >> 8)
246253

247-
await asyncio.sleep(0.005)
254+
await asyncio.sleep(0.01)
248255

249256
async def main():
250257
await asyncio.gather(

circuitpython/perc/hardware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# Settings
1818

1919
SAMPLE_RATE = 44100
20-
CHANNEL_COUNT = 1
20+
CHANNEL_COUNT = 2
2121
BUFFER_SIZE = 2048
2222

2323
# MCU

0 commit comments

Comments
 (0)