Commit Graph

35 Commits

Author SHA1 Message Date
David Reid d6f664e19a Add support for configuring automatic resetting of fade points.
This is useful for enabling or disabling fading around loop
transitions.
2020-08-23 16:55:58 +10:00
David Reid 49a9e2a2bf Minor refactor for getting load notifications working for sounds.
With this commit, you can now pass in a notification object which is
fired when an asynchronous sound has finished loading.
2020-08-23 14:08:22 +10:00
David Reid 96a60c069e Remove the pEngine parameter from all ma_sound_group_*() APIs.
Previously you could set the group to NULL in which case the master
group would be used, but this has now changed and the group parameter
can never be NULL. Use ma_engine_get_master_sound_group() to retrieve
the master sound group.
2020-08-23 10:51:04 +10:00
David Reid 0c410b0fdc Remove the pEngine parameter from all ma_sound_*() APIs. 2020-08-23 10:18:03 +10:00
David Reid fd1ca85219 Rename some APIs.
* ma_engine_sound_*() renamed to ma_sound_*().
  * ma_engine_sound_group_*() renamed to ma_sound_group_*().
2020-08-23 10:02:45 +10:00
David Reid 1f89b003c5 Changes to fading and delays.
* Removed ma_engine_sound_set_fade_in/out()
  * Add ma_engine_sound_set_fade_point_in_frames()
  * Add ma_engine_sound_set_fade_point_in_milliseconds()
  * Add ma_engine_sound_set_stop_delay()
  * Add ma_engine_sound_get_time_in_frames()
  * Removed ma_engine_sound_group_set_fade_in/out()
  * Add ma_engine_sound_group_set_fade_point_in_frames()
  * Add ma_engine_sound_group_set_fade_point_in_milliseconds()
  * Add ma_engine_sound_group_set_stop_delay()
  * Add ma_engine_sound_group_get_time_in_frames()

The fade in/out system has been replaced with something more general
and flexible which allows for up to two fade points to be configured
per sound or group, with arbitrary time periods and volumes.

This commit also includes the addition of a placeholder parameter for
ma_engine_sound_init_from_file() which is used to notify the caller
when an asynchronously loaded sound has finished loading.
2020-08-22 21:58:03 +10:00
David Reid 4873584058 Add support for fading out to sound groups. 2020-08-16 21:30:35 +10:00
David Reid 3de7f5caf5 Add support for start delays to sound groups. 2020-08-16 17:16:50 +10:00
David Reid 56dbcb529c Add support for fading in to sound groups. 2020-08-16 16:57:53 +10:00
David Reid 22a785d72b Add support for setting the pitch on sound groups. 2020-08-16 15:20:35 +10:00
David Reid 042e1b95b1 Add support for panning to sound groups. 2020-08-16 11:34:13 +10:00
David Reid 96ee8242f4 Add support for start delays for engine sounds. 2020-08-15 11:53:37 +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 0672f3043a Add ma_engine_sound_seek_to_pcm_frame(). 2020-08-09 08:37:35 +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 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 6f748942e6 Update examples and tests. 2020-06-24 19:37:46 +10:00
David Reid 45a12620bf Minor update to test code. 2020-06-22 21:03:07 +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 80da67de3b Revert some earlier test code. 2020-06-14 13:04:03 +10:00
David Reid c3e2038c3a Fix a crash trying to seek on a failed async data stream. 2020-06-14 12:54:14 +10:00
David Reid d2cffd18d6 Add support for streaming data sources.
A streaming data source keeps in memory only two pages of audio data
and dynamically loads data from a background thread. It is essentially
a double buffering system - as one page is playing, the other is being
loaded by the async thread.

The size of a single page is defined by the following macro:

    MA_RESOURCE_MANAGER_PAGE_SIZE_IN_MILLISECONDS

By default this is currently set to 1 second of audio data. This means
each page has 1 second to load which should be plenty of time. If you
need additional time, the only way to do it is increase the size of the
page by changing the value of the above macro.
2020-06-14 10:39:41 +10:00
David Reid f38dcab0f2 Rename data nodes to data buffers in the resource manager. 2020-06-13 08:44:15 +10:00
David Reid 213ee9dc52 Introduce paged decoding to the resource manager in the high level API.
This enables early playback of the sound while the remainder of the
sound is loaded in the background. When the first page is loaded, the
sound can start playback. While it's playing, the rest of the sound is
loaded in a background thread. In addition, sounds no longer need to
wait for every sound prior to it in the queue to fully decode before it
is able to start - it only needs to wait for the first page of each of
the queued sounds to decode. This enables much fairer prioritization of
asynchronously loaded sounds.

This paged decoding system is *not* a true streaming solution for long
sounds. Support for true streaming will be added in future commits.
This commit is only concerned with filling in-memory buffers containing
the whole sound in an asynchronous manner.
2020-06-12 21:47:49 +10:00
David Reid 8734e8f578 Work in progress on the new high level API.
* Early work on asynchronously decoding into a memory buffer. This is
    just an early implementation - there are still issues needing to be
    figured out. In particular, sounds do not automatically start until
    the entire file has been decoded. It would be good if they could
    start as soon as the first second or so of data has been decoded.
2020-06-10 22:07:16 +10:00
David Reid 95ded1d57c Fix sound uninitialization. 2020-06-07 15:33:49 +10:00
David Reid ce4d4b359f More work on the new high level API:
* Implement the notion of a virtual file system (VFS) which is used
    by the resource manager for loading sound files. The idea is that
    the application can implement these to support loading from custom
    packages, archives, etc.
  * Add a helper API for decoding a file from a VFS and a file name.
  * Add some symbols representing allocation types. These are not
    currently used, but I've added them in preparation for changes to
    the allocation callbacks. The idea is that an allocation type will
    be passed to the callbacks to give the allocator better intel as to
    what it's allocating which will give it a chance to optimize.
  * Add some placeholders for flags for controlling how to load a data
    source. Currently only MA_DATA_SOURCE_FLAG_DECODE is implemented
    which is used to indicate to the resource manager that it should
    store the decoded contents of the sound file in memory rather than
    the raw (encoded) file data.
  * Support has been added to the resource manager to load audio data
    into memory rather than naively reading straight from disk. This
    eliminates file IO from the audio thread, but comes at the expense
    of extra memory usage. Support for streaming is not implemented as
    of this commit. Early (largely untested) work has been implemented
    to avoid loading sound files multiple times. This is a simple ref
    count system for now, with hashed files paths being used for the
    key into a binary search tree. The BST is not fully tested and
    likely has bugs which will be ironed out in future commits.
  * Support has been added for configuring the stereo pan effect. Most
    audio engines use a simple balancing technique to implement the
    pan effect, but a true pan should "move" one side to the other
    rather than just simply making one side quieter. With this commit,
    the ma_panner effect can support both modes. The default mode will
    be set to ma_pan_mode_balance which is just a simple balancing and
    is consistent with most other audio engines. A true pan can be used
    by setting the mode to ma_pan_mode_pan.
2020-06-07 12:09:39 +10:00
David Reid b287d94fe8 Rename some functions for consistency. 2020-06-03 21:25:57 +10:00
David Reid 31f08287da Have decoders use their native channel count in the high level API.
This is required so we can do different spatialization logic depending
on the channel count of the audio source.
2020-06-03 17:01:39 +10:00
David Reid cc8201738b Optimization to stereo panner. 2020-06-01 20:47:34 +10:00
David Reid 1c26893930 Add initial implementation of stereo panning to the ma_engine API.
This currently only supports f32, but support for more formats will be
coming soon.
2020-05-31 23:54:29 +10:00
David Reid f4b0b271cd More work on the new engine API.
* Initial work on infrastructure for spatialization, panning and
    pitch shifting.
  * Add ma_engine_sound_set_pitch()

Spatialization and panning is not yet implemented, but pitch shifting
should now be working.
2020-05-31 23:14:59 +10:00
David Reid 105d016e69 Updates to the new ma_engine API.
* The engine will now auto-start by default. This can be changed in
    the config by setting `noAutoStart` to true.

  * Initial implementation of ma_engine_play_sound() which can be used
    for fire-and-forget playback of sounds.

  * Add ma_engine_sound_at_end() for querying whether or not a sound
    has reached the end. The at-end flag is set atomically and
    locklessly in the mixing thread.
2020-05-30 13:56:41 +10:00
David Reid 046bc0d7c6 Add initial experimental work on the ma_engine API. 2020-05-28 21:25:39 +10:00