Add "fast" variants for the bsinc resamplers
[openal-soft.git] / alc / backends / base.h
blob55240fd20707fbaae36f90f67d68812a170f7b57
1 #ifndef ALC_BACKENDS_BASE_H
2 #define ALC_BACKENDS_BASE_H
4 #include <chrono>
5 #include <memory>
6 #include <mutex>
7 #include <string>
9 #include "AL/alc.h"
11 #include "alcmain.h"
12 #include "albyte.h"
15 struct ClockLatency {
16 std::chrono::nanoseconds ClockTime;
17 std::chrono::nanoseconds Latency;
20 /* Helper to get the current clock time from the device's ClockBase, and
21 * SamplesDone converted from the sample rate.
23 inline std::chrono::nanoseconds GetDeviceClockTime(ALCdevice *device)
25 using std::chrono::seconds;
26 using std::chrono::nanoseconds;
28 auto ns = nanoseconds{seconds{device->SamplesDone}} / device->Frequency;
29 return device->ClockBase + ns;
32 ClockLatency GetClockLatency(ALCdevice *device);
34 struct BackendBase {
35 virtual ALCenum open(const ALCchar *name) = 0;
37 virtual bool reset();
38 virtual bool start() = 0;
39 virtual void stop() = 0;
41 virtual ALCenum captureSamples(al::byte *buffer, ALCuint samples);
42 virtual ALCuint availableSamples();
44 virtual ClockLatency getClockLatency();
46 virtual void lock() { mMutex.lock(); }
47 virtual void unlock() { mMutex.unlock(); }
49 ALCdevice *mDevice;
51 std::recursive_mutex mMutex;
53 BackendBase(ALCdevice *device) noexcept;
54 virtual ~BackendBase();
56 using BackendPtr = std::unique_ptr<BackendBase>;
57 using BackendUniqueLock = std::unique_lock<BackendBase>;
58 using BackendLockGuard = std::lock_guard<BackendBase>;
60 enum class BackendType {
61 Playback,
62 Capture
65 enum class DevProbe {
66 Playback,
67 Capture
71 struct BackendFactory {
72 virtual bool init() = 0;
74 virtual bool querySupport(BackendType type) = 0;
76 virtual void probe(DevProbe type, std::string *outnames) = 0;
78 virtual BackendPtr createBackend(ALCdevice *device, BackendType type) = 0;
80 protected:
81 virtual ~BackendFactory() = default;
84 #endif /* ALC_BACKENDS_BASE_H */