1 module allegro5.allegro_audio;
2 
3 version(ALLEGRO_NO_PRAGMA_LIB) {}
4 else
5 {
6 	pragma(lib, "allegro_audio");
7 }
8 
9 version (ALLEGRO_UNSTABLE)
10 	version = AllegroAudioUnstable;
11 version(ALLEGRO_INTERNAL_UNSTABLE)
12 	version = AllegroAudioUnstable;
13 version(ALLEGRO_KCM_AUDIO_SRC)
14 	version = AllegroAudioUnstable;
15 
16 import allegro5.allegro;
17 import allegro5.events;
18 import allegro5.internal.da5;
19 
20 nothrow @nogc extern (C)
21 {
22 	version (AllegroAudioUnstable)
23 	{
24 		struct ALLEGRO_AUDIO_RECORDER_EVENT
25 		{
26 			mixin(_AL_EVENT_HEADER("ALLEGRO_AUDIO_RECORDER"));
27 			ALLEGRO_USER_EVENT_DESCRIPTOR* __internal__descr;
28 			void* buffer;
29 			uint samples;
30 		};
31 	}
32 
33 	enum ALLEGRO_AUDIO_DEPTH
34 	{
35 		ALLEGRO_AUDIO_DEPTH_INT8      = 0x00,
36 		ALLEGRO_AUDIO_DEPTH_INT16     = 0x01,
37 		ALLEGRO_AUDIO_DEPTH_INT24     = 0x02,
38 		ALLEGRO_AUDIO_DEPTH_FLOAT32   = 0x03,
39 
40 		ALLEGRO_AUDIO_DEPTH_UNSIGNED  = 0x08,
41 
42 		/* For convenience */
43 		ALLEGRO_AUDIO_DEPTH_UINT8  = ALLEGRO_AUDIO_DEPTH_INT8 | ALLEGRO_AUDIO_DEPTH_UNSIGNED,
44 		ALLEGRO_AUDIO_DEPTH_UINT16 = ALLEGRO_AUDIO_DEPTH_INT16 | ALLEGRO_AUDIO_DEPTH_UNSIGNED,
45 		ALLEGRO_AUDIO_DEPTH_UINT24 = ALLEGRO_AUDIO_DEPTH_INT24 | ALLEGRO_AUDIO_DEPTH_UNSIGNED
46 	}
47 
48 	enum ALLEGRO_CHANNEL_CONF
49 	{
50 		ALLEGRO_CHANNEL_CONF_1   = 0x10,
51 		ALLEGRO_CHANNEL_CONF_2   = 0x20,
52 		ALLEGRO_CHANNEL_CONF_3   = 0x30,
53 		ALLEGRO_CHANNEL_CONF_4   = 0x40,
54 		ALLEGRO_CHANNEL_CONF_5_1 = 0x51,
55 		ALLEGRO_CHANNEL_CONF_6_1 = 0x61,
56 		ALLEGRO_CHANNEL_CONF_7_1 = 0x71
57 	}
58 	
59 	const ALLEGRO_MAX_CHANNELS = 8;
60 
61 	enum ALLEGRO_PLAYMODE
62 	{
63 		ALLEGRO_PLAYMODE_ONCE   = 0x100,
64 		ALLEGRO_PLAYMODE_LOOP   = 0x101,
65 		ALLEGRO_PLAYMODE_BIDIR  = 0x102,
66 		_ALLEGRO_PLAYMODE_STREAM_ONCE   = 0x103,   /* internal */
67 		_ALLEGRO_PLAYMODE_STREAM_ONEDIR = 0x104    /* internal */
68 	}
69 
70 	enum ALLEGRO_MIXER_QUALITY
71 	{
72 		ALLEGRO_MIXER_QUALITY_POINT   = 0x110,
73 		ALLEGRO_MIXER_QUALITY_LINEAR  = 0x111,
74 		ALLEGRO_MIXER_QUALITY_CUBIC   = 0x112
75 	}
76 
77 	const float ALLEGRO_AUDIO_PAN_NONE = -1000.0f;
78 	
79 	enum ALLEGRO_AUDIO_EVENT_TYPE
80 	{
81 		ALLEGRO_EVENT_AUDIO_ROUTE_CHANGE       = 520,
82 		ALLEGRO_EVENT_AUDIO_INTERRUPTION       = 521,
83 		ALLEGRO_EVENT_AUDIO_END_INTERRUPTION   = 522
84 	}
85 
86 	struct ALLEGRO_SAMPLE {};
87 
88 	struct ALLEGRO_SAMPLE_ID
89 	{
90 		int _index;
91 		int _id;
92 	}
93 
94 	struct ALLEGRO_SAMPLE_INSTANCE {};
95 	
96 	struct ALLEGRO_AUDIO_STREAM {};
97 	
98 	struct ALLEGRO_MIXER {};
99 
100 	struct ALLEGRO_VOICE {};
101 
102 	version (AllegroAudioUnstable)
103 		struct ALLEGRO_AUDIO_RECORDER {};
104 
105 	ALLEGRO_SAMPLE* al_create_sample(void* buf, uint samples, uint freq, ALLEGRO_AUDIO_DEPTH depth, ALLEGRO_CHANNEL_CONF chan_conf, bool free_buf);
106 	void al_destroy_sample(ALLEGRO_SAMPLE* spl);
107 
108 	/* Sample instance functions */
109 	ALLEGRO_SAMPLE_INSTANCE* al_create_sample_instance(ALLEGRO_SAMPLE* data);
110 	void al_destroy_sample_instance(ALLEGRO_SAMPLE_INSTANCE* spl);
111 
112 	uint al_get_sample_frequency(in ALLEGRO_SAMPLE* spl);
113 	uint al_get_sample_length(in ALLEGRO_SAMPLE* spl);
114 	ALLEGRO_AUDIO_DEPTH al_get_sample_depth(in ALLEGRO_SAMPLE* spl);
115 	ALLEGRO_CHANNEL_CONF al_get_sample_channels(in ALLEGRO_SAMPLE* spl);
116 	void* al_get_sample_data(in ALLEGRO_SAMPLE* spl);
117 
118 	uint al_get_sample_instance_frequency(in ALLEGRO_SAMPLE_INSTANCE* spl);
119 	uint al_get_sample_instance_length(in ALLEGRO_SAMPLE_INSTANCE* spl);
120 	uint al_get_sample_instance_position(in ALLEGRO_SAMPLE_INSTANCE* spl);
121 
122 	float al_get_sample_instance_speed(in ALLEGRO_SAMPLE_INSTANCE* spl);
123 	float al_get_sample_instance_gain(in ALLEGRO_SAMPLE_INSTANCE* spl);
124 	float al_get_sample_instance_pan(in ALLEGRO_SAMPLE_INSTANCE* spl);
125 	float al_get_sample_instance_time(in ALLEGRO_SAMPLE_INSTANCE* spl);
126 
127 	ALLEGRO_AUDIO_DEPTH al_get_sample_instance_depth(in ALLEGRO_SAMPLE_INSTANCE* spl);
128 	ALLEGRO_CHANNEL_CONF al_get_sample_instance_channels(in ALLEGRO_SAMPLE_INSTANCE* spl);
129 	ALLEGRO_PLAYMODE al_get_sample_instance_playmode(in ALLEGRO_SAMPLE_INSTANCE* spl);
130 
131 	bool al_get_sample_instance_playing(in ALLEGRO_SAMPLE_INSTANCE* spl);
132 	bool al_get_sample_instance_attached(in ALLEGRO_SAMPLE_INSTANCE* spl);
133 
134 	bool al_set_sample_instance_position(ALLEGRO_SAMPLE_INSTANCE* spl, uint val);
135 	bool al_set_sample_instance_length(ALLEGRO_SAMPLE_INSTANCE* spl, uint val);
136 
137 	bool al_set_sample_instance_speed(ALLEGRO_SAMPLE_INSTANCE* spl, float val);
138 	bool al_set_sample_instance_gain(ALLEGRO_SAMPLE_INSTANCE* spl, float val);
139 	bool al_set_sample_instance_pan(ALLEGRO_SAMPLE_INSTANCE* spl, float val);
140 
141 	bool al_set_sample_instance_playmode(ALLEGRO_SAMPLE_INSTANCE* spl, ALLEGRO_PLAYMODE val);
142 
143 	bool al_set_sample_instance_playing(ALLEGRO_SAMPLE_INSTANCE* spl, bool val);
144 	bool al_detach_sample_instance(ALLEGRO_SAMPLE_INSTANCE* spl);
145 
146 	bool al_set_sample(ALLEGRO_SAMPLE_INSTANCE* spl, ALLEGRO_SAMPLE* data);
147 	ALLEGRO_SAMPLE* al_get_sample(ALLEGRO_SAMPLE_INSTANCE* spl);
148 	bool al_play_sample_instance(ALLEGRO_SAMPLE_INSTANCE* spl);
149 	bool al_stop_sample_instance(ALLEGRO_SAMPLE_INSTANCE* spl);
150 
151 
152 	/* Stream functions */
153 	ALLEGRO_AUDIO_STREAM* al_create_audio_stream(size_t buffer_count, uint samples, uint freq, ALLEGRO_AUDIO_DEPTH depth, ALLEGRO_CHANNEL_CONF chan_conf);
154 	void al_destroy_audio_stream(ALLEGRO_AUDIO_STREAM* stream);
155 	void al_drain_audio_stream(ALLEGRO_AUDIO_STREAM* stream);
156 
157 	uint al_get_audio_stream_frequency(in ALLEGRO_AUDIO_STREAM* stream);
158 	uint al_get_audio_stream_length(in ALLEGRO_AUDIO_STREAM* stream);
159 	uint al_get_audio_stream_fragments(in ALLEGRO_AUDIO_STREAM* stream);
160 	uint al_get_available_audio_stream_fragments(in ALLEGRO_AUDIO_STREAM* stream);
161 
162 	float al_get_audio_stream_speed(in ALLEGRO_AUDIO_STREAM* stream);
163 	float al_get_audio_stream_gain(in ALLEGRO_AUDIO_STREAM* stream);
164 	float al_get_audio_stream_pan(in ALLEGRO_AUDIO_STREAM* stream);
165 
166 	ALLEGRO_CHANNEL_CONF al_get_audio_stream_channels(in ALLEGRO_AUDIO_STREAM* stream);
167 	ALLEGRO_AUDIO_DEPTH al_get_audio_stream_depth(in ALLEGRO_AUDIO_STREAM* stream);
168 	ALLEGRO_PLAYMODE al_get_audio_stream_playmode(in ALLEGRO_AUDIO_STREAM* stream);
169 
170 	bool al_get_audio_stream_playing(in ALLEGRO_AUDIO_STREAM* spl);
171 	bool al_get_audio_stream_attached(in ALLEGRO_AUDIO_STREAM* spl);
172 	ulong al_get_audio_stream_played_samples(in ALLEGRO_AUDIO_STREAM* stream);
173 
174 	void* al_get_audio_stream_fragment(in ALLEGRO_AUDIO_STREAM* stream);
175 
176 	bool al_set_audio_stream_speed(ALLEGRO_AUDIO_STREAM* stream, float val);
177 	bool al_set_audio_stream_gain(ALLEGRO_AUDIO_STREAM* stream, float val);
178 	bool al_set_audio_stream_pan(ALLEGRO_AUDIO_STREAM* stream, float val);
179 
180 	bool al_set_audio_stream_playmode(ALLEGRO_AUDIO_STREAM* stream, ALLEGRO_PLAYMODE val);
181 
182 	bool al_set_audio_stream_playing(ALLEGRO_AUDIO_STREAM* stream, bool val);
183 	bool al_detach_audio_stream(ALLEGRO_AUDIO_STREAM* stream);
184 	bool al_set_audio_stream_fragment(ALLEGRO_AUDIO_STREAM* stream, void* val);
185 
186 	bool al_rewind_audio_stream(ALLEGRO_AUDIO_STREAM* stream);
187 	bool al_seek_audio_stream_secs(ALLEGRO_AUDIO_STREAM* stream, double time);
188 	double al_get_audio_stream_position_secs(ALLEGRO_AUDIO_STREAM* stream);
189 	double al_get_audio_stream_length_secs(ALLEGRO_AUDIO_STREAM* stream);
190 	bool al_set_audio_stream_loop_secs(ALLEGRO_AUDIO_STREAM* stream, double start, double end);
191 
192 	ALLEGRO_EVENT_SOURCE * al_get_audio_stream_event_source(ALLEGRO_AUDIO_STREAM* stream);
193 
194 	/* Mixer functions */
195 	ALLEGRO_MIXER* al_create_mixer(uint freq,
196 	ALLEGRO_AUDIO_DEPTH depth, ALLEGRO_CHANNEL_CONF chan_conf);
197 	void al_destroy_mixer(ALLEGRO_MIXER* mixer);
198 	bool al_attach_sample_instance_to_mixer(ALLEGRO_SAMPLE_INSTANCE* stream, ALLEGRO_MIXER* mixer);
199 	bool al_attach_audio_stream_to_mixer(ALLEGRO_AUDIO_STREAM* stream, ALLEGRO_MIXER* mixer);
200 	bool al_attach_mixer_to_mixer(ALLEGRO_MIXER* stream, ALLEGRO_MIXER* mixer);
201 	bool al_set_mixer_postprocess_callback(ALLEGRO_MIXER* mixer, void function(void* buf, uint samples, void* data) cb, void* data);
202 
203 	uint al_get_mixer_frequency(in ALLEGRO_MIXER* mixer);
204 	ALLEGRO_CHANNEL_CONF al_get_mixer_channels(in ALLEGRO_MIXER* mixer);
205 	ALLEGRO_AUDIO_DEPTH al_get_mixer_depth(in ALLEGRO_MIXER* mixer);
206 	ALLEGRO_MIXER_QUALITY al_get_mixer_quality(in ALLEGRO_MIXER* mixer);
207 	float al_get_mixer_gain(in ALLEGRO_MIXER *mixer);
208 	bool al_get_mixer_playing(in ALLEGRO_MIXER* mixer);
209 	bool al_get_mixer_attached(in ALLEGRO_MIXER* mixer);
210 	bool al_set_mixer_frequency(ALLEGRO_MIXER* mixer, uint val);
211 	bool al_set_mixer_quality(ALLEGRO_MIXER* mixer, ALLEGRO_MIXER_QUALITY val);
212 	bool al_set_mixer_gain(ALLEGRO_MIXER *mixer, float gain);
213 	bool al_set_mixer_playing(ALLEGRO_MIXER* mixer, bool val);
214 	bool al_detach_mixer(ALLEGRO_MIXER* mixer);
215 
216 	/* Voice functions */
217 	ALLEGRO_VOICE* al_create_voice(uint freq,
218 	ALLEGRO_AUDIO_DEPTH depth,
219 	ALLEGRO_CHANNEL_CONF chan_conf);
220 	void al_destroy_voice(ALLEGRO_VOICE* voice);
221 	bool al_attach_sample_instance_to_voice(ALLEGRO_SAMPLE_INSTANCE* stream, ALLEGRO_VOICE* voice);
222 	bool al_attach_audio_stream_to_voice(ALLEGRO_AUDIO_STREAM* stream, ALLEGRO_VOICE* voice );
223 	bool al_attach_mixer_to_voice(ALLEGRO_MIXER* mixer,
224 	ALLEGRO_VOICE* voice);
225 	void al_detach_voice(ALLEGRO_VOICE* voice);
226 
227 	uint al_get_voice_frequency(in ALLEGRO_VOICE* voice);
228 	uint al_get_voice_position(in ALLEGRO_VOICE* voice);
229 	ALLEGRO_CHANNEL_CONF al_get_voice_channels(in ALLEGRO_VOICE* voice);
230 	ALLEGRO_AUDIO_DEPTH al_get_voice_depth(in ALLEGRO_VOICE* voice);
231 	bool al_get_voice_playing(in ALLEGRO_VOICE* voice);
232 	bool al_set_voice_position(ALLEGRO_VOICE* voice, uint val);
233 	bool al_set_voice_playing(ALLEGRO_VOICE* voice, bool val);
234 
235 	/* Misc. audio functions */
236 	bool al_install_audio();
237 	void al_uninstall_audio();
238 	bool al_is_audio_installed();
239 	uint al_get_allegro_audio_version();
240 
241 	size_t al_get_channel_count(ALLEGRO_CHANNEL_CONF conf);
242 	size_t al_get_audio_depth_size(ALLEGRO_AUDIO_DEPTH conf);
243 
244 	void al_fill_silence(void* buf, uint samples, ALLEGRO_AUDIO_DEPTH depth, ALLEGRO_CHANNEL_CONF chan_conf);
245 
246 	/* Simple audio layer */
247 	bool al_reserve_samples(int reserve_samples);
248 	ALLEGRO_MIXER* al_get_default_mixer();
249 	bool al_set_default_mixer(ALLEGRO_MIXER* mixer);
250 	bool al_restore_default_mixer();
251 	bool al_play_sample(ALLEGRO_SAMPLE* data, float gain, float pan, float speed, int loop, ALLEGRO_SAMPLE_ID* ret_id);
252 	void al_stop_sample(ALLEGRO_SAMPLE_ID* spl_id);
253 	void al_stop_samples();
254 	ALLEGRO_VOICE* al_get_default_voice();
255 	void al_set_default_voice(ALLEGRO_VOICE* voice);
256 
257 	/* File type handlers */
258 	bool al_register_sample_loader(in char* ext, ALLEGRO_SAMPLE* function(in char* filename) loader);
259 	bool al_register_sample_saver(in char* ext, bool function(in char* filename, ALLEGRO_SAMPLE* spl) saver);
260 	bool al_register_audio_stream_loader(in char* ext, ALLEGRO_AUDIO_STREAM* function(in char* filename, size_t buffer_count, uint samples) stream_loader);
261 
262 	bool al_register_sample_loader_f(in char* ext, ALLEGRO_SAMPLE* function(ALLEGRO_FILE* fp) loader);
263 	bool al_register_sample_saver_f(in char* ext, bool function(ALLEGRO_FILE* fp, ALLEGRO_SAMPLE* spl) saver);
264 	bool al_register_audio_stream_loader_f(in char* ext, ALLEGRO_AUDIO_STREAM* function(ALLEGRO_FILE* fp, size_t buffer_count, uint samples) stream_loader);
265 
266 	ALLEGRO_SAMPLE* al_load_sample(in char* filename);
267 	bool al_save_sample(in char* filename, ALLEGRO_SAMPLE* spl);
268 	ALLEGRO_AUDIO_STREAM* al_load_audio_stream(in char* filename, size_t buffer_count, uint samples);
269 
270 	ALLEGRO_SAMPLE* al_load_sample_f(ALLEGRO_FILE* fp, in char* ident);
271 	bool al_save_sample_f(ALLEGRO_FILE* fp, in char* ident, ALLEGRO_SAMPLE* spl);
272 	ALLEGRO_AUDIO_STREAM * al_load_audio_stream_f(ALLEGRO_FILE* fp, in char* ident,	size_t buffer_count, uint samples);
273 
274 	/* Recording functions */
275 	version (AllegroAudioUnstable)
276 	{
277 		ALLEGRO_AUDIO_RECORDER* al_create_audio_recorder(size_t fragment_count, uint samples, uint freq, ALLEGRO_AUDIO_DEPTH depth, ALLEGRO_CHANNEL_CONF chan_conf);
278 		bool al_start_audio_recorder(ALLEGRO_AUDIO_RECORDER* r);
279 		void al_stop_audio_recorder(ALLEGRO_AUDIO_RECORDER* r);
280 		bool al_is_audio_recorder_recording(ALLEGRO_AUDIO_RECORDER* r);
281 		ALLEGRO_EVENT_SOURCE* al_get_audio_recorder_event_source(ALLEGRO_AUDIO_RECORDER* r);
282 		ALLEGRO_AUDIO_RECORDER_EVENT* al_get_audio_recorder_event(ALLEGRO_EVENT* event);
283 		void al_destroy_audio_recorder(ALLEGRO_AUDIO_RECORDER* r);
284 	}
285 }