Skip to content

Instantly share code, notes, and snippets.

@todbot
Last active June 5, 2023 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todbot/18f8b6a1126fe6397784c5a4bf980510 to your computer and use it in GitHub Desktop.
Save todbot/18f8b6a1126fe6397784c5a4bf980510 to your computer and use it in GitHub Desktop.
tiny "song" made with just LFOs in synthio in CircuitPython
# synthio_tiny_lfo_song.py -- tiny "song" made with just LFOs in synthio
# 29 May 2023 - @todbot / Tod Kurt
# video demo: https://www.youtube.com/watch?v=m_ALNCWXor0
# requires CircuitPython 8.2.0-beta0 or later
import board, time, audiopwmio, synthio, random
audio = audiopwmio.PWMAudioOut(board.GP10)
synth = synthio.Synthesizer(sample_rate=22050)
audio.play(synth)
lfo_tremo1 = synthio.LFO(rate=3) # 3 Hz for fastest note
lfo_tremo2 = synthio.LFO(rate=2) # 2 Hz for middle note
lfo_tremo3 = synthio.LFO(rate=1) # 1 Hz for lower note
lfo_tremo4 = synthio.LFO(rate=0.75) # 0.75 Hz for lowest bass note
def do_notes(midi_note):
note1 = synthio.Note( synthio.midi_to_hz(midi_note), amplitude=lfo_tremo1)
note2 = synthio.Note( synthio.midi_to_hz(midi_note-7), amplitude=lfo_tremo2)
note3 = synthio.Note( synthio.midi_to_hz(midi_note-12), amplitude=lfo_tremo3)
note4 = synthio.Note( synthio.midi_to_hz(midi_note-24), amplitude=lfo_tremo4)
synth.release_all_then_press( (note1, note2, note3, note4) )
start_note = 65
song_notes = (start_note+0, start_note+5, start_note-3)
i=0
while True:
print("hi, we're just groovin")
do_notes(song_notes[i])
i= (i+1) % len(song_notes)
time.sleep(8)
@todbot
Copy link
Author

todbot commented May 30, 2023

And if you want the LFOs to retrigger on each note press, add this after press()-ing the notes:

    for lfo in (lfo_tremo1,lfo_tremo2,lfo_tremo3,lfo_tremo4):
        lfo.retrigger()

@todbot
Copy link
Author

todbot commented May 30, 2023

@RobCranfill
Copy link

Thanks for this code, I think it's gonna revitalize my 'featheremin' project!

I believe line 28 should be
i= (i+1) % len(song_notes)

Thanks!

@todbot
Copy link
Author

todbot commented Jun 5, 2023

Thanks for this code, I think it's gonna revitalize my 'featheremin' project!

I believe line 28 should be i= (i+1) % len(song_notes)

Thanks!

Thanks and yep sorry for the typo. Fixing now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment