Commit Graph

14 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 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 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 0ea924ae7a Merge branch 'dev' into dev-0.12 2025-02-19 12:09:13 +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 de5f370d09 Fix some warnings with examples. 2025-02-17 16:01:19 +10:00
David Reid 766a155fb3 Stop using MA_ASSERT in examples.
This is useful because MA_ASSERT is only defined in the implementation
section of miniaudio.h which can cause issues when people copy/paste
the code and use it in a file that does not have visibility of the
implementation.

Note that there are still more references to implementation-defined
macros, but these have been moved to the public section in the dev-0.12
branch so I'm not bothering to change those just yet.

Public issue https://github.com/mackron/miniaudio/issues/787
2023-12-17 08:42:19 +10:00
David Reid 9598247096 Remove old files and update examples. 2021-12-10 21:13:34 +10:00
David Reid dc912eb123 Fix some examples. 2021-12-10 07:03:25 +10:00
David Reid efa95d998f Remove the loop parameter from ma_data_source_read_pcm_frames(). 2021-10-13 18:51:17 +10:00
David Reid 2671e07560 Add examples for the high level API. 2021-08-14 18:41:26 +10:00