Skip to content

Conversation

@riknoll
Copy link
Member

@riknoll riknoll commented Jan 29, 2026

this PR does a few things:

  • refactors AudioContextManager into separate files and cleans up some of the audio channel stuff so that more code is shared (there's a new AudioSource base class)
  • moves our sound instruction synthesis for arcade from using the hacked together web audio oscillators to generate tones to instead use a new audio worklet (more on this below)
  • adds experimental spatial audio support

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

@riknoll riknoll requested a review from a team January 29, 2026 22:27
Copy link
Contributor

@srietkerk srietkerk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this console log be useful for future testing purposes or should it be removed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants