Skip to content

Instantly share code, notes, and snippets.

@treytomes
Created January 22, 2024 19:41
Show Gist options
  • Save treytomes/23b606142f987592e521fd33cea71111 to your computer and use it in GitHub Desktop.
Save treytomes/23b606142f987592e521fd33cea71111 to your computer and use it in GitHub Desktop.
Playing a familiar tune with the Mini Micro sound generator.
// Play a familiar tune.
bpm = 200
bps = bpm / 60
spb = 1 / bps
notes = {
"R": 0,
"C4": 60,
"C5": 72,
"E5": 76,
"G5": 79,
"G4": 67,
}
dur8 = spb / 2
dur4 = spb
waveform = Sound.triangleWave
instr = new Sound
instr.init spb, notes.C4, 1, waveform
song = [
[ notes.E5, dur8 ],
[ notes.E5, dur8 ],
[ notes.R, dur8 ],
[ notes.E5, dur8 ],
[ notes.R, dur8 ],
[ notes.C5, dur8 ],
[ notes.E5, dur4 ],
[ notes.G5, dur4 ],
[ notes.R, dur4 ],
[ notes.G4, dur4 ],
[ notes.R, dur4 ],
]
// play "O5T8EERERCT4EGRGR"
lastPlayTime = time
index = 0
while index < song.len
if time - lastPlayTime > spb then
lastPlayTime = time
noteNumber = song[index][0]
noteDuration = song[index][1]
instr.freq = noteFreq(noteNumber)
instr.duration = noteDuration
instr.play
index += 1
end if
end while
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment