pub struct AudioInput {
_host: Host,
_device: Device,
_stream: Stream,
buffer: Arc<Mutex<Vec<f32>>>,
sample_rate: u32,
}Expand description
Real-time audio input capture.
Fields§
§_host: HostAudio host
_device: DeviceInput device
_stream: StreamInput stream
buffer: Arc<Mutex<Vec<f32>>>Shared buffer for audio samples
sample_rate: u32Sample rate
Implementations§
Source§impl AudioInput
impl AudioInput
Sourcepub fn list_input_devices() -> Vec<String>
pub fn list_input_devices() -> Vec<String>
Enumerate the names of every input device offered by cpal’s
default host. Used by the GUI’s Options panel to populate the
audio device picker. Devices that fail name() (rare —
usually disconnected mid-enumeration) are silently skipped.
Prefer list_sources when callers want the
monitor/microphone classification flags (CLI list-audio
subcommand, future GUI picker).
Sourcepub fn with_device(name: Option<&str>) -> Result<Self>
pub fn with_device(name: Option<&str>) -> Result<Self>
Create a new audio input capture targeting a specific device by
name. name = None triggers the music-visualizer autodetect:
the monitor of the host’s default output sink is preferred over
the host default input (the microphone), so a fresh install
reacts to playing music without any GUI / CLI configuration.
See detect_default_source for the full preference order.
Unknown names log a warning and fall back to the same
autodetect.
Sourcepub fn get_samples(&self) -> Vec<f32>
pub fn get_samples(&self) -> Vec<f32>
Get the latest audio samples. Returns a copy of the current buffer.
Sourcepub fn sample_rate(&self) -> u32
pub fn sample_rate(&self) -> u32
Get the sample rate.
Sourcepub fn get_fixed_samples(&self, count: usize) -> Vec<f32>
pub fn get_fixed_samples(&self, count: usize) -> Vec<f32>
Get a fixed number of samples for processing. If not enough samples are available, returns zeros.
Auto Trait Implementations§
impl Freeze for AudioInput
impl !RefUnwindSafe for AudioInput
impl Send for AudioInput
impl Sync for AudioInput
impl Unpin for AudioInput
impl !UnwindSafe for AudioInput
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more