|
| 1 | +# 6_effects/code_chorus_penta.py |
| 2 | +# part of todbot circuitpython synthio tutorial |
| 3 | +# 14 Apr 2025 - @todbot / Tod Kurt |
| 4 | +import time, random |
| 5 | +import ulab.numpy as np |
| 6 | +import synthio |
| 7 | +import audiodelays, audiofilters |
| 8 | +from synth_setup import mixer, synth, SAMPLE_RATE, CHANNEL_COUNT, knobA, knobB |
| 9 | + |
| 10 | +time.sleep(1) |
| 11 | + |
| 12 | +chorus1 = audiodelays.Chorus( |
| 13 | + channel_count=CHANNEL_COUNT, |
| 14 | + sample_rate=SAMPLE_RATE, |
| 15 | + mix = 0.5, |
| 16 | + voices = 3, |
| 17 | + max_delay_ms = 50, |
| 18 | + delay_ms = synthio.LFO(rate=0.5, offset=15, scale=5), |
| 19 | +) |
| 20 | + |
| 21 | +mixer.voice[0].play(chorus1) # plug effect into the mixer (unplugs synth) |
| 22 | +chorus1.play(synth) # and plug synth into effect |
| 23 | + |
| 24 | +# make a quicky saw wave for chorus demo |
| 25 | +wave_saw = np.linspace(32000, -32000, num=128, dtype=np.int16) |
| 26 | +# and a filter to tame the high end |
| 27 | +lpf = synthio.Biquad(synthio.FilterMode.LOW_PASS, frequency=3000, Q=1.25) |
| 28 | + |
| 29 | +scale_pentatonic = [0, 2, 4, 7, 9, 12, 14, 16, 19, 21] # two octaves of offsets |
| 30 | + |
| 31 | +i=0 |
| 32 | +while True: |
| 33 | + midi_note = 48 + random.choice(scale_pentatonic) |
| 34 | + notes = [synthio.Note(synthio.midi_to_hz(midi_note), waveform=wave_saw, filter=lpf),] |
| 35 | + if knobB.value > 32000: |
| 36 | + notes.append(synthio.Note(synthio.midi_to_hz(midi_note+7), waveform=wave_saw, filter=lpf)) |
| 37 | + vA = knobA.value/65535 |
| 38 | + #chorus1.delay_ms.offset = (knobB.value/65535)*25 + 0.001 |
| 39 | + chorus1.mix = knobA.value/65535 |
| 40 | + print("playing %d mix: %.2f %d" % (midi_note,vA, len(notes))) |
| 41 | + synth.press(notes) |
| 42 | + time.sleep(0.1) |
| 43 | + synth.release(notes) |
| 44 | + time.sleep(0.25 if i%2 else 0.12 ) # give it a little groove |
| 45 | + i=i+1 |
0 commit comments