FAILURE MAP
← Case archive

FA-81506 / MIDI event timing / Open access

SMPTE time-division ticks to microseconds: code 29 timed at 29 frames per second · case 01

Files using 29.97 fps timing run about 3.4% slow because each frame is taken as 1/29 second.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The rate code 29 is mapped to 29 frames per second instead of 30000/1001.

VERIFIED REPAIR

Restore the drop-frame rate step so that it reads `29: Fraction(30000, 1001)`.

Unsuccessful approach: Approximating 29.97 as 2997/100 drifts by about one frame per hour on long files.

Case contract

Input [division_high_byte, ticks_per_frame, ticks]. The high byte is a negative frame-rate code in two's complement: 24, 25, 29 (meaning 30000/1001 frames per second) or 30. Microseconds = ticks * 1000000 / (rate * ticks_per_frame), floored once. Invalid codes, non-positive ticks per frame or negative ticks return 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
    hi, tpf, ticks = x
    code = 256 - hi
    rates = {24: Fraction(24), 25: Fraction(25), 29: Fraction(29), 30: Fraction(30)}
    if code not in rates or tpf <= 0 or ticks < 0:
        return None
    return int(Fraction(ticks * 1000000) / (rates[code] * tpf))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([232, 40, 40], 41666), ([231, 40, 1000], 1000000), ([227, 80, 80], 33366), ([227, 80, 2400], 1001000), ([227, 4, 107892], 899999100), ([226, 100, 3000], 1000000), ([226, 100, 7], 2333), ([227, 100, 300000], 100100000)], [([227, 80, 2400], 1001000), ([227, 4, 107892], 899999100), ([226, 100, 7], 2333), ([232, 1, 1], 41666), ([231, 4, 3], 30000), ([227, 1, 29], 967633), ([233, 40, 40], None), ([228, 40, 40], None)], [([227, 4, 107892], 899999100), ([227, 1, 29], 967633), ([233, 40, 40], None), ([228, 40, 40], None), ([232, 0, 10], None), ([232, 40, -1], None), ([227, 80, 0], 0), ([227, 100, 300000], 100100000)], [([227, 80, 80], 33366), ([227, 80, 2400], 1001000), ([227, 4, 107892], 899999100), ([227, 1, 29], 967633), ([232, 40, -1], None), ([227, 80, 0], 0), ([226, 3, 1000001], 11111122222), ([227, 100, 300000], 100100000)], [([232, 40, 40], 41666), ([231, 40, 1000], 1000000), ([227, 80, 80], 33366), ([227, 80, 2400], 1001000), ([227, 4, 107892], 899999100), ([226, 100, 3000], 1000000), ([227, 1, 29], 967633), ([227, 100, 300000], 100100000)]]
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 fixtureActualExpectedOutcome
oracle 04166641666Passed
oracle 110000001000000Passed
oracle 23448233366Failed
oracle 310344821001000Failed
oracle 4930103448899999100Failed
oracle 510000001000000Passed
oracle 623332333Passed
oracle 7103448275100100000Failed

SHA-256 / e7fc591fc6569eb97100e0a9681fd7d9e40673e8a79ce6511cf84a08922af178

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
    hi, tpf, ticks = x
    code = 256 - hi
    rates = {24: Fraction(24), 25: Fraction(25), 29: Fraction(2997, 100), 30: Fraction(30)}
    if code not in rates or tpf <= 0 or ticks < 0:
        return None
    return int(Fraction(ticks * 1000000) / (rates[code] * tpf))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([232, 40, 40], 41666), ([231, 40, 1000], 1000000), ([227, 80, 80], 33366), ([227, 80, 2400], 1001000), ([227, 4, 107892], 899999100), ([226, 100, 3000], 1000000), ([226, 100, 7], 2333), ([227, 100, 300000], 100100000)], [([227, 80, 2400], 1001000), ([227, 4, 107892], 899999100), ([226, 100, 7], 2333), ([232, 1, 1], 41666), ([231, 4, 3], 30000), ([227, 1, 29], 967633), ([233, 40, 40], None), ([228, 40, 40], None)], [([227, 4, 107892], 899999100), ([227, 1, 29], 967633), ([233, 40, 40], None), ([228, 40, 40], None), ([232, 0, 10], None), ([232, 40, -1], None), ([227, 80, 0], 0), ([227, 100, 300000], 100100000)], [([227, 80, 80], 33366), ([227, 80, 2400], 1001000), ([227, 4, 107892], 899999100), ([227, 1, 29], 967633), ([232, 40, -1], None), ([227, 80, 0], 0), ([226, 3, 1000001], 11111122222), ([227, 100, 300000], 100100000)], [([232, 40, 40], 41666), ([231, 40, 1000], 1000000), ([227, 80, 80], 33366), ([227, 80, 2400], 1001000), ([227, 4, 107892], 899999100), ([226, 100, 3000], 1000000), ([227, 1, 29], 967633), ([227, 100, 300000], 100100000)]]
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 fixtureActualExpectedOutcome
oracle 04166641666Passed
oracle 110000001000000Passed
oracle 23336633366Passed
oracle 310010011001000Failed
oracle 4900000000899999100Failed
oracle 510000001000000Passed
oracle 623332333Passed
oracle 7100100100100100000Failed

SHA-256 / c62ceb163baa2ca6f19fc817e9e965ffd8d662ddaa837ec2ec785195cd22ed2e

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
    hi, tpf, ticks = x
    code = 256 - hi
    rates = {24: Fraction(24), 25: Fraction(25), 29: Fraction(30000, 1001), 30: Fraction(30)}
    if code not in rates or tpf <= 0 or ticks < 0:
        return None
    return int(Fraction(ticks * 1000000) / (rates[code] * tpf))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([232, 40, 40], 41666), ([231, 40, 1000], 1000000), ([227, 80, 80], 33366), ([227, 80, 2400], 1001000), ([227, 4, 107892], 899999100), ([226, 100, 3000], 1000000), ([226, 100, 7], 2333), ([227, 100, 300000], 100100000)], [([227, 80, 2400], 1001000), ([227, 4, 107892], 899999100), ([226, 100, 7], 2333), ([232, 1, 1], 41666), ([231, 4, 3], 30000), ([227, 1, 29], 967633), ([233, 40, 40], None), ([228, 40, 40], None)], [([227, 4, 107892], 899999100), ([227, 1, 29], 967633), ([233, 40, 40], None), ([228, 40, 40], None), ([232, 0, 10], None), ([232, 40, -1], None), ([227, 80, 0], 0), ([227, 100, 300000], 100100000)], [([227, 80, 80], 33366), ([227, 80, 2400], 1001000), ([227, 4, 107892], 899999100), ([227, 1, 29], 967633), ([232, 40, -1], None), ([227, 80, 0], 0), ([226, 3, 1000001], 11111122222), ([227, 100, 300000], 100100000)], [([232, 40, 40], 41666), ([231, 40, 1000], 1000000), ([227, 80, 80], 33366), ([227, 80, 2400], 1001000), ([227, 4, 107892], 899999100), ([226, 100, 3000], 1000000), ([227, 1, 29], 967633), ([227, 100, 300000], 100100000)]]
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 fixtureActualExpectedOutcome
oracle 04166641666Passed
oracle 110000001000000Passed
oracle 23336633366Passed
oracle 310010001001000Passed
oracle 4899999100899999100Passed
oracle 510000001000000Passed
oracle 623332333Passed
oracle 7100100000100100000Passed

SHA-256 / d64a026077c0108a989ae593472e8aded7580c984e8a5d91584a5799806062bf

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.739929+00:00.

Case digest / 4c765781ddad6c720e55f4e17abe54c62d61ac0956dea2c79984e05e335e9517