Skip to content

Commit

Permalink
Merge branch 'fix-LiquidSFZ-race'
Browse files Browse the repository at this point in the history
* Branch commit log:
  devices/liquidsfz/liquidsfz.cc: add TODO about unconditional event processing
	See also: #44 (comment)
  devices/liquidsfz/liquidsfz.cc: fix for LiquidSFZ race cond by Stefan Westerfeld, #44
	#44
	swesterfeld commented Jun 18, 2024:
	>
	> tim-janik commented Jun 18, 2024:
	> > all input events must always be processed in render
	>
	> I agree. At least the filename changes, midi events can safely be dropped while a file is being loaded.
	>
	> Your patch is not good, because it will introduce race conditions of both threads accessing the same data.
	> Since we cannot use locks due to RT constraints, I guess the real fix will be to use a lock-free queue to send events to the loader thread.
	> I'll look into it and come up with a real fix and submit a PR.
	> However, here is a quick fix that just avoids the initial load problem and is still safe as in it doesn't introduce race conditions

Signed-off-by: Tim Janik <[email protected]>
  • Loading branch information
tim-janik committed Jun 18, 2024
2 parents da20031 + b4ecaec commit 5f8b8ee
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion devices/liquidsfz/liquidsfz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class LiquidSFZLoader
{
if (state_.load() == STATE_IDLE)
{
if (want_sfz_ == have_sfz_ && want_sample_rate_ == have_sample_rate_)
if (want_sfz_ == have_sfz_ && (want_sample_rate_ == have_sample_rate_ || want_sfz_ == ""))
return true;
}
state_.store (STATE_LOAD);
Expand Down Expand Up @@ -173,6 +173,8 @@ class LiquidSFZ : public AudioProcessor {
void
render (uint n_frames) override
{
// TODO: rework the logic so midi_event_input(), and in particular MidiMessage::PARAM_VALUE are processed unconditionally
// See also: https://github.com/tim-janik/anklang/issues/44#issuecomment-2176839260
if (loader_.idle())
{
if (synth_need_reset_)
Expand Down

0 comments on commit 5f8b8ee

Please sign in to comment.