-
Notifications
You must be signed in to change notification settings - Fork 617
move mixer sound synthesis into an audioworklet and add spatial audio #11072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
srietkerk
left a comment
There was a problem hiding this 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); |
There was a problem hiding this comment.
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?
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