FluidSynth / fluidsynth

Software synthesizer based on the SoundFont 2 specifications

Home Page:https://www.fluidsynth.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

incorrect tempo change handling

derselbst opened this issue · comments

Having a lot of tempo changes throws fluidsynth off-timing somewhy (compared to timidity and audacity midi parsing).

Attached file is one case where it happens. file1.midi has repeated tempo change tags that all change it to the exact same value. file2.midi has just the first of them. Effectively, they should be synthesized to the same audio, but in practice file1 is longer.

Reported by: velochy

Original Ticket: fluidsynth/tickets/143

Here's the problem:

player->cur_ticks = (player->start_ticks
+ (int) ((double) (player->cur_msec - player->start_msec)
/ player->deltatime));

It does a floating point calculation of the time diff between now and the last tempo change event. The result is then casted to int, every such cast results in an error. For file1.mid start_msec gets updated frequently and the error seems to increase, as start_msec is nearly the same as cur_msec.

Currently dont know how to fix this properly.

For 1.1.7 the time diff after about 1.5 minutes of playback is about 0.15 seconds between the two files. For 1.1.6 the diff was 0.26 seconds. I dont think we can get it any better without rewriting fluid_player and I dont see this to happen soon. Closing for now.

Here are the test files for later reference.
testfiles.zip