music: fix opus replaygain interpretation
- Don't parse the base gain, the media player actually does apply it. - Adjust R128 tags to LUFS -18 to be consistent w/MP3. Resolves #521.
This commit is contained in:
parent
be1ee55b96
commit
07a98029c6
2 changed files with 35 additions and 18 deletions
|
@ -1,5 +1,11 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## dev
|
||||||
|
|
||||||
|
#### What's Fixed
|
||||||
|
- R128 adjustments are now adjusted to -18 LUFS to be consistent with MP3
|
||||||
|
- Fixed double application of opus base gain
|
||||||
|
|
||||||
## 3.4.0
|
## 3.4.0
|
||||||
|
|
||||||
#### What's New
|
#### What's New
|
||||||
|
|
|
@ -99,22 +99,27 @@ private class TagWorkerImpl(
|
||||||
populateWithId3v2(textTags.id3v2)
|
populateWithId3v2(textTags.id3v2)
|
||||||
populateWithVorbis(textTags.vorbis)
|
populateWithVorbis(textTags.vorbis)
|
||||||
|
|
||||||
// If this metadata is of a vorbis file, we actually need to extract it's base gain
|
|
||||||
// and divide it by 256 to get the gain in decibels.
|
// OPUS base gain interpretation code: This is likely not needed, as the media player
|
||||||
if (format.sampleMimeType == MimeTypes.AUDIO_OPUS &&
|
// should be using the base gain already. Uncomment if that's not the case.
|
||||||
format.initializationData.isNotEmpty() &&
|
//if (format.sampleMimeType == MimeTypes.AUDIO_OPUS
|
||||||
format.initializationData[0].size >= 18) {
|
// && format.initializationData.isNotEmpty()
|
||||||
val header = format.initializationData[0]
|
// && format.initializationData[0].size >= 18) {
|
||||||
val gain = (((header[16]).toInt() and 0xFF) or ((header[17].toInt() shl 8))) / 256f
|
// val header = format.initializationData[0]
|
||||||
logD("Obtained opus base gain: $gain dB")
|
// val gain =
|
||||||
if (gain != 0f) {
|
// (((header[16]).toInt() and 0xFF) or ((header[17].toInt() shl 8)))
|
||||||
logD("Applying opus base gain")
|
// .R128ToLUFS18()
|
||||||
rawSong.replayGainTrackAdjustment =
|
// logD("Obtained opus base gain: $gain dB")
|
||||||
(rawSong.replayGainTrackAdjustment ?: 0f) + gain
|
// if (gain != 0f) {
|
||||||
rawSong.replayGainAlbumAdjustment =
|
// logD("Applying opus base gain")
|
||||||
(rawSong.replayGainAlbumAdjustment ?: 0f) + gain
|
// rawSong.replayGainTrackAdjustment =
|
||||||
}
|
// (rawSong.replayGainTrackAdjustment ?: 0f) + gain
|
||||||
}
|
// rawSong.replayGainAlbumAdjustment =
|
||||||
|
// (rawSong.replayGainAlbumAdjustment ?: 0f) + gain
|
||||||
|
// } else {
|
||||||
|
// logD("Ignoring opus base gain")
|
||||||
|
// }
|
||||||
|
//}
|
||||||
} else {
|
} else {
|
||||||
logD("No metadata could be extracted for ${rawSong.name}")
|
logD("No metadata could be extracted for ${rawSong.name}")
|
||||||
}
|
}
|
||||||
|
@ -317,14 +322,20 @@ private class TagWorkerImpl(
|
||||||
// the base adjustment intrinsic to the format to create the normalized adjustment. This is
|
// the base adjustment intrinsic to the format to create the normalized adjustment. This is
|
||||||
// normally the only tag used for opus files, but some software still writes replay gain
|
// normally the only tag used for opus files, but some software still writes replay gain
|
||||||
// tags anyway.
|
// tags anyway.
|
||||||
(comments["r128_track_gain"]?.parseReplayGainAdjustment()?.div(256)
|
(comments["r128_track_gain"]?.parseR128Adjustment()
|
||||||
?: comments["replaygain_track_gain"]?.parseReplayGainAdjustment())
|
?: comments["replaygain_track_gain"]?.parseReplayGainAdjustment())
|
||||||
?.let { rawSong.replayGainTrackAdjustment = it }
|
?.let { rawSong.replayGainTrackAdjustment = it }
|
||||||
(comments["r128_album_gain"]?.parseReplayGainAdjustment()?.div(256)
|
(comments["r128_album_gain"]?.parseR128Adjustment()
|
||||||
?: comments["replaygain_album_gain"]?.parseReplayGainAdjustment())
|
?: comments["replaygain_album_gain"]?.parseReplayGainAdjustment())
|
||||||
?.let { rawSong.replayGainAlbumAdjustment = it }
|
?.let { rawSong.replayGainAlbumAdjustment = it }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun List<String>.parseR128Adjustment() =
|
||||||
|
first().replace(REPLAYGAIN_ADJUSTMENT_FILTER_REGEX, "").toFloatOrNull()?.nonZeroOrNull()?.run {
|
||||||
|
// Convert to fixed-point and adjust to LUFS 18 to match the ReplayGain scale
|
||||||
|
this / 256f + 5
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a ReplayGain adjustment into a float value.
|
* Parse a ReplayGain adjustment into a float value.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue