emitadjaudio - measure the per-VBL YM sample-emit cadence
=========================================================

What it does
  Reads a WAV capture of the DEBUG_AUDIO_FLIP signal and writes a CSV of the
  averaged per-VBL emit cadence, split into regions.

    emitadjaudio <in.wav> <out.csv>

  CSV columns: region_index, sample_count, sample_period_us (mean per-sample
  interval).  The VBL gap shows up as a 1-sample region with a large period (the
  DAC holds the last value).  Sum of count*period ~= one 20 ms (50 Hz) frame.

Required input signal
  DEBUG_AUDIO_FLIP opens each VBL with 4 full-scale cycles (0,+127,0,-128) as a
  loud marker, then half scale (0,+63,0,-63).  The loud burst marks each VBL's a6
  reset, so the tool can pin frame boundaries and coherently average all frames.

How it works
  Each frame anchors on its first +127 (= emit 1; the leading mid-level 0 is emit
  0, undetectable, and folds into the trailing VBL-gap sample).  Emit instants are
  hysteresis peaks/troughs plus the zero-cross between each pair.  The averaged
  timeline is segmented by a sustained-change rule - split only when the rate
  stays off for several samples - so brief wipe/scroll dips and the period-4
  asymmetric-DAC wobble don't spawn spurious regions.

Caveats
  At a 44.1 kHz capture (~6 samples/emit) Hatari's reconstruction filter shifts
  edges, so per-sample periods are ~10-20% off; region counts, gap sizes and the
  overall structure are solid.  For exact timing use a raw YM register-write trace.

Build
  make            (needs only a C++23 compiler)
