Files
minstrel/internal/db/migrations/0068_leveled_stream_cache.up.sql
T
bvandeusenandClaude Opus 5.5 f34423a0e0
release / go (push) Successful in 2m17s
release / govulncheck (push) Successful in 26s
release / web (push) Successful in 2m4s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / integration (push) Canceled after 4m39s
release / android (push) Canceled after 2m53s
release / Build signed APK (releases and dev) (push) Canceled after 2m24s
feat: leveled FLAC stream for Sonos/UPnP speakers (M464 #5001)
Speakers fetch their own audio, so the phone cannot level it. A cast
token minted with level=true (and the client's asAlbum, which only the
queue holder knows) now returns GET /api/tracks/{id}/leveled.flac: the
track rendered by ffmpeg at the user's gain (volume=XdB, plus
alimiter at -1 dBFS for a limiter-mode boost), metadata stripped, FLAC
at 16 or 24 bits and at most 48 kHz. The gain is computed server-side
from the user's preference and the stored loudness, carried as
?g=<centi-dB>&lim=0|1 and signed into the token, so an edited URL does
not verify. Unity gains get the plain stream.

Renders are written beside the cache file and renamed in, keyed by the
source's size and mtime, coalesced per file (singleflight, detached
from the requesting speaker so a retry finds the render running),
started at mint time so the fetch finds them ready, and evicted least
recently used past leveled_cache_mb, a new admin setting (migration
0068, Loudness analysis card).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 19:31:07 -04:00

13 lines
678 B
SQL

-- 0068_leveled_stream_cache.up.sql — the size cap of the leveled-stream render
-- cache (Scribe milestone #464, #5001).
--
-- Sonos and other UPnP renderers fetch a track's URL themselves, so the phone
-- cannot level what they play. The server renders a gain-applied FLAC for them
-- instead and keeps it on disk, oldest-used first out once the cache is over
-- this size. An operator setting (rule 25), on the loudness settings row it
-- belongs with.
ALTER TABLE loudness_settings
ADD COLUMN leveled_cache_mb integer NOT NULL DEFAULT 2048,
ADD CONSTRAINT loudness_settings_leveled_cache_range
CHECK (leveled_cache_mb >= 256 AND leveled_cache_mb <= 65536);