FA-78671 / Broadcast timecode arithmetic / Open access
Audio sample to frame cadence at 48 kHz: frame start sample · case 01
In-frame offsets are one sample too large at NTSC frame starts.
ROOT CAUSE
The frame start sample is floored instead of ceiled.
VERIFIED REPAIR
Frame k starts at the ceiling of k*48000*D/N.
Unsuccessful approach: Multiplying by a truncated samples-per-frame value drifts through the cadence.
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//(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 start sample', [1602, '29.97'], [1, 0, 1602]), ('regression variant: frame start sample', [1920, '29.97'], [1, 318, 1602]), ('partial repair probe: frame start sample', [1919, '29.97'], [1, 317, 1602]), ('partial repair variant: frame start sample', [5867905, '29.97'], [3663, 1244, 1602]), ('boundary control', [1601, '29.97'], [0, 1601, 1602]), ('boundary control', [1920, '25'], [1, 0, 1920]), ('normal control', [2002, '23.976'], [1, 0, 2002]), ('normal control', [1602, '24'], [0, 1602, 2000]), ('normal control', [1600, '25'], [0, 1600, 1920])], [('regression: frame start sample', [3204, '29.97'], [2, 0, 1601]), ('regression variant: frame start sample', [2001, '29.97'], [1, 399, 1602]), ('partial repair probe: frame start sample', [9580501, '29.97'], [5981, 1331, 1602]), ('partial repair variant: frame start sample', [8007, '29.97'], [4, 1600, 1601]), ('boundary control', [1920, '25'], [1, 0, 1920]), ('boundary control', [2002, '23.976'], [1, 0, 2002]), ('normal control', [8008, '25'], [4, 328, 1920]), ('normal control', [0, '25'], [0, 0, 1920]), ('normal control', [1602, '23.976'], [0, 1602, 2002])], [('regression: frame start sample', [1919, '29.97'], [1, 317, 1602]), ('regression variant: frame start sample', [5867905, '29.97'], [3663, 1244, 1602]), ('partial repair probe: frame start sample', [8008, '29.97'], [5, 0, 1602]), ('partial repair variant: frame start sample', [3494632, '29.97'], [2181, 1542, 1602]), ('boundary control', [2002, '23.976'], [1, 0, 2002]), ('boundary control', [1601, '29.97'], [0, 1601, 1602]), ('normal control', [1601, '25'], [0, 1601, 1920]), ('normal control', [0, '30'], [0, 0, 1600]), ('normal control', [8009, '24'], [4, 9, 2000])], [('regression: frame start sample', [9580501, '29.97'], [5981, 1331, 1602]), ('regression variant: frame start sample', [8007, '29.97'], [4, 1600, 1601]), ('partial repair probe: frame start sample', [2002, '29.97'], [1, 400, 1602]), ('partial repair variant: frame start sample', [1603, '29.97'], [1, 1, 1602]), ('boundary control', [1601, '29.97'], [0, 1601, 1602]), ('boundary control', [1920, '25'], [1, 0, 1920]), ('normal control', [3204, '25'], [1, 1284, 1920]), ('normal control', [8009, '23.976'], [4, 1, 2002]), ('normal control', [2002, '24'], [1, 2, 2000])], [('regression: frame start sample', [2002, '29.97'], [1, 400, 1602]), ('regression variant: frame start sample', [3494632, '29.97'], [2181, 1542, 1602]), ('partial repair probe: frame start sample', [1920, '29.97'], [1, 318, 1602]), ('partial repair variant: frame start sample', [3203, '29.97'], [1, 1601, 1602]), ('boundary control', [1920, '25'], [1, 0, 1920]), ('boundary control', [2002, '23.976'], [1, 0, 2002]), ('normal control', [3203, '24'], [1, 1203, 2000]), ('normal control', [8009, '30'], [5, 9, 1600]), ('normal control', [1603, '24'], [0, 1603, 2000])]]
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: frame start sample | [1, 1, 1603] | [1, 0, 1602] | Failed |
| regression variant: frame start sample | [1, 319, 1603] | [1, 318, 1602] | Failed |
| partial repair probe: frame start sample | [1, 318, 1603] | [1, 317, 1602] | Failed |
| partial repair variant: frame start sample | [3663, 1245, 1603] | [3663, 1244, 1602] | Failed |
| boundary control | [0, 1601, 1602] | [0, 1601, 1602] | Passed |
| boundary control | [1, 0, 1920] | [1, 0, 1920] | Passed |
| normal control | [1, 0, 2002] | [1, 0, 2002] | Passed |
| normal control | [0, 1602, 2000] | [0, 1602, 2000] | Passed |
| normal control | [0, 1600, 1920] | [0, 1600, 1920] | Passed |
SHA-256 / f8d56ae0d57e666260abb0aa12106e2b724ef8914377ea2ac6f3803b07aed65c
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*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 start sample', [1602, '29.97'], [1, 0, 1602]), ('regression variant: frame start sample', [1920, '29.97'], [1, 318, 1602]), ('partial repair probe: frame start sample', [1919, '29.97'], [1, 317, 1602]), ('partial repair variant: frame start sample', [5867905, '29.97'], [3663, 1244, 1602]), ('boundary control', [1601, '29.97'], [0, 1601, 1602]), ('boundary control', [1920, '25'], [1, 0, 1920]), ('normal control', [2002, '23.976'], [1, 0, 2002]), ('normal control', [1602, '24'], [0, 1602, 2000]), ('normal control', [1600, '25'], [0, 1600, 1920])], [('regression: frame start sample', [3204, '29.97'], [2, 0, 1601]), ('regression variant: frame start sample', [2001, '29.97'], [1, 399, 1602]), ('partial repair probe: frame start sample', [9580501, '29.97'], [5981, 1331, 1602]), ('partial repair variant: frame start sample', [8007, '29.97'], [4, 1600, 1601]), ('boundary control', [1920, '25'], [1, 0, 1920]), ('boundary control', [2002, '23.976'], [1, 0, 2002]), ('normal control', [8008, '25'], [4, 328, 1920]), ('normal control', [0, '25'], [0, 0, 1920]), ('normal control', [1602, '23.976'], [0, 1602, 2002])], [('regression: frame start sample', [1919, '29.97'], [1, 317, 1602]), ('regression variant: frame start sample', [5867905, '29.97'], [3663, 1244, 1602]), ('partial repair probe: frame start sample', [8008, '29.97'], [5, 0, 1602]), ('partial repair variant: frame start sample', [3494632, '29.97'], [2181, 1542, 1602]), ('boundary control', [2002, '23.976'], [1, 0, 2002]), ('boundary control', [1601, '29.97'], [0, 1601, 1602]), ('normal control', [1601, '25'], [0, 1601, 1920]), ('normal control', [0, '30'], [0, 0, 1600]), ('normal control', [8009, '24'], [4, 9, 2000])], [('regression: frame start sample', [9580501, '29.97'], [5981, 1331, 1602]), ('regression variant: frame start sample', [8007, '29.97'], [4, 1600, 1601]), ('partial repair probe: frame start sample', [2002, '29.97'], [1, 400, 1602]), ('partial repair variant: frame start sample', [1603, '29.97'], [1, 1, 1602]), ('boundary control', [1601, '29.97'], [0, 1601, 1602]), ('boundary control', [1920, '25'], [1, 0, 1920]), ('normal control', [3204, '25'], [1, 1284, 1920]), ('normal control', [8009, '23.976'], [4, 1, 2002]), ('normal control', [2002, '24'], [1, 2, 2000])], [('regression: frame start sample', [2002, '29.97'], [1, 400, 1602]), ('regression variant: frame start sample', [3494632, '29.97'], [2181, 1542, 1602]), ('partial repair probe: frame start sample', [1920, '29.97'], [1, 318, 1602]), ('partial repair variant: frame start sample', [3203, '29.97'], [1, 1601, 1602]), ('boundary control', [1920, '25'], [1, 0, 1920]), ('boundary control', [2002, '23.976'], [1, 0, 2002]), ('normal control', [3203, '24'], [1, 1203, 2000]), ('normal control', [8009, '30'], [5, 9, 1600]), ('normal control', [1603, '24'], [0, 1603, 2000])]]
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: frame start sample | [1, 1, 1603] | [1, 0, 1602] | Failed |
| regression variant: frame start sample | [1, 319, 1603] | [1, 318, 1602] | Failed |
| partial repair probe: frame start sample | [1, 318, 1603] | [1, 317, 1602] | Failed |
| partial repair variant: frame start sample | [3663, 3442, 3800] | [3663, 1244, 1602] | Failed |
| boundary control | [0, 1601, 1602] | [0, 1601, 1602] | Passed |
| boundary control | [1, 0, 1920] | [1, 0, 1920] | Passed |
| normal control | [1, 0, 2002] | [1, 0, 2002] | Passed |
| normal control | [0, 1602, 2000] | [0, 1602, 2000] | Passed |
| normal control | [0, 1600, 1920] | [0, 1600, 1920] | Passed |
SHA-256 / 084bdf1bd7ade533a86fdf5d87ce2b9d0950b2e7f3e0fc968eec451fe2fc8766
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 start sample', [1602, '29.97'], [1, 0, 1602]), ('regression variant: frame start sample', [1920, '29.97'], [1, 318, 1602]), ('partial repair probe: frame start sample', [1919, '29.97'], [1, 317, 1602]), ('partial repair variant: frame start sample', [5867905, '29.97'], [3663, 1244, 1602]), ('boundary control', [1601, '29.97'], [0, 1601, 1602]), ('boundary control', [1920, '25'], [1, 0, 1920]), ('normal control', [2002, '23.976'], [1, 0, 2002]), ('normal control', [1602, '24'], [0, 1602, 2000]), ('normal control', [1600, '25'], [0, 1600, 1920])], [('regression: frame start sample', [3204, '29.97'], [2, 0, 1601]), ('regression variant: frame start sample', [2001, '29.97'], [1, 399, 1602]), ('partial repair probe: frame start sample', [9580501, '29.97'], [5981, 1331, 1602]), ('partial repair variant: frame start sample', [8007, '29.97'], [4, 1600, 1601]), ('boundary control', [1920, '25'], [1, 0, 1920]), ('boundary control', [2002, '23.976'], [1, 0, 2002]), ('normal control', [8008, '25'], [4, 328, 1920]), ('normal control', [0, '25'], [0, 0, 1920]), ('normal control', [1602, '23.976'], [0, 1602, 2002])], [('regression: frame start sample', [1919, '29.97'], [1, 317, 1602]), ('regression variant: frame start sample', [5867905, '29.97'], [3663, 1244, 1602]), ('partial repair probe: frame start sample', [8008, '29.97'], [5, 0, 1602]), ('partial repair variant: frame start sample', [3494632, '29.97'], [2181, 1542, 1602]), ('boundary control', [2002, '23.976'], [1, 0, 2002]), ('boundary control', [1601, '29.97'], [0, 1601, 1602]), ('normal control', [1601, '25'], [0, 1601, 1920]), ('normal control', [0, '30'], [0, 0, 1600]), ('normal control', [8009, '24'], [4, 9, 2000])], [('regression: frame start sample', [9580501, '29.97'], [5981, 1331, 1602]), ('regression variant: frame start sample', [8007, '29.97'], [4, 1600, 1601]), ('partial repair probe: frame start sample', [2002, '29.97'], [1, 400, 1602]), ('partial repair variant: frame start sample', [1603, '29.97'], [1, 1, 1602]), ('boundary control', [1601, '29.97'], [0, 1601, 1602]), ('boundary control', [1920, '25'], [1, 0, 1920]), ('normal control', [3204, '25'], [1, 1284, 1920]), ('normal control', [8009, '23.976'], [4, 1, 2002]), ('normal control', [2002, '24'], [1, 2, 2000])], [('regression: frame start sample', [2002, '29.97'], [1, 400, 1602]), ('regression variant: frame start sample', [3494632, '29.97'], [2181, 1542, 1602]), ('partial repair probe: frame start sample', [1920, '29.97'], [1, 318, 1602]), ('partial repair variant: frame start sample', [3203, '29.97'], [1, 1601, 1602]), ('boundary control', [1920, '25'], [1, 0, 1920]), ('boundary control', [2002, '23.976'], [1, 0, 2002]), ('normal control', [3203, '24'], [1, 1203, 2000]), ('normal control', [8009, '30'], [5, 9, 1600]), ('normal control', [1603, '24'], [0, 1603, 2000])]]
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: frame start sample | [1, 0, 1602] | [1, 0, 1602] | Passed |
| regression variant: frame start sample | [1, 318, 1602] | [1, 318, 1602] | Passed |
| partial repair probe: frame start sample | [1, 317, 1602] | [1, 317, 1602] | Passed |
| partial repair variant: frame start sample | [3663, 1244, 1602] | [3663, 1244, 1602] | Passed |
| boundary control | [0, 1601, 1602] | [0, 1601, 1602] | Passed |
| boundary control | [1, 0, 1920] | [1, 0, 1920] | Passed |
| normal control | [1, 0, 2002] | [1, 0, 2002] | Passed |
| normal control | [0, 1602, 2000] | [0, 1602, 2000] | Passed |
| normal control | [0, 1600, 1920] | [0, 1600, 1920] | Passed |
SHA-256 / 04f832a15f859c553d11ba6365ab7b9e6095571a7a0324379425cb88faf76942
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.379093+00:00.
Case digest / e23cad17dcc9b921474ef5562a8a87175c597ef8f13fcc0cf8c37cbdd96edf38