Skip to content
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

[AUDIO_WORKLET] Added support for MEMORY64 and 2GB heap (including tests) #23508

Open
wants to merge 73 commits into
base: main
Choose a base branch
from

Conversation

cwoffenden
Copy link
Contributor

@cwoffenden cwoffenden commented Jan 27, 2025

This is built on #22753 and expands on the tests in #23394 (which could also be split into their own PR, but they'll all fail due to the required changes).

It adds support for MEMORY64 to audio worklets and tests that:

  • All the pointer offsets and maths now work with >2GB heap
  • Everything works building with MEMORY64 and >4GB heap

The tests already prove out various buffer combinations using the INITIAL_MEMORY and GLOBAL_BASE flags.

For the code changes, besides parameters expecting BigInt it also needed any shifts removing from the offset calculations (signed shifts fail >2GB, unsigned >4GB).

The interactive tests can be run with:

test/runner.py interactive_2gb.test_audio_worklet_params_mixing
test/runner.py interactive64_4gb.test_audio_worklet_params_mixing

We can remove the float-by-float JS copy and replace with this simple TypedArray set() calls.
Typed views are recreated if needed but otherwise are reused.
Lots of juggling with the various pointers, and next will be to reduce the code and move all of the output first to stop repeating some of the calculations. Some can also move to the constructor.
The code has also been brought back closer to the original for comparison.
The initial stackAlloc() is overflowing, seeming to need more space so this is accounted for.
Tested with various stack sizes, output sizes, and generators.
The assertions should now cover all cases of changes in address and size of the output views.
(Off home!)
Rough implementation to see what needs doing in JS vs Wasm.
The tests pass the audio context in a void* for convenience, which needs shortening/widening for 64-bit pointers.
@cwoffenden
Copy link
Contributor Author

cwoffenden commented Jan 29, 2025

What about the exsiting audio worklet tests in test_browser.py?

I'll try to take a look in the next days, they're definitely all failing because even 2GB tests should fail. One of a couple of examples here:

options >>= 2;

Then for wasm64 the offset fails, e.g.:

numAudioParams = HEAPU32[options+1],

The offset should be +2 since the entry before is a pointer.

A simple standalone test with just the noise generator is:

emcc -sAUDIO_WORKLET -sWASM_WORKERS -sASSERTIONS=2 -sWEBAUDIO_DEBUG -sINITIAL_MEMORY=2200mb -sGLOBAL_BASE=2gb -o index.html audioworklet.c

With this PR's changes so far it now works, but I've more to do so this is still draft.

(All the CI failures I see are LLVM version issues Passed as of 1b36c8d.)

@cwoffenden cwoffenden changed the title [AUDIO_WORKLET] Added support for MEMORY64 (including tests) [AUDIO_WORKLET] Added support for MEMORY64 and 2GB heap (including tests) Jan 29, 2025
@cwoffenden
Copy link
Contributor Author

cwoffenden commented Feb 3, 2025

I wrote a test for the web audio parameters, creating a pair of descriptors and using the first to handle fading. It needs some tidying up but the important parts are done and it correctly gets the C structs to JS. Demo here:

https://wip.numfum.com/cw/2025-02-05/index.html

It only properly works in Chrome and Firefox so far (I'll look at it).

This single line does the fade-in/out:

param.setTargetAtTime((param.value > 0.5) ? 0 : 1, 0 /* same as context.currentTime */, 0.5);

And the mix is currently done with this:

outputData[i] += inputData[i] * params[0].data[(params[0].length > 1) ? i : 0]; // world's worst mixer...

As before, @sbc100, shall I create a new PR just for these tests? Then another PR that fixes running the tests?

@cwoffenden
Copy link
Contributor Author

What about the exsiting audio worklet tests in test_browser.py?

All the AW tests are silently failing. I'll look at fixing them next.

@cwoffenden
Copy link
Contributor Author

It looks like we already have interactive64 mode in test_interactive.py. Can you just add interactive64_4gb and interactive_2gb modes? (copy them from test_browser.py).

Done.

@cwoffenden cwoffenden marked this pull request as ready for review February 6, 2025 15:22
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.

2 participants