Skip to main content

StreamingWang

Struct StreamingWang 

Source
pub struct StreamingWang { /* private fields */ }
Expand description

Streaming Wang fingerprinter — fully incremental.

Maintains a rolling spectrogram window (2·neighborhood_t + 1 rows), detects peaks frame-by-frame as they ripen, accumulates per-second candidate buckets, finalises buckets via the per-second adaptive threshold, and grows per-anchor target heaps until each anchor’s target zone is fully observed. Per-push CPU cost is proportional to the number of new frames (not the total stream length).

For whole-second (and many other) clip lengths, the legacy StreamingFingerprinter::flush hash multiset matches Wang::extract — verified by the streaming_offline_* tests. At certain fractional-second remainders (audit F01) legacy flush may emit fewer hashes; use flush_complete when you need offline parity.

The pipeline itself is shared with StreamingPanako via the crate-internal streaming core; this wrapper supplies only the Wang-specific hash emission.

§Example

use audiofp::{SampleRate, StreamingFingerprinter};
use audiofp::classical::StreamingWang;

let mut s = StreamingWang::default();
// Feed 4 seconds of silence in two chunks; nothing should be emitted.
let zeros = vec![0.0_f32; 8_000 * 2];
assert!(s.push(&zeros).unwrap().is_empty());
assert!(s.push(&zeros).unwrap().is_empty());
assert!(s.flush().unwrap().is_empty());

Implementations§

Source§

impl StreamingWang

Source

pub fn new(cfg: WangConfig) -> Self

Build a streaming Wang extractor with the given config.

Clamps target_zone_t to a minimum of 1 and fan_out to a minimum of 1 to prevent underflows/empty output from degenerate configurations. Caps target_zone_t at 512 and fan_out at 64 to prevent OOM from extreme values.

Source

pub fn config(&self) -> &WangConfig

Borrow the configuration this stream was built with.

Source

pub fn reset(&mut self)

Reset all internal state. The stream behaves as if freshly constructed: no buffered audio, no pending peaks or anchors. Call between independent streams sharing one instance so stale data from a previous stream doesn’t bleed into the first emitted hash.

Source

pub fn flush_complete(&mut self) -> Result<Vec<(TimestampMs, WangHash)>>

Corrected end-of-stream finalisation matching offline Wang::extract.

The default StreamingFingerprinter::flush is legacy: it may emit fewer hashes than offline extraction at certain clip lengths (notably fractional-second remainders such as 18 000 samples at 8 kHz) because anchors are drained before later target buckets are finalised. Call this opt-in API when you need offline parity; keep using flush only when byte-identical legacy streaming output is required.

Idempotent with respect to anchor emission: a second call with no intervening push returns nothing. Safe after push following an earlier flush_complete (pending anchors/targets are empty).

Source

pub fn flush_complete_with<F>(&mut self, callback: F) -> Result<usize>

Callback variant of flush_complete.

Trait Implementations§

Source§

impl Default for StreamingWang

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl StreamingFingerprinter for StreamingWang

Source§

type Frame = WangHash

One unit of fingerprint material the stream emits.
Source§

fn required_sample_rate(&self) -> u32

Sample rate, in hertz, the stream expects its input at. Read more
Source§

fn push(&mut self, samples: &[f32]) -> Result<Vec<(TimestampMs, Self::Frame)>>

Feed PCM samples and return any fingerprints that became available during this push. Read more
Source§

fn push_with<F>(&mut self, samples: &[f32], callback: F) -> Result<usize>
where F: FnMut(TimestampMs, &Self::Frame),

Feed PCM samples and invoke callback for each fingerprint frame that became available during this push. Read more
Source§

fn flush(&mut self) -> Result<Vec<(TimestampMs, Self::Frame)>>

Drain any pending fingerprint material at end-of-stream. Read more
Source§

fn flush_with<F>(&mut self, callback: F) -> Result<usize>
where F: FnMut(TimestampMs, &Self::Frame),

Drain any pending fingerprint material at end-of-stream, invoking callback for each frame. Read more
Source§

fn latency_ms(&self) -> u32

Conservative upper bound on emission latency: from the time a sample enters push to the time the fingerprint covering it is returned.
Source§

fn push_strict( &mut self, samples: &[f32], ) -> Result<Vec<(TimestampMs, Self::Frame)>>

Like push, but fail fast on non-finite input instead of sanitizing it to 0.0. Read more
Source§

impl ZeroAllocStreaming for StreamingWang

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.