Microsoft MakeCode

Sound effect demo (no extensions)

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 :slight_smile:

If you want to explore the available waveforms, you try this simple interactive tool. It uses the 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 :wink:


Oh these are great! I had thought they made it in in the last release, completely forgot they came in right afterwards. Thanks again for the great contributions!

(also editing to note / confirm that I got ‘this far’!)


I added a few more, including knock/footsteps/thump sounds intended as less-obtrusive effects for games:

Feel free to copy or modify any of this as you see fit, and please post your results if you find new and interesting sounds.


Thanks kwx, this is a great addition to arcade.
Is it possible to play a loop like the drum&bass example during a game like your boulders and gems game or is that too complex for the hardware arcade is intended for?

1 Like

I used his simple loops 3 project and modified it a little to work on the PyGamer for one game my son designed.

1 Like

Here’s a quick test - it works in the emulator, but I haven’t tried it on hardware yet. I basically just pasted simple loops 4 onto the end of the file, and combined the snare+hi-hat into a single percussion track to avoid sound effect collisions:

I think you’d need something longer and more interesting than a single bar of music in a loop, otherwise it’s likely to drive the poor players insane :-/ The 12-bar pattern is arguably still too short, and it doesn’t help that I’m kind of tone deaf and am trying to compose songs based on half-understood music theory…

Once you have a longer piece, you’d either end up with a gigantic melody string that would be a pain to edit manually, or you’d need to use multiple distinct parts that you’d then need to synchronize. While the single-string example is easy to use with a single play() command, it’s a bit inefficient since it repeatedly switches back and forth between waveforms and envelopes in a way that has a lot of redundant pieces.

Separately, you need to be careful about the overall parallel sound channels being used. You’ll want to keep some available for sound effects, and I think there are also some collision issues when starting new sounds while previous ones are still playing. A new bar of melody might end up cutting off an ongoing sound effect instead of replacing a sustain from the previous bar’s last note.

I think it would be an interesting experiment to see what’s possible. Anyone up for tackling something like Ballblazer’s algorithmic theme music?


Hm, on second thought that doesn’t actually reduce the simultaneous sounds since it’s still playing the same notes (I was meaning to simplify the pattern but forgot to do so), but in practice it seems to help. I think there’s some melody-level scheduling in addition to soundInstruction-level scheduling?

Also, I failed to solve level 8 when testing it just now, maybe I was overdoing the difficulty on that one…

Yep, there’s a limit of four simultaneous music.Melody playing instances in melody.ts, and a limit of five simultaneous sound instructions in melody.h.

So you should be OK with something like 2-3 melody loops for music while still playing sound effects even if the loops have occasional overlapping notes.

I’ve just tried the game on a PyGamer, and performance is OK on the first two levels, but the scheduling falls apart on the much larger level three when moving since the rock update takes too long. Note to self: try a slightly less brute-force algorithm?

1 Like

Thanks for all the information. The first two levels of Boulders and Gems music hack run smoothly on Meowbit which is a bit weaker than Pygamer, I think.
The music sounds great on the hardware buzzer.
I’ll try to add some music to my Pergamon game and report how it goes :slight_smile: