October 24, 2026
Step 7: Giving Sound Movement with Modulation
Building a low-frequency oscillator, routing it into the synth, and letting the grain cloud evolve over time.
In Step 6, Drizel became a live granular synthesizer. We could load a sample, move the play position, change pitch, adjust density, and hear the result in real time.
But the sound still felt static. The controls moved only when we moved them. We had a live grain engine, but not a system that could make it evolve on its own.
This is where modulation enters the picture. Instead of manually changing a parameter every few milliseconds, we create a signal that changes it automatically. The result is a synthesizer that can drift, pulse, sweep, and slowly explore its own source material.
1. What modulation means in practice
Modulation is the act of changing one parameter over time using another signal. In a synth, the destination might be pitch, amplitude, position, density, or pan. The source is the signal that moves it.
Up to this point, Drizel used direct values like: position = 0.5; That is a fixed point in the sample. If we want a parameter to move automatically, we need a generated signal rather than a constant.
The basic flow is simple:
Modulation Source
↓
Modulation Amount
↓
Destination Parameter
↓
Granular Engine
↓
Audio OutputThe modulation signal is not the final sound itself. It is a control signal used to shape how the synth behaves over time.
2. Low-frequency oscillators as a starting point
An oscillator is a mathematical function that moves through a cycle. A musical oscillator can produce audible tones. An LFO is slower; it does not usually create a note directly, but instead moves a control parameter.
In this step, Drizel uses a simple LFO that can generate two kinds of waves:
- Sine: smooth, organic movement with gradual direction changes.
- Triangle: linear rise and fall with a sharper reversal at the peaks.
Both waveforms generate values between -1 and +1. That makes them useful for bipolar modulation, where a parameter can move above and below its base value.
3. Frequency, phase, and depth
Three concepts matter most when building an LFO:
| Concept | Meaning |
|---|---|
| Frequency | How quickly the oscillator cycles per second. |
| Phase | Where we are inside the current cycle. |
| Depth | How strongly the modulation affects the destination. |
Frequency is measured in Hz, with one cycle taking seconds. A 1 Hz LFO completes a cycle each second. A 0.1 Hz LFO takes 10 seconds. That gives us a way to create slow, evolving textures instead of fast audible vibrato.
Phase is the current position within the cycle. A normalized phase runs from 0 to 1, where 0.25 is a quarter cycle and 0.5 is halfway through. The sine is computed using:
Depth is the modulation intensity. A destination can move by a small amount or a large amount depending on how much of the LFO signal we apply. Rate says how fast it moves; depth says how much it moves.
4. Implementing the LFO in C++
The first implementation is deliberately lightweight and framework-independent. The modulation code lives in a simple DSP helper, not inside JUCE-specific graph code.
enum class LfoShape
{
sine,
triangle
};
class Lfo
{
private:
double sampleRate_ = 48000.0;
double rate_ = 1.0;
double phase_ = 0.0;
LfoShape shape_ = LfoShape::sine;
};The key part is phase accumulation. Each sample advances the oscillator by a tiny amount, then wraps around when it exceeds one full cycle:
phase_ += rate_ / sampleRate_;
phase_ -= std::floor(phase_);This is how the oscillator keeps moving without growing unbounded. The phase is a stateful value, which means the LFO remembers where it left off. That is the core requirement for any repeating DSP control signal.
The waveform itself is generated as the phase passes through the cycle:
double next() noexcept
{
const double value =
shape_ == LfoShape::triangle
? 1.0 - 4.0 * std::abs(phase_ - 0.5)
: std::sin(6.28318530717958647692 * phase_);
phase_ += rate_ / sampleRate_;
phase_ -= std::floor(phase_);
return value;
}This is intentionally minimal. It does not allocate memory, depend on the host, or block the audio thread. It is exactly the sort of thing we want in a real-time synth architecture.
5. Modulation routing: deciding where the movement goes
Once we have a modulation signal, we still need a destination. The same LFO should be able to move pitch, position, or other parameters depending on the design. That routing choice is the next layer.
enum class ModDestination
{
off,
position,
pitch
};The general formula is:
Here, P_base is the manual value, L(t) is the LFO output, D is modulation depth, and R is the maximum modulation range. A position modulation example becomes:
The same LFO can push the grain-start position from 0.3 to 0.7, giving the synth a repeated scan through a sample. For pitch, we might use a range of ±12 semitones and scale the LFO output by depth, creating a slow pitch drift or periodic movement.
6. Keeping modulation values in range
A parameter cannot always accept any possible modulation value. Position is valid only between 0 and 1; pitch must remain in a workable range. If modulation pushes an output beyond its valid domain, the result is not just a bad number; it can create unstable or unpredictable synth behaviour.
position = std::clamp(
position + lfoValue * depth * 0.25,
0.0,
1.0
);
pitch = std::clamp(
pitch + lfoValue * depth * 12.0,
-24.0,
24.0
);Clamping turns modulation from a loose mathematical idea into a bounded audio-control system. Every destination has a defined range, and the engine respects it.
Every modulation destination needs defined units, limits, and boundary behaviour. Clamping can flatten part of the LFO movement when the base value is already near a limit, but it prevents invalid targets from reaching the engine.
7. Connecting modulation to JUCE
The LFO itself is framework-independent, but JUCE still owns the parameter system and the audio callback. In the plugin, we register four controls: LFO rate, depth, shape, and destination. This is handled through AudioProcessorValueTreeState.
lfo.setRate(lfoRate->load());
lfo.setShape(
lfoShape->load() >= 0.5f
? drizel::LfoShape::triangle
: drizel::LfoShape::sine
);The processing loop then reads the modulator output once per sample, applies the routing logic, and passes the resulting target into the granular engine.
for (int i = 0; i < buffer.getNumSamples(); ++i)
{
const auto targets = modulation.apply(
pos,
semitones,
lfo.next()
);
const auto frame = engine.next(
targets.position,
targets.pitch,
grains,
level
);
}This creates a clean signal path: the LFO creates movement, routing decides where it lands, and the granular engine renders the result.
8. Modulation, clamping, and smoothing
These operations solve different problems. Modulation calculates a changing target, clamping keeps that target inside its valid range, and smoothing determines how quickly the engine follows it.
Modulation decides where a parameter should move. Clamping keeps the target valid. Smoothing controls how quickly the current value approaches it.
The signal flow looks like this:
Base Parameter
↓
+ Modulation
↓
Modulated Target
↓
Smoother
↓
Granular EngineA position target can be written as:
Here, P_base is the manually selected position, L[n] is the current LFO value, D is depth, and R is the modulation range. The LFO output is bipolar, so the target can move on either side of the base value. Clamping ensures the normalized position stays between 0 and 1.
The real-time engine then follows the safe target with a one-pole exponential smoother:
Drizel uses a 20 ms time constant. A stationary target is approached exponentially rather than reached in one step: after one time constant, the smoother has covered about 63.2% of the initial distance.
In RealtimeEngine.h, the coefficient and update are implemented along these lines:
coefficient_ = 1.0 - std::exp(-1.0 / (rate * 0.02));
void smooth(double& value, double target,
double low, double high) noexcept
{
if (std::isfinite(target))
value += coefficient_ *
(std::clamp(target, low, high) - value);
}The smoother runs once per output sample. It is also applied to pitch, density, and gain, each with its own valid range.
| Time after change | Target | Smoothed position |
|---|---|---|
| 0 ms | 1.00 | 0.200 |
| 10 ms | 1.00 | 0.515 |
| 20 ms | 1.00 | 0.706 |
| 40 ms | 1.00 | 0.892 |
| 60 ms | 1.00 | 0.960 |
These values show a target that jumps from 0.2 to 1.0 and then stays there. With a continuously oscillating LFO, the target keeps moving, so the smoother follows it with some lag and can attenuate faster movement.
A sine LFO is already continuous and does not inherently require smoothing. Smoothing is still useful for abrupt changes from manual controls, host automation, or modulation settings; too much smoothing can weaken fast modulation.
In the grain engine, the scheduler decides when to launch a grain. The smoothed position affects where that new grain starts in the source recording. Existing grains keep the source start position chosen when they launched.
9. Why this matters for the grain cloud
A position LFO changes the source position chosen for newly launched grains. That means grain starts can drift across the sample instead of staying fixed at one point. The result is organic movement through the recording, almost like the instrument is scanning through a landscape of sound.
A pitch LFO changes the playback rate selected for new grains. Because grains overlap, the cloud hears multiple pitch states at once. Some grains may be higher; others lower; together they form a richer texture than a single fixed pitch destination.
This is especially useful for granular synthesis because the sound is already composed of many overlapping events. Modulation adds motion to that cloud without requiring a separate, expensive render pipeline.
10. Keeping modulation real-time safe
The audio callback must finish within its deadline. A delay can produce an audible dropout, so modulation work inside that callback needs to stay lightweight and predictable.
The LFO keeps a small amount of state and does not allocate memory, read files, acquire mutexes, or create threads while generating values. Keeping it independent of JUCE also lets us test the signal-generation logic separately from the plugin and audio device.
11. Testing the modulation system
Automated tests check the behaviour we can predict without relying only on listening:
- Sine phase values at known points in the cycle.
- Triangle wave starting and midpoint values.
- Deterministic output from identical oscillator states.
- Zero depth leaves the destination unchanged.
- Position and pitch stay within their supported limits.
The CTest entry is named modulation. The draft records the tests as implemented, but says their results had not yet been verified on the target Mac. Listening tests and worst-case callback performance measurements are also still needed.
cmake -S . -B build -DDRIZEL_JUCE_PATH=../JUCE
cmake --build build --parallel 2
ctest --test-dir build --output-on-failure12. What we learn from the first modulation system
At first glance, Step 7 adds only a sine wave and a triangle wave. But the architectural shift is bigger than that. We now have a clean separation between:
- Source: a signal generator like an LFO.
- Routing: the choice of destination and depth.
- Engine: the granular synthesizer that consumes the control values.
That separation is what enables future work: envelope generators, random-walk modulation, density modulation, spread modulation, and more flexible control policies. It also gives us a foundation for instructions that can describe musically meaningful movement, even if that is still a longer-term experiment.
The key idea is simple: if we want a synthesizer to sound alive, its parameters must move. A good modulation system gives those parameters motion without sacrificing reliability or clarity in the real-time audio path.
Drizel can now move through its source material on its own. This is not the final modulation roadmap, but it is a strong first step toward a more expressive and evolving instrument.
13. The next step
The next work is to extend the modulation system beyond a single LFO and destination. We can add more sources, more routing flexibility, and clearer rules for how modulation interacts with the grain scheduler and smoothing layers. The goal is to preserve the real-time safety that made this early version useful while opening the door to richer, more musical motion.
And that is exactly what makes Step 7 important: it turns Drizel from a responsive instrument into an evolving one.