Low FPS causes inaccurate playing

Issue #68 resolved
Somni created an issue

By setting target_fps or force_fps to 30 or below, the MIDI player becomes increasingly inaccurate in when it plays notes, as notes get locked to the frame. For example, at 20FPS, notes are tied to one of the 20 frames, which is sometimes off by a lot.

I assume it’s related to https://bitbucket.org/arlez80/godot-midi-player/issues/51/timebase-1ms and the fixes introduced there to get notes to be more accurate, and I assume it’s the limitations of Godot at the moment which make it hard to get things timed properly. It seems that adjusting how frequently _sequence is called doesn’t help the problem at all.

If I had to guess, the amount of silence added to the front of audio samples to get them to line up correctly would need to be increased, so that there’s a larger gap available to line them up. However, I’m not sure if this is possible, and I haven’t had any luck in my own attempts.

Comments (6)

  1. Somni reporter

    An addendum: I found a way to control the rendering rate separately from the processing rate, so running the MIDI player at high frequencies without incurring a rendering cost isn’t a problem anymore.

    For anyone curious:

    var acc_delta: float
    const UPDATE_FREQ := 1.0 / 30.0
    func _process(delta: float) -> void:
        acc_delta += delta
        var root = get_tree().root
        if acc_delta > UPDATE_FREQ:
            root.render_target_update_mode = Viewport.UPDATE_ALWAYS
            acc_delta -= UPDATE_FREQ
        else:
            root.render_target_update_mode = Viewport.UPDATE_DISABLED
    

    That said, I believe the root of this issue also produces discrepancies even when the game is running at 60FPS.

  2. Somni reporter

    Just tested it; sounds great, even at low FPS. Thank you.

    It produces this error:

    E 0:00:01.677   wait_to_finish: Thread must have been started to wait for its completion.<C++ Error>   Condition "!is_active()" is true. Returned: Variant()<C++ Source>  core/bind/core_bind.cpp:2725 @ wait_to_finish()<Stack Trace> MidiPlayer.gd:602 @ _process()
    

  3. Log in to comment