FAILURE MAP
← Case archive

FA-78666 / Broadcast timecode arithmetic / Open access

Audio sample to frame cadence at 48 kHz: frame index · case 01

Samples in the second half of a frame are attributed to the next frame.

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

ROOT CAUSE

The frame index is rounded to nearest instead of floored.

VERIFIED REPAIR

Floor the sample position in frames.

Unsuccessful approach: Dividing by a truncated whole number of samples per frame drifts at NTSC rates.

Case contract

At 48000 samples per second and rate N/D, the frame containing sample s is floor(s*N/(48000*D)); frame k starts at sample ceil(k*48000*D/N). Return [frame, offset of s inside its frame, number of samples in that frame].

Why this case matters

Timecode arithmetic errors misplace edits, commercial breaks and captions against the broadcast clock.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(sample, rate):
    num,den={'23.976':(24000,1001),'24':(24,1),'25':(25,1),'29.97':(30000,1001),'30':(30,1)}[rate]
    frame=(sample*num+24000*den)//(48000*den)
    start=-(-frame*48000*den//num)
    return [frame,sample-start,-(-(frame+1)*48000*den//num)-start]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: frame index', [1601, '29.97'], [0, 1601, 1602]), ('regression variant: frame index', [1602, '23.976'], [0, 1602, 2002]), ('partial repair probe: frame index', [5867905, '29.97'], [3663, 1244, 1602]), ('partial repair variant: frame index', [8247925, '29.97'], [5149, 1286, 1601]), ('boundary control', [1602, '29.97'], [1, 0, 1602]), ('boundary control', [2002, '23.976'], [1, 0, 2002]), ('normal control', [3204, '29.97'], [2, 0, 1601]), ('normal control', [1919, '29.97'], [1, 317, 1602]), ('normal control', [1920, '30'], [1, 320, 1600])], [('regression: frame index', [1602, '24'], [0, 1602, 2000]), ('regression variant: frame index', [1601, '25'], [0, 1601, 1920]), ('partial repair probe: frame index', [8007, '29.97'], [4, 1600, 1601]), ('partial repair variant: frame index', [5303585, '29.97'], [3311, 687, 1602]), ('boundary control', [3204, '29.97'], [2, 0, 1601]), ('boundary control', [1602, '29.97'], [1, 0, 1602]), ('normal control', [8008, '25'], [4, 328, 1920]), ('normal control', [0, '25'], [0, 0, 1920]), ('normal control', [8008, '29.97'], [5, 0, 1602])], [('regression: frame index', [1600, '25'], [0, 1600, 1920]), ('regression variant: frame index', [1920, '23.976'], [0, 1920, 2002]), ('partial repair probe: frame index', [3494632, '29.97'], [2181, 1542, 1602]), ('partial repair variant: frame index', [8735595, '29.97'], [5454, 468, 1601]), ('boundary control', [1920, '25'], [1, 0, 1920]), ('boundary control', [3204, '29.97'], [2, 0, 1601]), ('normal control', [1, '23.976'], [0, 1, 2002]), ('normal control', [0, '24'], [0, 0, 2000]), ('normal control', [2002, '24'], [1, 2, 2000])], [('regression: frame index', [9580501, '29.97'], [5981, 1331, 1602]), ('regression variant: frame index', [2041513, '30'], [1275, 1513, 1600]), ('partial repair probe: frame index', [3203, '29.97'], [1, 1601, 1602]), ('partial repair variant: frame index', [7203996, '29.97'], [4497, 1600, 1601]), ('boundary control', [2002, '23.976'], [1, 0, 2002]), ('boundary control', [1920, '25'], [1, 0, 1920]), ('normal control', [8009, '30'], [5, 9, 1600]), ('normal control', [0, '23.976'], [0, 0, 2002]), ('normal control', [1600, '30'], [1, 0, 1600])], [('regression: frame index', [3203, '25'], [1, 1283, 1920]), ('regression variant: frame index', [1601, '24'], [0, 1601, 2000]), ('partial repair probe: frame index', [3315925, '29.97'], [2070, 613, 1602]), ('partial repair variant: frame index', [3637063, '29.97'], [2270, 1431, 1602]), ('boundary control', [1602, '29.97'], [1, 0, 1602]), ('boundary control', [2002, '23.976'], [1, 0, 2002]), ('normal control', [1, '24'], [0, 1, 2000]), ('normal control', [2002, '25'], [1, 82, 1920]), ('normal control', [8009, '29.97'], [5, 1, 1602])]]
for label, args, expected in fixtures[N-1]:
    check(label, 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
regression: frame index[1, -1, 1602][0, 1601, 1602]Failed
regression variant: frame index[1, -400, 2002][0, 1602, 2002]Failed
partial repair probe: frame index[3664, -358, 1601][3663, 1244, 1602]Failed
partial repair variant: frame index[5150, -315, 1602][5149, 1286, 1601]Failed
boundary control[1, 0, 1602][1, 0, 1602]Passed
boundary control[1, 0, 2002][1, 0, 2002]Passed
normal control[2, 0, 1601][2, 0, 1601]Passed
normal control[1, 317, 1602][1, 317, 1602]Passed
normal control[1, 320, 1600][1, 320, 1600]Passed

SHA-256 / 8c544bdcff96fe2df20d4770fd98c4e1fcc56b97eb33870112bfc75b6aa6b1dd

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(sample, rate):
    num,den={'23.976':(24000,1001),'24':(24,1),'25':(25,1),'29.97':(30000,1001),'30':(30,1)}[rate]
    frame=sample//(48000*den//num)
    start=-(-frame*48000*den//num)
    return [frame,sample-start,-(-(frame+1)*48000*den//num)-start]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: frame index', [1601, '29.97'], [0, 1601, 1602]), ('regression variant: frame index', [1602, '23.976'], [0, 1602, 2002]), ('partial repair probe: frame index', [5867905, '29.97'], [3663, 1244, 1602]), ('partial repair variant: frame index', [8247925, '29.97'], [5149, 1286, 1601]), ('boundary control', [1602, '29.97'], [1, 0, 1602]), ('boundary control', [2002, '23.976'], [1, 0, 2002]), ('normal control', [3204, '29.97'], [2, 0, 1601]), ('normal control', [1919, '29.97'], [1, 317, 1602]), ('normal control', [1920, '30'], [1, 320, 1600])], [('regression: frame index', [1602, '24'], [0, 1602, 2000]), ('regression variant: frame index', [1601, '25'], [0, 1601, 1920]), ('partial repair probe: frame index', [8007, '29.97'], [4, 1600, 1601]), ('partial repair variant: frame index', [5303585, '29.97'], [3311, 687, 1602]), ('boundary control', [3204, '29.97'], [2, 0, 1601]), ('boundary control', [1602, '29.97'], [1, 0, 1602]), ('normal control', [8008, '25'], [4, 328, 1920]), ('normal control', [0, '25'], [0, 0, 1920]), ('normal control', [8008, '29.97'], [5, 0, 1602])], [('regression: frame index', [1600, '25'], [0, 1600, 1920]), ('regression variant: frame index', [1920, '23.976'], [0, 1920, 2002]), ('partial repair probe: frame index', [3494632, '29.97'], [2181, 1542, 1602]), ('partial repair variant: frame index', [8735595, '29.97'], [5454, 468, 1601]), ('boundary control', [1920, '25'], [1, 0, 1920]), ('boundary control', [3204, '29.97'], [2, 0, 1601]), ('normal control', [1, '23.976'], [0, 1, 2002]), ('normal control', [0, '24'], [0, 0, 2000]), ('normal control', [2002, '24'], [1, 2, 2000])], [('regression: frame index', [9580501, '29.97'], [5981, 1331, 1602]), ('regression variant: frame index', [2041513, '30'], [1275, 1513, 1600]), ('partial repair probe: frame index', [3203, '29.97'], [1, 1601, 1602]), ('partial repair variant: frame index', [7203996, '29.97'], [4497, 1600, 1601]), ('boundary control', [2002, '23.976'], [1, 0, 2002]), ('boundary control', [1920, '25'], [1, 0, 1920]), ('normal control', [8009, '30'], [5, 9, 1600]), ('normal control', [0, '23.976'], [0, 0, 2002]), ('normal control', [1600, '30'], [1, 0, 1600])], [('regression: frame index', [3203, '25'], [1, 1283, 1920]), ('regression variant: frame index', [1601, '24'], [0, 1601, 2000]), ('partial repair probe: frame index', [3315925, '29.97'], [2070, 613, 1602]), ('partial repair variant: frame index', [3637063, '29.97'], [2270, 1431, 1602]), ('boundary control', [1602, '29.97'], [1, 0, 1602]), ('boundary control', [2002, '23.976'], [1, 0, 2002]), ('normal control', [1, '24'], [0, 1, 2000]), ('normal control', [2002, '25'], [1, 82, 1920]), ('normal control', [8009, '29.97'], [5, 1, 1602])]]
for label, args, expected in fixtures[N-1]:
    check(label, 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
regression: frame index[1, -1, 1602][0, 1601, 1602]Failed
regression variant: frame index[0, 1602, 2002][0, 1602, 2002]Passed
partial repair probe: frame index[3665, -1959, 1602][3663, 1244, 1602]Failed
partial repair variant: frame index[5151, -1917, 1602][5149, 1286, 1601]Failed
boundary control[1, 0, 1602][1, 0, 1602]Passed
boundary control[1, 0, 2002][1, 0, 2002]Passed
normal control[2, 0, 1601][2, 0, 1601]Passed
normal control[1, 317, 1602][1, 317, 1602]Passed
normal control[1, 320, 1600][1, 320, 1600]Passed

SHA-256 / 0f6cb7587b3c64b5147ef669cbdc74a78169d09f90f10ba7b336021a8cd1bbd0

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(sample, rate):
    num,den={'23.976':(24000,1001),'24':(24,1),'25':(25,1),'29.97':(30000,1001),'30':(30,1)}[rate]
    frame=sample*num//(48000*den)
    start=-(-frame*48000*den//num)
    return [frame,sample-start,-(-(frame+1)*48000*den//num)-start]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: frame index', [1601, '29.97'], [0, 1601, 1602]), ('regression variant: frame index', [1602, '23.976'], [0, 1602, 2002]), ('partial repair probe: frame index', [5867905, '29.97'], [3663, 1244, 1602]), ('partial repair variant: frame index', [8247925, '29.97'], [5149, 1286, 1601]), ('boundary control', [1602, '29.97'], [1, 0, 1602]), ('boundary control', [2002, '23.976'], [1, 0, 2002]), ('normal control', [3204, '29.97'], [2, 0, 1601]), ('normal control', [1919, '29.97'], [1, 317, 1602]), ('normal control', [1920, '30'], [1, 320, 1600])], [('regression: frame index', [1602, '24'], [0, 1602, 2000]), ('regression variant: frame index', [1601, '25'], [0, 1601, 1920]), ('partial repair probe: frame index', [8007, '29.97'], [4, 1600, 1601]), ('partial repair variant: frame index', [5303585, '29.97'], [3311, 687, 1602]), ('boundary control', [3204, '29.97'], [2, 0, 1601]), ('boundary control', [1602, '29.97'], [1, 0, 1602]), ('normal control', [8008, '25'], [4, 328, 1920]), ('normal control', [0, '25'], [0, 0, 1920]), ('normal control', [8008, '29.97'], [5, 0, 1602])], [('regression: frame index', [1600, '25'], [0, 1600, 1920]), ('regression variant: frame index', [1920, '23.976'], [0, 1920, 2002]), ('partial repair probe: frame index', [3494632, '29.97'], [2181, 1542, 1602]), ('partial repair variant: frame index', [8735595, '29.97'], [5454, 468, 1601]), ('boundary control', [1920, '25'], [1, 0, 1920]), ('boundary control', [3204, '29.97'], [2, 0, 1601]), ('normal control', [1, '23.976'], [0, 1, 2002]), ('normal control', [0, '24'], [0, 0, 2000]), ('normal control', [2002, '24'], [1, 2, 2000])], [('regression: frame index', [9580501, '29.97'], [5981, 1331, 1602]), ('regression variant: frame index', [2041513, '30'], [1275, 1513, 1600]), ('partial repair probe: frame index', [3203, '29.97'], [1, 1601, 1602]), ('partial repair variant: frame index', [7203996, '29.97'], [4497, 1600, 1601]), ('boundary control', [2002, '23.976'], [1, 0, 2002]), ('boundary control', [1920, '25'], [1, 0, 1920]), ('normal control', [8009, '30'], [5, 9, 1600]), ('normal control', [0, '23.976'], [0, 0, 2002]), ('normal control', [1600, '30'], [1, 0, 1600])], [('regression: frame index', [3203, '25'], [1, 1283, 1920]), ('regression variant: frame index', [1601, '24'], [0, 1601, 2000]), ('partial repair probe: frame index', [3315925, '29.97'], [2070, 613, 1602]), ('partial repair variant: frame index', [3637063, '29.97'], [2270, 1431, 1602]), ('boundary control', [1602, '29.97'], [1, 0, 1602]), ('boundary control', [2002, '23.976'], [1, 0, 2002]), ('normal control', [1, '24'], [0, 1, 2000]), ('normal control', [2002, '25'], [1, 82, 1920]), ('normal control', [8009, '29.97'], [5, 1, 1602])]]
for label, args, expected in fixtures[N-1]:
    check(label, 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
regression: frame index[0, 1601, 1602][0, 1601, 1602]Passed
regression variant: frame index[0, 1602, 2002][0, 1602, 2002]Passed
partial repair probe: frame index[3663, 1244, 1602][3663, 1244, 1602]Passed
partial repair variant: frame index[5149, 1286, 1601][5149, 1286, 1601]Passed
boundary control[1, 0, 1602][1, 0, 1602]Passed
boundary control[1, 0, 2002][1, 0, 2002]Passed
normal control[2, 0, 1601][2, 0, 1601]Passed
normal control[1, 317, 1602][1, 317, 1602]Passed
normal control[1, 320, 1600][1, 320, 1600]Passed

SHA-256 / 2aa3c30be298d8686c03cb5ac4d21fd1a41a3b2ba9af914bd3ecd1cc7316eae1

Verification & scope

A deterministic bounded teaching model with a stipulated toy contract; it does not claim conformance to SMPTE or any broadcast standard. 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:49:37.334344+00:00.

Case digest / a64e236d0c1bd4bdf65687731697ba2c6c2fb43f441cbe9f31decfa974c4cc6c