Trait beat_detector::Strategy [−][src]
pub trait Strategy { fn is_beat(&self, samples: &[i16]) -> Option<BeatInfo>; fn kind(&self) -> StrategyKind; fn name() -> &'static str
where
Self: Sized; fn description() -> &'static str
where
Self: Sized; fn min_duration_between_beats_ms() -> u32
where
Self: Sized; fn last_beat_beyond_threshold(&self, state: &AnalysisState) -> bool
where
Self: Sized, { ... } fn amplitude_high_enough(&self, w_stats: &WindowStats) -> bool { ... } }
Expand description
Common abstraction over a beat detection strategy. Each strategy keeps ongoing audio samples, for example from microphone. Strategies should have an internal mutable state via interior mutability to compare sample windows (and analysis) against previous values.
Required methods
fn is_beat(&self, samples: &[i16]) -> Option<BeatInfo>
[src]
Expand description
Checks if inside the samples window a new beat was recognized.
If so, it returns Some
with BeatInfo
as payload.
Implementations may buffer previous samples and combine them with the latest, i.e. make a sliding window.
fn kind(&self) -> StrategyKind
[src]
Expand description
Convenient getter to get the StrategyKind
of a strategy.
This is a 1:1 mapping.
fn name() -> &'static str where
Self: Sized,
[src]
Self: Sized,
Expand description
A nice name for the algorithm, displayable in user interfaces.
fn description() -> &'static str where
Self: Sized,
[src]
Self: Sized,
Expand description
A textual description of the algorithm to help the user to select the right one.
fn min_duration_between_beats_ms() -> u32 where
Self: Sized,
[src]
Self: Sized,
Expand description
Duration in ms after each beat. Useful do prevent the same beat to be
detected as two beats. This is a constant per strategy, because more
advanced strategies can cope with small durations (50ms) whereas
“stupid”/basic strategies may need 400ms.
This is a function instead of an associated constant, because
otherwise the build fails with “Strategy
cannot be made into an object”
Provided methods
fn last_beat_beyond_threshold(&self, state: &AnalysisState) -> bool where
Self: Sized,
[src]
Self: Sized,
Expand description
Common implementation for all strategies which checks if the last beat is beyond the threshold. Of not, we can return early and do not need to check if a beat is in the given sample.
fn amplitude_high_enough(&self, w_stats: &WindowStats) -> bool
[src]
Expand description
Common implementation for all strategies which checks if the current windows/frames max amplitude (i16) is above a value where a beat could happen in theory (discard noise/silence/break between songs)