schellingb / TinySoundFont

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

add sf3 support #75

Closed misterhat closed 1 year ago

misterhat commented 1 year ago

checks for the existence of the stb_vorbis header definition before checking the first shdr sample for the "OggS" header, then decompresses them all into the fontSamples buffer. sf3 provides significantly smaller sizes even if vorbis is outclassed by newer codecs like opus (OPL compresses from 128 megabytes into 17 with the default settings).

utilize sftools to convert .sf2 into .sf3.

misterhat commented 1 year ago

this pull request is related to https://github.com/schellingb/TinySoundFont/issues/71#issuecomment-983655354

schellingb commented 1 year ago

Hi there!

Thanks for this PR, as I mentioned in #71 this is the most interesting improvement over SF2 for me and I'm glad we have support for it in TSF now. I merged your PR but reworked it a bit in d21fe7b.

Most important was to avoid relying on C99 exclusive variable-length array support as well as avoiding having to allocate twice when loading regular SF2 files. I also switched from stb_vorbis_decode_memory to use either pull or push API that decodes directly to floats to avoid triple conversion and reduced the number of memory allocations required.

I tested this now on a few compilers and ran it through some more on godbolt and it looks good to me. I'd happily get feedback if things work with these changes for you as well.

Thanks again and cheers!