Skip to content

Keep looping resident reads inside the slice just below its start - #56

Open
yuichkun wants to merge 1 commit into
mainfrom
claude/project-thread-zm98y8
Open

yuichkun wants to merge 1 commit into
mainfrom
claude/project-thread-zm98y8

Conversation

@yuichkun

@yuichkun yuichkun commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

Requested by yuichkun · project thread

residentSample.read and the residentTakeRecorder reader wrap a looping position as r - floor(r / L) * L + start in f64. For a position a rounding error below start, the remainder can round up to L, or stay just below L and round up to the exclusive end once start is added. read(3 - 1e-15, 3, 91, true) returned the frame at 91, outside the slice, instead of interpolating toward frame 3, and the largest double below 3 in the slice [3, 5) wrapped to 5. After a shorter reload or a logical recorder reset, that frame holds stale bytes that docs/sample.md and docs/resident-recorder.md describe as unreachable. samplePlayer and granularSource share the wrap, so a looping player could report its end frame as its position for one sample.

Both readers now map a wrapped position at or above end back to start, and clamp one below start, which an underflowing quotient can leave at start 0. This is the guard loop-crossfade already applies, moved to the absolute position: guarding only the remainder before start is added still lets the second case through. The other wrap helpers (loop crossfade, modulation, musical controls, LFO, sine and pulse sources, windowed pitch shift, wavetables, granular clock, frequency shifter) were checked and are already guarded, clamped, or cannot reach the edge.

Validation:

  • New tests read at and just below the start of [3, 5) and [1, 4), read a slice clipped by a shorter reload and a take recorded over cleared bytes, and step a looping player just below its start. All fail without the guard; the two read tests also fail with a remainder-only guard.
  • npm run check passed, and npx vitest run passed 61 files / 1,106 tests locally on Node 24.
  • The packed-consumer and browser tests were not run locally on this head: this machine lacks the pinned Playwright Chromium build. The Entry gate on this PR ran them on this head and passed.

Audio remains CANDIDATE.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JP5nzyggXWpUAMagBt4JZB

residentSample.read and the residentTakeRecorder reader wrap a looping
position as r - floor(r/L)*L + start in f64. For a position a rounding error
below start, the remainder can round up to L, or stay just below L and round
up to the exclusive end when start is added: the largest double below 3 in
the slice [3,5) wraps to 5. Below capacity, the reader then returned the
frame at end. That frame lies outside the slice, and after a shorter reload
or a logical recorder reset it holds stale bytes that docs/sample.md and
docs/resident-recorder.md describe as unreachable. samplePlayer and
granularSource use the same wrap, so a looping player could report its end
frame as its position for one sample.

Both readers now map a wrapped position at or above end back to start and
clamp one below start, which an underflowing quotient can leave at start 0.
This is the loop-crossfade guard applied to the absolute position; guarding
only the remainder before start is added still lets the second case through.

New tests read at and just below the start of [3,5), [1,4) and a slice
clipped by a shorter reload or by a take recorded over cleared bytes, and
step a looping player just below its start. All three fail without the
guard; the two read tests also fail with a remainder-only guard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JP5nzyggXWpUAMagBt4JZB
@vercel

vercel Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
den Ready Ready Preview Nov 30, 2026 6:56am UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-30T06:58:01.177363Z b88fc63 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

This branch was successfully deployed

1 active deployment
Preview — b88fc637 Deployed Nov 30, 2026 by vercel[bot]
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