13 #include "aloptional.h"
15 #include "bufferline.h"
16 #include "buffer_storage.h"
17 #include "devformat.h"
18 #include "filters/biquad.h"
19 #include "filters/nfc.h"
20 #include "filters/splitter.h"
21 #include "mixer/defs.h"
22 #include "mixer/hrtfdefs.h"
23 #include "resampler_limits.h"
24 #include "uhjfilter.h"
30 enum class DistanceModel
: unsigned char;
32 using uint
= unsigned int;
38 enum class SpatializeMode
: unsigned char {
44 enum class DirectMode
: unsigned char {
51 /* Maximum number of extra source samples that may need to be loaded, for
52 * resampling or conversion purposes.
54 constexpr uint MaxPostVoiceLoad
{MaxResamplerEdge
+ UhjDecoder::sFilterDelay
};
61 AF_BandPass
= AF_LowPass
| AF_HighPass
67 BiquadFilter HighPass
;
69 NfcFilter NFCtrlFilter
;
74 alignas(16) std::array
<float,HrtfHistoryLength
> History
;
78 std::array
<float,MAX_OUTPUT_CHANNELS
> Current
;
79 std::array
<float,MAX_OUTPUT_CHANNELS
> Target
;
85 BiquadFilter HighPass
;
88 std::array
<float,MAX_OUTPUT_CHANNELS
> Current
;
89 std::array
<float,MAX_OUTPUT_CHANNELS
> Target
;
94 struct VoiceBufferItem
{
95 std::atomic
<VoiceBufferItem
*> mNext
{nullptr};
97 CallbackType mCallback
{nullptr};
98 void *mUserData
{nullptr};
104 al::byte
*mSamples
{nullptr};
119 std::array
<float,3> Position
;
120 std::array
<float,3> Velocity
;
121 std::array
<float,3> Direction
;
122 std::array
<float,3> OrientAt
;
123 std::array
<float,3> OrientUp
;
125 DistanceModel mDistanceModel
;
126 Resampler mResampler
;
127 DirectMode DirectChannels
;
128 SpatializeMode mSpatializeMode
;
135 float AirAbsorptionFactor
;
136 float RoomRolloffFactor
;
139 std::array
<float,2> StereoPan
;
144 /** Direct filter and auxiliary send info. */
162 struct VoicePropsItem
: public VoiceProps
{
163 std::atomic
<VoicePropsItem
*> next
{nullptr};
165 DEF_NEWDEL(VoicePropsItem
)
172 VoiceCallbackStopped
,
188 std::atomic
<VoicePropsItem
*> mUpdate
{nullptr};
192 std::atomic
<uint
> mSourceID
{0u};
193 std::atomic
<State
> mPlayState
{Stopped
};
194 std::atomic
<bool> mPendingChange
{false};
197 * Source offset in samples, relative to the currently playing buffer, NOT
200 std::atomic
<uint
> mPosition
;
201 /** Fractional (fixed-point) offset to the next sample. */
202 std::atomic
<uint
> mPositionFrac
;
204 /* Current buffer queue item being played. */
205 std::atomic
<VoiceBufferItem
*> mCurrentBuffer
;
207 /* Buffer queue item to loop to at end of queue (will be NULL for non-
210 std::atomic
<VoiceBufferItem
*> mLoopBuffer
;
212 /* Properties for the attached buffer(s). */
213 FmtChannels mFmtChannels
;
216 uint mFrameStep
; /**< In steps of the sample type size. */
217 uint mFrameSize
; /**< In bytes. */
218 AmbiLayout mAmbiLayout
;
219 AmbiScaling mAmbiScaling
;
222 std::unique_ptr
<DecoderBase
> mDecoder
;
224 /** Current target parameters used for mixing. */
227 ResamplerFunc mResampler
;
229 InterpState mResampleState
;
231 std::bitset
<VoiceFlagCount
> mFlags
{};
232 uint mNumCallbackSamples
{0};
236 al::span
<FloatBufferLine
> Buffer
;
239 std::array
<TargetData
,MAX_SENDS
> mSend
;
241 /* The first MaxResamplerPadding/2 elements are the sample history from the
242 * previous mix, with an additional MaxResamplerPadding/2 elements that are
243 * now current (which may be overwritten if the buffer data is still
246 using HistoryLine
= std::array
<float,MaxResamplerPadding
>;
247 al::vector
<HistoryLine
,16> mPrevSamples
{2};
250 float mAmbiHFScale
, mAmbiLFScale
;
251 BandSplitter mAmbiSplitter
;
253 DirectParams mDryParams
;
254 std::array
<SendParams
,MAX_SENDS
> mWetParams
;
256 al::vector
<ChannelData
> mChans
{2};
261 Voice(const Voice
&) = delete;
262 Voice
& operator=(const Voice
&) = delete;
264 void mix(const State vstate
, ContextBase
*Context
, const uint SamplesToDo
);
266 void prepare(DeviceBase
*device
);
268 static void InitMixer(al::optional
<std::string
> resampler
);
273 extern Resampler ResamplerDefault
;
275 #endif /* CORE_VOICE_H */