FA-81651 / MIDI event timing / Open access
14-bit pitch bend to cents: cents truncated · case 01
A bend worth 12.5 cents reports 12 and fractional values always shrink toward zero.
ROOT CAUSE
The scaled magnitude is truncated instead of rounded half away from zero.
VERIFIED REPAIR
Restore the cent rounding step so that it reads `int(c + Fraction(1, 2))`.
Unsuccessful approach: Python round rounds exact halves to even, so 12.5 still becomes 12.
Case contract
Input [lsb, msb, range_semitones] with 7-bit data bytes. value = msb*128 + lsb, offset = value - 8192. Positive offsets scale to +range by dividing by 8191, negative ones by 8192. cents = offset * range * 100 / divisor, rounded half away from zero. Invalid bytes or negative range 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
lsb, msb, rng = x
if not all(isinstance(v, int) and 0 <= v <= 127 for v in (lsb, msb)) or rng < 0:
return None
value = (msb << 7) | lsb
offset = value - 8192
den = 8191 if offset > 0 else 8192
c = Fraction(abs(offset) * rng * 100, den)
cents = int(c)
return cents if offset >= 0 else -cents
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([0, 64, 2], 0), ([127, 127, 2], 200), ([0, 0, 2], -200), ([0, 96, 2], 100), ([0, 32, 2], -100), ([0, 56, 1], -13), ([0, 24, 1], -63), ([0, 40, 1], -38)], [([0, 96, 2], 100), ([0, 32, 2], -100), ([0, 56, 1], -13), ([0, 24, 1], -63), ([1, 64, 2], 0), ([127, 63, 2], 0), ([0, 72, 12], 150), ([0, 56, 3], -38)], [([0, 56, 1], -13), ([0, 24, 1], -63), ([0, 40, 1], -38), ([127, 63, 2], 0), ([0, 72, 12], 150), ([0, 128, 2], None), ([128, 64, 2], None), ([0, 88, 1], 38)], [([0, 56, 1], -13), ([0, 24, 1], -63), ([0, 56, 3], -38), ([128, 64, 2], None), ([0, 64, -1], None), ([127, 127, 12], 1200), ([0, 0, 12], -1200), ([64, 100, 2], 114)], [([0, 56, 1], -13), ([0, 24, 1], -63), ([0, 0, 12], -1200), ([64, 100, 2], 114), ([0, 88, 1], 38), ([127, 127, 48], 4800), ([0, 0, 48], -4800), ([100, 127, 48], 4784)]]
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 | 0 | 0 | Passed |
| oracle 1 | 200 | 200 | Passed |
| oracle 2 | -200 | -200 | Passed |
| oracle 3 | 100 | 100 | Passed |
| oracle 4 | -100 | -100 | Passed |
| oracle 5 | -12 | -13 | Failed |
| oracle 6 | -62 | -63 | Failed |
| oracle 7 | -37 | -38 | Failed |
SHA-256 / 546e8c4efb19cf092da35eacf84137da782134d12412489f9a78a9016a899668
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
lsb, msb, rng = x
if not all(isinstance(v, int) and 0 <= v <= 127 for v in (lsb, msb)) or rng < 0:
return None
value = (msb << 7) | lsb
offset = value - 8192
den = 8191 if offset > 0 else 8192
c = Fraction(abs(offset) * rng * 100, den)
cents = round(c)
return cents if offset >= 0 else -cents
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([0, 64, 2], 0), ([127, 127, 2], 200), ([0, 0, 2], -200), ([0, 96, 2], 100), ([0, 32, 2], -100), ([0, 56, 1], -13), ([0, 24, 1], -63), ([0, 40, 1], -38)], [([0, 96, 2], 100), ([0, 32, 2], -100), ([0, 56, 1], -13), ([0, 24, 1], -63), ([1, 64, 2], 0), ([127, 63, 2], 0), ([0, 72, 12], 150), ([0, 56, 3], -38)], [([0, 56, 1], -13), ([0, 24, 1], -63), ([0, 40, 1], -38), ([127, 63, 2], 0), ([0, 72, 12], 150), ([0, 128, 2], None), ([128, 64, 2], None), ([0, 88, 1], 38)], [([0, 56, 1], -13), ([0, 24, 1], -63), ([0, 56, 3], -38), ([128, 64, 2], None), ([0, 64, -1], None), ([127, 127, 12], 1200), ([0, 0, 12], -1200), ([64, 100, 2], 114)], [([0, 56, 1], -13), ([0, 24, 1], -63), ([0, 0, 12], -1200), ([64, 100, 2], 114), ([0, 88, 1], 38), ([127, 127, 48], 4800), ([0, 0, 48], -4800), ([100, 127, 48], 4784)]]
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 | 0 | 0 | Passed |
| oracle 1 | 200 | 200 | Passed |
| oracle 2 | -200 | -200 | Passed |
| oracle 3 | 100 | 100 | Passed |
| oracle 4 | -100 | -100 | Passed |
| oracle 5 | -12 | -13 | Failed |
| oracle 6 | -62 | -63 | Failed |
| oracle 7 | -38 | -38 | Passed |
SHA-256 / a6a287db0de85c093b807e7f6be2265b4997726189d15cac667d5750c5f10e29
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
lsb, msb, rng = x
if not all(isinstance(v, int) and 0 <= v <= 127 for v in (lsb, msb)) or rng < 0:
return None
value = (msb << 7) | lsb
offset = value - 8192
den = 8191 if offset > 0 else 8192
c = Fraction(abs(offset) * rng * 100, den)
cents = int(c + Fraction(1, 2))
return cents if offset >= 0 else -cents
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([0, 64, 2], 0), ([127, 127, 2], 200), ([0, 0, 2], -200), ([0, 96, 2], 100), ([0, 32, 2], -100), ([0, 56, 1], -13), ([0, 24, 1], -63), ([0, 40, 1], -38)], [([0, 96, 2], 100), ([0, 32, 2], -100), ([0, 56, 1], -13), ([0, 24, 1], -63), ([1, 64, 2], 0), ([127, 63, 2], 0), ([0, 72, 12], 150), ([0, 56, 3], -38)], [([0, 56, 1], -13), ([0, 24, 1], -63), ([0, 40, 1], -38), ([127, 63, 2], 0), ([0, 72, 12], 150), ([0, 128, 2], None), ([128, 64, 2], None), ([0, 88, 1], 38)], [([0, 56, 1], -13), ([0, 24, 1], -63), ([0, 56, 3], -38), ([128, 64, 2], None), ([0, 64, -1], None), ([127, 127, 12], 1200), ([0, 0, 12], -1200), ([64, 100, 2], 114)], [([0, 56, 1], -13), ([0, 24, 1], -63), ([0, 0, 12], -1200), ([64, 100, 2], 114), ([0, 88, 1], 38), ([127, 127, 48], 4800), ([0, 0, 48], -4800), ([100, 127, 48], 4784)]]
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 | 0 | 0 | Passed |
| oracle 1 | 200 | 200 | Passed |
| oracle 2 | -200 | -200 | Passed |
| oracle 3 | 100 | 100 | Passed |
| oracle 4 | -100 | -100 | Passed |
| oracle 5 | -13 | -13 | Passed |
| oracle 6 | -63 | -63 | Passed |
| oracle 7 | -38 | -38 | Passed |
SHA-256 / fb8896cfa96ca11ba0e5b9547ef6dff1e0b8f65cb4393fb166d7f710c504af8d
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:05.037643+00:00.
Case digest / c4bd0678d41d632f5f79c87fe89ae8f13557e31607fa52f9b70f691618fb388e