TinySoundFont icon indicating copy to clipboard operation
TinySoundFont copied to clipboard

Kill off voices in release segment when at max voices

Open ell1e opened this issue 4 years ago • 1 comments
trafficstars

~~(I recommend merging #67 first, I will then fix the inevitable conflict in this one)~~

This pull request adds code that when tsf_note_on() hits maxVoiceNum will kill off the one voice playing that is 1. currently in its release envelope segment 2. furthest along into that segment sample wise. If no playing voice is in its release segment, it falls back to rejecting the new note on as before.

Without this patch, using my choice of complex test songs and soundfont I had bad playback with 128 still insufficient max voices before (missing notes). Applying this patch, 32 voices works after with even the busiest songs sounding fine with close to no noticeable artifacts. I tried picking any random voice anywhere in its release segment to kill at first, and that led to quite a lot of clicking artifacts at 96 already, so the furthest into release scoring appears to be worth it.

I am proposing this change mostly for performance reasons. I noticed setting max voices causes many functions in TSF to always loop the entire array of possible voices for every processed render slice. So hopefully this should help on constrained platforms.

ell1e avatar Nov 15 '21 03:11 ell1e

For what it's worth, I resolved the conflicts and have been running this patch for a few days in testing. It seems to work fine and I love the results, happy to hear from others trying it. I imagine particularly on embedded a test would be interesting.

ell1e avatar Nov 25 '21 08:11 ell1e

Upvote

yishengjiang99 avatar Apr 26 '23 06:04 yishengjiang99

Actually listening to a MIDI with low max voices with and without this patch makes it seem crazy I didn't get around to merge this sooner.

Sorry for ignoring this for so long! It's a really great addition, thank you very much!

schellingb avatar Sep 13 '23 17:09 schellingb

No problem! I'm very happy to see it found its way in, and yes it does seem to help a lot in more restrictive environments. I'm glad now everyone gets to benefit from it, and not just my local patched version.

ell1e avatar Sep 13 '23 17:09 ell1e