Commit Graph

271 Commits

Author SHA1 Message Date
David Reid df0358c870 Merge branch 'dev' into dev-0.12 2025-08-21 14:09:02 +10:00
David Reid 587bd83cbb Update fs and fix some build errors with -std=c89. 2025-08-21 13:57:57 +10:00
David Reid f6453a1418 Add ma_get_stock_device_backends().
This commit many warnings when compiling as C89.
2025-08-21 07:27:42 +10:00
David Reid ba35370f74 Merge branch 'dev' into dev-0.12 2025-08-19 08:32:35 +10:00
David Reid 6e1cd41622 tests: fix memory leak in filtering and generation tests 2025-08-19 08:26:22 +10:00
David Reid 0923a484ee Merge branch 'dev' into dev-0.12 2025-08-07 18:00:40 +10:00
David Reid 78cdb9c1cb Add batch file for setting up DJGPP environment. 2025-08-07 17:44:55 +10:00
David Reid 110ded6fc6 Include the SDL2 and PipeWire backends in the deviceio test. 2025-07-21 16:11:31 +10:00
David Reid ff73bd7af6 Remove new lines from log messages. 2025-07-21 12:57:48 +10:00
David Reid 5b21699ba9 Fix Emscripten test. 2025-07-21 09:13:53 +10:00
David Reid 47f9287ac8 Don't unnecessarily call ma_device_get_info() in deviceio test. 2025-07-20 16:20:41 +10:00
David Reid a014181372 Update fs. 2025-07-15 14:31:56 +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 180c7237f8 Fix a warning. 2025-07-15 07:21:04 +10:00
David Reid fd37406086 Update build instructions for Emscripten. 2025-07-15 06:53:52 +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 346d65091a Don't use threading or device IO in the conversion test. 2025-07-02 10:30:47 +10:00
David Reid c92e662de7 Simplify some test code. 2025-02-23 18:22:17 +10:00
David Reid a497466f75 Add basic testing app for Android.
This is only very basic right now. Will be expanded on later.
2025-02-22 18:54:45 +10:00
David Reid e1f5ed4f79 Rename some more test source files. 2025-02-22 13:00:06 +10:00
David Reid ed5cda309c Simplify the conversion test. 2025-02-22 12:50:00 +10:00
David Reid 3435aafb34 Use a simplified naming scheme for tests. 2025-02-22 12:29:56 +10:00
David Reid deafb7e96f Add debugging sandbox for the purpose of debugging miniaudio. 2025-02-22 09:44:03 +10:00
David Reid e08c1303ef Fix a bug with the deviceio test. 2025-02-19 09:43:51 +10:00
David Reid 22a5c65c94 Update tests. 2025-02-18 17:46:57 +10:00
David Reid cff683a1b1 Add a non-interactive mode for the deviceio test. 2025-02-18 17:30:59 +10:00
David Reid cf9371748a Fix compilation warnings with some tests. 2025-02-17 18:15:22 +10:00
David Reid 059a25d9c5 Minor update to tests build instructions for Emscripten. 2025-01-04 09:05:39 +10:00
David Reid bdab2fc3e0 Remove an accidental change to the deviceio test. 2024-01-08 12:30:04 +10:00
David Reid eb0ce6f1a5 Fix an error when dynamically linking when forcing the UWP build.
This also fixes a possible crash during initialization due to leaving a
thread running after early termination of the initialization routine.
2023-11-04 08:43:16 +10:00
David Reid bdf9a5554b Update the deviceio test. 2023-09-10 07:26:09 +10:00
David Reid 6e6823d9e4 Update deviceio test. 2023-08-31 18:30:04 +10:00
David Reid d4fd8411c4 Update Emscripten test. 2023-08-06 15:39:54 +10:00
David Reid 810cdc2380 Improvements to Audio Worklets support for Web Audio.
Public issue https://github.com/mackron/miniaudio/issues/597
2023-08-05 17:02:26 +10:00
David Reid 14be2bd394 Fix some long out of date tests. 2023-05-22 18:20:21 +10:00
David Reid a8f3cb857e Fix compilation errors with MA_NO_DEVICE_IO. 2023-05-22 18:09:04 +10:00
David Reid 9bb3467b74 Revert an accidental change. 2023-03-18 09:30:13 +10:00
David Reid 4da843bab6 Remove a dependency on a system header and change alignas to _Alignas. 2023-03-17 15:38:07 +10:00
David Reid 6132b5d4fe Update tests readme regarding the Emscripten build. 2023-03-16 12:29:15 +10:00
David Reid bfd66ab4d2 Add a very simple Emscripten-specific test.
This will be expanded on later to be a lot more complete.
2023-02-28 11:24:58 +10:00
David Reid 922b58463c Introduce a new device notification system.
This replaces the stop callback. The new callback supports different
event types, not all of which are supported on all backends.

This commit also fixes a bug where the stop callback is not fired.

Public issue https://github.com/mackron/miniaudio/issues/351
2021-12-28 19:35:05 +10:00
David Reid 46a062e149 Add ma_device_get_name(). 2021-12-27 09:49:52 +10:00
David Reid 26db06adca Update device IO test. 2021-10-10 20:07:36 +10:00
David Reid 61b95779c2 Fix line spacing in test. 2021-08-05 20:47:50 +10:00
David Reid 4bcf1931e5 Remove dependency on MA_MAX_CHANNELS from ma_noise. 2021-08-05 20:12:13 +10:00
David Reid d92c2016ad Remove some debugging code that was accidentally committed. 2020-12-26 18:05:08 +10:00
David Reid 929e70a544 Fix some static analaysis warnings. 2020-12-02 17:43:23 +10:00
David Reid 03794d9143 Clean up the deviceio test. 2020-11-08 19:26:04 +10:00
David Reid baf6a222e5 Make the isDefault property of ma_device_info public.
Public issue https://github.com/mackron/miniaudio/issues/126
2020-11-04 21:56:32 +10:00
David Reid f6800b423a Minor change to the deviceio test. 2020-11-01 21:11:23 +10:00