move mixer sound synthesis into an audioworklet and add spatial audio#11072
Merged
move mixer sound synthesis into an audioworklet and add spatial audio#11072
Conversation
jwunderl
approved these changes
Feb 2, 2026
srietkerk
reviewed
Feb 2, 2026
Contributor
srietkerk
left a comment
There was a problem hiding this comment.
In addition to these comments, I was wondering if you could include comments for the different audio source types and what they're used for? Like I know that the audio element source is used for the audio extension on the microbit, but everything else is fuzzy. I feel like the added context would be helpful for debugging audio issues.
| channel[j] = channel[j] + (v / 0xffff); | ||
| } | ||
| } | ||
| // console.log("v", v); |
Contributor
There was a problem hiding this comment.
Will this console log be useful for future testing purposes or should it be removed?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
this PR does a few things:
the new audio worklet allows us to generate PCM data using code closely adapted from the C++. audio worklet nodes are web audio nodes that spin up their own webworker-like thread that is able to generate sound on the fly, like an oscillator. because this code closely mirrors the C++, our sound is now much more accurate to what the hardware produces. this also fixes a number of edge-case bugs that we had with our old implementation such as the one reported here and the occasional "note playing backwards" bug you used to get when playing songs from the music editor.
as a bonus, the sound effect editor now displays an actual oscilloscope preview when sounds are playing rather than the fake one we used to show. i might do another PR later to update some of the button icons and block previews so that they more accurately reflect the actual waveform now that users can see it for themselves
spatial audio is also a part of this PR, but needs to be tested more thoroughly before it's surfaced to users. this is mainly intended as an accessibility feature for making games for people with low vision.
finally, there is no change to how sound expressions are played for the micro:bit. in the future, i might move that into the audioworklet as well since it will probably fix some of the choppy playback issues we have on firefox