al_sys/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#[cfg(all(not(target_os = "emscripten"), feature = "dynamic"))]
#[macro_use]
extern crate rental;


mod alc;
mod al;
mod efx;
mod efx_presets;

pub use alc::*;
pub use al::*;
pub use efx::*;
pub use efx_presets::*;


#[cfg(all(not(target_os = "emscripten"), feature = "dynamic"))]
macro_rules! al_api {
	{
		$($sym:ident: unsafe extern "C" fn ($($param:ident: $param_ty:ty),*) -> $ret_ty:ty,)*
	} => {
		mod al_api {
			extern crate libloading;

			use std::io;
			use std::path::Path;

			use super::*;


			#[allow(non_snake_case)]
			pub struct AlSymbols<'lib> {
				$(pub $sym: libloading::Symbol<'lib, unsafe extern "C" fn ($($param: $param_ty),*) -> $ret_ty>,)*
			}

			rental!{
				mod rent {
					use super::libloading;

					#[rental]
					pub struct RentSymbols {
						lib: Box<libloading::Library>,
						syms: super::AlSymbols<'lib>,
					}
				}
			}

			use self::rent::RentSymbols;


			pub struct AlApi(rent::RentSymbols);


			impl AlApi {
				pub fn load_default() -> io::Result<AlApi> {
					AlApi::from_lib(libloading::Library::new("libopenal.so")
						.or_else(|_| libloading::Library::new("libopenal.dylib"))
						.or_else(|_| libloading::Library::new("OpenAL.framework/OpenAL"))
						.or_else(|_| libloading::Library::new("soft_oal.dll"))
						.or_else(|_| libloading::Library::new("OpenAL32.dll"))
					?)
				}


				pub fn load<P: AsRef<Path>>(path: P) -> io::Result<AlApi> {
					AlApi::from_lib(libloading::Library::new(path.as_ref())?)
				}


				fn from_lib(lib: libloading::Library) -> io::Result<AlApi> {
					match RentSymbols::try_new(Box::new(lib), |lib| Ok(AlSymbols{
						$($sym: unsafe { lib.get(stringify!($sym).as_bytes())? },)*
					})) {
						Ok(syms) => Ok(AlApi(syms)),
						Err(rental::RentalError(e, _)) => return Err(e),
					}
				}


				$(#[allow(non_snake_case)]
				#[inline]
				pub unsafe fn $sym(&self, $($param: $param_ty),*) -> $ret_ty {
					self.0.rent(|s| (s.$sym)($($param),*))
				})*
			}
		}

		pub use al_api::AlApi;
	};
}


#[cfg(any(target_os = "emscripten", not(feature = "dynamic")))]
macro_rules! al_api {
	{
		$($sym:ident: unsafe extern "C" fn ($($param:ident: $param_ty:ty),*) -> $ret_ty:ty,)*
	} => {
		mod al_api {
			use std::io;
			use std::path::Path;
			use super::*;


			#[allow(non_snake_case)]
			pub mod al_symbols {
				use super::*;

				extern "C" {
					$(pub fn $sym ($($param: $param_ty),*) -> $ret_ty;)*
				}
			}


			pub struct AlApi;


			impl AlApi {
				pub fn load_default() -> io::Result<AlApi> {
					Ok(AlApi)
				}


				pub fn load<P: AsRef<Path>>(_path: P) -> io::Result<AlApi> {
					Err(io::Error::new(io::ErrorKind::Other, "Dynamic loading is not supported on emscripten"))
				}


				$(#[allow(non_snake_case)]
				#[inline]
				pub unsafe fn $sym(&self, $($param: $param_ty),*) -> $ret_ty {
					al_symbols::$sym($($param),*)
				})*
			}
		}

		pub use al_api::AlApi;
	};
}


al_api! {
	alcCreateContext: unsafe extern "C" fn(device: *mut ALCdevice, attrlist: *const ALCint) -> *mut ALCcontext,
	alcMakeContextCurrent: unsafe extern "C" fn(context: *mut ALCcontext) -> ALCboolean,
	alcProcessContext: unsafe extern "C" fn(context: *mut ALCcontext) -> (),
	alcSuspendContext: unsafe extern "C" fn(context: *mut ALCcontext) -> (),
	alcDestroyContext: unsafe extern "C" fn(context: *mut ALCcontext) -> (),
	alcGetCurrentContext: unsafe extern "C" fn() -> *mut ALCcontext,
	alcGetContextsDevice: unsafe extern "C" fn(context: *mut ALCcontext) -> *mut ALCdevice,
	alcOpenDevice: unsafe extern "C" fn(devicename: *const ALCchar) -> *mut ALCdevice,
	alcCloseDevice: unsafe extern "C" fn(device: *mut ALCdevice) -> ALCboolean,
	alcGetError: unsafe extern "C" fn(device: *mut ALCdevice) -> ALCenum,
	alcIsExtensionPresent: unsafe extern "C" fn(device: *mut ALCdevice, extname: *const ALCchar) -> ALCboolean,
	alcGetProcAddress: unsafe extern "C" fn(device: *mut ALCdevice, funcname: *const ALCchar) -> *mut ::std::os::raw::c_void,
	alcGetEnumValue: unsafe extern "C" fn(device: *mut ALCdevice, enumname: *const ALCchar) -> ALCenum,
	alcGetString: unsafe extern "C" fn(device: *mut ALCdevice, param: ALCenum) -> *const ALCchar,
	alcGetIntegerv: unsafe extern "C" fn(device: *mut ALCdevice, param: ALCenum, size: ALCsizei, values: *mut ALCint) -> (),
	alcCaptureOpenDevice: unsafe extern "C" fn(devicename: *const ALCchar, frequency: ALCuint, format: ALCenum, buffersize: ALCsizei) -> *mut ALCdevice,
	alcCaptureCloseDevice: unsafe extern "C" fn(device: *mut ALCdevice) -> ALCboolean,
	alcCaptureStart: unsafe extern "C" fn(device: *mut ALCdevice) -> (),
	alcCaptureStop: unsafe extern "C" fn(device: *mut ALCdevice) -> (),
	alcCaptureSamples: unsafe extern "C" fn(device: *mut ALCdevice, buffer: *mut ALCvoid, samples: ALCsizei) -> (),

	alDopplerFactor: unsafe extern "C" fn(value: ALfloat) -> (),
	alDopplerVelocity: unsafe extern "C" fn(value: ALfloat) -> (),
	alSpeedOfSound: unsafe extern "C" fn(value: ALfloat) -> (),
	alDistanceModel: unsafe extern "C" fn(distanceModel: ALenum) -> (),
	alEnable: unsafe extern "C" fn(capability: ALenum) -> (),
	alDisable: unsafe extern "C" fn(capability: ALenum) -> (),
	alIsEnabled: unsafe extern "C" fn(capability: ALenum) -> ALboolean,
	alGetString: unsafe extern "C" fn(param: ALenum) -> *const ALchar,
	alGetBooleanv: unsafe extern "C" fn(param: ALenum, values: *mut ALboolean) -> (),
	alGetIntegerv: unsafe extern "C" fn(param: ALenum, values: *mut ALint) -> (),
	alGetFloatv: unsafe extern "C" fn(param: ALenum, values: *mut ALfloat) -> (),
	alGetDoublev: unsafe extern "C" fn(param: ALenum, values: *mut ALdouble) -> (),
	alGetBoolean: unsafe extern "C" fn(param: ALenum) -> ALboolean,
	alGetInteger: unsafe extern "C" fn(param: ALenum) -> ALint,
	alGetFloat: unsafe extern "C" fn(param: ALenum) -> ALfloat,
	alGetDouble: unsafe extern "C" fn(param: ALenum) -> ALdouble,
	alGetError: unsafe extern "C" fn() -> ALenum,
	alIsExtensionPresent: unsafe extern "C" fn(extname: *const ALchar) -> ALboolean,
	alGetProcAddress: unsafe extern "C" fn(fname: *const ALchar) -> *mut ::std::os::raw::c_void,
	alGetEnumValue: unsafe extern "C" fn(ename: *const ALchar) -> ALenum,
	alListenerf: unsafe extern "C" fn(param: ALenum, value: ALfloat) -> (),
	alListener3f: unsafe extern "C" fn(param: ALenum, value1: ALfloat, value2: ALfloat, value3: ALfloat) -> (),
	alListenerfv: unsafe extern "C" fn(param: ALenum, values: *const ALfloat) -> (),
	alListeneri: unsafe extern "C" fn(param: ALenum, value: ALint) -> (),
	alListener3i: unsafe extern "C" fn(param: ALenum, value1: ALint, value2: ALint, value3: ALint) -> (),
	alListeneriv: unsafe extern "C" fn(param: ALenum, values: *const ALint) -> (),
	alGetListenerf: unsafe extern "C" fn(param: ALenum, value: *mut ALfloat) -> (),
	alGetListener3f: unsafe extern "C" fn(param: ALenum, value1: *mut ALfloat, value2: *mut ALfloat, value3: *mut ALfloat) -> (),
	alGetListenerfv: unsafe extern "C" fn(param: ALenum, values: *mut ALfloat) -> (),
	alGetListeneri: unsafe extern "C" fn(param: ALenum, value: *mut ALint) -> (),
	alGetListener3i: unsafe extern "C" fn(param: ALenum, value1: *mut ALint, value2: *mut ALint, value3: *mut ALint) -> (),
	alGetListeneriv: unsafe extern "C" fn(param: ALenum, values: *mut ALint) -> (),
	alGenSources: unsafe extern "C" fn(n: ALsizei, sources: *mut ALuint) -> (),
	alDeleteSources: unsafe extern "C" fn(n: ALsizei, sources: *const ALuint) -> (),
	alIsSource: unsafe extern "C" fn(source: ALuint) -> ALboolean,
	alSourcef: unsafe extern "C" fn(source: ALuint, param: ALenum, value: ALfloat) -> (),
	alSource3f: unsafe extern "C" fn(source: ALuint, param: ALenum, value1: ALfloat, value2: ALfloat, value3: ALfloat) -> (),
	alSourcefv: unsafe extern "C" fn(source: ALuint, param: ALenum, values: *const ALfloat) -> (),
	alSourcei: unsafe extern "C" fn(source: ALuint, param: ALenum, value: ALint) -> (),
	alSource3i: unsafe extern "C" fn(source: ALuint, param: ALenum, value1: ALint, value2: ALint, value3: ALint) -> (),
	alSourceiv: unsafe extern "C" fn(source: ALuint, param: ALenum, values: *const ALint) -> (),
	alGetSourcef: unsafe extern "C" fn(source: ALuint, param: ALenum, value: *mut ALfloat) -> (),
	alGetSource3f: unsafe extern "C" fn(source: ALuint, param: ALenum, value1: *mut ALfloat, value2: *mut ALfloat, value3: *mut ALfloat) -> (),
	alGetSourcefv: unsafe extern "C" fn(source: ALuint, param: ALenum, values: *mut ALfloat) -> (),
	alGetSourcei: unsafe extern "C" fn(source: ALuint, param: ALenum, value: *mut ALint) -> (),
	alGetSource3i: unsafe extern "C" fn(source: ALuint, param: ALenum, value1: *mut ALint, value2: *mut ALint, value3: *mut ALint) -> (),
	alGetSourceiv: unsafe extern "C" fn(source: ALuint, param: ALenum, values: *mut ALint) -> (),
	alSourcePlayv: unsafe extern "C" fn(n: ALsizei, sources: *const ALuint) -> (),
	alSourceStopv: unsafe extern "C" fn(n: ALsizei, sources: *const ALuint) -> (),
	alSourceRewindv: unsafe extern "C" fn(n: ALsizei, sources: *const ALuint) -> (),
	alSourcePausev: unsafe extern "C" fn(n: ALsizei, sources: *const ALuint) -> (),
	alSourcePlay: unsafe extern "C" fn(source: ALuint) -> (),
	alSourceStop: unsafe extern "C" fn(source: ALuint) -> (),
	alSourceRewind: unsafe extern "C" fn(source: ALuint) -> (),
	alSourcePause: unsafe extern "C" fn(source: ALuint) -> (),
	alSourceQueueBuffers: unsafe extern "C" fn(source: ALuint, nb: ALsizei, buffers: *const ALuint) -> (),
	alSourceUnqueueBuffers: unsafe extern "C" fn(source: ALuint, nb: ALsizei, buffers: *mut ALuint) -> (),
	alGenBuffers: unsafe extern "C" fn(n: ALsizei, buffers: *mut ALuint) -> (),
	alDeleteBuffers: unsafe extern "C" fn(n: ALsizei, buffers: *const ALuint) -> (),
	alIsBuffer: unsafe extern "C" fn(buffer: ALuint) -> ALboolean,
	alBufferData: unsafe extern "C" fn(buffer: ALuint, format: ALenum, data: *const ALvoid, size: ALsizei, freq: ALsizei) -> (),
	alBufferf: unsafe extern "C" fn(buffer: ALuint, param: ALenum, value: ALfloat) -> (),
	alBuffer3f: unsafe extern "C" fn(buffer: ALuint, param: ALenum, value1: ALfloat, value2: ALfloat, value3: ALfloat) -> (),
	alBufferfv: unsafe extern "C" fn(buffer: ALuint, param: ALenum, values: *const ALfloat) -> (),
	alBufferi: unsafe extern "C" fn(buffer: ALuint, param: ALenum, value: ALint) -> (),
	alBuffer3i: unsafe extern "C" fn(buffer: ALuint, param: ALenum, value1: ALint, value2: ALint, value3: ALint) -> (),
	alBufferiv: unsafe extern "C" fn(buffer: ALuint, param: ALenum, values: *const ALint) -> (),
	alGetBufferf: unsafe extern "C" fn(buffer: ALuint, param: ALenum, value: *mut ALfloat) -> (),
	alGetBuffer3f: unsafe extern "C" fn(buffer: ALuint, param: ALenum, value1: *mut ALfloat, value2: *mut ALfloat, value3: *mut ALfloat) -> (),
	alGetBufferfv: unsafe extern "C" fn(buffer: ALuint, param: ALenum, values: *mut ALfloat) -> (),
	alGetBufferi: unsafe extern "C" fn(buffer: ALuint, param: ALenum, value: *mut ALint) -> (),
	alGetBuffer3i: unsafe extern "C" fn(buffer: ALuint, param: ALenum, value1: *mut ALint, value2: *mut ALint, value3: *mut ALint) -> (),
	alGetBufferiv: unsafe extern "C" fn(buffer: ALuint, param: ALenum, values: *mut ALint) -> (),
}