chore(probe): theo doi clipping output (FXRT_PROBE_AMP + flat-top stats)

This commit is contained in:
2026-08-24 11:39:49 +07:00
parent 5ca2027966
commit b907db3251
+17 -2
View File
@@ -151,7 +151,8 @@ class WorkletSim:
def make_block():
t = np.arange(BLOCK) / SR
sig = 0.2 * np.sin(2 * np.pi * 220 * t) + 0.1 * np.sin(2 * np.pi * 331 * t)
amp = float(os.environ.get("FXRT_PROBE_AMP", "1.0"))
sig = amp * (0.2 * np.sin(2 * np.pi * 220 * t) + 0.1 * np.sin(2 * np.pi * 331 * t))
inter = np.empty(BLOCK * 2, dtype=np.float32)
inter[0::2] = sig
inter[1::2] = 0.85 * sig
@@ -179,6 +180,8 @@ async def run_ws_probe(port, chain, secs, stall):
s_prob, s_min, s_max = stall_model(stall)
sent_bursts = 0
recv_times = [] # (block_seq, time, peak)
out_peaks = [] # output peak per block (cause-5 clipping track)
out_flat = [] # flat-top samples per block (|x|>0.9999)
recv_lock = asyncio.Lock()
stop = asyncio.Event()
produced = asyncio.Queue() # burst buffers
@@ -265,9 +268,13 @@ async def run_ws_probe(port, chain, secs, stall):
break
if isinstance(msg, bytes) and len(msg) == BLOCK * 2 * 4:
now = time.perf_counter()
pk = float(np.frombuffer(msg, dtype=np.float32)[::2].max())
f = np.frombuffer(msg, dtype=np.float32)
pk = float(f[::2].max())
flat = int(np.count_nonzero(np.abs(f) > 0.9999))
async with recv_lock:
recv_times.append((len(recv_times), now, pk))
out_peaks.append(pk)
out_flat.append(flat)
# text frame (latency) bỏ qua
async with websockets.connect(ws_url) as ws:
@@ -319,6 +326,14 @@ async def run_ws_probe(port, chain, secs, stall):
rate = n_recv / dur
print(" sent=%d bursts (%d blocks) recv=%d blocks over %.1fs = %.1f blk/s (expect 187.5)"
% (len(sent_times), n_sent, n_recv, dur, rate))
if out_peaks:
op = np.array(out_peaks)
of = np.array(out_flat)
print(" OUT peak: min=%.4f p50=%.4f p95=%.4f max=%.4f" %
(op.min(), np.percentile(op, 50), np.percentile(op, 95), op.max()))
print(" OUT flat-top(|x|>0.9999): blocks=%d samples=%d (%.4f%%)" %
(int(np.count_nonzero(of > 0)), int(of.sum()),
100.0 * of.sum() / max(1, len(of) * BLOCK * 2)))
print(" lost blocks (sent-recv): %d" % max(0, n_sent - n_recv))
if len(times) > 1:
gaps = [b - a for (i, a, _), (j, b, _) in zip(times[:-1], times[1:])]