Fix default effect initialization
[openal-soft.git] / Alc / backends / base.h
blob8464fdee34c5945f4079fd599d6aa1da418c39ff
1 #ifndef AL_BACKENDS_BASE_H
2 #define AL_BACKENDS_BASE_H
4 #include "alMain.h"
5 #include "threads.h"
8 typedef struct ClockLatency {
9 ALint64 ClockTime;
10 ALint64 Latency;
11 } ClockLatency;
13 /* Helper to get the current clock time from the device's ClockBase, and
14 * SamplesDone converted from the sample rate.
16 inline ALuint64 GetDeviceClockTime(ALCdevice *device)
18 return device->ClockBase + (device->SamplesDone * DEVICE_CLOCK_RES /
19 device->Frequency);
23 struct ALCbackendVtable;
25 typedef struct ALCbackend {
26 const struct ALCbackendVtable *vtbl;
28 ALCdevice *mDevice;
30 almtx_t mMutex;
31 } ALCbackend;
33 void ALCbackend_Construct(ALCbackend *self, ALCdevice *device);
34 void ALCbackend_Destruct(ALCbackend *self);
35 ALCboolean ALCbackend_reset(ALCbackend *self);
36 ALCenum ALCbackend_captureSamples(ALCbackend *self, void *buffer, ALCuint samples);
37 ALCuint ALCbackend_availableSamples(ALCbackend *self);
38 ClockLatency ALCbackend_getClockLatency(ALCbackend *self);
39 void ALCbackend_lock(ALCbackend *self);
40 void ALCbackend_unlock(ALCbackend *self);
42 struct ALCbackendVtable {
43 void (*const Destruct)(ALCbackend*);
45 ALCenum (*const open)(ALCbackend*, const ALCchar*);
46 void (*const close)(ALCbackend*);
48 ALCboolean (*const reset)(ALCbackend*);
49 ALCboolean (*const start)(ALCbackend*);
50 void (*const stop)(ALCbackend*);
52 ALCenum (*const captureSamples)(ALCbackend*, void*, ALCuint);
53 ALCuint (*const availableSamples)(ALCbackend*);
55 ClockLatency (*const getClockLatency)(ALCbackend*);
57 void (*const lock)(ALCbackend*);
58 void (*const unlock)(ALCbackend*);
60 void (*const Delete)(void*);
63 #define DEFINE_ALCBACKEND_VTABLE(T) \
64 DECLARE_THUNK(T, ALCbackend, void, Destruct) \
65 DECLARE_THUNK1(T, ALCbackend, ALCenum, open, const ALCchar*) \
66 DECLARE_THUNK(T, ALCbackend, void, close) \
67 DECLARE_THUNK(T, ALCbackend, ALCboolean, reset) \
68 DECLARE_THUNK(T, ALCbackend, ALCboolean, start) \
69 DECLARE_THUNK(T, ALCbackend, void, stop) \
70 DECLARE_THUNK2(T, ALCbackend, ALCenum, captureSamples, void*, ALCuint) \
71 DECLARE_THUNK(T, ALCbackend, ALCuint, availableSamples) \
72 DECLARE_THUNK(T, ALCbackend, ClockLatency, getClockLatency) \
73 DECLARE_THUNK(T, ALCbackend, void, lock) \
74 DECLARE_THUNK(T, ALCbackend, void, unlock) \
75 static void T##_ALCbackend_Delete(void *ptr) \
76 { T##_Delete(STATIC_UPCAST(T, ALCbackend, (ALCbackend*)ptr)); } \
78 static const struct ALCbackendVtable T##_ALCbackend_vtable = { \
79 T##_ALCbackend_Destruct, \
81 T##_ALCbackend_open, \
82 T##_ALCbackend_close, \
83 T##_ALCbackend_reset, \
84 T##_ALCbackend_start, \
85 T##_ALCbackend_stop, \
86 T##_ALCbackend_captureSamples, \
87 T##_ALCbackend_availableSamples, \
88 T##_ALCbackend_getClockLatency, \
89 T##_ALCbackend_lock, \
90 T##_ALCbackend_unlock, \
92 T##_ALCbackend_Delete, \
96 typedef enum ALCbackend_Type {
97 ALCbackend_Playback,
98 ALCbackend_Capture,
99 ALCbackend_Loopback
100 } ALCbackend_Type;
103 struct ALCbackendFactoryVtable;
105 typedef struct ALCbackendFactory {
106 const struct ALCbackendFactoryVtable *vtbl;
107 } ALCbackendFactory;
109 void ALCbackendFactory_deinit(ALCbackendFactory *self);
111 struct ALCbackendFactoryVtable {
112 ALCboolean (*const init)(ALCbackendFactory *self);
113 void (*const deinit)(ALCbackendFactory *self);
115 ALCboolean (*const querySupport)(ALCbackendFactory *self, ALCbackend_Type type);
117 void (*const probe)(ALCbackendFactory *self, enum DevProbe type);
119 ALCbackend* (*const createBackend)(ALCbackendFactory *self, ALCdevice *device, ALCbackend_Type type);
122 #define DEFINE_ALCBACKENDFACTORY_VTABLE(T) \
123 DECLARE_THUNK(T, ALCbackendFactory, ALCboolean, init) \
124 DECLARE_THUNK(T, ALCbackendFactory, void, deinit) \
125 DECLARE_THUNK1(T, ALCbackendFactory, ALCboolean, querySupport, ALCbackend_Type) \
126 DECLARE_THUNK1(T, ALCbackendFactory, void, probe, enum DevProbe) \
127 DECLARE_THUNK2(T, ALCbackendFactory, ALCbackend*, createBackend, ALCdevice*, ALCbackend_Type) \
129 static const struct ALCbackendFactoryVtable T##_ALCbackendFactory_vtable = { \
130 T##_ALCbackendFactory_init, \
131 T##_ALCbackendFactory_deinit, \
132 T##_ALCbackendFactory_querySupport, \
133 T##_ALCbackendFactory_probe, \
134 T##_ALCbackendFactory_createBackend, \
138 ALCbackendFactory *ALCpulseBackendFactory_getFactory(void);
139 ALCbackendFactory *ALCalsaBackendFactory_getFactory(void);
140 ALCbackendFactory *ALCcoreAudioBackendFactory_getFactory(void);
141 ALCbackendFactory *ALCossBackendFactory_getFactory(void);
142 ALCbackendFactory *ALCjackBackendFactory_getFactory(void);
143 ALCbackendFactory *ALCsolarisBackendFactory_getFactory(void);
144 ALCbackendFactory *ALCsndioBackendFactory_getFactory(void);
145 ALCbackendFactory *ALCqsaBackendFactory_getFactory(void);
146 ALCbackendFactory *ALCmmdevBackendFactory_getFactory(void);
147 ALCbackendFactory *ALCdsoundBackendFactory_getFactory(void);
148 ALCbackendFactory *ALCwinmmBackendFactory_getFactory(void);
149 ALCbackendFactory *ALCportBackendFactory_getFactory(void);
150 ALCbackendFactory *ALCopenslBackendFactory_getFactory(void);
151 ALCbackendFactory *ALCnullBackendFactory_getFactory(void);
152 ALCbackendFactory *ALCwaveBackendFactory_getFactory(void);
153 ALCbackendFactory *ALCloopbackFactory_getFactory(void);
155 #endif /* AL_BACKENDS_BASE_H */