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

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions miniaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -40053,15 +40053,10 @@ typedef struct
static EM_BOOL ma_audio_worklet_process_callback__webaudio(int inputCount, const AudioSampleFrame* pInputs, int outputCount, AudioSampleFrame* pOutputs, int paramCount, const AudioParamFrame* pParams, void* pUserData)
{
ma_device* pDevice = (ma_device*)pUserData;
ma_uint32 frameCount;

(void)paramCount;
(void)pParams;

if (ma_device_get_state(pDevice) != ma_device_state_started) {
return EM_TRUE;
}

/*
The Emscripten documentation says that it'll always be 128 frames being passed in. Hard coding it like that feels
like a very bad idea to me. Even if it's hard coded in the backend, the API and documentation should always refer
Expand All @@ -40070,7 +40065,15 @@ static EM_BOOL ma_audio_worklet_process_callback__webaudio(int inputCount, const
Unfortunately the audio data is not interleaved so we'll need to convert it before we give the data to miniaudio
for further processing.
*/
frameCount = 128;
ma_uint32 frameCount = 128;

if (ma_device_get_state(pDevice) != ma_device_state_started) {
/* Fill the output buffer with zero to avoid a noise sound */
for (int i = 0; i < outputCount; i += 1) {
MA_ZERO_MEMORY(pOutputs[i].data, pOutputs[i].numberOfChannels * /*pOutputs[i].samplesPerChannel*/frameCount * sizeof(float));
}
return EM_TRUE;
}

if (inputCount > 0) {
/* Input data needs to be interleaved before we hand it to the client. */
Expand Down