Only use one accumulation buffer for B-Format HRTF mixing
It's all getting added together anyway and all channels are continuous inputs, so this is fewer passes over various buffers.
This commit is contained in:
+1
-1
@@ -438,7 +438,7 @@ void BuildBFormatHrtf(const HrtfEntry *Hrtf, DirectHrtfState *state, const ALuin
|
||||
{
|
||||
auto copy_arr = [](const std::array<double,2> &in) noexcept -> float2
|
||||
{ return float2{{static_cast<float>(in[0]), static_cast<float>(in[1])}}; };
|
||||
std::transform(tmpres[i].begin(), tmpres[i].end(), state->Chan[i].Coeffs.begin(),
|
||||
std::transform(tmpres[i].begin(), tmpres[i].end(), state->Coeffs[i].begin(),
|
||||
copy_arr);
|
||||
}
|
||||
tmpres.clear();
|
||||
|
||||
+4
-9
@@ -79,19 +79,14 @@ struct HrtfFilter {
|
||||
struct DirectHrtfState {
|
||||
/* HRTF filter state for dry buffer content */
|
||||
ALsizei IrSize{0};
|
||||
struct ChanData {
|
||||
alignas(16) HrirArray Values;
|
||||
alignas(16) HrirArray Coeffs;
|
||||
};
|
||||
al::FlexArray<ChanData> Chan;
|
||||
alignas(16) HrirArray Values;
|
||||
al::FlexArray<HrirArray,16> Coeffs;
|
||||
|
||||
DirectHrtfState(size_t numchans) : Chan{numchans} { }
|
||||
DirectHrtfState(const DirectHrtfState&) = delete;
|
||||
DirectHrtfState& operator=(const DirectHrtfState&) = delete;
|
||||
DirectHrtfState(size_t numchans) : Coeffs{numchans} { }
|
||||
|
||||
static std::unique_ptr<DirectHrtfState> Create(size_t num_chans);
|
||||
static constexpr size_t Sizeof(size_t numchans) noexcept
|
||||
{ return al::FlexArray<ChanData>::Sizeof(numchans, offsetof(DirectHrtfState, Chan)); }
|
||||
{ return al::FlexArray<HrirArray,16>::Sizeof(numchans, offsetof(DirectHrtfState, Coeffs)); }
|
||||
|
||||
DEF_PLACE_NEWDEL()
|
||||
};
|
||||
|
||||
+11
-15
@@ -108,29 +108,25 @@ inline void MixDirectHrtfBase(FloatBufferLine &LeftOut, FloatBufferLine &RightOu
|
||||
const ALsizei IrSize{State->IrSize};
|
||||
ASSUME(IrSize >= 4);
|
||||
|
||||
auto chanstate = State->Chan.begin();
|
||||
auto accum_iter = std::copy_n(State->Values.begin(), State->Values.size(), AccumSamples);
|
||||
std::fill_n(accum_iter, BufferSize, float2{});
|
||||
|
||||
auto coeff_iter = State->Coeffs.begin();
|
||||
for(const FloatBufferLine &input : InSamples)
|
||||
{
|
||||
const auto &Coeffs = chanstate->Coeffs;
|
||||
|
||||
auto accum_iter = std::copy_n(chanstate->Values.begin(),
|
||||
chanstate->Values.size(), AccumSamples);
|
||||
std::fill_n(accum_iter, BufferSize, float2{});
|
||||
|
||||
const auto &Coeffs = *(coeff_iter++);
|
||||
for(size_t i{0u};i < BufferSize;++i)
|
||||
{
|
||||
const ALfloat insample{input[i]};
|
||||
ApplyCoeffs(i, AccumSamples+i, IrSize, Coeffs, insample, insample);
|
||||
}
|
||||
for(size_t i{0u};i < BufferSize;++i)
|
||||
LeftOut[i] += AccumSamples[i][0];
|
||||
for(size_t i{0u};i < BufferSize;++i)
|
||||
RightOut[i] += AccumSamples[i][1];
|
||||
|
||||
std::copy_n(AccumSamples + BufferSize, chanstate->Values.size(),
|
||||
chanstate->Values.begin());
|
||||
++chanstate;
|
||||
}
|
||||
for(size_t i{0u};i < BufferSize;++i)
|
||||
LeftOut[i] += AccumSamples[i][0];
|
||||
for(size_t i{0u};i < BufferSize;++i)
|
||||
RightOut[i] += AccumSamples[i][1];
|
||||
|
||||
std::copy_n(AccumSamples + BufferSize, State->Values.size(), State->Values.begin());
|
||||
}
|
||||
|
||||
#endif /* MIXER_HRTFBASE_H */
|
||||
|
||||
Reference in New Issue
Block a user