allegro_audio_sys/
lib.rs

1// Copyright (c) 2014 by SiegeLord
2//
3// All rights reserved. Distributed under ZLib. For full terms see the file LICENSE.
4pub use allegro_audio::*;
5
6pub mod allegro_audio
7{
8	#![allow(non_camel_case_types)]
9
10	use allegro_sys::*;
11	use allegro_util::c_bool;
12	use libc::*;
13
14	pub use self::ALLEGRO_AUDIO_DEPTH::*;
15	pub use self::ALLEGRO_CHANNEL_CONF::*;
16	pub use self::ALLEGRO_MIXER_QUALITY::*;
17	pub use self::ALLEGRO_PLAYMODE::*;
18
19	pub const ALLEGRO_AUDIO_PAN_NONE: c_float = -1000.0;
20
21	// These are enums instead of consts because functions expect these an arguments.
22	// An API bug that cannot really be fixed.
23	#[repr(C)]
24	#[derive(Copy, Clone)]
25	pub enum ALLEGRO_AUDIO_DEPTH
26	{
27		ALLEGRO_AUDIO_DEPTH_INT8 = 0,
28		ALLEGRO_AUDIO_DEPTH_INT16 = 1,
29		ALLEGRO_AUDIO_DEPTH_INT24 = 2,
30		ALLEGRO_AUDIO_DEPTH_FLOAT32 = 3,
31		ALLEGRO_AUDIO_DEPTH_UNSIGNED = 8,
32		// Can't put this one here, but we don't really care for this anyway, as we wrap this differently.
33		//~ ALLEGRO_AUDIO_DEPTH_UINT8 = 8,
34		ALLEGRO_AUDIO_DEPTH_UINT16 = 9,
35		ALLEGRO_AUDIO_DEPTH_UINT24 = 10,
36	}
37	pub const ALLEGRO_AUDIO_DEPTH_UINT8: u32 = 8;
38
39	#[repr(C)]
40	#[derive(Copy, Clone)]
41	pub enum ALLEGRO_CHANNEL_CONF
42	{
43		ALLEGRO_CHANNEL_CONF_1 = 16,
44		ALLEGRO_CHANNEL_CONF_2 = 32,
45		ALLEGRO_CHANNEL_CONF_3 = 48,
46		ALLEGRO_CHANNEL_CONF_4 = 64,
47		ALLEGRO_CHANNEL_CONF_5_1 = 81,
48		ALLEGRO_CHANNEL_CONF_6_1 = 97,
49		ALLEGRO_CHANNEL_CONF_7_1 = 113,
50	}
51
52	#[repr(C)]
53	#[derive(Copy, Clone)]
54	pub enum ALLEGRO_PLAYMODE
55	{
56		ALLEGRO_PLAYMODE_ONCE = 256,
57		ALLEGRO_PLAYMODE_LOOP = 257,
58		ALLEGRO_PLAYMODE_BIDIR = 258,
59		_ALLEGRO_PLAYMODE_STREAM_ONCE = 259,
60		_ALLEGRO_PLAYMODE_STREAM_ONEDIR = 260,
61	}
62
63	#[repr(C)]
64	#[derive(Copy, Clone)]
65	pub enum ALLEGRO_MIXER_QUALITY
66	{
67		ALLEGRO_MIXER_QUALITY_POINT = 272,
68		ALLEGRO_MIXER_QUALITY_LINEAR = 273,
69		ALLEGRO_MIXER_QUALITY_CUBIC = 274,
70	}
71
72	allegro_util::opaque!(ALLEGRO_SAMPLE);
73
74	#[repr(C)]
75	#[derive(Copy, Clone)]
76	pub struct ALLEGRO_SAMPLE_ID
77	{
78		pub _index: c_int,
79		pub _id: c_int,
80	}
81
82	allegro_util::opaque!(ALLEGRO_SAMPLE_INSTANCE);
83	allegro_util::opaque!(ALLEGRO_AUDIO_STREAM);
84	allegro_util::opaque!(ALLEGRO_MIXER);
85	allegro_util::opaque!(ALLEGRO_VOICE);
86
87	unsafe extern "C" {
88		pub fn al_create_sample(
89			buf: *mut c_void, samples: c_uint, freq: c_uint, depth: ALLEGRO_AUDIO_DEPTH,
90			chan_conf: ALLEGRO_CHANNEL_CONF, free_buf: c_bool,
91		) -> *mut ALLEGRO_SAMPLE;
92		pub fn al_destroy_sample(spl: *mut ALLEGRO_SAMPLE);
93		pub fn al_create_sample_instance(data: *mut ALLEGRO_SAMPLE)
94		-> *mut ALLEGRO_SAMPLE_INSTANCE;
95		pub fn al_destroy_sample_instance(spl: *mut ALLEGRO_SAMPLE_INSTANCE);
96		pub fn al_get_sample_frequency(spl: *const ALLEGRO_SAMPLE) -> c_uint;
97		pub fn al_get_sample_length(spl: *const ALLEGRO_SAMPLE) -> c_uint;
98		pub fn al_get_sample_depth(spl: *const ALLEGRO_SAMPLE) -> ALLEGRO_AUDIO_DEPTH;
99		pub fn al_get_sample_channels(spl: *const ALLEGRO_SAMPLE) -> ALLEGRO_CHANNEL_CONF;
100		pub fn al_get_sample_data(spl: *const ALLEGRO_SAMPLE) -> *mut c_void;
101
102		pub fn al_get_sample_instance_frequency(spl: *const ALLEGRO_SAMPLE_INSTANCE) -> c_uint;
103		pub fn al_get_sample_instance_length(spl: *const ALLEGRO_SAMPLE_INSTANCE) -> c_uint;
104		pub fn al_get_sample_instance_position(spl: *const ALLEGRO_SAMPLE_INSTANCE) -> c_uint;
105		pub fn al_get_sample_instance_speed(spl: *const ALLEGRO_SAMPLE_INSTANCE) -> c_float;
106		pub fn al_get_sample_instance_gain(spl: *const ALLEGRO_SAMPLE_INSTANCE) -> c_float;
107		pub fn al_get_sample_instance_pan(spl: *const ALLEGRO_SAMPLE_INSTANCE) -> c_float;
108		pub fn al_get_sample_instance_time(spl: *const ALLEGRO_SAMPLE_INSTANCE) -> c_float;
109		pub fn al_get_sample_instance_depth(
110			spl: *const ALLEGRO_SAMPLE_INSTANCE,
111		) -> ALLEGRO_AUDIO_DEPTH;
112		pub fn al_get_sample_instance_channels(
113			spl: *const ALLEGRO_SAMPLE_INSTANCE,
114		) -> ALLEGRO_CHANNEL_CONF;
115		pub fn al_get_sample_instance_playmode(
116			spl: *const ALLEGRO_SAMPLE_INSTANCE,
117		) -> ALLEGRO_PLAYMODE;
118		pub fn al_get_sample_instance_playing(spl: *const ALLEGRO_SAMPLE_INSTANCE) -> c_bool;
119		pub fn al_get_sample_instance_attached(spl: *const ALLEGRO_SAMPLE_INSTANCE) -> c_bool;
120		pub fn al_set_sample_instance_position(
121			spl: *mut ALLEGRO_SAMPLE_INSTANCE, val: c_uint,
122		) -> c_bool;
123		pub fn al_set_sample_instance_length(
124			spl: *mut ALLEGRO_SAMPLE_INSTANCE, val: c_uint,
125		) -> c_bool;
126		pub fn al_set_sample_instance_speed(
127			spl: *mut ALLEGRO_SAMPLE_INSTANCE, val: c_float,
128		) -> c_bool;
129		pub fn al_set_sample_instance_gain(
130			spl: *mut ALLEGRO_SAMPLE_INSTANCE, val: c_float,
131		) -> c_bool;
132		pub fn al_set_sample_instance_pan(
133			spl: *mut ALLEGRO_SAMPLE_INSTANCE, val: c_float,
134		) -> c_bool;
135		pub fn al_set_sample_instance_playmode(
136			spl: *mut ALLEGRO_SAMPLE_INSTANCE, val: ALLEGRO_PLAYMODE,
137		) -> c_bool;
138		pub fn al_set_sample_instance_playing(
139			spl: *mut ALLEGRO_SAMPLE_INSTANCE, val: c_bool,
140		) -> c_bool;
141		pub fn al_detach_sample_instance(spl: *mut ALLEGRO_SAMPLE_INSTANCE) -> c_bool;
142		pub fn al_set_sample(
143			spl: *mut ALLEGRO_SAMPLE_INSTANCE, data: *mut ALLEGRO_SAMPLE,
144		) -> c_bool;
145		pub fn al_get_sample(spl: *mut ALLEGRO_SAMPLE_INSTANCE) -> *mut ALLEGRO_SAMPLE;
146		pub fn al_play_sample_instance(spl: *mut ALLEGRO_SAMPLE_INSTANCE) -> c_bool;
147		pub fn al_stop_sample_instance(spl: *mut ALLEGRO_SAMPLE_INSTANCE) -> c_bool;
148
149		pub fn al_create_audio_stream(
150			buffer_count: size_t, samples: c_uint, freq: c_uint, depth: ALLEGRO_AUDIO_DEPTH,
151			chan_conf: ALLEGRO_CHANNEL_CONF,
152		) -> *mut ALLEGRO_AUDIO_STREAM;
153		pub fn al_destroy_audio_stream(stream: *mut ALLEGRO_AUDIO_STREAM);
154		pub fn al_drain_audio_stream(stream: *mut ALLEGRO_AUDIO_STREAM);
155		pub fn al_get_audio_stream_frequency(stream: *const ALLEGRO_AUDIO_STREAM) -> c_uint;
156		pub fn al_get_audio_stream_length(stream: *const ALLEGRO_AUDIO_STREAM) -> c_uint;
157		pub fn al_get_audio_stream_fragments(stream: *const ALLEGRO_AUDIO_STREAM) -> c_uint;
158		pub fn al_get_available_audio_stream_fragments(
159			stream: *const ALLEGRO_AUDIO_STREAM,
160		) -> c_uint;
161		pub fn al_get_audio_stream_speed(stream: *const ALLEGRO_AUDIO_STREAM) -> c_float;
162		pub fn al_get_audio_stream_gain(stream: *const ALLEGRO_AUDIO_STREAM) -> c_float;
163		pub fn al_get_audio_stream_pan(stream: *const ALLEGRO_AUDIO_STREAM) -> c_float;
164		pub fn al_get_audio_stream_channels(
165			stream: *const ALLEGRO_AUDIO_STREAM,
166		) -> ALLEGRO_CHANNEL_CONF;
167		pub fn al_get_audio_stream_depth(
168			stream: *const ALLEGRO_AUDIO_STREAM,
169		) -> ALLEGRO_AUDIO_DEPTH;
170		pub fn al_get_audio_stream_playmode(
171			stream: *const ALLEGRO_AUDIO_STREAM,
172		) -> ALLEGRO_PLAYMODE;
173		pub fn al_get_audio_stream_playing(spl: *const ALLEGRO_AUDIO_STREAM) -> c_bool;
174		pub fn al_get_audio_stream_attached(spl: *const ALLEGRO_AUDIO_STREAM) -> c_bool;
175		pub fn al_get_audio_stream_fragment(stream: *const ALLEGRO_AUDIO_STREAM) -> *mut c_void;
176		pub fn al_set_audio_stream_speed(stream: *mut ALLEGRO_AUDIO_STREAM, val: c_float)
177		-> c_bool;
178		pub fn al_set_audio_stream_gain(stream: *mut ALLEGRO_AUDIO_STREAM, val: c_float) -> c_bool;
179		pub fn al_set_audio_stream_pan(stream: *mut ALLEGRO_AUDIO_STREAM, val: c_float) -> c_bool;
180		pub fn al_set_audio_stream_playmode(
181			stream: *mut ALLEGRO_AUDIO_STREAM, val: ALLEGRO_PLAYMODE,
182		) -> c_bool;
183		pub fn al_set_audio_stream_playing(
184			stream: *mut ALLEGRO_AUDIO_STREAM, val: c_bool,
185		) -> c_bool;
186		pub fn al_detach_audio_stream(stream: *mut ALLEGRO_AUDIO_STREAM) -> c_bool;
187		pub fn al_set_audio_stream_fragment(
188			stream: *mut ALLEGRO_AUDIO_STREAM, val: *mut c_void,
189		) -> c_bool;
190		pub fn al_rewind_audio_stream(stream: *mut ALLEGRO_AUDIO_STREAM) -> c_bool;
191		pub fn al_seek_audio_stream_secs(
192			stream: *mut ALLEGRO_AUDIO_STREAM, time: c_double,
193		) -> c_bool;
194		pub fn al_get_audio_stream_position_secs(stream: *mut ALLEGRO_AUDIO_STREAM) -> c_double;
195		pub fn al_get_audio_stream_length_secs(stream: *mut ALLEGRO_AUDIO_STREAM) -> c_double;
196		pub fn al_set_audio_stream_loop_secs(
197			stream: *mut ALLEGRO_AUDIO_STREAM, start: c_double, end: c_double,
198		) -> c_bool;
199		pub fn al_get_audio_stream_event_source(
200			stream: *mut ALLEGRO_AUDIO_STREAM,
201		) -> *mut ALLEGRO_EVENT_SOURCE;
202
203		pub fn al_create_mixer(
204			freq: c_uint, depth: ALLEGRO_AUDIO_DEPTH, chan_conf: ALLEGRO_CHANNEL_CONF,
205		) -> *mut ALLEGRO_MIXER;
206		pub fn al_destroy_mixer(mixer: *mut ALLEGRO_MIXER);
207		pub fn al_attach_sample_instance_to_mixer(
208			stream: *mut ALLEGRO_SAMPLE_INSTANCE, mixer: *mut ALLEGRO_MIXER,
209		) -> c_bool;
210		pub fn al_attach_audio_stream_to_mixer(
211			stream: *mut ALLEGRO_AUDIO_STREAM, mixer: *mut ALLEGRO_MIXER,
212		) -> c_bool;
213		pub fn al_attach_mixer_to_mixer(
214			stream: *mut ALLEGRO_MIXER, mixer: *mut ALLEGRO_MIXER,
215		) -> c_bool;
216		pub fn al_set_mixer_postprocess_callback(
217			mixer: *mut ALLEGRO_MIXER,
218			cb: Option<extern "C" fn(arg1: *mut c_void, arg2: c_uint, arg3: *mut c_void)>,
219			data: *mut c_void,
220		) -> c_bool;
221		pub fn al_get_mixer_frequency(mixer: *const ALLEGRO_MIXER) -> c_uint;
222		pub fn al_get_mixer_channels(mixer: *const ALLEGRO_MIXER) -> ALLEGRO_CHANNEL_CONF;
223		pub fn al_get_mixer_depth(mixer: *const ALLEGRO_MIXER) -> ALLEGRO_AUDIO_DEPTH;
224		pub fn al_get_mixer_quality(mixer: *const ALLEGRO_MIXER) -> ALLEGRO_MIXER_QUALITY;
225		pub fn al_get_mixer_gain(mixer: *const ALLEGRO_MIXER) -> c_float;
226		pub fn al_get_mixer_playing(mixer: *const ALLEGRO_MIXER) -> c_bool;
227		pub fn al_get_mixer_attached(mixer: *const ALLEGRO_MIXER) -> c_bool;
228		pub fn al_set_mixer_frequency(mixer: *mut ALLEGRO_MIXER, val: c_uint) -> c_bool;
229		pub fn al_set_mixer_quality(
230			mixer: *mut ALLEGRO_MIXER, val: ALLEGRO_MIXER_QUALITY,
231		) -> c_bool;
232		pub fn al_set_mixer_gain(mixer: *mut ALLEGRO_MIXER, gain: c_float) -> c_bool;
233		pub fn al_set_mixer_playing(mixer: *mut ALLEGRO_MIXER, val: c_bool) -> c_bool;
234		pub fn al_detach_mixer(mixer: *mut ALLEGRO_MIXER) -> c_bool;
235
236		pub fn al_create_voice(
237			freq: c_uint, depth: ALLEGRO_AUDIO_DEPTH, chan_conf: ALLEGRO_CHANNEL_CONF,
238		) -> *mut ALLEGRO_VOICE;
239		pub fn al_destroy_voice(voice: *mut ALLEGRO_VOICE);
240		pub fn al_attach_sample_instance_to_voice(
241			stream: *mut ALLEGRO_SAMPLE_INSTANCE, voice: *mut ALLEGRO_VOICE,
242		) -> c_bool;
243		pub fn al_attach_audio_stream_to_voice(
244			stream: *mut ALLEGRO_AUDIO_STREAM, voice: *mut ALLEGRO_VOICE,
245		) -> c_bool;
246		pub fn al_attach_mixer_to_voice(
247			mixer: *mut ALLEGRO_MIXER, voice: *mut ALLEGRO_VOICE,
248		) -> c_bool;
249		pub fn al_detach_voice(voice: *mut ALLEGRO_VOICE);
250		pub fn al_get_voice_frequency(voice: *const ALLEGRO_VOICE) -> c_uint;
251		pub fn al_get_voice_position(voice: *const ALLEGRO_VOICE) -> c_uint;
252		pub fn al_get_voice_channels(voice: *const ALLEGRO_VOICE) -> ALLEGRO_CHANNEL_CONF;
253		pub fn al_get_voice_depth(voice: *const ALLEGRO_VOICE) -> ALLEGRO_AUDIO_DEPTH;
254		pub fn al_get_voice_playing(voice: *const ALLEGRO_VOICE) -> c_bool;
255		pub fn al_set_voice_position(voice: *mut ALLEGRO_VOICE, val: c_uint) -> c_bool;
256		pub fn al_set_voice_playing(voice: *mut ALLEGRO_VOICE, val: c_bool) -> c_bool;
257
258		pub fn al_install_audio() -> c_bool;
259		pub fn al_uninstall_audio();
260		pub fn al_is_audio_installed() -> c_bool;
261		pub fn al_get_allegro_audio_version() -> u32;
262
263		pub fn al_get_channel_count(conf: ALLEGRO_CHANNEL_CONF) -> size_t;
264		pub fn al_get_audio_depth_size(conf: ALLEGRO_AUDIO_DEPTH) -> size_t;
265
266		pub fn al_reserve_samples(reserve_samples: c_int) -> c_bool;
267		pub fn al_get_default_mixer() -> *mut ALLEGRO_MIXER;
268		pub fn al_set_default_mixer(mixer: *mut ALLEGRO_MIXER) -> c_bool;
269		pub fn al_restore_default_mixer() -> c_bool;
270
271		pub fn al_play_sample(
272			data: *mut ALLEGRO_SAMPLE, gain: c_float, pan: c_float, speed: c_float,
273			_loop: ALLEGRO_PLAYMODE, ret_id: *mut ALLEGRO_SAMPLE_ID,
274		) -> c_bool;
275		pub fn al_stop_sample(spl_id: *mut ALLEGRO_SAMPLE_ID);
276		pub fn al_stop_samples();
277
278		pub fn al_register_sample_loader(
279			ext: *const c_char,
280			loader: Option<extern "C" fn(arg1: *const c_char) -> *mut ALLEGRO_SAMPLE>,
281		) -> c_bool;
282		pub fn al_register_sample_saver(
283			ext: *const c_char,
284			saver: Option<extern "C" fn(arg1: *const c_char, arg2: *mut ALLEGRO_SAMPLE) -> c_bool>,
285		) -> c_bool;
286		pub fn al_register_audio_stream_loader(
287			ext: *const c_char,
288			stream_loader: Option<
289				extern "C" fn(
290					arg1: *const c_char,
291					arg2: size_t,
292					arg3: c_uint,
293				) -> *mut ALLEGRO_AUDIO_STREAM,
294			>,
295		) -> c_bool;
296		pub fn al_register_sample_loader_f(
297			ext: *const c_char,
298			loader: Option<extern "C" fn(arg1: *mut ALLEGRO_FILE) -> *mut ALLEGRO_SAMPLE>,
299		) -> c_bool;
300		pub fn al_register_sample_saver_f(
301			ext: *const c_char,
302			saver: Option<
303				extern "C" fn(arg1: *mut ALLEGRO_FILE, arg2: *mut ALLEGRO_SAMPLE) -> c_bool,
304			>,
305		) -> c_bool;
306		pub fn al_register_audio_stream_loader_f(
307			ext: *const c_char,
308			stream_loader: Option<
309				extern "C" fn(
310					arg1: *mut ALLEGRO_FILE,
311					arg2: size_t,
312					arg3: c_uint,
313				) -> *mut ALLEGRO_AUDIO_STREAM,
314			>,
315		) -> c_bool;
316		pub fn al_load_sample(filename: *const c_char) -> *mut ALLEGRO_SAMPLE;
317		pub fn al_save_sample(filename: *const c_char, spl: *mut ALLEGRO_SAMPLE) -> c_bool;
318		pub fn al_load_audio_stream(
319			filename: *const c_char, buffer_count: size_t, samples: c_uint,
320		) -> *mut ALLEGRO_AUDIO_STREAM;
321		pub fn al_load_sample_f(fp: *mut ALLEGRO_FILE, ident: *const c_char)
322		-> *mut ALLEGRO_SAMPLE;
323		pub fn al_save_sample_f(
324			fp: *mut ALLEGRO_FILE, ident: *const c_char, spl: *mut ALLEGRO_SAMPLE,
325		) -> c_bool;
326		pub fn al_load_audio_stream_f(
327			fp: *mut ALLEGRO_FILE, ident: *const c_char, buffer_count: size_t, samples: c_uint,
328		) -> *mut ALLEGRO_AUDIO_STREAM;
329	}
330}