Repository navigation
feat: even out the volume from song to song - #78
Open
madeofpendletonwool wants to merge 1 commit into
Open
madeofpendletonwool wants to merge 1 commit into
madeofpendletonwool wants to merge 1 commit into
Conversation
Songs play at whatever level they were mastered at, so the room's volume jumps from track to track. The analysis now measures each song's integrated loudness (ITU-R BS.1770: K-weighted, gated) alongside its beat map, and the speaker turns loud songs down to -16 LUFS. - Measured on the mono mix the analysis already decodes, calibrated against ffmpeg's ebur128 on real songs: within 0.7 LU. - Beat map version 2, so songs are measured again when next played. - The speaker sets each <audio> element's volume when it loads or preloads a song, easing it in if the map arrives once the song's under way. Volume can only go down, so songs under -16 LUFS stay as they are; at most 12 dB off. - iOS ignores a page's volume, so iPhones as speakers are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The volume varies a lot from song to song. Each track plays at the level it was mastered at, and in this library that ranges from about −21 to −7 LUFS.
What
Server: the analysis now measures each song's integrated loudness (
server/internal/analysis/loudness.go) using ITU-R BS.1770 / EBU R128: K-weighting, 400 ms blocks, then the −70 LUFS absolute gate and the −10 LU relative gate. It runs on the mono 22.05 kHz signal the beat analysis already decodes, so it adds no extra decode. The result is exposed asBeatMap.lufs.ebur128on 7 real songs, from a 60s single to modern masters: within ±0.7 LU. The mono mix reads about 0.8 LU under a stereo meter, andstereoLUadds that back.analysis.Versiongoes to 2, so existing maps are recomputed when a song is next queued or played.Web:
web/src/lib/loudness.tsturns loud songs down to −16 LUFS (Apple Music's level), cutting at most 12 dB. The speaker applies this to each<audio>element when it loads or preloads a song. If the map arrives once the song is already playing, the change eases in over 2 s.Choices and limits
<audio>volume tops out at 1, and Web Audio is avoided on purpose (mobile browsers suspend it in the background). Songs quieter than −16 stay as they are. In an 18-track sample spanning the Beatles to Daft Punk, about 90% were above −16, so most get evened out.el.volume, so an iPhone acting as the speaker is unchanged. The box, desktops and Android work.Testing
loudness_test.go: the BS.1770 sine reference, level tracking, gating of surrounding silence, bass weighting, and silence reading as no loudness.loudness.test.ts: the gain maths.