Commit Graph

222 Commits

Author SHA1 Message Date
David Reid d1f34cd5db Update the audio ring buffer to use the standard config/init pattern.
This makes it consistent with everything else in the library.
2026-01-27 17:44:52 +10:00
David Reid fcd386dd87 Remove ma_audio_queue. 2026-01-27 06:17:14 +10:00
David Reid 2302e58045 API CHANGE: Rename vtable to pVTable.
This applies to `ma_data_source_config` and `ma_node_config` and makes
the naming consistent with other parts of the library.
2026-01-26 15:46:58 +10:00
David Reid 5a7bfd7c2c Update the hilo_interop example to use the new ring buffer. 2026-01-25 18:46:25 +10:00
David Reid 8a43271555 Initial work on the audio queue data source.
Public issue https://github.com/mackron/miniaudio/issues/744
2026-01-22 11:29:53 +10:00
David Reid b3f32437b8 Update an out of date comment. 2026-01-13 12:46:51 +10:00
David Reid 44b39fe097 Rename SDL2 backend source files. 2026-01-03 13:56:40 +10:00
David Reid 3df99ce51d Rename the SDL backend to SDL2.
This distinction is needed because we'll be doing an SDL3 backend in the
future.
2026-01-03 13:50:48 +10:00
David Reid cc4db76c26 Minor update to documentation for the single-threaded example. 2025-12-30 09:32:11 +10:00
David Reid a16756ec3b Add an example for single-threaded mode. 2025-12-30 09:26:38 +10:00
David Reid b37530fdd6 Merge branch 'dev' into dev-0.12 2025-08-21 14:34:11 +10:00
David Reid b1893aa8f1 Minor C89 compatibility fix. 2025-08-21 14:33:52 +10:00
David Reid df4baf8d40 Fix some errors. 2025-08-21 14:24:21 +10:00
David Reid 21237008df Silence some errors in the Steam Audio headers. 2025-08-21 14:23:31 +10:00
David Reid 26a1566cb2 Fix some errors. 2025-08-21 14:09:22 +10:00
David Reid 3191f957c3 Update simple_enumeration to show default devices. 2025-07-16 19:09:35 +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 ab76f7a27d Fix a typo. 2025-07-06 10:20:52 +10:00
David Reid 1ab91b05c0 Delete a duplicate example. 2025-03-05 14:58:59 +10:00
David Reid 569edb8436 Merge branch 'dev' into dev-0.12 2025-02-25 06:49:01 +10:00
David Reid 46d8abf3de Add teardown to custom_decoder_engine. 2025-02-25 06:48:34 +10:00
David Reid c5dda3c769 Merge branch 'dev' into dev-0.12 2025-02-24 16:35:53 +10:00
David Reid 2a79d124c1 Fix some bugs in the resource_manager_advanced example. 2025-02-24 12:39:42 +10:00
David Reid 17b8dbf948 Remove an invalid comment from some examples. 2025-02-24 10:03:21 +10:00
David Reid 7a250aa9f9 Merge branch 'dev' into dev-0.12 2025-02-23 12:55:40 +10:00
David Reid 8c52072f43 Remove const qualifiers from decoding backend vtable arrays. 2025-02-23 12:54:19 +10:00
David Reid 60c0b9eeba Merge branch 'dev' into dev-0.12 2025-02-22 13:09:30 +10:00
David Reid 1fbad32949 Stop using MINIAUDIO_IMPLEMENTATION in examples. 2025-02-22 13:09:11 +10:00
David Reid 3541d1b8cc Merge branch 'dev' into dev-0.12 2025-02-22 12:06:45 +10:00
David Reid c13504629e Minor update to custom_backend example. 2025-02-22 09:35:16 +10:00
David Reid 562b3483d1 Merge branch 'dev' into dev-0.12 2025-02-21 20:21:02 +10:00
David Reid e3151f2df1 Silence an unreachable code warning with MSVC. 2025-02-19 12:32:12 +10:00
David Reid 0ea924ae7a Merge branch 'dev' into dev-0.12 2025-02-19 12:09:13 +10:00
David Reid 8ad250ccf6 Updates to custom decoders. 2025-02-19 12:02:37 +10:00
David Reid eee86a0ae1 Fix the C++ build for some examples. 2025-02-19 08:28:01 +10:00
David Reid 724dac6af1 Fix compilation errors. 2025-02-18 18:26:07 +10:00
David Reid 391cca6e79 Merge branch 'dev' into dev-0.12 2025-02-18 18:03:01 +10:00
David Reid 46788d59a8 Rework the libvorbis and libopus custom decoders.
These decoders have been moved into their own subfolders under the
extras/decoders folder:

  extras/decoders/libvorbis
  extras/decoders/libopus

In addition to being relocated, they have also been split into separate
.c/h pairs. They now work like a more conventional library. The
implementation of these libraries have also been decoupled from the
miniaudio implementation which means they depend only on the header
section of miniaudio.h now.

With this change the custom_decoder and custom_decoder_engine examples
have been updated. To compile these you now need to link in the
miniaudio_libvorbis.c and miniaudio_libopus.c files via your build
tool. For your own code, you can still include the .c files directly
into your code if you want to compile as a single translation unit.
2025-02-17 16:57:47 +10:00
David Reid 01d6297bec Fix some warnings with some more examples. 2025-02-17 16:52:54 +10:00
David Reid de5f370d09 Fix some warnings with examples. 2025-02-17 16:01:19 +10:00
David Reid ca3ecd9086 Merge branch 'dev' into dev-0.12 2025-02-08 07:21:38 +10:00
David Reid fc905ec97f Add simple_spatialization example. 2025-01-11 18:42:34 +10:00
David Reid 33499941ae Merge branch 'dev' into dev-0.12 2025-01-11 17:03:23 +10:00
David Reid fcddfe6204 Update ma_pcm_rb data source implementation.
The data source implementation of a ma_pcm_rb could possibly return a
frame count of 0 which would in turn result in
ma_data_source_read_pcm_frames() returning MA_AT_END which does not
make sense for a ring buffer since it has no notion of an end.
2025-01-11 16:30:15 +10:00
David Reid f581a23f30 Fix a comment. 2024-03-01 09:35:01 +10:00
David Reid 5a0d1ad433 Merge branch 'dev' into dev-0.12 2024-03-01 08:37:16 +10:00
RainRat 030b9554c2 fix typos 2024-03-01 08:35:45 +10:00
David Reid f07c4cd3a1 Update engine_custom_decoder example. 2024-03-01 07:55:41 +10:00
David Reid d10a287f23 Rename custom_decoder_engine example to engine_custom_decoder.
This just makes it easier to find engine related examples in the
example list.
2024-03-01 07:30:08 +10:00