1 /*
2                                     __
3                                    / _|
4   __ _ _   _ _ __ ___  _ __ __ _  | |_ ___  ___ ___
5  / _` | | | | '__/ _ \| '__/ _` | |  _/ _ \/ __/ __|
6 | (_| | |_| | | | (_) | | | (_| | | || (_) \__ \__ \
7  \__,_|\__,_|_|  \___/|_|  \__,_| |_| \___/|___/___/
8 
9 Copyright (C) 2018-2019 Luís Ferreira <luis@aurorafoss.org>
10 Copyright (C) 2018-2019 Aurora Free Open Source Software.
11 
12 This file is part of the Aurora Free Open Source Software. This
13 organization promote free and open source software that you can
14 redistribute and/or modify under the terms of the GNU Lesser General
15 Public License Version 3 as published by the Free Software Foundation or
16 (at your option) any later version approved by the Aurora Free Open Source
17 Software Organization. The license is available in the package root path
18 as 'LICENSE' file. Please review the following information to ensure the
19 GNU Lesser General Public License version 3 requirements will be met:
20 https://www.gnu.org/licenses/lgpl.html .
21 
22 Alternatively, this file may be used under the terms of the GNU General
23 Public License version 3 or later as published by the Free Software
24 Foundation. Please review the following information to ensure the GNU
25 General Public License requirements will be met:
26 http://www.gnu.org/licenses/gpl-3.0.html.
27 
28 NOTE: All products, services or anything associated to trademarks and
29 service marks used or referenced on this file are the property of their
30 respective companies/owners or its subsidiaries. Other names and brands
31 may be claimed as the property of others.
32 
33 For more info about intellectual property visit: aurorafoss.org or
34 directly send an email to: contact (at) aurorafoss.org .
35 */
36 
37 module riverd.soundio.types;
38 
39 import core.stdc.stdarg;
40 
41 extern(C) @nogc nothrow:
42 
43 /// See also ::soundio_strerror
44 enum SoundIoError
45 {
46 	SoundIoErrorNone = 0,
47 	/// Out of memory.
48 	SoundIoErrorNoMem = 1,
49 	/// The backend does not appear to be active or running.
50 	SoundIoErrorInitAudioBackend = 2,
51 	/// A system resource other than memory was not available.
52 	SoundIoErrorSystemResources = 3,
53 	/// Attempted to open a device and failed.
54 	SoundIoErrorOpeningDevice = 4,
55 	SoundIoErrorNoSuchDevice = 5,
56 	/// The programmer did not comply with the API.
57 	SoundIoErrorInvalid = 6,
58 	/// libsoundio was compiled without support for that backend.
59 	SoundIoErrorBackendUnavailable = 7,
60 	/// An open stream had an error that can only be recovered from by
61 	/// destroying the stream and creating it again.
62 	SoundIoErrorStreaming = 8,
63 	/// Attempted to use a device with parameters it cannot support.
64 	SoundIoErrorIncompatibleDevice = 9,
65 	/// When JACK returns `JackNoSuchClient`
66 	SoundIoErrorNoSuchClient = 10,
67 	/// Attempted to use parameters that the backend cannot support.
68 	SoundIoErrorIncompatibleBackend = 11,
69 	/// Backend server shutdown or became inactive.
70 	SoundIoErrorBackendDisconnected = 12,
71 	SoundIoErrorInterrupted = 13,
72 	/// Buffer underrun occurred.
73 	SoundIoErrorUnderflow = 14,
74 	/// Unable to convert to or from UTF-8 to the native string format.
75 	SoundIoErrorEncodingString = 15
76 }
77 
78 /// Specifies where a channel is physically located.
79 enum SoundIoChannelId
80 {
81 	SoundIoChannelIdInvalid = 0,
82 
83 	SoundIoChannelIdFrontLeft = 1, ///< First of the more commonly supported ids.
84 	SoundIoChannelIdFrontRight = 2,
85 	SoundIoChannelIdFrontCenter = 3,
86 	SoundIoChannelIdLfe = 4,
87 	SoundIoChannelIdBackLeft = 5,
88 	SoundIoChannelIdBackRight = 6,
89 	SoundIoChannelIdFrontLeftCenter = 7,
90 	SoundIoChannelIdFrontRightCenter = 8,
91 	SoundIoChannelIdBackCenter = 9,
92 	SoundIoChannelIdSideLeft = 10,
93 	SoundIoChannelIdSideRight = 11,
94 	SoundIoChannelIdTopCenter = 12,
95 	SoundIoChannelIdTopFrontLeft = 13,
96 	SoundIoChannelIdTopFrontCenter = 14,
97 	SoundIoChannelIdTopFrontRight = 15,
98 	SoundIoChannelIdTopBackLeft = 16,
99 	SoundIoChannelIdTopBackCenter = 17,
100 	SoundIoChannelIdTopBackRight = 18, ///< Last of the more commonly supported ids.
101 
102 	SoundIoChannelIdBackLeftCenter = 19, ///< First of the less commonly supported ids.
103 	SoundIoChannelIdBackRightCenter = 20,
104 	SoundIoChannelIdFrontLeftWide = 21,
105 	SoundIoChannelIdFrontRightWide = 22,
106 	SoundIoChannelIdFrontLeftHigh = 23,
107 	SoundIoChannelIdFrontCenterHigh = 24,
108 	SoundIoChannelIdFrontRightHigh = 25,
109 	SoundIoChannelIdTopFrontLeftCenter = 26,
110 	SoundIoChannelIdTopFrontRightCenter = 27,
111 	SoundIoChannelIdTopSideLeft = 28,
112 	SoundIoChannelIdTopSideRight = 29,
113 	SoundIoChannelIdLeftLfe = 30,
114 	SoundIoChannelIdRightLfe = 31,
115 	SoundIoChannelIdLfe2 = 32,
116 	SoundIoChannelIdBottomCenter = 33,
117 	SoundIoChannelIdBottomLeftCenter = 34,
118 	SoundIoChannelIdBottomRightCenter = 35,
119 
120 	/// Mid/side recording
121 	SoundIoChannelIdMsMid = 36,
122 	SoundIoChannelIdMsSide = 37,
123 
124 	/// first order ambisonic channels
125 	SoundIoChannelIdAmbisonicW = 38,
126 	SoundIoChannelIdAmbisonicX = 39,
127 	SoundIoChannelIdAmbisonicY = 40,
128 	SoundIoChannelIdAmbisonicZ = 41,
129 
130 	/// X-Y Recording
131 	SoundIoChannelIdXyX = 42,
132 	SoundIoChannelIdXyY = 43,
133 
134 	SoundIoChannelIdHeadphonesLeft = 44, ///< First of the "other" channel ids
135 	SoundIoChannelIdHeadphonesRight = 45,
136 	SoundIoChannelIdClickTrack = 46,
137 	SoundIoChannelIdForeignLanguage = 47,
138 	SoundIoChannelIdHearingImpaired = 48,
139 	SoundIoChannelIdNarration = 49,
140 	SoundIoChannelIdHaptic = 50,
141 	SoundIoChannelIdDialogCentricMix = 51, ///< Last of the "other" channel ids
142 
143 	SoundIoChannelIdAux = 52,
144 	SoundIoChannelIdAux0 = 53,
145 	SoundIoChannelIdAux1 = 54,
146 	SoundIoChannelIdAux2 = 55,
147 	SoundIoChannelIdAux3 = 56,
148 	SoundIoChannelIdAux4 = 57,
149 	SoundIoChannelIdAux5 = 58,
150 	SoundIoChannelIdAux6 = 59,
151 	SoundIoChannelIdAux7 = 60,
152 	SoundIoChannelIdAux8 = 61,
153 	SoundIoChannelIdAux9 = 62,
154 	SoundIoChannelIdAux10 = 63,
155 	SoundIoChannelIdAux11 = 64,
156 	SoundIoChannelIdAux12 = 65,
157 	SoundIoChannelIdAux13 = 66,
158 	SoundIoChannelIdAux14 = 67,
159 	SoundIoChannelIdAux15 = 68
160 }
161 
162 /// Built-in channel layouts for convenience.
163 enum SoundIoChannelLayoutId
164 {
165 	SoundIoChannelLayoutIdMono = 0,
166 	SoundIoChannelLayoutIdStereo = 1,
167 	SoundIoChannelLayoutId2Point1 = 2,
168 	SoundIoChannelLayoutId3Point0 = 3,
169 	SoundIoChannelLayoutId3Point0Back = 4,
170 	SoundIoChannelLayoutId3Point1 = 5,
171 	SoundIoChannelLayoutId4Point0 = 6,
172 	SoundIoChannelLayoutIdQuad = 7,
173 	SoundIoChannelLayoutIdQuadSide = 8,
174 	SoundIoChannelLayoutId4Point1 = 9,
175 	SoundIoChannelLayoutId5Point0Back = 10,
176 	SoundIoChannelLayoutId5Point0Side = 11,
177 	SoundIoChannelLayoutId5Point1 = 12,
178 	SoundIoChannelLayoutId5Point1Back = 13,
179 	SoundIoChannelLayoutId6Point0Side = 14,
180 	SoundIoChannelLayoutId6Point0Front = 15,
181 	SoundIoChannelLayoutIdHexagonal = 16,
182 	SoundIoChannelLayoutId6Point1 = 17,
183 	SoundIoChannelLayoutId6Point1Back = 18,
184 	SoundIoChannelLayoutId6Point1Front = 19,
185 	SoundIoChannelLayoutId7Point0 = 20,
186 	SoundIoChannelLayoutId7Point0Front = 21,
187 	SoundIoChannelLayoutId7Point1 = 22,
188 	SoundIoChannelLayoutId7Point1Wide = 23,
189 	SoundIoChannelLayoutId7Point1WideBack = 24,
190 	SoundIoChannelLayoutIdOctagonal = 25
191 }
192 
193 enum SoundIoBackend
194 {
195 	SoundIoBackendNone = 0,
196 	SoundIoBackendJack = 1,
197 	SoundIoBackendPulseAudio = 2,
198 	SoundIoBackendAlsa = 3,
199 	SoundIoBackendCoreAudio = 4,
200 	SoundIoBackendWasapi = 5,
201 	SoundIoBackendDummy = 6
202 }
203 
204 enum SoundIoDeviceAim
205 {
206 	SoundIoDeviceAimInput = 0, ///< capture / recording
207 	SoundIoDeviceAimOutput = 1 ///< playback
208 }
209 
210 /// For your convenience, Native Endian and Foreign Endian constants are defined
211 /// which point to the respective SoundIoFormat values.
212 enum SoundIoFormat
213 {
214 	SoundIoFormatInvalid = 0,
215 	SoundIoFormatS8 = 1, ///< Signed 8 bit
216 	SoundIoFormatU8 = 2, ///< Unsigned 8 bit
217 	SoundIoFormatS16LE = 3, ///< Signed 16 bit Little Endian
218 	SoundIoFormatS16BE = 4, ///< Signed 16 bit Big Endian
219 	SoundIoFormatU16LE = 5, ///< Unsigned 16 bit Little Endian
220 	SoundIoFormatU16BE = 6, ///< Unsigned 16 bit Little Endian
221 	SoundIoFormatS24LE = 7, ///< Signed 24 bit Little Endian using low three bytes in 32-bit word
222 	SoundIoFormatS24BE = 8, ///< Signed 24 bit Big Endian using low three bytes in 32-bit word
223 	SoundIoFormatU24LE = 9, ///< Unsigned 24 bit Little Endian using low three bytes in 32-bit word
224 	SoundIoFormatU24BE = 10, ///< Unsigned 24 bit Big Endian using low three bytes in 32-bit word
225 	SoundIoFormatS32LE = 11, ///< Signed 32 bit Little Endian
226 	SoundIoFormatS32BE = 12, ///< Signed 32 bit Big Endian
227 	SoundIoFormatU32LE = 13, ///< Unsigned 32 bit Little Endian
228 	SoundIoFormatU32BE = 14, ///< Unsigned 32 bit Big Endian
229 	SoundIoFormatFloat32LE = 15, ///< Float 32 bit Little Endian, Range -1.0 to 1.0
230 	SoundIoFormatFloat32BE = 16, ///< Float 32 bit Big Endian, Range -1.0 to 1.0
231 	SoundIoFormatFloat64LE = 17, ///< Float 64 bit Little Endian, Range -1.0 to 1.0
232 	SoundIoFormatFloat64BE = 18 ///< Float 64 bit Big Endian, Range -1.0 to 1.0
233 }
234 
235 
236 enum SOUNDIO_MAX_CHANNELS = 24;
237 /// The size of this struct is OK to use.
238 struct SoundIoChannelLayout
239 {
240 	const(char)* name;
241 	int channel_count;
242 	SoundIoChannelId[SOUNDIO_MAX_CHANNELS] channels;
243 }
244 
245 /// The size of this struct is OK to use.
246 struct SoundIoSampleRateRange
247 {
248 	int min;
249 	int max;
250 }
251 
252 /// The size of this struct is OK to use.
253 struct SoundIoChannelArea
254 {
255 	/// Base address of buffer.
256 	char* ptr;
257 	/// How many bytes it takes to get from the beginning of one sample to
258 	/// the beginning of the next sample.
259 	int step;
260 }
261 
262 /// The size of this struct is not part of the API or ABI.
263 struct SoundIo
264 {
265 	/// Optional. Put whatever you want here. Defaults to NULL.
266 	void* userdata;
267 	/// Optional callback. Called when the list of devices change. Only called
268 	/// during a call to ::soundio_flush_events or ::soundio_wait_events.
269 	void function(SoundIo*) on_devices_change;
270 	/// Optional callback. Called when the backend disconnects. For example,
271 	/// when the JACK server shuts down. When this happens, listing devices
272 	/// and opening streams will always fail with
273 	/// SoundIoErrorBackendDisconnected. This callback is only called during a
274 	/// call to ::soundio_flush_events or ::soundio_wait_events.
275 	/// If you do not supply a callback, the default will crash your program
276 	/// with an error message. This callback is also called when the thread
277 	/// that retrieves device information runs into an unrecoverable condition
278 	/// such as running out of memory.
279 	///
280 	/// Possible errors:
281 	/// * #SoundIoErrorBackendDisconnected
282 	/// * #SoundIoErrorNoMem
283 	/// * #SoundIoErrorSystemResources
284 	/// * #SoundIoErrorOpeningDevice - unexpected problem accessing device
285 	///   information
286 	void function(SoundIo*, int err) on_backend_disconnect;
287 	/// Optional callback. Called from an unknown thread that you should not use
288 	/// to call any soundio functions. You may use this to signal a condition
289 	/// variable to wake up. Called when ::soundio_wait_events would be woken up.
290 	void function(SoundIo*) on_events_signal;
291 
292 	/// Read-only. After calling ::soundio_connect or ::soundio_connect_backend,
293 	/// this field tells which backend is currently connected.
294 	SoundIoBackend current_backend;
295 
296 	/// Optional: Application name.
297 	/// PulseAudio uses this for "application name".
298 	/// JACK uses this for `client_name`.
299 	/// Must not contain a colon (":").
300 	const(char)* app_name;
301 
302 	/// Optional: Real time priority warning.
303 	/// This callback is fired when making thread real-time priority failed. By
304 	/// default, it will print to stderr only the first time it is called
305 	/// a message instructing the user how to configure their system to allow
306 	/// real-time priority threads. This must be set to a function not NULL.
307 	/// To silence the warning, assign this to a function that does nothing.
308 	void function() emit_rtprio_warning;
309 
310 	/// Optional: JACK info callback.
311 	/// By default, libsoundio sets this to an empty function in order to
312 	/// silence stdio messages from JACK. You may override the behavior by
313 	/// setting this to `NULL` or providing your own function. This is
314 	/// registered with JACK regardless of whether ::soundio_connect_backend
315 	/// succeeds.
316 	void function(const(char)* msg) jack_info_callback;
317 	/// Optional: JACK error callback.
318 	/// See SoundIo::jack_info_callback
319 	void function(const(char)* msg) jack_error_callback;
320 }
321 
322 /// The size of this struct is not part of the API or ABI.
323 struct SoundIoDevice
324 {
325 	/// Read-only. Set automatically.
326 	SoundIo* soundio;
327 
328 	/// A string of bytes that uniquely identifies this device.
329 	/// If the same physical device supports both input and output, that makes
330 	/// one SoundIoDevice for the input and one SoundIoDevice for the output.
331 	/// In this case, the id of each SoundIoDevice will be the same, and
332 	/// SoundIoDevice::aim will be different. Additionally, if the device
333 	/// supports raw mode, there may be up to four devices with the same id:
334 	/// one for each value of SoundIoDevice::is_raw and one for each value of
335 	/// SoundIoDevice::aim.
336 	char* id;
337 	/// User-friendly UTF-8 encoded text to describe the device.
338 	char* name;
339 
340 	/// Tells whether this device is an input device or an output device.
341 	SoundIoDeviceAim aim;
342 
343 	/// Channel layouts are handled similarly to SoundIoDevice::formats.
344 	/// If this information is missing due to a SoundIoDevice::probe_error,
345 	/// layouts will be NULL. It's OK to modify this data, for example calling
346 	/// ::soundio_sort_channel_layouts on it.
347 	/// Devices are guaranteed to have at least 1 channel layout.
348 	SoundIoChannelLayout* layouts;
349 	int layout_count;
350 	/// See SoundIoDevice::current_format
351 	SoundIoChannelLayout current_layout;
352 
353 	/// List of formats this device supports. See also
354 	/// SoundIoDevice::current_format.
355 	SoundIoFormat* formats;
356 	/// How many formats are available in SoundIoDevice::formats.
357 	int format_count;
358 	/// A device is either a raw device or it is a virtual device that is
359 	/// provided by a software mixing service such as dmix or PulseAudio (see
360 	/// SoundIoDevice::is_raw). If it is a raw device,
361 	/// current_format is meaningless;
362 	/// the device has no current format until you open it. On the other hand,
363 	/// if it is a virtual device, current_format describes the
364 	/// destination sample format that your audio will be converted to. Or,
365 	/// if you're the lucky first application to open the device, you might
366 	/// cause the current_format to change to your format.
367 	/// Generally, you want to ignore current_format and use
368 	/// whatever format is most convenient
369 	/// for you which is supported by the device, because when you are the only
370 	/// application left, the mixer might decide to switch
371 	/// current_format to yours. You can learn the supported formats via
372 	/// formats and SoundIoDevice::format_count. If this information is missing
373 	/// due to a probe error, formats will be `NULL`. If current_format is
374 	/// unavailable, it will be set to #SoundIoFormatInvalid.
375 	/// Devices are guaranteed to have at least 1 format available.
376 	SoundIoFormat current_format;
377 
378 	/// Sample rate is the number of frames per second.
379 	/// Sample rate is handled very similar to SoundIoDevice::formats.
380 	/// If sample rate information is missing due to a probe error, the field
381 	/// will be set to NULL.
382 	/// Devices which have SoundIoDevice::probe_error set to #SoundIoErrorNone are
383 	/// guaranteed to have at least 1 sample rate available.
384 	SoundIoSampleRateRange* sample_rates;
385 	/// How many sample rate ranges are available in
386 	/// SoundIoDevice::sample_rates. 0 if sample rate information is missing
387 	/// due to a probe error.
388 	int sample_rate_count;
389 	/// See SoundIoDevice::current_format
390 	/// 0 if sample rate information is missing due to a probe error.
391 	int sample_rate_current;
392 
393 	/// Software latency minimum in seconds. If this value is unknown or
394 	/// irrelevant, it is set to 0.0.
395 	/// For PulseAudio and WASAPI this value is unknown until you open a
396 	/// stream.
397 	double software_latency_min;
398 	/// Software latency maximum in seconds. If this value is unknown or
399 	/// irrelevant, it is set to 0.0.
400 	/// For PulseAudio and WASAPI this value is unknown until you open a
401 	/// stream.
402 	double software_latency_max;
403 	/// Software latency in seconds. If this value is unknown or
404 	/// irrelevant, it is set to 0.0.
405 	/// For PulseAudio and WASAPI this value is unknown until you open a
406 	/// stream.
407 	/// See SoundIoDevice::current_format
408 	double software_latency_current;
409 
410 	/// Raw means that you are directly opening the hardware device and not
411 	/// going through a proxy such as dmix, PulseAudio, or JACK. When you open a
412 	/// raw device, other applications on the computer are not able to
413 	/// simultaneously access the device. Raw devices do not perform automatic
414 	/// resampling and thus tend to have fewer formats available.
415 	bool is_raw;
416 
417 	/// Devices are reference counted. See ::soundio_device_ref and
418 	/// ::soundio_device_unref.
419 	int ref_count;
420 
421 	/// This is set to a SoundIoError representing the result of the device
422 	/// probe. Ideally this will be SoundIoErrorNone in which case all the
423 	/// fields of the device will be populated. If there is an error code here
424 	/// then information about formats, sample rates, and channel layouts might
425 	/// be missing.
426 	///
427 	/// Possible errors:
428 	/// * #SoundIoErrorOpeningDevice
429 	/// * #SoundIoErrorNoMem
430 	int probe_error;
431 }
432 
433 /// The size of this struct is not part of the API or ABI.
434 struct SoundIoOutStream
435 {
436 	/// Populated automatically when you call ::soundio_outstream_create.
437 	SoundIoDevice* device;
438 
439 	/// Defaults to #SoundIoFormatFloat32NE, followed by the first one
440 	/// supported.
441 	SoundIoFormat format;
442 
443 	/// Sample rate is the number of frames per second.
444 	/// Defaults to 48000 (and then clamped into range).
445 	int sample_rate;
446 
447 	/// Defaults to Stereo, if available, followed by the first layout
448 	/// supported.
449 	SoundIoChannelLayout layout;
450 
451 	/// Ignoring hardware latency, this is the number of seconds it takes for
452 	/// the last sample in a full buffer to be played.
453 	/// After you call ::soundio_outstream_open, this value is replaced with the
454 	/// actual software latency, as near to this value as possible.
455 	/// On systems that support clearing the buffer, this defaults to a large
456 	/// latency, potentially upwards of 2 seconds, with the understanding that
457 	/// you will call ::soundio_outstream_clear_buffer when you want to reduce
458 	/// the latency to 0. On systems that do not support clearing the buffer,
459 	/// this defaults to a reasonable lower latency value.
460 	///
461 	/// On backends with high latencies (such as 2 seconds), `frame_count_min`
462 	/// will be 0, meaning you don't have to fill the entire buffer. In this
463 	/// case, the large buffer is there if you want it; you only have to fill
464 	/// as much as you want. On backends like JACK, `frame_count_min` will be
465 	/// equal to `frame_count_max` and if you don't fill that many frames, you
466 	/// will get glitches.
467 	///
468 	/// If the device has unknown software latency min and max values, you may
469 	/// still set this, but you might not get the value you requested.
470 	/// For PulseAudio, if you set this value to non-default, it sets
471 	/// `PA_STREAM_ADJUST_LATENCY` and is the value used for `maxlength` and
472 	/// `tlength`.
473 	///
474 	/// For JACK, this value is always equal to
475 	/// SoundIoDevice::software_latency_current of the device.
476 	double software_latency;
477 
478 	/// Defaults to NULL. Put whatever you want here.
479 	void* userdata;
480 	/// In this callback, you call ::soundio_outstream_begin_write and
481 	/// ::soundio_outstream_end_write as many times as necessary to write
482 	/// at minimum `frame_count_min` frames and at maximum `frame_count_max`
483 	/// frames. `frame_count_max` will always be greater than 0. Note that you
484 	/// should write as many frames as you can; `frame_count_min` might be 0 and
485 	/// you can still get a buffer underflow if you always write
486 	/// `frame_count_min` frames.
487 	///
488 	/// For Dummy, ALSA, and PulseAudio, `frame_count_min` will be 0. For JACK
489 	/// and CoreAudio `frame_count_min` will be equal to `frame_count_max`.
490 	///
491 	/// The code in the supplied function must be suitable for real-time
492 	/// execution. That means that it cannot call functions that might block
493 	/// for a long time. This includes all I/O functions (disk, TTY, network),
494 	/// malloc, free, printf, pthread_mutex_lock, sleep, wait, poll, select,
495 	/// pthread_join, pthread_cond_wait, etc.
496 	void function(SoundIoOutStream*, int frame_count_min, int frame_count_max) write_callback;
497 	/// This optional callback happens when the sound device runs out of
498 	/// buffered audio data to play. After this occurs, the outstream waits
499 	/// until the buffer is full to resume playback.
500 	/// This is called from the SoundIoOutStream::write_callback thread context.
501 	void function(SoundIoOutStream*) underflow_callback;
502 	/// Optional callback. `err` is always SoundIoErrorStreaming.
503 	/// SoundIoErrorStreaming is an unrecoverable error. The stream is in an
504 	/// invalid state and must be destroyed.
505 	/// If you do not supply error_callback, the default callback will print
506 	/// a message to stderr and then call `abort`.
507 	/// This is called from the SoundIoOutStream::write_callback thread context.
508 	void function(SoundIoOutStream*, int err) error_callback;
509 
510 	/// Optional: Name of the stream. Defaults to "SoundIoOutStream"
511 	/// PulseAudio uses this for the stream name.
512 	/// JACK uses this for the client name of the client that connects when you
513 	/// open the stream.
514 	/// WASAPI uses this for the session display name.
515 	/// Must not contain a colon (":").
516 	const(char)* name;
517 
518 	/// Optional: Hint that this output stream is nonterminal. This is used by
519 	/// JACK and it means that the output stream data originates from an input
520 	/// stream. Defaults to `false`.
521 	bool non_terminal_hint;
522 
523 	/// computed automatically when you call ::soundio_outstream_open
524 	int bytes_per_frame;
525 	/// computed automatically when you call ::soundio_outstream_open
526 	int bytes_per_sample;
527 
528 	/// If setting the channel layout fails for some reason, this field is set
529 	/// to an error code. Possible error codes are:
530 	/// * #SoundIoErrorIncompatibleDevice
531 	int layout_error;
532 }
533 
534 /// The size of this struct is not part of the API or ABI.
535 struct SoundIoInStream
536 {
537 	/// Populated automatically when you call ::soundio_outstream_create.
538 	SoundIoDevice* device;
539 
540 	/// Defaults to #SoundIoFormatFloat32NE, followed by the first one
541 	/// supported.
542 	SoundIoFormat format;
543 
544 	/// Sample rate is the number of frames per second.
545 	/// Defaults to max(sample_rate_min, min(sample_rate_max, 48000))
546 	int sample_rate;
547 
548 	/// Defaults to Stereo, if available, followed by the first layout
549 	/// supported.
550 	SoundIoChannelLayout layout;
551 
552 	/// Ignoring hardware latency, this is the number of seconds it takes for a
553 	/// captured sample to become available for reading.
554 	/// After you call ::soundio_instream_open, this value is replaced with the
555 	/// actual software latency, as near to this value as possible.
556 	/// A higher value means less CPU usage. Defaults to a large value,
557 	/// potentially upwards of 2 seconds.
558 	/// If the device has unknown software latency min and max values, you may
559 	/// still set this, but you might not get the value you requested.
560 	/// For PulseAudio, if you set this value to non-default, it sets
561 	/// `PA_STREAM_ADJUST_LATENCY` and is the value used for `fragsize`.
562 	/// For JACK, this value is always equal to
563 	/// SoundIoDevice::software_latency_current
564 	double software_latency;
565 
566 	/// Defaults to NULL. Put whatever you want here.
567 	void* userdata;
568 	/// In this function call ::soundio_instream_begin_read and
569 	/// ::soundio_instream_end_read as many times as necessary to read at
570 	/// minimum `frame_count_min` frames and at maximum `frame_count_max`
571 	/// frames. If you return from read_callback without having read
572 	/// `frame_count_min`, the frames will be dropped. `frame_count_max` is how
573 	/// many frames are available to read.
574 	///
575 	/// The code in the supplied function must be suitable for real-time
576 	/// execution. That means that it cannot call functions that might block
577 	/// for a long time. This includes all I/O functions (disk, TTY, network),
578 	/// malloc, free, printf, pthread_mutex_lock, sleep, wait, poll, select,
579 	/// pthread_join, pthread_cond_wait, etc.
580 	void function(SoundIoInStream*, int frame_count_min, int frame_count_max) read_callback;
581 	/// This optional callback happens when the sound device buffer is full,
582 	/// yet there is more captured audio to put in it.
583 	/// This is never fired for PulseAudio.
584 	/// This is called from the SoundIoInStream::read_callback thread context.
585 	void function(SoundIoInStream*) overflow_callback;
586 	/// Optional callback. `err` is always SoundIoErrorStreaming.
587 	/// SoundIoErrorStreaming is an unrecoverable error. The stream is in an
588 	/// invalid state and must be destroyed.
589 	/// If you do not supply `error_callback`, the default callback will print
590 	/// a message to stderr and then abort().
591 	/// This is called from the SoundIoInStream::read_callback thread context.
592 	void function(SoundIoInStream*, int err) error_callback;
593 
594 	/// Optional: Name of the stream. Defaults to "SoundIoInStream";
595 	/// PulseAudio uses this for the stream name.
596 	/// JACK uses this for the client name of the client that connects when you
597 	/// open the stream.
598 	/// WASAPI uses this for the session display name.
599 	/// Must not contain a colon (":").
600 	const(char)* name;
601 
602 	/// Optional: Hint that this input stream is nonterminal. This is used by
603 	/// JACK and it means that the data received by the stream will be
604 	/// passed on or made available to another stream. Defaults to `false`.
605 	bool non_terminal_hint;
606 
607 	/// computed automatically when you call ::soundio_instream_open
608 	int bytes_per_frame;
609 	/// computed automatically when you call ::soundio_instream_open
610 	int bytes_per_sample;
611 
612 	/// If setting the channel layout fails for some reason, this field is set
613 	/// to an error code. Possible error codes are: #SoundIoErrorIncompatibleDevice
614 	int layout_error;
615 }
616 
617 version (BigEndian)
618 {
619 	enum SoundIoFormatS16NE = SoundIoFormat.SoundIoFormatS16BE;
620 	enum SoundIoFormatU16NE = SoundIoFormat.SoundIoFormatU16BE;
621 	enum SoundIoFormatS24NE = SoundIoFormat.SoundIoFormatS24BE;
622 	enum SoundIoFormatU24NE = SoundIoFormat.SoundIoFormatU24BE;
623 	enum SoundIoFormatS32NE = SoundIoFormat.SoundIoFormatS32BE;
624 	enum SoundIoFormatU32NE = SoundIoFormat.SoundIoFormatU32BE;
625 	enum SoundIoFormatFloat32NE = SoundIoFormat.SoundIoFormatFloat32BE;
626 	enum SoundIoFormatFloat64NE = SoundIoFormat.SoundIoFormatFloat64BE;
627 
628 	enum SoundIoFormatS16FE = SoundIoFormat.SoundIoFormatS16LE;
629 	enum SoundIoFormatU16FE = SoundIoFormat.SoundIoFormatU16LE;
630 	enum SoundIoFormatS24FE = SoundIoFormat.SoundIoFormatS24LE;
631 	enum SoundIoFormatU24FE = SoundIoFormat.SoundIoFormatU24LE;
632 	enum SoundIoFormatS32FE = SoundIoFormat.SoundIoFormatS32LE;
633 	enum SoundIoFormatU32FE = SoundIoFormat.SoundIoFormatU32LE;
634 	enum SoundIoFormatFloat32FE = SoundIoFormat.SoundIoFormatFloat32LE;
635 	enum SoundIoFormatFloat64FE = SoundIoFormat.SoundIoFormatFloat64LE;
636 }
637 else version (LittleEndian)
638 {
639 	enum SoundIoFormatS16NE = SoundIoFormat.SoundIoFormatS16LE;
640 	enum SoundIoFormatU16NE = SoundIoFormat.SoundIoFormatU16LE;
641 	enum SoundIoFormatS24NE = SoundIoFormat.SoundIoFormatS24LE;
642 	enum SoundIoFormatU24NE = SoundIoFormat.SoundIoFormatU24LE;
643 	enum SoundIoFormatS32NE = SoundIoFormat.SoundIoFormatS32LE;
644 	enum SoundIoFormatU32NE = SoundIoFormat.SoundIoFormatU32LE;
645 	enum SoundIoFormatFloat32NE = SoundIoFormat.SoundIoFormatFloat32LE;
646 	enum SoundIoFormatFloat64NE = SoundIoFormat.SoundIoFormatFloat64LE;
647 
648 	enum SoundIoFormatS16FE = SoundIoFormat.SoundIoFormatS16BE;
649 	enum SoundIoFormatU16FE = SoundIoFormat.SoundIoFormatU16BE;
650 	enum SoundIoFormatS24FE = SoundIoFormat.SoundIoFormatS24BE;
651 	enum SoundIoFormatU24FE = SoundIoFormat.SoundIoFormatU24BE;
652 	enum SoundIoFormatS32FE = SoundIoFormat.SoundIoFormatS32BE;
653 	enum SoundIoFormatU32FE = SoundIoFormat.SoundIoFormatU32BE;
654 	enum SoundIoFormatFloat32FE = SoundIoFormat.SoundIoFormatFloat32BE;
655 	enum SoundIoFormatFloat64FE = SoundIoFormat.SoundIoFormatFloat64BE;
656 }
657 else
658 {
659 	static assert(false, "unknown byte order");
660 }
661 
662 /// A ring buffer is a single-reader single-writer lock-free fixed-size queue.
663 /// libsoundio ring buffers use memory mapping techniques to enable a
664 /// contiguous buffer when reading or writing across the boundary of the ring
665 /// buffer's capacity.
666 struct SoundIoRingBuffer;
667 
668 extern(C) @nogc nothrow {
669 	alias da_soundio_version_major = int function(); ///
670 	alias da_soundio_version_minor = int function(); ///
671 	alias da_soundio_version_patch = int function(); ///
672 	alias da_soundio_create = SoundIo* function(); ///
673 	alias da_soundio_instream_create = SoundIoInStream* function(SoundIoDevice* device); ///
674 	alias da_soundio_ring_buffer_create = SoundIoRingBuffer* function(SoundIo* soundio, int requested_capacity); ///
675 	alias da_soundio_ring_buffer_write_ptr = char* function(SoundIoRingBuffer* ring_buffer); ///
676 	alias da_soundio_ring_buffer_read_ptr = char* function(SoundIoRingBuffer* ring_buffer); ///
677 	alias da_soundio_get_input_device = SoundIoDevice* function(SoundIo* soundio, int index); ///
678 	alias da_soundio_get_output_device = SoundIoDevice* function(SoundIo* soundio, int index); ///
679 	alias da_soundio_outstream_create = SoundIoOutStream* function(SoundIoDevice* device); ///
680 	alias da_soundio_best_matching_channel_layout = const(SoundIoChannelLayout)* function(const(SoundIoChannelLayout)* preferred_layouts, int preferred_layout_count, const(SoundIoChannelLayout)* available_layouts, int available_layout_count); ///
681 	alias da_soundio_channel_layout_get_builtin = const(SoundIoChannelLayout)* function(int index); ///
682 	alias da_soundio_channel_layout_get_default = const(SoundIoChannelLayout)* function(int channel_count); ///
683 	alias da_soundio_format_string = const(char)* function(SoundIoFormat format); ///
684 	alias da_soundio_strerror = const(char)* function(int error); ///
685 	alias da_soundio_backend_name = const(char)* function(SoundIoBackend backend); ///
686 	alias da_soundio_get_channel_name = const(char)* function(SoundIoChannelId id); ///
687 	alias da_soundio_version_string = const(char)* function(); ///
688 	alias da_soundio_destroy = void function(SoundIo* soundio); ///
689 	alias da_soundio_connect = int function(SoundIo* soundio); ///
690 	alias da_soundio_connect_backend = int function(SoundIo* soundio, SoundIoBackend backend); ///
691 	alias da_soundio_disconnect = void function(SoundIo* soundio); ///
692 	alias da_soundio_backend_count = int function(SoundIo* soundio); ///
693 	alias da_soundio_get_backend = SoundIoBackend function(SoundIo* soundio, int index); ///
694 	alias da_soundio_have_backend = bool function(SoundIoBackend backend); ///
695 	alias da_soundio_flush_events = void function(SoundIo* soundio); ///
696 	alias da_soundio_wait_events = void function(SoundIo* soundio); ///
697 	alias da_soundio_wakeup = void function(SoundIo* soundio); ///
698 	alias da_soundio_force_device_scan = void function(SoundIo* soundio); ///
699 	alias da_soundio_channel_layout_equal = bool function(const(SoundIoChannelLayout)* a, const(SoundIoChannelLayout)* b); ///
700 	alias da_soundio_parse_channel_id = SoundIoChannelId function(const(char)* str, int str_len); ///
701 	alias da_soundio_channel_layout_builtin_count = int function(); ///
702 	alias da_soundio_channel_layout_find_channel = int function(const(SoundIoChannelLayout)* layout, SoundIoChannelId channel); ///
703 	alias da_soundio_channel_layout_detect_builtin = bool function(SoundIoChannelLayout* layout); ///
704 	alias da_soundio_sort_channel_layouts = void function(SoundIoChannelLayout* layouts, int layout_count); ///
705 	alias da_soundio_get_bytes_per_sample = int function(SoundIoFormat format); ///
706 	alias da_soundio_get_bytes_per_frame = int function(SoundIoFormat format, int channel_count); ///
707 	alias da_soundio_get_bytes_per_second = int function(SoundIoFormat format, int channel_count, int sample_rate); ///
708 	alias da_soundio_input_device_count = int function(SoundIo* soundio); ///
709 	alias da_soundio_output_device_count = int function(SoundIo* soundio); ///
710 	alias da_soundio_default_input_device_index = int function(SoundIo* soundio); ///
711 	alias da_soundio_default_output_device_index = int function(SoundIo* soundio); ///
712 	alias da_soundio_device_ref = void function(SoundIoDevice* device); ///
713 	alias da_soundio_device_unref = void function(SoundIoDevice* device); ///
714 	alias da_soundio_device_equal = bool function(const(SoundIoDevice)* a, const(SoundIoDevice)* b); ///
715 	alias da_soundio_device_sort_channel_layouts = void function(SoundIoDevice* device); ///
716 	alias da_soundio_device_supports_format = bool function(SoundIoDevice* device, SoundIoFormat format); ///
717 	alias da_soundio_device_supports_layout = bool function(SoundIoDevice* device, const(SoundIoChannelLayout)* layout); ///
718 	alias da_soundio_device_supports_sample_rate = bool function(SoundIoDevice* device, int sample_rate); ///
719 	alias da_soundio_device_nearest_sample_rate = int function(SoundIoDevice* device, int sample_rate); ///
720 	alias da_soundio_outstream_destroy = void function(SoundIoOutStream* outstream); ///
721 	alias da_soundio_outstream_open = int function(SoundIoOutStream* outstream); ///
722 	alias da_soundio_outstream_start = int function(SoundIoOutStream* outstream); ///
723 	alias da_soundio_outstream_begin_write = int function(SoundIoOutStream* outstream, SoundIoChannelArea** areas, int* frame_count); ///
724 	alias da_soundio_outstream_end_write = int function(SoundIoOutStream* outstream); ///
725 	alias da_soundio_outstream_clear_buffer = int function(SoundIoOutStream* outstream); ///
726 	alias da_soundio_outstream_pause = int function(SoundIoOutStream* outstream, bool pause); ///
727 	alias da_soundio_outstream_get_latency = int function(SoundIoOutStream* outstream, double* out_latency); ///
728 	alias da_soundio_instream_destroy = void function(SoundIoInStream* instream); ///
729 	alias da_soundio_instream_open = int function(SoundIoInStream* instream); ///
730 	alias da_soundio_instream_start = int function(SoundIoInStream* instream); ///
731 	alias da_soundio_instream_begin_read = int function(SoundIoInStream* instream, SoundIoChannelArea** areas, int* frame_count); ///
732 	alias da_soundio_instream_end_read = int function(SoundIoInStream* instream); ///
733 	alias da_soundio_instream_pause = int function(SoundIoInStream* instream, bool pause); ///
734 	alias da_soundio_instream_get_latency = int function(SoundIoInStream* instream, double* out_latency); ///
735 	alias da_soundio_ring_buffer_destroy = void function(SoundIoRingBuffer* ring_buffer); ///
736 	alias da_soundio_ring_buffer_capacity = int function(SoundIoRingBuffer* ring_buffer); ///
737 	alias da_soundio_ring_buffer_advance_write_ptr = void function(SoundIoRingBuffer* ring_buffer, int count); ///
738 	alias da_soundio_ring_buffer_advance_read_ptr = void function(SoundIoRingBuffer* ring_buffer, int count); ///
739 	alias da_soundio_ring_buffer_fill_count = int function(SoundIoRingBuffer* ring_buffer); ///
740 	alias da_soundio_ring_buffer_free_count = int function(SoundIoRingBuffer* ring_buffer); ///
741 	alias da_soundio_ring_buffer_clear = void function(SoundIoRingBuffer* ring_buffer); ///
742 }