Author Topic: soundfont questions  (Read 2567 times)


  • Posts: 1
soundfont questions
« on: 19 Mar '18 - 02:50 »
Hi, new member here looking for some insights on creating soundfonts and using them on-the-fly.

I need to write a program that, from a distance, looks like it could be implemented as a MIDI app using a custom soundfont file. The thing is, each time it runs, it needs to generate a new soundfont file and then use it.

Here's an analogy: Imagine a library with 1000s of sound samples. Each time this program is run, it grabs 100 of them somewhat randomly, downloads them, and builds the soundfont file from that collection. When it's done, it doesn't need to preserve the foundfont file or the samples, and they're deleted. This is by design.

What needs to be done is to gather these samples as they're downloaded and stuff them into a soundfont file, mapping them to separate MIDI controller notes. (They're not musical, they're more similar to percussion hits, like sticks, bells, gongs, etc.) This needs to be done by software, not a visual app. The program will be doing the playing later, not someone at a keyboard, so the mappings are irrelevant as long as they work.

Then the program will "compose" several tracks by creating a MIDI score where these samples are played in some order. Actually, there will be several of these, like "scenes", that need to be composed separately, and then played in sequence.

All of this is happening while a pre-recorded audio file is playing for a few minutes. When it finishes, I need to start playing this MIDI score.

The intended result is that the user is listening to it all in real-time, rather than recording it to disk for posterity; however, if it makes more sense to save an audio rendering to disk and THEN playing that, I'm open to that approach as well. (Any opinions as to which approach is better are quite welcome.)

I have a general understanding of MIDI, and what I know is that most notes are short but can be extended by holding down the keys or a sustain pedal.

But if you create your own soundfont, can you create "notes" that go on for several seconds naturally, that play with a simple trigger and ignore sustain?

I'm thinking of something like, say, a gong strike or Tibetan bowl that you want to play until it's pretty much inaudible. No sound efx, no modulators, no sustain, no nothing. Just a really long "note" that has its own natural decay curve that can last for 20-30 seconds or more. Does it work to put sounds like this into a soundfont and trigger them to play? If so, if you add another note after that in the MIDI sequence, will it begin playing when the long one before it finally stops?

(I imagine that if they're in separate tracks, then they can overlap, right? So a long gong or bowl could have a flute, drums, rattles, or other bowls in another track that play over it, no?)

If I'm making sense and this seems doable, does anybody know of any Delphi code I could get hold of to read and write soundfont (.sf2) files, and something that would let me build simple compositions to test them out (programmatically, not using a keyboard of any kind)? 

I'm prototyping this in Windows, but it ultimately needs to work in iOS and Android as well.



  • Posts: 2565
Re: soundfont questions
« Reply #1 on: 21 Mar '18 - 21:21 »
It seems like soundfonts would seem an unnecessary layer on top of what you want to achieve, but it's certainly doable that way.
If you were going with BASSMIDI (assuming you plan to do this as you are posting on the BASS forum), it might make sense to use SFZ files rather than SF2 soundfonts though, because they can be generated more easily (it's essentially just a text file that points at one or more WAV/FLAC/etc. sample files).
In either case, how instruments behaves is defined using ADSR envelopes, so whether a note will sound short or long entirely depends on how you define your SFZ or SF2 instrument's volume envelope. If required, your sample can be configured to never stop playing. Existing notes are typically not stopped when a new one starts playing (but of course you can place a note-off event in your MIDI data to make it do that), although an exception may be drum programs, where triggering the same (or a related) drum key twice will stop the previously playing sample of the same key. As an example, triggering an open hi-hat and then instantly triggering a closed hi-hat is configured to stop the open hi-hat sound in most soundfonts.
I'd definitely recommend getting familiar with the SFZ format, rather than SF2.