Commit Graph

292 Commits

Author SHA1 Message Date
David Reid 276dd4419d Fix some errors with the PipeWire backend. 2025-07-21 16:08:52 +10:00
David Reid de31f9ea49 Fix warnings in the PipeWire backend with GCC. 2025-07-21 14:07:24 +10:00
David Reid fa4107ae95 API CHANGE: Remove the onContextGetDeviceInfo backend callback.
Device information retrieval is now implemented in terms of device
enumeration. Backends should now return any information that would have
been returned from `onContextGetDeviceInfo` straight from
`onContextEnumerateDevices` instead.
2025-07-21 11:47:14 +10:00
David Reid 2b81f75cca API CHANGE: Change return type of device enumeration callback.
The callback passed into `ma_context_enumerate_devices()` would
previously return a boolean, with true telling miniaudio to continue
enumeration, and false to abort. This got a bit confusing to read at
times, so I've decided to make this more explicit.

The new return type is an enum called `ma_device_enumeration_result`.
Instead of returning true to continue enumeration, the new return value
is `MA_DEVICE_ENUMERATION_CONTINUE`. Similarly, instead of returning
false to abort enumeration, `MA_DEVICE_ENUMERATION_ABORT` should be
returned instead.
2025-07-21 11:33:15 +10:00
David Reid 5d86a6ef82 SDL: Include format information in device enumeration. 2025-07-21 10:08:15 +10:00
David Reid 8bb2b1ae80 Update to the PipeWire backend. 2025-07-18 19:16:50 +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 a4072246c5 Rename some variables and try silencing a warning. 2025-07-15 07:21:30 +10:00
David Reid ebec10b068 Add early PipeWire backend.
This is incomplete.
2025-07-15 06:59:19 +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 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 515e7fc2d3 Merge branch 'dev' into dev-0.12 2025-07-04 11:14:38 +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 c5dda3c769 Merge branch 'dev' into dev-0.12 2025-02-24 16:35:53 +10:00
David Reid 350784a946 Version 0.11.22 2025-02-24 16:31:42 +10:00
David Reid e79e35a5ef Fix compilation errors. 2025-02-23 13:08:56 +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 b6184fa2a0 Fix some Wnewline-eof warnings. 2025-02-23 12:11:29 +10:00
David Reid 9ed0a7c8ed Merge branch 'dev' into dev-0.12 2025-02-22 14:37:15 +10:00
David Reid 37b95f0f42 Remove unnecessary example.
The delay node is demonstrated in the engine_effects example.
2025-02-22 14:36:46 +10:00
David Reid 7fb5ef188f Merge branch 'dev' into dev-0.12 2025-02-22 14:26:03 +10:00
David Reid 9f10bc7540 Improvements to the build system for extra nodes.
With this change, nodes in the extras folder can now be compiled as a
conventional library.
2025-02-22 14:25:45 +10:00
David Reid 562b3483d1 Merge branch 'dev' into dev-0.12 2025-02-21 20:21:02 +10:00
David Reid ff66923b9a Fix a compilation warning. 2025-02-19 18:05:53 +10:00
David Reid abb81fe95c Fix a warning in miniaudio_libvorbis. 2025-02-19 12:31:48 +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 48ac10d1e1 Fix a C++ compilation error. 2025-02-18 18:41:10 +10:00
Edoardo Lolletti 4b4349af52 Fix miniaudio_libvorbis.h compilation as c++ 2025-02-18 18:39:26 +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 640d70c307 Add deprecation notice to old libopus and libvorbis custom decoders. 2025-02-17 18:14:40 +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 ca3ecd9086 Merge branch 'dev' into dev-0.12 2025-02-08 07:21:38 +10:00
David Reid 14a455143f Version control some osaudio files. 2025-01-18 14:20:13 +10:00
David Reid 22489aeff1 Merge branch 'dev' into dev-0.12 2025-01-06 08:59:30 +10:00
RainRat 3db49afa5b revert unneeded changes per request 2024-04-28 15:17:11 +10:00
RainRat aa98e1c493 fix typos 2024-04-28 15:17:11 +10:00
RainRat 3ba0595c6a fix typos 2024-04-11 12:40:39 +10:00
RainRat 4bc18bba5a revert unneeded changes per request 2024-04-11 12:40:39 +10:00
RainRat 26ce355703 fix typos 2024-04-11 12:40:39 +10:00
David Reid 5a0d1ad433 Merge branch 'dev' into dev-0.12 2024-03-01 08:37:16 +10:00
RainRat 2618c21415 revert unneeded changes per request 2024-03-01 08:35:45 +10:00
RainRat 030b9554c2 fix typos 2024-03-01 08:35:45 +10:00
David Reid ff0a53fa6f Implement onGetEncodingFormat for libvorbis and libopus decoders. 2024-02-29 20:45:19 +10:00
David Reid 991ae301e4 Remove some unused functions. 2024-02-29 20:35:56 +10:00