Repository navigation
[API Request] Loudness data for players: add MixRamp on ReplayGain, and songLoudness envelope #289
tokyovigilante
started this conversation in
API requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Type of change
API extension
Proposal description
Child.replayGaincarries a track's gain and peak, from tags or (where a server analyses) from the audio. Additional loudness data across a track enables two features:MIXRAMP_STARTandMIXRAMP_END, read together with ReplayGain when a crossfade is planned; andRamps are a few dozen bytes a track, however the whole-track loudness envelope data is a few kB. Therefore ramps are proposed as an addition to the
ReplayGainobject (change A). The envelope can be fetched on demand from a new and separatesongLoudnessendpoint (change B).A and B can be implemented independentlyl a server may read tag data only for A without implementing loudness analysis.
Change A - MixRamps in ReplayGain objects
Two optional string fields on
ReplayGain,mixRampStartandmixRampEnd. These may be computed by the server or read from previously-tagged files at the server's discretion.How MixRamp works
MixRamp describes the loudness at each end of a track, so a player can start the next track while the current one fades naturally, without artificially scaling volume (MixRamp). The MixRamp tool
writes the tags into files; they can also be computed while playing.
MIXRAMP_STARTandMIXRAMP_END(names case-insensitive; Vorbis comments in FLAC and Ogg files,
TXXXframes in ID3v2).dB seconds;pairs in rising dB order, for example-24.00 0.30;-18.00 0.60;-12.00 1.20;-6.00 3.00;.−40, −30, −24, −21, −18, −15, −12, −9, −6, −3, 0, +3 and +6 dBRS.
MIXRAMP_START: from the start of the track to the first chunk at or above that level. InMIXRAMP_END: from the last chunk at or above that level to the end of the track.Example, threshold −17 dB, safety margin 1 s: the outgoing track plays at −6 dB gain, so its
MIXRAMP_END(-24.00 1.00;-18.00 2.50;-12.00 4.00;-6.00 9.00;) is read at −17 − (−6) = −11 dBRS: 4.83 s.The incoming track plays at −3 dB gain, so its
MIXRAMP_START(-24.00 0.30;-18.00 0.60;-12.00 1.20;-6.00 3.00;) is read at −14 dBRS: 1.00 s. Overlap: 4.83 + 1.00 − 1 = 4.83 s.Change B - Whole track loudness data
A
songLoudnessextension with one endpoint,getSongLoudness?id=…, returning the track's EBU R128 momentaryloudness every 100 ms, packed one byte per point, and a
hasLoudnessflag onReplayGainso a client knows whichtracks to request data for.
Backward compatibility impact
None. Change A adds two optional fields to
ReplayGain, omitted when a server has no data; clients that do not know them ignore them. Change B is a new extension, advertised throughgetOpenSubsonicExtensions, with a new endpoint and one new optional field onReplayGain(hasLoudness, present only on servers that advertise the extension).Backward compatibility
API details
Change A:
mixRampStartandmixRampEndonReplayGainThe two new fields carry the MixRamp tags' values unchanged, as strings described under "How MixRamp works" in the proposal description: a server does not parse, reformat or
convert them (beyond the validation under "Security impacts"), so a client can use the same parser it would
use on the tags.
A server passes
MIXRAMP_START/MIXRAMP_ENDthrough as it passes ReplayGain tags. A server that analyses audio computes thesame quantities, preferably with MixRamp's own measurement. One that measures EBU R128 momentary loudness
(for change B) may derive them from it instead: dBRS ≈ momentary LUFS + 15, with each momentary value
taken at the centre of its 400 ms window. In practice, this difference is trivial: measured on eleven varied tracks, ramps derived from EBU R128 data land within
0.1 s of MixRamp's own at the median and 0.6 s at the 90th percentile (no bias), at the levels a crossfade
reads (−24 to −3 dBRS); small against overlaps of several seconds and a typical 1 s safety margin.
mixRampStartstringMIXRAMP_START.mixRampEndstringMIXRAMP_END.As with the other
ReplayGainfields, they are omitted when the server has no data.Example (JSON), a song's
replayGainwith change A (and change B'shasLoudness):XML:
<replayGain trackGain="-8.2" trackPeak="0.95" albumGain="-7.6" albumPeak="0.99" mixRampStart="-90.00 0.10;-60.00 0.30;-40.00 0.60;-30.00 1.10;-24.00 1.40;-18.00 2.20;" mixRampEnd="-90.00 0.40;-60.00 1.20;-40.00 2.80;-30.00 5.10;-24.00 6.30;-18.00 8.90;" hasLoudness="true"/>Change B: the
songLoudnessextension, version 1Extension name:
songLoudnessThis extension adds one endpoint:
getSongLoudness: a song's loudness envelope.idResponse: a
songLoudnessobject.idstringvaluesstringReplayGain.hasLoudness: a server that advertisessongLoudnessadds a boolean to every song'sreplayGain(whichChildalways carries), true whengetSongLoudnesshas an envelope for the song. Unlikethe other
ReplayGainfields, it is not omitted when false: a server that advertises the extension alwaysreturns it (
falsewhen there is no envelope yet), so a client can tell "not analysed" from "notsupported"; a server that does not advertise
songLoudnessomits it.hasLoudnessbooleangetSongLoudnesshas an envelope for this song. Present in every song'sreplayGainwhen the server advertisessongLoudness.The envelope is EBU R128 momentary loudness (BS.1770, a 400 ms window), one point every 100 ms (the
update rate of EBU Tech 3341): point k is the loudness of the 400 ms window centred on k × 100 ms, with
audio before the start and after the end of the song counted as silence. Each byte is
round((L + 70) × 2)clamped to0..255, where
Lis the loudness in LUFS; a client decodesL = −70 + byte / 2. The scale is fixed forevery server: 0.5 LU steps from −70 LUFS (BS.1770's absolute gate; 0 means at or below it) to +57.5 LUFS.
A four-minute song is 2,400 bytes (3.2 KB in base64). A client drawing fewer points averages them itself (in
the power domain: 10·log10 of the mean of 10^(L/10)).
Errors:
10(missing parameter) withoutid;70(data not found) when the song does not exist or theserver has no envelope for it yet.
Example (JSON):
{ "subsonic-response": { "status": "ok", "version": "1.16.1", "openSubsonic": true, "songLoudness": { "id": "8f3c...", "values": "AAAKKD5VdHmA..." } } }XML:
<songLoudness id="8f3c..." values="AAAKKD5VdHmA..."/>.Relation to
Child.replayGain: a server that implements this extension should fillreplayGainfromthe same analysis (ReplayGain 2.0: track gain = −18 LUFS minus the integrated loudness; peak as a linear
value) for songs whose files carry no ReplayGain tags, and may use it for every song in place of tags, at
its discretion (one consistent measurement across a library); likewise
mixRampStart/mixRampEndif itimplements change A. A server that does not analyse audio does not advertise
songLoudness.Later versions (not proposed now): summary values the envelope does not give (loudness range, true peak),
if clients ask for them; an album-level envelope.
Security impacts
parse as
dB seconds;pairs and cap their length (a full ladder is under 300 characters); clients shouldparse them defensively.
getSongLoudnessserves stored results and answers70for a track not yetanalysed; it must not start an analysis, so clients cannot generate excess server load.
minute); servers may refuse (
70) envelopes for very long items such as multi-hour mixes.Potential issues
loudness (+15 dB, window-centred) are close but not identical (0.1 s median, 0.6 s at the 90th percentile).
Should the spec require MixRamp's own measurement for computed ramps, or allow the derived form as above?
1,000-track playlist grows by about 150 KB uncompressed).
Alternative solutions
songLoudnessendpoint instead of onReplayGain: a crossfading player would need anextra call per track for a few dozen bytes it reads with the gain anyway.
longer pass through unchanged, and every server would need its own parser.
ReplayGain: a few kilobytes on every track in every listing; too heavy.envelope can decode bytes cheaply.
server, with no parameters to carry.
library, which many users of shared or archival libraries avoid.
All reactions