Silence and fix some clang-tidy warnings
[openal-soft.git] / alc / device.cpp
blob86fddcabdaa6b6931e4cc321b9b32ec8b070364e
2 #include "config.h"
4 #include "device.h"
6 #include <algorithm>
7 #include <cstddef>
8 #include <numeric>
10 #include "al/buffer.h"
11 #include "al/effect.h"
12 #include "al/filter.h"
13 #include "albit.h"
14 #include "alnumeric.h"
15 #include "atomic.h"
16 #include "backends/base.h"
17 #include "core/devformat.h"
18 #include "core/hrtf.h"
19 #include "core/logging.h"
20 #include "core/mastering.h"
21 #include "flexarray.h"
24 namespace {
26 using voidp = void*;
28 } // namespace
31 ALCdevice::ALCdevice(DeviceType type) : DeviceBase{type}
32 { }
34 ALCdevice::~ALCdevice()
36 TRACE("Freeing device %p\n", voidp{this});
38 Backend = nullptr;
40 size_t count{std::accumulate(BufferList.cbegin(), BufferList.cend(), 0_uz,
41 [](size_t cur, const BufferSubList &sublist) noexcept -> size_t
42 { return cur + static_cast<uint>(al::popcount(~sublist.FreeMask)); })};
43 if(count > 0)
44 WARN("%zu Buffer%s not deleted\n", count, (count==1)?"":"s");
46 count = std::accumulate(EffectList.cbegin(), EffectList.cend(), 0_uz,
47 [](size_t cur, const EffectSubList &sublist) noexcept -> size_t
48 { return cur + static_cast<uint>(al::popcount(~sublist.FreeMask)); });
49 if(count > 0)
50 WARN("%zu Effect%s not deleted\n", count, (count==1)?"":"s");
52 count = std::accumulate(FilterList.cbegin(), FilterList.cend(), 0_uz,
53 [](size_t cur, const FilterSubList &sublist) noexcept -> size_t
54 { return cur + static_cast<uint>(al::popcount(~sublist.FreeMask)); });
55 if(count > 0)
56 WARN("%zu Filter%s not deleted\n", count, (count==1)?"":"s");
59 void ALCdevice::enumerateHrtfs()
61 mHrtfList = EnumerateHrtf(configValue<std::string>({}, "hrtf-paths"));
62 if(auto defhrtfopt = configValue<std::string>({}, "default-hrtf"))
64 auto iter = std::find(mHrtfList.begin(), mHrtfList.end(), *defhrtfopt);
65 if(iter == mHrtfList.end())
66 WARN("Failed to find default HRTF \"%s\"\n", defhrtfopt->c_str());
67 else if(iter != mHrtfList.begin())
68 std::rotate(mHrtfList.begin(), iter, iter+1);
72 auto ALCdevice::getOutputMode1() const noexcept -> OutputMode1
74 if(mContexts.load(std::memory_order_relaxed)->empty())
75 return OutputMode1::Any;
77 switch(FmtChans)
79 case DevFmtMono: return OutputMode1::Mono;
80 case DevFmtStereo:
81 if(mHrtf)
82 return OutputMode1::Hrtf;
83 else if(mUhjEncoder)
84 return OutputMode1::Uhj2;
85 return OutputMode1::StereoBasic;
86 case DevFmtQuad: return OutputMode1::Quad;
87 case DevFmtX51: return OutputMode1::X51;
88 case DevFmtX61: return OutputMode1::X61;
89 case DevFmtX71: return OutputMode1::X71;
90 case DevFmtX714:
91 case DevFmtX7144:
92 case DevFmtX3D71:
93 case DevFmtAmbi3D:
94 break;
96 return OutputMode1::Any;