Skip to content

About

A ladder filter implemented in JUCE, written as a teaching example.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

12 Commits

Folders and files

Repository files navigation

JUCE-Ladder-Filter-Implementation

A ladder filter implemented in JUCE, written as a teaching example.

What this is

This is an audio plugin: a small program that loads inside a DAW (digital audio workstation, such as Ableton Live, Logic Pro, FL Studio or Reaper) and changes the sound on a track. The plugin is a filter, an effect that removes some frequencies and keeps others. Sweep the cutoff down on a bright synth and it turns dull and muffled. Raise the resonance and you hear a whistling peak at the cutoff, the classic squelchy synth sound.

It is a ladder filter, the design made famous by Moog synthesizers in the 1960s. The code is short on purpose. It shows how to wrap a filter in a plugin with sliders a user can move and a host can automate.

What you can learn from it

Music Technology:

  • What a filter's cutoff (the frequency where the filter starts to cut) and resonance (a boost right at the cutoff) do to a sound.
  • The difference between low-pass (keeps the lows), high-pass (keeps the highs) and band-pass (keeps a band in the middle) filters.
  • The difference between a 12 dB and a 24 dB filter: how steeply the sound is cut past the cutoff.
  • What drive does: it pushes the signal harder into the filter for a thicker, slightly distorted tone.

Computer Science:

  • How a C++ plugin is split into a processor (the audio code) and an editor (the window with the controls).
  • How parameters are shared safely between the audio thread and the user interface.

Run it

On your own computer

You will need:

  • JUCE, a C++ framework for audio software. The download includes the Projucer, the tool that turns a .jucer project file into a project for your compiler. The project uses the juce::dsp module and a Visual Studio 2022 exporter, so it needs JUCE 6.1 or later. The source files compile with JUCE 8.0.12, checked with a small test program. The Projucer build itself has not been tested.
  • A C++ compiler:
  • A DAW that loads VST3 plugins (Windows and macOS) or AU plugins (macOS). Reaper has a free evaluation. JUCE can also build a standalone app.

The project was set up on Windows. It has not been tested on macOS.

Steps:

  1. Download this repo with Code > Download ZIP on GitHub, or run:

    git clone https://github.com/godofecht/JUCE-Ladder-Filter-Implementation.git
  2. Open the Projucer. In File > Global Paths, set the path to the JUCE modules folder inside your JUCE download. The project uses this global path to find JUCE.

  3. In the Projucer, open ShivakumarLadderFilter.jucer.

  4. On Windows, choose the Visual Studio 2022 exporter and click the button to save and open it in your IDE. On macOS, first add an Xcode (macOS) exporter with the + button, because the project only has a Windows one.

  5. Build the Release configuration.

  6. Copy the built plugin to your plugin folder. On Windows, VST3 plugins go in C:\Program Files\Common Files\VST3.

  7. Rescan plugins in your DAW and add ShivakumarLadderFilter to a track with a bright sound on it, such as a sawtooth synth or a drum loop.

When it works, you see a 600 by 140 pixel window with three sliders and six buttons.

Controls:

Control Range What you hear
CUTOFF slider 10 Hz to 20 kHz Where the filter starts cutting.
RESONANCE slider 0 to 1 A peak at the cutoff. High values whistle.
DRIVE slider 1 to 2 How hard the signal is pushed into the filter.
LPF12, HPF12, BPF12 buttons Low-pass, high-pass or band-pass at 12 dB per octave.
LPF24, HPF24, BPF24 buttons The same at 24 dB per octave, a steeper cut.

How it works

JUCE already includes a ladder filter, juce::dsp::LadderFilter. This plugin connects it to controls. Every time the DAW sends a block of audio, processBlock reads the current slider values, passes them to the filter, and runs the filter over the block.

File or folder What is in it
ShivakumarLadderFilter.jucer The Projucer project: modules, exporters and settings.
Source/PluginProcessor.h The four parameters (mode, cutoff, resonance, drive), their ranges and defaults, and the list of filter modes.
Source/PluginProcessor.cpp prepareToPlay sets up the filter. processBlock reads the parameters and filters the audio.
Source/PluginEditor.h The editor class and the button click handler that picks the filter mode.
Source/PluginEditor.cpp Creates the sliders, labels and buttons, and lays them out in resized().

Ideas to try

  1. Change the default cutoff. In Source/PluginProcessor.h, the cutoff starts at 10 Hz, so a low-pass filter starts almost silent. Change the last number in the cutoff line to 1000.0f.
  2. Make the cutoff slider feel musical. It is linear, so most of its travel covers high frequencies. In Source/PluginProcessor.h, give the cutoff NormalisableRange a skew factor so the low end gets more room.
  3. Show the current mode when the window opens. At the moment no button is lit until you click one. In the editor's constructor in Source/PluginEditor.cpp, read the mode with valueTreeState.getRawParameterValue ("mode") and turn on the matching button with setToggleState.
  4. Change the layout in resized() in Source/PluginEditor.cpp, for example by turning the sliders into rotary knobs with setSliderStyle.
  5. Ambitious: replace the mode buttons with a juce::ComboBox and a ComboBoxAttachment for the mode parameter. Because mode is a choice parameter, the box can fill itself from the parameter's list of mode names.

Technical details

From the previous README, corrected against the code:

Parameters are held in an AudioProcessorValueTreeState. The constructor looks up a raw atomic pointer for each one (getRawParameterValue), and processBlock reads through those pointers. The message thread writes through the value tree, the audio thread reads an atomic, and neither blocks the other.

Parameter Range Default
mode LPF12, HPF12, BPF12, LPF24, HPF24, BPF24 LPF24
cutoff 10 Hz to 20 kHz 10 Hz
resonance 0 to 1 0.22
drive 1 to 2 1

processBlock clamps the cutoff to between 10 Hz and 45% of the sample rate before passing it to the filter. A 20 kHz cutoff would otherwise sit above the Nyquist frequency (half the sample rate) in a host running below 40 kHz.

mode is a choice parameter, so its raw value is an index into ModeList. processBlock clamps that index to the list before using it, so no value a DAW sends can read past the end. Each mode button sets mode to its own index with setValueNotifyingHost, between beginChangeGesture and endChangeGesture, so a DAW can record the clicks as automation.

See Analog-Fattener for a saturation effect built the same way, and danzig for the same problem solved without JUCE at all.

Project status

This is a first-commit teaching example from 2022 and is not being developed. Known problems:

  • Only a Visual Studio 2022 exporter is included.
  • There is no screenshot or audio example yet.

Licence

You can use, copy and change this code for any purpose, as long as you keep the copyright notice. See LICENSE (MIT).

JUCE has its own licence terms. Check the JUCE website before you share a built plugin.

Credits

  • Written by Abhishek Shivakumar, April 2022.
  • Built with JUCE and its juce::dsp::LadderFilter.

About

A ladder filter implemented in JUCE, written as a teaching example.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages