For some reason, I decided to try to play custom audio clips in MakeCode Arcade, completely ripping off of @chembot’s idea.
Instead of using SPEAR / complicated audio analysis tools, I decided to use scipy
’s signal.spectrogram
function to decompose to sine waves and play, which is a more basic version. You can see the GitHub repo here.
The thing I need help with, or would like the input and ideas of others, is that I’ve tried two methods to play the sine waves and I want to improve the sound quality of the second method… (both only tested in Chrome)
The first method, is storing two giant
number[][]
arrays of most prominent frequencies and their respective amplitudes, which actually turned out decently: (although it is not playing at full speed, more so ~92% speed…)
(make sure to interact with the page so sound can play. Also it’s quite laggy for the first few seconds as stuff loads in)
I generated it with the code in commit 04cb7a76510edee890c0f37265cff0d13940a6d3
and setting the period to 25. (20 sounded worse, but I left it as the default accidentally)
The second method, is using multiple long sound instructions to play the sine waves, which I thought would be better but it sounds much worse in that it’s “wobbly” and has a lot of extra sounds and noises:
I generated it with the code in commit 7cee335b09a4ecfd57332e53af4c4897c429f1e4
. You can see that I generate the sound instructions according to the format specified in the docs.
I was wondering if anyone had any ideas on why the sound instruction method is much worse and if there are any ways to improve the quality. I’ve tried different frequencies of sine waves, which wasn’t much better. Maybe there are some limitations I don’t know about or ways I’m abusing the sound instruction API incorrectly. (honestly, there’s a good chance that there is a simple tweak and I’m just incompetent lol)
@richard or anyone else on the dev team, (sorry for the ping) if you have any ideas or thoughts, I would love to hear them! Especially on my abuse on the sound instruction API / format.
Note: I don’t envision this being used actually in games, as this probably takes up a significant / almost all of the simulator’s power just to play the sine waves, which wouldn’t be very good if you were in a game that also needs to process stuff. This is also just lower quality in general, and it would probably be better to use the Song API and MIDI conversion for games instead. (speaking of which, I should probably get to work on some day… ) And this would probably be a PITA for moderation of games - I’m just trying to see what’s possible with MakeCode Arcade.