Last active
May 24, 2023 00:45
-
-
Save todbot/41414a94139d84651e29987343198134 to your computer and use it in GitHub Desktop.
rude noises using synthio in CircuitPython
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# synthio_rude_noises0.py -- rude noises using synthio | |
# 23 May 2023 - @todot / Tod Kurt | |
import board | |
import audiobusio, audiomixer, synthio | |
import ulab.numpy as np | |
SAMPLE_RATE = 28000 # clicks @ 36kHz & 48kHz on rp2040 | |
SAMPLE_SIZE = 512 | |
SAMPLE_VOLUME = 32000 # 0-32767 I think | |
# qtpy rp2040 pins (board.* names just match silkscreen, do not indicate functionality) | |
lck_pin, bck_pin, dat_pin = board.MISO, board.MOSI, board.SCK | |
audio = audiobusio.I2SOut(bit_clock=bck_pin, word_select=lck_pin, data=dat_pin) | |
mixer = audiomixer.Mixer(voice_count=1, sample_rate=SAMPLE_RATE, channel_count=1, | |
bits_per_sample=16, samples_signed=True, buffer_size=2048 ) | |
audio.play(mixer) | |
synth = synthio.Synthesizer(sample_rate=SAMPLE_RATE) | |
mixer.voice[0].level = 0.25 # turn down the volume a bit since this can get loud | |
mixer.voice[0].play(synth) | |
wave_sine = np.array(np.sin(np.linspace(0, 2*np.pi, SAMPLE_SIZE, endpoint=False)) * SAMPLE_VOLUME, dtype=np.int16) | |
wave_saw = np.linspace(SAMPLE_VOLUME, -SAMPLE_VOLUME, num=SAMPLE_SIZE, dtype=np.int16) | |
lfo1 = synthio.LFO(rate=(1/4), waveform=wave_saw) | |
lfo2 = synthio.LFO(rate=(1/8), waveform=wave_sine) | |
mathl12 = synthio.Math( synthio.MathOperation.LERP, lfo1, lfo2, 0.5) | |
note1 = synthio.Note( frequency=220, waveform=wave_saw, | |
ring_frequency=220, ring_bend=mathl12, ring_waveform=wave_saw) | |
synth.press( (note1,) ) | |
while True: | |
pass |
Author
todbot
commented
May 24, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment