Commit Graph

458 Commits

Author SHA1 Message Date
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 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 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 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
David Reid 54adbc3dfc Fix a possible infinite loop. 2020-06-01 18:03:43 +10:00
David Reid 32e240d4ec Fix a bug when mixing a data source. 2020-06-01 01:05:01 +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 3a62d44959 Work on changes to the effect API. 2020-05-31 07:03:14 +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 e2b37b5d6d Fix some warnings reported by GCC. 2020-05-30 13:40:02 +10:00
David Reid fda0c07626 Update ma_mixer_mix_data_source() return value.
This change makes it so MA_AT_END is returned when a non-looping data
source reaches the end. This is how the caller can know to do clean up
or whatnot.
2020-05-30 13:01:56 +10:00
David Reid 077ae13157 Clarify some wording. 2020-05-28 22:36:34 +10:00
David Reid 046bc0d7c6 Add initial experimental work on the ma_engine API. 2020-05-28 21:25:39 +10:00
David Reid 0d691012d6 Add support for effects when mixing memory mapped data sources. 2020-05-28 16:18:16 +10:00
David Reid 783aef728e Updates to the mixer API.
* Add support for volume control to ma_mixer_mix_*().
  * Add support for specifying an effect to apply before mixing.
  * Add optimized pipeline for memory mappable data sources.
  * Remove some unnecessary functions:
    - ma_mixer_mix_pcm_frames_ex()
    - ma_mixer_mix_callbacks()
    - ma_mixer_mix_decoder()
    - ma_mixer_mix_audio_buffer()
    - ma_mixer_mix_waveform()
    - ma_mixer_mix_noise()
    - ma_mixer_mix_rb_ex()
2020-05-27 22:58:22 +10:00
David Reid 51fea1b1bd Fix some warnings in ma_mixing.h. 2020-05-27 17:43:08 +10:00
David Reid c530416acc Minor update to ma_mixer. 2020-05-25 22:45:40 +10:00
David Reid b95e86765e Remove old research code. 2020-05-23 17:13:37 +10:00
David Reid ea3f7f511e Add ma_audio_buffer API.
The ma_audio_buffer object is used for storing raw audio data in memory
and reading from it like any other data source. It supports flexible
memory management, reading, seeking, memory mapping and looping.

See documentation under "Audio Buffers" for a detailed description.
2020-05-23 17:07:19 +10:00
David Reid eaca001361 Add research code for ma_data_source. 2020-05-22 21:37:48 +10:00
David Reid 6d574e25b2 Initial commit of the new mixing API. 2020-05-10 20:55:08 +10:00
David Reid 5974dd6375 Remove old research code.
This code has now been integrated into miniaudio.h.
2020-02-01 11:23:43 +10:00
David Reid 323d7a69a1 Hide a biquad implementation detail. 2020-01-31 21:33:35 +10:00
David Reid ab518977ec Remove unnecessary casts. 2020-01-30 21:25:50 +10:00
David Reid 96f747d3f3 Don't allow format and channels to change for biquad and LPF filters.
Previously this would result in a glitch, however in the interest of
avoiding as many sources of glitching as possible, changing the format
and/or channel count of a biquad filter (and by extension, anything
derived from it, such as low-pass filters) will now result in an error.
2020-01-30 21:23:21 +10:00
David Reid 9dbcc39c6e Update biquad documentation. 2020-01-29 19:01:04 +10:00
David Reid c8b6fdaf2c Use fixed point arithmetic with s16 biquads. 2020-01-29 18:50:50 +10:00
David Reid 68b960215f Update old comments. 2020-01-28 22:03:47 +10:00
David Reid b9c2509d78 Fix an overflow bug in the s16 biquad pipeline. 2020-01-28 21:54:15 +10:00
David Reid 040dcf8d2c Add documentation for low-pass filters. 2020-01-28 21:49:33 +10:00
David Reid b97c6fd35b Remove the old direct form 1 biquad code. 2020-01-28 21:19:14 +10:00
David Reid 8a44789840 Remove the unnecessary config member from ma_lpf.
This is never actually used internally and saves a bit of memory.
2020-01-28 20:42:59 +10:00
David Reid 42095a3e5a Add documentation for biquads. 2020-01-28 20:41:41 +10:00
David Reid e525d457c9 Change biquad filter to use transposed direct form 2.
This change reduces memory usage by removing half the number of delay
registers.

This commit also sets up some infrastructure for future work on a fixed
point implementation. Both the floating and fixed point implementations
will run on a 32-bit pipeline for now.
2020-01-28 20:14:55 +10:00
David Reid eedb7d3200 Add some documentation for channel conversion. 2020-01-27 20:17:01 +10:00
David Reid d37b23a729 Bug fixes to the new data converter. 2020-01-27 18:30:49 +10:00
David Reid 5d3ed8687e Bug fixes to the linear resampler.
This changes the the lpfCutoffFrequency config variable from a uint32
to a double. This is required because we simplify the sample rate
fraction which cant result in cases where the cutoff frequency is too
aggressively rounded down due to dividing tiny integers.
2020-01-27 18:12:25 +10:00
David Reid 4f5eb2f8a1 Finish initial work on the new data converter. 2020-01-27 09:08:15 +10:00
David Reid b546607332 Begin work on integration of the new channel converter. 2020-01-26 19:01:43 +10:00
David Reid cbcf6f6cf3 Early work on new channel converter. 2020-01-26 18:37:10 +10:00
David Reid 68dc797469 Add early work on new data converter. 2020-01-26 16:42:27 +10:00
David Reid d27678a277 Fix bug in ma_linear_resampler_get_required_input_frame_count(). 2020-01-26 11:53:12 +10:00
David Reid 4241b9f6ae Add ma_linear_resampler_set_rate_ratio(). 2020-01-26 11:28:33 +10:00
David Reid ed6ad79e24 Don't use generic seeking with the linear resampler. 2020-01-26 11:24:02 +10:00
David Reid f704b62767 Update resampling documentation. 2020-01-26 11:21:09 +10:00