This disables the WASAPI, DirectSound and WinMM backends which means
you will not get any actual audio output working. An Xbox backend will
need to come later. The main purpose of this commit is to get the main
library compiling.
The main complication arises from the fact that both _WIN32 and
_MSC_VER are defined which makes miniaudio think it's using a normal
desktop Windows build. In practice it mostly works, but there's a few
things needing to be changed specifically for NXDK:
- `fopen_s()` is not a thing with NXDK. It always uses `fopen()`.
- There is no `_wfopen()`, nor `wcsrtombs()`, so attempting to open
a file from a wide character string will fail.
- There is also no `CreateFileW()`, so this code path will also
result in an error if you attempt to open a file from a wide
character path.
- `CoInitialize()` is not a thing with NXDK and has therefore been
excluded from the build.
- `GetFileInformationByHandle()` does not exist, and neither does
`struct stat` or `stat()`. Since the only file information miniaudio
attempts to retrieve is the file size, I've implemented a fall back
which uses the seek/tell/seek pattern when info retrieval is
unavailable.
- A fall back has been implemented for comparing wide character path
extensions which performs a case-sensitive compare instead. This
means that if you are using wide character paths, miniaudio will not
detect an extension like "wav" and "WAV" as the same thing. This
might be made more robust later if there is enough demand.
Public issue https://github.com/mackron/miniaudio/issues/1023
Harmless warning on FreeBSD 14.2,
https://cirrus-ci.com/task/4700955851096064?logs=build#L44
```
../subprojects/miniaudio-0.11.22/miniaudio.h:36997:36: warning: a
function declaration without a prototype is deprecated in all versions
of C [-Wstrict-prototypes]
36997 | static int ma_open_temp_device__oss()
| ^
| void
```
In ma_resource_manager_data_buffer_node_acquire_critical_section, a job which releases already acquired fences is either processed or posted based on MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_WAIT_INIT. However on job post or process failure, the fences were being unconditionally released.
This commit moves the fence releases in acquire_critical_section down into a nested branch which only executes if MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_WAIT_INIT is not set, causing the fence release to take place only if the job failed to post while relying on the job itself to release the fences if it processes rather than causing a duplicate ma_fence_release and thus an eventual assertion failure.
My understanding is that "pause" was introduced with the Pentium 4 and
assembles to opcode F390 which is the same as "rep; nop". I believe this
should be backwards compatible.
Using "pause" here introduces an compilation error when targeting
architectures older than Pentium 4.
These were undefined when linking with the -static flag on:
1. Alpine Linux v3.21 x86_64
2. Debian GNU/Linux 12 (bookworm) aarch64
In both cases I had to manually compile alsa-lib as a static library
because the systems have only .so versions. I did it with:
cd path/to/alsa-libs
./gitcompile static
<this will create alsa-libs/src/.libs/libasound.a>
Tested with alsa-libs 1.12.2 and 1.12.3.
It's possible to reproduce the errors like this:
clang -static -DMA_NO_RUNTIME_LINKING -DMA_ENABLE_ONLY_SPECIFIC_BACKENDS -DMA_ENABLE_ALSA -DMA_DEBUG_OUTPUT -Wall -Wextra -g3 simple_playback_sine.c -o build/miniwave -fcolor-diagnostics -ferror-limit=2 -fuse-ld=lld -I../
-L/home/antharas/code/alsa-lib/src/.libs/ -lasound
However, even though it compiles I can't verify that everything works.
1. Alpine has musl which doesn't support runtime linking when
compiling with -static. So even though I disabled it for
miniaudio.h, libasound.a itself uses dlopen on
libasound_module_pcm_pipewire.so.
2. Debian uses glibc so it supports it but fails because my machine is
a VPS that doesn't have a soundcard.
No big deal, I don't really need to statically link, it was just
something I stumbled upon.
Also these are currently unused:
_snd_pcm_hw_params_set_rate_minmax
ma_timer_init
ma_timer_get_time_in_seconds
ma_device__on_notification_rerouted