Swiftpack.co - bradhowes/SF2Lib as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by bradhowes.
bradhowes/SF2Lib 2.2.0
SF2 parsing and rendering library in C++
⭐️ 0
🕓 6 weeks ago
iOS macOS tvOS
.package(url: "https://github.com/bradhowes/SF2Lib.git", from: "2.2.0")

CI COV License: MIT

SF2Lib - an SF2 library in C++ (mostly)

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 .mm suffix 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.

SF2 Spec Support

Currently, all SF2 generators and modulators are supported and/or implemented, except for the following:

  • chorusEffectSend -- how much of a rendered sample is sent to a chorus effect audio channel (L+R)
  • reverbEffectSend -- how much of a rendered sample is sent to a reverb effect audio channel (L+R)

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 chorusEffectSend and 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.

Code

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.

  • Resources -- contains a Configuration.plist file that sets some configury options.

Credits

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.

GitHub

link
Stars: 0
Last commit: 6 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Canard-Duchêne
6 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics