pub struct PcmBuffer { /* private fields */ }Expand description
Rolling / accumulating mono PCM buffer at WHISPER_SAMPLE_RATE.
Storage is a fixed-capacity ring. Capacity is never exceeded, including when a single push is larger than capacity (only the newest tail is retained).
Implementations§
Source§impl PcmBuffer
impl PcmBuffer
Sourcepub fn with_max_secs(max_secs: f64) -> Self
pub fn with_max_secs(max_secs: f64) -> Self
Create a buffer capped at max_secs of audio (rolling by default).
Sourcepub fn bounded(max_secs: f64) -> Self
pub fn bounded(max_secs: f64) -> Self
Grow until max_secs, then error instead of dropping audio.
pub fn clear(&mut self)
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn max_samples(&self) -> usize
pub fn is_rolling(&self) -> bool
pub fn duration_secs(&self) -> f64
Sourcepub fn clamped_count(&self) -> u64
pub fn clamped_count(&self) -> u64
How many samples were amplitude-clamped into [-1, 1] since construction.
Sourcepub fn samples(&self) -> ContiguousSamples<'_>
pub fn samples(&self) -> ContiguousSamples<'_>
Contiguous view of logical samples.
When the ring is not wrapped this is zero-copy. When wrapped, samples are
linearized into a temporary Vec (only on this call).
Sourcepub fn copy_samples_into(&self, dst: &mut Vec<f32>)
pub fn copy_samples_into(&self, dst: &mut Vec<f32>)
Copy logical samples into dst (reused by hosts to avoid allocation).
Sourcepub fn push(&mut self, chunk: &[f32]) -> Result<()>
pub fn push(&mut self, chunk: &[f32]) -> Result<()>
Append mono f32 samples already at 16 kHz.
Rejects NaN/Inf. Samples outside [-1, 1] are clamped and counted.
Oversized chunks in rolling mode keep only the newest max_samples without
ever allocating beyond capacity.
Sourcepub fn rms(&self) -> f32
pub fn rms(&self) -> f32
RMS energy using f64 accumulation (numerically stable for long windows).
Sourcepub fn to_audio_input(&self) -> Result<AudioInput>
pub fn to_audio_input(&self) -> Result<AudioInput>
Snapshot as AudioInput without clearing the buffer.
Sourcepub fn take_audio_input(&mut self) -> Result<AudioInput>
pub fn take_audio_input(&mut self) -> Result<AudioInput>
Take ownership of samples and clear the buffer.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PcmBuffer
impl RefUnwindSafe for PcmBuffer
impl Send for PcmBuffer
impl Sync for PcmBuffer
impl Unpin for PcmBuffer
impl UnsafeUnpin for PcmBuffer
impl UnwindSafe for PcmBuffer
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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