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

Don't stop playing until zero voices are active and reverb has a chance to fade out #1159

Merged
merged 1 commit into from
Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions src/midi/fluid_midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,7 @@ new_fluid_player(fluid_synth_t *synth)
player->deltatime = 4.0;
player->cur_msec = 0;
player->cur_ticks = 0;
player->end_msec = -1;
player->last_callback_ticks = -1;
fluid_atomic_int_set(&player->seek_ticks, -1);
fluid_player_set_playback_callback(player, fluid_synth_handle_midi_event, synth);
Expand Down Expand Up @@ -2177,6 +2178,23 @@ fluid_player_callback(void *data, unsigned int msec)
fluid_atomic_int_set(&player->seek_ticks, -1); /* clear seek_ticks */
}

/* 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)
{
status = FLUID_PLAYER_PLAYING;
}

/* Once no voices are active, if end_msec hasn't been scheduled, schedule it */
if(status == FLUID_PLAYER_DONE && player->end_msec < 0)
{
player->end_msec = msec + FLUID_PLAYER_STOP_GRACE_MS;
}
/* If end_msec has been scheduled and is in the future, keep playing */
if (player->end_msec >= 0 && msec < (unsigned int) player->end_msec)
{
status = FLUID_PLAYER_PLAYING;
}

if(status == FLUID_PLAYER_DONE)
{
FLUID_LOG(FLUID_DBG, "%s: %d: Duration=%.3f sec", __FILE__,
Expand Down Expand Up @@ -2225,12 +2243,14 @@ fluid_player_play(fluid_player_t *player)
fluid_sample_timer_reset(player->synth, player->sample_timer);
}

/* If we're at the end of the playlist and there are no loops left, loop once */
if(player->currentfile == NULL && player->loop == 0)
{
player->loop = 1;
}

/* If we're at the end of the playlist and there are no loops left, loop once */
if(player->currentfile == NULL && player->loop == 0)
{
player->loop = 1;
}

player->end_msec = -1;

fluid_atomic_int_set(&player->status, FLUID_PLAYER_PLAYING);

return FLUID_OK;
Expand Down
3 changes: 3 additions & 0 deletions src/midi/fluid_midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ struct _fluid_player_t
int begin_msec; /* the time (msec) of the beginning of the file */
int start_msec; /* the start time of the last tempo change */
int cur_msec; /* the current time */
int end_msec; /* when >=0, playback is extended until this time (for, e.g., reverb) */
/* sync mode: indicates the tempo mode the player is driven by (see fluid_player_set_tempo()):
1, the player is driven by internal tempo (miditempo). This is the default.
0, the player is driven by external tempo (exttempo)
Expand All @@ -330,6 +331,8 @@ struct _fluid_player_t
int channel_isplaying[MAX_NUMBER_OF_CHANNELS]; /* flags indicating channels on which notes have played */
};

#define FLUID_PLAYER_STOP_GRACE_MS 2000

void fluid_player_settings(fluid_settings_t *settings);


Expand Down