Help with music variables

@richard, could you set this topic to watching (and also the c++ one) (also tell me if you do/don’t do I know whether to @ or not)? So I’m more wanting to make beepbox inside makecode, but I need help with some of the things I am able to do in makecode. Also please note I’m doing this in javascript mainly for buffers.

Beepbox
freq and amp

beepbox.co can have some words notes, like this. It’s it possible to have all of those on makecode? the pitch/amp shifts is specifically what I’m talking about.

instruments

there are instruments like FM that should be easy to make, but there is also “harmonics”. How do I make that???

envelopes/EQ filter/effects/etc

There are many envelopes and effects and whatever inside beepbox, and I’m wondering what is possible, especially considering I could do a twang 1 on a pitch shift.

Makecode

so… obviously, I need to know what sound output to use. for example, i could attempt to use music.createSong the whole way which wouldn’t be the best, or I could do a combo of music.createSong and something else?

music.createSong buffer

There’s a good chance somethings wrong because I asked AI, but I at least showed the actual function from github. Are there other function(s) I should show it so I know exactly how it works?

-------------- section 1 (header) --------------
0:   version (00)
1-2: beats per minute
3: beats per measure
4:   ticks per beat
5:   number of measures
6:   number of tracks

-------------- section 2 (instrument header) --------------
0:     id
1:     flags:
  0: sound FX / Melodical toggle
  1: mute / audible
  2: pitch mode / noise
2-3:   data length
4-5:   note length
6:     waveform (triangle square sawtooth etc)
7-16:  amp attack, decay, sustain, release, volume (2 bytes per)
17-26: pitch attack, decay, sustain, release, volume (2 bytes per)
27:    amp   LFO freq
28-29: amp   LFO amp
30:    pitch LFO freq
31-32: pitch LFO amp
33:    base octave

-------------- section 3 (note) --------------
0-1: start
2-3: end
4:   notes in chord
5:   flags:
  0-1: accidental (00=normal, 01=flat, 10=sharp)
  2-7: pitch
how it loops: 1 \[2, \[3\]\] where \[...\] means a loop (\[1,\[2,3\]\] means 1 \[2323232323232323232323\] 1 \[233232323232323\] 1 \[2323\]...
Sharing

How do I share an anything from makecode? I was thinking about qr codes (there’s an extension for that) but are there better methods without using the console? For escape, can I copy paste information or scan a qr code using makecode? depending on what you say, how would I export information for it? I also don’t want the user to manually paste, as the code/data will get long and the user might make a mistake. The settings extension also isn’t enough because it cant share. I could also try to make it a Multiplayer thimg where you transfer data by connecting to another person’s game, but that wouldn’t be easy especially sense they cant always be online.

also, if there is anybody better at helping than Richard (I’m not saying you’re bad) at this, please do.

1 Like

@VoxelMaster64 the sad truth is that i have a lot of stuff to do and i can’t respond to every post! i try to spread my time among everyone and you ask a lot of questions (that’s not a complaint! just an explanation)

it’s definitely possible to change pitch and amp over time! sounds in makecode are created using buffers of sound “instructions”. each instruction has the following properties:

  • waveform
  • duration
  • start frequency
  • end frequency
  • start volume
  • end volume

you can render pitch bend events, envelopes, and more by chaining these instructions together.

if you want to see an example of this, check out the renderInstrument function:

the code here is complicated, but i added lots of comments that explain what it’s doing. this is how we render sounds for the instruments in the song editor by chaining together a ton of these sound instructions

as for how to make specific instruments, i recommend experimenting with layering different frequencies and playing with different envelopes and waveforms! also, check out the music projects by @WoofWoof and @UnsignedArduino, they’ve done lots of work recreating specific instruments

as for effects, there are some effects that you might be able to fake, like an echo or pitch shifting, but we don’t have any built in effects pipeline or anything like that.

finally: sharing. there’s no good way to export text from a makecode project, but you can work around this with three ways:

  1. QR code as you mentioned. there is a QR code extension but the amount of data you can include is pretty limited
  2. printing to console.log. this is the easiest want to do, but obviously relies on the user opening the console and copying the text
  3. finally, hosting the game in a github repo and injecting your own custom javascript into the page so that you can output the code in an easily copyable format. see @jwunderl’s recent post for more info on the types of things you can do here. this requires the most effort, but it’s what i would go for if i was doing something like this
3 Likes

Yeah so a lot of this is stuff I’m messing with in this topic. Press B to play the short demo song I have in there right now. I’m pretty proud of it!
If you open the console, you can see that it prints a giant block of data, which is your current song, and that’s how I plan to have song exporting work. I still have no idea how importing will work barring editing the code, which is what I do now. Maybe copy and paste will work as I know I have been able to use that before.

At the bottom of that topic you’ll also see a hand pan / steel drum sounding instrument I made which plays the main frequency of the note you play and then all the other frequencies of the other possible notes at a much lower volume to replicate the sound. Many instruments can be replicated this way, though probably @UnsignedArduino will be able to speak more on that.

Many things in beepbox will most definitely not be possible without some pull requests to the Makecode source code to make new instruments, which I have no experience with nor do I have any desire to do myself. Anything you can do by chaining sound instructions together is perfectly possible, and sound instructions can be down to 1 ms in length.

All the sounds in my editor use music.playInstructions() to play the “raw” sound buffers, mostly because I wanted to learn how to implement stuff like LFO and other effects myself.
Feel free to look at that code and ask any questions you want!

2 Likes

as richard said ya I am working on replicating instruments, the tool is in Python and hopefully within a week or so it’ll be ready. It directly maps MIDI’s 128 melodic instruments and 61 drums to actual MakeCode Arcade Song instruments (1:1) I hand-wrote (ok yeah with a bit of help from AI lol, but i did the final approval), and I did my best to replicate them - they’re…decent I guess. You’ll see then.

I also saw this, by @Kikketer, which looks relevant to what you’re doing:

2 Likes