Skip to content

Fix orbit read guard sample clamping#67

Open
ovelhaaa wants to merge 1 commit into
mainfrom
codex/fix-clamp-logic-in-orbit_delay_core.cpp
Open

Fix orbit read guard sample clamping#67
ovelhaaa wants to merge 1 commit into
mainfrom
codex/fix-clamp-logic-in-orbit_delay_core.cpp

Conversation

@ovelhaaa

Copy link
Copy Markdown
Owner

Motivation

  • Fix an incorrect nested clampf that inverted min/max and forced guardSamples to kOrbitReadGuardMinSamples, preventing it from growing with buffer size.

Description

  • Replace the nested clamps with a single clampf(maxGuardBySize, kOrbitReadGuardMinSamples, kOrbitReadGuardMaxSamples) in core/src/orbit_delay_core.cpp while leaving wrapPosFloat, readPos, writePos, and the distance checks unchanged.

Testing

  • Built with cmake .. -DBUILD_TESTING=ON && cmake --build . and ran tests with ctest --output-on-failure, and all tests passed (5/5).

Codex Task

@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@ovelhaaa has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 59 minutes and 12 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6bec74e3-fc41-4842-82dc-2d3cb4fabe86

📥 Commits

Reviewing files that changed from the base of the PR and between 9168ce5 and 0c573f0.

📒 Files selected for processing (1)
  • core/src/orbit_delay_core.cpp
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-clamp-logic-in-orbit_delay_core.cpp

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the calculation of guardSamples in OrbitDelayCore::processChannelFast to simplify the clamping logic. Feedback indicates that the current implementation may still cause issues with small delay buffers where the guard zone becomes disproportionately large, potentially breaking delay functionality. A code suggestion was provided to ensure the lower bound of the clamp is adjusted based on the buffer size to maintain robustness.

Comment on lines +638 to +640
const float guardSamples = clampf(maxGuardBySize,
kOrbitReadGuardMinSamples,
kOrbitReadGuardMaxSamples);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current clamping logic forces guardSamples to a minimum of kOrbitReadGuardMinSamples (16.0f). For small delay buffers where maxGuardBySize (25% of the buffer) is less than 16, this results in a guard zone that is too large relative to the buffer size. For example, if delaySize is 32, guardSamples becomes 16, which causes the read pointer to be constantly reset because the condition distanceForward < 16 || distanceForward > 16 (lines 641-642) will be true for almost all positions. This effectively breaks the delay functionality for small buffers.

To ensure robustness, the lower bound of the clamp should not exceed maxGuardBySize.

Suggested change
const float guardSamples = clampf(maxGuardBySize,
kOrbitReadGuardMinSamples,
kOrbitReadGuardMaxSamples);
const float guardSamples = clampf(maxGuardBySize,
(maxGuardBySize < kOrbitReadGuardMinSamples) ? maxGuardBySize : kOrbitReadGuardMinSamples,
kOrbitReadGuardMaxSamples);

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0c573f004a

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +638 to +640
const float guardSamples = clampf(maxGuardBySize,
kOrbitReadGuardMinSamples,
kOrbitReadGuardMaxSamples);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Cap guardSamples by delay size for small buffers

guardSamples is now floored to kOrbitReadGuardMinSamples (16) even when the attached delay buffer is smaller than 64 samples, so in orbit mode the check distanceForward < guardSamples || distanceForward > (delaySize - guardSamples) becomes effectively always true for small buffers (e.g. size 32, and for size <32 it is strictly always true). That forces readPos to writePos + guardSamples every sample, collapsing modulation and creating a read/write spacing that no longer scales with buffer size. The previous code reduced guard for small buffers, so this is a behavior regression for valid attachBuffers(..., size>=4) configurations.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant