geesawra.industries/hydraulophone
An unofficial YouTube Music app for iPhone, iPad, and Mac.
0
0
# 0008 — Track normalization and preparing the next song
Date: 2026-09-24
Status: accepted for implementation per owner request
## Playback
Use the optional InnerTube loudness measurements described in
[the protocol note](../protocol/audio-loudness.md). Normalize Volume is a single
persisted toggle, enabled by default. The policy lowers loud tracks and never
boosts quiet tracks, with unity gain if metadata is absent. This is track
normalization; it does not infer album-wide loudness.
AAC applies linear gain through AVPlayer. Opus applies gain to a fresh copy of
each scheduled Float32 PCM chunk, after codec header gain, using that chunk's
track metadata. Applying a shared mixer gain at a timer-driven transition
would mis-normalize audio already scheduled across the gapless boundary.
Changing the setting flushes scheduled native buffers through the existing
seek path and preserves the paused/playing intent. Encoded files are unchanged.
Loudness stays with cached/downloaded assets. Older files start immediately.
When online with normalization enabled, one background player metadata request
fills missing values, updates the current gain and persists metadata to existing
cache/download records without refetching audio. It is cancellation guarded and
is not retried in a loop. Offline assets with no metadata play at unity until a
later online playback can recover it.
## Queue preparation
The previous High implementation prepared only a decoded head in the final
45 seconds. On unmetered connections, with cache enabled, prepare the next
occurrence on first verified playback progress and fill the rest of that
successor's encoded file through the shared bounded cache. This reuses its
resolved stream. Standard caches one successor concurrently with the active
track's HLS cache fill, with both writes sharing the configured bounded cache.
Only the next occurrence is eligible, following the queue's repeat/shuffle and
end-of-track sleep policy. Once the current track has verified playback
progress, begin preparing that successor so the active track and its next
queue entry warm the cache as a pair. Queue edits, stop,
quality/offline changes and pause cancel speculation. Metered/Low Data Mode
connections retain the existing bounded High head preparation near the end but
do not fill entire successors. Cache limits and the existing Standard-to-High
replacement policy still apply. Prefetch failures are best effort and do not
affect current playback.
## Install configuration
Bundle the existing attributed public JNN key resource into both destinations.
The environment variable remains an override. This fixes loss of High proof
configuration when users reopen an installed app from the home screen. No user
credential is bundled or added to build logs.
## Validation on 2026-09-24
- `just lint` passed. Formal suites remain paused at the owner's request;
regression briefs are in `docs/test-briefs/audio-loudness.md` and
`docs/test-briefs/next-track-cache-and-public-key.md`.
- `just simulator-smoke-listening-quality` built and ran both qualities against
two public songs using isolated temporary caches. Both applied gain 0.425598
to perceptual loudness -6.58 despite different relative loudness baselines.
A separate quiet-song run retained unity gain. The canary checks native/AAC
scheduled gain, setting toggles, local successor resolution, retained cache
loudness, metadata-only refresh, and existing-manifest metadata updates.
- Both complete successors cached successfully. High transitioned with
`node_restarted=false`; Standard opened its successor locally.
- Successor preparation now starts on first verified playback progress, pairing
the active stream cache with its one eligible next queue entry.
- The simulator diagnostic launched without a key environment override and
confirmed bundled-key availability and successful High playback. Generated
app resources retain the original public key file's attribution.
- Hardware listening, normalization audibility, route changes, and long
background runs still need owner verification; simulator gain measurements
do not establish those outcomes.