Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendered MIDI file's audio export files are too long #1408

Open
ReinholdH opened this issue Oct 14, 2024 · 4 comments
Open

Rendered MIDI file's audio export files are too long #1408

ReinholdH opened this issue Oct 14, 2024 · 4 comments
Labels

Comments

@ReinholdH
Copy link

FluidSynth version

fluidsynth 2.3.1 and higher

Describe the bug

Rendered MIDI file's audio export files are too long

Expected behavior

This is a regression which came in with fluidsynth 2.3.1. The MIDI file Dance.mid is 1:36 long. But with fuidsynth 2.3.1 onwards an audio export file is 2:05 long. Between 1:36 and 2:05 there is silence.
At a first glance my gut feeling tells me that the regression came in with #1159 in fluidsynth 2.3.1 but I need to further investigate.

Steps to reproduce

Render the file Dance.mid from here into a wav file. Listen the exported wav files "dance - 16bit.wav" and "dance - 32bit.flac" from here

Additional context

Between 1:36 and 2:05 there is silence. In previous fluidsynth versions before 2.3.1, the exported wav files have the correct duration. The demos were created by es20490446e as part of #1405

@ReinholdH ReinholdH added the bug label Oct 14, 2024
@ReinholdH
Copy link
Author

Yes, the culprit is #1159.

Extending the playing in fluid_midi.c by (Code snippet from fluid_midi.c of fluidsynth 2.3.1)

    /* Once we've run out of MIDI events, keep playing until no voices are active */
    if(status == FLUID_PLAYER_DONE && fluid_synth_get_active_voice_count(player->synth) > 0)
    {
        /* The first time we notice we've run out of MIDI events but there are still active voices, disable all hold pedals */
        if(!player->end_pedals_disabled)
        {
            for(i = 0; i < synth->midi_channels; i++)
            {
                fluid_synth_cc(player->synth, i, SUSTAIN_SWITCH, 0);
                fluid_synth_cc(player->synth, i, SOSTENUTO_SWITCH, 0);
            }

            player->end_pedals_disabled = 1;
        }

        status = FLUID_PLAYER_PLAYING;
    }

causes the problem. Since 2.3.1 there have been further changes in this area which need to be validated.

The demo MIDI file Dance.mid is not only causing the problem. I tested other MIDI files, too. For all the tested MIDI files the duration is not properly determined. Some are 12 seconds longer, some 18 seconds, some even 1/2 minute like Dance.mid.
I come to the conclusion that this solution here is not appropriate. This regression bug is a showstopper for us.

@ReinholdH
Copy link
Author

For the MIDI file Dance.mid I did a deep dive in fluid_player_callback. Here are my findings:

At FLUID_PLAYER_DONE: msec = 94000 = 1:34 which is the correct end of the MIDI file
At no voices active: msec = 123251 = 2:03
Final end: 2:03 + FLUID_PLAYER_STOP_GRACE_MS = 2:05 what we see as the duration of the audio export.

Looks like that the criteria "no voices active" isn't the right criteria to keep player running. My 2 cents...

@ReinholdH
Copy link
Author

For completeness because the link above to download the MIDI file Dance.mid is off-line meanwhile. Dance.mid can be downloaded as part of the GeneralUse GS 2.0.0 package from here.

@ReinholdH
Copy link
Author

The issue is a general fluidsynth MIDI Player one not only relevant for file export. The basic MIDI Player from here (w/o reverb and chorus) plays for 2:05 long and not for 1:36. File rendering for audio export just makes the bug obvious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant