pub fn audio_to_midi(
samples: &[f32],
sample_rate: f32,
frame_size: usize,
hop_size: usize,
min_hz: f32,
max_hz: f32,
yin_threshold: f32,
ref_a4_hz: f32,
min_note_frames: usize,
f0_scratch: &mut [f32],
conf_scratch: &mut [f32],
yin_scratch: &mut [f32],
out: &mut [NoteEvent],
) -> Result<usize, AudioError>Expand description
Transcribe a mono samples buffer into MIDI note events.
samples: mono PCM in[-1, 1].sample_rate: sampling rate in Hz (> 0).frame_size: analysis window length in samples (≥ 8).hop_size: advance between frame starts in samples (> 0).min_hz/max_hz: YIN fundamental search band (0 < min_hz < max_hz).yin_threshold: YIN absolute CMND threshold (typical0.10..0.20).ref_a4_hz: reference tuning for A4 (default440.0).min_note_frames: minimum note length in frames (short runs are dropped).f0_scratch/conf_scratch: per-frame track buffers; each must hold at leastn_frames = (samples.len() − frame_size) / hop_size + 1floats.yin_scratch: YIN difference/CMND work buffer (seeyin_pitch).out: caller-owned destination for the note events.
Returns the number of notes written into out.
§Errors
AudioError::InvalidParameterfor a non-positive rate/hop, aframe_size < 8, an inconsistent search band, or a signal shorter than one frame.AudioError::WorkspaceTooSmalliff0_scratch/conf_scratchcannot hold every frame.AudioError::OutputBufferTooSmallifoutcannot hold every note.- Any error propagated by
yin_pitch(e.g. a too-smallyin_scratch).