Commit Graph

480 Commits

Author SHA1 Message Date
David Reid cc2b148598 Add support for configuring the size of the job queue.
This commit also decouples the job queue from the resource manager
which will make it easier to use in other areas if it ever comes up.
2021-07-17 14:47:30 +10:00
David Reid 49599adcaf Decouple the slot allocator from the resource manager. 2021-07-17 13:27:54 +10:00
David Reid 503670532d Properly namespace some tokens. 2021-07-17 12:38:38 +10:00
David Reid faf3381f49 Update documentation for resource management. 2021-07-17 12:30:01 +10:00
David Reid 1982364b89 Minor rearrangement of some code. 2021-07-17 08:29:36 +10:00
David Reid 36d74d0111 Move ma_copy_and_apply_volume_factor_per_channel_f32() into main file. 2021-07-16 19:35:24 +10:00
David Reid 7d16721626 Remove unused function. 2021-07-16 19:10:35 +10:00
David Reid 17fe34c105 Remove some old unused code. 2021-07-16 17:46:37 +10:00
David Reid d93eaf22c1 Move ma_paged_audio_buffer into the main library. 2021-07-16 17:38:36 +10:00
David Reid 3fd7af7274 Fix some issues with resampling in the engine. 2021-07-11 08:49:55 +10:00
David Reid 47cfe17ebd Add support for custom resampling backends.
Public issue https://github.com/mackron/miniaudio/issues/162
2021-07-10 18:23:55 +10:00
David Reid fff5ad353c Merge branch 'dev' into dev-0.11 2021-07-10 11:57:40 +10:00
David Reid b8599906b7 Fix some bugs when playing inlined sounds.
Public issue https://github.com/mackron/miniaudio/issues/340
2021-07-10 11:57:29 +10:00
David Reid 33aae652fe API CHANGE: Update ma_get_standard_channel_map().
This adds a capacity parameter for added safety. It also changes the
order of parameters to make it a bit more consistent.
2021-07-04 19:46:00 +10:00
David Reid 3fad6cad86 API CHANGE: Add channel maps to ma_data_source_get_data_format().
This commit also removes the onGetChannelMap callback from the decoding
backend vtable.
2021-07-04 18:21:36 +10:00
David Reid 29ef420ee1 API CHANGE: Update ma_decoder_read_pcm_frames().
This makes ma_decoder_read_pcm_frames() consistent with other data
sources. It now returns a result code and outputs the number of frames
read via an output parameter.
2021-07-04 17:23:53 +10:00
David Reid 2399359089 API CHANGE: Update ma_decoder_get_length_in_pcm_frames().
This is now consistent with all other data sources:

  * Returns a result code
  * Length is returned via an output parameter
2021-07-04 17:03:46 +10:00
David Reid 1a4742e262 API CHANGE: Remove mapping from data sources.
This has proven to be exceptionally un-useful in practice and the
maintenance cost just isn't worth it.
2021-07-04 16:34:47 +10:00
David Reid e679602a56 Abandon the allocation type idea.
This might come back later, but for now this is no longer a thing.
2021-07-04 16:27:45 +10:00
David Reid fb9716d9d1 API CHANGE: Update ma_clip_samples_f32() to take an input and output.
The previous version only allowed in-place clipping, whereas the new
one supports clipping into a separate buffer. The input and output
buffers can point to the same buffer in which case the clip will be
performed in-place.
2021-07-04 16:10:30 +10:00
David Reid f9c496a014 API CHANGE: Rename noPreZeroedOutputBuffer to noPreSilencedOutputBuffer 2021-07-04 16:00:24 +10:00
David Reid ffb5a995c0 Minor improvements to listener indexes. 2021-07-04 14:03:11 +10:00
David Reid cff3398af4 Move some macros over to the main library. 2021-07-04 13:48:11 +10:00
David Reid cc6ef11076 Clean up some old matrix code. 2021-07-04 13:42:43 +10:00
David Reid a99eac9f22 Use rectangular channel mixing instead of shuffling mode.
This fixes an issue where excess channels are not heard when the sound
source has more channels than the listener.
2021-07-04 13:37:16 +10:00
David Reid 35ce972bd3 Make sure heap layouts are aligned properly. 2021-07-04 11:53:21 +10:00
David Reid ebaa74d608 Improvements to channel conversion during spatialization.
This commit also fixes a bug where panning is incorrectly getting
applied to non-directional channels, such as mono and LFE channels.
2021-07-04 11:37:50 +10:00
David Reid b6387eb241 Add support for heap preallocation to nodes. 2021-07-03 19:33:45 +10:00
David Reid 5928aa9930 Add support for pre-allocation to engine nodes. 2021-07-03 18:51:17 +10:00
David Reid bf1b518357 Experimental work on a new memory allocation model.
This is work towards using the heap for storing per-channel data so we
can get rid of upper channel count limit and remove MA_MAX_CHANNELS or
at the very least stop MA_MAX_CHANNELS from affecting overall memory
usage.
2021-07-03 18:00:26 +10:00
David Reid 8d00d9f5fa Add some error checking to ma_node_init(). 2021-07-03 14:22:42 +10:00
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 4d1f619ff2 Formatting fixes. 2021-07-02 22:09:29 +10:00
David Reid d2e5d3c283 Start to add some logging to the resource manager. 2021-07-02 21:49:00 +10:00
David Reid 9978520acf Use better allocation functions. 2021-07-02 20:57:33 +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 f2ef1d8f99 Hook up the engine to the new logging system. 2021-07-02 20:29:52 +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 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 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 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 45d07688e5 Add ma_fence object in preparation for changes to async notifications. 2021-06-24 17:51:15 +10:00