Separate integer division from floating point conversion
[openal-soft.git] / alc / device.cpp
blobfc14557933f448b3cac2d795f75645d2994ae29d
2 #include "config.h"
4 #include "device.h"
6 #include <cstddef>
7 #include <numeric>
9 #include "al/buffer.h"
10 #include "al/effect.h"
11 #include "al/filter.h"
12 #include "albit.h"
13 #include "alconfig.h"
14 #include "backends/base.h"
15 #include "core/bformatdec.h"
16 #include "core/bs2b.h"
17 #include "core/front_stablizer.h"
18 #include "core/hrtf.h"
19 #include "core/logging.h"
20 #include "core/mastering.h"
21 #include "core/uhjfilter.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 DevFmtX3D71:
92 case DevFmtAmbi3D:
93 break;
95 return OutputMode1::Any;