Skip to content

feat(mobile): chunked audio engine via WAV Range requests - #237

Merged
thcp merged 1 commit into
mainfrom
feat/mobile-chunked-audio-engine-236
Jun 29, 2026
Merged

feat(mobile): chunked audio engine via WAV Range requests#237
thcp merged 1 commit into
mainfrom
feat/mobile-chunked-audio-engine-236

Conversation

@thcp

@thcp thcp commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Closes #236

What changed

Replaces the full-file MP3 decode approach with a progressive WAV engine (static/js/chunkedAudioEngine.js) that fetches stems in 10-second chunks via HTTP Range requests and chains AudioBufferSourceNodes back-to-back for gapless playback.

static/mobile/app.js changes are three lines: new import, WAV URLs (no .mp3 replacement), engine constructor swap.

Why

Before After
Wait before first audio Full file download + decode ~7 MB (one chunk, 4 stems)
Peak RAM (5-min track) ~420 MB ~28 MB
Track length limit ~7 min (4 stems) None
Safari glitch-free Yes Yes

How it works

  • ready(): fetches WAV headers (first 1 KB per stem), decodes chunk 0, pre-fetches chunk 1
  • play(): schedules chunk 0 immediately from the sync cache
  • RAF tick: when the playhead is within 12 seconds of the last scheduled chunk, fetches and schedules the next one
  • seek(t): stops all nodes, evicts stale cache, restarts from the new position
  • Backend: zero changes - Starlette FileResponse already handles Range headers

Tested

  • First audio on WiFi starts in ~1-2 seconds
  • No gap at chunk boundaries (10 s, 20 s, ...)
  • Seek mid-track resumes correctly
  • Tracks longer than 7 minutes load without error
  • Mute/solo/fader controls work as before

Replaces full-file MP3 decode with a progressive WAV engine that fetches
stems in 10-second chunks and chains AudioBufferSourceNodes back-to-back.

- First audio after ~7 MB download (one chunk for 4 stems) vs. waiting
  for the complete file
- Peak RAM ~28 MB vs. ~420 MB for a 5-minute 4-stem track
- No track-length cap (removes the 7-14 min OOM limit)
- Same glitch-free behavior on Safari/WKWebView: AudioBufferSourceNode,
  no streaming elements, no HTTP/1.1 connection-cap underruns
- Backend needs no changes: Starlette FileResponse handles Range requests

Closes #236
@thcp
thcp marked this pull request as ready for review June 29, 2026 16:00
@thcp
thcp merged commit 52197aa into main Jun 29, 2026
8 checks passed
@thcp
thcp deleted the feat/mobile-chunked-audio-engine-236 branch June 29, 2026 16:00
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.

feat(mobile): chunked audio engine - faster start, no RAM limit

1 participant