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 HrtfChannelState
;
15 using uint
= unsigned int;
16 using float2
= std::array
<float,2>;
19 constexpr int MixerFracBits
{12};
20 constexpr int MixerFracOne
{1 << MixerFracBits
};
21 constexpr int MixerFracMask
{MixerFracOne
- 1};
23 constexpr float GainSilenceThreshold
{0.00001f
}; /* -100dB */
26 enum class Resampler
{
38 /* Interpolator state. Kind of a misnomer since the interpolator itself is
39 * stateless. This just keeps it from having to recompute scale-related
40 * mappings for every sample.
43 float sf
; /* Scale interpolation factor. */
44 uint m
; /* Coefficient count. */
45 uint l
; /* Left coefficient offset. */
46 /* Filter coefficients, followed by the phase, scale, and scale-phase
47 * delta coefficients. Starting at phase index 0, each subsequent phase
48 * index follows contiguously.
57 using ResamplerFunc
= float*(*)(const InterpState
*state
, float *RESTRICT src
, uint frac
,
58 uint increment
, const al::span
<float> dst
);
60 ResamplerFunc
PrepareResampler(Resampler resampler
, uint increment
, InterpState
*state
);
63 template<typename TypeTag
, typename InstTag
>
64 float *Resample_(const InterpState
*state
, float *RESTRICT src
, uint frac
, uint increment
,
65 const al::span
<float> dst
);
67 template<typename InstTag
>
68 void Mix_(const al::span
<const float> InSamples
, const al::span
<FloatBufferLine
> OutBuffer
,
69 float *CurrentGains
, const float *TargetGains
, const size_t Counter
, const size_t OutPos
);
71 template<typename InstTag
>
72 void MixHrtf_(const float *InSamples
, float2
*AccumSamples
, const uint IrSize
,
73 const MixHrtfFilter
*hrtfparams
, const size_t BufferSize
);
74 template<typename InstTag
>
75 void MixHrtfBlend_(const float *InSamples
, float2
*AccumSamples
, const uint IrSize
,
76 const HrtfFilter
*oldparams
, const MixHrtfFilter
*newparams
, const size_t BufferSize
);
77 template<typename InstTag
>
78 void MixDirectHrtf_(const FloatBufferSpan LeftOut
, const FloatBufferSpan RightOut
,
79 const al::span
<const FloatBufferLine
> InSamples
, float2
*AccumSamples
,
80 float *TempBuf
, HrtfChannelState
*ChanState
, const size_t IrSize
, const size_t BufferSize
);
82 /* Vectorized resampler helpers */
84 inline void InitPosArrays(uint frac
, uint increment
, uint (&frac_arr
)[N
], uint (&pos_arr
)[N
])
88 for(size_t i
{1};i
< N
;i
++)
90 const uint frac_tmp
{frac_arr
[i
-1] + increment
};
91 pos_arr
[i
] = pos_arr
[i
-1] + (frac_tmp
>>MixerFracBits
);
92 frac_arr
[i
] = frac_tmp
&MixerFracMask
;
96 #endif /* CORE_MIXER_DEFS_H */