# SFZero sound font player, now available as Juce module

**URL:** <https://forum.juce.com/t/sfzero-sound-font-player-now-available-as-juce-module/17018>\
**Category:** Useful Tools and Components\
**Created:** [March 26, 2016, 12:28pm UTC](https://forum.juce.com/t/sfzero-sound-font-player-now-available-as-juce-module/17018 "2016-03-26T12:28:07Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![mucoder](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mucoder/32/595_2.png) [@mucoder](https://forum.juce.com/u/mucoder)\
**Post date:** [March 26, 2016, 12:28pm UTC](https://forum.juce.com/t/sfzero-sound-font-player-now-available-as-juce-module/17018/1 "2016-03-26T12:28:07Z")

</div>

If your projects could&nbsp;use&nbsp;a&nbsp;Juce synth that can play SF2 and SFZ soundfonts, this might interest you.

I have taken the liberty to update Steve Folta's great&nbsp;SFZero&nbsp;player&nbsp;a little and convert it to a Juce module. &nbsp;So it's now dead easy to use it from within your code.

The source code&nbsp;can be found here:&nbsp;https://github.com/altalogix/SFZero. &nbsp;It's MIT/BSD-style licensed - as was the original.

And I wrote a little blog article about it as well :&nbsp;http://www.mucoder.net/blog/2016/03/24/sfzero.html

Have fun  
Leo

(posted&nbsp;earlier at Audio Plugins&nbsp;board - but this is a better place)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 29, 2016, 8:09am UTC](https://forum.juce.com/t/sfzero-sound-font-player-now-available-as-juce-module/17018/2 "2016-03-29T08:09:23Z")

</div>

Cool stuff :)

---

<div class="post-metadata">

**Author:** ![olilarkin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/olilarkin/32/7142_2.png) [@olilarkin](https://forum.juce.com/u/olilarkin)\
**Post date:** [April 2, 2016, 12:02pm UTC](https://forum.juce.com/t/sfzero-sound-font-player-now-available-as-juce-module/17018/3 "2016-04-02T12:02:23Z")

</div>

could you separate the juce module and the example, so that it can be easily included in a project as a git submodule?

---

<div class="post-metadata">

**Author:** ![mucoder](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mucoder/32/595_2.png) [@mucoder](https://forum.juce.com/u/mucoder)\
**Post date:** [April 10, 2016, 9:24pm UTC](https://forum.juce.com/t/sfzero-sound-font-player-now-available-as-juce-module/17018/4 "2016-04-10T21:24:59Z")

</div>

makes sense. Will look into it

---

<div class="post-metadata">

**Author:** ![tsenkov](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/tsenkov/32/3150_2.png) [@tsenkov](https://forum.juce.com/u/tsenkov)\
**Post date:** [April 26, 2016, 7:38am UTC](https://forum.juce.com/t/sfzero-sound-font-player-now-available-as-juce-module/17018/5 "2016-04-26T07:38:06Z")

</div>

Thanks! This is very useful! I’ve looked in the original version and was discouraged to try and update it to latest once I saw it used a very old version of JUCE.

Few things I had to fix before running on latest (4.2.1) JUCE:

Probably this changed with the latest version, and now the common includes (SFZCommon.h) need to look like this:

```
#include <juce_audio_basics/juce_audio_basics.h>
#include <juce_audio_formats/juce_audio_formats.h>
#include <juce_audio_processors/juce_audio_processors.h>
#include <juce_gui_basics/juce_gui_basics.h>

```

Every project pointed to a VST 3 SDK specific for your FS.

My SFZ instrument is based on .FLAC, so I had to change this in the example:

```
sfzero::SFZeroAudioProcessor::SFZeroAudioProcessor() : loadProgress(0.0), loadThread(this)
{
  formatManager.registerBasicFormats();
  // instead of:
  // formatManager.registerFormat(new WavAudioFormat(), false);
  // formatManager.registerFormat(new OggVorbisAudioFormat(), false);

  // ...
}

```

Cheers!

---

<div class="post-metadata">

**Author:** ![mucoder](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mucoder/32/595_2.png) [@mucoder](https://forum.juce.com/u/mucoder)\
**Post date:** [April 26, 2016, 12:25pm UTC](https://forum.juce.com/t/sfzero-sound-font-player-now-available-as-juce-module/17018/6 "2016-04-26T12:25:26Z")

</div>

good catch tsenkov, I’ve added your changes to the repo. Works with juce 4.1 here as well.

as to the VST SDK, that’s difficult to fix as this is a global Projucer setting. It’s always best to load and save the .jucer project file once in order to regen the build scripts with your own preferences

thanks  
Leo

---

<div class="post-metadata">

**Author:** ![mucoder](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mucoder/32/595_2.png) [@mucoder](https://forum.juce.com/u/mucoder)\
**Post date:** [April 26, 2016, 1:29pm UTC](https://forum.juce.com/t/sfzero-sound-font-player-now-available-as-juce-module/17018/7 "2016-04-26T13:29:44Z")

</div>

hey Oli, I’ve now separated out the module into a submodule at

> **[altalogix/SFZeroModule](https://github.com/altalogix/SFZeroModule)**
>
> SFZeroModule - just the Juce module part of SFZero, not the sample plugin

can you have a look if it works for you this way?

---

<div class="post-metadata">

**Author:** ![mucoder](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mucoder/32/595_2.png) [@mucoder](https://forum.juce.com/u/mucoder)\
**Post date:** [April 29, 2016, 12:27pm UTC](https://forum.juce.com/t/sfzero-sound-font-player-now-available-as-juce-module/17018/9 "2016-04-29T12:27:05Z")

</div>

ah, yes. Unfortunately the SFZero repo was already in use as the parent repo - so I had to pick another name.  
Would it be helpful to rename SFZero.h to SFZeroModule.h instead?

---

<div class="post-metadata">

**Author:** ![olilarkin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/olilarkin/32/7142_2.png) [@olilarkin](https://forum.juce.com/u/olilarkin)\
**Post date:** [April 29, 2016, 12:33pm UTC](https://forum.juce.com/t/sfzero-sound-font-player-now-available-as-juce-module/17018/10 "2016-04-29T12:33:15Z")

</div>

could do. I have called my juce modules juce\_modulename to match what Jules does

---

<div class="post-metadata">

**Author:** ![mashu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mashu/32/579_2.png) [@mashu](https://forum.juce.com/u/mashu)\
**Post date:** [May 31, 2016, 8:01am UTC](https://forum.juce.com/t/sfzero-sound-font-player-now-available-as-juce-module/17018/11 "2016-05-31T08:01:33Z")

</div>

Hi Leo,

i would like to include your SFZero module as a sound source for my plugin, but i’m not getting too far with it.

can you (or somebody) please outline the basic steps to use this in inside an AudioProcessor?

edit: ahhh, don’t worry, i think i can see now. Read the blog post, has helped…will post again if i get stuck

edit2: woohoo! got it working! was way easier than i expected! thanks so much Leo!

---

<div class="post-metadata">

**Author:** ![adamwilson](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/adamwilson/32/1387_2.png) [@adamwilson](https://forum.juce.com/u/adamwilson)\
**Post date:** [May 31, 2016, 12:14pm UTC](https://forum.juce.com/t/sfzero-sound-font-player-now-available-as-juce-module/17018/12 "2016-05-31T12:14:19Z")

</div>

I think a better format is vendor\_module name or just modulename - I see juce\_ as a prefix for Juce internal modules.

---

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [August 15, 2018, 7:00pm UTC](https://forum.juce.com/t/sfzero-sound-font-player-now-available-as-juce-module/17018/13 "2018-08-15T19:00:45Z")

</div>

I’m getting a leak whenever I quit my project in `sfzero::Sample`. I’m using it like this:

```auto
SynthAudioSource::SynthAudioSource(MidiKeyboardState& state) : keyboardState(state)
{
    midiCollector.reset(44100);
    for( int i = 0; i < 16; ++i)
    {
        synth.addVoice( new sfzero::Voice() );
    }
    
    AudioFormatManager formatManager;
    formatManager.registerBasicFormats();
    
    auto sf2File = File::getSpecialLocation( File::SpecialLocationType::currentApplicationFile).getChildFile("Contents").getChildFile("Resources").getChildFile("TimGM6mb.sf2");
    auto* sound = new sfzero::SF2Sound( sf2File );
    sound->loadRegions();
    sound->loadSamples(&formatManager);
    sound->useSubsound(4); //E.Piano 1
    
    synth.clearSounds();
    synth.addSound( sound );
}

SynthAudioSource::~SynthAudioSource()
{
    synth.clearSounds();
    synth.clearVoices();
}

```

any ideas what is causing `sfzero::Sample` to leak?

```auto
*** Leaked objects detected: 8 instance(s) of class sfzero::Sample

```

---

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [August 15, 2018, 9:36pm UTC](https://forum.juce.com/t/sfzero-sound-font-player-now-available-as-juce-module/17018/14 "2018-08-15T21:36:20Z")

</div>

I’m going through the codebase, and see a lot of things like this:

```auto
class Sample
{
// snip
    virtual ~Sample();
private:
    juce::AudioSampleBuffer* buffer_;
};

sfzero::Sample::~Sample()
{
    delete buffer_;
}

```

that is pretty hard to look at in 2018. Is there any particular reason this module isn’t doing things like this:

```auto
private:
    juce::ScopedPointer<juce::AudioSampleBuffer> buffer_;

```

that handles all of the automatic deletion, and functions like this are immediately much simpler:

```auto
juce::AudioSampleBuffer *sfzero::Sample::detachBuffer()
{
    /*
    juce::AudioSampleBuffer *result = buffer_;
    buffer_ = nullptr;
    return result;
     */
    return buffer_.release();
}

```

---

<div class="post-metadata">

**Author:** ![adamwilson](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/adamwilson/32/1387_2.png) [@adamwilson](https://forum.juce.com/u/adamwilson)\
**Post date:** [August 16, 2018, 11:15am UTC](https://forum.juce.com/t/sfzero-sound-font-player-now-available-as-juce-module/17018/15 "2018-08-16T11:15:40Z")

</div>

Looks like it could do with some updating to use smart pointers…

---

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [August 17, 2018, 9:31am UTC](https://forum.juce.com/t/sfzero-sound-font-player-now-available-as-juce-module/17018/16 "2018-08-17T09:31:52Z")

</div>

Already done: [https://github.com/matkatmusic/SFZeroModule/tree/JUCECleanup](https://github.com/matkatmusic/SFZeroModule/tree/JUCECleanup)
