schellingb / TinySoundFont

SoundFont2 synthesizer library in a single C/C++ file
MIT License
608 stars 71 forks source link

MIDI latency #76

Open tuia23 opened 1 year ago

tuia23 commented 1 year ago

The TSF library is working really well. However, I notice a significant latency between the note command and the note actually playing. In other MIDI libraries, this issue could be solved by simply reducing the size of a buffer, but I don't find this option in TSF. What could I do to reduce the latency?

ell1e commented 1 year ago

How exactly are you using it? Basically, if you tsf_render_... too much in advance (can be both too much in terms of buffer size, and in terms of time when you let it sit for too long before you move your render result into whatever audio library you're using for actual output) then you'll get latency. Also, I think lowering TSF_RENDER_EFFECTSAMPLEBLOCK and TSF_RENDER_SHORTBUFFERBLOCK could help but I could be wrong, these default to 64 and 512 and the latter needs to be a multiple of the former. (You can define these to new values before including the tsf headers, and that should override it then.) Maybe some of that helps you figure out what is going on?