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

Fix player termination after stopping and restarting #1273

Merged
merged 1 commit into from
Sep 24, 2023

Conversation

albedozero
Copy link
Contributor

If using the sample timer, reset cur_msec=0 in fluid_player_play() since the sample timer is also reset. This way fluid_player_callback() will not misinterpret the player's cur_msec < msec as being due to a fluid_synth_get_ticks overflow.

If using the sample timer, reset cur_msec=0 in fluid_player_play() since the sample timer is also reset. This way fluid_player_callback() will not misinterpret the player's cur_msec < msec as being due to a fluid_synth_get_ticks overflow.
@sonarcloud
Copy link

sonarcloud bot commented Sep 3, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@albedozero
Copy link
Contributor Author

Fixes #1272 and perhaps #1270?

@albedozero
Copy link
Contributor Author

albedozero commented Sep 3, 2023

#1236 added a check that fluid_synth_get_ticks() has not overflowed by comparing the sample timer's msec provided to fluid_player_callback() to the cur_msec of the player. However, fluid_player_play() calls fluid_sample_timer_reset(), which resets the startticks of the timer. Before, this was fine because the player callback updates cur_msec on its own, but now we need to reset the player's cur_msec as well so it's not misinterpreted as a ticks overflow.

@albedozero albedozero marked this pull request as ready for review September 3, 2023 19:15
@albedozero albedozero changed the title fix player termination after stopping and restarting Fix player termination after stopping and restarting Sep 4, 2023
Copy link
Member

@derselbst derselbst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all, thanks for looking into this. However, I don't think this is correct. cur_msec is needed to process tempo change events correctly. We can't just reset it because the user has called e.g. fluid_player_stop(); fluid_player_play();. Yes, the fluid_player_callback restores cur_msec, but still I believe this could easily break something else that we currently don't see (we don't know because there is not a single test for the player).

I prefer a more conservative change here, which is to simply memorize the msec send by the synth in fluid_player_callback and compare against that accordingly.

#1270 doesn't use the player, so this is unrelated.

@albedozero
Copy link
Contributor Author

Sorry it's been a while for me to come back to this. I still think cur_msec is supposed to be the thing that memorizes the last msec sent by the synth - that's why it's set in fluid_player_callback(). cur_msec is used by fluid_player_update_tempo() to set the synth-time of the tempo change, but that is based on the assumption that fluid_player_callback() has kept it updated. cur_msec isn't used anywhere else.

If we are as of #1236 also going to use cur_msec as a flag to determine whether the sample timer has overflowed, we have to reset it if we reset the sample timer. A more conservative solution would be to add an unsigned int last_msec to fluid_player_t, reset that in fluid_player_play(), and use it to check for overflow in fluid_player_callback(). I can do that if you think it's safer.

@derselbst
Copy link
Member

A more conservative solution would be to add an unsigned int last_msec to fluid_player_t, reset that in fluid_player_play(), and use it to check for overflow in fluid_player_callback(). I can do that if you think it's safer.

Well, if you're sure that directly manipulating cur_msec is fine and doesn't break any other existing use-case, tell me and you can keep it. Otherwise, use last_msec.

I'm thinking of use-cases like seeking in the file with and without stopping / starting the player; manipulating the tempo via an external timesource and switching back to internal, etc.

Copy link
Member

@derselbst derselbst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed my opinion. I once again looked through the code, checked any side-effects but couldn't find one. It should work, just as you said. I'll take this now hoping to release 2.3.4 later today.

Excuse the confusion and thanks again!

@derselbst derselbst merged commit 377ab9d into FluidSynth:master Sep 24, 2023
46 of 55 checks passed
@albedozero
Copy link
Contributor Author

Thanks! I was confident it would work, but I was trying to find time to write a player test to prove it. I will hopefully do this for an upcoming commit.

DominusExult added a commit to DominusExult/fluidsynth-sans-glib that referenced this pull request Mar 6, 2024
* commit '683270db64302e59d26b9610514af1cfe0a80493':
  Bump to 2.3.5
  Fix libinstpatch and sndfile not being discovered on Windows (FluidSynth#1299)
  Update FreeBSD CI: Drop 12.4 and add 14.0
  Fix some rounding issues due to double promotion (FluidSynth#1286)
  Bump to 2.3.4
  Fix player termination after stopping and restarting (FluidSynth#1273)
  fix for issue FluidSynth#1268: Pipewire's Jack implementation not found (FluidSynth#1269)
  Fix issue with CMake Xcode generator (FluidSynth#1266)
  Refurbish CI (FluidSynth#1267)
  Fallback to IPv4 when creating socket if IPv6 is not available (FluidSynth#1208) (FluidSynth#1265)
  Turn off pending notes and issue a warning (FluidSynth#1264)
  Fix incorrect way of turning CMAKE_INSTALL_LIBDIR absolute (FluidSynth#1261)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants