Skip to content

Fix AudioProcessingTrack per-sample loop performance#633

Merged
BuffMcBigHuge merged 1 commit intomarco/feat/audio-sync-2from
ryan/fix/audio-track-numpy-perf
Mar 9, 2026
Merged

Fix AudioProcessingTrack per-sample loop performance#633
BuffMcBigHuge merged 1 commit intomarco/feat/audio-sync-2from
ryan/fix/audio-track-numpy-perf

Conversation

@ryanontheinside
Copy link
Copy Markdown
Collaborator

Summary

  • Replace per-sample Python loops in AudioProcessingTrack with vectorized numpy operations, addressing review feedback
  • Add 42 tests covering interleaving, buffering, resampling, channel conversion, frame construction, and full recv() integration with adversarial inputs

Changes

src/scope/server/tracks.py

  • Audio buffer changed from deque[float] to np.ndarray (float32)
  • Channel interleaving now uses np.ravel(order="F") instead of nested for loops
  • Frame extraction uses numpy slicing instead of per-sample popleft()
  • _create_audio_frame accepts np.ndarray directly, skipping redundant conversion

tests/test_audio_processing_track.py (new)

  • Interleaving correctness (stereo ordering, mono passthrough, multi-channel)
  • Buffer accumulation (exact boundaries, undersized, multi-frame drain, small chunk accumulation)
  • Frame construction (clipping, silence, mono/stereo layout)
  • Adversarial inputs (zero-length, single sample, NaN, Inf, large chunks, float64, DC offset)
  • Resampling (passthrough, up/down, odd ratios, edge cases)
  • Full recv() integration (no audio, resampling, mono upmix, 1D tensor, pause, accumulation)

Test plan

  • All 42 new tests pass (uv run pytest tests/test_audio_processing_track.py)
  • Module imports cleanly
  • @BuffMcBigHuge Manual test with LTX-2 audio pipeline

…ioProcessingTrack

Addresses review feedback on #534. The audio buffer interleaving and
frame extraction used O(n) Python loops over individual samples, which
is expensive for real-time audio. Now uses np.ravel(order="F") for
interleaving and numpy slicing for frame extraction.

Also adds 42 tests covering interleaving, buffering, resampling,
channel conversion, frame construction, and adversarial inputs.

Signed-off-by: RyanOnTheInside <[email protected]>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 9, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e265dfbb-10bd-49c3-852a-5f17a4b1607e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ryan/fix/audio-track-numpy-perf

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

Copy link
Copy Markdown
Collaborator

@BuffMcBigHuge BuffMcBigHuge left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 9, 2026

🚀 fal.ai Preview Deployment

App ID daydream/scope-pr-633
WebSocket wss://fal.run/daydream/scope-pr-633/ws
Commit 38486db

Testing

Connect to this preview deployment by setting the fal endpoint in your client:

FAL_WS_URL=wss://fal.run/daydream/scope-pr-633/ws

🧪 E2E tests will run automatically against this deployment.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 9, 2026

✅ E2E Tests passed

Status passed
fal App daydream/scope-pr-633
Run View logs

Test Artifacts

Check the workflow run for screenshots.

@BuffMcBigHuge BuffMcBigHuge merged commit 2c445ba into marco/feat/audio-sync-2 Mar 9, 2026
5 checks passed
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