rtaudio/
lib.rs

1mod buffer;
2mod device_info;
3mod enums;
4mod error;
5mod ffi_utils;
6mod host;
7mod options;
8mod stream;
9mod wrapper;
10
11pub use buffer::*;
12pub use device_info::*;
13pub use enums::*;
14pub use error::*;
15pub use host::*;
16pub use options::*;
17pub use stream::*;
18
19/// Get the current RtAudio version.
20pub fn version() -> String {
21    // Safety: We assume this c string pointer to always be valid.
22    unsafe {
23        let raw_s = rtaudio_sys::rtaudio_version();
24        crate::ffi_utils::c_str_ptr_to_string_lossy(raw_s).unwrap_or_else(|| String::from("error"))
25    }
26}
27
28/// Get the list of APIs compiled into this instance of RtAudio.
29pub fn compiled_apis() -> Vec<Api> {
30    // Safety: We assume RtAudio reports the correct length, we check
31    // for the null case, and we do not free the `raw_list` pointer.
32    let raw_apis_slice: &[rtaudio_sys::rtaudio_api_t] = unsafe {
33        let num_compiled_apis = rtaudio_sys::rtaudio_get_num_compiled_apis();
34
35        if num_compiled_apis == 0 {
36            return Vec::new();
37        }
38
39        let raw_list = rtaudio_sys::rtaudio_compiled_api();
40
41        if raw_list.is_null() {
42            return Vec::new();
43        }
44
45        std::slice::from_raw_parts(raw_list, num_compiled_apis as usize)
46    };
47
48    raw_apis_slice
49        .iter()
50        .filter_map(|raw_api| Api::from_raw(*raw_api))
51        .collect()
52}