musikr: read ReplayGain with APE preferred over ID3v2
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
#include "JByteArrayRef.h"
|
||||
|
||||
JMetadataBuilder::JMetadataBuilder(JNIEnv *env) : env(env), id3v2(env), xiph(
|
||||
env), mp4(env), cover(), properties(nullptr) {
|
||||
env), mp4(env), ape(env), cover(), properties(nullptr) {
|
||||
}
|
||||
|
||||
void JMetadataBuilder::setMimeType(TagLib::String type) {
|
||||
@@ -203,15 +203,16 @@ jobject JMetadataBuilder::build() {
|
||||
|
||||
JClassRef jMetadataClass { env, "org/oxycblt/musikr/metadata/Metadata" };
|
||||
jmethodID jMetadataInitMethod = jMetadataClass.method("<init>",
|
||||
"(Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;[BLorg/"
|
||||
"(Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;[BLorg/"
|
||||
"oxycblt/musikr/metadata/Properties;)V");
|
||||
auto jId3v2Map = id3v2.getObject();
|
||||
auto jXiphMap = xiph.getObject();
|
||||
auto jMp4Map = mp4.getObject();
|
||||
auto jApeMap = ape.getObject();
|
||||
if (cover.has_value()) {
|
||||
JByteArrayRef jCoverArray { env, cover.value() };
|
||||
jobject result = env->NewObject(*jMetadataClass, jMetadataInitMethod,
|
||||
**jId3v2Map, **jXiphMap, **jMp4Map, *jCoverArray, *jProperties);
|
||||
**jId3v2Map, **jXiphMap, **jMp4Map, **jApeMap, *jCoverArray, *jProperties);
|
||||
return result;
|
||||
}
|
||||
return env->NewObject(*jMetadataClass, jMetadataInitMethod, **jId3v2Map,
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "taglib/id3v2tag.h"
|
||||
#include "taglib/xiphcomment.h"
|
||||
#include "taglib/mp4tag.h"
|
||||
#include "taglib/apetag.h"
|
||||
#include "taglib/audioproperties.h"
|
||||
|
||||
#include "JTagMap.h"
|
||||
@@ -40,6 +41,7 @@ public:
|
||||
void setId3v2(TagLib::ID3v2::Tag &tag);
|
||||
void setXiph(TagLib::Ogg::XiphComment &tag);
|
||||
void setMp4(TagLib::MP4::Tag &tag);
|
||||
void setApe(TagLib::APE::Tag &tag);
|
||||
void setFlacPictures(TagLib::List<TagLib::FLAC::Picture*> &pics);
|
||||
void setProperties(TagLib::AudioProperties *properties);
|
||||
|
||||
@@ -56,6 +58,7 @@ private:
|
||||
JTagMap id3v2;
|
||||
JTagMap xiph;
|
||||
JTagMap mp4;
|
||||
JTagMap ape;
|
||||
};
|
||||
|
||||
#endif //AUXIO_JMETADATABUILDER_H
|
||||
|
||||
@@ -28,7 +28,7 @@ build_for_arch() {
|
||||
cmake -B $DST_DIR -DANDROID_NDK_PATH=${NDK_PATH} -DCMAKE_TOOLCHAIN_FILE=${NDK_TOOLCHAIN} \
|
||||
-DANDROID_ABI=$ARCH -DBUILD_SHARED_LIBS=OFF -DVISIBILITY_HIDDEN=ON -DBUILD_TESTING=OFF \
|
||||
-DBUILD_EXAMPLES=OFF -DBUILD_BINDINGS=OFF -DWITH_ZLIB=OFF -DCMAKE_BUILD_TYPE=Release \
|
||||
-DWITH_APE=OFF -DWITH_ASF=OFF -DWITH_ASF=OFF -DWITH_MOD=OFF -DWITH_SHORTEN=OFF \
|
||||
-DWITH_APE=ON -DWITH_ASF=OFF -DWITH_ASF=OFF -DWITH_MOD=OFF -DWITH_SHORTEN=OFF \
|
||||
-DWITH_TRUEAUDIO=OFF -DCMAKE_CXX_FLAGS="-fPIC"
|
||||
# Try to parallelize the build
|
||||
cmake --build $DST_DIR --config Release -j$(nproc)
|
||||
|
||||
@@ -22,6 +22,7 @@ data class Metadata(
|
||||
val id3v2: Map<String, List<String>>,
|
||||
val xiph: Map<String, List<String>>,
|
||||
val mp4: Map<String, List<String>>,
|
||||
val ape: Map<String, List<String>>,
|
||||
val cover: ByteArray?,
|
||||
val properties: Properties,
|
||||
) {
|
||||
@@ -34,6 +35,7 @@ data class Metadata(
|
||||
if (id3v2 != other.id3v2) return false
|
||||
if (xiph != other.xiph) return false
|
||||
if (mp4 != other.mp4) return false
|
||||
if (ape != other.ape) return false
|
||||
if (cover != null) {
|
||||
if (other.cover == null) return false
|
||||
if (!cover.contentEquals(other.cover)) return false
|
||||
@@ -47,6 +49,7 @@ data class Metadata(
|
||||
var result = id3v2.hashCode()
|
||||
result = 31 * result + xiph.hashCode()
|
||||
result = 31 * result + mp4.hashCode()
|
||||
result = 31 * result + ape.hashCode()
|
||||
result = 31 * result + (cover?.contentHashCode() ?: 0)
|
||||
result = 31 * result + properties.hashCode()
|
||||
return result
|
||||
|
||||
@@ -253,15 +253,18 @@ internal fun Metadata.isCompilation() =
|
||||
?: id3v2["TXXX:COMPILATION"]
|
||||
?: id3v2["TXXX:ITUNESCOMPILATION"]) == listOf("1")
|
||||
|
||||
// ReplayGain information
|
||||
// ReplayGain information. APE is preferred over the other tag formats: it is the only ReplayGain
|
||||
// carrier in some libraries, and where it coexists with ID3v2 it is the more deliberate choice.
|
||||
internal fun Metadata.replayGainTrackAdjustment() =
|
||||
(xiph["R128_TRACK_GAIN"]?.parseR128Adjustment()
|
||||
(ape["REPLAYGAIN_TRACK_GAIN"]?.parseReplayGainAdjustment()
|
||||
?: xiph["R128_TRACK_GAIN"]?.parseR128Adjustment()
|
||||
?: xiph["REPLAYGAIN_TRACK_GAIN"]?.parseReplayGainAdjustment()
|
||||
?: mp4["----:COM.APPLE.ITUNES:REPLAYGAIN_TRACK_GAIN"]?.parseReplayGainAdjustment()
|
||||
?: id3v2["TXXX:REPLAYGAIN_TRACK_GAIN"]?.parseReplayGainAdjustment())
|
||||
|
||||
internal fun Metadata.replayGainAlbumAdjustment() =
|
||||
(xiph["R128_ALBUM_GAIN"]?.parseR128Adjustment()
|
||||
(ape["REPLAYGAIN_ALBUM_GAIN"]?.parseReplayGainAdjustment()
|
||||
?: xiph["R128_ALBUM_GAIN"]?.parseR128Adjustment()
|
||||
?: xiph["REPLAYGAIN_ALBUM_GAIN"]?.parseReplayGainAdjustment()
|
||||
?: mp4["----:COM.APPLE.ITUNES:REPLAYGAIN_ALBUM_GAIN"]?.parseReplayGainAdjustment()
|
||||
?: id3v2["TXXX:REPLAYGAIN_ALBUM_GAIN"]?.parseReplayGainAdjustment())
|
||||
|
||||
@@ -321,10 +321,22 @@ class TagFieldsTest {
|
||||
assertEquals(listOf("Classical", "Ambient"), metadata.genreNames())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun metadata_replayGainTrack_apePreferredOverId3v2() {
|
||||
val metadata =
|
||||
createTestMetadata(
|
||||
id3v2Tags = mapOf("TXXX:REPLAYGAIN_TRACK_GAIN" to listOf("-1.0 dB")),
|
||||
apeTags = mapOf("REPLAYGAIN_TRACK_GAIN" to listOf("-5.175 dB")),
|
||||
)
|
||||
|
||||
assertEquals(-5.175f, metadata.replayGainTrackAdjustment()!!, 0.0001f)
|
||||
}
|
||||
|
||||
private fun createTestMetadata(
|
||||
id3v2Tags: Map<String, List<String>> = emptyMap(),
|
||||
xiphTags: Map<String, List<String>> = emptyMap(),
|
||||
mp4Tags: Map<String, List<String>> = emptyMap(),
|
||||
apeTags: Map<String, List<String>> = emptyMap(),
|
||||
cover: ByteArray? = null,
|
||||
durationMs: Long = 1000,
|
||||
bitrateKbps: Int = 320,
|
||||
@@ -332,6 +344,6 @@ class TagFieldsTest {
|
||||
mimeType: String = "audio/mpeg",
|
||||
): Metadata {
|
||||
val properties = Properties(mimeType, durationMs, bitrateKbps, sampleRateHz)
|
||||
return Metadata(id3v2Tags, xiphTags, mp4Tags, cover, properties)
|
||||
return Metadata(id3v2Tags, xiphTags, mp4Tags, apeTags, cover, properties)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,6 +185,6 @@ class TagParserTest {
|
||||
mimeType: String = "audio/mpeg",
|
||||
): Metadata {
|
||||
val properties = Properties(mimeType, durationMs, bitrateKbps, sampleRateHz)
|
||||
return Metadata(id3v2Tags, xiphTags, mp4Tags, cover, properties)
|
||||
return Metadata(id3v2Tags, xiphTags, mp4Tags, emptyMap(), cover, properties)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,6 +243,6 @@ class TagParsingEdgeCasesTest {
|
||||
mimeType: String = "audio/mpeg",
|
||||
): Metadata {
|
||||
val properties = Properties(mimeType, durationMs, bitrateKbps, sampleRateHz)
|
||||
return Metadata(id3v2Tags, xiphTags, mp4Tags, cover, properties)
|
||||
return Metadata(id3v2Tags, xiphTags, mp4Tags, emptyMap(), cover, properties)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user