Audible click when stopping oldest sound

Thanks for the info. The volume scaling is exactly what I thought about and tried. It did kinda help, but it basically only lessens the click and unfortunately it isn’t a real solution. Is there maybe a different workaround please? No problem if it involves tweaking the code a bit too.