pub struct Pcm { /* private fields */ }alsa only.Expand description
An opened PCM device.
Implementations§
Source§impl Pcm
impl Pcm
Sourcepub fn open(name: &CStr, stream: Stream) -> Result<Self>
pub fn open(name: &CStr, stream: Stream) -> Result<Self>
Open the given pcm device identified by name.
§Examples
use audio_device::alsa;
use std::ffi::CStr;
let name = CStr::from_bytes_with_nul(b"hw:0\0")?;
let pcm = alsa::Pcm::open(name, alsa::Stream::Playback)?;Sourcepub fn open_default(stream: Stream) -> Result<Self>
pub fn open_default(stream: Stream) -> Result<Self>
Open the default pcm device.
§Examples
use audio_device::alsa;
use std::ffi::CStr;
let pcm = alsa::Pcm::open_default(alsa::Stream::Playback)?;Sourcepub fn open_nonblocking(name: &CStr, stream: Stream) -> Result<Self>
pub fn open_nonblocking(name: &CStr, stream: Stream) -> Result<Self>
Open the given pcm device identified by name in a nonblocking manner.
§Examples
use audio_device::alsa;
use std::ffi::CStr;
let name = CStr::from_bytes_with_nul(b"hw:0\0")?;
let pcm = alsa::Pcm::open_nonblocking(name, alsa::Stream::Playback)?;Sourcepub fn open_default_nonblocking(stream: Stream) -> Result<Self>
pub fn open_default_nonblocking(stream: Stream) -> Result<Self>
Open the default pcm device in a nonblocking mode.
§Examples
use audio_device::alsa;
use std::ffi::CStr;
let pcm = alsa::Pcm::open_default_nonblocking(alsa::Stream::Playback)?;Sourcepub fn state(&self) -> State
pub fn state(&self) -> State
Get the state of the PCM.
§Examples
use audio_device::alsa;
let pcm = alsa::Pcm::open_default(alsa::Stream::Playback)?;
dbg!(pcm.state());Sourcepub fn configure<T>(&mut self) -> Configurator<'_, T>where
T: Sample,
pub fn configure<T>(&mut self) -> Configurator<'_, T>where
T: Sample,
Construct a simple stream Configurator.
It will be initialized with a set of default parameters which are
usually suitable for simple playback or recording for the given sample
type T.
See Configurator.
§Examples
use audio_device::alsa;
let mut pcm = alsa::Pcm::open_default(alsa::Stream::Playback)?;
let config = pcm.configure::<i16>().install()?;Sourcepub fn start(&mut self) -> Result<()>
pub fn start(&mut self) -> Result<()>
Start a PCM.
§Examples
use audio_device::alsa;
let mut pcm = alsa::Pcm::open_default(alsa::Stream::Playback)?;
pcm.start()?;Sourcepub fn pause(&mut self) -> Result<()>
pub fn pause(&mut self) -> Result<()>
Pause a PCM.
§Examples
use audio_device::alsa;
let mut pcm = alsa::Pcm::open_default(alsa::Stream::Playback)?;
pcm.pause()?;Sourcepub fn resume(&mut self) -> Result<()>
pub fn resume(&mut self) -> Result<()>
Resume a PCM.
§Examples
use audio_device::alsa;
let mut pcm = alsa::Pcm::open_default(alsa::Stream::Playback)?;
pcm.resume()?;Sourcepub fn hardware_parameters_any(&mut self) -> Result<HardwareParametersMut<'_>>
pub fn hardware_parameters_any(&mut self) -> Result<HardwareParametersMut<'_>>
Open all available hardware parameters for the current handle.
§Examples
use audio_device::alsa;
let mut pcm = alsa::Pcm::open_default(alsa::Stream::Playback)?;
let mut hw = pcm.hardware_parameters_any()?;
hw.set_rate_last()?;
hw.install()?;Sourcepub fn hardware_parameters_mut(&mut self) -> Result<HardwareParametersMut<'_>>
pub fn hardware_parameters_mut(&mut self) -> Result<HardwareParametersMut<'_>>
Open current hardware parameters for the current handle for mutable access.
§Examples
use audio_device::alsa;
let mut pcm = alsa::Pcm::open_default(alsa::Stream::Playback)?;
let mut hw = pcm.hardware_parameters_mut()?;
let actual_rate = hw.set_rate(44100, alsa::Direction::Nearest)?;
hw.install()?;
dbg!(actual_rate);Sourcepub fn hardware_parameters(&mut self) -> Result<HardwareParameters>
pub fn hardware_parameters(&mut self) -> Result<HardwareParameters>
Open current hardware parameters for the current handle.
§Examples
use audio_device::alsa;
let mut pcm = alsa::Pcm::open_default(alsa::Stream::Playback)?;
let sw = pcm.hardware_parameters()?;
dbg!(sw.rate()?);Sourcepub fn software_parameters(&mut self) -> Result<SoftwareParameters>
pub fn software_parameters(&mut self) -> Result<SoftwareParameters>
Open current software parameters for the current handle.
§Examples
use audio_device::alsa;
let mut pcm = alsa::Pcm::open_default(alsa::Stream::Playback)?;
let sw = pcm.software_parameters()?;
dbg!(sw.boundary()?);Sourcepub fn software_parameters_mut(&mut self) -> Result<SoftwareParametersMut<'_>>
pub fn software_parameters_mut(&mut self) -> Result<SoftwareParametersMut<'_>>
Open current software parameters for the current handle for mutable access.
§Examples
use audio_device::alsa;
let mut pcm = alsa::Pcm::open_default(alsa::Stream::Playback)?;
let mut sw = pcm.software_parameters_mut()?;
sw.set_timestamp_mode(alsa::Timestamp::Enable)?;
sw.install()?;Sourcepub fn poll_descriptors_count(&mut self) -> usize
pub fn poll_descriptors_count(&mut self) -> usize
Get count of poll descriptors for PCM handle.
§Examples
use audio_device::alsa;
let mut pcm = alsa::Pcm::open_default(alsa::Stream::Playback)?;
let count = pcm.poll_descriptors_count();
dbg!(count);Sourcepub fn poll_descriptors_vec(&mut self, fds: &mut Vec<pollfd>) -> Result<()>
pub fn poll_descriptors_vec(&mut self, fds: &mut Vec<pollfd>) -> Result<()>
Get poll descriptors.
This function fills the given poll descriptor structs for the specified PCM handle. The poll desctiptor array should have the size returned by poll_descriptors_count() function.
The result is intended for direct use with the poll() syscall.
For reading the returned events of poll descriptor after poll() system
call, use ::snd_pcm_poll_descriptors_revents() function. The field
values in pollfd structs may be bogus regarding the stream direction
from the application perspective (POLLIN might not imply read
direction and POLLOUT might not imply write), but the
poll_descriptors_revents() function
does the right “demangling”.
You can use output from this function as arguments for the select()
syscall, too. Do not forget to translate POLLIN and POLLOUT events
to corresponding FD_SET arrays and demangle events using
poll_descriptors_revents().
§Examples
use audio_device::alsa;
let mut pcm = alsa::Pcm::open_default(alsa::Stream::Playback)?;
let mut fds = Vec::with_capacity(pcm.poll_descriptors_count());
pcm.poll_descriptors_vec(&mut fds)?;Sourcepub fn poll_descriptors_revents(
&mut self,
fds: &mut [pollfd],
) -> Result<PollFlags>
pub fn poll_descriptors_revents( &mut self, fds: &mut [pollfd], ) -> Result<PollFlags>
Get returned events from poll descriptors.
This function does “demangling” of the revents mask returned from the
poll() syscall to correct semantics (PollFlags::POLLIN = read,
PollFlags::POLLOUT = write).
Note: The null event also exists. Even if poll() or select() syscall
returned that some events are waiting, this function might return empty
set of events. In this case, application should do next event waiting
using poll() or select().
Note: Even if multiple poll descriptors are used (i.e. fds.len() > 1),
this function returns only a single event.
Sourcepub unsafe fn write_interleaved_unchecked(
&mut self,
buf: *const c_void,
len: c_ulong,
) -> Result<c_long>
pub unsafe fn write_interleaved_unchecked( &mut self, buf: *const c_void, len: c_ulong, ) -> Result<c_long>
Write unchecked interleaved frames to a PCM.
Note: that the len must be the number of frames in the buf which
does not account for the number of channels. So if len is 100, and
the number of configured channels is 2, the buf must contain at
least 200 bytes.
Sourcepub fn writer<T>(&mut self) -> Result<Writer<'_, T>>where
T: Sample,
pub fn writer<T>(&mut self) -> Result<Writer<'_, T>>where
T: Sample,
Construct a checked safe writer with the given number of channels and the specified sample type.
This will error if the type T is not appropriate for this device, or
if the number of channels does not match the number of configured
channels.
§Examples
use audio_device::alsa;
let mut pcm = alsa::Pcm::open_default(alsa::Stream::Playback)?;
let config = pcm.configure::<i16>().install()?;
let mut writer = pcm.writer::<i16>()?;
// use writer with the resulting config.Sourcepub fn async_writer<T>(&mut self) -> Result<AsyncWriter<'_, T>>where
T: Sample,
Available on crate feature poll-driver only.
pub fn async_writer<T>(&mut self) -> Result<AsyncWriter<'_, T>>where
T: Sample,
poll-driver only.Construct a checked safe writer with the given number of channels and the specified sample type.
This will error if the type T is not appropriate for this device, or
if the number of channels does not match the number of configured
channels.
§Panics
Panics if the audio runtime is not available.
See Runtime for more.
§Examples
use audio_device::alsa;
let mut pcm = alsa::Pcm::open_default(alsa::Stream::Playback)?;
let config = pcm.configure::<i16>().install()?;
let mut writer = pcm.writer::<i16>()?;
// use writer with the resulting config.Sourcepub fn available_update(&mut self) -> Result<usize>
pub fn available_update(&mut self) -> Result<usize>
Return number of frames ready to be read (capture) / written (playback).
§Examples
use audio_device::alsa;
let mut pcm = alsa::Pcm::open_default(alsa::Stream::Playback)?;
let avail = pcm.available_update()?;
dbg!(avail);