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 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::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::ChunkFlags;
pub use types::DeviceEvent;
pub use types::DeviceInfo;
pub use types::Error;
pub use types::Event;
pub use types::OutputFormat;
pub use types::ProcessInfo;
pub use types::Result;
pub use types::SecondaryChunk;
pub use types::SourceKind;
pub use types::StreamConfig;
pub use types::CHANNELS;
pub use types::SAMPLE_RATE;

Modules§

backend
The CaptureBackend trait implemented by OS backends, and the RawSink handle used by backends to pass raw frames to the core.
chunk_ring
SPSC ring for completed AudioChunk values, backed by ringbuf.
clock
Helpers for normalizing device PTS and monotonic clocks to shared i64 nanoseconds.
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).
types
Shared types: internal canonical-form constants / AudioChunk / ChunkFlags / SourceKind / OutputFormat / StreamConfig / Event / Error.