aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-01-24 10:05:37 -0800
committerChris Robinson <[email protected]>2019-01-24 10:05:37 -0800
commit98be1d1bf5608425cb679ab492922f1b5b925323 (patch)
treef0b377d151b98f221eefdcb91a34bd946e6eaed3 /Alc
parent7757789590edf655555c96f03ce8ad1000abe1f4 (diff)
Make IncRef and DecRef member functions
Diffstat (limited to 'Alc')
-rw-r--r--Alc/alc.cpp6
-rw-r--r--Alc/hrtf.cpp26
-rw-r--r--Alc/hrtf.h8
-rw-r--r--Alc/panning.cpp10
4 files changed, 27 insertions, 23 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp
index 6165779f..e42ec20f 100644
--- a/Alc/alc.cpp
+++ b/Alc/alc.cpp
@@ -1869,8 +1869,8 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
device->FmtChans = DevFmtStereo;
device->Frequency = hrtf->sampleRate;
device->Flags |= DEVICE_CHANNELS_REQUEST | DEVICE_FREQUENCY_REQUEST;
- if(device->mHrtf)
- Hrtf_DecRef(device->mHrtf);
+ if(HrtfEntry *oldhrtf{device->mHrtf})
+ oldhrtf->DecRef();
device->mHrtf = hrtf;
}
else
@@ -2226,7 +2226,7 @@ ALCdevice::~ALCdevice()
WARN(SZFMT " Filter%s not deleted\n", count, (count==1)?"":"s");
if(mHrtf)
- Hrtf_DecRef(mHrtf);
+ mHrtf->DecRef();
mHrtf = nullptr;
}
diff --git a/Alc/hrtf.cpp b/Alc/hrtf.cpp
index 5996c947..655aff1f 100644
--- a/Alc/hrtf.cpp
+++ b/Alc/hrtf.cpp
@@ -450,7 +450,7 @@ HrtfEntry *CreateHrtfStore(ALuint rate, ALsizei irSize, ALfloat distance, ALsize
total += sizeof(Hrtf->coeffs[0])*irSize*irCount;
total += sizeof(Hrtf->delays[0])*irCount;
- Hrtf = static_cast<HrtfEntry*>(al_calloc(16, total));
+ Hrtf = new (al_calloc(16, total)) HrtfEntry{};
if(Hrtf == nullptr)
ERR("Out of memory allocating storage for %s.\n", filename);
else
@@ -1223,7 +1223,7 @@ HrtfEntry *GetLoadedHrtf(HrtfHandle *handle)
if(handle->entry)
{
HrtfEntry *hrtf{handle->entry};
- Hrtf_IncRef(hrtf);
+ hrtf->IncRef();
return hrtf;
}
@@ -1287,7 +1287,7 @@ HrtfEntry *GetLoadedHrtf(HrtfHandle *handle)
else
{
handle->entry = hrtf;
- Hrtf_IncRef(hrtf);
+ hrtf->IncRef();
TRACE("Loaded HRTF support for format: %s %uhz\n",
DevFmtChannelsString(DevFmtStereo), hrtf->sampleRate);
}
@@ -1296,16 +1296,16 @@ HrtfEntry *GetLoadedHrtf(HrtfHandle *handle)
}
-void Hrtf_IncRef(HrtfEntry *hrtf)
+void HrtfEntry::IncRef()
{
- auto ref = IncrementRef(&hrtf->ref);
- TRACEREF("%p increasing refcount to %u\n", hrtf, ref);
+ auto ref = IncrementRef(&this->ref);
+ TRACEREF("%p increasing refcount to %u\n", this, ref);
}
-void Hrtf_DecRef(HrtfEntry *hrtf)
+void HrtfEntry::DecRef()
{
- auto ref = DecrementRef(&hrtf->ref);
- TRACEREF("%p decreasing refcount to %u\n", hrtf, ref);
+ auto ref = DecrementRef(&this->ref);
+ TRACEREF("%p decreasing refcount to %u\n", this, ref);
if(ref == 0)
{
std::lock_guard<std::mutex> _{LoadedHrtfLock};
@@ -1315,12 +1315,12 @@ void Hrtf_DecRef(HrtfEntry *hrtf)
* before the lock was taken.
*/
auto iter = std::find_if(LoadedHrtfs.begin(), LoadedHrtfs.end(),
- [hrtf](const HrtfHandlePtr &entry) noexcept -> bool
- { return hrtf == entry->entry; }
+ [this](const HrtfHandlePtr &entry) noexcept -> bool
+ { return this == entry->entry; }
);
- if(iter != LoadedHrtfs.end() && ReadRef(&hrtf->ref) == 0)
+ if(iter != LoadedHrtfs.end() && ReadRef(&this->ref) == 0)
{
- al_free((*iter)->entry);
+ delete (*iter)->entry;
(*iter)->entry = nullptr;
TRACE("Unloaded unused HRTF %s\n", (*iter)->filename.data());
}
diff --git a/Alc/hrtf.h b/Alc/hrtf.h
index b59cd4ea..742a1812 100644
--- a/Alc/hrtf.h
+++ b/Alc/hrtf.h
@@ -35,6 +35,12 @@ struct HrtfEntry {
const ALushort *evOffset;
const ALfloat (*coeffs)[2];
const ALubyte (*delays)[2];
+
+ void IncRef();
+ void DecRef();
+
+ static constexpr inline const char *CurrentPrefix() noexcept { return "HrtfEntry::"; }
+ DEF_PLACE_NEWDEL()
};
struct EnumeratedHrtf {
@@ -84,8 +90,6 @@ struct AngularPoint {
al::vector<EnumeratedHrtf> EnumerateHrtf(const char *devname);
HrtfEntry *GetLoadedHrtf(HrtfHandle *handle);
-void Hrtf_IncRef(HrtfEntry *hrtf);
-void Hrtf_DecRef(HrtfEntry *hrtf);
void GetHrtfCoeffs(const HrtfEntry *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat spread, ALfloat (*RESTRICT coeffs)[2], ALsizei *delays);
diff --git a/Alc/panning.cpp b/Alc/panning.cpp
index 9c92a166..b53e3464 100644
--- a/Alc/panning.cpp
+++ b/Alc/panning.cpp
@@ -885,7 +885,7 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appr
if(device->FmtChans != DevFmtStereo)
{
if(old_hrtf)
- Hrtf_DecRef(old_hrtf);
+ old_hrtf->DecRef();
old_hrtf = nullptr;
if(hrtf_appreq == Hrtf_Enable)
device->HrtfStatus = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
@@ -1025,7 +1025,7 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appr
device->HrtfName = entry.name;
}
else if(hrtf)
- Hrtf_DecRef(hrtf);
+ hrtf->DecRef();
}
if(!device->mHrtf)
@@ -1036,7 +1036,7 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appr
if(!hrtf) return false;
if(hrtf->sampleRate != device->Frequency)
{
- Hrtf_DecRef(hrtf);
+ hrtf->DecRef();
return false;
}
device->mHrtf = hrtf;
@@ -1049,7 +1049,7 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appr
if(device->mHrtf)
{
if(old_hrtf)
- Hrtf_DecRef(old_hrtf);
+ old_hrtf->DecRef();
old_hrtf = nullptr;
device->mRenderMode = HrtfRender;
@@ -1074,7 +1074,7 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appr
no_hrtf:
if(old_hrtf)
- Hrtf_DecRef(old_hrtf);
+ old_hrtf->DecRef();
old_hrtf = nullptr;
TRACE("HRTF disabled\n");