Skip to main content

audio_to_midi

Function audio_to_midi 

Source
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 (typical 0.10..0.20).
  • ref_a4_hz: reference tuning for A4 (default 440.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 least n_frames = (samples.len() − frame_size) / hop_size + 1 floats.
  • yin_scratch: YIN difference/CMND work buffer (see yin_pitch).
  • out: caller-owned destination for the note events.

Returns the number of notes written into out.

§Errors