1 #ifndef CORE_MIXER_DEFS_H
2 #define CORE_MIXER_DEFS_H
8 #include "core/bufferline.h"
9 #include "core/resampler_limits.h"
11 struct CubicCoefficients;
12 struct HrtfChannelState;
16 using uint = unsigned int;
17 using float2 = std::array<float,2>;
20 constexpr int MixerFracBits{16};
21 constexpr int MixerFracOne{1 << MixerFracBits};
22 constexpr int MixerFracMask{MixerFracOne - 1};
23 constexpr int MixerFracHalf{MixerFracOne >> 1};
25 constexpr float GainSilenceThreshold{0.00001f}; /* -100dB */
28 enum class Resampler : uint8_t {
40 /* Interpolator state. Kind of a misnomer since the interpolator itself is
41 * stateless. This just keeps it from having to recompute scale-related
42 * mappings for every sample.
45 float sf; /* Scale interpolation factor. */
46 uint m; /* Coefficient count. */
47 uint l; /* Left coefficient offset. */
48 /* Filter coefficients, followed by the phase, scale, and scale-phase
49 * delta coefficients. Starting at phase index 0, each subsequent phase
50 * index follows contiguously.
56 /* Filter coefficients, and coefficient deltas. Starting at phase index 0,
57 * each subsequent phase index follows contiguously.
59 const CubicCoefficients *filter;
67 using ResamplerFunc = void(*)(const InterpState *state, const float *RESTRICT src, uint frac,
68 const uint increment, const al::span<float> dst);
70 ResamplerFunc PrepareResampler(Resampler resampler, uint increment, InterpState *state);
73 template<typename TypeTag, typename InstTag>
74 void Resample_(const InterpState *state, const float *RESTRICT src, uint frac,
75 const uint increment, const al::span<float> dst);
77 template<typename InstTag>
78 void Mix_(const al::span<const float> InSamples, const al::span<FloatBufferLine> OutBuffer,
79 float *CurrentGains, const float *TargetGains, const size_t Counter, const size_t OutPos);
80 template<typename InstTag>
81 void Mix_(const al::span<const float> InSamples, float *OutBuffer, float &CurrentGain,
82 const float TargetGain, const size_t Counter);
84 template<typename InstTag>
85 void MixHrtf_(const float *InSamples, float2 *AccumSamples, const uint IrSize,
86 const MixHrtfFilter *hrtfparams, const size_t BufferSize);
87 template<typename InstTag>
88 void MixHrtfBlend_(const float *InSamples, float2 *AccumSamples, const uint IrSize,
89 const HrtfFilter *oldparams, const MixHrtfFilter *newparams, const size_t BufferSize);
90 template<typename InstTag>
91 void MixDirectHrtf_(const FloatBufferSpan LeftOut, const FloatBufferSpan RightOut,
92 const al::span<const FloatBufferLine> InSamples, float2 *AccumSamples,
93 float *TempBuf, HrtfChannelState *ChanState, const size_t IrSize, const size_t BufferSize);
95 /* Vectorized resampler helpers */
97 inline void InitPosArrays(uint frac, uint increment, uint (&frac_arr)[N], uint (&pos_arr)[N])
101 for(size_t i{1};i < N;i++)
103 const uint frac_tmp{frac_arr[i-1] + increment};
104 pos_arr[i] = pos_arr[i-1] + (frac_tmp>>MixerFracBits);
105 frac_arr[i] = frac_tmp&MixerFracMask;
109 #endif /* CORE_MIXER_DEFS_H */