Commit Graph

25 Commits

Author SHA1 Message Date
David Reid 15da9bd7ff API CHANGE: Add onProp callback to ma_data_source_vtable.
A new callback called `onProp` has been added to
`ma_data_source_vtable`. This replaces the following callbacks:

    onGetDataFormat
    onGetCursor
    onGetLength
    onSetLooping

This new callback is for retrieving and setting various properties
relating to the data source. It takes a `prop` parameter which is an ID
for the property being handled, and a `void*` pointer for
property-specific data.

Typically onProp implementations would discriminate on the property type
using a switch. The example below shows how to handle the old callbacks:

    switch (prop)
    {
        // Replaces onGetDataFormat (format/channels/rate).
        case MA_DATA_SOURCE_GET_DATA_SOURCE:
        {
            ma_data_source_data_format* pDataFormat =
                (ma_data_source_data_format*)pData;
            pDataFormat->format     = pCustomDataSource->format;
            pDataFormat->channels   = pCustomDataSource->channels;
            pDataFormat->sampleRate = pCustomDataSource->sampleRate;

            return MA_SUCCESS;
        }

        // Replaces onGetDataFormat (channel map)
        case MA_DATA_SOURCE_GET_CHANNEL_MAP:
        {
            ma_channel_map_init_standard(
                ma_standard_channel_map_default,
                (ma_channel*)pData,
                MA_MAX_CHANNELS,
                pCustomDataSource->channels);

            return MA_SUCCESS;
        }

        // Replaces onGetCursor
        case MA_DATA_SOURCE_GET_CURSOR:
        {
            *((ma_uint64*)pData) = pCustomDataSource->cursor;
            return MA_SUCCESS;
        }

        // Replaces onGetLength
        case MA_DATA_SOURCE_GET_LENGTH:
        {
            *((ma_uint64*)pData) = pCustomDataSource->length;
            return MA_SUCCESS;
        }

        // Replaces onSetLooping
        case MA_DATA_SOURCE_SET_LOOPING:
        {
            pCustomDataSource->isLooping = *((ma_bool32*)pData);
            return MA_SUCCESS;
        }

        // Mandatory when MA_DATA_SOURCE_SET_LOOPING is implemented.
        case MA_DATA_SOURCE_GET_LOOPING:
        {
            *((ma_bool32*)pData) = pCustomDataSource->isLooping;
            return MA_SUCCESS;
        }

        // Return MA_NOT_IMPLEMENTED for any ignored properties.
        default: return MA_NOT_IMPLEMENTED;
    }

Note how the format/channels/rate and channel map properties have been
split across two separate properties, `MA_DATA_SOURCE_GET_DATA_SOURCE`
and `MA_DATA_SOURCE_GET_CHANNEL_MAP`. Along with this change, the
channel map parameters have been removed from
`ma_data_source_get_data_format()` and a new function called
`ma_data_source_get_channel_map()` has been added.

New properties have also been added for handling ranges and loop points.
This allows the data source implementation itself to handle it rather
than miniaudio doing it at a higher level. Where this is useful is if
your data source is a wrapper around another data source and you want to
route ranges and loop points to the internal data source.

The reason for this change is that it allows for properties to be added
without having to break the build due to yet another callback being
added. It also hides away the more niche properties that the majority of
data sources do not care about. For example, rarely does a data source
need to handle the `onSetLooping` callback, yet every data source needed
to add a `NULL` entry to their vtables just for this one extremely niche
property.

See documentation for further details.

Tag: release-notes
Tag: api-change
2026-05-02 15:31:09 +10:00
David Reid ab15b24065 API CHANGE: Remove the flags member from ma_data_source_vtable. 2026-04-29 11:30:27 +10:00
David Reid a9043ba26d API CHANGE: Add an onCopy callback to ma_data_source_vtable.
This is used for making a copy of a data source.

Data sources are not required to support copying, in which case this
callback can be set to NULL, or it can return MA_NOT_IMPLEMENTED.

This commit just sets up the infrastructure. As of this commit, no data
sources actually implement this, however future commits will be
introducing support in stages.
2026-04-29 07:33:50 +10:00
David Reid 137298734e API CHANGE: Add an onSizeof callback to ma_data_source_vtable.
This should return the size of the implementations struct. For example,
`ma_decoder` would return `sizeof(ma_decoder)`.

This is in preparation for future work to support copying data sources.
2026-04-29 06:54:57 +10:00
David Reid 70d52e5eaa Simplify ma_allocation_callbacks_init_copy().
This returns the ma_allocation_callbacks object instead of a result
code.
2026-04-28 19:21:30 +10:00
David Reid d7802c3b14 API CHANGE: Remove decoding backend file initialization specializations.
This removes the onInitFile and onInitFileW callbacks from
ma_decoding_backend_vtable. This means decoding backends can no longer
implement a specialized initialization routine for loading from a file.
What this does is enforces all file IO to go through the same code path,
that being the `ma_decoder` and `ma_vfs` infrastructure. It also
simplifies the backend vtable.

The ability to initialize from memory (the onInitMemory callback) is
still available and there are not plans to remove this.
2026-04-28 19:07:23 +10:00
David Reid 77074f0597 API CHANGE: Add an onUninit callback to ma_data_source_vtable.
This callback to execute the data source's uninitialization routine.
2026-04-28 17:27:31 +10:00
David Reid 44323c9cae API CHANGE: Rename data source init and uninit APIs.
These have been renamed to the following:

  ma_data_source_init   > ma_data_source_base_init
  ma_data_source_uninit > ma_data_source_base_uninit

The new naming scheme makes it clearer that you're initializing the
base data source structure.
2026-04-28 16:24:22 +10:00
David Reid cb0e6afe70 Update to the decoding backend system.
The `onGetEncodingFormat` callback has been removed and replaced with an
`onInfo`. This new callback fills out a struct with the supported
encoding format (is recognized by miniaudio), in addition to the name of
the decoding backend, and the decoding library and vendor.
2026-01-17 14:49:26 +10:00
David Reid 882d7329f9 Add getter functions for backend vtables. 2026-01-07 09:22:43 +10:00
David Reid a4072246c5 Rename some variables and try silencing a warning. 2025-07-15 07:21:30 +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 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 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 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
David Reid 724dac6af1 Fix compilation errors. 2025-02-18 18:26:07 +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