Skip to content

feat(builtins): buf_resample_linear — endpoint-inclusive linear resample kernel (#603) - #609

Merged
InauguralPhysicist merged 1 commit into
mainfrom
feat-buf-resample-603
Jul 14, 2026
Merged

feat(builtins): buf_resample_linear — endpoint-inclusive linear resample kernel (#603)#609
InauguralPhysicist merged 1 commit into
mainfrom
feat-buf-resample-603

Conversation

@InauguralPhysicist

Copy link
Copy Markdown
Collaborator

Closes #603

What

Third leg of the DAW audio-I/O train (after #597 mix kernels and #602 PCM codecs): DeslanStudio's WAV import spent 3.9 s resampling a 50 s stereo file on the N3350 in ab_resample_linear's interpreted per-sample loop.

buf_resample_linear of [src, dst_len] → NEW buffer with exactly the consumer's endpoint-inclusive mapping:

pos = i * (n - 1) / (dst_len - 1)    (0 when dst_len == 1)
lo = floor(pos); hi = min(lo + 1, n - 1); frac = pos - lo
out[i] = src[lo] * (1 - frac) + src[hi] * frac

num_guard per step in VM evaluation order — bit-identical to the interpreted loop, pinned by the differential leg in tests/test_buf_resample.eigs (upsample/downsample/identity/dst 1/n 1 shapes on seeded pseudo-random data).

Doc note in BUILTINS.md: the kernel is linear interpolation, not Fourier/sinc — the consumer-documented divergence from scipy.signal.resample (no anti-aliasing).

Edges: dst_len 0 → empty buffer; negative/non-numeric dst_len raises value; empty src with dst_len > 0 raises value; dst_len > INT_MAX raises limit. Allocation charges the #292 sandbox budget; sandbox pure-compute allowlist; freestanding-safe.

Perf (n=5 medians, N3350, 1,102,500 → 1,200,000 samples, pinned to one core)

leg per pass
interpreted (JIT) 1048 ms
interpreted (JIT off) 1986 ms
buf_resample_linear 60.3 ms (~17x / ~33x)

Gates

  • Release suite 2890/2890, 0 failed (includes the new 5-check section).
  • ASan/UBSan detect_leaks=1: 2893/2894, leak tally 0 — single failure is the known invariant_weak [97] 60 s wall-guard marginality under ASan on this box (71 s in isolation; unrelated).
  • Doc gates [99]/[99b] green.

🤖 Generated with Claude Code

…ple kernel (#603)

Third leg of the DAW audio-I/O train: DeslanStudio's import spent 3.9 s
resampling a 50 s stereo 48 kHz file on the N3350 in ab_resample_linear's
interpreted per-sample loop (src/daw/audio_buf.eigs).

buf_resample_linear of [src, dst_len] -> NEW buffer with exactly that
mapping: pos = i*(n-1)/(dst_len-1) (0 when dst_len == 1), lerp between
the floor/ceil neighbors with hi clamped to n-1, num_guard per step in
VM evaluation order — bit-identical to the interpreted loop, pinned by
the differential leg in tests/test_buf_resample.eigs across shapes
(upsample 480->733, downsample 480->217, identity, dst 1, n 1, small).

The kernel is LINEAR interpolation, not Fourier/sinc — the
consumer-documented divergence from scipy.signal.resample (no
anti-aliasing); noted in BUILTINS.md.

Edges: dst_len 0 -> empty buffer; negative/non-numeric dst_len raises
`value`; empty src with dst_len > 0 raises `value`; dst_len > INT_MAX
raises `limit`. Allocation charged to the #292 sandbox budget; joins
the sandbox pure-compute allowlist; freestanding-safe. The unreachable
index clamps are memory-safety belts only (pos ∈ [0, n-1] by
construction — an exact-integer product over an exact divisor cannot
round past n-1).

Perf (tests/bench_buf_resample.eigs, 1,102,500 -> 1,200,000 samples,
n=5 medians, N3350, pinned to one core): interpreted pass 1048 ms (JIT)
/ 1986 ms (interpreter) vs buf_resample_linear 60.3 ms — ~17x / ~33x.

Closes #603

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@InauguralPhysicist
InauguralPhysicist merged commit 15e4f3a into main Jul 14, 2026
17 checks passed
@InauguralPhysicist
InauguralPhysicist deleted the feat-buf-resample-603 branch July 14, 2026 10:20
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.

buf_resample_linear: C kernel for DeslanStudio's endpoint-inclusive linear resample (3.9s interpreted per import)

1 participant