Commit Graph

2648 Commits

Author SHA1 Message Date
David Reid 366aa4346e Relax restrictions on the maximum input and output buses for nodes.
Previously this was restricted to 2 input buses and 2 output buses, but
this has been lifted to 254. When the number exceeds 2, internal data
structures will be allocated on the heap, otherwise they'll use a local
array contained within the ma_node structure.

This commit changes the node configuration. Previously there was a
fixed sized array for specifying the channel counts for each bus. This
array must now be defined outside of the config by the caller. The
following config variables have been renamed:

  * inputChannels > pInputChannels
  * outputChannels > pOutputChannels

This commit also adds the ability to configure input and output bus
counts on a per-instance basis rather than via the node vtable. To do
this, set the bus count in the vtable to MA_NODE_BUS_COUNT_UNKNOWN.
This will tell miniaudio to look at the node config to determine the
bus count rather than the vtable. It's an error to specify this in the
node config if the vtable specifies anything other than
MA_NODE_BUS_COUNT_UNKNOWN.
2021-07-03 12:40:13 +10:00
David Reid db7a3dfd23 Update stb_vorbis. 2021-07-03 07:48:12 +10:00
David Reid 4d1f619ff2 Formatting fixes. 2021-07-02 22:09:29 +10:00
David Reid f568dd8a79 Fix an infinite loop with the Vorbis decoder. 2021-07-02 21:54:50 +10:00
David Reid d2e5d3c283 Start to add some logging to the resource manager. 2021-07-02 21:49:00 +10:00
David Reid 479718d86d Fix a log formatting bug. 2021-07-02 21:31:19 +10:00
David Reid 9978520acf Use better allocation functions. 2021-07-02 20:57:33 +10:00
David Reid 18d185832f Fix a compilation warning. 2021-07-02 20:54:38 +10:00
David Reid 9b237dac04 Hook up the resource manager to the new logging system. 2021-07-02 20:54:30 +10:00
David Reid f940118fd8 Fix some logging bugs. 2021-07-02 20:30:13 +10:00
David Reid f2ef1d8f99 Hook up the engine to the new logging system. 2021-07-02 20:29:52 +10:00
David Reid 591d340343 Improvements to logging.
* The old logging callback has been deprecated and will be removed in
    version 0.11.
  * MA_LOG_LEVEL_DEBUG has been added and MA_LOG_LEVEL_VERBOSE
    deprecated.
  * The MA_LOG_LEVEL option has been deprecated. All log levels are now
    posted to the logging callbacks, except for MA_LOG_LEVEL_DEBUG
    which is only posted if MA_DEBUG_OUTPUT is enabled.

The new logging system works by creating a `ma_log` object. You then
register callbacks that will be fired when a log message is posted. You
can register up to 4 callbacks. You the specify a pointer to this log
object in the context config. This replaces the `logCallback` variable.

The old logging system was specific to context's and device's, however
with the introduction of new APIs this is no longer appropriate. The
new logging system is completely generic with a simple user-data
pointer being used for application-specific data.

This commit adds some helper APIs for retrieving a pointer to the
context's log object:

  * ma_context_get_log()
  * ma_device_get_log()
  * ma_device_get_context()

The MA_DEBUG_OUTPUT option has been improved for Android builds. With
the new system, __android_log_print() will be used instead of printf().
2021-07-02 20:10:23 +10:00
David Reid 1ad55ca9ad OpenSL: Fix a copy/paste bug. 2021-07-02 15:52:50 +10:00
David Reid 410bdaa6bf Fix some bugs with recent commits. 2021-07-01 19:51:17 +10:00
David Reid 210d2db9a3 Deprecate some decoder initialization functions. 2021-07-01 19:25:10 +10:00
David Reid acb7aba85e PulseAudio: Another attempt at fixing a division by zero.
Public issue https://github.com/mackron/miniaudio/issues/323
2021-07-01 18:43:45 +10:00
David Reid f340578d76 Update revision history. 2021-07-01 17:43:49 +10:00
David Reid 00baf2f622 Remove some unnecessary members from ma_decoder. 2021-07-01 17:42:20 +10:00
David Reid fd0c441423 Remove unused variables from the ma_decoder structure. 2021-07-01 17:14:47 +10:00
David Reid e312ac5411 Remove the old "raw" decoder.
This is no longer used. New code should use `ma_audio_buffer`.
2021-07-01 17:11:56 +10:00
David Reid b1f64fdaf6 Update simple_playback example. 2021-07-01 17:05:31 +10:00
David Reid 11a774c9ff Update dr_wav. 2021-07-01 17:05:17 +10:00
David Reid ead7373925 Update the WAV decoder to use the new backend infrastructure. 2021-07-01 16:20:27 +10:00
David Reid ea4453377a Update the FLAC decoder to use the new backend infrastructure. 2021-07-01 16:12:44 +10:00
David Reid 13252284e5 Update the MP3 decoder to use the new backend infrastructure. 2021-07-01 16:01:08 +10:00
David Reid 956701fcdd Update the Vorbis decoder to use the new backend infrastructure. 2021-07-01 15:31:39 +10:00
David Reid e0bfc59bc0 Restructuring in preparation for future work. 2021-07-01 15:22:13 +10:00
David Reid c54bb96964 Rename some config variables. 2021-07-01 14:58:05 +10:00
David Reid 6ec9a1c1fb Minor code restructure. 2021-07-01 14:55:20 +10:00
David Reid 9f4460797f Fix memory leaks. 2021-07-01 14:36:22 +10:00
David Reid 022b38517e Simplify the custom_decoder example. 2021-07-01 13:46:43 +10:00
David Reid 6dbb31849b Fix copy/paste errors. 2021-07-01 10:08:22 +10:00
David Reid d80c41f414 Update wording in comments. 2021-07-01 06:45:55 +10:00
David Reid a70515a96d Add example for using custom decoders with the resource manager. 2021-06-30 20:59:16 +10:00
David Reid 9ed296b3b9 Fix a bug where custom decoding backends aren't being used. 2021-06-30 20:58:43 +10:00
David Reid 52f471ae43 Try to standardize the use of MA_AT_END.
With this change, MA_AT_END should only ever be returned the number of
bytes or frames returned is equal to 0.
2021-06-30 20:58:07 +10:00
David Reid 07fbb6ac6d Update custom_decoder example. 2021-06-30 20:43:05 +10:00
David Reid 998bd995bc Add libvorbis and libopus data sources to the extras folder. 2021-06-30 20:42:43 +10:00
David Reid 54aae74d6e Rename ma_engine_config_init_default() to ma_engine_config_init(). 2021-06-30 20:30:57 +10:00
David Reid 8567a4bc37 Hook up custom decoders to the resource manager. 2021-06-30 16:36:36 +10:00
David Reid 4559253587 Remove the MA_END_OF_FILE result code.
Use MA_AT_END instead. Use of MA_END_OF_FILE is too easily confused
with MA_AT_END, and MA_AT_END is a more generally applicable.
2021-06-30 12:30:31 +10:00
David Reid 1c179fb475 Try fixing an infinite loop. 2021-06-30 12:17:21 +10:00
David Reid 38f2754edb Fix compilation errors on 32-bit. 2021-06-30 06:10:44 +10:00
David Reid dad754b745 Add support for custom decoding backends.
Public issue https://github.com/mackron/miniaudio/issues/311
2021-06-27 21:43:31 +10:00
David Reid fca4d5c16a Fix an edge case where async notifications are not getting fired. 2021-06-26 15:07:24 +10:00
David Reid 1597f6c041 Update test code. 2021-06-26 13:49:55 +10:00
David Reid 5df38de8ad Improvements to the async notification system.
These changes expand on the notification system which allows a program
to be notified on when a sound has reached various stages in the async
loading process. There are two stages:

  1) Decoder initialization
  2) Completion of decoding

The previous system has the following problems:

  * There's no way to wait on only the decoder initialization
  * The callback doesn't work well if you want to pass it through
    multiple layers. Example:
    - Client wants to wait for the sound to complete
    - Pass the callback into ma_sound_init_from_file(), which passes
      it into ma_resource_manager_data_source_init(). The latter will
      fire the callback, but will do so before ma_sound_init_from_file()
      has returned. The client will think the sound has finished
      loading and will reference the `ma_sound` object before it's
      completed initialization.
  * It's not easy to wait on object in bulk. Clients may want to pump a
    bunch of ASYNC sounds in one go, and then just have a single
    notification for the group.

The new system introduces the notion of a "fence". A fence contains a
counter which is incremented and decremented from anywhere. It also has
a wait routine which will block until the counter hits zero:

  ma_fence_acquire() - Increments the counter
  ma_fence_release() - Decrements the counter
  ma_fence_wait()    - Blocks until the counter is 0.

The fence system can be used to wait for a number of sounds to finish
decoding rather than only one at a time, which is the case with the
previous system. Example:

```
/* Fences must be initialized before use. */
ma_fence_init(&fence);

/* Loop over each sound and start loading them, passing in the fence. */
for each sound in sounds
{
    flags = MA_DATA_SOURCE_FLAG_DECODE | MA_DATA_SOURCE_FLAG_ASYNC;
    ma_sound_init_from_file(&engine, pFilePath, flags, &group, &fence, &sound);
}

... do some other stuff while sounds are loading ...

/* Wait for sounds to finish loading. */
ma_fence_wait(&fence);
ma_fence_uninit(&fence);
```

The above example initializes a sound, but it can also be used by
resource managed data sources. When loading data sources directly from
the resource manager, you can specify a second fence which is used to
only wait until the internal decoder has been initialized.
2021-06-26 13:24:22 +10:00
David Reid b4d6c37d13 Simplify async notifications. 2021-06-26 09:58:29 +10:00
David Reid ea84294d97 Fix the custom_backend example. 2021-06-24 19:23:30 +10:00
David Reid 5551dc67e1 Update wording in example. 2021-06-24 19:07:33 +10:00