libsoundio_sys/lib.rs
1#![deny(warnings)]
2#![warn(clippy::all)]
3
4use std::os::raw::{c_char, c_double, c_float, c_int, c_void};
5
6// There is no c_bool, but you can use Rust's i8 or bool instead.
7// See https://github.com/rust-lang/rfcs/pull/954#issuecomment-169820630
8#[allow(non_camel_case_types)]
9type c_bool = i8;
10
11/** \mainpage
12 *
13 * \section intro_sec Overview
14 *
15 * libsoundio is a C library for cross-platform audio input and output. It is
16 * suitable for real-time and consumer software.
17 *
18 * Documentation: soundio.h
19 */
20
21/** \example sio_list_devices.c
22 * List the available input and output devices on the system and their
23 * properties. Supports watching for changes and specifying backend to use.
24 */
25
26/** \example sio_sine.c
27 * Play a sine wave over the default output device.
28 * Supports specifying device and backend to use.
29 */
30
31/** \example sio_record.c
32 * Record audio to an output file.
33 * Supports specifying device and backend to use.
34 */
35
36/** \example sio_microphone.c
37 * Stream the default input device over the default output device.
38 * Supports specifying device and backend to use.
39 */
40
41/** \example backend_disconnect_recover.c
42 * Demonstrates recovering from a backend disconnecting.
43 */
44
45// See also ::soundio_strerror
46#[repr(u32)]
47#[derive(Copy, Clone)]
48pub enum SoundIoError {
49 SoundIoErrorNone,
50 // Out of memory.
51 SoundIoErrorNoMem,
52 // The backend does not appear to be active or running.
53 SoundIoErrorInitAudioBackend,
54 // A system resource other than memory was not available.
55 SoundIoErrorSystemResources,
56 // Attempted to open a device and failed.
57 SoundIoErrorOpeningDevice,
58 SoundIoErrorNoSuchDevice,
59 // The programmer did not comply with the API.
60 SoundIoErrorInvalid,
61 // libsoundio was compiled without support for that backend.
62 SoundIoErrorBackendUnavailable,
63 // An open stream had an error that can only be recovered from by
64 // destroying the stream and creating it again.
65 SoundIoErrorStreaming,
66 // Attempted to use a device with parameters it cannot support.
67 SoundIoErrorIncompatibleDevice,
68 // When JACK returns `JackNoSuchClient`
69 SoundIoErrorNoSuchClient,
70 // Attempted to use parameters that the backend cannot support.
71 SoundIoErrorIncompatibleBackend,
72 // Backend server shutdown or became inactive.
73 SoundIoErrorBackendDisconnected,
74 SoundIoErrorInterrupted,
75 // Buffer underrun occurred.
76 SoundIoErrorUnderflow,
77 // Unable to convert to or from UTF-8 to the native string format.
78 SoundIoErrorEncodingString,
79}
80
81// Specifies where a channel is physically located.
82#[repr(u32)]
83#[derive(Copy, Clone)]
84pub enum SoundIoChannelId {
85 SoundIoChannelIdInvalid,
86
87 SoundIoChannelIdFrontLeft, // First of the more commonly supported ids.
88 SoundIoChannelIdFrontRight,
89 SoundIoChannelIdFrontCenter,
90 SoundIoChannelIdLfe,
91 SoundIoChannelIdBackLeft,
92 SoundIoChannelIdBackRight,
93 SoundIoChannelIdFrontLeftCenter,
94 SoundIoChannelIdFrontRightCenter,
95 SoundIoChannelIdBackCenter,
96 SoundIoChannelIdSideLeft,
97 SoundIoChannelIdSideRight,
98 SoundIoChannelIdTopCenter,
99 SoundIoChannelIdTopFrontLeft,
100 SoundIoChannelIdTopFrontCenter,
101 SoundIoChannelIdTopFrontRight,
102 SoundIoChannelIdTopBackLeft,
103 SoundIoChannelIdTopBackCenter,
104 SoundIoChannelIdTopBackRight, // Last of the more commonly supported ids.
105
106 SoundIoChannelIdBackLeftCenter, // First of the less commonly supported ids.
107 SoundIoChannelIdBackRightCenter,
108 SoundIoChannelIdFrontLeftWide,
109 SoundIoChannelIdFrontRightWide,
110 SoundIoChannelIdFrontLeftHigh,
111 SoundIoChannelIdFrontCenterHigh,
112 SoundIoChannelIdFrontRightHigh,
113 SoundIoChannelIdTopFrontLeftCenter,
114 SoundIoChannelIdTopFrontRightCenter,
115 SoundIoChannelIdTopSideLeft,
116 SoundIoChannelIdTopSideRight,
117 SoundIoChannelIdLeftLfe,
118 SoundIoChannelIdRightLfe,
119 SoundIoChannelIdLfe2,
120 SoundIoChannelIdBottomCenter,
121 SoundIoChannelIdBottomLeftCenter,
122 SoundIoChannelIdBottomRightCenter,
123
124 // Mid/side recording
125 SoundIoChannelIdMsMid,
126 SoundIoChannelIdMsSide,
127
128 // first order ambisonic channels
129 SoundIoChannelIdAmbisonicW,
130 SoundIoChannelIdAmbisonicX,
131 SoundIoChannelIdAmbisonicY,
132 SoundIoChannelIdAmbisonicZ,
133
134 // X-Y Recording
135 SoundIoChannelIdXyX,
136 SoundIoChannelIdXyY,
137
138 SoundIoChannelIdHeadphonesLeft, // First of the "other" channel ids
139 SoundIoChannelIdHeadphonesRight,
140 SoundIoChannelIdClickTrack,
141 SoundIoChannelIdForeignLanguage,
142 SoundIoChannelIdHearingImpaired,
143 SoundIoChannelIdNarration,
144 SoundIoChannelIdHaptic,
145 SoundIoChannelIdDialogCentricMix, // Last of the "other" channel ids
146
147 SoundIoChannelIdAux,
148 SoundIoChannelIdAux0,
149 SoundIoChannelIdAux1,
150 SoundIoChannelIdAux2,
151 SoundIoChannelIdAux3,
152 SoundIoChannelIdAux4,
153 SoundIoChannelIdAux5,
154 SoundIoChannelIdAux6,
155 SoundIoChannelIdAux7,
156 SoundIoChannelIdAux8,
157 SoundIoChannelIdAux9,
158 SoundIoChannelIdAux10,
159 SoundIoChannelIdAux11,
160 SoundIoChannelIdAux12,
161 SoundIoChannelIdAux13,
162 SoundIoChannelIdAux14,
163 SoundIoChannelIdAux15,
164}
165
166// Built-in channel layouts for convenience.
167#[repr(u32)]
168#[derive(Copy, Clone)]
169pub enum SoundIoChannelLayoutId {
170 SoundIoChannelLayoutIdMono,
171 SoundIoChannelLayoutIdStereo,
172 SoundIoChannelLayoutId2Point1,
173 SoundIoChannelLayoutId3Point0,
174 SoundIoChannelLayoutId3Point0Back,
175 SoundIoChannelLayoutId3Point1,
176 SoundIoChannelLayoutId4Point0,
177 SoundIoChannelLayoutIdQuad,
178 SoundIoChannelLayoutIdQuadSide,
179 SoundIoChannelLayoutId4Point1,
180 SoundIoChannelLayoutId5Point0Back,
181 SoundIoChannelLayoutId5Point0Side,
182 SoundIoChannelLayoutId5Point1,
183 SoundIoChannelLayoutId5Point1Back,
184 SoundIoChannelLayoutId6Point0Side,
185 SoundIoChannelLayoutId6Point0Front,
186 SoundIoChannelLayoutIdHexagonal,
187 SoundIoChannelLayoutId6Point1,
188 SoundIoChannelLayoutId6Point1Back,
189 SoundIoChannelLayoutId6Point1Front,
190 SoundIoChannelLayoutId7Point0,
191 SoundIoChannelLayoutId7Point0Front,
192 SoundIoChannelLayoutId7Point1,
193 SoundIoChannelLayoutId7Point1Wide,
194 SoundIoChannelLayoutId7Point1WideBack,
195 SoundIoChannelLayoutIdOctagonal,
196}
197
198#[repr(u32)]
199#[derive(Copy, Clone)]
200pub enum SoundIoBackend {
201 SoundIoBackendNone,
202 SoundIoBackendJack,
203 SoundIoBackendPulseAudio,
204 SoundIoBackendAlsa,
205 SoundIoBackendCoreAudio,
206 SoundIoBackendWasapi,
207 SoundIoBackendDummy,
208}
209
210#[repr(u32)]
211#[derive(Copy, Clone)]
212pub enum SoundIoDeviceAim {
213 SoundIoDeviceAimInput, // capture / recording
214 SoundIoDeviceAimOutput, // playback
215}
216
217// For your convenience, Native Endian and Foreign Endian constants are defined
218// which point to the respective SoundIoFormat values.
219#[repr(u32)]
220#[derive(Copy, Clone)]
221pub enum SoundIoFormat {
222 SoundIoFormatInvalid,
223 SoundIoFormatS8, // Signed 8 bit
224 SoundIoFormatU8, // Unsigned 8 bit
225 SoundIoFormatS16LE, // Signed 16 bit Little Endian
226 SoundIoFormatS16BE, // Signed 16 bit Big Endian
227 SoundIoFormatU16LE, // Unsigned 16 bit Little Endian
228 SoundIoFormatU16BE, // Unsigned 16 bit Little Endian
229 SoundIoFormatS24LE, // Signed 24 bit Little Endian using low three bytes in 32-bit word
230 SoundIoFormatS24BE, // Signed 24 bit Big Endian using low three bytes in 32-bit word
231 SoundIoFormatU24LE, // Unsigned 24 bit Little Endian using low three bytes in 32-bit word
232 SoundIoFormatU24BE, // Unsigned 24 bit Big Endian using low three bytes in 32-bit word
233 SoundIoFormatS32LE, // Signed 32 bit Little Endian
234 SoundIoFormatS32BE, // Signed 32 bit Big Endian
235 SoundIoFormatU32LE, // Unsigned 32 bit Little Endian
236 SoundIoFormatU32BE, // Unsigned 32 bit Big Endian
237 SoundIoFormatFloat32LE, // Float 32 bit Little Endian, Range -1.0 to 1.0
238 SoundIoFormatFloat32BE, // Float 32 bit Big Endian, Range -1.0 to 1.0
239 SoundIoFormatFloat64LE, // Float 64 bit Little Endian, Range -1.0 to 1.0
240 SoundIoFormatFloat64BE, // Float 64 bit Big Endian, Range -1.0 to 1.0
241}
242
243pub const SOUNDIO_MAX_CHANNELS: usize = 24;
244
245// The size of this struct is OK to use.
246#[repr(C)]
247#[derive(Copy, Clone)]
248pub struct SoundIoChannelLayout {
249 pub name: *const c_char, // Note that Copy and Clone are ok because this normally points to an internal static string. I think.
250 pub channel_count: c_int,
251 pub channels: [SoundIoChannelId; SOUNDIO_MAX_CHANNELS],
252}
253
254// The size of this struct is OK to use.
255#[repr(C)]
256#[derive(Copy, Clone)]
257pub struct SoundIoSampleRateRange {
258 pub min: c_int,
259 pub max: c_int,
260}
261
262// The size of this struct is OK to use.
263#[repr(C)]
264#[derive(Copy, Clone)]
265pub struct SoundIoChannelArea {
266 // Base address of buffer.
267 pub ptr: *mut c_char,
268 // How many bytes it takes to get from the beginning of one sample to
269 // the beginning of the next sample.
270 pub step: c_int,
271}
272
273// The size of this struct is not part of the API or ABI.
274#[repr(C)]
275pub struct SoundIo {
276 // Optional. Put whatever you want here. Defaults to NULL.
277 pub userdata: *mut c_void,
278 // Optional callback. Called when the list of devices change. Only called
279 // during a call to ::soundio_flush_events or ::soundio_wait_events.
280 pub on_devices_change: Option<extern "C" fn(sio: *mut SoundIo)>,
281 // Optional callback. Called when the backend disconnects. For example,
282 // when the JACK server shuts down. When this happens, listing devices
283 // and opening streams will always fail with
284 // SoundIoErrorBackendDisconnected. This callback is only called during a
285 // call to ::soundio_flush_events or ::soundio_wait_events.
286 // If you do not supply a callback, the default will crash your program
287 // with an error message. This callback is also called when the thread
288 // that retrieves device information runs into an unrecoverable condition
289 // such as running out of memory.
290 //
291 // Possible errors:
292 // * #SoundIoErrorBackendDisconnected
293 // * #SoundIoErrorNoMem
294 // * #SoundIoErrorSystemResources
295 // * #SoundIoErrorOpeningDevice - unexpected problem accessing device
296 // information
297 pub on_backend_disconnect: Option<extern "C" fn(sio: *mut SoundIo, err: c_int)>,
298 // Optional callback. Called from an unknown thread that you should not use
299 // to call any soundio functions. You may use this to signal a condition
300 // variable to wake up. Called when ::soundio_wait_events would be woken up.
301 pub on_events_signal: Option<extern "C" fn(sio: *mut SoundIo)>,
302
303 // Read-only. After calling ::soundio_connect or ::soundio_connect_backend,
304 // this field tells which backend is currently connected.
305 pub current_backend: SoundIoBackend,
306
307 // Optional: Application name.
308 // PulseAudio uses this for "application name".
309 // JACK uses this for `client_name`.
310 // Must not contain a colon (":").
311 pub app_name: *mut c_char,
312
313 // Optional: Real time priority warning.
314 // This callback is fired when making thread real-time priority failed. By
315 // default, it will print to stderr only the first time it is called
316 // a message instructing the user how to configure their system to allow
317 // real-time priority threads. This must be set to a function not NULL.
318 // To silence the warning, assign this to a function that does nothing.
319 pub emit_rtprio_warning: Option<extern "C" fn()>,
320
321 // Optional: JACK info callback.
322 // By default, libsoundio sets this to an empty function in order to
323 // silence stdio messages from JACK. You may override the behavior by
324 // setting this to `NULL` or providing your own function. This is
325 // registered with JACK regardless of whether ::soundio_connect_backend
326 // succeeds.
327 pub jack_info_callback: Option<extern "C" fn(msg: *const c_char)>,
328 // Optional: JACK error callback.
329 // See SoundIo::jack_info_callback
330 pub jack_error_callback: Option<extern "C" fn(msg: *const c_char)>,
331}
332
333// The size of this struct is not part of the API or ABI.
334#[repr(C)]
335pub struct SoundIoDevice {
336 // Read-only. Set automatically.
337 pub soundio: *mut SoundIo,
338
339 // A string of bytes that uniquely identifies this device.
340 // If the same physical device supports both input and output, that makes
341 // one SoundIoDevice for the input and one SoundIoDevice for the output.
342 // In this case, the id of each SoundIoDevice will be the same, and
343 // SoundIoDevice::aim will be different. Additionally, if the device
344 // supports raw mode, there may be up to four devices with the same id:
345 // one for each value of SoundIoDevice::is_raw and one for each value of
346 // SoundIoDevice::aim.
347 pub id: *mut c_char,
348 // User-friendly UTF-8 encoded text to describe the device.
349 pub name: *mut c_char,
350
351 // Tells whether this device is an input device or an output device.
352 pub aim: SoundIoDeviceAim,
353
354 // Channel layouts are handled similarly to SoundIoDevice::formats.
355 // If this information is missing due to a SoundIoDevice::probe_error,
356 // layouts will be NULL. It's OK to modify this data, for example calling
357 // ::soundio_sort_channel_layouts on it.
358 // Devices are guaranteed to have at least 1 channel layout.
359 pub layouts: *mut SoundIoChannelLayout,
360 pub layout_count: c_int,
361 // See SoundIoDevice::current_format
362 pub current_layout: SoundIoChannelLayout,
363
364 // List of formats this device supports. See also
365 // SoundIoDevice::current_format.
366 pub formats: *mut SoundIoFormat,
367 // How many formats are available in SoundIoDevice::formats.
368 pub format_count: c_int,
369 // A device is either a raw device or it is a virtual device that is
370 // provided by a software mixing service such as dmix or PulseAudio (see
371 // SoundIoDevice::is_raw). If it is a raw device,
372 // current_format is meaningless;
373 // the device has no current format until you open it. On the other hand,
374 // if it is a virtual device, current_format describes the
375 // destination sample format that your audio will be converted to. Or,
376 // if you're the lucky first application to open the device, you might
377 // cause the current_format to change to your format.
378 // Generally, you want to ignore current_format and use
379 // whatever format is most convenient
380 // for you which is supported by the device, because when you are the only
381 // application left, the mixer might decide to switch
382 // current_format to yours. You can learn the supported formats via
383 // formats and SoundIoDevice::format_count. If this information is missing
384 // due to a probe error, formats will be `NULL`. If current_format is
385 // unavailable, it will be set to #SoundIoFormatInvalid.
386 // Devices are guaranteed to have at least 1 format available.
387 pub current_format: SoundIoFormat,
388
389 // Sample rate is the number of frames per second.
390 // Sample rate is handled very similar to SoundIoDevice::formats.
391 // If sample rate information is missing due to a probe error, the field
392 // will be set to NULL.
393 // Devices which have SoundIoDevice::probe_error set to #SoundIoErrorNone are
394 // guaranteed to have at least 1 sample rate available.
395 pub sample_rates: *mut SoundIoSampleRateRange,
396 // How many sample rate ranges are available in
397 // SoundIoDevice::sample_rates. 0 if sample rate information is missing
398 // due to a probe error.
399 pub sample_rate_count: c_int,
400 // See SoundIoDevice::current_format
401 // 0 if sample rate information is missing due to a probe error.
402 pub sample_rate_current: c_int,
403
404 // Software latency minimum in seconds. If this value is unknown or
405 // irrelevant, it is set to 0.0.
406 // For PulseAudio and WASAPI this value is unknown until you open a
407 // stream.
408 pub software_latency_min: c_double,
409 // Software latency maximum in seconds. If this value is unknown or
410 // irrelevant, it is set to 0.0.
411 // For PulseAudio and WASAPI this value is unknown until you open a
412 // stream.
413 pub software_latency_max: c_double,
414 // Software latency in seconds. If this value is unknown or
415 // irrelevant, it is set to 0.0.
416 // For PulseAudio and WASAPI this value is unknown until you open a
417 // stream.
418 // See SoundIoDevice::current_format
419 pub software_latency_current: c_double,
420
421 // Raw means that you are directly opening the hardware device and not
422 // going through a proxy such as dmix, PulseAudio, or JACK. When you open a
423 // raw device, other applications on the computer are not able to
424 // simultaneously access the device. Raw devices do not perform automatic
425 // resampling and thus tend to have fewer formats available.
426 pub is_raw: c_bool,
427
428 // Devices are reference counted. See ::soundio_device_ref and
429 // ::soundio_device_unref.
430 pub ref_count: c_int,
431
432 // This is set to a SoundIoError representing the result of the device
433 // probe. Ideally this will be SoundIoErrorNone in which case all the
434 // fields of the device will be populated. If there is an error code here
435 // then information about formats, sample rates, and channel layouts might
436 // be missing.
437 //
438 // Possible errors:
439 // * #SoundIoErrorOpeningDevice
440 // * #SoundIoErrorNoMem
441 pub probe_error: c_int,
442}
443
444// The size of this struct is not part of the API or ABI.
445#[repr(C)]
446pub struct SoundIoOutStream {
447 // Populated automatically when you call ::soundio_outstream_create.
448 pub device: *mut SoundIoDevice,
449
450 // Defaults to #SoundIoFormatFloat32NE, followed by the first one
451 // supported.
452 pub format: SoundIoFormat,
453
454 // Sample rate is the number of frames per second.
455 // Defaults to 48000 (and then clamped into range).
456 pub sample_rate: c_int,
457
458 // Defaults to Stereo, if available, followed by the first layout
459 // supported.
460 pub layout: SoundIoChannelLayout,
461
462 // Ignoring hardware latency, this is the number of seconds it takes for
463 // the last sample in a full buffer to be played.
464 // After you call ::soundio_outstream_open, this value is replaced with the
465 // actual software latency, as near to this value as possible.
466 // On systems that support clearing the buffer, this defaults to a large
467 // latency, potentially upwards of 2 seconds, with the understanding that
468 // you will call ::soundio_outstream_clear_buffer when you want to reduce
469 // the latency to 0. On systems that do not support clearing the buffer,
470 // this defaults to a reasonable lower latency value.
471 //
472 // On backends with high latencies (such as 2 seconds), `frame_count_min`
473 // will be 0, meaning you don't have to fill the entire buffer. In this
474 // case, the large buffer is there if you want it; you only have to fill
475 // as much as you want. On backends like JACK, `frame_count_min` will be
476 // equal to `frame_count_max` and if you don't fill that many frames, you
477 // will get glitches.
478 //
479 // If the device has unknown software latency min and max values, you may
480 // still set this, but you might not get the value you requested.
481 // For PulseAudio, if you set this value to non-default, it sets
482 // `PA_STREAM_ADJUST_LATENCY` and is the value used for `maxlength` and
483 // `tlength`.
484 //
485 // For JACK, this value is always equal to
486 // SoundIoDevice::software_latency_current of the device.
487 pub software_latency: c_double,
488 pub volume: c_float,
489
490 // Defaults to NULL. Put whatever you want here.
491 pub userdata: *mut c_void,
492 // In this callback, you call ::soundio_outstream_begin_write and
493 // ::soundio_outstream_end_write as many times as necessary to write
494 // at minimum `frame_count_min` frames and at maximum `frame_count_max`
495 // frames. `frame_count_max` will always be greater than 0. Note that you
496 // should write as many frames as you can; `frame_count_min` might be 0 and
497 // you can still get a buffer underflow if you always write
498 // `frame_count_min` frames.
499 //
500 // For Dummy, ALSA, and PulseAudio, `frame_count_min` will be 0. For JACK
501 // and CoreAudio `frame_count_min` will be equal to `frame_count_max`.
502 //
503 // The code in the supplied function must be suitable for real-time
504 // execution. That means that it cannot call functions that might block
505 // for a long time. This includes all I/O functions (disk, TTY, network),
506 // malloc, free, printf, pthread_mutex_lock, sleep, wait, poll, select,
507 // pthread_join, pthread_cond_wait, etc.
508 pub write_callback: extern "C" fn(
509 stream: *mut SoundIoOutStream,
510 frame_count_min: c_int,
511 frame_count_max: c_int,
512 ),
513 // This optional callback happens when the sound device runs out of
514 // buffered audio data to play. After this occurs, the outstream waits
515 // until the buffer is full to resume playback.
516 // This is called from the SoundIoOutStream::write_callback thread context.
517 pub underflow_callback: Option<extern "C" fn(stream: *mut SoundIoOutStream)>,
518 // Optional callback. `err` is always SoundIoErrorStreaming.
519 // SoundIoErrorStreaming is an unrecoverable error. The stream is in an
520 // invalid state and must be destroyed.
521 // If you do not supply error_callback, the default callback will print
522 // a message to stderr and then call `abort`.
523 // This is called from the SoundIoOutStream::write_callback thread context.
524 pub error_callback: Option<extern "C" fn(stream: *mut SoundIoOutStream, err: c_int)>,
525
526 // Optional: Name of the stream. Defaults to "SoundIoOutStream"
527 // PulseAudio uses this for the stream name.
528 // JACK uses this for the client name of the client that connects when you
529 // open the stream.
530 // WASAPI uses this for the session display name.
531 // Must not contain a colon (":").
532 pub name: *const c_char,
533
534 // Optional: Hint that this output stream is nonterminal. This is used by
535 // JACK and it means that the output stream data originates from an input
536 // stream. Defaults to `false`.
537 pub non_terminal_hint: c_bool,
538
539 // computed automatically when you call ::soundio_outstream_open
540 pub bytes_per_frame: c_int,
541 // computed automatically when you call ::soundio_outstream_open
542 pub bytes_per_sample: c_int,
543
544 // If setting the channel layout fails for some reason, this field is set
545 // to an error code. Possible error codes are:
546 // * #SoundIoErrorIncompatibleDevice
547 pub layout_error: c_int,
548}
549
550// The size of this struct is not part of the API or ABI.
551#[repr(C)]
552pub struct SoundIoInStream {
553 // Populated automatically when you call ::soundio_outstream_create.
554 pub device: *mut SoundIoDevice,
555
556 // Defaults to #SoundIoFormatFloat32NE, followed by the first one
557 // supported.
558 pub format: SoundIoFormat,
559
560 // Sample rate is the number of frames per second.
561 // Defaults to max(sample_rate_min, min(sample_rate_max, 48000))
562 pub sample_rate: c_int,
563
564 // Defaults to Stereo, if available, followed by the first layout
565 // supported.
566 pub layout: SoundIoChannelLayout,
567
568 // Ignoring hardware latency, this is the number of seconds it takes for a
569 // captured sample to become available for reading.
570 // After you call ::soundio_instream_open, this value is replaced with the
571 // actual software latency, as near to this value as possible.
572 // A higher value means less CPU usage. Defaults to a large value,
573 // potentially upwards of 2 seconds.
574 // If the device has unknown software latency min and max values, you may
575 // still set this, but you might not get the value you requested.
576 // For PulseAudio, if you set this value to non-default, it sets
577 // `PA_STREAM_ADJUST_LATENCY` and is the value used for `fragsize`.
578 // For JACK, this value is always equal to
579 // SoundIoDevice::software_latency_current
580 pub software_latency: c_double,
581
582 // Defaults to NULL. Put whatever you want here.
583 pub userdata: *mut c_void,
584 // In this function call ::soundio_instream_begin_read and
585 // ::soundio_instream_end_read as many times as necessary to read at
586 // minimum `frame_count_min` frames and at maximum `frame_count_max`
587 // frames. If you return from read_callback without having read
588 // `frame_count_min`, the frames will be dropped. `frame_count_max` is how
589 // many frames are available to read.
590 //
591 // The code in the supplied function must be suitable for real-time
592 // execution. That means that it cannot call functions that might block
593 // for a long time. This includes all I/O functions (disk, TTY, network),
594 // malloc, free, printf, pthread_mutex_lock, sleep, wait, poll, select,
595 // pthread_join, pthread_cond_wait, etc.
596 pub read_callback:
597 extern "C" fn(stream: *mut SoundIoInStream, frame_count_min: c_int, frame_count_max: c_int),
598 // This optional callback happens when the sound device buffer is full,
599 // yet there is more captured audio to put in it.
600 // This is never fired for PulseAudio.
601 // This is called from the SoundIoInStream::read_callback thread context.
602 pub overflow_callback: Option<extern "C" fn(stream: *mut SoundIoInStream)>,
603 // Optional callback. `err` is always SoundIoErrorStreaming.
604 // SoundIoErrorStreaming is an unrecoverable error. The stream is in an
605 // invalid state and must be destroyed.
606 // If you do not supply `error_callback`, the default callback will print
607 // a message to stderr and then abort().
608 // This is called from the SoundIoInStream::read_callback thread context.
609 pub error_callback: Option<extern "C" fn(stream: *mut SoundIoInStream, err: c_int)>,
610
611 // Optional: Name of the stream. Defaults to "SoundIoInStream";
612 // PulseAudio uses this for the stream name.
613 // JACK uses this for the client name of the client that connects when you
614 // open the stream.
615 // WASAPI uses this for the session display name.
616 // Must not contain a colon (":").
617 pub name: *const c_char,
618
619 // Optional: Hint that this input stream is nonterminal. This is used by
620 // JACK and it means that the data received by the stream will be
621 // passed on or made available to another stream. Defaults to `false`.
622 pub non_terminal_hint: c_bool,
623
624 // computed automatically when you call ::soundio_instream_open
625 pub bytes_per_frame: c_int,
626 // computed automatically when you call ::soundio_instream_open
627 pub bytes_per_sample: c_int,
628
629 // If setting the channel layout fails for some reason, this field is set
630 // to an error code. Possible error codes are: #SoundIoErrorIncompatibleDevice
631 pub layout_error: c_int,
632}
633
634pub enum SoundIoRingBuffer {}
635
636extern "C" {
637
638 // See also ::soundio_version_major, ::soundio_version_minor, ::soundio_version_patch
639 pub fn soundio_version_string() -> *const c_char;
640 // See also ::soundio_version_string, ::soundio_version_minor, ::soundio_version_patch
641 pub fn soundio_version_major() -> c_int;
642 // See also ::soundio_version_major, ::soundio_version_string, ::soundio_version_patch
643 pub fn soundio_version_minor() -> c_int;
644 // See also ::soundio_version_major, ::soundio_version_minor, ::soundio_version_string
645 pub fn soundio_version_patch() -> c_int;
646
647 // Create a SoundIo context. You may create multiple instances of this to
648 // connect to multiple backends. Sets all fields to defaults.
649 // Returns `NULL` if and only if memory could not be allocated.
650 // See also ::soundio_destroy
651 pub fn soundio_create() -> *mut SoundIo;
652 pub fn soundio_destroy(soundio: *mut SoundIo);
653
654 // Tries ::soundio_connect_backend on all available backends in order.
655 // Possible errors:
656 // * #SoundIoErrorInvalid - already connected
657 // * #SoundIoErrorNoMem
658 // * #SoundIoErrorSystemResources
659 // * #SoundIoErrorNoSuchClient - when JACK returns `JackNoSuchClient`
660 // See also ::soundio_disconnect
661 pub fn soundio_connect(soundio: *mut SoundIo) -> c_int;
662 // Instead of calling ::soundio_connect you may call this function to try a
663 // specific backend.
664 // Possible errors:
665 // * #SoundIoErrorInvalid - already connected or invalid backend parameter
666 // * #SoundIoErrorNoMem
667 // * #SoundIoErrorBackendUnavailable - backend was not compiled in
668 // * #SoundIoErrorSystemResources
669 // * #SoundIoErrorNoSuchClient - when JACK returns `JackNoSuchClient`
670 // * #SoundIoErrorInitAudioBackend - requested `backend` is not active
671 // * #SoundIoErrorBackendDisconnected - backend disconnected while connecting
672 // See also ::soundio_disconnect
673 pub fn soundio_connect_backend(soundio: *mut SoundIo, backend: SoundIoBackend) -> c_int;
674 pub fn soundio_disconnect(soundio: *mut SoundIo);
675
676 // Get a string representation of a #SoundIoError
677 pub fn soundio_strerror(error: c_int) -> *const c_char;
678 // Get a string representation of a #SoundIoBackend
679 pub fn soundio_backend_name(backend: SoundIoBackend) -> *const c_char;
680
681 // Returns the number of available backends.
682 pub fn soundio_backend_count(soundio: *mut SoundIo) -> c_int;
683 // get the available backend at the specified index
684 // (0 <= index < ::soundio_backend_count)
685 pub fn soundio_get_backend(soundio: *mut SoundIo, index: c_int) -> SoundIoBackend;
686
687 // Returns whether libsoundio was compiled with backend.
688 pub fn soundio_have_backend(backend: SoundIoBackend) -> c_bool;
689
690 // Atomically update information for all connected devices. Note that calling
691 // this function merely flips a pointer; the actual work of collecting device
692 // information is done elsewhere. It is performant to call this function many
693 // times per second.
694 //
695 // When you call this, the following callbacks might be called:
696 // * SoundIo::on_devices_change
697 // * SoundIo::on_backend_disconnect
698 // This is the only time those callbacks can be called.
699 //
700 // This must be called from the same thread as the thread in which you call
701 // these functions:
702 // * ::soundio_input_device_count
703 // * ::soundio_output_device_count
704 // * ::soundio_get_input_device
705 // * ::soundio_get_output_device
706 // * ::soundio_default_input_device_index
707 // * ::soundio_default_output_device_index
708 //
709 // Note that if you do not care about learning about updated devices, you
710 // might call this function only once ever and never call
711 // ::soundio_wait_events.
712 pub fn soundio_flush_events(soundio: *mut SoundIo);
713
714 // This function calls ::soundio_flush_events then blocks until another event
715 // is ready or you call ::soundio_wakeup. Be ready for spurious wakeups.
716 pub fn soundio_wait_events(soundio: *mut SoundIo);
717
718 // Makes ::soundio_wait_events stop blocking.
719 pub fn soundio_wakeup(soundio: *mut SoundIo);
720
721 // If necessary you can manually trigger a device rescan. Normally you will
722 // not ever have to call this function, as libsoundio listens to system events
723 // for device changes and responds to them by rescanning devices and preparing
724 // the new device information for you to be atomically replaced when you call
725 // ::soundio_flush_events. However you might run into cases where you want to
726 // force trigger a device rescan, for example if an ALSA device has a
727 // SoundIoDevice::probe_error.
728 //
729 // After you call this you still have to use ::soundio_flush_events or
730 // ::soundio_wait_events and then wait for the
731 // SoundIo::on_devices_change callback.
732 //
733 // This can be called from any thread context except for
734 // SoundIoOutStream::write_callback and SoundIoInStream::read_callback
735 pub fn soundio_force_device_scan(soundio: *mut SoundIo);
736
737 // Channel Layouts
738
739 // Returns whether the channel count field and each channel id matches in
740 // the supplied channel layouts.
741 pub fn soundio_channel_layout_equal(
742 a: *mut SoundIoChannelLayout,
743 b: *mut SoundIoChannelLayout,
744 ) -> c_bool;
745
746 pub fn soundio_get_channel_name(id: SoundIoChannelId) -> *const c_char;
747 // Given UTF-8 encoded text which is the name of a channel such as
748 // "Front Left", "FL", or "front-left", return the corresponding
749 // SoundIoChannelId. Returns SoundIoChannelIdInvalid for no match.
750 pub fn soundio_parse_channel_id(str: *const c_char, str_len: c_int) -> SoundIoChannelId;
751
752 // Returns the number of builtin channel layouts.
753 pub fn soundio_channel_layout_builtin_count() -> c_int;
754 // Returns a builtin channel layout. 0 <= `index` < ::soundio_channel_layout_builtin_count
755 //
756 // Although `index` is of type `int`, it should be a valid
757 // #SoundIoChannelLayoutId enum value.
758 pub fn soundio_channel_layout_get_builtin(index: c_int) -> *const SoundIoChannelLayout;
759
760 // Get the default builtin channel layout for the given number of channels.
761 pub fn soundio_channel_layout_get_default(channel_count: c_int) -> *const SoundIoChannelLayout;
762
763 // Return the index of `channel` in `layout`, or `-1` if not found.
764 pub fn soundio_channel_layout_find_channel(
765 layout: *const SoundIoChannelLayout,
766 channel: SoundIoChannelId,
767 ) -> c_int;
768
769 // Populates the name field of layout if it matches a builtin one.
770 // returns whether it found a match
771 pub fn soundio_channel_layout_detect_builtin(layout: *mut SoundIoChannelLayout) -> c_bool;
772
773 // Iterates over preferred_layouts. Returns the first channel layout in
774 // preferred_layouts which matches one of the channel layouts in
775 // available_layouts. Returns NULL if none matches.
776 pub fn soundio_best_matching_channel_layout(
777 preferred_layouts: *const SoundIoChannelLayout,
778 preferred_layout_count: c_int,
779 available_layouts: *const SoundIoChannelLayout,
780 available_layout_count: c_int,
781 ) -> *const SoundIoChannelLayout;
782
783 // Sorts by channel count, descending.
784 pub fn soundio_sort_channel_layouts(layout: *mut SoundIoChannelLayout, layout_count: c_int);
785
786 // Sample Formats
787
788 // Returns -1 on invalid format.
789 pub fn soundio_get_bytes_per_sample(format: SoundIoFormat) -> c_int;
790
791 // A frame is one sample per channel.
792 // static inline int soundio_get_bytes_per_frame(enum SoundIoFormat format, channel_count: c_int) {
793 // return soundio_get_bytes_per_sample(format) * channel_count;
794 // }
795
796 // Sample rate is the number of frames per second.
797 // static inline int soundio_get_bytes_per_second(enum SoundIoFormat format,
798 // channel_count: c_int, int sample_rate)
799 // {
800 // return soundio_get_bytes_per_frame(format, channel_count) * sample_rate;
801 // }
802
803 // Returns string representation of `format`.
804 pub fn soundio_format_string(format: SoundIoFormat) -> *const c_char;
805
806 // Devices
807
808 // When you call ::soundio_flush_events, a snapshot of all device state is
809 // saved and these functions merely access the snapshot data. When you want
810 // to check for new devices, call ::soundio_flush_events. Or you can call
811 // ::soundio_wait_events to block until devices change. If an error occurs
812 // scanning devices in a background thread, SoundIo::on_backend_disconnect is called
813 // with the error code.
814
815 // Get the number of input devices.
816 // Returns -1 if you never called ::soundio_flush_events.
817 pub fn soundio_input_device_count(soundio: *mut SoundIo) -> c_int;
818 // Get the number of output devices.
819 // Returns -1 if you never called ::soundio_flush_events.
820 pub fn soundio_output_device_count(soundio: *mut SoundIo) -> c_int;
821
822 // Always returns a device. Call ::soundio_device_unref when done.
823 // `index` must be 0 <= index < ::soundio_input_device_count
824 // Returns NULL if you never called ::soundio_flush_events or if you provide
825 // invalid parameter values.
826 pub fn soundio_get_input_device(soundio: *mut SoundIo, index: c_int) -> *mut SoundIoDevice;
827 // Always returns a device. Call ::soundio_device_unref when done.
828 // `index` must be 0 <= index < ::soundio_output_device_count
829 // Returns NULL if you never called ::soundio_flush_events or if you provide
830 // invalid parameter values.
831 pub fn soundio_get_output_device(soundio: *mut SoundIo, index: c_int) -> *mut SoundIoDevice;
832
833 // returns the index of the default input device
834 // returns -1 if there are no devices or if you never called
835 // ::soundio_flush_events.
836 pub fn soundio_default_input_device_index(soundio: *mut SoundIo) -> c_int;
837
838 // returns the index of the default output device
839 // returns -1 if there are no devices or if you never called
840 // ::soundio_flush_events.
841 pub fn soundio_default_output_device_index(soundio: *mut SoundIo) -> c_int;
842
843 // Add 1 to the reference count of `device`.
844 pub fn soundio_device_ref(device: *mut SoundIoDevice);
845 // Remove 1 to the reference count of `device`. Clean up if it was the last
846 // reference.
847 pub fn soundio_device_unref(device: *mut SoundIoDevice);
848
849 // Return `true` if and only if the devices have the same SoundIoDevice::id,
850 // SoundIoDevice::is_raw, and SoundIoDevice::aim are the same.
851 pub fn soundio_device_equal(a: *const SoundIoDevice, b: *const SoundIoDevice) -> c_bool;
852
853 // Sorts channel layouts by channel count, descending.
854 pub fn soundio_device_sort_channel_layouts(device: *mut SoundIoDevice);
855
856 // Convenience function. Returns whether `format` is included in the device's
857 // supported formats.
858 pub fn soundio_device_supports_format(
859 device: *mut SoundIoDevice,
860 format: SoundIoFormat,
861 ) -> c_bool;
862
863 // Convenience function. Returns whether `layout` is included in the device's
864 // supported channel layouts.
865 pub fn soundio_device_supports_layout(
866 device: *mut SoundIoDevice,
867 layout: *const SoundIoChannelLayout,
868 ) -> c_bool;
869
870 // Convenience function. Returns whether `sample_rate` is included in the
871 // device's supported sample rates.
872 pub fn soundio_device_supports_sample_rate(
873 device: *mut SoundIoDevice,
874 sample_rate: c_int,
875 ) -> c_bool;
876
877 // Convenience function. Returns the available sample rate nearest to
878 // `sample_rate`, rounding up.
879 pub fn soundio_device_nearest_sample_rate(
880 device: *mut SoundIoDevice,
881 sample_rate: c_int,
882 ) -> c_int;
883
884 // Output Streams
885 // Allocates memory and sets defaults. Next you should fill out the struct fields
886 // and then call ::soundio_outstream_open. Sets all fields to defaults.
887 // Returns `NULL` if and only if memory could not be allocated.
888 // See also ::soundio_outstream_destroy
889 pub fn soundio_outstream_create(device: *mut SoundIoDevice) -> *mut SoundIoOutStream;
890 // You may not call this function from the SoundIoOutStream::write_callback thread context.
891 pub fn soundio_outstream_destroy(outstream: *mut SoundIoOutStream);
892
893 // After you call this function, SoundIoOutStream::software_latency is set to
894 // the correct value.
895 //
896 // The next thing to do is call ::soundio_instream_start.
897 // If this function returns an error, the outstream is in an invalid state and
898 // you must call ::soundio_outstream_destroy on it.
899 //
900 // Possible errors:
901 // * #SoundIoErrorInvalid
902 // * SoundIoDevice::aim is not #SoundIoDeviceAimOutput
903 // * SoundIoOutStream::format is not valid
904 // * SoundIoOutStream::channel_count is greater than #SOUNDIO_MAX_CHANNELS
905 // * #SoundIoErrorNoMem
906 // * #SoundIoErrorOpeningDevice
907 // * #SoundIoErrorBackendDisconnected
908 // * #SoundIoErrorSystemResources
909 // * #SoundIoErrorNoSuchClient - when JACK returns `JackNoSuchClient`
910 // * #SoundIoErrorOpeningDevice
911 // * #SoundIoErrorIncompatibleBackend - SoundIoOutStream::channel_count is
912 // greater than the number of channels the backend can handle.
913 // * #SoundIoErrorIncompatibleDevice - stream parameters requested are not
914 // compatible with the chosen device.
915 pub fn soundio_outstream_open(outstream: *mut SoundIoOutStream) -> c_int;
916
917 // After you call this function, SoundIoOutStream::write_callback will be called.
918 //
919 // This function might directly call SoundIoOutStream::write_callback.
920 //
921 // Possible errors:
922 // * #SoundIoErrorStreaming
923 // * #SoundIoErrorNoMem
924 // * #SoundIoErrorSystemResources
925 // * #SoundIoErrorBackendDisconnected
926 pub fn soundio_outstream_start(outstream: *mut SoundIoOutStream) -> c_int;
927
928 // Call this function when you are ready to begin writing to the device buffer.
929 // * `outstream` - (in) The output stream you want to write to.
930 // * `areas` - (out) The memory addresses you can write data to, one per
931 // channel. It is OK to modify the pointers if that helps you iterate.
932 // * `frame_count` - (in/out) Provide the number of frames you want to write.
933 // Returned will be the number of frames you can actually write, which is
934 // also the number of frames that will be written when you call
935 // ::soundio_outstream_end_write. The value returned will always be less
936 // than or equal to the value provided.
937 // It is your responsibility to call this function exactly as many times as
938 // necessary to meet the `frame_count_min` and `frame_count_max` criteria from
939 // SoundIoOutStream::write_callback.
940 // You must call this function only from the SoundIoOutStream::write_callback thread context.
941 // After calling this function, write data to `areas` and then call
942 // ::soundio_outstream_end_write.
943 // If this function returns an error, do not call ::soundio_outstream_end_write.
944 //
945 // Possible errors:
946 // * #SoundIoErrorInvalid
947 // * `*frame_count` <= 0
948 // * `*frame_count` < `frame_count_min` or `*frame_count` > `frame_count_max`
949 // * function called too many times without respecting `frame_count_max`
950 // * #SoundIoErrorStreaming
951 // * #SoundIoErrorUnderflow - an underflow caused this call to fail. You might
952 // also get a SoundIoOutStream::underflow_callback, and you might not get
953 // this error code when an underflow occurs. Unlike #SoundIoErrorStreaming,
954 // the outstream is still in a valid state and streaming can continue.
955 // * #SoundIoErrorIncompatibleDevice - in rare cases it might just now
956 // be discovered that the device uses non-byte-aligned access, in which
957 // case this error code is returned.
958 pub fn soundio_outstream_begin_write(
959 outstream: *mut SoundIoOutStream,
960 areas: *mut *mut SoundIoChannelArea,
961 frame_count: *mut c_int,
962 ) -> c_int;
963
964 // Commits the write that you began with ::soundio_outstream_begin_write.
965 // You must call this function only from the SoundIoOutStream::write_callback thread context.
966 //
967 // Possible errors:
968 // * #SoundIoErrorStreaming
969 // * #SoundIoErrorUnderflow - an underflow caused this call to fail. You might
970 // also get a SoundIoOutStream::underflow_callback, and you might not get
971 // this error code when an underflow occurs. Unlike #SoundIoErrorStreaming,
972 // the outstream is still in a valid state and streaming can continue.
973 pub fn soundio_outstream_end_write(outstream: *mut SoundIoOutStream) -> c_int;
974
975 // Clears the output stream buffer.
976 // This function can be called from any thread.
977 // This function can be called regardless of whether the outstream is paused
978 // or not.
979 // Some backends do not support clearing the buffer. On these backends this
980 // function will return SoundIoErrorIncompatibleBackend.
981 // Some devices do not support clearing the buffer. On these devices this
982 // function might return SoundIoErrorIncompatibleDevice.
983 // Possible errors:
984 //
985 // * #SoundIoErrorStreaming
986 // * #SoundIoErrorIncompatibleBackend
987 // * #SoundIoErrorIncompatibleDevice
988 pub fn soundio_outstream_clear_buffer(outstream: *mut SoundIoOutStream) -> c_int;
989
990 // If the underlying backend and device support pausing, this pauses the
991 // stream. SoundIoOutStream::write_callback may be called a few more times if
992 // the buffer is not full.
993 // Pausing might put the hardware into a low power state which is ideal if your
994 // software is silent for some time.
995 // This function may be called from any thread context, including
996 // SoundIoOutStream::write_callback.
997 // Pausing when already paused or unpausing when already unpaused has no
998 // effect and returns #SoundIoErrorNone.
999 //
1000 // Possible errors:
1001 // * #SoundIoErrorBackendDisconnected
1002 // * #SoundIoErrorStreaming
1003 // * #SoundIoErrorIncompatibleDevice - device does not support
1004 // pausing/unpausing. This error code might not be returned even if the
1005 // device does not support pausing/unpausing.
1006 // * #SoundIoErrorIncompatibleBackend - backend does not support
1007 // pausing/unpausing.
1008 // * #SoundIoErrorInvalid - outstream not opened and started
1009 pub fn soundio_outstream_pause(outstream: *mut SoundIoOutStream, pause: c_bool) -> c_int;
1010
1011 // Obtain the total number of seconds that the next frame written after the
1012 // last frame written with ::soundio_outstream_end_write will take to become
1013 // audible. This includes both software and hardware latency. In other words,
1014 // if you call this function directly after calling ::soundio_outstream_end_write,
1015 // this gives you the number of seconds that the next frame written will take
1016 // to become audible.
1017 //
1018 // This function must be called only from within SoundIoOutStream::write_callback.
1019 //
1020 // Possible errors:
1021 // * #SoundIoErrorStreaming
1022 pub fn soundio_outstream_get_latency(
1023 outstream: *mut SoundIoOutStream,
1024 out_latency: *mut c_double,
1025 ) -> c_int;
1026
1027 // Input Streams
1028 // Allocates memory and sets defaults. Next you should fill out the struct fields
1029 // and then call ::soundio_instream_open. Sets all fields to defaults.
1030 // Returns `NULL` if and only if memory could not be allocated.
1031 // See also ::soundio_instream_destroy
1032 pub fn soundio_instream_create(device: *mut SoundIoDevice) -> *mut SoundIoInStream;
1033 // You may not call this function from SoundIoInStream::read_callback.
1034 pub fn soundio_instream_destroy(instream: *mut SoundIoInStream);
1035
1036 // After you call this function, SoundIoInStream::software_latency is set to the correct
1037 // value.
1038 // The next thing to do is call ::soundio_instream_start.
1039 // If this function returns an error, the instream is in an invalid state and
1040 // you must call ::soundio_instream_destroy on it.
1041 //
1042 // Possible errors:
1043 // * #SoundIoErrorInvalid
1044 // * device aim is not #SoundIoDeviceAimInput
1045 // * format is not valid
1046 // * requested layout channel count > #SOUNDIO_MAX_CHANNELS
1047 // * #SoundIoErrorOpeningDevice
1048 // * #SoundIoErrorNoMem
1049 // * #SoundIoErrorBackendDisconnected
1050 // * #SoundIoErrorSystemResources
1051 // * #SoundIoErrorNoSuchClient
1052 // * #SoundIoErrorIncompatibleBackend
1053 // * #SoundIoErrorIncompatibleDevice
1054 pub fn soundio_instream_open(instream: *mut SoundIoInStream) -> c_int;
1055
1056 // After you call this function, SoundIoInStream::read_callback will be called.
1057 //
1058 // Possible errors:
1059 // * #SoundIoErrorBackendDisconnected
1060 // * #SoundIoErrorStreaming
1061 // * #SoundIoErrorOpeningDevice
1062 // * #SoundIoErrorSystemResources
1063 pub fn soundio_instream_start(instream: *mut SoundIoInStream) -> c_int;
1064
1065 // Call this function when you are ready to begin reading from the device
1066 // buffer.
1067 // * `instream` - (in) The input stream you want to read from.
1068 // * `areas` - (out) The memory addresses you can read data from. It is OK
1069 // to modify the pointers if that helps you iterate. There might be a "hole"
1070 // in the buffer. To indicate this, `areas` will be `NULL` and `frame_count`
1071 // tells how big the hole is in frames.
1072 // * `frame_count` - (in/out) - Provide the number of frames you want to read;
1073 // returns the number of frames you can actually read. The returned value
1074 // will always be less than or equal to the provided value. If the provided
1075 // value is less than `frame_count_min` from SoundIoInStream::read_callback this function
1076 // returns with #SoundIoErrorInvalid.
1077 // It is your responsibility to call this function no more and no fewer than the
1078 // correct number of times according to the `frame_count_min` and
1079 // `frame_count_max` criteria from SoundIoInStream::read_callback.
1080 // You must call this function only from the SoundIoInStream::read_callback thread context.
1081 // After calling this function, read data from `areas` and then use
1082 // ::soundio_instream_end_read` to actually remove the data from the buffer
1083 // and move the read index forward. ::soundio_instream_end_read should not be
1084 // called if the buffer is empty (`frame_count` == 0), but it should be called
1085 // if there is a hole.
1086 //
1087 // Possible errors:
1088 // * #SoundIoErrorInvalid
1089 // * `*frame_count` < `frame_count_min` or `*frame_count` > `frame_count_max`
1090 // * #SoundIoErrorStreaming
1091 // * #SoundIoErrorIncompatibleDevice - in rare cases it might just now
1092 // be discovered that the device uses non-byte-aligned access, in which
1093 // case this error code is returned.
1094 pub fn soundio_instream_begin_read(
1095 instream: *mut SoundIoInStream,
1096 areas: *mut *mut SoundIoChannelArea,
1097 frame_count: *mut c_int,
1098 ) -> c_int;
1099 // This will drop all of the frames from when you called
1100 // ::soundio_instream_begin_read.
1101 // You must call this function only from the SoundIoInStream::read_callback thread context.
1102 // You must call this function only after a successful call to
1103 // ::soundio_instream_begin_read.
1104 //
1105 // Possible errors:
1106 // * #SoundIoErrorStreaming
1107 pub fn soundio_instream_end_read(instream: *mut SoundIoInStream) -> c_int;
1108
1109 // If the underyling device supports pausing, this pauses the stream and
1110 // prevents SoundIoInStream::read_callback from being called. Otherwise this returns
1111 // #SoundIoErrorIncompatibleDevice.
1112 // This function may be called from any thread.
1113 // Pausing when already paused or unpausing when already unpaused has no
1114 // effect and always returns #SoundIoErrorNone.
1115 //
1116 // Possible errors:
1117 // * #SoundIoErrorBackendDisconnected
1118 // * #SoundIoErrorStreaming
1119 // * #SoundIoErrorIncompatibleDevice - device does not support pausing/unpausing
1120 pub fn soundio_instream_pause(instream: *mut SoundIoInStream, pause: c_bool) -> c_int;
1121
1122 // Obtain the number of seconds that the next frame of sound being
1123 // captured will take to arrive in the buffer, plus the amount of time that is
1124 // represented in the buffer. This includes both software and hardware latency.
1125 //
1126 // This function must be called only from within SoundIoInStream::read_callback.
1127 //
1128 // Possible errors:
1129 // * #SoundIoErrorStreaming
1130 pub fn soundio_instream_get_latency(
1131 instream: *mut SoundIoInStream,
1132 out_latency: *mut c_double,
1133 ) -> c_int;
1134
1135 // A ring buffer is a single-reader single-writer lock-free fixed-size queue.
1136 // libsoundio ring buffers use memory mapping techniques to enable a
1137 // contiguous buffer when reading or writing across the boundary of the ring
1138 // buffer's capacity.
1139
1140 // Enum is defined above. See https://github.com/rust-lang/rust/issues/27303
1141 // struct SoundIoRingBuffer;
1142
1143 // `requested_capacity` in bytes.
1144 // Returns `NULL` if and only if memory could not be allocated.
1145 // Use ::soundio_ring_buffer_capacity to get the actual capacity, which might
1146 // be greater for alignment purposes.
1147 // See also ::soundio_ring_buffer_destroy
1148 pub fn soundio_ring_buffer_create(
1149 soundio: *mut SoundIo,
1150 requested_capacity: c_int,
1151 ) -> *mut SoundIoRingBuffer;
1152 pub fn soundio_ring_buffer_destroy(ring_buffer: *mut SoundIoRingBuffer);
1153
1154 // When you create a ring buffer, capacity might be more than the requested
1155 // capacity for alignment purposes. This function returns the actual capacity.
1156 pub fn soundio_ring_buffer_capacity(ring_buffer: *mut SoundIoRingBuffer) -> c_int;
1157
1158 // Do not write more than capacity.
1159 pub fn soundio_ring_buffer_write_ptr(ring_buffer: *mut SoundIoRingBuffer) -> *mut c_char;
1160 // `count` in bytes.
1161 pub fn soundio_ring_buffer_advance_write_ptr(ring_buffer: *mut SoundIoRingBuffer, count: c_int);
1162
1163 // Do not read more than capacity.
1164 pub fn soundio_ring_buffer_read_ptr(ring_buffer: *mut SoundIoRingBuffer) -> *mut c_char;
1165 // `count` in bytes.
1166 pub fn soundio_ring_buffer_advance_read_ptr(ring_buffer: *mut SoundIoRingBuffer, count: c_int);
1167
1168 // Returns how many bytes of the buffer is used, ready for reading.
1169 pub fn soundio_ring_buffer_fill_count(ring_buffer: *mut SoundIoRingBuffer) -> c_int;
1170
1171 // Returns how many bytes of the buffer is free, ready for writing.
1172 pub fn soundio_ring_buffer_free_count(ring_buffer: *mut SoundIoRingBuffer) -> c_int;
1173
1174 // Must be called by the writer.
1175 pub fn soundio_ring_buffer_clear(ring_buffer: *mut SoundIoRingBuffer);
1176
1177}