Use spans instead of references to arrays
parent
72c4dd4d10
commit
dfe627133c
|
@ -154,9 +154,9 @@ struct ChanMap {
|
|||
float elevation;
|
||||
};
|
||||
|
||||
using HrtfDirectMixerFunc = void(*)(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
|
||||
const al::span<const FloatBufferLine> InSamples, float2 *AccumSamples,
|
||||
float *TempBuf, HrtfChannelState *ChanState, const size_t IrSize, const size_t BufferSize);
|
||||
using HrtfDirectMixerFunc = void(*)(const FloatBufferSpan LeftOut, const FloatBufferSpan RightOut,
|
||||
const al::span<const FloatBufferLine> InSamples, float2 *AccumSamples, float *TempBuf,
|
||||
HrtfChannelState *ChanState, const size_t IrSize, const size_t BufferSize);
|
||||
|
||||
HrtfDirectMixerFunc MixDirectHrtf{MixDirectHrtf_<CTag>};
|
||||
|
||||
|
|
|
@ -285,7 +285,7 @@ void DirectHrtfState::build(const HrtfStore *Hrtf, const uint irSize,
|
|||
{
|
||||
using double2 = std::array<double,2>;
|
||||
struct ImpulseResponse {
|
||||
const HrirArray &hrir;
|
||||
const ConstHrirSpan hrir;
|
||||
uint ldelay, rdelay;
|
||||
};
|
||||
|
||||
|
@ -341,7 +341,7 @@ void DirectHrtfState::build(const HrtfStore *Hrtf, const uint irSize,
|
|||
auto tmpres = al::vector<std::array<double2,HrirLength>>(mChannels.size());
|
||||
for(size_t c{0u};c < AmbiPoints.size();++c)
|
||||
{
|
||||
const HrirArray &hrir{impres[c].hrir};
|
||||
const ConstHrirSpan hrir{impres[c].hrir};
|
||||
const uint ldelay{hrir_delay_round(impres[c].ldelay - min_delay)};
|
||||
const uint rdelay{hrir_delay_round(impres[c].rdelay - min_delay)};
|
||||
|
||||
|
|
|
@ -359,14 +359,14 @@ void DoHrtfMix(const float *samples, const uint DstBufferSize, DirectParams &par
|
|||
const float a{static_cast<float>(fademix) / static_cast<float>(Counter)};
|
||||
gain = lerp(parms.Hrtf.Old.Gain, TargetGain, a);
|
||||
}
|
||||
MixHrtfFilter hrtfparams;
|
||||
hrtfparams.Coeffs = &parms.Hrtf.Target.Coeffs;
|
||||
hrtfparams.Delay = parms.Hrtf.Target.Delay;
|
||||
hrtfparams.Gain = 0.0f;
|
||||
hrtfparams.GainStep = gain / static_cast<float>(fademix);
|
||||
|
||||
MixHrtfFilter hrtfparams{
|
||||
parms.Hrtf.Target.Coeffs,
|
||||
parms.Hrtf.Target.Delay,
|
||||
0.0f, gain / static_cast<float>(fademix)};
|
||||
MixHrtfBlendSamples(HrtfSamples, AccumSamples+OutPos, IrSize, &parms.Hrtf.Old, &hrtfparams,
|
||||
fademix);
|
||||
|
||||
/* Update the old parameters with the result. */
|
||||
parms.Hrtf.Old = parms.Hrtf.Target;
|
||||
parms.Hrtf.Old.Gain = gain;
|
||||
|
@ -387,12 +387,13 @@ void DoHrtfMix(const float *samples, const uint DstBufferSize, DirectParams &par
|
|||
gain = lerp(parms.Hrtf.Old.Gain, TargetGain, a);
|
||||
}
|
||||
|
||||
MixHrtfFilter hrtfparams;
|
||||
hrtfparams.Coeffs = &parms.Hrtf.Target.Coeffs;
|
||||
hrtfparams.Delay = parms.Hrtf.Target.Delay;
|
||||
hrtfparams.Gain = parms.Hrtf.Old.Gain;
|
||||
hrtfparams.GainStep = (gain - parms.Hrtf.Old.Gain) / static_cast<float>(todo);
|
||||
MixHrtfFilter hrtfparams{
|
||||
parms.Hrtf.Target.Coeffs,
|
||||
parms.Hrtf.Target.Delay,
|
||||
parms.Hrtf.Old.Gain,
|
||||
(gain - parms.Hrtf.Old.Gain) / static_cast<float>(todo)};
|
||||
MixHrtfSamples(HrtfSamples+fademix, AccumSamples+OutPos, IrSize, &hrtfparams, todo);
|
||||
|
||||
/* Store the now-current gain for next time. */
|
||||
parms.Hrtf.Old.Gain = gain;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include <array>
|
||||
|
||||
#include "alspan.h"
|
||||
|
||||
/* Size for temporary storage of buffer data, in floats. Larger values need
|
||||
* more memory and are harder on cache, while smaller values may need more
|
||||
* iterations for mixing.
|
||||
|
@ -10,5 +12,6 @@
|
|||
constexpr int BufferLineSize{1024};
|
||||
|
||||
using FloatBufferLine = std::array<float,BufferLineSize>;
|
||||
using FloatBufferSpan = al::span<float,BufferLineSize>;
|
||||
|
||||
#endif /* CORE_BUFFERLINE_H */
|
||||
|
|
|
@ -80,7 +80,7 @@ template<typename InstTag>
|
|||
void MixHrtfBlend_(const float *InSamples, float2 *AccumSamples, const uint IrSize,
|
||||
const HrtfFilter *oldparams, const MixHrtfFilter *newparams, const size_t BufferSize);
|
||||
template<typename InstTag>
|
||||
void MixDirectHrtf_(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
|
||||
void MixDirectHrtf_(const FloatBufferSpan LeftOut, const FloatBufferSpan RightOut,
|
||||
const al::span<const FloatBufferLine> InSamples, float2 *AccumSamples,
|
||||
float *TempBuf, HrtfChannelState *ChanState, const size_t IrSize, const size_t BufferSize);
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
using uint = unsigned int;
|
||||
|
||||
using ApplyCoeffsT = void(&)(float2 *RESTRICT Values, const size_t irSize,
|
||||
const HrirArray &Coeffs, const float left, const float right);
|
||||
const ConstHrirSpan Coeffs, const float left, const float right);
|
||||
|
||||
template<ApplyCoeffsT ApplyCoeffs>
|
||||
inline void MixHrtfBase(const float *InSamples, float2 *RESTRICT AccumSamples, const size_t IrSize,
|
||||
|
@ -20,7 +20,7 @@ inline void MixHrtfBase(const float *InSamples, float2 *RESTRICT AccumSamples, c
|
|||
{
|
||||
ASSUME(BufferSize > 0);
|
||||
|
||||
const HrirArray &Coeffs = *hrtfparams->Coeffs;
|
||||
const ConstHrirSpan Coeffs{hrtfparams->Coeffs};
|
||||
const float gainstep{hrtfparams->GainStep};
|
||||
const float gain{hrtfparams->Gain};
|
||||
|
||||
|
@ -45,9 +45,9 @@ inline void MixHrtfBlendBase(const float *InSamples, float2 *RESTRICT AccumSampl
|
|||
{
|
||||
ASSUME(BufferSize > 0);
|
||||
|
||||
const auto &OldCoeffs = oldparams->Coeffs;
|
||||
const ConstHrirSpan OldCoeffs{oldparams->Coeffs};
|
||||
const float oldGainStep{oldparams->Gain / static_cast<float>(BufferSize)};
|
||||
const auto &NewCoeffs = *newparams->Coeffs;
|
||||
const ConstHrirSpan NewCoeffs{newparams->Coeffs};
|
||||
const float newGainStep{newparams->GainStep};
|
||||
|
||||
if LIKELY(oldparams->Gain > GainSilenceThreshold)
|
||||
|
@ -84,7 +84,7 @@ inline void MixHrtfBlendBase(const float *InSamples, float2 *RESTRICT AccumSampl
|
|||
}
|
||||
|
||||
template<ApplyCoeffsT ApplyCoeffs>
|
||||
inline void MixDirectHrtfBase(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
|
||||
inline void MixDirectHrtfBase(const FloatBufferSpan LeftOut, const FloatBufferSpan RightOut,
|
||||
const al::span<const FloatBufferLine> InSamples, float2 *RESTRICT AccumSamples,
|
||||
float *TempBuf, HrtfChannelState *ChanState, const size_t IrSize, const size_t BufferSize)
|
||||
{
|
||||
|
@ -133,7 +133,7 @@ inline void MixDirectHrtfBase(FloatBufferLine &LeftOut, FloatBufferLine &RightOu
|
|||
ChanState->mSplitter.processHfScale(tempbuf, ChanState->mHfScale);
|
||||
|
||||
/* Now apply the HRIR coefficients to this channel. */
|
||||
const auto &Coeffs = ChanState->mCoeffs;
|
||||
const ConstHrirSpan Coeffs{ChanState->mCoeffs};
|
||||
for(size_t i{0u};i < BufferSize;++i)
|
||||
{
|
||||
const float insample{tempbuf[i]};
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <array>
|
||||
|
||||
#include "alspan.h"
|
||||
#include "core/ambidefs.h"
|
||||
#include "core/bufferline.h"
|
||||
#include "core/filters/splitter.h"
|
||||
|
@ -28,9 +29,11 @@ constexpr uint MinIrLength{8};
|
|||
constexpr uint HrtfDirectDelay{256};
|
||||
|
||||
using HrirArray = std::array<float2,HrirLength>;
|
||||
using HrirSpan = al::span<float2,HrirLength>;
|
||||
using ConstHrirSpan = al::span<const float2,HrirLength>;
|
||||
|
||||
struct MixHrtfFilter {
|
||||
const HrirArray *Coeffs;
|
||||
const ConstHrirSpan Coeffs;
|
||||
uint2 Delay;
|
||||
float Gain;
|
||||
float GainStep;
|
||||
|
|
|
@ -83,7 +83,7 @@ float *DoResample(const InterpState *state, float *RESTRICT src, uint frac, uint
|
|||
return dst.data();
|
||||
}
|
||||
|
||||
inline void ApplyCoeffs(float2 *RESTRICT Values, const size_t IrSize, const HrirArray &Coeffs,
|
||||
inline void ApplyCoeffs(float2 *RESTRICT Values, const size_t IrSize, const ConstHrirSpan Coeffs,
|
||||
const float left, const float right)
|
||||
{
|
||||
ASSUME(IrSize >= MinIrLength);
|
||||
|
@ -149,7 +149,7 @@ void MixHrtfBlend_<CTag>(const float *InSamples, float2 *AccumSamples, const uin
|
|||
}
|
||||
|
||||
template<>
|
||||
void MixDirectHrtf_<CTag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
|
||||
void MixDirectHrtf_<CTag>(const FloatBufferSpan LeftOut, const FloatBufferSpan RightOut,
|
||||
const al::span<const FloatBufferLine> InSamples, float2 *AccumSamples,
|
||||
float *TempBuf, HrtfChannelState *ChanState, const size_t IrSize, const size_t BufferSize)
|
||||
{
|
||||
|
|
|
@ -34,7 +34,7 @@ inline float32x4_t set_f4(float l0, float l1, float l2, float l3)
|
|||
constexpr uint FracPhaseBitDiff{MixerFracBits - BSincPhaseBits};
|
||||
constexpr uint FracPhaseDiffOne{1 << FracPhaseBitDiff};
|
||||
|
||||
inline void ApplyCoeffs(float2 *RESTRICT Values, const size_t IrSize, const HrirArray &Coeffs,
|
||||
inline void ApplyCoeffs(float2 *RESTRICT Values, const size_t IrSize, const ConstHrirSpan Coeffs,
|
||||
const float left, const float right)
|
||||
{
|
||||
float32x4_t leftright4;
|
||||
|
@ -213,7 +213,7 @@ void MixHrtfBlend_<NEONTag>(const float *InSamples, float2 *AccumSamples, const
|
|||
}
|
||||
|
||||
template<>
|
||||
void MixDirectHrtf_<NEONTag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
|
||||
void MixDirectHrtf_<NEONTag>(const FloatBufferSpan LeftOut, const FloatBufferSpan RightOut,
|
||||
const al::span<const FloatBufferLine> InSamples, float2 *AccumSamples,
|
||||
float *TempBuf, HrtfChannelState *ChanState, const size_t IrSize, const size_t BufferSize)
|
||||
{
|
||||
|
|
|
@ -27,7 +27,7 @@ constexpr uint FracPhaseDiffOne{1 << FracPhaseBitDiff};
|
|||
|
||||
#define MLA4(x, y, z) _mm_add_ps(x, _mm_mul_ps(y, z))
|
||||
|
||||
inline void ApplyCoeffs(float2 *RESTRICT Values, const size_t IrSize, const HrirArray &Coeffs,
|
||||
inline void ApplyCoeffs(float2 *RESTRICT Values, const size_t IrSize, const ConstHrirSpan Coeffs,
|
||||
const float left, const float right)
|
||||
{
|
||||
const __m128 lrlr{_mm_setr_ps(left, right, left, right)};
|
||||
|
@ -180,7 +180,7 @@ void MixHrtfBlend_<SSETag>(const float *InSamples, float2 *AccumSamples, const u
|
|||
}
|
||||
|
||||
template<>
|
||||
void MixDirectHrtf_<SSETag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
|
||||
void MixDirectHrtf_<SSETag>(const FloatBufferSpan LeftOut, const FloatBufferSpan RightOut,
|
||||
const al::span<const FloatBufferLine> InSamples, float2 *AccumSamples,
|
||||
float *TempBuf, HrtfChannelState *ChanState, const size_t IrSize, const size_t BufferSize)
|
||||
{
|
||||
|
|
|
@ -221,7 +221,7 @@ void allpass_process(al::span<float> dst, const float *RESTRICT src)
|
|||
* with the desired shift.
|
||||
*/
|
||||
|
||||
void Uhj2Encoder::encode(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
|
||||
void Uhj2Encoder::encode(const FloatBufferSpan LeftOut, const FloatBufferSpan RightOut,
|
||||
const FloatBufferLine *InSamples, const size_t SamplesToDo)
|
||||
{
|
||||
ASSUME(SamplesToDo > 0);
|
||||
|
|
|
@ -30,7 +30,7 @@ struct Uhj2Encoder {
|
|||
* Encodes a 2-channel UHJ (stereo-compatible) signal from a B-Format input
|
||||
* signal. The input must use FuMa channel ordering and scaling.
|
||||
*/
|
||||
void encode(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
|
||||
void encode(const FloatBufferSpan LeftOut, const FloatBufferSpan RightOut,
|
||||
const FloatBufferLine *InSamples, const size_t SamplesToDo);
|
||||
|
||||
DEF_NEWDEL(Uhj2Encoder)
|
||||
|
|
Loading…
Reference in New Issue