aboutsummaryrefslogtreecommitdiffstats
path: root/alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2020-03-01 17:16:09 -0800
committerChris Robinson <[email protected]>2020-03-01 17:16:09 -0800
commit3e1a2c0f77baa81244a436e29db4e4780cdc2105 (patch)
treecacb56fa34b20d971a0d89718a4b20d733ef9ebb /alc
parenta01617904c222578b71d6912cc5e5410b137c626 (diff)
Use an intrusive_ptr for the device's HrtfStore
Diffstat (limited to 'alc')
-rw-r--r--alc/alc.cpp2
-rw-r--r--alc/alcmain.h2
-rw-r--r--alc/alu.cpp4
-rw-r--r--alc/hrtf.cpp16
-rw-r--r--alc/hrtf.h8
-rw-r--r--alc/panning.cpp21
6 files changed, 23 insertions, 30 deletions
diff --git a/alc/alc.cpp b/alc/alc.cpp
index 42d586c7..e03dc2f6 100644
--- a/alc/alc.cpp
+++ b/alc/alc.cpp
@@ -2447,8 +2447,6 @@ ALCdevice::~ALCdevice()
if(count > 0)
WARN("%zu Filter%s not deleted\n", count, (count==1)?"":"s");
- if(mHrtf)
- mHrtf->DecRef();
mHrtf = nullptr;
auto *oldarray = mContexts.exchange(nullptr, std::memory_order_relaxed);
diff --git a/alc/alcmain.h b/alc/alcmain.h
index 673997dc..071e43f5 100644
--- a/alc/alcmain.h
+++ b/alc/alcmain.h
@@ -304,7 +304,7 @@ struct ALCdevice : public al::intrusive_ref<ALCdevice> {
/* HRTF state and info */
std::unique_ptr<DirectHrtfState> mHrtfState;
- HrtfStore *mHrtf{nullptr};
+ al::intrusive_ptr<HrtfStore> mHrtf;
/* Ambisonic-to-UHJ encoder */
std::unique_ptr<Uhj2Encoder> Uhj_Encoder;
diff --git a/alc/alu.cpp b/alc/alu.cpp
index 42642e75..b29ac977 100644
--- a/alc/alu.cpp
+++ b/alc/alu.cpp
@@ -1007,7 +1007,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat xpos, const ALfloat ypo
/* Get the HRIR coefficients and delays just once, for the given
* source direction.
*/
- GetHrtfCoeffs(Device->mHrtf, ev, az, Distance, Spread,
+ GetHrtfCoeffs(Device->mHrtf.get(), ev, az, Distance, Spread,
voice->mChans[0].mDryParams.Hrtf.Target.Coeffs,
voice->mChans[0].mDryParams.Hrtf.Target.Delay);
voice->mChans[0].mDryParams.Hrtf.Target.Gain = DryGain.Base * downmix_gain;
@@ -1054,7 +1054,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat xpos, const ALfloat ypo
/* Get the HRIR coefficients and delays for this channel
* position.
*/
- GetHrtfCoeffs(Device->mHrtf, chans[c].elevation, chans[c].angle,
+ GetHrtfCoeffs(Device->mHrtf.get(), chans[c].elevation, chans[c].angle,
std::numeric_limits<float>::infinity(), Spread,
voice->mChans[c].mDryParams.Hrtf.Target.Coeffs,
voice->mChans[c].mDryParams.Hrtf.Target.Delay);
diff --git a/alc/hrtf.cpp b/alc/hrtf.cpp
index 6e5d079d..a705bdd7 100644
--- a/alc/hrtf.cpp
+++ b/alc/hrtf.cpp
@@ -1355,7 +1355,7 @@ al::vector<std::string> EnumerateHrtf(const char *devname)
return list;
}
-HrtfStore *GetLoadedHrtf(const std::string &name, const char *devname, const ALuint devrate)
+HrtfStorePtr GetLoadedHrtf(const std::string &name, const char *devname, const ALuint devrate)
{
std::lock_guard<std::mutex> _{EnumeratedHrtfLock};
auto entry_iter = std::find_if(EnumeratedHrtfs.cbegin(), EnumeratedHrtfs.cend(),
@@ -1374,8 +1374,8 @@ HrtfStore *GetLoadedHrtf(const std::string &name, const char *devname, const ALu
HrtfStore *hrtf{handle->mEntry.get()};
if(hrtf && hrtf->sampleRate == devrate)
{
- hrtf->IncRef();
- return hrtf;
+ hrtf->add_ref();
+ return HrtfStorePtr{hrtf};
}
++handle;
}
@@ -1519,20 +1519,20 @@ HrtfStore *GetLoadedHrtf(const std::string &name, const char *devname, const ALu
hrtf->sampleRate, hrtf->irSize);
handle = LoadedHrtfs.emplace(handle, LoadedHrtf{fname, std::move(hrtf)});
- return handle->mEntry.get();
+ return HrtfStorePtr{handle->mEntry.get()};
}
-void HrtfStore::IncRef()
+void HrtfStore::add_ref()
{
auto ref = IncrementRef(mRef);
- TRACE("HrtfEntry %p increasing refcount to %u\n", decltype(std::declval<void*>()){this}, ref);
+ TRACE("HrtfStore %p increasing refcount to %u\n", decltype(std::declval<void*>()){this}, ref);
}
-void HrtfStore::DecRef()
+void HrtfStore::release()
{
auto ref = DecrementRef(mRef);
- TRACE("HrtfEntry %p decreasing refcount to %u\n", decltype(std::declval<void*>()){this}, ref);
+ TRACE("HrtfStore %p decreasing refcount to %u\n", decltype(std::declval<void*>()){this}, ref);
if(ref == 0)
{
std::lock_guard<std::mutex> _{LoadedHrtfLock};
diff --git a/alc/hrtf.h b/alc/hrtf.h
index 46b71920..a7b84880 100644
--- a/alc/hrtf.h
+++ b/alc/hrtf.h
@@ -12,6 +12,7 @@
#include "alspan.h"
#include "ambidefs.h"
#include "atomic.h"
+#include "intrusive_ptr.h"
#include "vector.h"
@@ -54,11 +55,12 @@ struct HrtfStore {
const HrirArray *coeffs;
const ubyte2 *delays;
- void IncRef();
- void DecRef();
+ void add_ref();
+ void release();
DEF_PLACE_NEWDEL()
};
+using HrtfStorePtr = al::intrusive_ptr<HrtfStore>;
struct HrtfFilter {
@@ -88,7 +90,7 @@ struct AngularPoint {
al::vector<std::string> EnumerateHrtf(const char *devname);
-HrtfStore *GetLoadedHrtf(const std::string &name, const char *devname, const ALuint devrate);
+HrtfStorePtr GetLoadedHrtf(const std::string &name, const char *devname, const ALuint devrate);
void GetHrtfCoeffs(const HrtfStore *Hrtf, float elevation, float azimuth, float distance,
float spread, HrirArray &coeffs, const al::span<ALuint,2> delays);
diff --git a/alc/panning.cpp b/alc/panning.cpp
index 435555d2..1f80be55 100644
--- a/alc/panning.cpp
+++ b/alc/panning.cpp
@@ -659,10 +659,9 @@ void InitHrtfPanning(ALCdevice *device)
);
AllocChannels(device, static_cast<ALuint>(count), device->channelsFromFmt());
- BuildBFormatHrtf(device->mHrtf, device->mHrtfState.get(), AmbiPoints, AmbiMatrix,
- AmbiOrderHFGain);
+ HrtfStore *Hrtf{device->mHrtf.get()};
+ BuildBFormatHrtf(Hrtf, device->mHrtfState.get(), AmbiPoints, AmbiMatrix, AmbiOrderHFGain);
- HrtfStore *Hrtf{device->mHrtf};
InitNearFieldCtrl(device, Hrtf->field[0].distance, ambi_order, true);
}
@@ -686,7 +685,7 @@ void InitUhjPanning(ALCdevice *device)
void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appreq, HrtfRequestMode hrtf_userreq)
{
/* Hold the HRTF the device last used, in case it's used again. */
- HrtfStore *old_hrtf{device->mHrtf};
+ HrtfStorePtr old_hrtf{std::move(device->mHrtf)};
device->mHrtfState = nullptr;
device->mHrtf = nullptr;
@@ -695,8 +694,6 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appr
if(device->FmtChans != DevFmtStereo)
{
- if(old_hrtf)
- old_hrtf->DecRef();
old_hrtf = nullptr;
if(hrtf_appreq == Hrtf_Enable)
device->HrtfStatus = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
@@ -792,9 +789,9 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appr
{
const char *devname{device->DeviceName.c_str()};
const std::string &hrtfname = device->HrtfList[static_cast<ALuint>(hrtf_id)];
- if(HrtfStore *hrtf{GetLoadedHrtf(hrtfname, devname, device->Frequency)})
+ if(HrtfStorePtr hrtf{GetLoadedHrtf(hrtfname, devname, device->Frequency)})
{
- device->mHrtf = hrtf;
+ device->mHrtf = std::move(hrtf);
device->HrtfName = hrtfname;
}
}
@@ -804,9 +801,9 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appr
const char *devname{device->DeviceName.c_str()};
auto find_hrtf = [device,devname](const std::string &hrtfname) -> bool
{
- HrtfStore *hrtf{GetLoadedHrtf(hrtfname, devname, device->Frequency)};
+ HrtfStorePtr hrtf{GetLoadedHrtf(hrtfname, devname, device->Frequency)};
if(!hrtf) return false;
- device->mHrtf = hrtf;
+ device->mHrtf = std::move(hrtf);
device->HrtfName = hrtfname;
return true;
};
@@ -815,8 +812,6 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appr
if(device->mHrtf)
{
- if(old_hrtf)
- old_hrtf->DecRef();
old_hrtf = nullptr;
InitHrtfPanning(device);
@@ -826,8 +821,6 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appr
device->HrtfStatus = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
no_hrtf:
- if(old_hrtf)
- old_hrtf->DecRef();
old_hrtf = nullptr;
device->mRenderMode = StereoPair;