Merge pull request #1279 from OxygenCobalt/copilot/fix-r128-gain-zero-issue
Fix R128_*_GAIN Opus fields containing 0 should not be ignored
This commit is contained in:
@@ -267,7 +267,7 @@ internal fun Metadata.replayGainAlbumAdjustment() =
|
||||
?: id3v2["TXXX:REPLAYGAIN_ALBUM_GAIN"]?.parseReplayGainAdjustment())
|
||||
|
||||
private fun List<String>.parseR128Adjustment() =
|
||||
first().replace(REPLAYGAIN_ADJUSTMENT_FILTER_REGEX, "").toFloatOrNull()?.nonZeroOrNull()?.run {
|
||||
first().replace(REPLAYGAIN_ADJUSTMENT_FILTER_REGEX, "").toFloatOrNull()?.run {
|
||||
// Convert to fixed-point and adjust to LUFS 18 to match the ReplayGain scale
|
||||
this / 256f + 5
|
||||
}
|
||||
|
||||
@@ -281,6 +281,16 @@ class TagFieldsTest {
|
||||
// R128 is converted to match ReplayGain scale (-2560/256 + 5 = -5.0)
|
||||
assertEquals(-5.0f, metadata.replayGainTrackAdjustment())
|
||||
|
||||
// Test R128 with zero value (should return +5.0 dB, not null)
|
||||
metadata = createTestMetadata(xiphTags = mapOf("R128_TRACK_GAIN" to listOf("0")))
|
||||
// R128 is converted to match ReplayGain scale (0/256 + 5 = 5.0)
|
||||
assertEquals(5.0f, metadata.replayGainTrackAdjustment())
|
||||
|
||||
// Test R128 album gain with zero value
|
||||
metadata = createTestMetadata(xiphTags = mapOf("R128_ALBUM_GAIN" to listOf("0")))
|
||||
// R128 is converted to match ReplayGain scale (0/256 + 5 = 5.0)
|
||||
assertEquals(5.0f, metadata.replayGainAlbumAdjustment())
|
||||
|
||||
// Test zero value
|
||||
metadata = createTestMetadata(xiphTags = mapOf("REPLAYGAIN_TRACK_GAIN" to listOf("0.0 dB")))
|
||||
assertNull(metadata.replayGainTrackAdjustment())
|
||||
|
||||
Reference in New Issue
Block a user