Skip to main content

Crate flexaudio_core

Crate flexaudio_core 

Source
Expand description

flexaudio-core — OS-independent core.

The OS-independent part of the desktop audio capture abstraction library flexaudio. Provides ring buffers, sample-rate conversion, channel mixing, 20 ms chunking, clock normalization, events, and type definitions. OS-specific capture is implemented by separate flexaudio-os-* crates that implement backend::CaptureBackend, which the facade layer wires to the core.

§Fixed contract

All internal processing uses interleaved f32 / 48000 Hz / stereo 2ch / 20 ms = 960 frames/chunk. OutputFormat can change the external rate/channels (the Normalizer’s second stage resamples; e.g. 16k/1ch gives 320 frames/chunk). Output chunks remain 20 ms regardless of rate.

The public API has no callbacks. RT threads only push; consumers poll. The RT path never blocks (DROP_OLDEST / overflow drop when full). PTS comes from the device and gaps are detected.

§Two-stage ring-buffer layout

[RT cb] --push--> RawRing (rtrb, RT-safe) --pop--> [ingest/process thread]
                                                      |
                                         Normalizer (mix + rubato SRC + 960-frame slicing)
                                                      |
                                                      v
                                      ChunkRing (ringbuf, DROP_OLDEST) --try_pop--> [poll]

Re-exports§

pub use capabilities::Availability;
pub use capabilities::BackendKind;
pub use capabilities::Capabilities;
pub use capabilities::DeviceSelectionBehavior;
pub use capabilities::DeviceWatcherCapabilities;
pub use capabilities::OsVersion;
pub use capabilities::PidScope;
pub use capabilities::ProcessCapabilities;
pub use capabilities::SideEffectCapabilities;
pub use capabilities::SideEffectCapability;
pub use capabilities::SideEffectCondition;
pub use capabilities::SourceCapabilities;
pub use capabilities::SourceCapability;
pub use capabilities::SystemExclusionCapabilities;
pub use capabilities::UnavailableReason;
pub use capabilities::WatchScope;
pub use capabilities::WatcherMode;
pub use backend::CaptureBackend;
pub use backend::RawSink;
pub use chunk_ring::chunk_ring;
pub use chunk_ring::ChunkConsumer;
pub use chunk_ring::ChunkProducer;
pub use clock::monotonic_now_ns;
pub use clock::ClockNormalizer;
pub use normalizer::InnerProcessor;
pub use normalizer::NormalizedChunk;
pub use normalizer::Normalizer;
pub use normalizer::CHUNK_FRAMES;
pub use quant::quantize_i16;
pub use raw_ring::raw_ring;
pub use raw_ring::RawConsumer;
pub use raw_ring::RawProducer;
pub use secondary_ring::secondary_chunk_ring;
pub use secondary_ring::SecondaryChunkConsumer;
pub use secondary_ring::SecondaryChunkProducer;
pub use types::AudioChunk;
pub use types::AudioLoss;
pub use types::AudioPath;
pub use types::ChunkFlags;
pub use types::DefaultDeviceKind;
pub use types::DeviceEvent;
pub use types::DeviceInfo;
pub use types::Error;
pub use types::ErrorContext;
pub use types::ErrorGroup;
pub use types::ErrorKind;
pub use types::Event;
pub use types::LossReason;
pub use types::MixLane;
pub use types::NativeStatus;
pub use types::Operation;
pub use types::OutputFormat;
pub use types::OutputTap;
pub use types::Permission;
pub use types::ProcessInfo;
pub use types::Result;
pub use types::SecondaryChunk;
pub use types::ShutdownReport;
pub use types::SourceKind;
pub use types::StreamConfig;
pub use types::CHANNELS;
pub use types::SAMPLE_RATE;
pub use diagnostics::CaptureDiagnostics;
pub use startup::StartupDropReason;

Modules§

backend
The CaptureBackend trait implemented by OS backends, and the RawSink handle used by backends to pass raw frames to the core.
capabilities
Capture support and optional side effects, independent of capture permissions.
chunk_ring
SPSC ring for completed AudioChunk values, backed by ringbuf.
clock
Helpers for translating timestamps to process-monotonic i64 nanoseconds.
diagnostics
Allocation-free realtime rejection summaries, materialized off callback.
error_context
Typed failure context and retained shutdown outcomes.
inventory
Shared discovery policy: collection failures are terminal; entry metadata is best effort.
normalizer
Normalize arbitrary device frames (any sample rate/channel count, interleaved f32) in two stages, then convert them back to the requested output format.
process_list
OS-independent post-processing for process enumeration results (ProcessInfo).
quant
Signed 16-bit PCM quantization, shared by every output path.
raw_ring
SPSC, real-time-safe ring for raw interleaved f32 device frames, backed by rtrb.
secondary_ring
SPSC ring of finished SecondaryChunks (ringbuf-backed, DROP_OLDEST).
startup
Sample-based microphone startup confirmation, shared by facade capture paths.
types
Shared types: internal canonical-form constants / AudioChunk / ChunkFlags / SourceKind / OutputFormat / StreamConfig / Event / Error.

Enums§

AddonErrorKind
Addon failure identity, independent of native or model diagnostic messages.
ChunkMsOption
Public spelling of the canonical chunk-duration option.
VadErrorCode
Typed cause of an isolated VAD failure.

Functions§

chunk_ms_error
One cause/remedy message with the binding’s public option name.
spawn_error
Keep the I/O classification and numeric OS cause without exposing paths or payloads.
validate_chunk_ms
Validate the canonical frame duration before acquiring capture resources.