Commit Graph

473 Commits

Author SHA1 Message Date
David Reid 11acb0caa5 Prep work in preparation for some changes to data sources.
Public issue https://github.com/mackron/miniaudio/issues/290
2021-05-03 15:35:07 +10:00
David Reid 1897c59993 Add support for initializing a sound from another.
This only works for non-streaming sounds whose data source was created
via the resource manager.
2021-05-03 12:08:24 +10:00
David Reid 2f56829b45 Fix an error due to inconsistent types. 2021-04-09 17:52:53 +10:00
David Reid 56beafcfe9 Fix a possible crash in the engine when loading async sounds.
This crash can happen if the decoder reads more data than it reports
from ma_decoder_get_length_in_pcm_frames().
2021-04-06 20:45:54 +10:00
David Reid 56a5ecbdbd Fix a subtle bug in gain smoothing. 2021-04-05 19:34:11 +10:00
David Reid c300aa9f72 Experimental fix for an issue with gain smoothing. 2021-04-05 19:19:08 +10:00
David Reid 1604512e89 Make spatialization gain smoothing configurable at the engine level. 2021-04-05 18:16:08 +10:00
David Reid 9097bb862b Minor tweak to default gain smoothing time for spatialization. 2021-04-05 17:58:26 +10:00
David Reid 602161b69b Fix a crackling bug with spatialization.
This crackling was happening due to abrupt volume transitions as the
gain changes for each channel as sounds move around the world. This
change smooths out these transitions using linear interpolation.
2021-04-05 16:07:09 +10:00
David Reid 608e839c6a Fix a warning. 2021-04-05 13:21:02 +10:00
David Reid 8a1c72f2c3 Fix a pitching bug with the engine.
This is happening when the engine's sample rate differs from the data
source's sample rate.
2021-04-05 12:37:22 +10:00
David Reid 2a31247b50 Fix a bug when async loading sounds with an unknown length. 2021-04-05 10:54:10 +10:00
David Reid 8c2f457de9 Reduce the weight of ma_sound by allocating some data on the heap. 2021-04-04 18:38:12 +10:00
David Reid 65987d8034 Unify the ma_sound and ma_sound_group APIs. 2021-04-04 16:18:56 +10:00
David Reid e968fb38ae Fix some bugs for sounds not backed by a data source. 2021-04-04 14:52:08 +10:00
David Reid dba9e1b314 Add support for more advanced sound configuration.
* Sounds can now have another node be used as input rather than a
    data source.

  * Sounds can now have a configurable input and output channel count.
    For sounds that are backed by a data source, the input channel
    count will always be set to the data source's native channel count.

  * Sounds can now be initially attached to any node and input bus
    rather than only a sound group.

With this change, sounds can now be used as groups. In future commits,
it's likely that ma_sound_group will be unified with ma_sound. Whether
or not the `ma_sound_group_*()` APIs will continue to exists is for now
undecided.

This change allows more flexibility for doing custom effects before the
spatialization stage in the DSP pipeline. The problem with the existing
design is that there's no way to apply a custom effect before
spatialization which becomes a problem because spatialization will
often increase the channel count which results in excessive effect
processing due to the increased channel count. Now it should be
possible to set up a graph such that an effect can be plugged in
between the data source and the spatializer.

A new function called `ma_sound_init_ex()` has been added which is what
needs to be used to initialize a sound without a data source. This API
uses the config/init pattern. The config is called `ma_sound_config`.
2021-04-04 12:05:36 +10:00
David Reid f814a10c02 Try fixing a bug with doppler effect and rotations. 2021-04-02 13:50:16 +10:00
David Reid cb983db535 Attempt another fix for reversed front/back spatialization panning. 2021-04-02 12:39:41 +10:00
David Reid 544ec856f7 Another attempt at fixing a spatialization error. 2021-04-02 12:24:19 +10:00
David Reid 6d414a359b An experimental fix for some spatialization issues. 2021-04-02 10:52:26 +10:00
David Reid 215621f15e Fix an spatialization edge case relating to listener direction.
When the listener is looking at exactly the same direction as the world
up vector the 3D math breaks down due to a cross product evaluating to
a zero length vector.
2021-04-02 10:06:52 +10:00
David Reid ca5023415f Fix a division by 0 when normalizing a vector. 2021-04-02 09:48:00 +10:00
David Reid 88687fdc43 Try fixing a bug with calculating the relative position of a sound. 2021-04-02 09:27:08 +10:00
David Reid 045ee8ae18 Experimental fix for a memory leak in the resource manager. 2021-03-21 09:38:21 +10:00
Steven Noonan 8a1858eba6 use MA_ASSUME for channel counts before loops
The range of the value isn't obvious to any compiler, as it could go for
one iteration or 4 billion iterations. Adding MA_ASSUME in these places
helps the compiler understand the range of possible values, and know how
heavily to vectorize (or not vectorize) these loops.

Signed-off-by: Steven Noonan <steven@uplinklabs.net>
2021-03-15 04:10:10 -07:00
Steven Noonan c88bb8ccd2 extract channel count constants from loops
These values are constant, but Clang has some trouble noticing that,
especially if the loop body is complex enough. This prevents it from
noticing places where vectorization is possible (and desirable).

Signed-off-by: Steven Noonan <steven@uplinklabs.net>
2021-03-15 04:10:08 -07:00
David Reid 0a7207d5db Merge pull request #281 from morlad/fix-engine-no-resman-1
Fix linker error when MA_NO_RESOURCE_MANAGER is defined
2021-03-10 17:39:43 +10:00
morlad (iLeitgeb) 3a31faf8f0 Fix linker error when MA_NO_RESOURCE_MANAGER is defined 2021-03-10 06:43:57 +00:00
Steven Noonan 6c4937f495 engine: use atomics for setting live pitch and spatialization variables
Thread Sanitizer was unhappy about these variables being modified on one
thread and read on another (data race).

Signed-off-by: Steven Noonan <steven@uplinklabs.net>
2021-03-09 04:46:47 -08:00
David Reid 9c761921ab Try fixing an infinite loop. 2021-03-09 19:28:13 +10:00
David Reid 61f5d4e027 Fix a typo. 2021-03-06 18:55:47 +10:00
Steven Noonan a5db7b6574 resource manager: fix tree hierarchy when removing nodes
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
2021-03-06 08:49:10 +10:00
David Reid 91b4b62bf5 Minor clean up. 2021-03-06 08:42:25 +10:00
Steven Noonan 22414f8c01 miniaudio_engine: fix sample rate conversion for sounds
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
2021-03-06 08:40:39 +10:00
David Reid 062f150dc4 Fix a typo. 2021-03-05 17:39:46 +10:00
David Reid f8dd3780a2 Fix a typo. 2021-03-04 17:12:58 +10:00
David Reid 55e4e59bfa Add support for configuring rolloff. 2021-03-03 17:29:46 +10:00
David Reid 85cd9c1848 Fix a bug with ma_resource_manager_data_stream relating to seeking. 2021-02-28 06:49:36 +10:00
David Reid fc8f50457d Fixes to the C89 build. 2021-02-20 08:30:08 +10:00
David Reid f27a330a32 Experiment with improving async decoding on the Emscripten build. 2021-02-07 08:10:41 +10:00
David Reid b8f00dc4f9 Disable threading on the Emscripten build when init-ing the engine. 2021-02-07 07:51:43 +10:00
David Reid 1e0ccd6201 Fix a bug with start and stop times. 2021-02-05 22:11:12 +10:00
David Reid 2e32eca6dd Ensure the engine device uses ma_format_f32 for it's format. 2021-02-05 20:54:23 +10:00
David Reid 553c7f0093 Add some new APIs.
* ma_sound_set_start_time_in_milliseconds()
  * ma_sound_set_stop_time_in_milliseconds()
  * ma_sound_group_set_start_time_in_milliseconds()
  * ma_sound_group_set_stop_time_in_milliseconds()
2021-02-05 20:29:06 +10:00
David Reid 76640272be Rename some APIs for consistency with other APIs.
* ma_sound_set_fade_in_frames()       > ma_sound_set_fade_in_pcm_frames()
  * ma_sound_get_time_in_frames()       > ma_sound_get_time_in_pcm_frames()
  * ma_sound_set_start_time()           > ma_sound_set_start_time_in_pcm_frames()
  * ma_sound_set_stop_time()            > ma_sound_set_stop_time_in_pcm_frames()
  * ma_sound_group_set_fade_in_frames() > ma_sound_group_set_fade_in_pcm_frames()
  * ma_sound_group_get_time_in_frames() > ma_sound_group_get_time_in_pcm_frames()
  * ma_sound_group_set_start_time()     > ma_sound_group_set_start_time_in_pcm_frames()
  * ma_sound_group_set_stop_time()      > ma_sound_group_set_stop_time_in_pcm_frames()
2021-02-05 19:33:37 +10:00
David Reid cc2365b2b8 Fix a warning due to use of non-standard functionality. 2021-02-05 19:19:33 +10:00
David Reid 59db61d9f3 Add ma_sound_get_engine(). 2021-02-05 19:17:28 +10:00
David Reid fbb953ff01 Fix an unused variable warning. 2021-02-05 18:30:23 +10:00
David Reid 3265107cbd Fix a bug in ma_sound_is_playing().
This bug is due to the current time not being taken into account when
determining the node state.

Public issue https://github.com/mackron/miniaudio/issues/269
2021-02-05 17:16:30 +10:00
David Reid 1bd587e59f Fix the C++ build. 2021-01-31 19:52:35 +10:00