Commit Graph

169 Commits

Author SHA1 Message Date
David Reid 340dbcc37b Fix a mixing bug when applying an effect. 2020-08-16 11:32:07 +10:00
David Reid 96ee8242f4 Add support for start delays for engine sounds. 2020-08-15 11:53:37 +10:00
David Reid fea2cba24b Add support for offsets to the low-level mixing API. 2020-08-15 11:48:40 +10:00
David Reid fe85a13214 Add ma_decoder_get_cursor_in_pcm_frames(). 2020-08-15 10:09:19 +10:00
David Reid 6d1a1ccd05 Engine: Improve support for fading in and out of sounds.
Fading is now set using these APIs:

  * ma_engine_sound_set_fade_in()
  * ma_engine_sound_set_fade_out()

When a sound is stopped, either by naturally reaching the end, or
explicitly with ma_engine_sound_stop(), the fade out will be applied.
Fading will also be applied around loop transitions.

Note that when a sound is stopped implicitly by it reaching the end,
fading out will not work when the length of the sound is not know (that
is, when ma_data_source_get_length_in_pcm_frames() returns 0).
2020-08-14 13:25:47 +10:00
David Reid 775c624e66 Add some APIs to data sources:
* ma_data_source_get_cursor_in_pcm_frames()
  * ma_data_source_get_length_in_pcm_frames()

When the data source has no notion of a cursor or length, these return
MA_NOT_IMPLEMENTED to let the caller know about it. This is returned
when a custom data source leaves these functions unimplemented.

ma_decoder, ma_audio_buffer, ma_waveform and ma_noise have all been
updated to support these new functions.
2020-08-09 22:29:11 +10:00
David Reid 78ff206095 Fix bug in ma_resource_manager_data_buffer_get_available_frames(). 2020-08-09 18:49:48 +10:00
David Reid ab38bf91aa Add ma_engine_sound_get_data_format().
This function is used for retrieving the sample format, channel count
and sample rate of the sound.
2020-08-09 17:17:52 +10:00
David Reid 6e32cc22ff Add ma_engine_sound_set_fade_in/out().
As of this commit, ma_engine_sound_set_fade_out() is not fully
implemented pending the writing of some additional infrastructure.
2020-08-09 17:01:18 +10:00
David Reid f3f11b4133 Update the fader effect to support dual sub-fades.
This is useful for having a separate fade in and fade out for a sound
which is what we require for the ma_engine API.
2020-08-09 10:42:56 +10:00
David Reid 65e547c5a6 Add output parameter for number of frames mixed to ma_mixer_mix_*(). 2020-08-09 09:02:25 +10:00
David Reid 0672f3043a Add ma_engine_sound_seek_to_pcm_frame(). 2020-08-09 08:37:35 +10:00
David Reid 76a43426de Add sample rate to ma_data_source_get_data_format(). 2020-08-09 07:27:41 +10:00
David Reid 4060f18cda Minor cleanup. 2020-08-08 20:10:43 +10:00
David Reid 9763fa626b Engine: Add support for fading.
This adds support for having a sound fade in when it is started and
fade out when it is stopped.

This commit does not yet include support for fading out when the sound
approaches the end - it only fades out when explicitly stopped with
ma_sound_stop().

The fade time is set in milliseconds.

This commit includes a new effect called ma_fader, but it currently
only supports f32 formats. Support for other formats will be added in
the future.
2020-08-08 19:31:49 +10:00
David Reid 9ded34fec4 Fix some minor typos. 2020-08-08 15:39:12 +10:00
David Reid d91ca8e88c Resource Manager: Cleanup from some previous refactoring. 2020-08-08 13:31:30 +10:00
David Reid 0cbd8c2c4f Resource Manager: Add support for flexible async notifications.
The ma_async_notification object is used for notifying the application
that an asynchronous operation has completed.

Custom notifications can be implemented by implementing the callback in
ma_async_notification_callbacks. There is currently only a single
callback called onSignal which is fired when the operation completes. A
helper notification which wraps around an ma_event object called
ma_async_notification_event is implemented which you can use as an
example for building your own notifications.
2020-08-08 13:29:20 +10:00
David Reid f5284505ac Resource Manager: Fix retrieval of available frames. 2020-08-08 12:15:04 +10:00
David Reid 61b545e2b4 Resource Manager: Rename some APIs for consistency. 2020-08-03 20:32:50 +10:00
David Reid dbbae5b6a6 Resource Manager: Remove some unnecessary functions. 2020-08-03 19:43:29 +10:00
David Reid 91d1a5abcd Resource Manager: Add public APIs for data stream/buffer/source. 2020-08-03 19:37:16 +10:00
David Reid d48708d5de Big refactor to the resource manager.
* The data buffers and data streams are now first class data sources.
  * The ma_resource_manager_data_source object is now just a simple
    wrapper around ma_resource_manager_data_buffer and
    ma_resource_manager_data_stream.
  * Unnecessary pResourceManager parameters have been removed.
  * The part of the data buffer that's added to the BST has been split
    out from the main data buffer object so that the main object can be
    owned by the caller.
  * Add ma_resource_manager_data_source_get_available_frames() which is
    used to retrieve the number of frames that can be read at the time
    of calling. This is useful in asynchronous scenarios.
2020-08-02 21:26:34 +10:00
David Reid 5303558ac8 Add ma_resource_manager_data_source_get_available_frames(). 2020-08-02 13:58:36 +10:00
David Reid 0336896c33 Resource Manager: Update some documentation for implementation details. 2020-08-02 12:38:14 +10:00
David Reid 0d8bf45dba Start some documentation for resource management. 2020-07-26 15:41:33 +10:00
David Reid 4fef753432 Resource Manager: Add public APIs for reading and seeking. 2020-07-25 19:49:20 +10:00
David Reid 5eb7761d8e Resource Manager: Rename some APIs for consistency. 2020-07-25 19:19:52 +10:00
David Reid 2a15044ff9 Update resource_manager example. 2020-07-25 18:27:59 +10:00
David Reid 3df4a9e860 Resource Manager: Decode synchronously on the calling thread.
This commit changes synchronous decoding so that the calling thread is
the one which performs the decoding. Previously, decoding was done on
the job threads which was then waited on by an event on the calling
thread. The rationale for this design was to keep decoding on a single
code path, however this creates a problem for programs that would
prefer not to have any asynchronous job threads. In this case, these
synchronously decoded sounds would never get decoded because there
would not be any threads available to actually perform the decoding.

This commit enables the resource manager to be able to be used without
a job thread so long as asynchronous decoding and streaming are not
used. This scenario could be useful for programs that want to pre-load
all of their sounds at load time and save some system resources by not
incurring the overhead of an additional unnecessary thread.
2020-07-25 18:06:48 +10:00
David Reid 24a1108834 Minor updates to the resource_manager example. 2020-07-23 17:01:04 +10:00
David Reid 83178a1dfc Fix a buffer overflow in the mixer. 2020-07-23 09:44:20 +10:00
David Reid 5dda38d417 Add a clarifying comment to the resource_manager example. 2020-07-23 08:02:19 +10:00
David Reid 9972488bde Add some comments to the resource manager example for clarity. 2020-07-22 20:50:57 +10:00
David Reid 3bcdf3942d Add a resource manager example. 2020-07-22 20:35:34 +10:00
David Reid 681d26a557 Fix bugs in the resource manager. 2020-07-22 20:22:44 +10:00
David Reid 77057895a8 Set up some infrastructure for enabling multiple job threads. 2020-07-20 19:15:32 +10:00
David Reid 861f6a23c8 Initial work on a new job system for the high level API.
This new system is used for asynchronous decoding of sound data. The
main improvement with this one over the old one is the ability to do
multi-producer, multi-consumer lock-free posting of messages which
means multiple threads can be used to process jobs simultaneously
rather than a single thread processing all jobs serially.

Decoding is inherently serial which means multiple job threads is only
useful when decoding multiple sounds. Each individual sound will be
decoded serially.

Another change with this commit is the ability for applications to
control whether or not the resource manager manages it's own job
threads. This is useful if an application wants to manage the job queue
themselves if, for example, they want to integrate it more closely with
their existing job system.
2020-07-19 21:56:12 +10:00
David Reid cf14d0773e Experiment with some mitigation for the ABA problem. 2020-07-19 10:43:18 +10:00
David Reid 6f748942e6 Update examples and tests. 2020-06-24 19:37:46 +10:00
David Reid 9467152730 Integrate c89atomic to replace the old atomics API.
This is an internal change and does not affect any public APIs. This
change is in preparation for future lock-free high level APIs.
2020-06-23 17:39:06 +10:00
David Reid 45a12620bf Minor update to test code. 2020-06-22 21:03:07 +10:00
David Reid c92c7764de Experimental work on some lock free queues.
These are completely untested. Nothing here is wired up to the main
system - they're just for experimenting with some ideas.
2020-06-16 21:06:04 +10:00
David Reid a04a318b44 Fix a copy/paste error. 2020-06-14 21:59:42 +10:00
David Reid badb651b79 Add next() and peek() APIs for messages to the resource manager.
This is in preparation for self-managed message handling.
2020-06-14 20:32:52 +10:00
David Reid 4b6c8f555b Add support for configuring thread stack sizes and fix GCC errors.
The thread priority can be set via ma_thread_create() and can be set in
the context config along side the thread priority for configuring the
size of the stack for the audio thread.
2020-06-14 19:27:02 +10:00
David Reid d4cdee82b5 Fix looping with data streams. 2020-06-14 17:24:15 +10:00
David Reid cb5e6f33df Tidy up a few things with the resource manager. 2020-06-14 15:22:11 +10:00
David Reid 9d81823a73 Fix a typo. 2020-06-14 15:20:31 +10:00
David Reid 9cb5ee06ac Comment out some unused functions. 2020-06-14 15:20:13 +10:00