2019-10-02 16:53:23 -07:00
|
|
|
#ifndef VOICE_H
|
|
|
|
#define VOICE_H
|
|
|
|
|
2019-10-05 21:23:31 -07:00
|
|
|
#include <array>
|
2020-12-15 23:39:17 -08:00
|
|
|
#include <atomic>
|
2019-10-05 21:23:31 -07:00
|
|
|
|
2020-03-22 11:34:37 -07:00
|
|
|
#include "almalloc.h"
|
2019-10-02 16:53:23 -07:00
|
|
|
#include "alspan.h"
|
|
|
|
#include "alu.h"
|
2020-08-28 00:09:46 -07:00
|
|
|
#include "buffer_storage.h"
|
2020-12-15 23:39:17 -08:00
|
|
|
#include "core/bufferline.h"
|
2020-11-27 19:18:17 -08:00
|
|
|
#include "core/devformat.h"
|
2020-12-04 09:42:13 -08:00
|
|
|
#include "core/filters/biquad.h"
|
|
|
|
#include "core/filters/nfc.h"
|
|
|
|
#include "core/filters/splitter.h"
|
2020-12-12 14:58:09 -08:00
|
|
|
#include "core/mixer/defs.h"
|
2020-12-15 23:39:17 -08:00
|
|
|
#include "core/mixer/hrtfdefs.h"
|
|
|
|
#include "vector.h"
|
2019-10-02 16:53:23 -07:00
|
|
|
|
2020-12-15 23:39:17 -08:00
|
|
|
struct ALCcontext;
|
2020-11-07 08:36:49 -08:00
|
|
|
struct EffectSlot;
|
2020-12-27 10:09:39 -08:00
|
|
|
enum class DistanceModel : unsigned char;
|
2019-10-02 19:13:07 -07:00
|
|
|
|
2020-11-20 01:37:19 -08:00
|
|
|
using uint = unsigned int;
|
|
|
|
|
2019-10-02 16:53:23 -07:00
|
|
|
|
2020-05-21 09:10:32 -07:00
|
|
|
enum class SpatializeMode : unsigned char {
|
2020-11-20 01:37:19 -08:00
|
|
|
Off,
|
|
|
|
On,
|
|
|
|
Auto
|
2019-10-02 16:53:23 -07:00
|
|
|
};
|
|
|
|
|
2019-12-28 11:33:19 -08:00
|
|
|
enum class DirectMode : unsigned char {
|
2020-11-20 01:37:19 -08:00
|
|
|
Off,
|
|
|
|
DropMismatch,
|
|
|
|
RemixMismatch
|
2019-12-28 11:33:19 -08:00
|
|
|
};
|
|
|
|
|
2019-10-02 16:53:23 -07:00
|
|
|
|
|
|
|
enum {
|
|
|
|
AF_None = 0,
|
|
|
|
AF_LowPass = 1,
|
|
|
|
AF_HighPass = 2,
|
|
|
|
AF_BandPass = AF_LowPass | AF_HighPass
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct DirectParams {
|
|
|
|
BiquadFilter LowPass;
|
|
|
|
BiquadFilter HighPass;
|
|
|
|
|
|
|
|
NfcFilter NFCtrlFilter;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
HrtfFilter Old;
|
|
|
|
HrtfFilter Target;
|
2020-12-25 20:52:18 -08:00
|
|
|
alignas(16) std::array<float,HrtfHistoryLength> History;
|
2019-10-02 16:53:23 -07:00
|
|
|
} Hrtf;
|
|
|
|
|
|
|
|
struct {
|
2019-10-05 21:23:31 -07:00
|
|
|
std::array<float,MAX_OUTPUT_CHANNELS> Current;
|
|
|
|
std::array<float,MAX_OUTPUT_CHANNELS> Target;
|
2019-10-02 16:53:23 -07:00
|
|
|
} Gains;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SendParams {
|
|
|
|
BiquadFilter LowPass;
|
|
|
|
BiquadFilter HighPass;
|
|
|
|
|
|
|
|
struct {
|
2019-10-05 21:23:31 -07:00
|
|
|
std::array<float,MAX_OUTPUT_CHANNELS> Current;
|
|
|
|
std::array<float,MAX_OUTPUT_CHANNELS> Target;
|
2019-10-02 16:53:23 -07:00
|
|
|
} Gains;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-03-28 17:20:38 -07:00
|
|
|
struct VoiceProps {
|
2019-10-02 16:53:23 -07:00
|
|
|
float Pitch;
|
|
|
|
float Gain;
|
|
|
|
float OuterGain;
|
|
|
|
float MinGain;
|
|
|
|
float MaxGain;
|
|
|
|
float InnerAngle;
|
|
|
|
float OuterAngle;
|
|
|
|
float RefDistance;
|
|
|
|
float MaxDistance;
|
|
|
|
float RolloffFactor;
|
|
|
|
std::array<float,3> Position;
|
|
|
|
std::array<float,3> Velocity;
|
|
|
|
std::array<float,3> Direction;
|
|
|
|
std::array<float,3> OrientAt;
|
|
|
|
std::array<float,3> OrientUp;
|
|
|
|
bool HeadRelative;
|
|
|
|
DistanceModel mDistanceModel;
|
|
|
|
Resampler mResampler;
|
2019-12-28 11:33:19 -08:00
|
|
|
DirectMode DirectChannels;
|
2019-10-02 16:53:23 -07:00
|
|
|
SpatializeMode mSpatializeMode;
|
|
|
|
|
|
|
|
bool DryGainHFAuto;
|
|
|
|
bool WetGainAuto;
|
|
|
|
bool WetGainHFAuto;
|
2019-10-02 17:07:23 -07:00
|
|
|
float OuterGainHF;
|
2019-10-02 16:53:23 -07:00
|
|
|
|
|
|
|
float AirAbsorptionFactor;
|
|
|
|
float RoomRolloffFactor;
|
|
|
|
float DopplerFactor;
|
|
|
|
|
|
|
|
std::array<float,2> StereoPan;
|
|
|
|
|
|
|
|
float Radius;
|
|
|
|
|
|
|
|
/** Direct filter and auxiliary send info. */
|
|
|
|
struct {
|
|
|
|
float Gain;
|
|
|
|
float GainHF;
|
|
|
|
float HFReference;
|
|
|
|
float GainLF;
|
|
|
|
float LFReference;
|
|
|
|
} Direct;
|
|
|
|
struct SendData {
|
2020-11-07 08:36:49 -08:00
|
|
|
EffectSlot *Slot;
|
2019-10-02 16:53:23 -07:00
|
|
|
float Gain;
|
|
|
|
float GainHF;
|
|
|
|
float HFReference;
|
|
|
|
float GainLF;
|
|
|
|
float LFReference;
|
|
|
|
} Send[MAX_SENDS];
|
|
|
|
};
|
|
|
|
|
2020-03-28 17:20:38 -07:00
|
|
|
struct VoicePropsItem : public VoiceProps {
|
|
|
|
std::atomic<VoicePropsItem*> next{nullptr};
|
2019-10-02 16:53:23 -07:00
|
|
|
|
2020-03-28 17:20:38 -07:00
|
|
|
DEF_NEWDEL(VoicePropsItem)
|
2019-10-02 16:53:23 -07:00
|
|
|
};
|
|
|
|
|
2020-11-20 01:37:19 -08:00
|
|
|
constexpr uint VoiceIsStatic{ 1u<<0};
|
|
|
|
constexpr uint VoiceIsCallback{ 1u<<1};
|
|
|
|
constexpr uint VoiceIsAmbisonic{ 1u<<2}; /* Needs HF scaling for ambisonic upsampling. */
|
|
|
|
constexpr uint VoiceCallbackStopped{1u<<3};
|
|
|
|
constexpr uint VoiceIsFading{ 1u<<4}; /* Use gain stepping for smooth transitions. */
|
|
|
|
constexpr uint VoiceHasHrtf{ 1u<<5};
|
|
|
|
constexpr uint VoiceHasNfc{ 1u<<6};
|
2019-10-02 16:53:23 -07:00
|
|
|
|
2020-03-28 17:20:38 -07:00
|
|
|
struct Voice {
|
2019-10-02 16:53:23 -07:00
|
|
|
enum State {
|
2020-03-04 10:09:44 -08:00
|
|
|
Stopped,
|
|
|
|
Playing,
|
|
|
|
Stopping,
|
|
|
|
Pending
|
2019-10-02 16:53:23 -07:00
|
|
|
};
|
|
|
|
|
2020-03-28 17:20:38 -07:00
|
|
|
std::atomic<VoicePropsItem*> mUpdate{nullptr};
|
2019-10-02 16:53:23 -07:00
|
|
|
|
2020-03-28 17:20:38 -07:00
|
|
|
VoiceProps mProps;
|
2020-02-20 19:18:07 -08:00
|
|
|
|
2020-11-20 01:37:19 -08:00
|
|
|
std::atomic<uint> mSourceID{0u};
|
2019-10-02 16:53:23 -07:00
|
|
|
std::atomic<State> mPlayState{Stopped};
|
2020-02-26 01:48:59 -08:00
|
|
|
std::atomic<bool> mPendingChange{false};
|
2019-10-02 16:53:23 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Source offset in samples, relative to the currently playing buffer, NOT
|
|
|
|
* the whole queue.
|
|
|
|
*/
|
2020-11-20 01:37:19 -08:00
|
|
|
std::atomic<uint> mPosition;
|
2019-10-02 16:53:23 -07:00
|
|
|
/** Fractional (fixed-point) offset to the next sample. */
|
2020-11-20 01:37:19 -08:00
|
|
|
std::atomic<uint> mPositionFrac;
|
2019-10-02 16:53:23 -07:00
|
|
|
|
|
|
|
/* Current buffer queue item being played. */
|
2020-11-19 04:18:25 -08:00
|
|
|
std::atomic<BufferlistItem*> mCurrentBuffer;
|
2019-10-02 16:53:23 -07:00
|
|
|
|
|
|
|
/* Buffer queue item to loop to at end of queue (will be NULL for non-
|
|
|
|
* looping voices).
|
|
|
|
*/
|
2020-11-19 04:18:25 -08:00
|
|
|
std::atomic<BufferlistItem*> mLoopBuffer;
|
2019-10-02 16:53:23 -07:00
|
|
|
|
|
|
|
/* Properties for the attached buffer(s). */
|
|
|
|
FmtChannels mFmtChannels;
|
2021-01-24 09:29:56 -08:00
|
|
|
FmtType mFmtType;
|
2020-11-20 01:37:19 -08:00
|
|
|
uint mFrequency;
|
|
|
|
uint mSampleSize;
|
2019-12-02 12:50:18 -08:00
|
|
|
AmbiLayout mAmbiLayout;
|
2020-08-28 00:09:46 -07:00
|
|
|
AmbiScaling mAmbiScaling;
|
2020-11-20 01:37:19 -08:00
|
|
|
uint mAmbiOrder;
|
2019-10-02 16:53:23 -07:00
|
|
|
|
|
|
|
/** Current target parameters used for mixing. */
|
2020-11-20 01:37:19 -08:00
|
|
|
uint mStep{0};
|
2019-10-02 16:53:23 -07:00
|
|
|
|
|
|
|
ResamplerFunc mResampler;
|
|
|
|
|
|
|
|
InterpState mResampleState;
|
|
|
|
|
2020-11-20 01:37:19 -08:00
|
|
|
uint mFlags{};
|
|
|
|
uint mNumCallbackSamples{0};
|
2019-10-02 16:53:23 -07:00
|
|
|
|
2019-10-05 16:11:38 -07:00
|
|
|
struct TargetData {
|
2019-10-02 16:53:23 -07:00
|
|
|
int FilterType;
|
|
|
|
al::span<FloatBufferLine> Buffer;
|
|
|
|
};
|
2019-10-05 16:11:38 -07:00
|
|
|
TargetData mDirect;
|
|
|
|
std::array<TargetData,MAX_SENDS> mSend;
|
2019-10-02 16:53:23 -07:00
|
|
|
|
|
|
|
struct ChannelData {
|
2020-11-28 03:38:20 -08:00
|
|
|
alignas(16) std::array<float,MaxResamplerPadding> mPrevSamples;
|
2019-10-02 16:53:23 -07:00
|
|
|
|
2019-10-02 17:07:23 -07:00
|
|
|
float mAmbiScale;
|
2019-10-02 16:53:23 -07:00
|
|
|
BandSplitter mAmbiSplitter;
|
|
|
|
|
|
|
|
DirectParams mDryParams;
|
|
|
|
std::array<SendParams,MAX_SENDS> mWetParams;
|
|
|
|
};
|
2020-03-25 21:06:24 -07:00
|
|
|
al::vector<ChannelData> mChans{2};
|
2019-10-02 16:53:23 -07:00
|
|
|
|
2020-03-28 17:20:38 -07:00
|
|
|
Voice() = default;
|
|
|
|
Voice(const Voice&) = delete;
|
|
|
|
~Voice() { delete mUpdate.exchange(nullptr, std::memory_order_acq_rel); }
|
|
|
|
Voice& operator=(const Voice&) = delete;
|
2019-10-02 16:53:23 -07:00
|
|
|
|
2020-11-20 01:37:19 -08:00
|
|
|
void mix(const State vstate, ALCcontext *Context, const uint SamplesToDo);
|
2020-03-22 11:34:37 -07:00
|
|
|
|
2020-03-28 17:20:38 -07:00
|
|
|
DEF_NEWDEL(Voice)
|
2019-10-02 16:53:23 -07:00
|
|
|
};
|
|
|
|
|
2020-12-03 23:09:23 -08:00
|
|
|
extern Resampler ResamplerDefault;
|
|
|
|
|
2019-10-02 16:53:23 -07:00
|
|
|
#endif /* VOICE_H */
|