Half a sample: autopsy of a defect nobody could hear
How a blind audit found, in Doublure, a rounding remainder that detuned the double — and why it sounded rather good
Ultra-GeekWritten with the help of AI
Ultra-Geek · A follow-up to Doublure — under the hood: the story of a defect in Doublure, from its discovery by a measurement campaign to its fix in version 2.0.0. To use the plugin, the manual is enough.
Doublure makes a second voice from yours. It follows the sung pitch frame by frame, cuts the signal into one-period grains, and pastes them back, shifted slightly in time and in pitch. It is TD-PSOLA, a technique that is forty years old and works very well as long as you count right.
For months, Doublure did not count right. Half a sample, at worst, every period. Nobody heard it as a defect, not even the author of the code. Here is how it was found, and why it was so hard to see.
An auditor who cannot see the code
The starting idea was simple: have the plugin measured by someone who had not written the code. Not a review — a measurement campaign, with a test bench, test signals and numerical criteria fixed in advance.
The set-up: a separate working session, isolated from the repository, which receives only compiled binaries and written instructions. It builds its own bench, hosts the plugin as a VST3, sends it signals and analyses the outputs. It cannot read the code. It cannot fix anything. It measures, it reports, and it is entitled to contradict.
That last clause was used more often than expected.
The first clue: 12 dB instead of 40
The first criterion of the campaign is called PSOLA identity. The idea: if you set the plugin so that the double is an exact copy of the voice — no delay, no detuning, no variation — then subtracting the two signals should leave almost nothing. You measure the ratio between the signal and that residual. Above 40 dB, the resynthesis chain is clean.
On a real voice, the bench measured 11 to 12 dB.
The result is very far from the target. A residual 12 dB below the signal means a double that differs from the original by about a quarter of its amplitude. And yet, listening, nothing unusual.
Three false leads
Before reaching the defect, the campaign lost time on three mistakes, two of which stem from the initial design of the audit.
The test signal. A Dirac impulse had been proposed to excite the chain. Unsuitable choice: a pitch detector has nothing to detect on an impulse, and the result says nothing about real behaviour.
The factory settings. The Tone parameter was at 30 % by default and coloured the residual. It had to be neutralised before any identity measurement — which was written nowhere.
A measurement error in the bench itself, which it diagnosed and corrected on its own.
Once these three points were settled, the residual went back up — but not everywhere in the same way. And it is this asymmetry that opened everything.
The decomposition that changes everything
On a fixed-pitch signal, the residual falls to 55.8 dB. Nominal value. On a variable-pitch signal, it stays at 12 dB.
This difference says something precise: the double is not deformed, it is shifted. It is the original voice, affected by a slowly changing delay. Subtract a signal from itself with a delay of a fraction of a sample and you get exactly that residual — without any information being lost.
So far, no bug. A PSOLA that follows a variable pitch must move its grains; that is its job. The question became: is this shift a back-and-forth around zero, as it should be, or a drift going in one direction?
A formula, and a signature
The plugin detects a period P in samples, which is P = fₛ / f₀. For 130 Hz at 48 kHz, that is 369.23 samples. A period is almost never a whole number.
If the code rounds this period before emitting the next grain, it loses the remainder. The grain lands 0.23 sample too early, every period, 130 times a second. The drift is then:
This formula has a remarkable signature: it vanishes exactly when f₀ divides fₛ. At 48 kHz and in the sung range, that happens seventeen times: at 100 Hz, 120, 125, 128, 150, 160, 192, 200, 240, 250, 300, 320, 375, 384, 400, 480 and 500 Hz. Between these pitches, the drift climbs back abruptly.
No acoustic phenomenon does that. No bench artefact either. If the measurement follows this sawtooth, it is integer arithmetic, and nothing else.
The campaign measured thirteen pitches spread over nearly two octaves. The sawtooth was there.
The corrected model — by the session that was measuring
The initial model used ⌊P⌋: the plugin truncated the period. It matched at four points out of six.
The measurement session added two frequencies, chosen because their fractional part exceeded 0.5 — 143 Hz and 187 Hz — and showed that the sign of the detuning reversed where the initial model predicted it should not. Then it proposed the right form:
The code did not round the period. It added the remainder to a value that already contained it. Writing e = P − round(P), the emission period is P + e, and the detuning of the double is written:
On the nine pitches where prediction and measurement can be compared point by point, the median deviation is 0.07 cent.
The only three notable deviations — 0.14, 0.15 and 0.22 cent — all fall on the pitches where e is exactly half a sample. That is precisely where rounding has no stable choice: it flips from one integer to the other from one frame to the next. The model is right on average there, and undecided in detail, which is exactly what you expect of it.
What a lost remainder really does
A remainder of 0.23 sample looks negligible. It is not, because it comes back every period and it adds up.
After one second of a held note at 130 Hz, the double is thirty samples late. After four seconds, a hundred and twenty — two and a half milliseconds. The offset you had set at 18 ms becomes 20.5 at the end of the note, and it keeps growing as long as the note lasts. At worst, and in the high register, it is four times as much: nearly 21 ms of slide over a four-second note at 500 Hz.
And that is only the first of the three symptoms. The same remainder also produces:
- a permanent detuning of 0.018 × f₀ cents at worst — 2.3 cents for a man’s voice at 130 Hz, 9 cents for a high note at 500 Hz;
- a pitch warble when the note crosses a zone where rounding flips: the double then jumps between two opposite detunings, that is 0.036 × f₀ cents peak to peak.
Everything grows with the sung pitch, because the higher the note, the more periods per second there are to accumulate the same remainder.
Two windows that did not drift
The sweep delivered an anomaly: two windows a few tenths of a hertz wide, around 399 Hz, where the drift vanished even though the period was not a whole number there. The model did not account for them.
It disappeared with the fix, like the rest. But the reason why these two windows behaved correctly was never established: it would take reading the code of the time, and nobody did. It is the only point of this investigation that remains open, and it is more honest to say so than to invent a retrospective explanation for it.
One line, and zeros
The principle of the fix fits in one sentence: the read position is kept as a fractional value, and the signal is interpolated at that exact position. There is no rounding any more, so no remainder to lose or to count twice.
The three quantities that carried the defect fall to zero — measured zero, not rounded zero. The residual period warble of 0.013 cent rms is the bench’s noise floor.
Why nobody heard it
This section is the most instructive, and it comes down to two reasons.
The first: it appeared and disappeared within a fraction of a hertz. Sing an A at 220 Hz, the double is 1.4 cent too low. Go up by two tenths of a hertz, to 220.2: it is perfectly in tune. Go down to 219.5: it is 2.5 cents too high. Three quarters of a hertz separate these three situations — far less than the vibrato of any singer. No listening, however attentive, can tell the difference between that and a double that breathes.
The second, more awkward: part of the defect sounded good. A detuning of two or three cents that changes with pitch is the definition of a chorus. A delay that slowly lengthens over a held note is a very slow flanger effect. Both are effects you look for on a doubled voice. The defect was not heard as a defect because, on many sources, it resembled a quality.
This is exactly why the ear does not replace measurement. It does not tell you where what it likes comes from. And an effect you did not write is an effect you do not control: here it depended on the sung note, on the sample rate of the session, and on nothing the user could set. At 44.1 kHz, the clean pitches are no longer the same. The same singer, the same setting, a project imported into another session: another result.
What the audit got wrong about itself
An audit that only publishes its successes is not worth much. Here is the liability side, mostly attributable to the initial design of the audit.
Five badly set statistical thresholds. Some criteria had been set in such a way that no correct plugin could have passed them, others in such a way that a faulty plugin passed them easily. A flatness threshold of 1 dB that was arithmetically impossible to meet. A root-mean-square value used on a heavy-tailed distribution, where only the median made sense. A stratification that counted frames where the statistical unit was the note — three to twelve observations per class, not a thousand. And an uncertainty computed on the ideal noise of the estimator rather than on the real dispersion of the measurements: underestimated by a factor of twelve.
The common cause is the same each time: the theoretical noise of the instrument was taken in place of the observed dispersion of the system. It is a classic mistake, and the more readily made the better one knows the theory.
A wrong prediction that gave the right result. A random walk of about forty samples had been announced at the rounding flip points. The bench measured 0.3. The gap was so large that the calculation had to be redone — and it was in redoing it that it appeared that a strict alternation bounds the error to half a sample, which pointed to the accumulator. The wrong prediction produced the right mechanism, because it was wrong in a measurable way.
A contradiction between the two sessions, and a third culprit. One claimed that a blocking call came from the plugin during real-time processing; the other swore that this code did not exist. Both were right: the call came from the statically linked VST3 wrapper, which neither had inspected.
And the bench was wrong about itself, twice: a stack frame taken for a call stack, and a filter that blamed the plugin for the locks of its own test host. It found and fixed them without being asked.
What follows from it
The defect had been in the code since 1.2.0. The audit measured it on 1.5.0 and 1.5.8, it was fixed in 1.6.0, and verified null on 1.7.1. It survived dozens of hours of listening and an author who knew perfectly well what a period rounding is — because it could not be heard, and above all because what could be heard was pleasant.
It was found by a formula that fits on one line, whose only virtue was a signature impossible to mistake for anything else: a drift that vanishes exactly when the frequency divides the sample rate. Once that signature was present in the measurements, the discussion was closed.
The fix is available in Doublure 2.0.0.