-
Notifications
You must be signed in to change notification settings - Fork 775
/
Copy pathexample_09_LFO_tremolo.py
43 lines (31 loc) · 1.1 KB
/
example_09_LFO_tremolo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# SPDX-FileCopyrightText: 2023 John Park and @todbot / Tod Kurt
#
# SPDX-License-Identifier: MIT
import time
import board
import digitalio
import audiomixer
import synthio
# for PWM audio with an RC filter
# import audiopwmio
# audio = audiopwmio.PWMAudioOut(board.GP10)
# for I2S audio with external I2S DAC board
import audiobusio
# I2S on Audio BFF or Amp BFF on QT Py:
# audio = audiobusio.I2SOut(bit_clock=board.A3, word_select=board.A2, data=board.A1)
# I2S audio on PropMaker Feather RP2040
power = digitalio.DigitalInOut(board.EXTERNAL_POWER)
power.switch_to_output(value=True)
audio = audiobusio.I2SOut(board.I2S_BIT_CLOCK, board.I2S_WORD_SELECT, board.I2S_DATA)
mixer = audiomixer.Mixer(channel_count=1, sample_rate=44100, buffer_size=4096)
synth = synthio.Synthesizer(channel_count=1, sample_rate=44100)
audio.play(mixer)
mixer.voice[0].play(synth)
mixer.voice[0].level = 0.2
lfo_tremolo = synthio.LFO(rate=0.8, scale=0.3, offset=0.7)
midi_note = 50
note1 = synthio.Note(synthio.midi_to_hz(midi_note), amplitude=lfo_tremolo)
synth.press(note1)
while True:
print(lfo_tremolo.value)
time.sleep(0.05)