Trait Backend
pub trait Backend: Send + Sync {
// Required method
fn predict_window(&self, window: &[f32]) -> Result<Posteriorgrams, Error>;
}Expand description
An engine able to run the Basic Pitch network on one window of audio.
Implementations must be deterministic and process exactly one window per call (batch size 1): batching windows changes the outputs of ONNX Runtime by about 1e-5, which is enough to move a note across a threshold.
use basic_pitch::model::Backend;
use basic_pitch::{Posteriorgram, Posteriorgrams, Result};
/// A backend that hears nothing, handy in tests.
struct Deaf;
impl Backend for Deaf {
fn predict_window(&self, _window: &[f32]) -> Result<Posteriorgrams> {
Posteriorgrams::new(
Posteriorgram::zeros(172, 88),
Posteriorgram::zeros(172, 88),
Posteriorgram::zeros(172, 264),
)
}
}
let raw = basic_pitch::model::run_windows(&Deaf, &[0.0; 50_000])?;
assert_eq!(raw.n_frames(), 2 * 172);Required Methods§
fn predict_window(&self, window: &[f32]) -> Result<Posteriorgrams, Error>
fn predict_window(&self, window: &[f32]) -> Result<Posteriorgrams, Error>
Runs the network on one window of [AUDIO_N_SAMPLES] samples.
Returns 172 frames of note (88 bins), onset (88 bins) and contour (264 bins) activations.
§Errors
[Error::WindowLength] if window has the wrong length, and
[Error::Backend] if the engine fails.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".