Skip to content

Add ctypes demo notebook and C ABI shared library - #6

Merged
tap merged 4 commits into
mainfrom
claude/demo-notebook
Jun 11, 2026
Merged

tap merged 4 commits into
mainfrom
claude/demo-notebook

Conversation

@tap

@tap tap commented Jun 10, 2026

Copy link
Copy Markdown
Owner

A visual demo/validation notebook driving the real compiled library through ctypes, plus the C ABI it needs.

tools/capi/ — C ABI shim (SRT_BUILD_CAPI=ON)

~80 lines of extern "C" over the float converter: srt_create/destroy/push/pull/status/designed_latency_seconds/reset_from_consumer. Opaque handle, errors as null/zero, hot path stays noexcept. Usable from any FFI host (ctypes today; cffi/Julia/Rust trivially).

notebooks/asrc_demo.ipynb — committed with executed outputs (7 figures)

Walks the library's story end to end, every section plot-first and assertion-backed:

  1. The problem: a naive FIFO at +200 ppm — waveform discontinuity at a sample drop, spur-filled spectrum, 29 dB SNR.
  2. Lock acquisition: servo telemetry from cold start, state-machine shading (Filling/Acquiring/Locked), ppm converging to +200.01 against a true +200.
  3. The money plot: naive vs SampleRateTap spectra overlaid — 126 dB vs 29 dB (97 dB improvement) on this run.
  4. Spectrograms: a 100 Hz→20 kHz sweep through both paths; every vertical stripe in the naive image is an audible click, the ASRC image has none.
  5. Latency: impulse measured at 1.50 ms = designedLatencySeconds() exactly.
  6. Drift: 0→+300 ppm at 50 ppm/s tracked while streaming, settling to +4.5 ppm error, zero underruns.
  7. Dropout recovery: 60 ms producer stall — the fade-in's max recovery step equals the tone's own slope (0.0652), i.e. the recovery adds no discontinuity at all; the (inherent, lookahead-free) onset cut is shown honestly.

Because every demo cell asserts its measurement, re-executing the notebook is an end-to-end FFI + quality validation, not just a slideshow. Notes for reviewers: the first cell auto-builds the DSO if missing; the quality demo runs a 30 s virtual stream because the servo's Quiet stage (lowest noise floor) takes ~20 s to engage — earlier sampling reads the Track stage at ~92 dB, which is itself documented behavior.

Also: the clang-format CI check now covers bench/ and tools/capi/ (previously only the original directories were globbed).

https://claude.ai/code/session_01HuAFfoeD5a5Xe5aGNA16M9


Generated by Claude Code

claude added 4 commits June 10, 2026 22:37
tools/capi/ is an ~80-line extern "C" shim over the float converter
(create/destroy/push/pull/status/latency/reset), built as a shared
library behind SRT_BUILD_CAPI for FFI consumers.

notebooks/asrc_demo.ipynb loads it with ctypes and walks through the
library visually, committed with executed outputs (7 figures): the
naive-FIFO failure mode at +200 ppm (waveform discontinuity and spur
spectrum), servo lock acquisition with state shading, the transparency
comparison (126 dB measured vs 29 dB naive on this run), side-by-side
sweep spectrograms, impulse latency vs designedLatencySeconds (1.50 ms
both), a 0->300 ppm drift ramp tracked while streaming, and dropout
recovery where the fade-in's max sample step equals the tone's own
slope. Every demo cell carries an assertion, so re-executing the
notebook doubles as an end-to-end FFI validation.
The setup cell hard-coded libsrt_capi.so; on macOS CMake produces
libsrt_capi.dylib (and srt_capi.dll under Release/ on Windows), so
the auto-build succeeded and the dlopen then failed on a path that
never exists there. Search for all three names recursively, pass
--config Release for multi-config generators, and print the build
output on failure instead of swallowing it.
@tap
tap merged commit f294885 into main Jun 11, 2026
22 checks passed
@tap
tap deleted the claude/demo-notebook branch June 27, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants