pub struct RingBufferStft { /* private fields */ }Expand description
Ring-buffer STFT processor for low-latency, online signal analysis.
Maintains a circular sample buffer of length window_size. Samples
pushed via push are written into the ring; once at least
hop_size new samples have arrived a complete frame is produced without
any extra allocation.
Implementations§
Source§impl RingBufferStft
impl RingBufferStft
Sourcepub fn new(config: RingBufferStftConfig) -> Result<RingBufferStft, FFTError>
pub fn new(config: RingBufferStftConfig) -> Result<RingBufferStft, FFTError>
Create a new processor from config.
§Errors
Returns FFTError::ValueError if:
window_sizeis not a power of two or is less than 4.hop_sizeis zero or larger thanwindow_size.
Sourcepub fn push(&mut self, samples: &[f32]) -> Vec<StftFrame>
pub fn push(&mut self, samples: &[f32]) -> Vec<StftFrame>
Push new samples into the processor.
Returns all complete frames generated from the incoming data. A frame
is emitted every hop_size samples.
Sourcepub fn flush(&mut self) -> Vec<StftFrame>
pub fn flush(&mut self) -> Vec<StftFrame>
Flush any remaining buffered samples by zero-padding to the next frame boundary and emitting the final frames.
Sourcepub fn reconstruct(
&mut self,
frame: &StftFrame,
modified_spectrum: Option<&[(f32, f32)]>,
) -> Result<Vec<f32>, FFTError>
pub fn reconstruct( &mut self, frame: &StftFrame, modified_spectrum: Option<&[(f32, f32)]>, ) -> Result<Vec<f32>, FFTError>
Overlap-add reconstruction.
Computes the IFFT of modified_spectrum (or of the original spectrum
stored in frame if modified_spectrum is None), applies the window
function, and accumulates the result in the internal OLA buffer.
Returns hop_size reconstructed samples (the oldest hop’s worth of
completed output).
§Errors
Returns FFTError::ValueError if overlap-add was not enabled in the
config, or if the spectrum length is wrong.
Sourcepub fn n_freq_bins(&self) -> usize
pub fn n_freq_bins(&self) -> usize
Number of one-sided frequency bins (window_size / 2 + 1).
Auto Trait Implementations§
impl Freeze for RingBufferStft
impl RefUnwindSafe for RingBufferStft
impl Send for RingBufferStft
impl Sync for RingBufferStft
impl Unpin for RingBufferStft
impl UnsafeUnpin for RingBufferStft
impl UnwindSafe for RingBufferStft
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.