Don't return a large-ish array on the stack
[openal-soft.git] / alc / device.cpp
blob66b13c5e40bb09d78e1f501f5dde643310fb98d7
2 #include "config.h"
4 #include "device.h"
6 #include <numeric>
7 #include <stddef.h>
9 #include "albit.h"
10 #include "alconfig.h"
11 #include "backends/base.h"
12 #include "core/bformatdec.h"
13 #include "core/bs2b.h"
14 #include "core/front_stablizer.h"
15 #include "core/hrtf.h"
16 #include "core/logging.h"
17 #include "core/mastering.h"
18 #include "core/uhjfilter.h"
21 namespace {
23 using voidp = void*;
25 } // namespace
28 ALCdevice::ALCdevice(DeviceType type) : DeviceBase{type}
29 { }
31 ALCdevice::~ALCdevice()
33 TRACE("Freeing device %p\n", voidp{this});
35 Backend = nullptr;
37 size_t count{std::accumulate(BufferList.cbegin(), BufferList.cend(), size_t{0u},
38 [](size_t cur, const BufferSubList &sublist) noexcept -> size_t
39 { return cur + static_cast<uint>(al::popcount(~sublist.FreeMask)); })};
40 if(count > 0)
41 WARN("%zu Buffer%s not deleted\n", count, (count==1)?"":"s");
43 count = std::accumulate(EffectList.cbegin(), EffectList.cend(), size_t{0u},
44 [](size_t cur, const EffectSubList &sublist) noexcept -> size_t
45 { return cur + static_cast<uint>(al::popcount(~sublist.FreeMask)); });
46 if(count > 0)
47 WARN("%zu Effect%s not deleted\n", count, (count==1)?"":"s");
49 count = std::accumulate(FilterList.cbegin(), FilterList.cend(), size_t{0u},
50 [](size_t cur, const FilterSubList &sublist) noexcept -> size_t
51 { return cur + static_cast<uint>(al::popcount(~sublist.FreeMask)); });
52 if(count > 0)
53 WARN("%zu Filter%s not deleted\n", count, (count==1)?"":"s");
56 void ALCdevice::enumerateHrtfs()
58 mHrtfList = EnumerateHrtf(configValue<std::string>(nullptr, "hrtf-paths"));
59 if(auto defhrtfopt = configValue<std::string>(nullptr, "default-hrtf"))
61 auto iter = std::find(mHrtfList.begin(), mHrtfList.end(), *defhrtfopt);
62 if(iter == mHrtfList.end())
63 WARN("Failed to find default HRTF \"%s\"\n", defhrtfopt->c_str());
64 else if(iter != mHrtfList.begin())
65 std::rotate(mHrtfList.begin(), iter, iter+1);
69 auto ALCdevice::getOutputMode1() const noexcept -> OutputMode1
71 if(mContexts.load(std::memory_order_relaxed)->empty())
72 return OutputMode1::Any;
74 switch(FmtChans)
76 case DevFmtMono: return OutputMode1::Mono;
77 case DevFmtStereo:
78 if(mHrtf)
79 return OutputMode1::Hrtf;
80 else if(mUhjEncoder)
81 return OutputMode1::Uhj2;
82 return OutputMode1::StereoBasic;
83 case DevFmtQuad: return OutputMode1::Quad;
84 case DevFmtX51: return OutputMode1::X51;
85 case DevFmtX61: return OutputMode1::X61;
86 case DevFmtX71: return OutputMode1::X71;
87 case DevFmtX714:
88 case DevFmtX3D71:
89 case DevFmtAmbi3D:
90 break;
92 return OutputMode1::Any;