Commit Graph

2005 Commits

Author SHA1 Message Date
David Reid d4cdee82b5 Fix looping with data streams. 2020-06-14 17:24:15 +10:00
David Reid 50eb67f946 Update revision history. 2020-06-14 16:39:34 +10:00
David Reid 8bc153069a Clean up some formatting warnings with GCC and -Wall and -Wpedantic. 2020-06-14 15:29:30 +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
David Reid 3a54f2b6a4 Add a Win32 specific VFS.
This addresses some 64-bit issues with stdio with older versions of VC.
2020-06-14 15:20:00 +10:00
David Reid 18a70db5a9 Make MA_MAX_CHANNELS configurable.
This needs to be #define-d before the header *and* implementation
because it affects the size of publicly visible structures.
2020-06-14 13:33:14 +10:00
David Reid 5a7c2be726 Update comment. 2020-06-14 13:16:47 +10:00
David Reid 80da67de3b Revert some earlier test code. 2020-06-14 13:04:03 +10:00
David Reid dedb843814 Fix ma_compare_and_swap_*() on non-MSVC builds. 2020-06-14 13:02:50 +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 9be52c7075 Remove a debugging line. 2020-06-14 12:34:16 +10:00
David Reid 78aeabfa41 Update ma_yield(). 2020-06-14 12:30:14 +10:00
David Reid 103574f108 Fix a bug where ma_default_vfs_open_w() is not being used. 2020-06-14 10:40:49 +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 eb27826749 Fixes for the VC6 build. 2020-06-14 10:32:23 +10:00
David Reid 33aec2fcf9 Clean up and bug fixes to the resource manager.
* ma_resource_manager_uninit() has been implemented.
  * Bug fixes and inserting and removing data buffers from the BST.
  * Some old experimental code has been removed.
  * Minor whitespace clean up.
2020-06-13 10:40:04 +10:00
David Reid 005e19f783 Use ma_result instead of ma_bool32 for some internal sync primitives. 2020-06-13 09:43:33 +10:00
David Reid 96da8dd4bd Add ma_swap_endian_uint32() in preparation for future work. 2020-06-13 09:19:36 +10:00
David Reid 373234255a Add ma_decode_from_vfs(). 2020-06-13 09:15:47 +10:00
David Reid d65d714802 Rearrange some documents in preparation for repurposing the docs folder 2020-06-13 08:49:40 +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 7f49fca227 Add support for initializing decoders from a VFS. 2020-06-12 21:28:08 +10:00
David Reid 37669bcc8c Fix with Vorbis decoding. 2020-06-11 08:39:29 +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 86181dfac8 Updates to data sources.
* ma_data_source_read_pcm_frames and ma_data_source_seek_pcm_frames
    now return a result code and output the frames read/seeked as an
    output parameter.
  * These return MA_AT_END if the end of the data source has been
    reached. This should never be returned if the loop parameter is set
    to true.
2020-06-10 22:01:55 +10:00
David Reid 5f766acf8e Update revision history. 2020-06-08 17:15:35 +10:00
David Reid 13c7a0389f Add custom semaphore implementation for POSIX platforms.
This is needing to be done manually because Apple has decided to
deprecate anonymous semaphores from semaphore.h which we're going to
need.
2020-06-08 17:10:44 +10:00
David Reid ebf0826b17 Simplify the ma_thread structure. 2020-06-08 16:58:31 +10:00
David Reid 66e7518ef3 Simplify the ma_event structure. 2020-06-08 16:47:38 +10:00
David Reid ad7084030e Remove dependency on ma_context from the event API. 2020-06-08 16:42:06 +10:00
David Reid fc1a6930d3 Remove dependency on ma_context from the thread API. 2020-06-08 16:31:17 +10:00
David Reid d54b9efc07 Remove the dependency on ma_context from the semaphore API. 2020-06-08 16:24:01 +10:00
David Reid b819a0800f Rearrange some threading code to decouple it from device IO. 2020-06-08 16:18:38 +10:00
David Reid 2efe1ab81a Simplify mutex API by removing the ma_context parameter. 2020-06-08 16:06:13 +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 99fea233e8 Fix a bug when mixing a data source using mmap mode.
This was causing mmaped data sources to not loop if they coincidentally
reached the end at the same time as the final output frame was written.
2020-06-07 11:51:59 +10:00
David Reid 0be72c02dd Add ma_seek_origin_end in preparation for future work. 2020-06-07 11:50:42 +10:00
David Reid bc23d565e7 Minor optimization to ma_copy_pcm_frames() and update to documentation.
This changes makes ma_copy_pcm_frames() a no-op when the input and
output buffers are both set to the same pointer. This is useful for
some in-place no-ops for effects and filters.
2020-06-06 18:16:45 +10:00
David Reid b287d94fe8 Rename some functions for consistency. 2020-06-03 21:25:57 +10:00
David Reid fe06814325 Don't do filtering when pitch shifting for now.
This may be changed back to a first order LPF later on.
2020-06-03 20:50:44 +10:00
David Reid 5b1b160c62 Fix compilation errors with MA_NO_DEVICE_IO. 2020-06-03 20:01:36 +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 c0ebf41633 Minor renaming. 2020-06-03 16:52:05 +10:00
David Reid 766420eb2b Update revision history. 2020-06-01 21:20:36 +10:00
David Reid cc8201738b Optimization to stereo panner. 2020-06-01 20:47:34 +10:00
David Reid 4d5433ae58 Use first order LPF for pitch shifting by default.
There is a bug that's causing glitches which appears to be something to
do with the second order LPF.
2020-06-01 20:38:37 +10:00