This library can read SF2 SoundFont files and render audio samples from them. It properly reads in a compliant SF2 file and can be used to obtain meta data such as preset names. It also has an audio rendering engine that can generate audio samples for key events that come from (say) a MIDI keyboard. Work on the rendering side is still on-going, but at present it can generate audio at the right pitch. This library is currently being used by my SoundFonts application for SF2 file parsing, and soon for rendering.
Although much of the code is generic C++17, there are bits that expect an Apple platform that has
the AudioToolbox and Accelerate frameworks available. As such, there are some code files that have the
so that they compile as Obj-C++ instead of C++. However, such cases are fairly isolated. The goal is to be a
simple library for reading SF2 files as well as a competent SF2 audio renderer whose output can be fed to any sort of
audio processing chain, not just macOS and iOS systems Core Audio systems. For my own use, this will be used in AUv3
components on iOS and macOS platforms.
This package depends on some general DSP and audio class from my AUv3Support package.
Currently, all SF2 generators and modulators are supported and/or implemented, except for the following:
Since there are plenty of chorus and reverb effects available, this library will not have any of its own. Rather the
goal will be to make available the effect send busses for other AUv3 nodes to process as they wish. This is the case
now: the render Engine
renderInto method takes a
Mixer instance which supports a main "dry" bus and two busses
for the "chorus effect send" and a "reverb effect send". These are populated with samples from active voices,
and their levels are controlled by the
reverbEffectSend parameters mentioned above. One
can then connect bus 1 to a chorus effect and bus 2 to reverb, and then connect those outputs and bus 0 of this
library to a mixer to generate the final output.
Here is a rough description of the top-level folders in SF2Lib:
DSP -- various utility functions for signal processing and converting values from one unit to
another. Some of these conversion rely on tables generated by the
DSPTableGenerator tool mentioned above.
Entity -- representations of entities defined in the SF2 spec. Provides for fast loading of SF2 files.
include -- headers for the library. Note that the library exists mostly in header files with very little to be found in source files.
IO -- performs the reading and loading of SF2 files.
MIDI -- state for a MIDI connection.
Render -- handles rendering of audio samples from SF2 entities.
All of the code has been written by myself over the course of several years, but I have benefitted from the existence of other projects, especially FluidSynth and their wealth of knowledge in all things SF2. In particular, if there is any confusion about what the SF2 spec means, I rely on their interpretation in code. That said, any misrepresentations of SF2 functionality are of my own doing.
There are a collection of routines in ConstMath that provide compile-time values for
sine, natural log, and exponential function. These are used to generate the lookup tables for MIDI controller value mapping and panning.
The functions that do this were taken from Lakshay Garg's compile_time (no specific liceense) repo
and Keith O'Hara's GCEM (Apache license) repo. I started off with
compile_time but I lifted the natural log function from
GCEM. Note that the use of these compile-time methods are only for a very limited set of use-cases, all of which are not that
demanding in terms of precision. This is SF2 after all.