Expand description
Real-time audio input capture using cpal.
On Linux, cpal sits on top of ALSA and transparently sees both
PulseAudio and PipeWire (via its Pulse compatibility layer)
devices. The interesting bit for a music visualizer is selecting
the right source: the host’s default input is usually the
microphone, but we want the active sink’s monitor so the
visualizer reacts to whatever is playing out of the speakers.
detect_default_source applies that heuristic — pick the
monitor of the default output sink when one exists, otherwise
any .monitor source, otherwise the host’s default input.
[with_device] uses it transparently when no explicit name is
requested.
Structs§
- Audio
Analysis Input - Audio input with FFT analysis for bass/mid/treb extraction.
- Audio
Input - Real-time audio input capture.
- Audio
Source - A capture device enumerated from the active cpal host.
Enums§
- Audio
Input Error - Audio input errors.
- Source
Kind - Coarse classification of an input source. Used by the CLI
list-audiosubcommand and the GUI device picker to flag which devices are monitor sources (capture what speakers play) versus microphones — both surface as cpalDevices with no built-in type tag, so we infer from the name.
Functions§
- classify_
source 🔒 - Classify a device name with the heuristic documented above. Pure function so we can unit-test without a real audio host.
- detect_
default_ 🔒source - Pick the best autodetect source for a music visualizer.
- device_
name 🔒 - Read a cpal
Device’s human name through the [DeviceTrait::description] surface (cpal 0.17 deprecates the barename()accessor). ReturnsNonewhen the description can’t be fetched — usually because the device was disconnected mid-enumeration. - list_
sources - Enumerate every capture source the active cpal host exposes, with classification flags. Cheap (no streams opened); the CLI / GUI device pickers and the autodetect-preview both call this.