S022: audio player backend with symphonia, rubato and cpal, plus waveform peaks

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-18 13:53:04 -06:00
commit 3867facdea

View file

@ -77,5 +77,13 @@ One entry per session, newest last, ≤ 15 lines: done, verified how, not done,
- Found: the local watch (S006) also reports reads (opening a file, listing the folder). The model ignores events whose stat is unchanged, and the folder's own event unless it is gone; the shared playlist watch compares mtime/size. Without that, listing and watch looped.
- Later: filter access events in `LocalLocation::watch` itself (debouncer-mini hides the event kind); back/up navigation and per-folder sort in `.directory` (S010, S015).
## S022 — Audio player backend
- Done: `tunal-player`. `Player::new(on_event: Fn(Event) + Send)` (engine thread; events called there): `open(path)`, `play()`, `pause()`, `stop()`, `seek(Duration)`, `set_volume(0..=1)` (atomic, immediate), `volume()`; drop joins the thread. `Event::{Opened { path, duration }, State(State::{Stopped, Playing, Paused}), Position(Duration) (~10×/s while playing, once after open/pause/stop/seek), Ended (then Stopped at 0), Error(Error)}`. `Error::{Unsupported, Io, Decode, NoDevice, Output, Cancelled}` (Clone, Display).
- Pipeline: symphonia 0.5 (mp3, flac, vorbis/ogg, aac/mp4, wav; accurate seek, gapless) → channel map (mono fans out, mono out averages) → rubato 0.16 `FftFixedIn` when rates differ (delay trimmed) → rtrb 0.4 ring (0.5 s) → cpal 0.18 default device (f32/f64/i16/i32/u16/u8). Pause = `stream.pause()`, engine blocks on its channel when not playing; stop/seek/end drop the stream. Device missing → `Error::NoDevice`.
- `Waveforms::request(path, buckets, done) -> WaveTicket` (`cancel()`): own thread, `(min, max)` per bucket over all channels + duration; memory cache by (path, mtime, buckets), hit calls `done` at once on the caller thread. Example `play [--volume V] [--buckets N] <file>`.
- Verified: workspace build, clippy -D warnings, fmt --check; example on ffmpeg fixtures in the scratchpad (wav, mp3, flac, ogg, m4a, mono 22.05 kHz): positions advance, pause, seek to 2.5 s, Ended, 800 buckets, cache hit ~30 µs; opus → `Unsupported`; missing file → `Io`; `ALSA_CONFIG_PATH=<empty>` → `NoDevice`, waveform still fine.
- Not done: audible check not done (volume 0); cancel path of waveforms exercised only by code; mid-stream spec changes skip the packet; device loss mid-play reports `Output` error and stops (no reconnect).
- Later: waveform worker pool instead of a thread per request; resume on default-device change.
## Later
-