music: add opus base gain support
OPUS has another volume adjustment field on top of the existing R128 adjustments. I was under the impression this was handled by the android system, but apparently not. This commit applies the base gain to files by just adding them onto the existing ReplayGain values. Resolves #521.
This commit is contained in:
parent
cdd08e7f99
commit
5c85001b0c
2 changed files with 19 additions and 0 deletions
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
## dev
|
## dev
|
||||||
|
|
||||||
|
#### What's Improved
|
||||||
|
- The OPUS base volume adjustment field is now parsed and used in as a ReplayGain adjustment
|
||||||
|
|
||||||
## 3.3.0
|
## 3.3.0
|
||||||
|
|
||||||
#### What's New
|
#### What's New
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ package org.oxycblt.auxio.music.metadata
|
||||||
|
|
||||||
import androidx.core.text.isDigitsOnly
|
import androidx.core.text.isDigitsOnly
|
||||||
import androidx.media3.common.MediaItem
|
import androidx.media3.common.MediaItem
|
||||||
|
import androidx.media3.common.MimeTypes
|
||||||
import androidx.media3.exoplayer.MetadataRetriever
|
import androidx.media3.exoplayer.MetadataRetriever
|
||||||
import androidx.media3.exoplayer.source.MediaSource
|
import androidx.media3.exoplayer.source.MediaSource
|
||||||
import androidx.media3.exoplayer.source.TrackGroupArray
|
import androidx.media3.exoplayer.source.TrackGroupArray
|
||||||
|
|
@ -97,6 +98,21 @@ private class TagWorkerImpl(
|
||||||
val textTags = TextTags(metadata)
|
val textTags = TextTags(metadata)
|
||||||
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.
|
||||||
|
if (format.sampleMimeType == MimeTypes.AUDIO_OPUS
|
||||||
|
&& format.initializationData.isNotEmpty()
|
||||||
|
&& format.initializationData[0].size >= 18) {
|
||||||
|
val header = format.initializationData[0]
|
||||||
|
val gain = header[1].toInt() or ((header[0].toInt() shl 8) and 0xFF)
|
||||||
|
logD("Obtained opus base gain: ${gain / 256f} dB")
|
||||||
|
rawSong.replayGainTrackAdjustment =
|
||||||
|
rawSong.replayGainTrackAdjustment?.plus(gain / 256f)
|
||||||
|
rawSong.replayGainAlbumAdjustment =
|
||||||
|
rawSong.replayGainAlbumAdjustment?.plus(gain / 256f)
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
logD("No metadata could be extracted for ${rawSong.name}")
|
logD("No metadata could be extracted for ${rawSong.name}")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue