Repository navigation
Parse ReplayGain album gain field - #17315
Conversation
|
|
||
| if (float.TryParse(trackAlbumGainTag, NumberStyles.Float, CultureInfo.InvariantCulture, out var value) && float.IsFinite(value)) | ||
| { | ||
| if (!audio.AlbumEntity.NormalizationGain.HasValue) |
There was a problem hiding this comment.
Possible nullref here. AlbumEntity is FindParent<MusicAlbum>(), which returns null when the track has no MusicAlbum parent.
| if (float.TryParse(trackReferenceLoudnessTag, NumberStyles.Float, CultureInfo.InvariantCulture, out var value) && float.IsFinite(value)) | ||
| { | ||
| audio.ReferenceLoudness = value; | ||
| if (!audio.AlbumEntity.ReferenceLoudness.HasValue) |
There was a problem hiding this comment.
No longer relevant if not parsing the reference loudness
|
|
||
| if (trackReferenceLoudnessTag is not null) | ||
| { | ||
| if (trackReferenceLoudnessTag.EndsWith("LUFS", StringComparison.OrdinalIgnoreCase)) |
There was a problem hiding this comment.
Consider stripping "db" like with the gain. Not sure though how common that is in practice.
There was a problem hiding this comment.
I'm not sure either, but it definitely doesn't hurt. Is it ok to do the 2 checks separately like this? I assume you could have either "LUFS" or "dB" but not both.
There was a problem hiding this comment.
No longer relevant if not parsing the reference loudness
This comment was marked as off-topic.
This comment was marked as off-topic.
|
REPLAYGAIN_REFERENCE_LOUDNESS should not be used as it deviates from the spec |
I understand your point and while I'm personally anyway using the default -18 value, I also don't see the harm in processing it as long as it's available in the file. A file that has a track gain tag of -6 dB at -18 reference will have the track gain tag at -2 dB if it was scanned at -14 reference. If you parse only the -2dB tag without considering it was relative to a non-standard value, the file will be played too loud. If only some albums in your collection used the non-standard reference for whatever reason, but not the entire library, that defeats the purpose of volume normalization. What should we do in this situation? Process the reference gain tag when present, translate the track/album gain internally to -18 and only expose the adjusted gain relative to -18 LUFS? I think that might be a good alternative. But ignoring the tag when present in files will cause inconsistent playback volume. |
Correct, but I see that as user error. |
ede6d0d to
605de14
Compare
OK, removed the reference gain. PR greatly simplified due to this. |
Bond-009
left a comment
There was a problem hiding this comment.
Thank you, this is way simpler
605de14 to
144c120
Compare
|
This pull request has merge conflicts. Please resolve the conflicts so the PR can be successfully reviewed and merged. |
c820a94 to
f6f0fed
Compare
|
Changes
Hello! First time contributor here.
I'm missing proper support for ReplayGain tags for volume normalization in Music Assistant. This PR parses the ReplayGain tags internally if present in the music files and exposes them on the server API to be usable by 3rd party clients such as Music Assistant. The following tags are parsed if available in music files:
Code assistance
I'm normally a developer from the embedded world, so my C# experience is limited. I used an LLM to understand the code base, where to plug my changes, but I did the actual implementation and debugging. Tested and confirmed it works on my machine, not just AI slop.
Issues
This change just exposes the information but doesn't really fix anything by itself. I'm submitting related PRs to Music Assistant to parse this information:
Jc2k/aiojellyfin#10
music-assistant/server#4784
I haven't found any issues related to ReplayGain or volume normalization in this repo.