From b91639f6619e1c6a1f13294d2e5680cd37e56262 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Sun, 1 Sep 2024 20:43:01 +0200 Subject: [PATCH] Fluidsynth: Exhaust the internal synth buffer to prevent playing of old samples after long pauses Fix #3135 (this time for real) --- src/decoder_fluidsynth.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/decoder_fluidsynth.cpp b/src/decoder_fluidsynth.cpp index f171ff7d2f..5b048feb04 100644 --- a/src/decoder_fluidsynth.cpp +++ b/src/decoder_fluidsynth.cpp @@ -214,7 +214,12 @@ FluidSynthDecoder::~FluidSynthDecoder() { --instances; assert(instances >= 0); - if (!use_global_synth) { + if (use_global_synth) { + // Exhaust the internal synth buffer + // Prevents that old samples play when a new Midi song starts (even when there was a longer break between them) + std::array buffer; + fluid_synth_write_s16(global_synth.get(), buffer.size() / 4, buffer.data(), 0, 2, buffer.data(), 1, 2); + } else { delete_fluid_synth(local_synth); } }