#![allow(unsafe_code)]
use std::os::raw::{c_char, c_int, c_long, c_uint, c_ulong, c_void};
#[allow(unused)]
#[repr(C)]
#[non_exhaustive]
#[derive(Copy, Clone, Debug, PartialEq)]
pub(crate) enum SndPcmMode {
Block = 0,
Nonblock = 1,
Async = 2,
}
#[allow(unused)]
#[repr(C)]
#[non_exhaustive]
#[derive(Copy, Clone, Debug, PartialEq)]
pub(crate) enum SndPcmStream {
Playback = 0,
Capture,
}
#[allow(unused)]
#[repr(C)]
#[non_exhaustive]
#[derive(Copy, Clone, Debug, PartialEq)]
pub(crate) enum SndPcmAccess {
MmapInterleaved = 0,
MmapNoninterleaved,
MmapComplex,
RwInterleaved,
RwNoninterleaved,
}
#[allow(unused)]
#[repr(C)]
#[non_exhaustive]
#[derive(Copy, Clone, Debug, PartialEq)]
pub(crate) enum SndPcmFormat {
Unknown = -1,
S8 = 0,
U8,
S16Le,
S16Be,
U16Le,
U16Be,
S24Le,
S24Be,
U24Le,
U24Be,
S32Le,
S32Be,
U32Le,
U32Be,
FloatLe,
FloatBe,
Float64Le,
Float64Be,
Iec958SubframeLe,
Iec958SubframeBe,
MuLaw,
ALaw,
ImaAdpcm,
Mpeg,
Gsm,
S20Le,
S20Be,
U20Le,
U20Be,
Special = 31,
S243le = 32,
S243be,
U243le,
U243be,
S203le,
S203be,
U203le,
U203be,
S183le,
S183be,
U183le,
U183be,
G72324,
G723241b,
G72340,
G723401b,
DsdU8,
DsdU16Le,
DsdU32Le,
DsdU16Be,
DsdU32Be,
}
#[allow(unused)]
#[repr(C)]
#[non_exhaustive]
#[derive(Copy, Clone, Debug, PartialEq)]
pub(crate) enum SndPcmState {
Open = 0,
Setup,
Prepared,
Running,
Xrun,
Draining,
Paused,
Suspended,
Disconnected,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub(crate) struct PollFd {
pub(super) fd: c_int,
pub(super) events: std::os::raw::c_short,
pub(super) revents: std::os::raw::c_short,
}
dl_api::linker!(extern "C" Alsa "libasound.so.2" {
fn snd_device_name_hint(
card: c_int,
iface: *const c_char,
hints: *mut *mut *mut c_void,
) -> c_int;
fn snd_device_name_get_hint(hint: *const c_void, id: *const c_char)
-> *mut c_char;
fn snd_device_name_free_hint(hints: *mut *mut c_void) -> c_int;
fn snd_pcm_open(pcmp: *mut *mut c_void,
name: *const c_char,
stream: SndPcmStream,
mode: c_int,
) -> c_int;
fn snd_pcm_close(pcm: *mut c_void) -> c_int;
fn snd_pcm_drop(pcm: *mut c_void) -> c_int;
fn snd_pcm_prepare(pcm: *mut c_void) -> c_int;
fn snd_pcm_resume(pcm: *mut c_void) -> c_int;
fn snd_pcm_state(pcm: *mut c_void) -> SndPcmState;
fn snd_pcm_readi(
pcm: *mut c_void,
buffer: *mut c_void,
size: c_ulong,
) -> c_long;
fn snd_pcm_writei(
pcm: *mut c_void,
buffer: *const c_void,
size: c_ulong,
) -> c_long;
fn snd_pcm_poll_descriptors(pcm: *mut c_void, pfds: *mut PollFd, space: c_uint) -> c_int;
fn snd_pcm_poll_descriptors_count(pcm: *mut c_void) -> c_int;
fn snd_pcm_hw_params(pcm: *mut c_void, params: *mut c_void) -> c_int;
fn snd_pcm_hw_params_free(params: *mut c_void) -> ();
fn snd_pcm_hw_params_set_rate_near(pcm: *mut c_void, params: *mut c_void, val: *mut c_uint, dir: *mut c_int) -> c_int;
fn snd_pcm_hw_params_get_rate_numden(params: *mut c_void, rate_num: *mut c_uint, rate_den: *mut c_uint) -> c_int;
fn snd_pcm_hw_params_any(pcm: *mut c_void, params: *mut c_void) -> c_int;
fn snd_pcm_hw_params_test_channels(pcm: *mut c_void, params: *mut c_void, val: c_uint) -> c_int;
fn snd_pcm_hw_params_set_channels(pcm: *mut c_void, params: *mut c_void, val: c_uint) -> c_int;
fn snd_pcm_hw_params_malloc(ptr: *mut *mut c_void) -> c_int;
fn snd_pcm_hw_params_set_access(
pcm: *mut c_void,
params: *mut c_void,
access: SndPcmAccess,
) -> c_int;
fn snd_pcm_hw_params_set_format(
pcm: *mut c_void,
params: *mut c_void,
access: SndPcmFormat,
) -> c_int;
fn snd_pcm_hw_params_set_buffer_size_near(
pcm: *mut c_void,
params: *mut c_void,
val: *mut c_uint,
) -> c_int;
fn snd_pcm_hw_params_set_period_size_near(
pcm: *mut c_void,
params: *mut c_void,
val: *mut c_uint,
dir: *mut c_int,
) -> c_int;
});
extern "C" {
pub(super) fn free(ptr: *mut c_void);
}
thread_local! {
static ALSA: Option<Alsa> = Alsa::new().ok();
}
#[path = "device_list.rs"]
pub(super) mod device_list;
#[path = "pcm.rs"]
pub(super) mod pcm;