AUDIO TO MIDI / SWUNG NOTE TIMING
Audio to MIDI for a swung melody
Check the offbeat starts before quantizing a converted melody. A readable MIDI download can keep the pitch sequence while changing the long and short gaps that give a phrase its swing.
What our control returned. Both synthetic WAVs produced all eight programmed pitches. But the swung input's first two gaps, one third and one sixth of a second, came back as two equal gaps of approximately 0.255208 seconds. This converter did not preserve that constructed swing pair.
Same pitches and tempo, different offbeats
We programmed two format-0 MIDI files with one track and 480 ticks per quarter note. Both contain C4, D4, E4, G4, A4, G4, E4 and C4. Every keyed note lasts 150 ticks. Both set the same tempo event: 500,000 microseconds per quarter note, equivalent to 120 BPM because 60,000,000 ÷ 500,000 = 120. The timing arrays, files and hashes are available below.
The straight starts are 0, 240, 480, 720, 960, 1200, 1440 and 1680 ticks. The swung starts are 0, 320, 480, 800, 960, 1280, 1440 and 1760 ticks. Each offbeat moves 80 ticks later while the following beat stays in place. In seconds, the change is 80 ÷ 480 × 500,000 ÷ 1,000,000 = approximately 0.083333 seconds. This is a deliberately fixed two-to-one pattern, not a model of every swung performance.
For the first three notes, the straight intervals are 240 and 240 ticks. The swung intervals are 320 and 160 ticks: 320 ÷ 160 = 2. At the declared tempo these become one third and one sixth of a second. The ratio describes note starts; it is not the ratio of how long the keys stay down.
How the WAVs and downloads were obtained
We ran the exact parseMidi, synth and wav functions from Midilot's production audio helper locally in a Node runtime. Both inputs used the same sine setting and envelope. This rendered eight pitched notes in each file. The straight WAV contains 53,058 frames and the swung WAV 54,896 frames, both mono 16-bit PCM at 22,050 Hz. Their durations are frame count ÷ sample rate: approximately 2.406259 and 2.489615 seconds. The buffer includes the renderer's tail allocation.
The MIDI picker in the browser renderer did not open during this session. We therefore used the production renderer code locally, rather than reporting a successful browser render. We then selected each resulting WAV on the live WAV-to-MIDI page in Chrome, with MIDI tempo set to 120 BPM and the final-release estimate enabled. Both conversions completed. Their native download links saved separate 119-byte MIDI files, which we parsed independently from their bytes. The calculations below use those downloaded events, not the rounded note-list display.
The pitch sequence survived; the spacing changed
Each output contains the eight programmed pitches in order, with one track, 480 ticks per quarter note and a 500,000-microsecond tempo event. That establishes matching pitch order in these controls. It does not establish matching note attacks or durations.
| Note | Straight input | Straight output | Swung input | Swung output |
|---|---|---|---|---|
| C4 | 0.000000 | 0.000000 | 0.000000 | 0.000000 |
| D4 | 0.250000 | 0.209375 | 0.333333 | 0.255208 |
| E4 | 0.500000 | 0.464583 | 0.500000 | 0.510417 |
| G4 | 0.750000 | 0.719792 | 0.833333 | 0.766667 |
| A4 | 1.000000 | 0.952083 | 1.000000 | 0.998958 |
| G4 | 1.250000 | 1.207292 | 1.333333 | 1.254167 |
| E4 | 1.500000 | 1.462500 | 1.500000 | 1.532292 |
| C4 | 1.750000 | 1.694792 | 1.833333 | 1.764583 |
The swung output begins at 0, approximately 0.255208 and 0.510417 seconds for C4, D4 and E4. Its first interval is 245 ÷ 480 × 0.5 = approximately 0.255208 seconds. Its second interval uses the same 245 ticks. Their measured ratio is therefore 245 ÷ 245 = 1, compared with the programmed 320 ÷ 160 = 2. Later pairs also have timing errors; this is not simply the original phrase shifted as a whole.
Comparing corresponding offbeats between the two output files gives swung start minus straight start of approximately 0.045833, 0.046875, 0.046875 and 0.069792 seconds. The programmed difference was approximately 0.083333 seconds at each of those positions. These four comparisons use notes two, four, six and eight, rather than treating the entire file length as evidence of swing.
Across all eight corresponding starts, mean absolute onset error is the sum of |output start − programmed start| divided by eight. The straight error sum is 0.289583333 seconds, giving approximately 0.036198 seconds. The swung sum is 0.336458333 seconds, giving approximately 0.042057 seconds. Every input value is preserved in the JSON. These measurements describe this pair, not an accuracy rate for jazz, vocals or finished songs.
Review the offbeats before applying a grid
Keep an unchanged download
Save the first MIDI and the source audio before editing. Align a clear beat in your editor, then inspect the offbeat notes as well as the beat notes. A correct pitch list is only one part of this check.
Compare local intervals
Look at three neighboring starts: the beat, its offbeat and the next beat. Compare both gaps with the recording. The fixed ratio in our input is a diagnostic; do not impose it on a performance whose phrasing varies.
Correct timing against the recording
Move or split the affected notes in your MIDI editor, keeping a copy of the original. Applying a straight grid to an uneven source deliberately changes its timing. We did not test a particular DAW or an automatic swing correction workflow.
The tempo field does not choose a swing pattern
In the current export implementation, tempo = round(60,000,000 ÷ BPM), ticks per second = 480,000,000 ÷ tempo, and start tick = round(detected start seconds × ticks per second). At 120 BPM this is 960 ticks per second. The writer rounds detected times to integer MIDI ticks; it does not snap each note to an eighth-note grid or select a two-to-one swing template. This is source analysis, not a measurement of internal detector frames.
The downloaded swung starts of 245 and 490 ticks are therefore the events actually written for the second and third notes. We did not isolate which detection or decoding stage caused their differences from the programmed 320 and 480 ticks. Changing the tempo label or assuming every timing error has one common offset would not establish the intended starts.
Inspect the controls and actual results
- Straight reference MIDI
- Swung reference MIDI
- Straight rendered WAV
- Swung rendered WAV
- Actual straight transcription
- Actual swung transcription
Hashes, all MIDI events, formula inputs and outcomes · Rebuild the WAVs from the reference MIDI and current audio helper
A question before quantizing
Does a MIDI file marked 120 BPM prove that swing was preserved?
Editorial question. No. Both of our downloads contain the expected 120 BPM tempo event, but the swung file's first pair of gaps is equal. Check the individual note starts against the source. The tempo metadata and a correct pitch sequence did not establish the intended long-short spacing in this run.
Where this evidence stops
These are two programmed sine-tone controls, not human performances. The source files share the same pitches, keyed lengths and synthesis settings; their planned offbeat positions differ. We tested one production conversion of each WAV and independently read the downloaded MIDI. We did not benchmark other converters, test a DAW import, measure a singer's swing, or establish a universal swing ratio. Key durations and synthesis tails also affect the signal presented to the detector. Keep these downloadable controls as a reproducible timing check, and judge a real transcription against its own recording.
For the complete conversion workflow, see how to convert audio to MIDI. For a separate comparison of two source tempos, read the tempo-matched loop test.