Commit Graph

169 Commits

Author SHA1 Message Date
Chris Robinson
a16739f765 Properly defer effect slot changes
Note that this now also causes all playing sources to update when an effect
slot is updated. This is a bit wasteful, as it should only need to re-update
sources that are using the effect slot (and only when a relevant property is
changed), but it's good enough. Especially with deferring since all playing
sources are going to get updated on the process call anyway.
2016-08-25 06:17:36 -07:00
Chris Robinson
4e4e597fa5 Track all references for effect states
This allows us to not have to play around with trying to avoid duplicate state
pointers, since the reference count will ensure they're deleted as appropriate.
The only caveat is that the mixer is not allowed to decrement references, since
that can cause the object to be freed (which the mixer code is not allowed to
do).
2016-08-25 04:57:58 -07:00
Chris Robinson
0fbf34fb45 Add a ref count to ALeffectState
This is mostly just reorganizing the effects to call the Construct method which
initializes the ref count.
2016-08-25 03:49:57 -07:00
Chris Robinson
dc8b7814c7 Avoid resupplying unneeded source updates
The source's voice holds a copy of the last properties it received, so listener
updates can make sources recalculate internal properties from that stored copy.
2016-08-23 18:56:01 -07:00
Chris Robinson
d2eb866abe Avoid a NULL deref when creating 0 auxiliary effect slots 2016-07-26 04:54:27 -07:00
Chris Robinson
25d1b7bdba Remove broken autowah effect code
It's been disabled forever, and I have no idea how to make it work properly.
Better to just redo it when making something that works.
2016-07-26 03:45:25 -07:00
Chris Robinson
b495d80f56 Avoid using memcpy to copy a single struct 2016-07-06 13:33:40 -07:00
Chris Robinson
8f4d6c48ce Use separate arrays for UIntMap keys and values 2016-07-04 20:35:32 -07:00
Chris Robinson
4802465f1a Hold the effectslot map lock while handling it 2016-05-29 02:47:54 -07:00
Chris Robinson
8aa4a74a7b Use a linked list for active effect slots 2016-05-29 01:40:16 -07:00
Chris Robinson
800e38bac6 Use the backend lock for the effectstate's deviceUpdate call 2016-05-27 19:40:54 -07:00
Chris Robinson
c522658d19 Avoid duplicate effect state objects in the freelist
If an unapplied update was superceded, it would be placed in the freelist with
its effect state object intact. This would cause another update with the same
effect state object to be placed into the freelist as well, or worse, cause it
to get deleted while in use when the container had its effect state cleared.
2016-05-15 13:50:56 -07:00
Chris Robinson
576c1116a6 Avoid using a flag to specify if the effect state needs to be updated
This fixes a potential missed state change if an update with a new state got
replaced with one that doesn't.
2016-05-15 01:19:05 -07:00
Chris Robinson
b3338d25f6 Provide asynchronous property updates for sources
This necessitates a change in how source updates are handled. Rather than just
being able to update sources when a dependent object state is changed (e.g. a
listener gain change), now all source updates must be proactively provided.
Consequently, apps that do not utilize any deferring (AL_SOFT_defer_updates or
alcSuspendContext/alcProcessContext) may utilize more CPU since it'll be
filling out more update containers for the mixer thread to use.

The upside is that there's less blocking between the app's calling thread and
the mixer thread, particularly for vectors and other multi-value properties
(filters and sends). Deferring behavior when used is also improved, since
updates that shouldn't be applied yet are simply not provided. And when they
are provided, the mixer doesn't have to ignore them, meaning the actual
deferring of a context doesn't have to synchrnously force an update -- the
process call will send any pending updates, which the mixer will apply even if
another deferral occurs before the mixer runs, because it'll still be there
waiting on the next mixer invocation.

There is one slight bug introduced by this commit. When a listener change is
made, or changes to multiple sources while updates are being deferred, it is
possible for the mixer to run while the sources are prepping their updates,
causing some of the source updates to be seen before the other. This will be
fixed in short order.
2016-05-14 23:43:40 -07:00
Chris Robinson
59cd6230a6 Properly load the effect state pointer from the property container 2016-05-13 00:24:26 -07:00
Chris Robinson
9e6d8342de Hold the effect and filter maps while handling effects and filters 2016-05-12 23:12:11 -07:00
Chris Robinson
210e150601 Avoid updating the effect state object if it's not changed 2016-05-12 19:05:06 -07:00
Chris Robinson
ef0d4f8210 Provide (mostly) lockless updates for effect slots
Similar to the listener, separate containers are provided atomically for the
mixer thread to apply updates without needing to block, and a free-list is used
to reuse container objects.

A couple things to note. First, the lock is still used when the effect state's
deviceUpdate method is called to prevent asynchronous calls to reset the device
from interfering. This can be fixed by using the list lock in ALc.c instead.

Secondly, old effect states aren't immediately deleted when the effect type
changes (the actual type, not just its properties). This is because the mixer
thread is intended to be real-time safe, and so can't be freeing anything. They
are cleared away when updates reuse the container they were kept in, and they
don't incur any extra processing cost, but there may be cases where the memory
is kept around until the effect slot is deleted.
2016-05-12 18:41:33 -07:00
Chris Robinson
186b54aa3d Use a lockless method for updating listener and context properties
This uses a separate container to provide the relevant properties to the
internal update method, using atomic pointer swaps. A free-list is used to
avoid having too many individual containers.

This allows the mixer to update the internal listener properties without
requiring the lock to protect against async updates. It also allows concurrent
read access to the user-facing property values, even the multi-value ones (e.g.
the vectors).
2016-05-11 21:02:11 -07:00
Chris Robinson
f4ff5fc106 Shorten VECTOR_ITER_ macros to VECTOR_ 2016-04-15 12:22:54 -07:00
Chris Robinson
2ccc1d1d8a Move the aligned malloc functions to the common lib 2016-03-29 00:44:58 -07:00
Chris Robinson
ce575718ef Store the effect's output buffer in the effect state 2016-03-17 10:10:26 -07:00
Chris Robinson
c1f87414c5 Mix to multichannel for effects
This mixes to a 4-channel first-order ambisonics buffer. With ACN ordering and
N3D scaling, this makes it easy to remain compatible with effects that only
care about mono input since channel 0 is an unattenuated mono signal.
2016-01-28 00:02:46 -08:00
François Cami
3c13e1e333 Update COPYING to the latest https://www.gnu.org/licenses/old-licenses/lgpl-2.0.txt to fix the FSF' address Fix the FSF' address in the source 2014-08-18 11:34:29 -07:00
Chris Robinson
f5194a9d8e Use an ATOMIC_INIT macro instead of ATOMIC_LOAD_UNSAFE 2014-08-03 00:26:21 -07:00
Chris Robinson
531c0d8e6b Explicitly pass the address of atomics and parameters that can be modified 2014-07-26 03:00:49 -07:00
Chris Robinson
e4b779c492 Use generic atomics in more places 2014-07-22 18:57:51 -07:00
Chris Robinson
5a339a2a5b Add macros for generic atomic functionality 2014-07-22 00:20:28 -07:00
Chris Robinson
23979ac648 Use VECTOR_FIND_IF instead of a manual loop 2014-07-06 05:16:44 -07:00
Chris Robinson
d0a64fe191 Don't require pre-declaring vector types 2014-07-06 03:27:39 -07:00
Chris Robinson
1d2504d12e Make RefCount a non-integer type
It should only be accessed through the appropriate functions to ensure proper
atomicity.
2014-05-14 02:47:07 -07:00
Chris Robinson
e76bc53d37 Insert all new effect slots into the active effect slots at once 2014-04-10 20:49:01 -07:00
Chris Robinson
72986882f5 Remove the click removal buffers for auxiliary effect slots 2014-03-23 16:28:55 -07:00
Chris Robinson
8c33b4d742 Increase the vector reserve as needed when pushing in new items 2014-03-21 16:35:38 -07:00
Chris Robinson
ff63188cc2 Add a generic vector interface and use it for the active effect slots 2014-03-21 01:23:01 -07:00
Chris Robinson
d3c70e63b4 Use C99 inline in more places 2013-11-04 13:44:46 -08:00
Chris Robinson
9760a592b2 Rename VCALL and VCALL0 to V and V0 2013-11-02 17:30:28 -07:00
Chris Robinson
034935b2e1 Modify how VCALL is handled
Now instead of specifying the arguments as a third argument to the macro, like
VCALL(object,function,(arg1, arg2));
they are specified separately after the macro, like
VCALL(object,function)(arg1, arg2);

Also, VCALL_NOARGS has been removed in favor of VCALL0, which behaves like
above but expects an empty argument list (a separate macro is needed to work
around preprocessor limitations).
2013-10-28 11:06:04 -07:00
Chris Robinson
c787a9bf74 Remove al_try from alAuxEffectSlot.c 2013-10-07 11:30:11 -07:00
Chris Robinson
41175ec84c Implement the Compressor effect 2013-10-03 07:55:12 -07:00
Chris Robinson
99fa5911bc Implement the Autowah effect. 2013-10-03 03:37:03 -07:00
Chris Robinson
52096234e1 Limit the source step to 10
This means the combination of the buffer frequency, source pitch, and
doppler shift can't exceed 10x the device playback frequency.

This is needed to keep the mixer from starving with a really high
increment, causing small DstBufferSize values that require a lot of
iterations.
2013-07-02 06:57:27 -07:00
Chris Robinson
764e3aa496 Fix up the naming convention of effect methods 2013-05-29 11:17:45 -07:00
Chris Robinson
e96cc656e9 Use C99's inline instead of __inline 2013-05-28 22:27:07 -07:00
Chris Robinson
0ad71a67d4 Store pointers to the getFactory funcs in the map 2013-05-27 13:41:16 -07:00
Chris Robinson
334a7c1d59 Cleanup the ALeffectStateFactory_create methods
Get rid of the ALeffectStateFactory_create macro, and use the VCALL_NOARGS
helper (requires adding the 'this' factory parameter).
2013-05-27 13:16:17 -07:00
Chris Robinson
9e84f38a46 Use generic VCALL[_NOARGS] macros instead of type-specific wrappers 2013-05-27 11:48:29 -07:00
Chris Robinson
d1c5599c8e Use an ALeffectProps union to store the effect properties 2013-05-25 22:07:31 -07:00
Chris Robinson
f667c028e6 Move the AL_EFFECT_NULL state into a separate file 2013-05-23 18:50:07 -07:00
Chris Robinson
52efb8d7f4 Use restrict instead of RESTRICT 2013-05-22 15:11:39 -07:00