Using the Sfizz SFZ Player-Sampler Library in Juce

The open source Sfizz SFZ player-sampler project refactored their code to make a standalone library. This move has created possibilities. The developer Cycling74 has recently added Sfizz to the Max product. The Sfizz code has a permissive license, not GPL.

https://cycling74.com/products/new-in-max/sfizz
https://docs.cycling74.com/max8/refpages/sfizz~

Has anyone figured out how to hook up the Sfizz library to Juce, such as with the example audio plugin project? I would like to use Sfizz with Juce for some experiments. I am not an audio programmer so i am having difficulty figuring out how to hook up the audio out from Sfizz to Juce. Sfizz implements things a different way than Juce.

Below is how Juce 7.x does things in PluginProcessor.cpp.

void processBlock (AudioBuffer& buffer, MidiBuffer& midiMessages)

Below is how Sfizz 1.2.3 does things in the API.

void sfizz_render_block (sfizz_synth_t* synth, float** channels, int num_channels, int num_frames)

Some general advice may be sufficient for me to work things out. Example code would be better. Below is informatiom on how to set up and use Sfizz.

Below is the Sfizz API.

https://sfz.tools/sfizz/api/

Below is the library download. The Mac and Windows versions come as a group of folders with header files, dll, lib, dylib, and other. The Windows download is missing the header files so copy them from the Mac download.

https://github.com/sfztools/sfizz/releases

Below is instruction on setting up the Sfizz library in Windows Visual Studio 2017/2019 project.

  • Place the header and lib files wherever you want;
  • Set the project target platform to x64 in solution > properties > configuration properties > (project) > platform;
  • Add the header files to project > configuration properties > c/c++ > general > additional include directories;
  • Add the lib folder to project > configuration properties > linker > general > additional library directories;
  • Add the lib files to project > configuration properties > linker > input > additional dependencies;
  • Place the dll in the main project folder where the debug/release file is created;
  • Include the header files in project code and start using the library;

Below is instruction on setting up the Sfizz library in Mac Xcode 11.3/14.2 project.

  • Place the header and dylib files wherever you want;
  • Add the header files to project > build settings > search paths > user header search paths;
  • Add the dylib files to project > build phases > link binary with libraries;
  • Include the header files in project code and start using the library;
  • To silence the Xcode comment warnings, wrap the Sfizz include files in pragma compiler directive below;

#pragma clang diagnostic push
#pragma clang diagnostic ignored “-Wdocumentation”
#include “sfizz.h”
#include “sfizz.hpp”
#pragma clang diagnostic pop

I have not documented set up instructions for Linux yet.

Below is basic code example.

#include “sfizz.h”
#include “sfizz.hpp”

// add synth
sfizz_synth_t* synth = sfizz_create_synth();
std::cout << “synth added\n”;

// load sfz instrument
sfizz_load_file(synth, “C:/Test SFZ/Test.sfz”);
std::cout << “sfz loaded\n”;

// play note
sfizz_send_note_on(synth, 0, 70, 127);
sfizz_send_note_off(synth, 10000, 70, 0);
std::cout << “note played\n”;

// remove synth
sfizz_free(synth);
std::cout << “synth removed\n”;