Refactor/s1 audiosync determinism#66
Merged
Merged
Conversation
…exact lag Fix non-deterministic FFT peak selection by implementing earliest-peak tie-break when multiple peaks are within 0.5 SNR threshold. Convert lag from floating- point seconds to integer frame offsets for reproducible sync results. Changes: - findBestLag: collect all near-maximum candidates and select earliest peak - validatePeak: updated to work with frame-based lag calculation - Lag normalization: convert to nearest frame at 30fps standard rate - Added comprehensive unit tests for tie-break and frame rounding logic - Added determinism verification tests AC: #1, #2
…nism - Fix validatePeak test to use deterministic correlation array instead of Math.random() - Extract frameRate to module-level constant SYNC_FRAME_RATE - Extract magic numbers as named constants PEAK_NEARNESS_THRESHOLD and RELIABILITY_SNR_THRESHOLD - Remove stale lenA parameter from determinism test - Add test case for near-equal peak appearing before global maximum All tests now pass and provide better protection against regressions.
- Move peak to index 67 in happy-path validatePeak test; lagSeconds=0.033 at sampleRate=8000 round-trips to that index, not 50 as the comment claimed - Expand frame-rounding correlation array to 1000 elements so samples=267 and samples=-150 (idx=850) are in bounds; previously the bounds guard silently skipped placing the peak, leaving all-zeros and returning 0 frames - Fix misleading comment on the mismatched-lag test to clarify it is an intentional negative case (lag ≠ peak → isReliable=false) - Update review findings doc and SKILL.md pattern log Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
How to review
Test plan
npm testpasses (all Jest suites) ✅Manual verification completed:
Issues
Closes #12