aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2020-05-01 10:28:16 -0700
committerChris Robinson <[email protected]>2020-05-01 10:28:16 -0700
commit8acf16fc820c1b36b5364bcf17cf4f96a27fedef (patch)
tree2bf075614ee358d2e052314168d0794becac8801
parentae09e1f60cbf67f73ba61a29734a8b297d44772f (diff)
Make BuildBFormatHrtf a member of DirectHrtfState
-rw-r--r--alc/hrtf.cpp25
-rw-r--r--alc/hrtf.h42
-rw-r--r--alc/mixer/hrtfbase.h4
-rw-r--r--alc/panning.cpp6
4 files changed, 38 insertions, 39 deletions
diff --git a/alc/hrtf.cpp b/alc/hrtf.cpp
index 6a9c187e..26e08cba 100644
--- a/alc/hrtf.cpp
+++ b/alc/hrtf.cpp
@@ -281,8 +281,8 @@ std::unique_ptr<DirectHrtfState> DirectHrtfState::Create(size_t num_chans)
return std::unique_ptr<DirectHrtfState>{new (FamCount{num_chans}) DirectHrtfState{num_chans}};
}
-void BuildBFormatHrtf(const HrtfStore *Hrtf, DirectHrtfState *state,
- const al::span<const AngularPoint> AmbiPoints, const float (*AmbiMatrix)[MAX_AMBI_CHANNELS],
+void DirectHrtfState::build(const HrtfStore *Hrtf, const al::span<const AngularPoint> AmbiPoints,
+ const float (*AmbiMatrix)[MAX_AMBI_CHANNELS],
const al::span<const float,MAX_AMBI_ORDER+1> AmbiOrderHFGain)
{
using double2 = std::array<double,2>;
@@ -346,9 +346,9 @@ void BuildBFormatHrtf(const HrtfStore *Hrtf, DirectHrtfState *state,
const double xover_norm{400.0 / Hrtf->sampleRate};
BandSplitterR<double> splitter{xover_norm};
- auto tmpres = al::vector<std::array<double2,HRIR_LENGTH>>(state->Coeffs.size());
+ auto tmpres = al::vector<std::array<double2,HRIR_LENGTH>>(mCoeffs.size());
auto tmpflt = al::vector<std::array<double,HRIR_LENGTH*4>>(3);
- const al::span<double,HRIR_LENGTH*4> tempir{tmpflt[2].data(), tmpflt[2].size()};
+ const al::span<double,HRIR_LENGTH*4> tempir{tmpflt[2]};
for(size_t c{0u};c < AmbiPoints.size();++c)
{
const HrirArray &hrir{impres[c].hrir};
@@ -358,7 +358,7 @@ void BuildBFormatHrtf(const HrtfStore *Hrtf, DirectHrtfState *state,
if /*constexpr*/(!DualBand)
{
/* For single-band decoding, apply the HF scale to the response. */
- for(size_t i{0u};i < state->Coeffs.size();++i)
+ for(size_t i{0u};i < mCoeffs.size();++i)
{
const size_t order{AmbiIndex::OrderFromChannel[i]};
const double mult{double{AmbiOrderHFGain[order]} * AmbiMatrix[c][i]};
@@ -388,7 +388,7 @@ void BuildBFormatHrtf(const HrtfStore *Hrtf, DirectHrtfState *state,
* sample array. This produces the forward response with a backwards
* phase-shift (+n degrees becomes -n degrees).
*/
- splitter.applyAllpass({tempir.data(), tempir.size()});
+ splitter.applyAllpass(tempir);
std::reverse(tempir.begin(), tempir.end());
/* Now apply the band-splitter. This applies the normal phase-shift,
@@ -399,7 +399,7 @@ void BuildBFormatHrtf(const HrtfStore *Hrtf, DirectHrtfState *state,
splitter.process(tempir, tmpflt[0].data(), tmpflt[1].data());
/* Apply left ear response with delay and HF scale. */
- for(size_t i{0u};i < state->Coeffs.size();++i)
+ for(size_t i{0u};i < mCoeffs.size();++i)
{
const double mult{AmbiMatrix[c][i]};
const double hfgain{AmbiOrderHFGain[AmbiIndex::OrderFromChannel[i]]};
@@ -413,13 +413,13 @@ void BuildBFormatHrtf(const HrtfStore *Hrtf, DirectHrtfState *state,
std::transform(hrir.crbegin(), hrir.crend(), tempir.begin(),
[](const float2 &ir) noexcept -> double { return ir[1]; });
- splitter.applyAllpass({tempir.data(), tempir.size()});
+ splitter.applyAllpass(tempir);
std::reverse(tempir.begin(), tempir.end());
splitter.clear();
splitter.process(tempir, tmpflt[0].data(), tmpflt[1].data());
- for(size_t i{0u};i < state->Coeffs.size();++i)
+ for(size_t i{0u};i < mCoeffs.size();++i)
{
const double mult{AmbiMatrix[c][i]};
const double hfgain{AmbiOrderHFGain[AmbiIndex::OrderFromChannel[i]]};
@@ -431,12 +431,11 @@ void BuildBFormatHrtf(const HrtfStore *Hrtf, DirectHrtfState *state,
tmpflt.clear();
impres.clear();
- for(size_t i{0u};i < state->Coeffs.size();++i)
+ for(size_t i{0u};i < mCoeffs.size();++i)
{
auto copy_arr = [](const double2 &in) noexcept -> float2
{ return float2{{static_cast<float>(in[0]), static_cast<float>(in[1])}}; };
- std::transform(tmpres[i].cbegin(), tmpres[i].cend(), state->Coeffs[i].begin(),
- copy_arr);
+ std::transform(tmpres[i].cbegin(), tmpres[i].cend(), mCoeffs[i].begin(), copy_arr);
}
tmpres.clear();
@@ -450,7 +449,7 @@ void BuildBFormatHrtf(const HrtfStore *Hrtf, DirectHrtfState *state,
TRACE("Skipped delay: %.2f, max delay: %.2f, new FIR length: %u\n",
min_delay/double{HRIR_DELAY_FRACONE}, max_delay/double{HRIR_DELAY_FRACONE},
max_length);
- state->IrSize = max_length;
+ mIrSize = max_length;
}
diff --git a/alc/hrtf.h b/alc/hrtf.h
index d82c67db..5b709e30 100644
--- a/alc/hrtf.h
+++ b/alc/hrtf.h
@@ -69,17 +69,6 @@ struct HrtfFilter {
float Gain;
};
-struct DirectHrtfState {
- /* HRTF filter state for dry buffer content */
- ALuint IrSize{0};
- al::FlexArray<HrirArray,16> Coeffs;
-
- DirectHrtfState(size_t numchans) : Coeffs{numchans} { }
-
- static std::unique_ptr<DirectHrtfState> Create(size_t num_chans);
-
- DEF_FAM_NEWDEL(DirectHrtfState, Coeffs)
-};
struct EvRadians { float value; };
struct AzRadians { float value; };
@@ -88,6 +77,27 @@ struct AngularPoint {
AzRadians Azim;
};
+struct DirectHrtfState {
+ /* HRTF filter state for dry buffer content */
+ ALuint mIrSize{0};
+ al::FlexArray<HrirArray,16> mCoeffs;
+
+ DirectHrtfState(size_t numchans) : mCoeffs{numchans} { }
+ /**
+ * Produces HRTF filter coefficients for decoding B-Format, given a set of
+ * virtual speaker positions, a matching decoding matrix, and per-order
+ * high-frequency gains for the decoder. The calculated impulse responses
+ * are ordered and scaled according to the matrix input.
+ */
+ void build(const HrtfStore *Hrtf, const al::span<const AngularPoint> AmbiPoints,
+ const float (*AmbiMatrix)[MAX_AMBI_CHANNELS],
+ const al::span<const float,MAX_AMBI_ORDER+1> AmbiOrderHFGain);
+
+ static std::unique_ptr<DirectHrtfState> Create(size_t num_chans);
+
+ DEF_FAM_NEWDEL(DirectHrtfState, mCoeffs)
+};
+
al::vector<std::string> EnumerateHrtf(const char *devname);
HrtfStorePtr GetLoadedHrtf(const std::string &name, const char *devname, const ALuint devrate);
@@ -95,14 +105,4 @@ HrtfStorePtr GetLoadedHrtf(const std::string &name, const char *devname, const A
void GetHrtfCoeffs(const HrtfStore *Hrtf, float elevation, float azimuth, float distance,
float spread, HrirArray &coeffs, const al::span<ALuint,2> delays);
-/**
- * Produces HRTF filter coefficients for decoding B-Format, given a set of
- * virtual speaker positions, a matching decoding matrix, and per-order high-
- * frequency gains for the decoder. The calculated impulse responses are
- * ordered and scaled according to the matrix input.
- */
-void BuildBFormatHrtf(const HrtfStore *Hrtf, DirectHrtfState *state,
- const al::span<const AngularPoint> AmbiPoints, const float (*AmbiMatrix)[MAX_AMBI_CHANNELS],
- const al::span<const float,MAX_AMBI_ORDER+1> AmbiOrderHFGain);
-
#endif /* ALC_HRTF_H */
diff --git a/alc/mixer/hrtfbase.h b/alc/mixer/hrtfbase.h
index 7cc65640..5bef1ddd 100644
--- a/alc/mixer/hrtfbase.h
+++ b/alc/mixer/hrtfbase.h
@@ -85,9 +85,9 @@ inline void MixDirectHrtfBase(FloatBufferLine &LeftOut, FloatBufferLine &RightOu
{
ASSUME(BufferSize > 0);
- const uint_fast32_t IrSize{State->IrSize};
+ const uint_fast32_t IrSize{State->mIrSize};
- auto coeff_iter = State->Coeffs.begin();
+ auto coeff_iter = State->mCoeffs.begin();
for(const FloatBufferLine &input : InSamples)
{
const auto &Coeffs = *(coeff_iter++);
diff --git a/alc/panning.cpp b/alc/panning.cpp
index 2f2eba76..353c9994 100644
--- a/alc/panning.cpp
+++ b/alc/panning.cpp
@@ -651,8 +651,6 @@ void InitHrtfPanning(ALCdevice *device)
device->mAmbiOrder = ambi_order;
const size_t count{AmbiChannelsFromOrder(ambi_order)};
- device->mHrtfState = DirectHrtfState::Create(count);
-
std::transform(AmbiIndex::FromACN.begin(), AmbiIndex::FromACN.begin()+count,
std::begin(device->Dry.AmbiMap),
[](const uint8_t &index) noexcept { return BFChannelConfig{1.0f, index}; }
@@ -660,7 +658,9 @@ void InitHrtfPanning(ALCdevice *device)
AllocChannels(device, static_cast<ALuint>(count), device->channelsFromFmt());
HrtfStore *Hrtf{device->mHrtf.get()};
- BuildBFormatHrtf(Hrtf, device->mHrtfState.get(), AmbiPoints, AmbiMatrix, AmbiOrderHFGain);
+ auto hrtfstate = DirectHrtfState::Create(count);
+ hrtfstate->build(Hrtf, AmbiPoints, AmbiMatrix, AmbiOrderHFGain);
+ device->mHrtfState = std::move(hrtfstate);
InitNearFieldCtrl(device, Hrtf->field[0].distance, ambi_order, true);
}