diff options
-rw-r--r-- | Alc/hrtf.cpp | 22 | ||||
-rw-r--r-- | Alc/hrtf.h | 2 | ||||
-rw-r--r-- | Alc/panning.cpp | 3 |
3 files changed, 19 insertions, 8 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()); @@ -1,6 +1,7 @@ #ifndef ALC_HRTF_H #define ALC_HRTF_H +#include <memory> #include <string> #include "AL/al.h" @@ -64,6 +65,7 @@ struct DirectHrtfState { } Chan[]; DirectHrtfState() noexcept { } + static std::unique_ptr<DirectHrtfState> Create(ALsizei num_chans); DEF_PLACE_NEWDEL() }; diff --git a/Alc/panning.cpp b/Alc/panning.cpp index 502a02cd..99a0534f 100644 --- a/Alc/panning.cpp +++ b/Alc/panning.cpp @@ -697,8 +697,7 @@ void InitHrtfPanning(ALCdevice *device) count = static_cast<ALsizei>(COUNTOF(IndexMap)); } - device->mHrtfState.reset( - new (al_calloc(16, FAM_SIZE(DirectHrtfState, Chan, count))) DirectHrtfState{}); + device->mHrtfState = DirectHrtfState::Create(count); std::transform(std::begin(IndexMap), std::begin(IndexMap)+count, std::begin(device->Dry.AmbiMap), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } |