Add "fast" variants for the bsinc resamplers
[openal-soft.git] / alc / backends / base.cpp
bloba5f66606183b894619185874374a456acec055a6
2 #include "config.h"
4 #include "base.h"
6 #include <atomic>
7 #include <thread>
9 #include "AL/al.h"
11 #include "alcmain.h"
12 #include "alnumeric.h"
13 #include "atomic.h"
16 ClockLatency GetClockLatency(ALCdevice *device)
18 BackendBase *backend{device->Backend.get()};
19 ClockLatency ret{backend->getClockLatency()};
20 ret.Latency += device->FixedLatency;
21 return ret;
25 /* BackendBase method implementations. */
26 BackendBase::BackendBase(ALCdevice *device) noexcept : mDevice{device}
27 { }
29 BackendBase::~BackendBase() = default;
31 bool BackendBase::reset()
32 { return false; }
34 ALCenum BackendBase::captureSamples(al::byte*, ALCuint)
35 { return ALC_INVALID_DEVICE; }
37 ALCuint BackendBase::availableSamples()
38 { return 0; }
40 ClockLatency BackendBase::getClockLatency()
42 ClockLatency ret;
44 ALuint refcount;
45 do {
46 while(((refcount=ReadRef(mDevice->MixCount))&1) != 0)
47 std::this_thread::yield();
48 ret.ClockTime = GetDeviceClockTime(mDevice);
49 std::atomic_thread_fence(std::memory_order_acquire);
50 } while(refcount != ReadRef(mDevice->MixCount));
52 /* NOTE: The device will generally have about all but one periods filled at
53 * any given time during playback. Without a more accurate measurement from
54 * the output, this is an okay approximation.
56 ret.Latency = std::max(std::chrono::seconds{mDevice->BufferSize-mDevice->UpdateSize},
57 std::chrono::seconds::zero());
58 ret.Latency /= mDevice->Frequency;
60 return ret;