mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-23 08:44:04 +02:00
Web Audio: Add support for variable buffer sizes to Audio Worklets.
Support for this was added to Emscripten 3.1.70. Currently only querying the quantum size is supported. I believe support for configuring the quantum size is coming later in Web Audio 1.1. Compilation with versions of Emscripten earlier than 3.1.70 is still supported.
This commit is contained in:
+17
-1
@@ -39857,6 +39857,10 @@ Web Audio Backend
|
|||||||
#if (__EMSCRIPTEN_major__ > 3) || (__EMSCRIPTEN_major__ == 3 && (__EMSCRIPTEN_minor__ > 1 || (__EMSCRIPTEN_minor__ == 1 && __EMSCRIPTEN_tiny__ >= 32)))
|
#if (__EMSCRIPTEN_major__ > 3) || (__EMSCRIPTEN_major__ == 3 && (__EMSCRIPTEN_minor__ > 1 || (__EMSCRIPTEN_minor__ == 1 && __EMSCRIPTEN_tiny__ >= 32)))
|
||||||
#include <emscripten/webaudio.h>
|
#include <emscripten/webaudio.h>
|
||||||
#define MA_SUPPORT_AUDIO_WORKLETS
|
#define MA_SUPPORT_AUDIO_WORKLETS
|
||||||
|
|
||||||
|
#if (__EMSCRIPTEN_major__ > 3) || (__EMSCRIPTEN_major__ == 3 && (__EMSCRIPTEN_minor__ > 1 || (__EMSCRIPTEN_minor__ == 1 && __EMSCRIPTEN_tiny__ >= 70)))
|
||||||
|
#define MA_SUPPORT_AUDIO_WORKLETS_VARIABLE_BUFFER_SIZE
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -40112,7 +40116,11 @@ 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
|
Unfortunately the audio data is not interleaved so we'll need to convert it before we give the data to miniaudio
|
||||||
for further processing.
|
for further processing.
|
||||||
*/
|
*/
|
||||||
frameCount = 128;
|
if (pDevice->type == ma_device_type_playback) {
|
||||||
|
frameCount = pDevice->playback.internalPeriodSizeInFrames;
|
||||||
|
} else {
|
||||||
|
frameCount = pDevice->capture.internalPeriodSizeInFrames;
|
||||||
|
}
|
||||||
|
|
||||||
if (ma_device_get_state(pDevice) != ma_device_state_started) {
|
if (ma_device_get_state(pDevice) != ma_device_state_started) {
|
||||||
/* Fill the output buffer with zero to avoid a noise sound */
|
/* Fill the output buffer with zero to avoid a noise sound */
|
||||||
@@ -40199,7 +40207,15 @@ static void ma_audio_worklet_processor_created__webaudio(EMSCRIPTEN_WEBAUDIO_T a
|
|||||||
Now that we know the channel count to use we can allocate the intermediary buffer. The
|
Now that we know the channel count to use we can allocate the intermediary buffer. The
|
||||||
intermediary buffer is used for interleaving and deinterleaving.
|
intermediary buffer is used for interleaving and deinterleaving.
|
||||||
*/
|
*/
|
||||||
|
#if defined(MA_SUPPORT_AUDIO_WORKLETS_VARIABLE_BUFFER_SIZE)
|
||||||
|
{
|
||||||
|
intermediaryBufferSizeInFrames = (size_t)emscripten_audio_context_quantum_size(audioContext);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
intermediaryBufferSizeInFrames = 128;
|
intermediaryBufferSizeInFrames = 128;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
pParameters->pDevice->webaudio.pIntermediaryBuffer = (float*)ma_malloc(intermediaryBufferSizeInFrames * (ma_uint32)channels * sizeof(float), &pParameters->pDevice->pContext->allocationCallbacks);
|
pParameters->pDevice->webaudio.pIntermediaryBuffer = (float*)ma_malloc(intermediaryBufferSizeInFrames * (ma_uint32)channels * sizeof(float), &pParameters->pDevice->pContext->allocationCallbacks);
|
||||||
if (pParameters->pDevice->webaudio.pIntermediaryBuffer == NULL) {
|
if (pParameters->pDevice->webaudio.pIntermediaryBuffer == NULL) {
|
||||||
|
|||||||
Reference in New Issue
Block a user