spotify / basic-pitch

A lightweight yet powerful audio-to-MIDI converter with pitch bend detection
https://basicpitch.io
Apache License 2.0
3.5k stars 275 forks source link

Misleading midi_tempo parameter in predict_and_save function #152

Open WangHaoyuuu opened 1 week ago

WangHaoyuuu commented 1 week ago

Hello,

First, thank you for the incredible work on this tool—it has been invaluable during my workflow. However, I’ve encountered a potential issue that I would like to bring to your attention.

Description of the Issue: The predict_and_save function includes a midi_tempo parameter, but it seems ineffective in controlling the playback speed of the generated MIDI file.

Current Behavior: Setting the midi_tempo parameter (e.g., to 120 BPM) does not appear to adjust the playback speed as expected. The generated MIDI file retains the original timing of the audio via time-value compensation. As a result, the midi_tempo setting does not influence the playback speed.

Concerns: This behavior might be confusing for users who expect the midi_tempo parameter to directly control playback speed. The presence of the parameter suggests that it should perform this function, but it currently does not. Additionally, there does not seem to be any documentation clarifying this limitation.

Code Context

Upon reviewing the relevant section of the code, it seems that the start_time and end_time values are calculated based on the original timing of the input, independent of the midi_tempo setting:

for start_time, end_time, note_number, amplitude, pitch_bend in note_events_with_pitch_bends:
    instrument = instruments[note_number] if multiple_pitch_bends else instruments[0]
    note = pretty_midi.Note(
        velocity=int(np.round(127 * amplitude)),
        pitch=note_number,
        start=start_time,  # Original time
        end=end_time,      # Original time
    )

I hope this feedback is helpful and would be happy to provide further details if needed. Thank you again for your excellent work!

Best regards, Haoyu Wang