|
14 | 14 | import audiocore
|
15 | 15 | import os
|
16 | 16 | import audiomixer
|
| 17 | +import audiofilters |
| 18 | +import synthio |
| 19 | +import audiofreeverb |
17 | 20 |
|
18 | 21 | # Settings
|
19 | 22 |
|
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 |
21 | 26 |
|
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 |
25 | 29 |
|
26 | 30 | SAMPLES = {
|
27 | 31 | 36: {
|
28 | 32 | "samples": {
|
29 |
| - HARD: "kick_hard", |
30 |
| - SOFT: "kick_soft" |
| 33 | + VELOCITY_HARD: "kick_hard", |
| 34 | + VELOCITY_SOFT: "kick_soft" |
31 | 35 | },
|
32 | 36 | "level": 0.3
|
33 | 37 | },
|
34 | 38 | 38: {
|
35 | 39 | "samples": {
|
36 |
| - HARD: "snare_hard", |
37 |
| - SOFT: "snare_soft" |
| 40 | + VELOCITY_HARD: "snare_hard", |
| 41 | + VELOCITY_SOFT: "snare_soft" |
38 | 42 | },
|
39 | 43 | "level": 0.3
|
40 | 44 | },
|
41 | 45 | 41: {
|
42 | 46 | "samples": {
|
43 |
| - HARD: "tom_lo_hard", |
44 |
| - SOFT: "tom_lo_soft" |
| 47 | + VELOCITY_HARD: "tom_lo_hard", |
| 48 | + VELOCITY_SOFT: "tom_lo_soft" |
45 | 49 | }
|
46 | 50 | },
|
47 | 51 | 42: {
|
48 | 52 | "samples": {
|
49 |
| - SOFT: "hihat_closed" |
| 53 | + VELOCITY_SOFT: "hihat_closed" |
50 | 54 | }
|
51 | 55 | },
|
52 | 56 | 43: {
|
53 | 57 | "samples": {
|
54 |
| - HARD: "tom_mid_hard", |
55 |
| - SOFT: "tom_mid_soft" |
| 58 | + VELOCITY_HARD: "tom_mid_hard", |
| 59 | + VELOCITY_SOFT: "tom_mid_soft" |
56 | 60 | }
|
57 | 61 | },
|
58 | 62 | 44: {
|
59 | 63 | "samples": {
|
60 |
| - SOFT: "hihat_pedal" |
| 64 | + VELOCITY_SOFT: "hihat_pedal" |
61 | 65 | }
|
62 | 66 | },
|
63 | 67 | 45: {
|
64 | 68 | "samples": {
|
65 |
| - HARD: "tom_hi_hard", |
66 |
| - SOFT: "tom_hi_soft" |
| 69 | + VELOCITY_HARD: "tom_hi_hard", |
| 70 | + VELOCITY_SOFT: "tom_hi_soft" |
67 | 71 | }
|
68 | 72 | },
|
69 | 73 | 46: {
|
70 | 74 | "samples": {
|
71 |
| - SOFT: "hihat_open" |
| 75 | + VELOCITY_SOFT: "hihat_open" |
72 | 76 | }
|
73 | 77 | },
|
74 | 78 | 49: {
|
75 | 79 | "samples": {
|
76 |
| - HARD: "crash_hard", |
77 |
| - SOFT: "crash_soft" |
| 80 | + VELOCITY_HARD: "crash_hard", |
| 81 | + VELOCITY_SOFT: "crash_soft" |
78 | 82 | }
|
79 | 83 | },
|
80 | 84 | 51: {
|
81 | 85 | "samples": {
|
82 |
| - HARD: "ride_hard", |
83 |
| - SOFT: "ride_soft" |
| 86 | + VELOCITY_HARD: "ride_hard", |
| 87 | + VELOCITY_SOFT: "ride_soft" |
84 | 88 | }
|
85 | 89 | }
|
86 | 90 | }
|
|
100 | 104 | voice_count=len(samples),
|
101 | 105 | )
|
102 | 106 |
|
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 | + |
104 | 125 | for i, wav in enumerate(samples.values()):
|
105 | 126 | mixer.voice[i].play(wav)
|
106 | 127 | mixer.voice[i].level = 0.0
|
@@ -169,7 +190,11 @@ async def controls_handler():
|
169 | 190 | while True:
|
170 | 191 | for event in hardware.check_buttons():
|
171 | 192 | pass
|
| 193 | + |
172 | 194 | 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 | + |
173 | 198 | await asyncio.sleep(0.005)
|
174 | 199 |
|
175 | 200 | async def main():
|
|
0 commit comments