diff options
author | Chris Robinson <[email protected]> | 2019-01-08 23:44:08 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-01-08 23:44:08 -0800 |
commit | 673983dc5d05e8b47958c95f12dba3d7a915edfa (patch) | |
tree | f0abff2eab0b2fe3b0cfb8a5762a54e113bfb4b1 /Alc | |
parent | bc1eeb5df052d3e7eb0f11a4730357b463774e6a (diff) |
Make Create methods for structs with flexible array members ...
... that are used with unique_ptr.
Diffstat (limited to 'Alc')
-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}; } |