In case you’re looking for adding sound effects to your game, you may want to check out the new “noise” waveforms I had contributed a while back that are now available in the live version of MakeCode Arcade. These are usable without any extensions, the Melody feature allows choosing waveforms and setting envelopes, and this is also how the existing “play sound” options in the “Music” toolbox work.
Here are some examples:
For example, the “zapped” effect
~16 @10,0,255,1 !3200,500^1
works as follows:
- select waveform 16 (cycle noise 16)
- set the envelope - attack 10ms, decay 0ms, sustain volume 255, release 1ms
- play the note - start at 3200 Hz, play for 500ms, and continuously drop the frequency down to 1 Hz at the end.
The documentation doesn’t show the new waveforms yet, but you can now use waveforms 16-18 for repeating pseudorandom patterns with length 16/32/64. Waveform 4 is a tunable noise which replaces the old “metallic” waveform that got removed a while back. The pre-existing waveform 5 is white noise, this ignores the supplied frequency.
Let me know if you want more explanations of how these work. And please share if you have cool sound effects that make use of this
If you want to explore the available waveforms, you try this simple interactive tool. It uses the https://github.com/klausw3/pxt-sound-effects/ extension, but it’s also possible to play the same sounds using the string-based melody format.
One small gotcha is that you need to use new Melody(string)
in JavaScript to create the melodies. The music.playMelody(string, tempo)
method from the Music toolbox is intended to work with the melody editor, and it modifies the input string in ways that can break custom effects.
As the demo shows, it’s also possible to abuse the Melody syntax to play chords or multi-voice songs from a single melody string by setting a long decay on a super-short note, though this gets rather clunky to edit manually. For example,
~3 @20,0,255,1000 c4-99999 e g
plays a C chord using the “sine” waveform 3.
The sounds played this way still all count against the maximum number of supported simultaneous sounds, so this isn’t a way to get around that limit, but it may still be useful for simple cases since it can be tricky to synchronize a longer multipart melody when it’s split into parts. For comparison, here’s simple loops 4 which was my earlier attempt to do that.
Sorry about the long ramble, please let me know if you got this far