Visits—
Donate

Journal · Behind the scenes

Doublure — under the hood

YIN, TD-PSOLA, deterministic noise: how a second vocal take is made

Ultra-GeekWritten with the help of AI

Ultra-Geek · This post opens the hood of Doublure 1.2: algorithms, physics and formulas. To use the plugin, the manual is enough; to understand what happens inside, read on. Version 1.3 also adds a stage of modelled microphones, described in the manual.

Doublure makes a second vocal take by re-synthesising the voice period by period (TD-PSOLA driven by YIN). Each double gets its own timing, pitch, attacks, mouth shape and tone, all drawn from a deterministic noise locked to the position in the song.

1. The problem: a copy is not a second take

Copying the track and delaying it by a few milliseconds does not give a double take: you get a comb filter, which sounds hollow and metallic. If you vary the delay to “humanise” it, you add a Doppler effect, which makes the pitch wobble.

The output signal is the sum of the voice and its copy delayed by τ:

y(t)=x(t)+g x(t−τ)⇒H(f)=1+g e−j2πfτ,∣H(f)∣g=1=2 ∣cos⁡(πfτ)∣y(t) = x(t) + g\,x(t-\tau) \quad\Rightarrow\quad H(f) = 1 + g\,e^{-j2\pi f\tau}, \qquad |H(f)|_{g=1} = 2\,\lvert\cos(\pi f \tau)\rvert

The magnitude drops to zero every time the two voices are in opposite phase:

fk=2k+12τ,Δf=1τf_k = \frac{2k+1}{2\tau}, \qquad \Delta f = \frac{1}{\tau}

Comb filter: voice + copy delayed by 15 ms, g = 1

With τ = 15 ms, a notch falls every 66.7 Hz, and the peaks rise to +6 dB. These notches are fixed in time: the ear hears them as a “pipe” colouration, not as a second singer.

Modulating the delay does not fix it. Reading a copy with a variable delay τ(t) amounts to reading it at a different speed:

y(t)=x(t−τ(t))  ⇒  foutput=finput (1−τ′(t))y(t) = x\big(t - \tau(t)\big) \;\Rightarrow\; f_{\text{output}} = f_{\text{input}}\,\big(1 - \tau'(t)\big)

For example, a delay that oscillates by ±5 ms at 1 Hz reaches a slope τ′ = 2π × 1 × 0.005 ≈ 0.031. The pitch then varies by 1,200 × log₂(1.031) ≈ ±54 cents, more than a quarter of a tone: that is the typical wobble of modulated-delay “doublers”.

A real singer who sings again does neither. They place each syllable a little differently, without changing pitch. Their intonation drifts by a few cents, independently of their timing. They attack each note in their own way, and their mouth does not quite have the same shape. The two takes are decorrelated: no stable comb forms. Doublure must therefore be able to change time without touching pitch, and pitch without touching time. That is the job of TD-PSOLA resynthesis.

2. Overview: two paths that meet again

The signal follows two paths. The lead vocal is simply delayed by the latency L, to stay aligned. Each double, on the other hand, is rebuilt from scratch from grains taken from a buffer that holds 150 ms of “future”.

Doublure 1.2 processing chain: two paths, eight stages

Three pieces of information drive the reconstruction of each double:

  • where the periods are, supplied by the YIN analysis: the period P(t), whether the sound is voiced or not, and the note onsets;
  • how the double must differ: the time offset δ, the pitch ratio r, the formant factor φ and the gain g, drawn from a deterministic noise;
  • what to read: the grains, taken from the buffer at time τ = t − L + δ.

In version 1.2, the double then goes through a shaping chain: tone, saturation (OD, TUBE, TAPE), a target-band EQ and 12 dB/oct filters. It is finally mixed with the voice, before a safety limiter at −0.3 dBFS.

3. Finding the period: the YIN algorithm

PSOLA cuts the voice period by period. If the period is wrong, the grains are badly cut and the double becomes rough. Everything therefore starts with a reliable pitch detector: YIN (de Cheveigné and Kawahara, 2002).

Preparation. The signal is summed to mono, low-pass filtered, then decimated to about 24 kHz. This halves the computation, and keeps only the band that carries the fundamental and the first harmonics. The analysis uses a window of W = 1024 samples (about 43 ms) and a hop of 128 samples (about 5.3 ms).

Step 1: the difference function

We compare the signal with itself shifted by τ:

dt(τ)=∑j=1W(xj−xj+τ)2d_t(\tau) = \sum_{j=1}^{W} \left(x_j - x_{j+\tau}\right)^2

For a perfectly periodic signal of period P, d(P) = 0. It is the autocorrelation turned upside down: d(τ) = r(0) + r_τ(0) − 2r(τ). But d(0) is also 0, and d tends to fall for small τ: a naive detector would often pick a period that is too short (a high-octave error).

Step 2: the cumulative mean normalised difference (CMND)

dt′(τ)={1τ=0dt(τ)1τ∑j=1τdt(j)τ>0d'_t(\tau) = \begin{cases} 1 & \tau = 0 \\[4pt] \dfrac{d_t(\tau)}{\frac{1}{\tau}\sum_{j=1}^{\tau} d_t(j)} & \tau > 0 \end{cases}

We divide by the running mean. The zero-lag trap disappears (d′(0) = 1) and the scale becomes absolute: 0 means “perfectly periodic”, 1 means “no relation at all”.

d′(τ) computed on a synthetic vowel at 250 Hz, 5 harmonics and a little noise

Step 3: absolute threshold, and the first dip wins

A signal that is periodic in P is also periodic in 2P and 3P, and those dips are almost as deep. Choosing the global minimum would regularly lead to the low octave. YIN therefore takes the first τ where d′ goes below the threshold (0.12 in Doublure), then walks down to the bottom of that dip. If no dip goes below the threshold, Doublure still accepts the deepest global dip if it goes below 0.20; otherwise, or if the frame is weaker than −55 dB, it is declared unvoiced (consonant, breath, silence).

Step 4: parabolic interpolation

τ is an integer, which is too coarse. At 24 kHz and 250 Hz, τ = 96; going to 97 already makes a difference of 1200·log₂(97/96) ≈ 18 cents. We fit a parabola through the three points around the minimum τ₀:

τ^=τ0+d′(τ0−1)−d′(τ0+1)2[d′(τ0−1)−2 d′(τ0)+d′(τ0+1)]\hat\tau = \tau_0 + \frac{d'(\tau_0-1) - d'(\tau_0+1)}{2\left[d'(\tau_0-1) - 2\,d'(\tau_0) + d'(\tau_0+1)\right]}

The precision then drops to a fraction of a sample, a few cents.

Step 5: safeguards and onsets

  • Anti octave-jump: if the new period is about double or half the previous one without the singer having really jumped, we keep the previous octave.
  • Onset detection: a note starts when a frame becomes voiced again after at least two unvoiced frames, or when the pitch jumps by more than 80 cents. These onsets drive the Scoop (section 5).

Computation cost. In direct form, it takes (W − τmax) × τmax multiplications per frame: about 655 × 370 ≈ 240,000 every 5.3 ms, on the order of 45 million operations per second. That is comfortable for a modern processor. An FFT version (Wiener–Khinchin theorem) would drop to O(N log N) if needed.

4. Rebuilding the voice: TD-PSOLA

The source–filter model

A sung vowel is a train of impulses (the closures of the vocal folds, one every P seconds) that excites a filter: the vocal tract, whose resonances are the formants. Each impulse triggers the same damped response h(t). A piece of signal two periods long, centred on an impulse, is therefore a good approximation of the impulse response of the vocal tract at that moment. That is a grain.

The key point: pitch is carried by the spacing of the impulses, timbre by the shape of each response. PSOLA (Pitch-Synchronous Overlap-Add, Moulines and Charpentier, 1990) separates the two.

Analysis: placing the epochs

The centres of the grains (the epochs) are placed at multiples of the period P, then readjusted by cross-correlation within a window of ±P/8 and aligned on the peak of the impulse. Without this readjustment, two successive grains do not have quite the same phase, and their superposition produces an audible jitter.

gk(u)=x(tk+u)  wk(u),wk(u)=12(1+cos⁡πuPk),∣u∣<Pkg_k(u) = x(t_k + u)\; w_k(u), \qquad w_k(u) = \tfrac12\left(1 + \cos\frac{\pi u}{P_k}\right), \quad |u| < P_k

Synthesis: two clocks

Synthesis has two independent clocks:

  • the emission clock sₘ decides when a grain is emitted. Its step P/r sets the pitch of the double;
  • the reading clock τₘ = sₘ − L + δ(sₘ) decides which grain is read. It sets the placement in time.
y(t)=∑mgk(m)(φ (t−sm))∑mwk(m)(φ (t−sm)),sm+1=sm+hm,hm=P(τm)rm,rm=2cm/1200y(t) = \frac{\sum_m g_{k(m)}\big(\varphi\,(t - s_m)\big)}{\sum_m w_{k(m)}\big(\varphi\,(t - s_m)\big)}, \qquad s_{m+1} = s_m + h_m, \quad h_m = \frac{P(\tau_m)}{r_m}, \quad r_m = 2^{c_m/1200}

k(m) is the grain whose epoch is closest to τₘ. When r > 1, more grains are emitted than are analysed: some are read twice. When r < 1, some are skipped. The duration is therefore preserved automatically. The denominator compensates for the overlap: at each instant, the output is divided by the sum of the windows of the overlapping grains (with a floor at 0.4, so as not to amplify the edges). The level stays exact whatever the overlap ratio P/h.

TD-PSOLA in three lines: three independent manipulations, computed waveforms

Formants: reading the grain faster

Reading each grain at speed φ compresses its impulse response in time: all the resonance frequencies are multiplied by φ. Since the spacing sₘ does not change, the note stays the same. With φ = 2^(f/12) and f up to about ±4 semitones, φ goes from 0.79 to 1.26: a more or less open mouth, a slightly shorter or longer vocal tract.

Why not a phase vocoder?

A phase vocoder (STFT) transposes rich sounds well, but it smears transients and gives a “phasey” sound on a voice. On a monophonic voice, PSOLA keeps the phase coherence inside each period, hence the natural grain of the voice. It also costs very little: no FFT, just windowed copies. The downside: you need a single, dry voice, and a correct period, hence the importance of YIN.

5. Human factors: how to make “another take”

A real second take does not differ from the first by a constant offset. It differs by slow, smooth and independent deviations: a little early here, a little flat there, a different attack on each note. Doublure generates these deviations with a deterministic noise, then applies them separately, thanks to the two clocks of PSOLA.

The generator: smoothed value noise

A pseudo-random value is drawn every Δ seconds, then we interpolate between the two neighbouring values with an S-shaped curve, to avoid any audible step:

n(t)=hk+(hk+1−hk) S(f),k=⌊t/Δ⌋,f=t/Δ−k,S(f)=3f2−2f3n(t) = h_k + (h_{k+1} - h_k)\,S(f), \qquad k = \left\lfloor t/\Delta \right\rfloor, \quad f = t/\Delta - k, \quad S(f) = 3f^2 - 2f^3

The values hₖ ∈ [−1, 1] come from a hash (section 6). Looseness sets Δ: a small Δ, and the double changes its mind often (loose singer); a large Δ, and it drifts slowly (steady singer). For timing, Δ goes from about 0.9 s (Looseness at 0) to 0.2 s (Looseness at 100 %); for pitch, from 1.2 to 0.3 s. The larger the requested deviation, the longer Δ is stretched, so that the time shift stays under 25 % and the pitch glide under 600 cents per second. Each parameter (timing, pitch, formant, gain) has its own noise stream, decorrelated from the others.

The deviations applied

Deviation Formula Control What it imitates
Timing δ(t) = Tₘₐₓ · nδ(t) Timing, 0 to 80 ms syllables early or late
Pitch c(t) = Cₘₐₓ · nc(t) + scoop(t) Pitch, 0 to 100 cents floating intonation
Formant φ(t) = 2^(F · nφ(t) / 12) Formant, up to ±4 semitones another mouth shape
Intensity g(t) = 10^(D · ng(t) / 20) Dynamics, 0 to 6 dB phrases pushed or held back
Tone treble shelf (hinge at 2.5 kHz) drawn for each double Tone another distance from the mic

The Scoop: the attack of each note

At each detected onset (section 3), the double gets its own attack flaw: it comes in a little from below, then joins the note. Sometimes it overshoots slightly.

scoop(t)=−Anote  e−(t−ton)/τs,t≥ton\mathrm{scoop}(t) = -A_{note}\; e^{-(t - t_{on})/\tau_s}, \qquad t \ge t_{on}

A_note is drawn at random for each note and each double: it equals Scoop × (12 to 42 cents). It is positive in 70 % of cases (the double comes in from below) and negative in 30 % of cases (it overshoots), with then 0.6 times the amplitude. The constant τₛ is drawn between 40 and 130 ms, and the effect dies out after half a second at most. It is the most “vocal” of all the deviations: two real takes differ mostly there.

Harmonics (1.2): the micro-irregularity of the vocal folds

A PSOLA resynthesis emits perfectly regular impulses. Real vocal folds do not: each period varies a little in duration (jitter) and in amplitude (shimmer). In a healthy voice, one typically measures a jitter below about 1 % and a shimmer of a few percent. Harmonics adds these irregularities, this time independent from one period to the next, plus a light breath:

s^m=sm+0.06 H Pr εm,am=10 1.2 H ηm/20,εm, ηm∈[−1,1]\hat s_m = s_m + 0.06\,H\,\frac{P}{r}\,\varepsilon_m, \qquad a_m = 10^{\,1.2\,H\,\eta_m/20}, \qquad \varepsilon_m,\ \eta_m \in [-1, 1]

Here H is the Harmonics setting (from 0 to 1) and ε, η are drawn independently for each impulse. At 100 %, each grain is shifted by at most 6 % of the period (jitter) and its level varies by at most ±1.2 dB (shimmer); at the default setting (50 %), it is half of that. These values are deliberately wider than those of a healthy voice, so that the double clearly decorrelates from the lead. The shift of each impulse is measured against the regular grid s_m: it does not accumulate.

In the spectrum, this jitter mostly blurs the high harmonics, because the same time shift represents a larger fraction of a period at high frequency. The double therefore decorrelates from the lead in the treble, exactly like a second take. At 0 %, the resynthesis stays “perfect”.

Why independence is essential

A simple delay shifts everything as a block: pitch, timbre and timing stay coupled, and the ear hears a comb filter (section 1). A chorus modulates the delay, so it also shifts the pitch by the Doppler effect, periodically. Doublure moves the timing without touching the pitch, the pitch without touching the timing, and the formants without touching anything else. This separation is what makes you believe in a second person, or a second take.

6. Latency and determinism

Why the plugin needs 150 ms of lookahead

A plugin never sees the future. For a double to sing before the lead, the lead has to be delayed. Doublure therefore reads the voice at t − L, and each double at τ = t − L + δ. The most advanced reading point (δ = +80 ms) must still leave room for three things: the advance with which the grains are placed (up to one output half-grain, about 19.5 ms), half of the grain read in the input (about 17 ms at worst, for a low voice at 65 Hz), and the YIN analysis window, which must have seen the signal before the periods are cut out (about 27 ms). In the worst case: 80 + 19.5 + 17 + 27 ≈ 144 ms. The 150 ms chosen therefore leave a margin of about 6 ms.

Latency budget: worst case, 144 ms needed for 150 ms of lookahead, plus 1.5 ms of limiter

The latency is reported to the host, which shifts all the other tracks by the same amount (plugin delay compensation, PDC). It is painless when mixing, but unusable for monitoring: nobody sings with 152 ms of delay in the headphones.

Determinism: same song, same double

A classic random generator depends on the order of calls: restart playback at another place, and the double changes. Doublure instead computes each noise value as a pure function of the position in the song:

uk=splitmix64(splitmix64(c (take+17))⊕voice⊕channel⊕k)≫40224∈[0,1[,hk=2 uk−1u_k = \frac{\mathrm{splitmix64}\Big(\mathrm{splitmix64}\big(c\,(\mathrm{take}+17)\big) \oplus \mathrm{voice} \oplus \mathrm{channel} \oplus k\Big) \gg 40}{2^{24}} \in [0,1[, \qquad h_k = 2\,u_k - 1

Here c is a 64-bit constant, “voice” and “channel” (timing, pitch, formant, gain…) are shifted into the high bits so that each stream is independent, and only the 24 leading bits of the result are kept. splitmix64 (Steele, Lea and Flood, 2014) is a very fast 64-bit hash with good avalanche properties: changing one bit of the input changes about half the bits of the output. Consequences:

  • the same position in the song always gives the same deviations, whatever the starting point of playback;
  • each take number (1 to 12) is another seed, hence another interpretation, also reproducible;
  • the TAKES tab can compute the curves of the twelve takes without playing a single note: they are the same functions, evaluated over a 10 s window;
  • the offline export gives exactly what the plugin plays live (checked to the precision of a 24-bit file in 1.2).

The Scoop is the only visible exception: it depends on the sung notes, hence on the onsets detected in the audio. It remains deterministic, because the same audio gives the same onsets, but it cannot be predicted without the signal.

7. Stereo, mixing and the 1.2 chain

Placement and panning law

Each double is placed by a linear balance law. The three modes: Mono (everything in the centre), Pair (voice on the left, double on the right) and Spread (voice in the centre, doubles on either side). Width sets the spread.

Why 1/√N

Two doubles are decorrelated: they do not add in amplitude (+6 dB) but in power (+3 dB). So that adding a double does not raise the level, the sum is normalised:

Psum=∑n=1NPn  ⇒  gain=1NP_{\text{sum}} = \sum_{n=1}^{N} P_n \;\Rightarrow\; \text{gain} = \frac{1}{\sqrt{N}}

Drive: where the harmonics come from

A saturation is a non-linear function y = f(x). If f is odd (f(−x) = −f(x)), like tanh, the Fourier series of the output only contains odd harmonics (3, 5, 7): that is the OD model. The signal is first emphasised (0.55 times itself plus its version high-pass filtered at 260 Hz, which carves a hump in the mid-range), multiplied by a gain g = 1 + 30 D², where D is the Drive setting from 0 to 1, then clipped by tanh; the high frequencies are then softened by a low-pass at 5.2 kHz. Shifting the curve breaks the symmetry and makes the even harmonics appear:

fTUBE(x)=tanh⁡(g x+b)−tanh⁡(b),b=0.30+0.35 D  ⇒  H2,H3,…f_{\text{TUBE}}(x) = \tanh(g\,x + b) - \tanh(b), \qquad b = 0.30 + 0.35\,D \;\Rightarrow\; H_2, H_3, \dots

That is the principle of the TUBE model, warm and full: the DC offset it creates is removed by a filter at 25 Hz, and the high frequencies are softened at 9.5 kHz. TAPE combines a soft knee, a bump in the bass and a loss in the treble:

fTAPE(x)=2π arctan⁡ ⁣(π2 g x)f_{\text{TAPE}}(x) = \frac{2}{\pi}\,\arctan\!\Big(\frac{\pi}{2}\,g\,x\Big)

Here the signal is first added to 0.45 times its version low-passed at 160 Hz (the bass bump), then the high frequencies are reduced by a low-pass at 6.8 kHz. In all three models, the curve is computed with anti-aliasing (the antiderivative method), without oversampling, hence without latency. The level is compensated after each model: you set the colour, not the volume. These three shapes are mathematical approximations, not copies of a specific piece of equipment.

EQ, filters, limiter

  • Target band: a correction between the two edges Low and High, of ±12 dB, visible on the spectrum.
  • Low cut / High cut: second-order biquads (12 dB/oct), whose quality factor Q is set by Res: Q = 0.707 gives a Butterworth response without a bump, above that a peak appears at the cut-off.
  • Mix: a dry/wet blend. The dry signal is delayed by the same latency, so as not to create any parasitic comb filter.
  • Safety limiter: a ceiling at −0.3 dBFS with 1.5 ms of lookahead. It sees the peak coming and lowers the gain smoothly, instead of clipping.

Order matters: the Drive is placed before the EQ and the filters, so the High cut can soften the harmonics the Drive has just added.

Next: Half a sample: autopsy of a defect nobody could hear, the story of a Doublure defect found by a measurement campaign.

8. References

  • A. de Cheveigné and H. Kawahara, “YIN, a fundamental frequency estimator for speech and music”, Journal of the Acoustical Society of America, 111(4), 2002, pp. 1917–1930.
  • E. Moulines and F. Charpentier, “Pitch-synchronous waveform processing techniques for text-to-speech synthesis using diphones”, Speech Communication, 9(5–6), 1990, pp. 453–467.
  • G. Fant, Acoustic Theory of Speech Production, Mouton, 1960: the source–filter model.
  • H. Haas, “The influence of a single echo on the audibility of speech”, Journal of the Audio Engineering Society, 20(2), 1972 (translation of the 1951 paper): the precedence effect.
  • G. L. Steele Jr., D. Lea and C. H. Flood, “Fast splittable pseudorandom number generators”, OOPSLA 2014: splitmix64.
  • U. Zölzer (ed.), DAFX: Digital Audio Effects, 2nd ed., Wiley, 2011: PSOLA, phase vocoder, saturation, filters.
  • J. O. Smith III, Spectral Audio Signal Processing, CCRMA, Stanford (online): OLA, windows, STFT.
  • J. Laroche and M. Dolson, “Improved phase vocoder time-scale modification of audio”, IEEE Transactions on Speech and Audio Processing, 7(3), 1999: for the comparison with PSOLA.
  • PolMax Studio, Doublure page and manual: /plugins/doublure/