Document the different filter types, and combine some split lines
[openal-soft.git] / Alc / backends / base.c
blob37e4ccc905dde7ed320ad81314cd4894b0d67f97
2 #include "config.h"
4 #include <stdlib.h>
6 #include "alMain.h"
8 #include "backends/base.h"
11 /* Base ALCbackend method implementations. */
12 void ALCbackend_Construct(ALCbackend *self, ALCdevice *device)
14 int ret;
15 self->mDevice = device;
16 ret = almtx_init(&self->mMutex, almtx_recursive);
17 assert(ret == althrd_success);
20 void ALCbackend_Destruct(ALCbackend *self)
22 almtx_destroy(&self->mMutex);
25 ALCboolean ALCbackend_reset(ALCbackend* UNUSED(self))
27 return ALC_FALSE;
30 ALCenum ALCbackend_captureSamples(ALCbackend* UNUSED(self), void* UNUSED(buffer), ALCuint UNUSED(samples))
32 return ALC_INVALID_DEVICE;
35 ALCuint ALCbackend_availableSamples(ALCbackend* UNUSED(self))
37 return 0;
40 ALint64 ALCbackend_getLatency(ALCbackend* UNUSED(self))
42 return 0;
45 void ALCbackend_lock(ALCbackend *self)
47 int ret = almtx_lock(&self->mMutex);
48 assert(ret == althrd_success);
51 void ALCbackend_unlock(ALCbackend *self)
53 int ret = almtx_unlock(&self->mMutex);
54 assert(ret == althrd_success);
58 /* Base ALCbackendFactory method implementations. */
59 void ALCbackendFactory_deinit(ALCbackendFactory* UNUSED(self))
64 /* Wrappers to use an old-style backend with the new interface. */
65 typedef struct PlaybackWrapper {
66 DERIVE_FROM_TYPE(ALCbackend);
68 const BackendFuncs *Funcs;
69 } PlaybackWrapper;
71 static void PlaybackWrapper_Construct(PlaybackWrapper *self, ALCdevice *device, const BackendFuncs *funcs);
72 static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, void, Destruct)
73 static ALCenum PlaybackWrapper_open(PlaybackWrapper *self, const ALCchar *name);
74 static void PlaybackWrapper_close(PlaybackWrapper *self);
75 static ALCboolean PlaybackWrapper_reset(PlaybackWrapper *self);
76 static ALCboolean PlaybackWrapper_start(PlaybackWrapper *self);
77 static void PlaybackWrapper_stop(PlaybackWrapper *self);
78 static DECLARE_FORWARD2(PlaybackWrapper, ALCbackend, ALCenum, captureSamples, void*, ALCuint)
79 static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, ALCuint, availableSamples)
80 static ALint64 PlaybackWrapper_getLatency(PlaybackWrapper *self);
81 static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, void, lock)
82 static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, void, unlock)
83 DECLARE_DEFAULT_ALLOCATORS(PlaybackWrapper)
84 DEFINE_ALCBACKEND_VTABLE(PlaybackWrapper);
86 static void PlaybackWrapper_Construct(PlaybackWrapper *self, ALCdevice *device, const BackendFuncs *funcs)
88 ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
89 SET_VTABLE2(PlaybackWrapper, ALCbackend, self);
91 self->Funcs = funcs;
94 static ALCenum PlaybackWrapper_open(PlaybackWrapper *self, const ALCchar *name)
96 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
97 return self->Funcs->OpenPlayback(device, name);
100 static void PlaybackWrapper_close(PlaybackWrapper *self)
102 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
103 self->Funcs->ClosePlayback(device);
106 static ALCboolean PlaybackWrapper_reset(PlaybackWrapper *self)
108 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
109 return self->Funcs->ResetPlayback(device);
112 static ALCboolean PlaybackWrapper_start(PlaybackWrapper *self)
114 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
115 return self->Funcs->StartPlayback(device);
118 static void PlaybackWrapper_stop(PlaybackWrapper *self)
120 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
121 self->Funcs->StopPlayback(device);
124 static ALint64 PlaybackWrapper_getLatency(PlaybackWrapper *self)
126 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
127 return self->Funcs->GetLatency(device);
131 typedef struct CaptureWrapper {
132 DERIVE_FROM_TYPE(ALCbackend);
134 const BackendFuncs *Funcs;
135 } CaptureWrapper;
137 static void CaptureWrapper_Construct(CaptureWrapper *self, ALCdevice *device, const BackendFuncs *funcs);
138 static DECLARE_FORWARD(CaptureWrapper, ALCbackend, void, Destruct)
139 static ALCenum CaptureWrapper_open(CaptureWrapper *self, const ALCchar *name);
140 static void CaptureWrapper_close(CaptureWrapper *self);
141 static DECLARE_FORWARD(CaptureWrapper, ALCbackend, ALCboolean, reset)
142 static ALCboolean CaptureWrapper_start(CaptureWrapper *self);
143 static void CaptureWrapper_stop(CaptureWrapper *self);
144 static ALCenum CaptureWrapper_captureSamples(CaptureWrapper *self, void *buffer, ALCuint samples);
145 static ALCuint CaptureWrapper_availableSamples(CaptureWrapper *self);
146 static ALint64 CaptureWrapper_getLatency(CaptureWrapper *self);
147 static DECLARE_FORWARD(CaptureWrapper, ALCbackend, void, lock)
148 static DECLARE_FORWARD(CaptureWrapper, ALCbackend, void, unlock)
149 DECLARE_DEFAULT_ALLOCATORS(CaptureWrapper)
150 DEFINE_ALCBACKEND_VTABLE(CaptureWrapper);
153 static void CaptureWrapper_Construct(CaptureWrapper *self, ALCdevice *device, const BackendFuncs *funcs)
155 ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
156 SET_VTABLE2(CaptureWrapper, ALCbackend, self);
158 self->Funcs = funcs;
161 static ALCenum CaptureWrapper_open(CaptureWrapper *self, const ALCchar *name)
163 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
164 return self->Funcs->OpenCapture(device, name);
167 static void CaptureWrapper_close(CaptureWrapper *self)
169 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
170 self->Funcs->CloseCapture(device);
173 static ALCboolean CaptureWrapper_start(CaptureWrapper *self)
175 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
176 self->Funcs->StartCapture(device);
177 return ALC_TRUE;
180 static void CaptureWrapper_stop(CaptureWrapper *self)
182 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
183 self->Funcs->StopCapture(device);
186 static ALCenum CaptureWrapper_captureSamples(CaptureWrapper *self, void *buffer, ALCuint samples)
188 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
189 return self->Funcs->CaptureSamples(device, buffer, samples);
192 static ALCuint CaptureWrapper_availableSamples(CaptureWrapper *self)
194 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
195 return self->Funcs->AvailableSamples(device);
198 static ALint64 CaptureWrapper_getLatency(CaptureWrapper *self)
200 ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
201 return self->Funcs->GetLatency(device);
205 ALCbackend *create_backend_wrapper(ALCdevice *device, const BackendFuncs *funcs, ALCbackend_Type type)
207 if(type == ALCbackend_Playback)
209 PlaybackWrapper *backend;
211 backend = PlaybackWrapper_New(sizeof(*backend));
212 if(!backend) return NULL;
214 PlaybackWrapper_Construct(backend, device, funcs);
216 return STATIC_CAST(ALCbackend, backend);
219 if(type == ALCbackend_Capture)
221 CaptureWrapper *backend;
223 backend = CaptureWrapper_New(sizeof(*backend));
224 if(!backend) return NULL;
226 CaptureWrapper_Construct(backend, device, funcs);
228 return STATIC_CAST(ALCbackend, backend);
231 return NULL;