Hello! Welcome back to your capstone project module.
In our last lesson, we built a simple echo effect using a delay line with a fixed length, implemented with a circular buffer. This created discrete, evenly-spaced repetitions of the input sound. Today, we'll build directly on that foundation to explore what happens when the delay length is no longer fixed, but is instead made to vary continuously over time.
This lesson will guide you to develop a chorus or flanger effect by modulating the delay time of a delay line with a low-frequency oscillator (LFO). By the end, you will understand the signal processing principles behind these classic effects, their historical origins, and the key mathematical and implementation details that bring them to life.
1. From Echo to Flanger: The Modulated Delay
The flanger is one of the most recognizable audio effects, creating a characteristic "swooshing" or "jet plane" sound. Its structure is a direct evolution of the delay effects we have already discussed. While an echo uses a feedback delay, a classic flanger uses a feedforward structure, mixing the original "dry" signal with a delayed "wet" signal. The crucial difference is that the delay time, , is now a function of time, .
To understand the flanger's structure and origins, we'll turn to Julius O. Smith's 'Physical Audio Signal Processing'. This text provides the historical context and mathematical model you appreciate.
Please read the section titled 'Flanging'. Pay attention to: The historical origin: How the effect was first created using two tape machines. The block diagram: Note that it's a feedforward comb filter, as shown in Figure 5.3. The difference equation: y(t) = x(t) + g \cdot x(t - D(t)), where D(t) is the time-varying delay. The LFO: How a low-frequency oscillator is used to modulate the delay length, creating the sweeping effect.
As you've read, the flanger's sound comes from its time-varying frequency response. It is a comb filter, but because the delay is changing, the notches in the filter's spectrum are not static. They sweep through the frequency range, creating the distinctive "whoosh".
The delay time is typically modulated by a Low-Frequency Oscillator (LFO), often with a sinusoidal or triangular waveform. The modulation can be expressed as:
where:
- is the average delay length (e.g., 5 ms).
- is the sweep depth or excursion (e.g., ±4 ms).
- is the frequency of the LFO, also known as the "rate" or "speed" of the effect (e.g., 0.2 Hz).
For a flanger, the average delay is kept very short, typically under 15 ms, so that we don't perceive the delay as a distinct echo.
2. The Physics of a Changing Delay: Doppler Shift
A key question arises: what is the perceptual effect of continuously changing the delay of a signal? Your background in signal processing and physics might suggest an answer: a change in frequency. This is precisely correct and is analogous to the Doppler effect.
When a sound source moves towards you, its sound waves are compressed, leading to a higher perceived pitch. When it moves away, the waves are stretched, leading to a lower pitch. A time-varying delay line simulates this phenomenon perfectly.
- Decreasing the delay is like moving the "listener" (the read-pointer) towards the "source" (the write-pointer), compressing the signal and increasing its pitch.
- Increasing the delay is like moving the listener away from the source, stretching the signal and decreasing its pitch.
Let's look at the mathematics behind this.
The 'Doppler Simulation' section of the same text derives the exact mathematical relationship between the rate of change of delay and the resulting frequency shift.
Please read the subsection 'Time-Varying Delay-Line Reads'. Focus on the derivation that leads to Equation (5.6), which is the most important result here. Understand how differentiating the phase of the output signal reveals the instantaneous frequency.
The key equation you saw is:
Where:
- is the instantaneous output frequency.
- is the input frequency.
- is the delay in seconds.
- is the rate of change of delay. This dimensionless quantity is the crucial factor.
This equation formalizes our intuition: the output frequency is shifted by a factor proportional to the negative derivative of the delay time. When the LFO is on its rising slope, the delay is increasing, , and the pitch is shifted down. When the LFO is on its falling slope, the delay is decreasing, , and the pitch is shifted up.
Test your understanding!
Suppose you are modulating your delay time with a sinusoidal LFO:
- At what point(s) in the LFO cycle is the pitch shift at its maximum upward value?
- At what point(s) is the pitch shift at its maximum downward value?
- At what point(s) is there zero pitch shift?
Show answer
The pitch shift is proportional to . Let's find the derivative:
The pitch shift is proportional to .
- Maximum upward shift: This occurs when is at its maximum positive value, which is +1. This happens when , i.e., at the troughs of the cosine wave. This corresponds to the falling zero-crossings of the original sine wave LFO.
- Maximum downward shift: This occurs when is at its maximum negative value, which is -1. This happens when , i.e., at the peaks of the cosine wave. This corresponds to the rising zero-crossings of the original sine wave LFO.
- Zero pitch shift: This occurs when . This happens at the peaks and troughs of the original sine wave LFO, where its slope is momentarily zero.
3. Implementation: The Need for Interpolation
In the previous lesson, our delay D was an integer number of samples. With LFO modulation, the delay D(t) will almost always be a floating-point number (e.g., 220.7 samples). We cannot simply access buffer[220.7]. We need a way to estimate the value of the signal between two samples. This technique is called fractional delay interpolation.
The simplest and most common method is linear interpolation. To find the value at a fractional position p (e.g., 220.7):
- Find the integer sample index
ibeforep(i.e.,floor(p), which is 220). - Find the fractional part
alpha(i.e.,p - i, which is 0.7). - The interpolated value is a weighted average of the samples at
iandi+1:
value = (1 - alpha) * buffer[i] + alpha * buffer[i+1]
While more advanced interpolation methods exist (e.g., polynomial, all-pass, or windowed-sinc), linear interpolation is computationally cheap and often sufficient for these effects.
4. The Chorus Effect: Creating an Ensemble
The goal of a chorus effect is to make a single voice or instrument sound like a group of musicians playing in unison. Real musicians never play with perfect timing or tuning. The chorus effect simulates this by creating several copies of the original signal, each with its own slight, time-varying delay and pitch modulation.
Figure 1: Structure of a basic flanger effect. The delay D(t) is modulated by an LFO. (Source: Physical Audio Signal Processing)
The implementation is a direct extension of what we've learned. Instead of one modulated delay line, we use multiple.
The 'Chorus Effect' section of the same resource succinctly defines the effect and its implementation.
Please read the short section 'Chorus Effect'. Notice how it's described as using multiple interpolating taps on a delay line, each creating an independent 'voice'.
To create a rich stereo chorus, one might use two or more modulated delay lines. Each line would have its own LFO, or a single LFO with different phase offsets for each line, to ensure the pitch variations are independent and decorrelated. The outputs of these delay lines are then panned to different positions in the stereo field and mixed with the dry signal.
Chorus vs. Flanger Parameters:
- Delay: Chorus uses longer average delays (typically 15-50 ms) to create a sense of distinct voices, while flangers use very short delays (< 15 ms) for a strong comb-filtering coloration.
- Feedback: Flangers often include a feedback or "regeneration" control to accentuate the resonant peaks of the comb filter. Choruses typically have no feedback.
- Modulation: Both use LFOs, but the modulation in a chorus is often subtler, aimed at creating a gentle shimmer rather than a dramatic sweep.
5. A Deeper Look: The Nuances of Modulation
So far, we've assumed a simple relationship: a sinusoidal LFO modulating delay creates a sinusoidal pitch variation (specifically, a cosine). However, the reality, especially in historical analog circuits, is more complex and interesting. This is a nuance your EE background will allow you to appreciate.
This article investigates the behavior of classic Bucket-Brigade Device (BBD) analog delay chips used in many famous chorus and flanger pedals. It uses simulation to show that the relationship between the LFO shape and the resulting pitch modulation is not linear.
Investigations into what a BBD Chorus unit *really* does
This article from Electric Druid is a fascinating investigation into what really happens inside a BBD-based chorus unit. It reveals some non-obvious distortions in the modulation waveform.
Please read through the article, focusing on the following progression of ideas: Initial Simulation: Observe how a sine wave LFO produces a distorted frequency modulation (pitch shift). The 'Why': Understand the core insight: pitch shift depends on the rate-of-change of the total delay. The total delay is an integral of the clock period over the length of the BBD. This chain of operations (inversion, integration, differentiation) is the source of the distortion. LFO Waveforms: Look at the surprising pitch modulation that results from different LFO shapes, especially the square wave. Mathematical Validation: Skim the final section showing the Wolfram Alpha plots that mathematically confirm the simulated results.
This deep dive shows that the character of these beloved analog effects is partly due to these inherent non-linearities. While a modern digital implementation can create a "perfect" sinusoidal pitch vibrato, accurately modeling a vintage pedal might require emulating these very distortions. It's a perfect example of how limitations in analog technology created a unique and desirable sonic signature.
Conclusion
You have now extended your knowledge from fixed delays to time-varying delays, unlocking a new class of powerful modulation effects. You've seen how a simple concept—making the delay time dynamic—gives rise to the sweeping resonance of a flanger and the shimmering textures of a chorus.
Key Takeaways:
- Flanger and Chorus effects are built on delay lines where the delay time is modulated by a Low-Frequency Oscillator (LFO).
- The core mechanism for the pitch-shifting component is the Doppler effect: the output frequency is scaled by a factor related to the negative derivative of the delay time, .
- A Flanger typically uses a short delay (<15ms), feedforward mixing, and often feedback to create a sweeping comb filter effect.
- A Chorus uses multiple, independent, longer-delay modulated lines (15-50ms) with no feedback to simulate an ensemble of performers.
- Implementing these effects requires fractional delay interpolation (e.g., linear interpolation) to read from the delay buffer at non-integer sample positions.
Preview of the Next Lesson:
We have just explored how to modulate pitch using a time-domain method based on the Doppler effect. This approach has its limits; large pitch shifts can introduce audible artifacts. The next lesson, "Analyze the phase vocoder method for time-stretching and pitch-shifting," will introduce you to a powerful frequency-domain technique. The phase vocoder analyzes, modifies, and resynthesizes the signal's spectrum, allowing for high-quality, independent control over pitch and time.