Avoid a virtual function call to set the decoder width
[openal-soft.git] / alc / backends / base.cpp
blob4abd7c03742452002d5c28cb85183f84de1cde02
2 #include "config.h"
4 #include "base.h"
6 #include <algorithm>
7 #include <array>
8 #include <atomic>
10 #ifdef _WIN32
11 #define WIN32_LEAN_AND_MEAN
12 #include <windows.h>
13 #include <mmreg.h>
15 #include "albit.h"
16 #include "core/logging.h"
17 #include "aloptional.h"
18 #endif
20 #include "atomic.h"
21 #include "core/devformat.h"
24 bool BackendBase::reset()
25 { throw al::backend_exception{al::backend_error::DeviceError, "Invalid BackendBase call"}; }
27 void BackendBase::captureSamples(al::byte*, uint)
28 { }
30 uint BackendBase::availableSamples()
31 { return 0; }
33 ClockLatency BackendBase::getClockLatency()
35 ClockLatency ret;
37 uint refcount;
38 do {
39 refcount = mDevice->waitForMix();
40 ret.ClockTime = GetDeviceClockTime(mDevice);
41 std::atomic_thread_fence(std::memory_order_acquire);
42 } while(refcount != ReadRef(mDevice->MixCount));
44 /* NOTE: The device will generally have about all but one periods filled at
45 * any given time during playback. Without a more accurate measurement from
46 * the output, this is an okay approximation.
48 ret.Latency = std::max(std::chrono::seconds{mDevice->BufferSize-mDevice->UpdateSize},
49 std::chrono::seconds::zero());
50 ret.Latency /= mDevice->Frequency;
52 return ret;
55 void BackendBase::setDefaultWFXChannelOrder()
57 mDevice->RealOut.ChannelIndex.fill(INVALID_CHANNEL_INDEX);
59 switch(mDevice->FmtChans)
61 case DevFmtMono:
62 mDevice->RealOut.ChannelIndex[FrontCenter] = 0;
63 break;
64 case DevFmtStereo:
65 mDevice->RealOut.ChannelIndex[FrontLeft] = 0;
66 mDevice->RealOut.ChannelIndex[FrontRight] = 1;
67 break;
68 case DevFmtQuad:
69 mDevice->RealOut.ChannelIndex[FrontLeft] = 0;
70 mDevice->RealOut.ChannelIndex[FrontRight] = 1;
71 mDevice->RealOut.ChannelIndex[BackLeft] = 2;
72 mDevice->RealOut.ChannelIndex[BackRight] = 3;
73 break;
74 case DevFmtX51:
75 mDevice->RealOut.ChannelIndex[FrontLeft] = 0;
76 mDevice->RealOut.ChannelIndex[FrontRight] = 1;
77 mDevice->RealOut.ChannelIndex[FrontCenter] = 2;
78 mDevice->RealOut.ChannelIndex[LFE] = 3;
79 mDevice->RealOut.ChannelIndex[SideLeft] = 4;
80 mDevice->RealOut.ChannelIndex[SideRight] = 5;
81 break;
82 case DevFmtX61:
83 mDevice->RealOut.ChannelIndex[FrontLeft] = 0;
84 mDevice->RealOut.ChannelIndex[FrontRight] = 1;
85 mDevice->RealOut.ChannelIndex[FrontCenter] = 2;
86 mDevice->RealOut.ChannelIndex[LFE] = 3;
87 mDevice->RealOut.ChannelIndex[BackCenter] = 4;
88 mDevice->RealOut.ChannelIndex[SideLeft] = 5;
89 mDevice->RealOut.ChannelIndex[SideRight] = 6;
90 break;
91 case DevFmtX71:
92 mDevice->RealOut.ChannelIndex[FrontLeft] = 0;
93 mDevice->RealOut.ChannelIndex[FrontRight] = 1;
94 mDevice->RealOut.ChannelIndex[FrontCenter] = 2;
95 mDevice->RealOut.ChannelIndex[LFE] = 3;
96 mDevice->RealOut.ChannelIndex[BackLeft] = 4;
97 mDevice->RealOut.ChannelIndex[BackRight] = 5;
98 mDevice->RealOut.ChannelIndex[SideLeft] = 6;
99 mDevice->RealOut.ChannelIndex[SideRight] = 7;
100 break;
101 case DevFmtX3D71:
102 mDevice->RealOut.ChannelIndex[FrontLeft] = 0;
103 mDevice->RealOut.ChannelIndex[FrontRight] = 1;
104 mDevice->RealOut.ChannelIndex[FrontCenter] = 2;
105 mDevice->RealOut.ChannelIndex[LFE] = 3;
106 mDevice->RealOut.ChannelIndex[Aux0] = 4;
107 mDevice->RealOut.ChannelIndex[Aux1] = 5;
108 mDevice->RealOut.ChannelIndex[SideLeft] = 6;
109 mDevice->RealOut.ChannelIndex[SideRight] = 7;
110 break;
111 case DevFmtAmbi3D:
112 break;
116 void BackendBase::setDefaultChannelOrder()
118 mDevice->RealOut.ChannelIndex.fill(INVALID_CHANNEL_INDEX);
120 switch(mDevice->FmtChans)
122 case DevFmtX51:
123 mDevice->RealOut.ChannelIndex[FrontLeft] = 0;
124 mDevice->RealOut.ChannelIndex[FrontRight] = 1;
125 mDevice->RealOut.ChannelIndex[SideLeft] = 2;
126 mDevice->RealOut.ChannelIndex[SideRight] = 3;
127 mDevice->RealOut.ChannelIndex[FrontCenter] = 4;
128 mDevice->RealOut.ChannelIndex[LFE] = 5;
129 return;
130 case DevFmtX71:
131 mDevice->RealOut.ChannelIndex[FrontLeft] = 0;
132 mDevice->RealOut.ChannelIndex[FrontRight] = 1;
133 mDevice->RealOut.ChannelIndex[BackLeft] = 2;
134 mDevice->RealOut.ChannelIndex[BackRight] = 3;
135 mDevice->RealOut.ChannelIndex[FrontCenter] = 4;
136 mDevice->RealOut.ChannelIndex[LFE] = 5;
137 mDevice->RealOut.ChannelIndex[SideLeft] = 6;
138 mDevice->RealOut.ChannelIndex[SideRight] = 7;
139 return;
140 case DevFmtX3D71:
141 mDevice->RealOut.ChannelIndex[FrontLeft] = 0;
142 mDevice->RealOut.ChannelIndex[FrontRight] = 1;
143 mDevice->RealOut.ChannelIndex[Aux0] = 2;
144 mDevice->RealOut.ChannelIndex[Aux1] = 3;
145 mDevice->RealOut.ChannelIndex[FrontCenter] = 4;
146 mDevice->RealOut.ChannelIndex[LFE] = 5;
147 mDevice->RealOut.ChannelIndex[SideLeft] = 6;
148 mDevice->RealOut.ChannelIndex[SideRight] = 7;
149 return;
151 /* Same as WFX order */
152 case DevFmtMono:
153 case DevFmtStereo:
154 case DevFmtQuad:
155 case DevFmtX61:
156 case DevFmtAmbi3D:
157 setDefaultWFXChannelOrder();
158 break;