Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
miniaudio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
miniaudio
Commits
2b8bb34c
Commit
2b8bb34c
authored
Nov 29, 2023
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update split version for testing.
parent
2b0c525e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
38 deletions
+54
-38
extras/miniaudio_split/miniaudio.c
extras/miniaudio_split/miniaudio.c
+47
-36
extras/miniaudio_split/miniaudio.h
extras/miniaudio_split/miniaudio.h
+7
-2
No files found.
extras/miniaudio_split/miniaudio.c
View file @
2b8bb34c
/*
/*
Audio playback and capture library. Choice of public domain or MIT-0. See license statements at the end of this file.
Audio playback and capture library. Choice of public domain or MIT-0. See license statements at the end of this file.
miniaudio - v0.11.2
1 - 2023-11-15
miniaudio - v0.11.2
2 - TBD
David Reid - mackron@gmail.com
David Reid - mackron@gmail.com
...
@@ -12600,10 +12600,13 @@ static ma_result ma_context_create_IDirectSound__dsound(ma_context* pContext, ma
...
@@ -12600,10 +12600,13 @@ static ma_result ma_context_create_IDirectSound__dsound(ma_context* pContext, ma
}
}
/* The cooperative level must be set before doing anything else. */
/* The cooperative level must be set before doing anything else. */
hWnd = (HWND)pContext->dsound.hWnd;
if (hWnd == 0) {
hWnd = ((MA_PFN_GetForegroundWindow)pContext->win32.GetForegroundWindow)();
hWnd = ((MA_PFN_GetForegroundWindow)pContext->win32.GetForegroundWindow)();
if (hWnd == 0) {
if (hWnd == 0) {
hWnd = ((MA_PFN_GetDesktopWindow)pContext->win32.GetDesktopWindow)();
hWnd = ((MA_PFN_GetDesktopWindow)pContext->win32.GetDesktopWindow)();
}
}
}
hr = ma_IDirectSound_SetCooperativeLevel(pDirectSound, hWnd, (shareMode == ma_share_mode_exclusive) ? MA_DSSCL_EXCLUSIVE : MA_DSSCL_PRIORITY);
hr = ma_IDirectSound_SetCooperativeLevel(pDirectSound, hWnd, (shareMode == ma_share_mode_exclusive) ? MA_DSSCL_EXCLUSIVE : MA_DSSCL_PRIORITY);
if (FAILED(hr)) {
if (FAILED(hr)) {
...
@@ -13919,6 +13922,8 @@ static ma_result ma_context_init__dsound(ma_context* pContext, const ma_context_
...
@@ -13919,6 +13922,8 @@ static ma_result ma_context_init__dsound(ma_context* pContext, const ma_context_
return MA_API_NOT_FOUND;
return MA_API_NOT_FOUND;
}
}
pContext->dsound.hWnd = pConfig->dsound.hWnd;
pCallbacks->onContextInit = ma_context_init__dsound;
pCallbacks->onContextInit = ma_context_init__dsound;
pCallbacks->onContextUninit = ma_context_uninit__dsound;
pCallbacks->onContextUninit = ma_context_uninit__dsound;
pCallbacks->onContextEnumerateDevices = ma_context_enumerate_devices__dsound;
pCallbacks->onContextEnumerateDevices = ma_context_enumerate_devices__dsound;
...
@@ -16639,6 +16644,7 @@ static ma_result ma_device_stop__alsa(ma_device* pDevice)
...
@@ -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.
a small chance that our wakeupfd has not been cleared. We'll clear that out now if applicable.
*/
*/
int resultPoll;
int resultPoll;
int resultRead;
if (pDevice->type == ma_device_type_capture || pDevice->type == ma_device_type_duplex) {
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");
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[ALSA] Dropping capture device...\n");
...
@@ -16657,7 +16663,10 @@ static ma_result ma_device_stop__alsa(ma_device* pDevice)
...
@@ -16657,7 +16663,10 @@ static ma_result ma_device_stop__alsa(ma_device* pDevice)
resultPoll = poll((struct pollfd*)pDevice->alsa.pPollDescriptorsCapture, 1, 0);
resultPoll = poll((struct pollfd*)pDevice->alsa.pPollDescriptorsCapture, 1, 0);
if (resultPoll > 0) {
if (resultPoll > 0) {
ma_uint64 t;
ma_uint64 t;
read(((struct pollfd*)pDevice->alsa.pPollDescriptorsCapture)[0].fd, &t, sizeof(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);
}
}
}
}
}
...
@@ -16678,7 +16687,10 @@ static ma_result ma_device_stop__alsa(ma_device* pDevice)
...
@@ -16678,7 +16687,10 @@ static ma_result ma_device_stop__alsa(ma_device* pDevice)
resultPoll = poll((struct pollfd*)pDevice->alsa.pPollDescriptorsPlayback, 1, 0);
resultPoll = poll((struct pollfd*)pDevice->alsa.pPollDescriptorsPlayback, 1, 0);
if (resultPoll > 0) {
if (resultPoll > 0) {
ma_uint64 t;
ma_uint64 t;
read(((struct pollfd*)pDevice->alsa.pPollDescriptorsPlayback)[0].fd, &t, sizeof(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)
...
@@ -28350,7 +28362,7 @@ static ma_result ma_device_uninit__webaudio(ma_device* pDevice)
#if defined(MA_USE_AUDIO_WORKLETS)
#if defined(MA_USE_AUDIO_WORKLETS)
{
{
EM_ASM({
EM_ASM({
var device = miniaudio.get_device_by_index($0);
var device =
window.
miniaudio.get_device_by_index($0);
if (device.streamNode !== undefined) {
if (device.streamNode !== undefined) {
device.streamNode.disconnect();
device.streamNode.disconnect();
...
@@ -28365,7 +28377,7 @@ static ma_result ma_device_uninit__webaudio(ma_device* pDevice)
...
@@ -28365,7 +28377,7 @@ static ma_result ma_device_uninit__webaudio(ma_device* pDevice)
#else
#else
{
{
EM_ASM({
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. */
/* Make sure all nodes are disconnected and marked for collection. */
if (device.scriptNode !== undefined) {
if (device.scriptNode !== undefined) {
...
@@ -28392,7 +28404,7 @@ static ma_result ma_device_uninit__webaudio(ma_device* pDevice)
...
@@ -28392,7 +28404,7 @@ static ma_result ma_device_uninit__webaudio(ma_device* pDevice)
/* Clean up the device on the JS side. */
/* Clean up the device on the JS side. */
EM_ASM({
EM_ASM({
miniaudio.untrack_device_by_index($0);
window.
miniaudio.untrack_device_by_index($0);
}, pDevice->webaudio.deviceIndex);
}, pDevice->webaudio.deviceIndex);
ma_free(pDevice->webaudio.pIntermediaryBuffer, &pDevice->pContext->allocationCallbacks);
ma_free(pDevice->webaudio.pIntermediaryBuffer, &pDevice->pContext->allocationCallbacks);
...
@@ -28557,7 +28569,6 @@ static void ma_audio_worklet_processor_created__webaudio(EMSCRIPTEN_WEBAUDIO_T a
...
@@ -28557,7 +28569,6 @@ static void ma_audio_worklet_processor_created__webaudio(EMSCRIPTEN_WEBAUDIO_T a
return;
return;
}
}
pParameters->pDevice->webaudio.audioWorklet = emscripten_create_wasm_audio_worklet_node(audioContext, "miniaudio", &audioWorkletOptions, &ma_audio_worklet_process_callback__webaudio, pParameters->pDevice);
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. */
/* 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
...
@@ -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. */
/* 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);
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
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.
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
...
@@ -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. */
/* 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({
pDevice->webaudio.deviceIndex = EM_ASM_INT({
return miniaudio.track_device({
return
window.
miniaudio.track_device({
webaudio: emscriptenGetAudioObject($0),
webaudio: emscriptenGetAudioObject($0),
state: 1 /* 1 = ma_device_state_stopped */
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
...
@@ -28831,11 +28841,11 @@ static ma_result ma_device_init__webaudio(ma_device* pDevice, const ma_device_co
/* The node processing callback. */
/* The node processing callback. */
device.scriptNode.onaudioprocess = function(e) {
device.scriptNode.onaudioprocess = function(e) {
if (device.intermediaryBufferView == null || device.intermediaryBufferView.length == 0) {
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. */
/* 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. */
/* The data must be interleaved before being processed miniaudio. */
for (var iChannel = 0; iChannel < channels; iChannel += 1) {
for (var iChannel = 0; iChannel < channels; iChannel += 1) {
var inputBuffer = e.inputBuffer.getChannelData(iChannel);
var inputBuffer = e.inputBuffer.getChannelData(iChannel);
...
@@ -28849,7 +28859,7 @@ static ma_result ma_device_init__webaudio(ma_device* pDevice, const ma_device_co
...
@@ -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);
_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);
_ma_device_process_pcm_frames_playback__webaudio(pDevice, bufferSize, pIntermediaryBuffer);
for (var iChannel = 0; iChannel < e.outputBuffer.numberOfChannels; ++iChannel) {
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
...
@@ -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. */
/* 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})
navigator.mediaDevices.getUserMedia({audio:true, video:false})
.then(function(stream) {
.then(function(stream) {
device.streamNode = device.webaudio.createMediaStreamSource(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
...
@@ -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.scriptNode.connect(device.webaudio.destination);
}
}
device.pDevice = pDevice;
device.pDevice = pDevice;
return miniaudio.track_device(device);
return
window.
miniaudio.track_device(device);
}, pConfig->deviceType, channels, sampleRate, periodSizeInFrames, pDevice->webaudio.pIntermediaryBuffer, pDevice);
}, pConfig->deviceType, channels, sampleRate, periodSizeInFrames, pDevice->webaudio.pIntermediaryBuffer, pDevice);
if (deviceIndex < 0) {
if (deviceIndex < 0) {
...
@@ -28897,7 +28907,7 @@ static ma_result ma_device_init__webaudio(ma_device* pDevice, const ma_device_co
...
@@ -28897,7 +28907,7 @@ static ma_result ma_device_init__webaudio(ma_device* pDevice, const ma_device_co
pDevice->webaudio.deviceIndex = deviceIndex;
pDevice->webaudio.deviceIndex = deviceIndex;
/* Grab the sample rate from the audio context directly. */
/* 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) {
if (pDescriptorCapture != NULL) {
pDescriptorCapture->format = ma_format_f32;
pDescriptorCapture->format = ma_format_f32;
...
@@ -28927,9 +28937,9 @@ static ma_result ma_device_start__webaudio(ma_device* pDevice)
...
@@ -28927,9 +28937,9 @@ static ma_result ma_device_start__webaudio(ma_device* pDevice)
MA_ASSERT(pDevice != NULL);
MA_ASSERT(pDevice != NULL);
EM_ASM({
EM_ASM({
var device = miniaudio.get_device_by_index($0);
var device =
window.
miniaudio.get_device_by_index($0);
device.webaudio.resume();
device.webaudio.resume();
device.state = miniaudio.device_state.started;
device.state =
window.
miniaudio.device_state.started;
}, pDevice->webaudio.deviceIndex);
}, pDevice->webaudio.deviceIndex);
return MA_SUCCESS;
return MA_SUCCESS;
...
@@ -28949,9 +28959,9 @@ static ma_result ma_device_stop__webaudio(ma_device* pDevice)
...
@@ -28949,9 +28959,9 @@ static ma_result ma_device_stop__webaudio(ma_device* pDevice)
do any kind of explicit draining.
do any kind of explicit draining.
*/
*/
EM_ASM({
EM_ASM({
var device = miniaudio.get_device_by_index($0);
var device =
window.
miniaudio.get_device_by_index($0);
device.webaudio.suspend();
device.webaudio.suspend();
device.state = miniaudio.device_state.stopped;
device.state =
window.
miniaudio.device_state.stopped;
}, pDevice->webaudio.deviceIndex);
}, pDevice->webaudio.deviceIndex);
ma_device__on_notification_stopped(pDevice);
ma_device__on_notification_stopped(pDevice);
...
@@ -29010,6 +29020,7 @@ static ma_result ma_context_init__webaudio(ma_context* pContext, const ma_contex
...
@@ -29010,6 +29020,7 @@ static ma_result ma_context_init__webaudio(ma_context* pContext, const ma_contex
window.miniaudio.device_state.started = $4;
window.miniaudio.device_state.started = $4;
/* Device cache for mapping devices to indexes for JavaScript/C interop. */
/* Device cache for mapping devices to indexes for JavaScript/C interop. */
let miniaudio = window.miniaudio;
miniaudio.devices = [];
miniaudio.devices = [];
miniaudio.track_device = function(device) {
miniaudio.track_device = function(device) {
...
@@ -29061,10 +29072,10 @@ static ma_result ma_context_init__webaudio(ma_context* pContext, const ma_contex
...
@@ -29061,10 +29072,10 @@ static ma_result ma_context_init__webaudio(ma_context* pContext, const ma_contex
var device = miniaudio.devices[i];
var device = miniaudio.devices[i];
if (device != null &&
if (device != null &&
device.webaudio != null &&
device.webaudio != null &&
device.state ===
window.
miniaudio.device_state.started) {
device.state === miniaudio.device_state.started) {
device.webaudio.resume().then(() => {
device.webaudio.resume().then(() => {
Module.
_ma_device__on_notification_unlocked(device.pDevice);
_ma_device__on_notification_unlocked(device.pDevice);
},
},
(error) => {console.error("Failed to resume audiocontext", error);
(error) => {console.error("Failed to resume audiocontext", error);
});
});
extras/miniaudio_split/miniaudio.h
View file @
2b8bb34c
/*
/*
Audio playback and capture library. Choice of public domain or MIT-0. See license statements at the end of this file.
Audio playback and capture library. Choice of public domain or MIT-0. See license statements at the end of this file.
miniaudio - v0.11.2
1 - 2023-11-15
miniaudio - v0.11.2
2 - TBD
David Reid - mackron@gmail.com
David Reid - mackron@gmail.com
...
@@ -20,7 +20,7 @@ extern "C" {
...
@@ -20,7 +20,7 @@ extern "C" {
#define MA_VERSION_MAJOR 0
#define MA_VERSION_MAJOR 0
#define MA_VERSION_MINOR 11
#define MA_VERSION_MINOR 11
#define MA_VERSION_REVISION 2
1
#define MA_VERSION_REVISION 2
2
#define MA_VERSION_STRING MA_XSTRINGIFY(MA_VERSION_MAJOR) "." MA_XSTRINGIFY(MA_VERSION_MINOR) "." MA_XSTRINGIFY(MA_VERSION_REVISION)
#define MA_VERSION_STRING MA_XSTRINGIFY(MA_VERSION_MAJOR) "." MA_XSTRINGIFY(MA_VERSION_MINOR) "." MA_XSTRINGIFY(MA_VERSION_REVISION)
#if defined(_MSC_VER) && !defined(__clang__)
#if defined(_MSC_VER) && !defined(__clang__)
...
@@ -3545,6 +3545,10 @@ struct ma_context_config
...
@@ -3545,6 +3545,10 @@ struct ma_context_config
void
*
pUserData
;
void
*
pUserData
;
ma_allocation_callbacks
allocationCallbacks
;
ma_allocation_callbacks
allocationCallbacks
;
struct
struct
{
ma_handle
hWnd
;
/* HWND. Optional window handle to pass into SetCooperativeLevel(). Will default to the foreground window, and if that fails, the desktop window. */
}
dsound
;
struct
{
{
ma_bool32
useVerboseDeviceEnumeration
;
ma_bool32
useVerboseDeviceEnumeration
;
}
alsa
;
}
alsa
;
...
@@ -3633,6 +3637,7 @@ struct ma_context
...
@@ -3633,6 +3637,7 @@ struct ma_context
#ifdef MA_SUPPORT_DSOUND
#ifdef MA_SUPPORT_DSOUND
struct
struct
{
{
ma_handle
hWnd
;
/* Can be null. */
ma_handle
hDSoundDLL
;
ma_handle
hDSoundDLL
;
ma_proc
DirectSoundCreate
;
ma_proc
DirectSoundCreate
;
ma_proc
DirectSoundEnumerateA
;
ma_proc
DirectSoundEnumerateA
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment