FA-81471 / MIDI event timing / Open access
Tick to microsecond conversion through a tempo map: each tempo segment floored separately · case 01
Long files with many tempo changes drift early: fractional microseconds are discarded at every segment boundary.
ROOT CAUSE
Each completed segment is integer-divided before being added instead of flooring the exact total once.
VERIFIED REPAIR
Restore the rounding stage step so that it reads `total += Fraction((t - tick) * tempo, ppq)`.
Unsuccessful approach: Rounding each segment to nearest still quantises per segment, drifting in the other direction.
Case contract
Input [ppq, changes, tick] where changes are [tick, microseconds_per_quarter] in any order (a later entry at the same tick overrides an earlier one). Before the first change the tempo is 500000. Each tempo applies from its tick onward. Sum the exact time of each segment and floor once at the end. Invalid ppq or negative tick returns None.
Why this case matters
MIDI sequencers, file readers and synth drivers depend on exact event ordering and tick/time arithmetic.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
if not isinstance(x, list) or len(x) != 3:
return None
ppq, changes, target = x
if ppq <= 0 or target < 0:
return None
tempo_at = {}
for t, us in changes:
tempo_at[t] = us
points = sorted(tempo_at.items())
total = Fraction(0)
tick = 0
tempo = 500000
for t, us in points:
if t >= target:
break
total += (t - tick) * tempo // ppq
tick = t
tempo = us
total += Fraction((target - tick) * tempo, ppq)
return int(total)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([480, [], 480], 500000), ([480, [], 1], 1041), ([96, [[0, 600000]], 96], 600000), ([480, [[480, 250000]], 960], 750000), ([480, [[960, 1000000], [480, 250000]], 1440], 1750000), ([7, [[3, 333333]], 10], 547618), ([7, [[1, 100001], [2, 200003]], 5], 171430), ([11, [[5, 777777], [9, 123457]], 13], 554994)], [([480, [[480, 250000]], 960], 750000), ([480, [[960, 1000000], [480, 250000]], 1440], 1750000), ([7, [[3, 333333]], 10], 547618), ([480, [[0, 400000], [0, 300000]], 480], 300000), ([480, [[240, 300000], [240, 200000]], 480], 350000), ([3, [[1, 1000]], 2], 167000), ([480, [[480, 250000]], 480], 500000), ([13, [[4, 499999], [8, 333337]], 12], 410257)], [([7, [[3, 333333]], 10], 547618), ([7, [[1, 100001], [2, 200003]], 5], 171430), ([480, [[240, 300000], [240, 200000]], 480], 350000), ([480, [[480, 250000]], 480], 500000), ([0, [], 10], None), ([480, [], -1], None), ([480, [[100, 100000]], 50], 52083), ([11, [[5, 777777], [9, 123457]], 13], 554994)], [([7, [[3, 333333]], 10], 547618), ([3, [[1, 1000]], 2], 167000), ([480, [], -1], None), ([480, [[100, 100000]], 50], 52083), ([480, [[0, 1000000], [480, 500000]], 720], 1250000), ([480, [[0, 300000], [0, 400000]], 480], 400000), ([7, [[2, 300001], [2, 400003]], 6], 371430), ([13, [[4, 499999], [8, 333337]], 12], 410257)], [([480, [], 480], 500000), ([7, [[3, 333333]], 10], 547618), ([7, [[1, 100001], [2, 200003]], 5], 171430), ([3, [[1, 1000]], 2], 167000), ([11, [[5, 777777], [9, 123457]], 13], 554994), ([480, [[0, 300000], [0, 400000]], 480], 400000), ([7, [[2, 300001], [2, 400003]], 6], 371430), ([13, [[4, 499999], [8, 333337]], 12], 410257)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| oracle 0 | 500000 | 500000 | Passed |
| oracle 1 | 1041 | 1041 | Passed |
| oracle 2 | 600000 | 600000 | Passed |
| oracle 3 | 750000 | 750000 | Passed |
| oracle 4 | 1750000 | 1750000 | Passed |
| oracle 5 | 547618 | 547618 | Passed |
| oracle 6 | 171428 | 171430 | Failed |
| oracle 7 | 554993 | 554994 | Failed |
SHA-256 / ede5c610270e2d5e38d4408e3208e22fe4531e46daec4637599e0fd490caaebc
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
if not isinstance(x, list) or len(x) != 3:
return None
ppq, changes, target = x
if ppq <= 0 or target < 0:
return None
tempo_at = {}
for t, us in changes:
tempo_at[t] = us
points = sorted(tempo_at.items())
total = Fraction(0)
tick = 0
tempo = 500000
for t, us in points:
if t >= target:
break
total += round(Fraction((t - tick) * tempo, ppq))
tick = t
tempo = us
total += Fraction((target - tick) * tempo, ppq)
return int(total)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([480, [], 480], 500000), ([480, [], 1], 1041), ([96, [[0, 600000]], 96], 600000), ([480, [[480, 250000]], 960], 750000), ([480, [[960, 1000000], [480, 250000]], 1440], 1750000), ([7, [[3, 333333]], 10], 547618), ([7, [[1, 100001], [2, 200003]], 5], 171430), ([11, [[5, 777777], [9, 123457]], 13], 554994)], [([480, [[480, 250000]], 960], 750000), ([480, [[960, 1000000], [480, 250000]], 1440], 1750000), ([7, [[3, 333333]], 10], 547618), ([480, [[0, 400000], [0, 300000]], 480], 300000), ([480, [[240, 300000], [240, 200000]], 480], 350000), ([3, [[1, 1000]], 2], 167000), ([480, [[480, 250000]], 480], 500000), ([13, [[4, 499999], [8, 333337]], 12], 410257)], [([7, [[3, 333333]], 10], 547618), ([7, [[1, 100001], [2, 200003]], 5], 171430), ([480, [[240, 300000], [240, 200000]], 480], 350000), ([480, [[480, 250000]], 480], 500000), ([0, [], 10], None), ([480, [], -1], None), ([480, [[100, 100000]], 50], 52083), ([11, [[5, 777777], [9, 123457]], 13], 554994)], [([7, [[3, 333333]], 10], 547618), ([3, [[1, 1000]], 2], 167000), ([480, [], -1], None), ([480, [[100, 100000]], 50], 52083), ([480, [[0, 1000000], [480, 500000]], 720], 1250000), ([480, [[0, 300000], [0, 400000]], 480], 400000), ([7, [[2, 300001], [2, 400003]], 6], 371430), ([13, [[4, 499999], [8, 333337]], 12], 410257)], [([480, [], 480], 500000), ([7, [[3, 333333]], 10], 547618), ([7, [[1, 100001], [2, 200003]], 5], 171430), ([3, [[1, 1000]], 2], 167000), ([11, [[5, 777777], [9, 123457]], 13], 554994), ([480, [[0, 300000], [0, 400000]], 480], 400000), ([7, [[2, 300001], [2, 400003]], 6], 371430), ([13, [[4, 499999], [8, 333337]], 12], 410257)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| oracle 0 | 500000 | 500000 | Passed |
| oracle 1 | 1041 | 1041 | Passed |
| oracle 2 | 600000 | 600000 | Passed |
| oracle 3 | 750000 | 750000 | Passed |
| oracle 4 | 1750000 | 1750000 | Passed |
| oracle 5 | 547619 | 547618 | Failed |
| oracle 6 | 171430 | 171430 | Passed |
| oracle 7 | 554994 | 554994 | Passed |
SHA-256 / 09f2a5ea579bc88ce18301db9cf02a5d257d1b57e049d39c188beb7f2f1ab2ec
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
if not isinstance(x, list) or len(x) != 3:
return None
ppq, changes, target = x
if ppq <= 0 or target < 0:
return None
tempo_at = {}
for t, us in changes:
tempo_at[t] = us
points = sorted(tempo_at.items())
total = Fraction(0)
tick = 0
tempo = 500000
for t, us in points:
if t >= target:
break
total += Fraction((t - tick) * tempo, ppq)
tick = t
tempo = us
total += Fraction((target - tick) * tempo, ppq)
return int(total)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([480, [], 480], 500000), ([480, [], 1], 1041), ([96, [[0, 600000]], 96], 600000), ([480, [[480, 250000]], 960], 750000), ([480, [[960, 1000000], [480, 250000]], 1440], 1750000), ([7, [[3, 333333]], 10], 547618), ([7, [[1, 100001], [2, 200003]], 5], 171430), ([11, [[5, 777777], [9, 123457]], 13], 554994)], [([480, [[480, 250000]], 960], 750000), ([480, [[960, 1000000], [480, 250000]], 1440], 1750000), ([7, [[3, 333333]], 10], 547618), ([480, [[0, 400000], [0, 300000]], 480], 300000), ([480, [[240, 300000], [240, 200000]], 480], 350000), ([3, [[1, 1000]], 2], 167000), ([480, [[480, 250000]], 480], 500000), ([13, [[4, 499999], [8, 333337]], 12], 410257)], [([7, [[3, 333333]], 10], 547618), ([7, [[1, 100001], [2, 200003]], 5], 171430), ([480, [[240, 300000], [240, 200000]], 480], 350000), ([480, [[480, 250000]], 480], 500000), ([0, [], 10], None), ([480, [], -1], None), ([480, [[100, 100000]], 50], 52083), ([11, [[5, 777777], [9, 123457]], 13], 554994)], [([7, [[3, 333333]], 10], 547618), ([3, [[1, 1000]], 2], 167000), ([480, [], -1], None), ([480, [[100, 100000]], 50], 52083), ([480, [[0, 1000000], [480, 500000]], 720], 1250000), ([480, [[0, 300000], [0, 400000]], 480], 400000), ([7, [[2, 300001], [2, 400003]], 6], 371430), ([13, [[4, 499999], [8, 333337]], 12], 410257)], [([480, [], 480], 500000), ([7, [[3, 333333]], 10], 547618), ([7, [[1, 100001], [2, 200003]], 5], 171430), ([3, [[1, 1000]], 2], 167000), ([11, [[5, 777777], [9, 123457]], 13], 554994), ([480, [[0, 300000], [0, 400000]], 480], 400000), ([7, [[2, 300001], [2, 400003]], 6], 371430), ([13, [[4, 499999], [8, 333337]], 12], 410257)]]
for i, (args, expected) in enumerate(fixtures[N-1]):
check("oracle %d" % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| oracle 0 | 500000 | 500000 | Passed |
| oracle 1 | 1041 | 1041 | Passed |
| oracle 2 | 600000 | 600000 | Passed |
| oracle 3 | 750000 | 750000 | Passed |
| oracle 4 | 1750000 | 1750000 | Passed |
| oracle 5 | 547618 | 547618 | Passed |
| oracle 6 | 171430 | 171430 | Passed |
| oracle 7 | 554994 | 554994 | Passed |
SHA-256 / 15236f05ab34005e7a482f2287f8c0550017a5ff5718e2df14ccf9e49b21ffba
Verification & scope
A deterministic bounded teaching model with a stipulated toy contract; it is not a complete Standard MIDI File or MIDI 1.0/2.0 implementation. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:50:03.196471+00:00.
Case digest / 7ffc9bdeb2cc9b970d985a51d54198111f18a044906d31ce4e9d34de5d639467