FAILURE MAP
← Case archive

FA-81641 / MIDI event timing / Open access

14-bit pitch bend to cents: centre position reads as a small upward bend · case 01

The neutral bend (lsb 0, msb 64) reports a nonzero offset instead of exactly 0 cents at wide ranges.

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

ROOT CAUSE

The centre is taken as 8191 (the largest positive offset) instead of 8192.

VERIFIED REPAIR

Restore the centre value step so that it reads `value - 8192`.

Unsuccessful approach: Using 0x4000 (16384) puts the centre at the top of the range, so neutral reads as a full downward bend.

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 - 8191
    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, 96, 2], 100), ([0, 56, 1], -13), ([0, 40, 1], -38), ([0, 128, 2], None), ([128, 64, 2], None), ([0, 64, -1], None)], [([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, 56, 3], -38)], [([0, 0, 2], -200), ([0, 96, 2], 100), ([0, 32, 2], -100), ([0, 56, 1], -13), ([0, 24, 1], -63), ([0, 40, 1], -38), ([1, 64, 2], 0), ([127, 127, 48], 4800)], [([0, 96, 2], 100), ([0, 24, 1], -63), ([0, 40, 1], -38), ([1, 64, 2], 0), ([127, 63, 2], 0), ([0, 72, 12], 150), ([0, 56, 3], -38), ([0, 0, 48], -4800)], [([0, 32, 2], -100), ([0, 40, 1], -38), ([127, 63, 2], 0), ([0, 72, 12], 150), ([0, 56, 3], -38), ([127, 127, 12], 1200), ([127, 127, 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 fixtureActualExpectedOutcome
oracle 000Passed
oracle 1200200Passed
oracle 2100100Passed
oracle 3-12-13Failed
oracle 4-37-38Failed
oracle 5NoneNonePassed
oracle 6NoneNonePassed
oracle 7NoneNonePassed

SHA-256 / e31e3d75748b1ac6d77e910bc4c3c650817dc9870a88f736ab2f64c697d1b050

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 - 0x4000
    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, 96, 2], 100), ([0, 56, 1], -13), ([0, 40, 1], -38), ([0, 128, 2], None), ([128, 64, 2], None), ([0, 64, -1], None)], [([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, 56, 3], -38)], [([0, 0, 2], -200), ([0, 96, 2], 100), ([0, 32, 2], -100), ([0, 56, 1], -13), ([0, 24, 1], -63), ([0, 40, 1], -38), ([1, 64, 2], 0), ([127, 127, 48], 4800)], [([0, 96, 2], 100), ([0, 24, 1], -63), ([0, 40, 1], -38), ([1, 64, 2], 0), ([127, 63, 2], 0), ([0, 72, 12], 150), ([0, 56, 3], -38), ([0, 0, 48], -4800)], [([0, 32, 2], -100), ([0, 40, 1], -38), ([127, 63, 2], 0), ([0, 72, 12], 150), ([0, 56, 3], -38), ([127, 127, 12], 1200), ([127, 127, 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 fixtureActualExpectedOutcome
oracle 0-2000Failed
oracle 10200Failed
oracle 2-100100Failed
oracle 3-113-13Failed
oracle 4-138-38Failed
oracle 5NoneNonePassed
oracle 6NoneNonePassed
oracle 7NoneNonePassed

SHA-256 / 8303014fc83b74ca6e396f3013a873ca42d38f58785437c29c09109f734ac11f

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, 96, 2], 100), ([0, 56, 1], -13), ([0, 40, 1], -38), ([0, 128, 2], None), ([128, 64, 2], None), ([0, 64, -1], None)], [([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, 56, 3], -38)], [([0, 0, 2], -200), ([0, 96, 2], 100), ([0, 32, 2], -100), ([0, 56, 1], -13), ([0, 24, 1], -63), ([0, 40, 1], -38), ([1, 64, 2], 0), ([127, 127, 48], 4800)], [([0, 96, 2], 100), ([0, 24, 1], -63), ([0, 40, 1], -38), ([1, 64, 2], 0), ([127, 63, 2], 0), ([0, 72, 12], 150), ([0, 56, 3], -38), ([0, 0, 48], -4800)], [([0, 32, 2], -100), ([0, 40, 1], -38), ([127, 63, 2], 0), ([0, 72, 12], 150), ([0, 56, 3], -38), ([127, 127, 12], 1200), ([127, 127, 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 fixtureActualExpectedOutcome
oracle 000Passed
oracle 1200200Passed
oracle 2100100Passed
oracle 3-13-13Passed
oracle 4-38-38Passed
oracle 5NoneNonePassed
oracle 6NoneNonePassed
oracle 7NoneNonePassed

SHA-256 / ef71a63edc7e6a6ed56693f76b79fdad3cd5b975c033f979827f0573ee89db31

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

Case digest / 30aac3053af29128938c8b228995f80fc7c57a009a90f005f2a87f1502632401