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 78 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 uses the _2gb and _4gb tests (plus the parameter test) from #23659.

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 (from #23659) 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 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? Tests moved to #23659, work started on fixing the browser 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
cwoffenden added a commit to cwoffenden/emscripten that referenced this pull request Feb 12, 2025
This mostly adds an Audio Worklet parameter test, but also tidies a little the related tests and shared code.
@cwoffenden
Copy link
Contributor Author

Note for me to look at (POINTER_TYPE and POINTER_SIZE):

pointer_size

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