mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-22 00:06:59 +02:00
Update split version for testing.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Audio playback and capture library. Choice of public domain or MIT-0. See license statements at the end of this file.
|
||||
miniaudio - v0.11.21 - 2023-11-15
|
||||
miniaudio - v0.11.22 - TBD
|
||||
|
||||
David Reid - mackron@gmail.com
|
||||
|
||||
@@ -12600,9 +12600,12 @@ static ma_result ma_context_create_IDirectSound__dsound(ma_context* pContext, ma
|
||||
}
|
||||
|
||||
/* The cooperative level must be set before doing anything else. */
|
||||
hWnd = ((MA_PFN_GetForegroundWindow)pContext->win32.GetForegroundWindow)();
|
||||
hWnd = (HWND)pContext->dsound.hWnd;
|
||||
if (hWnd == 0) {
|
||||
hWnd = ((MA_PFN_GetDesktopWindow)pContext->win32.GetDesktopWindow)();
|
||||
hWnd = ((MA_PFN_GetForegroundWindow)pContext->win32.GetForegroundWindow)();
|
||||
if (hWnd == 0) {
|
||||
hWnd = ((MA_PFN_GetDesktopWindow)pContext->win32.GetDesktopWindow)();
|
||||
}
|
||||
}
|
||||
|
||||
hr = ma_IDirectSound_SetCooperativeLevel(pDirectSound, hWnd, (shareMode == ma_share_mode_exclusive) ? MA_DSSCL_EXCLUSIVE : MA_DSSCL_PRIORITY);
|
||||
@@ -13919,6 +13922,8 @@ static ma_result ma_context_init__dsound(ma_context* pContext, const ma_context_
|
||||
return MA_API_NOT_FOUND;
|
||||
}
|
||||
|
||||
pContext->dsound.hWnd = pConfig->dsound.hWnd;
|
||||
|
||||
pCallbacks->onContextInit = ma_context_init__dsound;
|
||||
pCallbacks->onContextUninit = ma_context_uninit__dsound;
|
||||
pCallbacks->onContextEnumerateDevices = ma_context_enumerate_devices__dsound;
|
||||
@@ -16639,6 +16644,7 @@ static ma_result ma_device_stop__alsa(ma_device* pDevice)
|
||||
a small chance that our wakeupfd has not been cleared. We'll clear that out now if applicable.
|
||||
*/
|
||||
int resultPoll;
|
||||
int resultRead;
|
||||
|
||||
if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) {
|
||||
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[ALSA] Dropping capture device...\n");
|
||||
@@ -16653,12 +16659,15 @@ static ma_result ma_device_stop__alsa(ma_device* pDevice)
|
||||
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[ALSA] Preparing capture device successful.\n");
|
||||
}
|
||||
|
||||
/* Clear the wakeupfd. */
|
||||
resultPoll = poll((struct pollfd*)pDevice->alsa.pPollDescriptorsCapture, 1, 0);
|
||||
if (resultPoll > 0) {
|
||||
ma_uint64 t;
|
||||
read(((struct pollfd*)pDevice->alsa.pPollDescriptorsCapture)[0].fd, &t, sizeof(t));
|
||||
}
|
||||
/* Clear the wakeupfd. */
|
||||
resultPoll = poll((struct pollfd*)pDevice->alsa.pPollDescriptorsCapture, 1, 0);
|
||||
if (resultPoll > 0) {
|
||||
ma_uint64 t;
|
||||
resultRead = read(((struct pollfd*)pDevice->alsa.pPollDescriptorsCapture)[0].fd, &t, sizeof(t));
|
||||
if (resultRead != sizeof(t)) {
|
||||
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[ALSA] Failed to read from capture wakeupfd. read() = %d\n", resultRead);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) {
|
||||
@@ -16675,11 +16684,14 @@ static ma_result ma_device_stop__alsa(ma_device* pDevice)
|
||||
}
|
||||
|
||||
/* Clear the wakeupfd. */
|
||||
resultPoll = poll((struct pollfd*)pDevice->alsa.pPollDescriptorsPlayback, 1, 0);
|
||||
if (resultPoll > 0) {
|
||||
ma_uint64 t;
|
||||
read(((struct pollfd*)pDevice->alsa.pPollDescriptorsPlayback)[0].fd, &t, sizeof(t));
|
||||
}
|
||||
resultPoll = poll((struct pollfd*)pDevice->alsa.pPollDescriptorsPlayback, 1, 0);
|
||||
if (resultPoll > 0) {
|
||||
ma_uint64 t;
|
||||
resultRead = read(((struct pollfd*)pDevice->alsa.pPollDescriptorsPlayback)[0].fd, &t, sizeof(t));
|
||||
if (resultRead != sizeof(t)) {
|
||||
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[ALSA] Failed to read from playback wakeupfd. read() = %d\n", resultRead);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28350,7 +28362,7 @@ static ma_result ma_device_uninit__webaudio(ma_device* pDevice)
|
||||
#if defined(MA_USE_AUDIO_WORKLETS)
|
||||
{
|
||||
EM_ASM({
|
||||
var device = miniaudio.get_device_by_index($0);
|
||||
var device = window.miniaudio.get_device_by_index($0);
|
||||
|
||||
if (device.streamNode !== undefined) {
|
||||
device.streamNode.disconnect();
|
||||
@@ -28365,7 +28377,7 @@ static ma_result ma_device_uninit__webaudio(ma_device* pDevice)
|
||||
#else
|
||||
{
|
||||
EM_ASM({
|
||||
var device = miniaudio.get_device_by_index($0);
|
||||
var device = window.miniaudio.get_device_by_index($0);
|
||||
|
||||
/* Make sure all nodes are disconnected and marked for collection. */
|
||||
if (device.scriptNode !== undefined) {
|
||||
@@ -28392,7 +28404,7 @@ static ma_result ma_device_uninit__webaudio(ma_device* pDevice)
|
||||
|
||||
/* Clean up the device on the JS side. */
|
||||
EM_ASM({
|
||||
miniaudio.untrack_device_by_index($0);
|
||||
window.miniaudio.untrack_device_by_index($0);
|
||||
}, pDevice->webaudio.deviceIndex);
|
||||
|
||||
ma_free(pDevice->webaudio.pIntermediaryBuffer, &pDevice->pContext->allocationCallbacks);
|
||||
@@ -28557,7 +28569,6 @@ static void ma_audio_worklet_processor_created__webaudio(EMSCRIPTEN_WEBAUDIO_T a
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
pParameters->pDevice->webaudio.audioWorklet = emscripten_create_wasm_audio_worklet_node(audioContext, "miniaudio", &audioWorkletOptions, &ma_audio_worklet_process_callback__webaudio, pParameters->pDevice);
|
||||
|
||||
/* With the audio worklet initialized we can now attach it to the graph. */
|
||||
@@ -28697,7 +28708,6 @@ static ma_result ma_device_init__webaudio(ma_device* pDevice, const ma_device_co
|
||||
/* It's not clear if this can return an error. None of the tests in the Emscripten repository check for this, so neither am I for now. */
|
||||
pDevice->webaudio.audioContext = emscripten_create_audio_context(&audioContextAttributes);
|
||||
|
||||
|
||||
/*
|
||||
With the context created we can now create the worklet. We can only have a single worklet per audio
|
||||
context which means we'll need to craft this appropriately to handle duplex devices correctly.
|
||||
@@ -28746,7 +28756,7 @@ static ma_result ma_device_init__webaudio(ma_device* pDevice, const ma_device_co
|
||||
|
||||
/* We need to add an entry to the miniaudio.devices list on the JS side so we can do some JS/C interop. */
|
||||
pDevice->webaudio.deviceIndex = EM_ASM_INT({
|
||||
return miniaudio.track_device({
|
||||
return window.miniaudio.track_device({
|
||||
webaudio: emscriptenGetAudioObject($0),
|
||||
state: 1 /* 1 = ma_device_state_stopped */
|
||||
});
|
||||
@@ -28831,11 +28841,11 @@ static ma_result ma_device_init__webaudio(ma_device* pDevice, const ma_device_co
|
||||
/* The node processing callback. */
|
||||
device.scriptNode.onaudioprocess = function(e) {
|
||||
if (device.intermediaryBufferView == null || device.intermediaryBufferView.length == 0) {
|
||||
device.intermediaryBufferView = new Float32Array(Module.HEAPF32.buffer, pIntermediaryBuffer, bufferSize * channels);
|
||||
device.intermediaryBufferView = new Float32Array(HEAPF32.buffer, pIntermediaryBuffer, bufferSize * channels);
|
||||
}
|
||||
|
||||
/* Do the capture side first. */
|
||||
if (deviceType == miniaudio.device_type.capture || deviceType == miniaudio.device_type.duplex) {
|
||||
if (deviceType == window.miniaudio.device_type.capture || deviceType == window.miniaudio.device_type.duplex) {
|
||||
/* The data must be interleaved before being processed miniaudio. */
|
||||
for (var iChannel = 0; iChannel < channels; iChannel += 1) {
|
||||
var inputBuffer = e.inputBuffer.getChannelData(iChannel);
|
||||
@@ -28849,7 +28859,7 @@ static ma_result ma_device_init__webaudio(ma_device* pDevice, const ma_device_co
|
||||
_ma_device_process_pcm_frames_capture__webaudio(pDevice, bufferSize, pIntermediaryBuffer);
|
||||
}
|
||||
|
||||
if (deviceType == miniaudio.device_type.playback || deviceType == miniaudio.device_type.duplex) {
|
||||
if (deviceType == window.miniaudio.device_type.playback || deviceType == window.miniaudio.device_type.duplex) {
|
||||
_ma_device_process_pcm_frames_playback__webaudio(pDevice, bufferSize, pIntermediaryBuffer);
|
||||
|
||||
for (var iChannel = 0; iChannel < e.outputBuffer.numberOfChannels; ++iChannel) {
|
||||
@@ -28869,7 +28879,7 @@ static ma_result ma_device_init__webaudio(ma_device* pDevice, const ma_device_co
|
||||
};
|
||||
|
||||
/* Now we need to connect our node to the graph. */
|
||||
if (deviceType == miniaudio.device_type.capture || deviceType == miniaudio.device_type.duplex) {
|
||||
if (deviceType == window.miniaudio.device_type.capture || deviceType == window.miniaudio.device_type.duplex) {
|
||||
navigator.mediaDevices.getUserMedia({audio:true, video:false})
|
||||
.then(function(stream) {
|
||||
device.streamNode = device.webaudio.createMediaStreamSource(stream);
|
||||
@@ -28881,13 +28891,13 @@ static ma_result ma_device_init__webaudio(ma_device* pDevice, const ma_device_co
|
||||
});
|
||||
}
|
||||
|
||||
if (deviceType == miniaudio.device_type.playback) {
|
||||
if (deviceType == window.miniaudio.device_type.playback) {
|
||||
device.scriptNode.connect(device.webaudio.destination);
|
||||
}
|
||||
|
||||
device.pDevice = pDevice;
|
||||
|
||||
return miniaudio.track_device(device);
|
||||
return window.miniaudio.track_device(device);
|
||||
}, pConfig->deviceType, channels, sampleRate, periodSizeInFrames, pDevice->webaudio.pIntermediaryBuffer, pDevice);
|
||||
|
||||
if (deviceIndex < 0) {
|
||||
@@ -28897,7 +28907,7 @@ static ma_result ma_device_init__webaudio(ma_device* pDevice, const ma_device_co
|
||||
pDevice->webaudio.deviceIndex = deviceIndex;
|
||||
|
||||
/* Grab the sample rate from the audio context directly. */
|
||||
sampleRate = (ma_uint32)EM_ASM_INT({ return miniaudio.get_device_by_index($0).webaudio.sampleRate; }, deviceIndex);
|
||||
sampleRate = (ma_uint32)EM_ASM_INT({ return window.miniaudio.get_device_by_index($0).webaudio.sampleRate; }, deviceIndex);
|
||||
|
||||
if (pDescriptorCapture != NULL) {
|
||||
pDescriptorCapture->format = ma_format_f32;
|
||||
@@ -28927,9 +28937,9 @@ static ma_result ma_device_start__webaudio(ma_device* pDevice)
|
||||
MA_ASSERT(pDevice != NULL);
|
||||
|
||||
EM_ASM({
|
||||
var device = miniaudio.get_device_by_index($0);
|
||||
var device = window.miniaudio.get_device_by_index($0);
|
||||
device.webaudio.resume();
|
||||
device.state = miniaudio.device_state.started;
|
||||
device.state = window.miniaudio.device_state.started;
|
||||
}, pDevice->webaudio.deviceIndex);
|
||||
|
||||
return MA_SUCCESS;
|
||||
@@ -28949,9 +28959,9 @@ static ma_result ma_device_stop__webaudio(ma_device* pDevice)
|
||||
do any kind of explicit draining.
|
||||
*/
|
||||
EM_ASM({
|
||||
var device = miniaudio.get_device_by_index($0);
|
||||
var device = window.miniaudio.get_device_by_index($0);
|
||||
device.webaudio.suspend();
|
||||
device.state = miniaudio.device_state.stopped;
|
||||
device.state = window.miniaudio.device_state.stopped;
|
||||
}, pDevice->webaudio.deviceIndex);
|
||||
|
||||
ma_device__on_notification_stopped(pDevice);
|
||||
@@ -29010,6 +29020,7 @@ static ma_result ma_context_init__webaudio(ma_context* pContext, const ma_contex
|
||||
window.miniaudio.device_state.started = $4;
|
||||
|
||||
/* Device cache for mapping devices to indexes for JavaScript/C interop. */
|
||||
let miniaudio = window.miniaudio;
|
||||
miniaudio.devices = [];
|
||||
|
||||
miniaudio.track_device = function(device) {
|
||||
@@ -29061,13 +29072,13 @@ static ma_result ma_context_init__webaudio(ma_context* pContext, const ma_contex
|
||||
var device = miniaudio.devices[i];
|
||||
if (device != null &&
|
||||
device.webaudio != null &&
|
||||
device.state === window.miniaudio.device_state.started) {
|
||||
device.state === miniaudio.device_state.started) {
|
||||
|
||||
device.webaudio.resume().then(() => {
|
||||
Module._ma_device__on_notification_unlocked(device.pDevice);
|
||||
},
|
||||
(error) => {console.error("Failed to resume audiocontext", error);
|
||||
});
|
||||
_ma_device__on_notification_unlocked(device.pDevice);
|
||||
},
|
||||
(error) => {console.error("Failed to resume audiocontext", error);
|
||||
});
|
||||
}
|
||||
}
|
||||
miniaudio.unlock_event_types.map(function(event_type) {
|
||||
|
||||
Reference in New Issue
Block a user