Drum sampler plugin - structure, best practice

(I did see one other post sort of related)

From bits of tutorials, and some guesses, I have cobbled together a simple drum sampler plugin. It seems to work pretty successfully. I do have some questions about best practices.

  1. I started with 15 drum samples (most useful GM drums).
  2. I converted the samples into BinaryData.
  3. I load each drum sample data into an individual SamplerSound.
  4. For each SamplerSound I create a unique SamplerVoice.
  5. In Processor::processBlock() I process all the MIDI messages and control the SamplerVoices directly. Each SamplerVoice is controlled by one MIDI note. (They are basically independent except for hi-hat chokes.) Then for all SamplerVoices I renderNextBlock().

The Synthesiser class seemed to get in my way, trying to (as I understand) find free voices to assign new notes. So I removed it from the middle.

Is this “correct”, or is there a better/more elegant way to get the job done?

We used a very similar approach, but without using the JUCE classes. One thing you do have to consider is when you get a new note-on whilst a sound is already playing; this can lead to clicks/pops in the output as you suddenly stop playing the sound and restart it. You can either have 2 (or more) voices per drum pad (but hope you never get more than <number of voices> note-ons in the release time of the sampler), or the approach we took was to have a small (20ms-ish) ring buffer that we render out a short decay should a note-on come whilst the voice is already playing, we then mix (and clear) that ring buffer into the voice output.

1 Like