Commit Graph

3982 Commits

Author SHA1 Message Date
David Reid d1955c29a9 Improvements to the OpenSL|ES backend.
* Some untested placeholder code has been removed for non-Android
    builds. This was adding unnecessary complexity.
  * Device enumeration now includes detailed info.
2025-07-18 12:20:08 +10:00
David Reid 6ab1cc83cd AAudio: Fix a bug with device enumeration. 2025-07-18 12:18:50 +10:00
David Reid 3f9dd6ddd0 AAudio: Extract detailed device information from enumeration. 2025-07-18 10:21:27 +10:00
David Reid 55564ede75 Fix Android build. 2025-07-18 10:11:57 +10:00
David Reid 7b887e0ca5 Update sndio backend to included detailed device info from enumeration. 2025-07-18 09:22:06 +10:00
David Reid c2b45b58af Improvements to the NetBSD audio(4) backend.
* Device enumeration will now mark appropriate devices as default.
  * The onContextGetDeviceInfo backend callback has been removed so that
    all device info is retrieved from the enumeration process.
2025-07-18 08:25:16 +10:00
David Reid c468230e8f Enable the OSS backend on Linux.
This is the lowest priority stock backend for Linux.
2025-07-17 19:09:30 +10:00
David Reid 7b157815ab Fix ALSA build on very old compilers. 2025-07-17 15:08:58 +10:00
David Reid 291442cd6c Update external/fs. 2025-07-17 15:08:29 +10:00
David Reid d8236f9d22 Improvements to the OSS backend.
These changes add initial support for OSSv3. Where this is of particular
note is Linux which never updated to OSSv4. This compiles on Linux, but
I have not yet tested this at run time. Future commits will enable the
OSS backend for Linux which will be useful for getting miniaudio working
on very old versions of Linux.
2025-07-17 11:13:29 +10:00
David Reid 552ef533d4 Make the onDeviceGetDeviceInfo backend callback optional.
In this case, device information will be retrieved through device
enumeration. This callback will eventually be removed entirely once all
backends have been updated.
2025-07-17 10:53:45 +10:00
David Reid 3191f957c3 Update simple_enumeration to show default devices. 2025-07-16 19:09:35 +10:00
David Reid a0402c6f1f Fix a compilation error. 2025-07-16 14:37:03 +10:00
David Reid 0acd0a4b78 Fix memory leaks. 2025-07-15 15:38:51 +10:00
David Reid f0ff4b6de3 API CHANGE: Remove ma_performance_profile.
This also removes the `performanceProfile` config option from
`ma_device_config`. Increase the period size if you want to be more
conservative.

Backends that have their own notion of a "latency hint" or the like will
have those options exposed via a backend-specific configuration option.
2025-07-15 14:35:24 +10:00
David Reid a014181372 Update fs. 2025-07-15 14:31:56 +10:00
David Reid 27b593c2d2 API CHANGE: Rename ma_device_state to ma_device_status.
This renames the `ma_device_state` enum to `ma_device_status`, and also
renames `ma_device_get_state()` to `ma_device_get_status()`.

The reason for this change is that the new backend system uses the
notion of a "state" for backend-specific state for devices. This change
is just to avoid ambiguity between the two concepts.
2025-07-15 12:09:39 +10:00
David Reid 94b07291fc Remove old code from some earlier experiments. 2025-07-15 11:57:06 +10:00
David Reid 5b3bc33425 WASAPI: Move some code out of the header section. 2025-07-15 11:50:45 +10:00
David Reid 147c6620cb API CHANGE: Remove ma_backend.
This is from the old backend system and is no longer used.
2025-07-15 11:43:57 +10:00
David Reid 24a073eab3 API CHANGE: Remove ma_is_loopback_supported().
Use `ma_get_device_backend_info()` instead. Inspect the
`isLoopbackSupported` member of `ma_device_backend_info`.
2025-07-15 11:38:06 +10:00
David Reid 714afe2c42 API CHANGE: Remove ma_context_is_loopback_supported().
Use `ma_context_get_device_info()` instead. Inspect the
`isLoopbackSupported` member of `ma_device_backend_info`.
2025-07-15 11:33:35 +10:00
David Reid 3df76aa05e Add isLoopbackSupported to ma_device_backend_info. 2025-07-15 11:31:27 +10:00
David Reid 0c7be93f6f API CHANGE: Remove ma_is_backend_enabled() and ma_get_enabled_backends()
For determining if a backend is enabled, just compare it to NULL:

    if (ma_device_backend_wasapi != NULL) {
        /* Enabled */
    } else {
        /* Disabled */
    }

If you need to list available backends, just keep track of a list of
backends that you care about, and then check which ones are null.
2025-07-15 11:25:11 +10:00
David Reid d89e7c8e5d Add back some SDK version checks for Android. 2025-07-15 10:51:51 +10:00
David Reid 9f171142cf API CHANGE: Remove ma_get_backend_from_name().
With the new pluggable backend system, this function no longer makes
sense. If you need this, you should manage it yourself.
2025-07-15 10:23:40 +10:00
David Reid a432e4db4c API CHANGE: Remove ma_get_backend_name().
Use `ma_get_device_backend_info()` or `ma_context_get_backend_info()`
instead.
2025-07-15 10:19:28 +10:00
David Reid fabab10843 Remove the backend member from ma_context.
This is a legacy from the old backend system.
2025-07-15 10:11:18 +10:00
David Reid d1643b3487 Add ma_get_device_backend_info() and ma_context_get_backend_info().
These functions are used to retrieve basic information about the
backend, such as the name. Useful for logging and UI.
2025-07-15 10:10:29 +10:00
David Reid c0336335a6 Make some functions private. 2025-07-15 08:50:07 +10:00
David Reid 51715474d7 CMake: Improve handling of dl. 2025-07-15 08:12:36 +10:00
David Reid a4072246c5 Rename some variables and try silencing a warning. 2025-07-15 07:21:30 +10:00
David Reid 180c7237f8 Fix a warning. 2025-07-15 07:21:04 +10:00
David Reid 1e6c01f31d Fix CMake script for NetBSD. 2025-07-15 07:20:52 +10:00
David Reid 96eea50e7d Remove references to the custom backend from the CMake script. 2025-07-15 06:59:55 +10:00
David Reid 2833ccf4e7 Whitespace. 2025-07-15 06:59:36 +10:00
David Reid ebec10b068 Add early PipeWire backend.
This is incomplete.
2025-07-15 06:59:19 +10:00
David Reid fd37406086 Update build instructions for Emscripten. 2025-07-15 06:53:52 +10:00
David Reid b9f6d99217 Rename some variables for consistency. 2025-07-15 06:50:22 +10:00
David Reid 8890eac6aa One Big Beautiful Commit with refactoring to the device backend system.
This includes API changes that affect custom backends.

`ma_backend_callbacks` has been renamed to `ma_device_backend_vtable`.
The reason for this change is to to be consistent with the naming
convention used in other parts of the library. In addition, using the
term "device backend" rather than just "backend" removes ambiguity with
decoding backends.

A change has been made to the way backends manage their internal state,
and some functions in the vtable have been updated to reflect this.
Previously internal state for stock backends were located directly in
the `ma_device` structure. This works fine if stock backends are the
only backends to be concerned about, but it falls apart when you need
to consider how to manage the internal state of custom backends since
they cannot modify the `ma_device` structure. In order to simplify and
unify state management between stock and custom backends, the decision
was made to change the backend system such that backends now manage
their own internal state.

When the context is initialized with `onContextInit`, the backend must
now allocate an internal state object and output a pointer to it via
an output parameter. Typically you would do something like this:

    ma_result custom_context_init(..., void** ppContextState)
    {
        ctx_state_t* state = malloc(...);

        ...

        *ppContextState = state;
        return MA_SUCCESS;
    }

miniaudio will store a pointer to the state object internally. When you
need to access this later in other backend callbacks, you can retrieve
it straight from the context with `ma_context_get_backend_state()`:

    state = (ctx_state_t*)ma_context_get_backend_state(pContext);

The same idea applies to devices and `onDeviceInit`. You can use
`ma_device_get_backend_state()` to get a pointer to the internal state
object.

When a context and device is initialized, backend-specific
configurations can be supplied. The way these configs are provided to
`onContextInit` and `onDeviceInit` has been changed. Previously, these
callbacks would take a `ma_context/device_config` object. These have
been replaced with a `const void*` which points to a backend-specific
config object which is defined by the backend. All stock backends have
their own backend-specific config object:

    struct ma_context_config_wasapi
    struct ma_context_config_pulseaudio
    etc.

    struct ma_device_config_wasapi
    struct ma_device_config_pulseaudio
    etc.

You can cast the config object inside the relevant callbacks:

    ma_result custom_context_init(..., const void* pBackendConfig, ...)
    {
        ctx_config_t* pCustomConfig = (ctx_config_t*)pBackendConfig;
    }

The backend itself defines whether or not a config is required. None of
the stock backends require a config. If the config is NULL, it'll use
defaults. It's recommended custom backends follow this convention.

In addition to the above, `onContextUninit` and `onDeviceUninit` have
been updated to return void instead of `ma_result`.

The last change to the backend vtable is a new callback called
`onBackendInfo`. This is used to fill the `ma_device_backend_info`
structure.

In addition to the backend vtable, some changes have been made to the
public API to make it much easier to support plugging in custom
backends.

Previously, plugging in more than one custom backend was a complete
mess. It was possible, but you had to use a stupid wrapper thing to
make it work, and you had no control over prioritization. The entire
thing was just aweful, so it's now been stripped out and replaced with
a brand new system.

When a context or device is initialized, it is done so with a config
which is standard across the entire library. A complication to this is
that backends can sometimes require their own backend-specific configs.
But since miniaudio cannot possibly know about custom backends, it
cannot put their config options inside `ma_context/device_config`. The
functions for initializing a context and device have been updated to
allow plugging in backend-specific configs.

When initializing a context, instead of passing in an array of
`ma_backend` enums, an array of `ma_device_backend_config` objects is
passed in instead. This object has two members: A pointer to a backend
vtable, and a pointer to a config object. It can be initialized
something like this:

    ma_context_config_custom customContextConfig;
    ... initialize the custom backend config if necessary ...

    ma_device_backend_config backends[] =
    {
        { ma_device_backend_custom,     &customContextConfig },
        { ma_device_backend_wasapi,     NULL },
        { ma_device_backend_pulseaudio, NULL }
    };

    ma_context_init(backends, backendCount, ...);

Here `ma_device_backend_custom` is our custom backend. You can see how
the config is mapped to the backend. For stock backends (WASAPI and
PulseAudio in this example), you can pass in NULL and just set the
relevant config options straight in `ma_context_config` exactly how it
was done before:

    ma_context_config contextConfig = ma_context_config_init();
    contextConfig.pulseaudio.pApplicationName = "My App";

Here we are just using the standard `ma_context_config` object for
configuring the stock PulseAudio backend. This is possible for all
stock backends, but for custom backends an explicit config object will
be required. You can still use a separate explicit config object for
stock backends if you prefer that style:

    ma_context_config_pulseaudio paContextConfig;
    paContextConfig = ma_context_config_pulseaudio_init();
    paContextConfig.pApplicationName = "My App";

    ma_device_backend_config backends[] =
    {
        { ma_device_backend_pulseaudio, &paContextConfig }
    };

Note that if you do not use custom backends, you can still pass in NULL
for the backends in which case defaults will be used like how it's
always worked in the past.

As with contexts, devices can also have their own backend-specific
configs associated with them. These work exactly the same way, except
these configs are passed into the main `ma_device_config` object. (A
future commit may make this consistent between contexts and devices).

    ma_device_backend_config deviceBackendConfigs[] =
    {
        { ma_device_backend_custom, &customDeviceConfig }
    };

    deviceConfig.pBackendConfigs    = deviceBackendConfigs;
    deviceConfig.backendConfigCount = backendCount;

    ma_device_init(&deviceConfig, &device);

This commit is just the start of many backend related changes. Future
commits will be cleaning up a lot of residual code from the old system,
such as removing `ma_backend`.
2025-07-14 18:05:55 +10:00
David Reid cdfd219377 Clean up some old code. 2025-07-06 11:46:29 +10:00
David Reid aa1cd76b96 Add a new device backend vtable in preparation for backend reworking. 2025-07-06 11:41:29 +10:00
David Reid ab76f7a27d Fix a typo. 2025-07-06 10:20:52 +10:00
David Reid 9bce75d858 Add some some experimental code for a new backend architecture. 2025-07-06 10:19:21 +10:00
David Reid 636fe28d86 API CHANGE: Remove the pContext parameter from device enum callback.
This is part of some future work to decouple `ma_context` and
`ma_device` from backends. If you need access to the context for some
reason, you can pass it in via the user data.
2025-07-04 16:24:22 +10:00
David Reid 017eae73ac Fix compilation of libopus and libvorbis decoders. 2025-07-04 11:37:01 +10:00
David Reid 57423c6cea API CHANGE: Rename seek origin enums.
ma_seek_origin_start   > MA_SEEK_SET
  ma_seek_origin_current > MA_SEEK_CUR
  ma_seek_origin_end     > MA_SEEK_END
2025-07-04 11:23:29 +10:00
David Reid 515e7fc2d3 Merge branch 'dev' into dev-0.12 2025-07-04 11:14:38 +10:00
David Reid e54336996d Update dr_libs. 2025-07-04 11:13:40 +10:00
David Reid 1c7967fc88 PulseAudio: Fix a crash if the requested channel count is too high. 2025-07-04 06:37:08 +10:00