DC offset

Audio to MIDI with a DC offset: the rests come back as notes.

A recording that sits off centre turns every silence into sound as far as this converter is concerned. Measured on one six-note melody, an offset of 0.015 above zero — about −36 dBFS, well below anything you would call audible — added five notes that were never played, one per rest. Subtracting the recording's mean removed all five and left the six real notes untouched.

Select an audio file to create a MIDI draft locally.

The selected audio is decoded in your browser; it is not uploaded to a server.

This is the one failure on this site that cannot be blamed on the pitch estimator. A DC offset has no frequency at all — it is a constant added to every sample — so there is no note to mis-hear. What it changes is the first test the detector makes, before any pitch is computed: the loudness of a frame. Every gap in the file is supposed to be silence, the gate is supposed to reject it, and an offset lifts those gaps above the gate. The detector then does exactly what it was built to do with a frame that is loud enough, and reports a note.

Everything below comes from one melody, one detector and one variable. Same six notes, same lengths, same gaps, same five-partial timbre, same 44.1 kHz mono, same peak level; the only change is a constant added to every sample, gaps included.

Measured

Five rests, five extra notes, and the real six survive.

The baseline is the six-note phrase used across these tests, A3 to F4, each note 0.30 s with 0.10 s of digital silence between them, five partials at 1/h with a 5 ms attack and an exponential decay, peak 0.5. On a clean file it returns six notes, 57, 59, 60, 62, 64, 65, at all three sensitivity settings. That baseline reproduces on every run, which is what makes the offset the only thing that can explain what follows.

Offset addedLevel of the restsNotes returnedPitch sequence
00.0000657, 59, 60, 62, 64, 65
0.0050.0050657, 59, 60, 62, 64, 65
0.0100.0100657, 59, 60, 62, 64, 65
0.0150.0150657, 59, 60, 62, 64, 65
0.0200.02001157, 89, 59, 89, 60, 89, 62, 89, 64, 89, 65
0.0500.05001157, 89, 59, 89, 60, 89, 62, 89, 64, 89, 65
0.1200.12001157, 89, 59, 89, 60, 89, 62, 89, 64, 89, 65
0.3000.30001257, 89, 59, 89, 60, 89, 62, 89, 64, 89, 65, 89

The important column is the last one. All six real notes are still there, in the right order, at every offset tested — up to 0.300, which is 60% of the phrase's own amplitude. The extra events are interleaved, never substituted. That means a listener hears the melody correctly and sees a wrong file: the phrase plays, but the piano roll has five extra notes sitting in the rests, and every one of them is pitch 89.

Where they land is not random. Each phantom note begins where a real note ends and stops where the next real note begins, which is exactly the rest between them:

EventPitchStartsLengthSilence in the source
note 1570.000 s296 ms— (played)
phantom890.296 s93 ms0.30–0.40 s
note 2590.389 s308 ms— (played)
phantom890.697 s87 ms0.70–0.80 s
note 3600.789 s308 ms— (played)
phantom891.097 s87 ms1.10–1.20 s
note 4621.184 s313 ms— (played)
phantom891.503 s81 ms1.50–1.60 s
note 5641.585 s313 ms— (played)
phantom891.904 s81 ms1.90–2.00 s
note 6651.985 s313 ms— (played)

Every phantom is 81 to 93 ms long, and that length is not a property of the offset. It is the width of the gap: the extra event lasts as long as the silence it is standing in. A recording with longer rests gets longer phantom notes; one with no rests gets none, which is why a legato take can carry a large offset and still look clean.

Test conditions. Six notes, A3 220.00 / B3 246.94 / C4 261.63 / D4 293.66 / E4 329.63 / F4 349.23 Hz, each 0.30 s with 0.10 s of digital silence between, five partials at 1/h, 5 ms linear attack, exponential decay with a 1.2 /s rate, peak amplitude 0.5, 44.1 kHz mono. Offset added as a constant to every sample including the gaps, no clamping. Detector read from the shipped converter.js rather than re-implemented — frame 1,024, hop 256, lag 31–512, RMS gate 0.015 at Balanced, minimum note duration 75 ms. Log: localmidi-private/logs/dcoffset-2026-11-20.txt.

Mechanism

The gate is a level test, and an offset is level.

The detector does not look for notes. It looks at 1,024-sample frames, one every 256 samples, and asks two questions in order. First: is this frame louder than 0.015 RMS? If not, the frame is marked empty and nothing else happens to it. Second, only for frames that pass: which whole-sample delay makes the frame correlate best with itself? That delay is converted to a frequency and rounded to a MIDI number.

Silence fails the first question by definition. A gap of exactly zero samples has a level of exactly zero, so it is rejected and contributes nothing. Add a constant c to every sample and the gap is no longer zero: its level is now exactly c, because every sample in it has the same value. The first question is now answered by the value of the offset alone, and the answer flips at the gate constant itself.

That is visible as an exact number rather than a trend. Bisecting for the offset at which the seventh note first appears gives 0.015000 at Balanced — the gate constant to six decimal places. The same bisection at More notes lands on 0.00900, its own constant. The offset does not gradually degrade the result; it crosses a threshold that is written into the code.

SensitivityGate constantOffset that first adds a noteIn dBFS
More notes0.0090.00900−40.9
Balanced0.0150.01500−36.5
Fewer notes0.023none up to 0.300—

The third row is the interesting one, and it is not a threshold. Fewer notes swept from 0.023 all the way to 0.300 — twenty times the gate — returned six clean notes at every step, with no phantom at any offset. It is not resisting the offset. Its minimum note duration is 110 ms, every phantom on this melody is 81 to 93 ms long, and a burst shorter than the floor is discarded before the pitch is ever written. The setting is masked, not immune, and the mask is the length of the rests. Hold the offset at 0.05 and make only the gaps longer:

Rest lengthMore notesBalancedFewer notes
50 ms6, none6, none6, none
75 ms10, 4 phantoms6, none6, none
100 ms12, 6 phantoms11, 5 phantoms6, none
115 ms12, 6 phantoms12, 6 phantoms6, none
120 ms12, 6 phantoms12, 6 phantoms7, 1
150 ms12, 6 phantoms12, 6 phantoms12, 6
300 ms12, 6 phantoms12, 6 phantoms12, 6

Three settings, three different thresholds, and the ordering is not the one the labels suggest. At 50 ms rests nothing produces a phantom at any setting, because a gap that short never accumulates enough frames to clear the minimum duration. At 75 ms More notes is already at four phantoms while the other two are clean, so the loosest setting is the first to fail — it has the lowest gate, 0.009. Then Balanced fails somewhere between 75 and 100 ms, and Fewer notes holds out until 120 ms.

Bisecting that last one puts the break at exactly 120 ms, with the phantom it finally admits measuring 110 ms — the floor itself. Only 10 ms of margin above the floor is needed, because the phantom's length is set by the rest, not by the offset. A recording with short gaps is protected by accident; a recording with long gaps gets every phantom at every setting. That is why the slider is not a fix: it changes which files fail, not whether the fault is there.

Once a gap clears the gate, the second question produces 89 every time, and again this is arithmetic rather than a pitch. Correlation of a constant with itself over a window of N samples at a lag of L is (N−L)·c², which falls as L grows because fewer samples overlap. The best lag is therefore always the shortest one the search allows — 31 samples at 44.1 kHz — and 44,100 / 31 is 1,422.6 Hz, the nearest MIDI number to which is 89. Measured on a frame of pure offset, the correlation values run 0.0996 at lag 31, 0.0960 at 64, 0.0896 at 128, 0.0768 at 256 and 0.0512 at 512: monotone, with no peak anywhere. There is no pitch in the signal and the search still has to name one.

A gap is not the only thing this affects. Feed a file that contains no music at all — 1.5 s of pure digital silence — and the result is nothing at any offset up to 0.015. At 0.016 it returns one note, pitch 89, and it does so at 0.100 as well. Silence multiplied by gain stays silence; silence plus an offset does not. That is the difference between this failure and every level-related failure on the site: a quiet file can be fixed by turning it up, and an offset file cannot.

The fix

Subtract the mean, not more gain.

The repair is one line in any editor, and it works exactly because the defect is a constant. Take the file's average sample value and subtract it from every sample. On the same melody at an offset of 0.020 the estimate comes out at 0.019762, the residual mean after subtraction is 4.7×10−9, and the conversion returns six notes, 57, 59, 60, 62, 64, 65 — the clean baseline, with no repair to the pitches.

The tempting alternative is a high-pass filter, and it does work here, but the detail matters more than the fact. A single-pole high-pass at any cutoff from 1 Hz to 300 Hz removed all five phantom notes in this test, because even 1 Hz attenuates a constant over the length of a 2.5 s file. What the cutoff actually buys you is how fast the offset decays, and what it costs you is low-frequency content:

High-pass cutoffNotes returnedLoss at 220 HzLoss at 65.4 Hz
1 Hz6, all correct0.00 dB0.00 dB
20 Hz6, all correct0.04 dB0.39 dB
40 Hz6, all correct0.14 dB1.38 dB
80 Hz6, all correct0.54 dB3.97 dB

So the cutoff is not a free choice. 40 Hz costs a melody 0.14 dB and already takes 1.4 dB off a C2; 80 Hz takes 0.54 dB from the melody and 3.97 dB from the C2. For anything with a bass in it, subtracting the mean is the better tool because it has no frequency response to damage at all. The bass page covers the separate problem that low fundamentals have with this detector, which a DC removal does not touch.

Do not reach for the sensitivity slider. It moves the gate, so it appears to work, and it does work while the rests are short. On this melody at an offset of 0.120 the Fewer notes setting returned six clean notes — not because it rejected the offset, but because every phantom was 81 to 93 ms long and fell under its 110 ms floor. That is masking with an unrelated threshold, and it stops the moment the rests get long enough to produce a phantom past the floor: at 120 ms of silence it returns one, and at 150 ms it returns all six. The same table, read the other way, shows the loosest setting failing first — at 75 ms of silence More notes has four phantoms while the other two are still clean.

Diagnosis

How to tell this apart from hum, noise and a quiet take.

Three different faults produce extra notes in the rests, and the numbers that identify them are not the same. This matters because the fix is different for each, and because the pitch they produce is identical: all three land on 89.

FaultLevel that triggers itPhantom pitchHow to confirm
DC offsetAbsolute: 0.015 regardless of how loud the music is89The waveform never crosses zero symmetrically — zoom into a rest and the line sits off centre.
Mains humRelative: about 15 dB below the phrase's own level89Zoom into a rest and you see a 50 or 60 Hz wave, not a flat line.
Take too quietRelative: the music itself below 0.015— no phantoms, real notes vanishNothing in the rests; the melody is simply short or empty.

The distinction between the first two is worth stating precisely, because they look identical in the output. Hum is a signal with a frequency, so it is judged against the music: at 15 dB below the phrase it starts producing phantoms, and at 20 dB below it produces none. An offset has no frequency, so it is judged against an absolute constant: an offset of 0.020 produces phantoms on a phrase at peak 0.5 and on the same phrase 24 dB quieter, because the gaps in both are lifted to 0.020 either way. Lowering the recording level makes hum disappear and leaves a DC offset exactly as it was.

That is the check that separates them without any tooling. Measure a rest, not the music: if the rest reads a steady non-zero number that does not oscillate, it is an offset, and normalising or turning the file down will not touch it. If it oscillates at 50 or 60 Hz, it is hum, and the recording-prep page has the levels at which that starts producing phantoms.

One more reason not to fold this into the hum finding: a file can carry both, and the two do not add up. On the same melody, an offset of 0.020 alone returned eleven notes, a 50 Hz hum at 0.0366 RMS alone returned eleven notes, and both together returned eleven notes — not sixteen, not twenty-two. Each rest produces one phantom regardless of how many faults are present in it, because the phantom is a single event standing in for a period of time.

Limits

The limits of this test.

One melody, one register, one timbre. A3 to F4 with five partials. Nothing here establishes how an offset interacts with a low fundamental near the detector's floor, where the pitch estimate is already failing for its own reasons, or with a chord, where one pitch per frame is chosen by interval arithmetic. Both are separate failures that this test does not touch.

No real recording was measured. Every number above comes from a synthesised phrase with a constant added in code. That is the right way to isolate the variable and the wrong way to predict a specific file's offset: a real converter's offset drifts with temperature, and a real recording's offset is rarely a clean constant. The mechanism — a level gate that cannot tell a raised silence from a sound — is what generalises. The 0.015 figure is this detector's constant, not a property of audio in general.

The threshold is the gate, not a musical judgement. 0.015 is where Balanced sits. A different sensitivity moves the number to 0.009 or 0.023, and a different tool has its own gate entirely. What carries over is that the trigger is absolute and independent of programme level, so a quiet recording is not more at risk than a loud one.

Rests were digital silence. Exactly zero between the notes, which makes the arithmetic clean and the threshold exact. A real room is never silent, so a real file's rests already carry some level, and an offset adds to that rather than starting from zero. In that case the offset needed to cross the gate is smaller, not larger — but this test did not measure how much smaller, and the 0.015 figure should not be applied to a noisy file as if it were.

MP3 keeps it. Round-tripping the offset file through a 192 kbps MP3 and back to WAV left 97.0% of the offset in place at both 0.020 and 0.050, so re-encoding is not a fix. That figure is from one encoder at one bitrate on one signal.

Reproduction: node run-dcoffset.js regenerates the offset sweep and the pure-silence case; node run-dcoffset-fix.js the mean subtraction, the filter table and the two gate thresholds; node run-dcoffset-rests.js the rest-length table and the 120 ms break; node run-dcoffset-cross.js the level cross-table, the MP3 round trip and the hum comparison; node run-dcoffset-gain.js the gain-versus-offset test. node run-dcoffset.js --fixture writes the 0.020 test file used for the browser check. All five print the detector's sha256 on the first line.

Questions

DC offset and this converter

What is a DC offset, in one sentence?

A constant added to every sample of a recording, so the waveform is centred on a value other than zero. It has no frequency, so it is inaudible on its own, and it is visible as a waveform whose rests sit above or below the centre line instead of on it.

Why would that add notes that were never played?

Because the detector's first test is a loudness gate. A rest is normally rejected for being silent; an offset makes the rest loud enough to pass, and the detector then names a pitch for it. Measured: at an offset of 0.015 the six-note melody still returns six notes, and at 0.020 it returns eleven — five real notes plus five phantoms sitting one per rest.

Why are the extra notes all the same pitch?

Because there is no pitch in the signal to report. Correlation of a constant with itself is highest at the shortest delay the search tests, which is 31 samples at 44.1 kHz. That works out to 1,422.6 Hz, and the nearest MIDI number is 89. Every gap produces the same value for the same reason.

Will normalising or turning the file down fix it?

No. Normalising multiplies every sample and the offset is multiplied with it, so the gap stays exactly as far above zero in relative terms. Measured on a phrase 24 dB quieter than the baseline, an offset of 0.020 produced the same five phantoms. Subtracting the mean removes them; changing the level does not.

Is this the same thing as mains hum?

No, and the difference is the one that decides the fix. Hum is a signal with a frequency and is judged against the music's level, so it stops causing trouble when the recording is quiet enough. An offset has no frequency and is judged against an absolute constant, so it is unaffected by level. In the output both produce extra notes at pitch 89 and are indistinguishable without looking at a rest.

Does the Fewer notes setting solve it?

It can hide it, for the wrong reason, and only while the rests are short. It raises the gate to 0.023 and the minimum note length to 110 ms. Phantoms in this test were 81 to 93 ms long, so the length floor rejected them before the gate mattered. Measured at 0.05 of offset: 100 ms rests returned six clean notes, 120 ms returned one phantom, and 150 ms returned all six. Nothing in the setting addresses the offset.