Commit Graph

3969 Commits

Author SHA1 Message Date
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
David Reid 2bc0e14abf Minor clarifying comment. 2025-07-02 17:57:50 +10:00
Sam Tupy b348ab0155 fix assertion failure upon loading invalid sound path due to extra ma_fence_release
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.
2025-07-02 17:54:30 +10:00
David Reid 346d65091a Don't use threading or device IO in the conversion test. 2025-07-02 10:30:47 +10:00
David Reid aa75d5f8e8 Don't include pthread.h if threading is disabled. 2025-07-02 10:30:06 +10:00
David Reid 0ac5c89157 MP3: Disable SIMD when disabled by miniaudio.
This applies when MA_NO_NEON or MA_NO_SSE2 is set.

Public issue https://github.com/mackron/miniaudio/issues/997
2025-06-09 07:37:25 +10:00
Guillaume Prieur 47020e4092 Fix seek origin conversion in ma_mp3_dr_callback__seek 2025-05-19 08:34:46 +10:00
David Reid 02873ca300 Update c89atomic. 2025-05-11 06:48:51 +10:00
David Reid 11177ed19f Style and formatting changes. 2025-05-08 14:15:12 +10:00
caturria 682fad7d55 Revert accidental include change. 2025-05-08 14:04:57 +10:00
caturria 1497f5e467 Fix leaked OggVorbis_File handle when input is not vorbis. Also implements ma_libvorbis_get_length_in_pcm_frames() for the common case of an ogg file with a single bitstream. 2025-05-08 14:04:57 +10:00
David Reid 853f27ed56 Whitespace. 2025-05-08 08:01:12 +10:00
Keith 05d367eed5 CMake: remove macro and fix warnings 2025-05-08 07:11:27 +10:00
Keith 97493bdfcd CMake: support install
All Miniaudio static libraries now install their headers such that they can
still use relative paths, but external code can #include "miniaudio/miniaudio.h"

Also adds a CMake macro to simplify adding static libraries
2025-05-08 07:11:27 +10:00