The Juce Synth classes are wonderful. But I found myself rewriting very similar code to implement some very basic synth functionality in multiple projects, so I decided to create my own Synth and SynthVoice base classes for my own use.
I frequently see people having issues with correctly implementing a juce::SynthVoice class, so I decided to post my synth code here, and mention that it is 100% free to use, and has proven so-far fool proof (if I can’t break it…)
anyway, here she is: https://github.com/benthevining/JuceSynthBase
My goal in writing these base classes was to encapsulate as much of the functionality common to almost every synth as possible, to allow the actual creation of a specific synth to only need to worry about its actual audio generation with its specific oscillators, etc.
My SynthVoiceBase class takes care of ADSRs, click-preventing, tracking note off/cleared, and pretty much everything else. All you need to do is override the actual function that generates the voice’s audio – which the base class will call for you with the correct current desired frequency, taking into account pitch bend, master detune, and everything else. (midi note glide is coming soon! it’s on my list!)
This synth infrastructure provides the following features out of the box with no configuration:
- built in midi-controlled ADSRs and anti-click “quick-fade” ADSRs
- applied to each voice: midi velocity/aftertouch gain (with a sensitivity setting), soft pedal gain, playing-but-released gain (ie for sostenuto/sustain pedal, etc), soft pedal gain [each with smoothing]
- panning – easily control the synth’s stereo spread with one stereo width parameter and a lowest panned note parameter
- sostenuto, sustain & soft pedal behavior that mimics a real piano’s pedals
- advanced voice management - polyphonic lines are kept (semi-)consistently in the same synth voices
- automated midi features
This code is 100% free to use. Anyone may freely copy, modify, or distribute this code.
I hope this is helpful. If anyone finds any bugs or has any feature requests, feel free to comment on the GitHub repo or on this thread