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

WebAudio: Fix a noise sound before device was started #908

Merged
merged 3 commits into from
Jan 10, 2025

Conversation

FrancoisRecisio
Copy link

Hello! In our project compiled with Emscripten and executed in a browser, we had a noise sound at startup. We found that it occurred after the device was init and before it was started. And if we don't start the device, we can hear the never-ending noise. This code fixes that: if the device is not started, the output buffer is filled with 0.

@FrancoisRecisio
Copy link
Author

I updated this PR, we still had the problem (but I don't know if there was a version regression on our side...). So now I use a loop to iterate through outputs, rather than having a single MA_ZERO_MEMORY. Or maybe pDevice->playback.internalChannels = pOutputs[i].numberOfChannels * outputCount ?

On another topic, emscripten has exposed samplesPerChannel instead of 128, since version 3.1.70. This could be the subject of another PR but it would be great to use.

@mackron
Copy link
Owner

mackron commented Nov 15, 2024

Thanks for this. This looks fine to me on the surface. I've just switched from Windows to Linux and haven't yet moved all of my projects over to my new workflow so might be a bit before I get to this.

On another topic, emscripten has exposed samplesPerChannel instead of 128, since version 3.1.70. This could be the subject of another PR but it would be great to use.

Nice! Thanks a lot for the tip on that. I actually mentioned this to the Emscripten developers a while ago, so I'll definitely be open to integrating that (my issue if you care: emscripten-core/emscripten#18853).

@mackron mackron merged commit 1a7a9a7 into mackron:dev Jan 10, 2025
@mackron
Copy link
Owner

mackron commented Jan 11, 2025

I've finally got around to merging this. I also added support for the samplesPerChannel thing as well. Older versions of Emscripten are still supported. This was the change in case you were interested: ae2cd4b

The way I understand it is that Emscripten currently supports the ability to query the quantum size, but you can't actually configure it just yet. The internal infrastructure to support that is now in place though so it should be trivial to plug that in once Emscripten adds support.

@FrancoisRecisio
Copy link
Author

Thanks for the merge and the variable buffer sizes!

@FrancoisRecisio FrancoisRecisio deleted the fix_noise_before_start_device branch January 13, 2025 09: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