I’ve gone ahead and made another extension! This one is super simple, it allows you to play songs written using MML. For more info on the syntax of MML, check out the README of this repo, where I’ve written up an explainer:
MML was used back in the old days for authoring chiptunes on systems like the NES! Some videogames still use it today. Anyways, have fun!
@Jedi the computer should just be a square wave, though i’ve never tested it to see how square it is. maybe i should hook it up to my oscilloscope…
in any case, you can make a custom instrument like this:
const myInstrument = new music.sequencer.Instrument();
// The waveform. See the table on this page: https://arcade.makecode.com/developer/sound
myInstrument.waveform = 15
// Controls the volume over time
myInstrument.ampEnvelope.attack = 0;
myInstrument.ampEnvelope.decay = 0;
myInstrument.ampEnvelope.sustain = 1024;
myInstrument.ampEnvelope.release = 0;
myInstrument.ampEnvelope.amplitude = 1204;
// Controls the pitch over time. Set the amplitude to 0 to ignore
myInstrument.pitchEnvelope.attack = 0;
myInstrument.pitchEnvelope.decay = 0;
myInstrument.pitchEnvelope.sustain = 0;
myInstrument.pitchEnvelope.release = 0;
myInstrument.pitchEnvelope.amplitude = 0;
// Varies the volume over time with a triangle wave. Set the amplitude to 0 to ignore
myInstrument.ampLFO.frequency = 1;
myInstrument.ampLFO.amplitude = 0;
// Varies the pitch over time with a triangle wave. Set the amplitude to 0 to ignore
myInstrument.pitchLFO.frequency = 1;
myInstrument.pitchLFO.amplitude = 0;
const mmlInstrument = new mml.MMLInstrument(myInstrument.buf);
music.play(
mml.playable(
mml.track(mmlInstrument, "CDEFGAB>C")
),
music.PlaybackMode.UntilDone
);
for more info on how envelopes work, here’s the wikipedia page though i’m sure there are many helpful youtube videos on the subject as well.
@Jedi here, I made a template project you can use to make custom instruments:
Just edit the code in this and reshare it. Then you can add the share link to a project as an extension and your custom instrument will appear in the dropdown of options next to the default ones.
If you do edit this, make sure you change the name of the exported variable to something descriptive so that you don’t accidentally collide with other folks. Also, this example makes the icon for the instrument pizza; change the //% jres="" comment to change the icon. You can use the qualified name for any of the builtin gallery sprites as icons; just hover over the sprite you want in the gallery and the hover text will be what you need to put in that jres comment