Commit Graph

280 Commits

Author SHA1 Message Date
David Reid 9c7431ab91 Add support for metadata for nodes.
This is useful for retrieving information about some aspect of the
node. A good example is human readable names associated with the node
and it's input and output buses. This is useful for user interfaces
where a brief description of the node such as "Low Pass Filter" can be
drawn on the screen. It's also useful for buses to be named, such as
the source/carrier and excite/modulator on a vocoder effect which would
also need to be visible on a UI.
2021-01-16 14:06:24 +10:00
David Reid 85580a4c0a Minor grammar fix. 2021-01-15 22:48:35 +10:00
David Reid 0c435ae844 Add a TODO. 2021-01-15 22:47:23 +10:00
David Reid 13e03e4169 Some improvements to the processing of nodes.
The following flags can now be associated with nodes via the vtable:

  * MA_NODE_FLAG_PASSTHROUGH
  * MA_NODE_FLAG_CONTINUOUS_PROCESSING
  * MA_NODE_FLAG_ALLOW_NULL_INPUT
  * MA_NODE_FLAG_DIFFERENT_PROCESSING_RATES

See commit changes for a description of these flags.
2021-01-15 22:37:04 +10:00
David Reid 916c1b8a5f Changes to node processing callbacks.
* The simplified callback has been removed.
  * The `globalTime` parameter has been removed from the callback.
  * The order of input and output frames and counts has been swapped to
    be consistent with ma_data_converter_process_pcm_frames(), etc.
2021-01-15 19:44:36 +10:00
David Reid 88fc453f5f Add the MA_ATOMIC annotation.
Variables are marked with this annotation to make it clear that access
to the variable should be done through atomics.

I've also review the use of volatile in this commit.

Public issue https://github.com/mackron/miniaudio/issues/259
2021-01-14 19:05:10 +10:00
David Reid 687e9e5502 Fix a bug in the node graph relating to attaching and detaching nodes.
This was setting the previous pointer of newly attached nodes to NULL
instead of a pointer to the dummy head node. This then results in the
dummy head node never being updated when the node is detached which in
turn results in an uninitialized node being dereferenced.
2021-01-14 17:23:48 +10:00
David Reid 416ead6e35 Properly fix a bug with volume of output buses. 2021-01-14 17:08:14 +10:00
David Reid 63df16a2df Add some safety checks when reading from data sources. 2021-01-13 22:44:08 +10:00
David Reid 7a8ff122bc Fix a bug with the application of output bus volume. 2021-01-13 22:20:38 +10:00
David Reid fa416d323b Fix a bug when reading from a node with no attachments.
This would try reading from an uninitialized buffer thereby resulting
in a bad audio glitch. This does two things to fix the problem:

  1) When there are no input nodes attached to an input bus, nothing is
     read and 0 will be returned for the frames read variable.

  2) The buffer is silenced by default.

This fixes a bug with ma_engine where it would glitch in the moment
just after the engine is initialized and before a sound or group is
attached.
2021-01-13 22:03:09 +10:00
David Reid 14c5b35b8a Make the read counter for loop detection per output bus. 2021-01-13 21:18:07 +10:00
David Reid e6c2e4441b No longer force fixed sized updates from ma_engine.
This is no longer necessary and just introduces unnecessary latency and
inefficiency due to extra data movement.
2021-01-12 22:16:49 +10:00
David Reid 3f7cf70619 Reimplement ma_engine_play_sound(). 2021-01-12 21:37:45 +10:00
David Reid 2209234af8 Remove ma_effect. 2021-01-12 20:39:08 +10:00
David Reid 0e8a19eef2 Decouple fader, spatializer and panner from ma_effect. 2021-01-12 20:35:30 +10:00
David Reid 56e0e62497 Add support for disabling pitching.
This provides an optimization by allowing processing to bypass the
resampler. Audio data needs to pass through the resampler even for the
case where pitch=1 because it needs to update internal buffers which if
it didn't do, would result in a glitch when moving away from 1.

In practice most sounds won't require individual pitch control, however
in the interest in being consistent with miniaudio's philosophy of
things "Just Working", pitching is enabled by default. Pitching can be
disabled with MA_SOUND_FLAG_DISABLE_PITCH in ma_sound_init_*() and
ma_sound_group_init().
2021-01-12 20:33:53 +10:00
David Reid b5c0f6f6d3 Remove ma_engine_effect.
This is the first step towards decoupling the ma_effect API from the
engine for the eventual removal.

This also fixes bugs regarding channel conversion when processing an
engine node.
2021-01-12 20:09:05 +10:00
David Reid ff22dc3c87 Fix a bug when trying to play a sound with inconsistent channel counts.
This bug happens when the channel count of the data source does not
match the channel count of the engine.
2021-01-12 17:22:44 +10:00
David Reid 400aaf582d Rename ma_sound_set_start/stop_delay() to ma_sound_set_start/stop_time()
This is mainly for consistency with the node API, but also because it
more clearly indicates that it's an absolute time rather than a delay
which sounds more like a relative time.
2021-01-12 16:23:27 +10:00
David Reid d5b25502c1 Migrate start and stop delays to the node graph system.
This changes ma_sound_set_start/stop_delay() to take an absolute time
in frames based on the global clock. Previously these took a relative
time in milliseconds. To use a relative time, add it to the value
returned by ma_engine_get_time(). To use milliseconds, use a standard
sample rate to milliseconds conversion.
2021-01-12 12:40:22 +10:00
David Reid 369fb6fd8f Some small improvements to the resource manager.
These changes are in preparation for fixing some issues relating to
retrieval of channel counts from data sources. The problem relates to
the asynchronous nature of the resource manager and how data sources
may be in the middle of loading when trying to initialize a sound which
results in the channel count not yet being available. The channel count
is necessary in order for the engine to be able to convert the data
source to the channel count of the final output.
2021-01-10 22:38:00 +10:00
David Reid 085728fdcd Remove ma_mixer. 2021-01-10 20:47:22 +10:00
David Reid 66a20f0a87 Remove the old mixing code from ma_engine. 2021-01-10 20:39:36 +10:00
David Reid d72b6f1dca Begin work on integrating the engine with the routing system.
This commit has known issues which will be fixed in the next commits.
2021-01-10 19:48:24 +10:00
David Reid 8da4b4fa8b Add support for timing operations to the node graph system.
This is needed for scheduling frame-exact starting and stopping of
nodes, in addition to any kind of time-based effects required by custom
nodes, such as fading.
2021-01-10 10:56:44 +10:00
David Reid 554c505f9c Work in progress on integrating ma_engine with the routing system.
This is not fully functional as of this commit.
2021-01-09 15:18:46 +10:00
David Reid 3e8a9ec040 Remove the ability to configure the engine's sample format.
The sample format is now always 32-bit floating point. This was done
for simplicity and practicality.
2021-01-09 09:15:26 +10:00
David Reid 72bc5bc043 Update ma_node_output_bus_set_volume() to allow amplification. 2021-01-07 20:44:38 +10:00
David Reid c394348d9a Remove ma_sound_set_effect() and ma_sound_group_set_effect().
Effects will now be implemented by plugging effect nodes into the node
graph at the appropriate location.
2021-01-07 20:43:31 +10:00
David Reid afcb46dbb1 Fix a typo. 2021-01-06 22:11:02 +10:00
David Reid d580e3043f Remove some unnecessary atomics. 2021-01-06 22:06:25 +10:00
David Reid 9f62d69669 Update documentation. 2021-01-06 22:04:39 +10:00
David Reid 79845b5ec6 Update documentation. 2021-01-06 21:27:41 +10:00
David Reid fb1e61cb06 Add ma_node_detach_all_output_buses(). 2021-01-06 21:19:55 +10:00
David Reid fb336f54e3 Make ma_node_detach() private and rename to ma_node_detach_full(). 2021-01-06 21:17:02 +10:00
David Reid bb0e486d95 Simplify node attachment APIs.
With this change, attachment and detachment of a node's output bus is
now consistent:

  * ma_node_attach_output_bus()
  * ma_node_detach_output_bus()

The old function that allowed you to attach the other way around has
been removed as the caller can easily do that themselves by swapping
the order of parameters.
2021-01-06 21:10:42 +10:00
David Reid 4f96309cbf Add experimental loop detection to the routing system. 2021-01-06 19:06:39 +10:00
David Reid c540366921 Improve performance of ma_node_uninit().
This changes the way ma_node_uninit() waits for the audio thread. Now,
instead of waiting for the *entire* graph to complete, it only waits
for it's local processing to complete.
2021-01-05 22:21:56 +10:00
David Reid 61c6e5b12a Typos. 2021-01-03 22:32:52 +10:00
David Reid 02f78d7787 Make channel counts per-bus rather than per-node.
This makes it possible to give individual input and output buses unique
channel counts which might be useful for specific kinds of effects.
2021-01-03 21:44:18 +10:00
David Reid c8e1438b11 Stop pre-converting input channel counts to output channel counts. 2021-01-03 21:03:47 +10:00
David Reid f6c563e523 Merge the new routing infrastructure into miniaudio_engine. 2021-01-03 18:41:40 +10:00
David Reid 1dcdd44088 Fix some errors with the C++ build. 2021-01-03 18:07:17 +10:00
Elias Ku 475d6f1296 Fix issue #252 2020-12-28 14:54:37 +03:00
David Reid 0e45b95e04 Rearrange some function parameters in miniaudio_engine. 2020-12-26 18:04:33 +10:00
David Reid 8095b9bcfb Whitespace. 2020-12-19 21:28:05 +10:00
David Reid ab8d87be23 Clean up some multithreading bugs due to incorrect use of atomics.
Public issue https://github.com/mackron/miniaudio/issues/237
2020-12-19 13:20:34 +10:00
David Reid c07411dde2 Fix a bug in period size calculation. 2020-12-08 07:41:00 +10:00
Eduardo Bart e76283822a Fix sound seek in miniaudio engine 2020-12-05 16:24:11 -03:00