"""Ring-buffer simulation. The peak-vs-sustained comparison in FINDINGS 18 was the wrong test: with SD-backed SCSI the fill rate is a CONSTANT, and a burst frame is absorbed by the buffer rather than having to arrive within one frame. What actually matters: 1. required PREFILL so the buffer never underruns mid-scene 2. STALL TOLERANCE at a branch point -- Dragon's Lair seeks between streams, and the buffer drains while the seek completes """ import sys; sys.path.insert(0,'tools/encoder') import vq_hybrid as H, ratectl as RC, numpy as np S=sys.argv[1]; BW=4_000_000/8/1024; FPS=12 fill=BW/FPS print(f"fill {BW:.0f} KB/s = {fill:.2f} KB per frame time\n") print(f'{"scene":8}{"lam":>5}{"mean":>8}{"max f":>8}{"prefill":>9}{"stall @0KB":>12}{"stall @256KB":>14}') for s in ['00010','00020','00146','00181']: m=H.build(f'{S}/fr_{s}',k1=256,k4=256,iters=16) for lam in [10.,60.]: e=H.encode(m,lam=lam) kb=e['sizes']/1024 + RC.AUDIO_KBPS/FPS # KB demanded per frame # cumulative deficit: worst shortfall of supply vs demand deficit=np.maximum.accumulate(np.cumsum(kb-fill)) prefill=max(0.0,deficit.max()) # stall tolerance: with buffer B prefilled, how many frame times can the # fill be zero (seeking) before the buffer empties, at mean drain mean_kb=kb.mean() stall0 = prefill/mean_kb if mean_kb>0 else 0 stall256 = (256.0+0.0)/mean_kb print(f'{s:8}{lam:5.0f}{kb.mean()*FPS:8.1f}{kb.max():8.2f}{prefill:9.1f}' f'{stall0:9.1f} fr{stall256:11.1f} fr') print() print("prefill = KB the buffer must hold before playback starts") print("stall = frame times the buffer survives with NO fill (seek/branch)") print(" at 12fps, 1 frame = 83.3 ms")