2019-07-28 21:29:59 -07:00
|
|
|
#ifndef AL_SOURCE_H
|
|
|
|
#define AL_SOURCE_H
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2018-12-26 22:27:34 -08:00
|
|
|
#include <array>
|
2019-07-28 21:29:59 -07:00
|
|
|
#include <atomic>
|
|
|
|
#include <cstddef>
|
2019-07-31 09:20:53 -07:00
|
|
|
#include <iterator>
|
2020-03-23 15:04:26 -07:00
|
|
|
#include <limits>
|
2021-01-25 05:07:02 -08:00
|
|
|
#include <deque>
|
2018-12-26 22:27:34 -08:00
|
|
|
|
2019-07-28 21:29:59 -07:00
|
|
|
#include "AL/al.h"
|
|
|
|
#include "AL/alc.h"
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2019-07-28 21:29:59 -07:00
|
|
|
#include "alcontext.h"
|
2019-08-11 03:34:35 -07:00
|
|
|
#include "almalloc.h"
|
2019-07-28 21:29:59 -07:00
|
|
|
#include "alnumeric.h"
|
|
|
|
#include "alu.h"
|
2020-03-23 15:04:26 -07:00
|
|
|
#include "math_defs.h"
|
2019-07-28 21:29:59 -07:00
|
|
|
#include "vector.h"
|
2020-12-27 16:14:11 -08:00
|
|
|
#include "voice.h"
|
2017-03-02 00:49:03 -08:00
|
|
|
|
2014-08-20 21:35:18 -07:00
|
|
|
struct ALbuffer;
|
2018-12-24 19:29:01 -08:00
|
|
|
struct ALeffectslot;
|
2014-08-20 21:35:18 -07:00
|
|
|
|
2021-01-25 05:07:02 -08:00
|
|
|
namespace al {
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
using deque = std::deque<T, al::allocator<T>>;
|
|
|
|
|
|
|
|
} // namespace al
|
|
|
|
|
2010-11-26 02:53:15 -08:00
|
|
|
|
2019-07-28 21:29:59 -07:00
|
|
|
#define DEFAULT_SENDS 2
|
|
|
|
|
2019-08-02 12:38:20 -07:00
|
|
|
#define INVALID_VOICE_IDX static_cast<ALuint>(-1)
|
2019-07-28 21:29:59 -07:00
|
|
|
|
2021-01-25 09:08:49 -08:00
|
|
|
struct ALbufferQueueItem : public VoiceBufferItem {
|
|
|
|
ALbuffer *mBuffer{nullptr};
|
|
|
|
|
|
|
|
DISABLE_ALLOC()
|
|
|
|
};
|
|
|
|
|
2014-03-18 19:56:25 -07:00
|
|
|
|
2018-12-24 19:29:01 -08:00
|
|
|
struct ALsource {
|
2012-04-26 03:26:22 -07:00
|
|
|
/** Source properties. */
|
2020-03-23 15:04:26 -07:00
|
|
|
float Pitch{1.0f};
|
|
|
|
float Gain{1.0f};
|
|
|
|
float OuterGain{0.0f};
|
|
|
|
float MinGain{0.0f};
|
|
|
|
float MaxGain{1.0f};
|
|
|
|
float InnerAngle{360.0f};
|
|
|
|
float OuterAngle{360.0f};
|
|
|
|
float RefDistance{1.0f};
|
|
|
|
float MaxDistance{std::numeric_limits<float>::max()};
|
|
|
|
float RolloffFactor{1.0f};
|
|
|
|
std::array<float,3> Position{{0.0f, 0.0f, 0.0f}};
|
|
|
|
std::array<float,3> Velocity{{0.0f, 0.0f, 0.0f}};
|
|
|
|
std::array<float,3> Direction{{0.0f, 0.0f, 0.0f}};
|
|
|
|
std::array<float,3> OrientAt{{0.0f, 0.0f, -1.0f}};
|
|
|
|
std::array<float,3> OrientUp{{0.0f, 1.0f, 0.0f}};
|
|
|
|
bool HeadRelative{false};
|
|
|
|
bool Looping{false};
|
|
|
|
DistanceModel mDistanceModel{DistanceModel::Default};
|
|
|
|
Resampler mResampler{ResamplerDefault};
|
|
|
|
DirectMode DirectChannels{DirectMode::Off};
|
2020-05-21 09:10:32 -07:00
|
|
|
SpatializeMode mSpatialize{SpatializeMode::Auto};
|
2020-03-23 15:04:26 -07:00
|
|
|
|
|
|
|
bool DryGainHFAuto{true};
|
|
|
|
bool WetGainAuto{true};
|
|
|
|
bool WetGainHFAuto{true};
|
|
|
|
float OuterGainHF{1.0f};
|
|
|
|
|
|
|
|
float AirAbsorptionFactor{0.0f};
|
|
|
|
float RoomRolloffFactor{0.0f};
|
|
|
|
float DopplerFactor{1.0f};
|
2008-07-15 02:33:05 -07:00
|
|
|
|
2016-03-25 14:40:44 -07:00
|
|
|
/* NOTE: Stereo pan angles are specified in radians, counter-clockwise
|
|
|
|
* rather than clockwise.
|
|
|
|
*/
|
2020-03-23 15:04:26 -07:00
|
|
|
std::array<float,2> StereoPan{{Deg2Rad( 30.0f), Deg2Rad(-30.0f)}};
|
2016-03-25 14:40:44 -07:00
|
|
|
|
2020-03-23 15:04:26 -07:00
|
|
|
float Radius{0.0f};
|
2014-07-08 09:13:35 -07:00
|
|
|
|
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
|
|
|
/** Direct filter and auxiliary send info. */
|
|
|
|
struct {
|
2020-03-23 15:04:26 -07:00
|
|
|
float Gain;
|
|
|
|
float GainHF;
|
|
|
|
float HFReference;
|
|
|
|
float GainLF;
|
|
|
|
float LFReference;
|
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
|
|
|
} Direct;
|
2018-11-20 12:25:15 -08:00
|
|
|
struct SendData {
|
2018-12-24 19:29:01 -08:00
|
|
|
ALeffectslot *Slot;
|
2020-03-23 15:04:26 -07:00
|
|
|
float Gain;
|
|
|
|
float GainHF;
|
|
|
|
float HFReference;
|
|
|
|
float GainLF;
|
|
|
|
float LFReference;
|
2018-11-20 12:25:15 -08:00
|
|
|
};
|
2020-02-25 06:39:03 -08:00
|
|
|
std::array<SendData,MAX_SENDS> Send;
|
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
|
|
|
|
2012-04-26 03:26:22 -07:00
|
|
|
/**
|
|
|
|
* Last user-specified offset, and the offset type (bytes, samples, or
|
|
|
|
* seconds).
|
|
|
|
*/
|
2020-03-23 15:04:26 -07:00
|
|
|
double Offset{0.0};
|
|
|
|
ALenum OffsetType{AL_NONE};
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2012-04-26 03:26:22 -07:00
|
|
|
/** Source type (static, streaming, or undetermined) */
|
2019-09-12 11:33:04 -07:00
|
|
|
ALenum SourceType{AL_UNDETERMINED};
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2012-04-26 03:26:22 -07:00
|
|
|
/** Source state (initial, playing, paused, or stopped) */
|
2019-08-02 12:38:20 -07:00
|
|
|
ALenum state{AL_INITIAL};
|
2012-04-26 03:26:22 -07:00
|
|
|
|
2017-02-27 15:35:15 -08:00
|
|
|
/** Source Buffer Queue head. */
|
2021-01-25 09:08:49 -08:00
|
|
|
al::deque<ALbufferQueueItem> mQueue;
|
2016-07-31 23:42:30 -07:00
|
|
|
|
2019-02-04 19:59:19 -08:00
|
|
|
std::atomic_flag PropsClean;
|
2016-11-23 01:31:13 -08:00
|
|
|
|
2018-02-01 23:56:35 -08:00
|
|
|
/* Index into the context's Voices array. Lazily updated, only checked and
|
|
|
|
* reset when looking up the voice.
|
|
|
|
*/
|
2019-08-02 12:38:20 -07:00
|
|
|
ALuint VoiceIdx{INVALID_VOICE_IDX};
|
2018-02-01 23:56:35 -08:00
|
|
|
|
2012-04-26 03:26:22 -07:00
|
|
|
/** Self ID */
|
2019-08-02 12:38:20 -07:00
|
|
|
ALuint id{0};
|
2018-11-20 12:25:15 -08:00
|
|
|
|
|
|
|
|
2020-02-25 06:39:03 -08:00
|
|
|
ALsource();
|
2018-11-20 12:25:15 -08:00
|
|
|
~ALsource();
|
|
|
|
|
|
|
|
ALsource(const ALsource&) = delete;
|
|
|
|
ALsource& operator=(const ALsource&) = delete;
|
2020-03-23 16:00:50 -07:00
|
|
|
|
|
|
|
DISABLE_ALLOC()
|
2018-12-24 19:29:01 -08:00
|
|
|
};
|
2007-11-13 18:02:18 -08:00
|
|
|
|
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
|
|
|
void UpdateAllSourceProps(ALCcontext *context);
|
2017-02-13 21:18:18 -08:00
|
|
|
|
2007-11-13 18:02:18 -08:00
|
|
|
#endif
|