aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/hrtf.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-01-08 23:44:08 -0800
committerChris Robinson <[email protected]>2019-01-08 23:44:08 -0800
commit673983dc5d05e8b47958c95f12dba3d7a915edfa (patch)
treef0abff2eab0b2fe3b0cfb8a5762a54e113bfb4b1 /Alc/hrtf.cpp
parentbc1eeb5df052d3e7eb0f11a4730357b463774e6a (diff)
Make Create methods for structs with flexible array members ...
... that are used with unique_ptr.
Diffstat (limited to 'Alc/hrtf.cpp')
-rw-r--r--Alc/hrtf.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/Alc/hrtf.cpp b/Alc/hrtf.cpp
index ff9e2f79..422f5052 100644
--- a/Alc/hrtf.cpp
+++ b/Alc/hrtf.cpp
@@ -47,9 +47,17 @@ struct HrtfHandle {
HrtfEntry *entry{nullptr};
char filename[];
+ static std::unique_ptr<HrtfHandle> Create(size_t fname_len);
+
DEF_PLACE_NEWDEL()
};
+std::unique_ptr<HrtfHandle> HrtfHandle::Create(size_t fname_len)
+{
+ void *ptr{al_calloc(DEF_ALIGN, FAM_SIZE(HrtfHandle, filename, fname_len))};
+ return std::unique_ptr<HrtfHandle>{new (ptr) HrtfHandle{}};
+}
+
namespace {
using HrtfHandlePtr = std::unique_ptr<HrtfHandle>;
@@ -273,6 +281,12 @@ void GetHrtfCoeffs(const HrtfEntry *Hrtf, ALfloat elevation, ALfloat azimuth, AL
}
+std::unique_ptr<DirectHrtfState> DirectHrtfState::Create(ALsizei num_chans)
+{
+ void *ptr{al_calloc(16, FAM_SIZE(DirectHrtfState, Chan, num_chans))};
+ return std::unique_ptr<DirectHrtfState>{new (ptr) DirectHrtfState{}};
+}
+
void BuildBFormatHrtf(const HrtfEntry *Hrtf, DirectHrtfState *state, const ALsizei NumChannels, const AngularPoint *AmbiPoints, const ALfloat (*RESTRICT AmbiMatrix)[MAX_AMBI_COEFFS], const ALsizei AmbiCount, const ALfloat *RESTRICT AmbiOrderHFGain)
{
static constexpr int OrderFromChan[MAX_AMBI_COEFFS]{
@@ -980,9 +994,7 @@ void AddFileEntry(al::vector<EnumeratedHrtf> &list, const std::string &filename)
{
TRACE("Got new file \"%s\"\n", filename.c_str());
- LoadedHrtfs.emplace_back(HrtfHandlePtr{new
- (al_calloc(DEF_ALIGN, FAM_SIZE(HrtfHandle, filename, filename.length()+1)))
- HrtfHandle{}});
+ LoadedHrtfs.emplace_back(HrtfHandle::Create(filename.length()+1));
loaded_entry = LoadedHrtfs.end()-1;
strcpy((*loaded_entry)->filename, filename.c_str());
}
@@ -1042,9 +1054,7 @@ void AddBuiltInEntry(al::vector<EnumeratedHrtf> &list, const std::string &filena
TRACE("Got new file \"%s\"\n", filename.c_str());
- LoadedHrtfs.emplace_back(HrtfHandlePtr{new
- (al_calloc(DEF_ALIGN, FAM_SIZE(HrtfHandle, filename, namelen)))
- HrtfHandle{}});
+ LoadedHrtfs.emplace_back(HrtfHandle::Create(namelen));
loaded_entry = LoadedHrtfs.end()-1;
snprintf((*loaded_entry)->filename, namelen, "!%u_%s",
residx, filename.c_str());